/*	mapp coding short message c file	*/
/*	written by Liu Zhiguo 2003-03-04	*/
/*	Version 2.0							*/
/*	--------------------------------	*/

#include "map_includes.h"

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding Send Routing Info For SM argument		*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_routinfoforsmarg(struct MapRIFSM_Arg *rif_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	
	flag = rif_ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01) //msisdn
		buf_len = add_tlv("0",rif_ptr->msisdn[0],rif_ptr->msisdn+1,0x80,&asn_buf);
	else
		return RER;
	if (flag & 0x02)	//sm_rp_pri
		buf_len = add_tlv("1",1,&rif_ptr->sm_rp_pri,0x80,&asn_buf);
	else
		return RER;
	if (flag & 0x04)	//service centre address
		buf_len = add_tlv("2",rif_ptr->sc_add[0],rif_ptr->sc_add+1,0x80,&asn_buf);
	else
		return RER;		
	if (flag & 0x08)	// gprs support indicator
		buf_len = add_null("7",0x80,&asn_buf);
	if (flag & 0x10)	// sm-rp-mti
		buf_len = add_tlv("8",1,&rif_ptr->sm_rp_mti,0x80,&asn_buf);
	if (flag & 0x20)	// sm-rp-smea
		buf_len = add_tlv("9",rif_ptr->sm_rp_smea[0],rif_ptr->sm_rp_smea+1,0x80,&asn_buf);
	return buf_len;	
}

int extract_routinfoforsmarg(struct	MapRIFSM_Arg *rif_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	rif_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_routinfoforsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("0",temp_buf,&asn_buf)) > 2)	//get msisdn
	{
		rif_ptr->msisdn[0] = len;
		memcpy(rif_ptr->msisdn+1,temp_buf,len);
		rif_ptr->param_flag |= 0x01;
	}
	else
		return RER;
	if(get_tlv("1",temp_buf,&asn_buf) == 1)		//get sm_rp_pri
	{
		rif_ptr->sm_rp_pri = temp_buf[0];
		rif_ptr->param_flag |= 0x02;
	}
	else
		return RER;
	if((len=get_tlv("2",temp_buf,&asn_buf)) > 2 )	//get service centre address
	{
		rif_ptr->sc_add[0] = len;
		memcpy(rif_ptr->sc_add+1,temp_buf,len);
		rif_ptr->param_flag |= 0x04;
	}
	else
		return RER;
	if (get_tlv("7",temp_buf,&asn_buf) != -1)	// gprs support indicator
	{
		rif_ptr->param_flag |= 0x08;
		rif_ptr->gprssup_flag = 1;
	}
	if (get_tlv("8",temp_buf,&asn_buf) == 1)	// sm-rp-mti
	{
		rif_ptr->param_flag |= 0x10;
		rif_ptr->sm_rp_mti = temp_buf[0];
	}
	len = get_tlv("9",temp_buf,&asn_buf);
	if (len != -1 && len < SMEA_LEN)		// sm-rp-smea
	{
		rif_ptr->param_flag |= 0x20;
		rif_ptr->sm_rp_smea[0] =len;
		memcpy(rif_ptr->sm_rp_smea+1,temp_buf,len);
	}
	return ROK;		
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding Send Routing Info For SM response		*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_routinfoforsmres(struct MapRIFSM_Res *rif_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	u32			flag;
	u8			tag1;
	char			tlv1[32];
	
	flag = rif_ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//imsi
		buf_len = add_tlv("4-1",IMSI_LEN,rif_ptr->imsi,0x00,&asn_buf);
	else
		return RER;
	if (flag & 0x02)	//LocInfoLMSI_struct
	{
		tag1 = 1;
		if (rif_ptr->loc_info.param_flag & 0x01)	//msc_number
		{
			sprintf(tlv1,"0-2.1-%d",tag1++);
			len = rif_ptr->loc_info.netnode_num[0];
			buf_len = add_tlv(tlv1,len,rif_ptr->loc_info.netnode_num+1,0x80,&asn_buf);			
		}
		if (rif_ptr->loc_info.param_flag & 0x02)	//lmsi
		{
			sprintf(tlv1,"0-2.4-%d",tag1++);
			buf_len = add_tlv(tlv1,LMSI_LEN,rif_ptr->loc_info.lmsi,0x00,&asn_buf);
		}
		if (rif_ptr->loc_info.param_flag & 0x04)	// gprs node indicator
		{
			sprintf(tlv1,"0-2.5-%d",tag1++);
			buf_len = add_null(tlv1,0x80,&asn_buf);
		}
		if (rif_ptr->loc_info.param_flag & 0x08)	// additional number
		{
			if (rif_ptr->loc_info.add_num.choice_flag & 0x01)	// msc number
			{
				sprintf(tlv1,"0-2.6-%d.0",tag1);
				len = rif_ptr->loc_info.add_num.choice.msc_num[0];
				buf_len = add_tlv(tlv1,len,rif_ptr->loc_info.add_num.choice.msc_num+1,0x80,&asn_buf);
			}
			else
			{
				sprintf(tlv1,"0-2.6-%d.1",tag1);
				len = rif_ptr->loc_info.add_num.choice.sgsn_num[0];
				buf_len = add_tlv(tlv1,len,rif_ptr->loc_info.add_num.choice.sgsn_num+1,0x80,&asn_buf);
			}
		}
	}
	else
		return RER;
	return buf_len;		
}

int extract_routinfoforsmres(struct MapRIFSM_Res *rif_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len,loop;
	
	rif_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_routinfoforsmres buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("4",temp_buf,&asn_buf) % 9;
//	if (len==IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)
	if (len>0)
	{
		if(len<IMSI_LEN)
		{
			for(loop=len;loop<IMSI_LEN;loop++)
			{
				temp_buf[loop] = 0xFF;
			}
		}
		memcpy(rif_ptr->imsi,temp_buf,IMSI_LEN);
		rif_ptr->param_flag |= 0x01;
	}
	else
		return RER;
	if (get_tlv("0",temp_buf,&asn_buf) > 0)	//get LocInfoLMSI_struct
	{
		rif_ptr->param_flag|=0x02;
		rif_ptr->loc_info.param_flag = 0;
		if((len=get_tlv("0.1",temp_buf,&asn_buf)) > 0)	//msc_num
		{
			rif_ptr->loc_info.param_flag |= 0x01;
			rif_ptr->loc_info.netnode_num[0] = len;
			memcpy(rif_ptr->loc_info.netnode_num+1,temp_buf,len);			
		}
		if(get_tlv("0.4",temp_buf,&asn_buf) == LMSI_LEN)	//get lmsi
		{
			rif_ptr->loc_info.param_flag |= 0x02;
			memcpy(rif_ptr->loc_info.lmsi,temp_buf,LMSI_LEN);
		}
		if (get_tlv("0.5",temp_buf,&asn_buf) != -1)		// gprs node indicator
		{
			rif_ptr->loc_info.param_flag |= 0x04;
			rif_ptr->loc_info.gprsnode_flag = 1;
		}
		len = get_tlv("0.6.0",temp_buf,&asn_buf);	// msc number
		if (len != -1 && len <= ISDN_LEN)
		{
			rif_ptr->loc_info.param_flag |= 0x08;
			rif_ptr->loc_info.add_num.choice_flag = 1;
			rif_ptr->loc_info.add_num.choice.msc_num[0] = len;
			memcpy(rif_ptr->loc_info.add_num.choice.msc_num+1,temp_buf,len);
		}
		else
		{
			len = get_tlv("0.6.1",temp_buf,&asn_buf);	// sgsn number
			if (len != -1 && len <= ISDN_LEN)
			{
				rif_ptr->loc_info.param_flag |= 0x08;
				rif_ptr->loc_info.add_num.choice_flag = 2;
				rif_ptr->loc_info.add_num.choice.sgsn_num[0] = len;
				memcpy(rif_ptr->loc_info.add_num.choice.sgsn_num+1,temp_buf,len);
			}
		}
	}
	else
		return RER;
	return ROK;		
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding Send Routing Info For SM V1 argument		*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_routinfoforsm_v1_arg(struct MapRIFSMV1_Arg *rif_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	
	flag = rif_ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)//msisdn
		buf_len = add_tlv("0",rif_ptr->msisdn[0],rif_ptr->msisdn+1,0x80,&asn_buf);
	else
		return RER;
	if (flag & 0x02)	//sm_rp_pri
		buf_len = add_tlv("1",1,&rif_ptr->sm_rp_pri,0x80,&asn_buf);
	else
		return RER;
	if (flag & 0x04)	//service centre address
		buf_len = add_tlv("2",rif_ptr->sc_add[0],rif_ptr->sc_add+1,0x80,&asn_buf);
	else
		return RER;		
	if (flag & 0x08)	//tele service
		buf_len = add_tlv("5",1,&rif_ptr->tele_service,0x80,&asn_buf);	
		
	return buf_len;	
}

int extract_routinfoforsm_v1_arg(struct	MapRIFSMV1_Arg *rif_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	rif_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_routinfoforsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("0",temp_buf,&asn_buf)) > 2)	//get msisdn
	{
		rif_ptr->msisdn[0] = len;
		memcpy(rif_ptr->msisdn+1,temp_buf,len);
		rif_ptr->param_flag |= 0x01;
	}
	else
		return RER;
	if(get_tlv("1",temp_buf,&asn_buf) == 1)		//get sm_rp_pri
	{
		rif_ptr->sm_rp_pri = temp_buf[0];
		rif_ptr->param_flag |= 0x02;
	}
	else
		return RER;
	if((len=get_tlv("2",temp_buf,&asn_buf)) > 2 )	//get service centre address
	{
		rif_ptr->sc_add[0] = len;
		memcpy(rif_ptr->sc_add+1,temp_buf,len);
		rif_ptr->param_flag |= 0x04;
	}
	else
		return RER;
	if (get_tlv("5",temp_buf,&asn_buf) == -1)	// gprs support indicator
	{
		rif_ptr->param_flag |= 0x08;
		memcpy( &rif_ptr->tele_service , temp_buf ,1 );
	}
	return ROK;		
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding Send Routing Info For SM response		*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_routinfoforsm_v1_res(struct MapRIFSMV1_Res *rif_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	
	flag = rif_ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//imsi
		buf_len = add_tlv("4-1",IMSI_LEN,rif_ptr->imsi,0x00,&asn_buf);
	else
		return RER;
	if (flag & 0x02)	//LocInfoLMSI_struct_v1
	{
		
		if (rif_ptr->loc_info.param_flag & 0x01)	//location info
		{
			if( rif_ptr->loc_info.choice_flag == 1)
			{
				buf_len = add_tlv("0-2.0-1",ISDN_LEN,rif_ptr->loc_info.choice.roaming_num,0x80,&asn_buf);
			}
			else if( rif_ptr->loc_info.choice_flag == 2)
			{
				buf_len = add_tlv("0-2.1-1",ISDN_LEN,rif_ptr->loc_info.choice.msc_num,0x80,&asn_buf);
			}
		}
		if (rif_ptr->loc_info.param_flag & 0x02)	//imsi
		{
			buf_len = add_tlv("0-2.4-2",IMSI_LEN,rif_ptr->loc_info.imsi,0x80,&asn_buf);
		}
	}
	else
		return RER;
		
	if( flag & 0x04 )
		buf_len = add_tlv("2-3",1,&rif_ptr->mwd_set,0x80,&asn_buf);
	return buf_len;		
}

int extract_routinfoforsm_v1_res(struct MapRIFSMV1_Res *rif_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	rif_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_routinfoforsmres buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("4-1",temp_buf,&asn_buf) ;
	if ( len == IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)
	{
		memcpy(rif_ptr->imsi,temp_buf,IMSI_LEN);
		rif_ptr->param_flag |= 0x01;
	}
	else
		return RER;
	
	if (get_tlv("0",temp_buf,&asn_buf) > 0)	//get LocInfoLMSI_struct
	{
		rif_ptr->param_flag|=0x02;
		rif_ptr->loc_info.param_flag = 0;
		if((len=get_tlv("0.0",temp_buf,&asn_buf)) > 0)	//msc_num
		{
			rif_ptr->loc_info.param_flag |= 0x01;
			rif_ptr->loc_info.choice_flag = 1;
			memcpy(rif_ptr->loc_info.choice.roaming_num,temp_buf,len);			
		}
		if(get_tlv("0.1",temp_buf,&asn_buf) == LMSI_LEN)	//get lmsi
		{
			rif_ptr->loc_info.param_flag |= 0x01;
			rif_ptr->loc_info.choice_flag = 2;
			memcpy(rif_ptr->loc_info.choice.msc_num,temp_buf,len);
		}
		if (get_tlv("0.4",temp_buf,&asn_buf) == IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)		// gprs node indicator
		{
			rif_ptr->loc_info.param_flag |= 0x02;
			memcpy(rif_ptr->loc_info.imsi,temp_buf,IMSI_LEN);
		}
	}
	else
		return RER;
	
	if( get_tlv("0",temp_buf,&asn_buf) == 1 )
	{
		memcpy(&rif_ptr->mwd_set,temp_buf,len); 
	}
	return ROK;		
}

/*	++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding forward SM Arg	*/
/*  ++++++++++++++++++++++++++++++++++++++++	*/
int assign_fwdsmarg(struct MapFSM_Arg *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	u32			flag;
	
	flag = ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//sm_rp_da
	{
		if (ptr->sm_rp_da_choice == 1)	//imsi
			buf_len = add_tlv("0-1",IMSI_LEN,ptr->sm_rp_da.imsi,0x80,&asn_buf);			
		else if (ptr->sm_rp_da_choice == 2)	//lmsi
			buf_len = add_tlv("1-1",LMSI_LEN,ptr->sm_rp_da.lmsi,0x80,&asn_buf);	
		else if( ptr->sm_rp_da_choice == 3 )
		{
			len = ptr->sm_rp_da.roaming_num[0];
			buf_len = add_tlv("3-1",len,ptr->sm_rp_da.roaming_num+1,0x80,&asn_buf);
		}
		else if (ptr->sm_rp_da_choice== 4)	//sc_add
		{
			len = ptr->sm_rp_da.sc_add[0];
			buf_len = add_tlv("4-1",len,ptr->sm_rp_da.sc_add+1,0x80,&asn_buf);
		}
		else
			buf_len = add_null("5-2",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_fwdsmarg:loss sm_rp_da");
		return RER;
	}	
	if (flag & 0x02)	//sm_rp_oa
	{
		if (ptr->sm_rp_oa_choice == 1)	//msisdn
		{
			len = ptr->sm_rp_oa.msisdn[0];
			buf_len = add_tlv("2-2",len,ptr->sm_rp_oa.msisdn+1,0x80,&asn_buf);
		}
		else if (ptr->sm_rp_oa_choice == 2)//sc_add
		{
			len = ptr->sm_rp_oa.sc_add[0];
			buf_len = add_tlv("4-2",len,ptr->sm_rp_oa.sc_add+1,0x80,&asn_buf);
		}
		else
			buf_len = add_null("5-2",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_fwdsmarg:loss sm_rp_oa");
		return RER;
	}
	if (flag & 0x04)	//sm_rp_ui
	{
		len = ptr->sm_rp_ui_len;
		buf_len = add_tlv("4-3",len,ptr->sm_rp_ui,0x00,&asn_buf);
	}
	else
		return RER;
		
	return buf_len;
}

int extract_fwdsmarg(struct MapFSM_Arg *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_mofwdsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	//imsi
	if(len == IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)
	{
		ptr->sm_rp_da_choice = 1;
		memcpy(ptr->sm_rp_da.imsi,temp_buf,IMSI_LEN);
	}
	else
	{
		if((len=get_tlv("1",temp_buf,&asn_buf)) == LMSI_LEN)//lmsi
		{
			ptr->sm_rp_da_choice = 2;
			memcpy(ptr->sm_rp_da.lmsi,temp_buf,LMSI_LEN);
		}
		else
		{
			if((len=get_tlv("3-1",temp_buf,&asn_buf)) > 0)//sc_add
			{
				ptr->sm_rp_da_choice = 3;
				ptr->sm_rp_da.roaming_num[0] = len;
				memcpy(ptr->sm_rp_da.roaming_num+1,temp_buf,len);
			}
			else
			{
				if((len=get_tlv("4-1",temp_buf,&asn_buf)) > 0)//sc_add
				{
					ptr->sm_rp_da_choice = 4;
					ptr->sm_rp_da.sc_add[0] = len;
					memcpy(ptr->sm_rp_da.sc_add+1,temp_buf,len);
				}
				else
				{
					if (get_tlv("5-1",temp_buf,&asn_buf) != -1)	// no SM-RP-DA
					{
						ptr->sm_rp_da_choice = 5;
						ptr->sm_rp_da.noms_rp_da = 1;
					}
					else
						return RER;
				}
			}
			
		}
	}
	
	ptr->param_flag |= 0x01;
	if ((len=get_tlv("2",temp_buf,&asn_buf)) > 0)	//msisdn
	{
		ptr->sm_rp_oa_choice = 1;
		ptr->sm_rp_oa.msisdn[0] = len;
		memcpy(ptr->sm_rp_oa.msisdn+1,temp_buf,len);
	}
	else
	{
		if ((len=get_tlv("4-2",temp_buf,&asn_buf)) > 0)	//sc_add
		{
			ptr->sm_rp_oa_choice = 2;
			ptr->sm_rp_oa.sc_add[0] = len;
			memcpy(ptr->sm_rp_oa.sc_add+1,temp_buf,len);
		}
		else
		{
			if (get_tlv("5-2",temp_buf,&asn_buf) != -1)	// no SM-RP-OA
			{
				ptr->sm_rp_oa_choice = 3;
				ptr->sm_rp_oa.noms_rp_oa = 1;
			}
			else
				return RER;
		}
	}
	ptr->param_flag |= 0x02;
	if((len=get_tlv("4-3",temp_buf,&asn_buf)) !=-1)
	{
		ptr->param_flag |= 0x04;
		ptr->sm_rp_ui_len = len;
		memcpy(ptr->sm_rp_ui,temp_buf,len);		
	}
	
	return ROK;
}




/*	++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MO forward SM Arg	*/
/*  ++++++++++++++++++++++++++++++++++++++++	*/
int assign_mofwdsmarg(struct MapMOFSM_Arg *ptr,u8 *buf, u8 version)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	u32			flag;
	
	flag = ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//sm_rp_da
	{
		if (ptr->sm_rp_da.choice_flag == 1)	//imsi
			buf_len = add_tlv("0-1",IMSI_LEN,ptr->sm_rp_da.choice.imsi,0x80,&asn_buf);			
		else if (ptr->sm_rp_da.choice_flag == 2)	//lmsi
			buf_len = add_tlv("1-1",LMSI_LEN,ptr->sm_rp_da.choice.lmsi,0x80,&asn_buf);		
		else if (ptr->sm_rp_da.choice_flag == 3)	//sc_add
		{
			len = ptr->sm_rp_da.choice.sc_add[0];
			buf_len = add_tlv("4-1",len,ptr->sm_rp_da.choice.sc_add+1,0x80,&asn_buf);
		}
		else if( version <3 && ptr->sm_rp_da.choice_flag == 5 )
		{
			len = ptr->sm_rp_da.choice.roaming_num[0];
			buf_len = add_tlv("3-1",len,ptr->sm_rp_da.choice.roaming_num+1,0x80,&asn_buf);
		}
		else 
			buf_len = add_null("5-1",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_mofwdsmarg:loss sm_rp_da");
		return RER;
	}	
	if (flag & 0x02)	//sm_rp_oa
	{
		if (ptr->sm_rp_oa.choice_flag == 1)	//msisdn
		{
			len = ptr->sm_rp_oa.choice.msisdn[0];
			buf_len = add_tlv("2-2",len,ptr->sm_rp_oa.choice.msisdn+1,0x80,&asn_buf);
		}
		else if (ptr->sm_rp_oa.choice_flag == 2)//sc_add
		{
			len = ptr->sm_rp_oa.choice.sc_add[0];
			buf_len = add_tlv("4-2",len,ptr->sm_rp_oa.choice.sc_add+1,0x80,&asn_buf);
		}
		else
			buf_len = add_null("5-2",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_mofwdsmarg:loss sm_rp_oa");
		return RER;
	}
	if (flag & 0x04)	//sm_rp_ui
	{
		len = ptr->sm_rp_ui.siginfo_len;
		buf_len = add_tlv("4-3",len,ptr->sm_rp_ui.signal_info,0x00,&asn_buf);
	}
	else
		return RER;
	if ((flag & 0x08) && (version==2))	//moremsg_flag,only MAP V2 support this
		buf_len = add_null("5-4",0x00,&asn_buf);
	
	return buf_len;
}

int extract_mofwdsmarg(struct MapMOFSM_Arg *ptr,u32 buf_len,u8 *buf,u8 version)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_mofwdsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	//imsi
	if(len == IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)
	{
		ptr->sm_rp_da.choice_flag = 1;
		memcpy(ptr->sm_rp_da.choice.imsi,temp_buf,IMSI_LEN);
	}
	else
	{
		if((len=get_tlv("1",temp_buf,&asn_buf)) == LMSI_LEN)//lmsi
		{
			ptr->sm_rp_da.choice_flag = 2;
			memcpy(ptr->sm_rp_da.choice.lmsi,temp_buf,LMSI_LEN);
		}
		else
		{
			if((len=get_tlv("4-1",temp_buf,&asn_buf)) > 0)//sc_add
			{
				ptr->sm_rp_da.choice_flag = 3;
				ptr->sm_rp_da.choice.sc_add[0] = len;
				memcpy(ptr->sm_rp_da.choice.sc_add+1,temp_buf,len);
			}
			else
			{
				if( version < 3 && (len=get_tlv("3-1",temp_buf,&asn_buf)) > 0 ) //roaming_num for ver <3
				{
					 ptr->sm_rp_da.choice_flag =5;
					 ptr->sm_rp_da.choice.roaming_num[0]= len;
					 memcpy( ptr->sm_rp_da.choice.roaming_num+1, temp_buf,len);
				}
				else
				{
						if (get_tlv("5-1",temp_buf,&asn_buf) != -1)	// no SM-RP-DA
						{
							ptr->sm_rp_da.choice_flag = 4;
							ptr->sm_rp_da.choice.no_rpda = 1;
						}
						else
							return RER;
				}
			}
		}
	}
	ptr->param_flag |= 0x01;
	if ((len=get_tlv("2",temp_buf,&asn_buf)) > 0)	//msisdn
	{
		ptr->sm_rp_oa.choice_flag = 1;
		ptr->sm_rp_oa.choice.msisdn[0] = len;
		memcpy(ptr->sm_rp_oa.choice.msisdn+1,temp_buf,len);
	}
	else
	{
		if ((len=get_tlv("4-2",temp_buf,&asn_buf)) > 0)	//sc_add
		{
			ptr->sm_rp_oa.choice_flag = 2;
			ptr->sm_rp_oa.choice.sc_add[0] = len;
			memcpy(ptr->sm_rp_oa.choice.sc_add+1,temp_buf,len);
		}
		else
		{
			if (get_tlv("5-2",temp_buf,&asn_buf) != -1)	// no SM-RP-OA
			{
				ptr->sm_rp_oa.choice_flag = 3;
				ptr->sm_rp_oa.choice.no_rpoa = 1;
			}
			else
				return RER;
		}
	}
	ptr->param_flag |= 0x02;
	if((len=get_tlv("4-3",temp_buf,&asn_buf)) !=-1 )
	{
		ptr->param_flag |= 0x04;
		ptr->sm_rp_ui.siginfo_len = len;
		memcpy(ptr->sm_rp_ui.signal_info,temp_buf,len);		
	}
	if (get_tlv("5-4",temp_buf,&asn_buf) != -1)
		ptr->param_flag |= 0x08;		
	
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MO forward SM response	*/
/*  ++++++++++++++++++++++++++++++++++++++++	*/
int assign_mofwdsmres(struct MapMOFSM_Res *ptr,u8 *buf, u8 version)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	
	if(version<3) 
		return buf_len;

	asn_encode(buf,&asn_buf);
	if (ptr->param_flag & 0x01)		// sm-rp-ui
	{
		len = ptr->sm_rp_ui.siginfo_len;
		buf_len = add_tlv("4",len,ptr->sm_rp_ui.signal_info,0x00,&asn_buf);
	}
	return buf_len;
}

int extract_mofwdsmres(struct MapMOFSM_Res *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	ptr->param_flag = 0;
	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("4",temp_buf,&asn_buf)) > 0)
	{
		ptr->param_flag |= 0x01;
		ptr->sm_rp_ui.siginfo_len = len;
		memcpy(ptr->sm_rp_ui.signal_info,temp_buf,len);		
	}
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MT forward SM argument	*/
/*  ++++++++++++++++++++++++++++++++++++++++	*/
int assign_mtfwdsmarg(struct MapMTFSM_Arg *ptr,u8 *buf,u8 MAPVer)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	u32			flag;
	
	flag = ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//sm_rp_da
	{
		if (ptr->sm_rp_da.choice_flag == 1)	//imsi
		{
			len = IMSI_LEN;
			if(ptr->sm_rp_da.choice.imsi[IMSI_LEN-1]== 0xff)
			{
				int loop;
				for(loop=IMSI_LEN-1;loop>2;loop--)
				{
					if(ptr->sm_rp_da.choice.imsi[loop] == 0xff)
						len --;
				}
			}
				
			buf_len = add_tlv("0-1",
							len,
							ptr->sm_rp_da.choice.imsi,
							0x80,
							&asn_buf);			
		}
		else if (ptr->sm_rp_da.choice_flag == 2)	//lmsi
			buf_len = add_tlv("1-1",LMSI_LEN,ptr->sm_rp_da.choice.lmsi,0x80,&asn_buf);		
		else if (ptr->sm_rp_da.choice_flag == 3)	//sc_add
		{
			len = ptr->sm_rp_da.choice.sc_add[0];
			buf_len = add_tlv("4-1",len,ptr->sm_rp_da.choice.sc_add+1,0x80,&asn_buf);
		}
		else
			buf_len = add_null("5-1",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_mofwdsmarg:loss sm_rp_da");
		return RER;
	}	
	if (flag & 0x02)	//sm_rp_oa
	{
		if (ptr->sm_rp_oa.choice_flag == 1)	//msisdn
		{
			len = ptr->sm_rp_oa.choice.msisdn[0];
			buf_len = add_tlv("2-2",len,ptr->sm_rp_oa.choice.msisdn+1,0x80,&asn_buf);
		}
		else if (ptr->sm_rp_oa.choice_flag == 2)//sc_add
		{
			len = ptr->sm_rp_oa.choice.sc_add[0];
			buf_len = add_tlv("4-2",len,ptr->sm_rp_oa.choice.sc_add+1,0x80,&asn_buf);
		}
		else
			buf_len = add_null("5-2",0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("MAPP--assign_mofwdsmarg:loss sm_rp_oa");
		return RER;
	}
	if (flag & 0x04)	//sm_rp_ui
	{
		len = ptr->sm_rp_ui.siginfo_len;
		buf_len = add_tlv("4-3",len,ptr->sm_rp_ui.signal_info,0x00,&asn_buf);
	}
	else
		return RER;
	if ((flag & 0x08) && ((MAPVer==3)||(MAPVer==2)))	//moremsg_flag,only MAP V3 support this
		buf_len = add_null("5-4",0x00,&asn_buf);
	return buf_len;
}
	
int extract_mtfwdsmarg(struct MapMTFSM_Arg *ptr,u32 buf_len,u8 *buf,u8 MAPVer)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_mofwdsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	//imsi
	if(len == IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)
	{
		ptr->sm_rp_da.choice_flag = 1;
		memcpy(ptr->sm_rp_da.choice.imsi,temp_buf,IMSI_LEN);
	}
	else
	{
		if((len=get_tlv("1",temp_buf,&asn_buf)) == LMSI_LEN)//lmsi
		{
			ptr->sm_rp_da.choice_flag = 2;
			memcpy(ptr->sm_rp_da.choice.lmsi,temp_buf,LMSI_LEN);
		}
		else
		{
			if((len=get_tlv("4-1",temp_buf,&asn_buf)) > 0)//sc_add
			{
				ptr->sm_rp_da.choice_flag = 3;
				ptr->sm_rp_da.choice.sc_add[0] = len;
				memcpy(ptr->sm_rp_da.choice.sc_add+1,temp_buf,len);
			}
			else
			{
				if (get_tlv("5-1",temp_buf,&asn_buf) != -1)	// no SM-RP-DA
				{
					ptr->sm_rp_da.choice_flag = 4;
					ptr->sm_rp_da.choice.no_rpda = 1;
				}
				else
					return RER;
			}
		}
	}
	ptr->param_flag |= 0x01;
	if ((len=get_tlv("2",temp_buf,&asn_buf)) > 0)	//msisdn
	{
		ptr->sm_rp_oa.choice_flag = 1;
		ptr->sm_rp_oa.choice.msisdn[0] = len;
		memcpy(ptr->sm_rp_oa.choice.msisdn+1,temp_buf,len);
	}
	else
	{
		if ((len=get_tlv("4-2",temp_buf,&asn_buf)) > 0)	//sc_add
		{
			ptr->sm_rp_oa.choice_flag = 2;
			ptr->sm_rp_oa.choice.sc_add[0] = len;
			memcpy(ptr->sm_rp_oa.choice.sc_add+1,temp_buf,len);
		}
		else
		{
			if (get_tlv("5-2",temp_buf,&asn_buf) != -1)	// no SM-RP-OA
			{
				ptr->sm_rp_oa.choice_flag = 3;
				ptr->sm_rp_oa.choice.no_rpoa = 1;
			}
			else
				return RER;
		}
	}
	ptr->param_flag |= 0x02;
	if((len=get_tlv("4-3",temp_buf,&asn_buf)) != -1)
	{
		ptr->param_flag |= 0x04;
		ptr->sm_rp_ui.siginfo_len = len;
		memcpy(ptr->sm_rp_ui.signal_info,temp_buf,len);		
	}
	if (get_tlv("5-4",temp_buf,&asn_buf) != -1)
		ptr->param_flag |= 0x08;
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MT forward SM response	*/
/*  ++++++++++++++++++++++++++++++++++++++++	*/
int assign_mtfwdsmres(struct MapMTFSM_Res *ptr,u8 *buf,u8 MAPVer)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	
	asn_encode(buf,&asn_buf);
	if (ptr->param_flag & 0x01)		// sm-rp-ui
	{
		len = ptr->sm_rp_ui.siginfo_len;
		buf_len = add_tlv("4",len,ptr->sm_rp_ui.signal_info,0x00,&asn_buf);
	}
	return buf_len;
}

int extract_mtfwdsmres(struct MapMTFSM_Res *ptr,u32 buf_len,u8 *buf,u8 MAPVer)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	ptr->param_flag = 0;
	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("4",temp_buf,&asn_buf)) > 0)
	{
		ptr->param_flag |= 0x01;
		ptr->sm_rp_ui.siginfo_len = len;
		memcpy(ptr->sm_rp_ui.signal_info,temp_buf,len);		
	}
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding report SM Delivery Status argument	*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_repsmdelstatarg(struct MapRSMDS_Arg *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	u8			temp_buf[256];
	u8			tag1;
	char			tlv1[32];
	
	flag = ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)		//msisdn
		buf_len = add_tlv("4-1",ptr->msisdn[0],ptr->msisdn+1,0x00,&asn_buf);			
	else
	{
		mapp_log_debug("MAPP--assign_reportSM_DeliveryStatus_arg:loss msisdn");
		return RER;
	}
	if (flag & 0x02)	//sc_add
		buf_len = add_tlv("4-2",ptr->sc_add[0],ptr->sc_add+1,0x00,&asn_buf);			
	else
	{
		mapp_log_debug("MAPP--assign_reportSM_DeliveryStatus_arg:loss sc_add");
		return RER;
	}	
	if (flag & 0x04)	//sm_deliout
	{
		temp_buf[0] = ptr->sm_deliout;
		buf_len = add_tlv("10-3",1,temp_buf,0x00,&asn_buf);
	}
	else
		return RER;
	tag1 = 4;
	if (flag & 0x08)	// absent subscriber diagnostic sm
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&ptr->abssubdiagsm,0x80,&asn_buf);
	}
	if (flag & 0x10)	// gprs support indicator
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_null(tlv1,0x80,&asn_buf);
	}
	if (flag & 0x20)	// delivery outcome indicator
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_null(tlv1,0x80,&asn_buf);
	}
	if (flag & 0x40)	// additional sm delivery outcome
	{
		sprintf(tlv1,"4-%d",tag1++);
		temp_buf[0] = ptr->addsm_deliout;
		buf_len = add_tlv(tlv1,1,temp_buf,0x80,&asn_buf);
	}
	if (flag & 0x80)	// additional absent subscriber diagnostic sm
	{
		sprintf(tlv1,"5-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&ptr->add_abssubdiagsm,0x80,&asn_buf);
	}
	return buf_len;	
}

int extract_repsmdelstatarg(struct MapRSMDS_Arg *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	u8		tag1;
	char		tlv1[32];

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_repsmdelstatarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("4-1",temp_buf,&asn_buf)) > 0)//msisdn
	{
		ptr->param_flag |= 0x01;
		ptr->msisdn[0] = len;
		memcpy(ptr->msisdn+1,temp_buf,len);
	}
	else
		return RER;
	if((len=get_tlv("4-2",temp_buf,&asn_buf)) > 0)//sc_add
	{
		ptr->param_flag |= 0x02;
		ptr->sc_add[0] = len;
		memcpy(ptr->sc_add+1,temp_buf,len);
	}
	else
		return RER;
	if(get_tlv("10",temp_buf,&asn_buf) > 0)	//sm_deliout
	{
		ptr->param_flag |= 0x04;
		ptr->sm_deliout = temp_buf[0];
	}
	else
		return RER;
	tag1 = 4;
	if (get_tlv("0",temp_buf,&asn_buf) == 1)	// absent subscriber diagnostic sm
	{
		ptr->param_flag |= 0x08;
		ptr->abssubdiagsm = temp_buf[0];
		tag1 ++;
	}
	if (get_tlv("2",temp_buf,&asn_buf) != -1)	// gprs support indicator
	{
		ptr->param_flag |= 0x10;
		ptr->gprssup_flag = 1;
		tag1 ++;
	}
	if (get_tlv("3",temp_buf,&asn_buf) != -1)	// delivery outcome indicator
	{
		ptr->param_flag |= 0x20;
		ptr->deliout_flag = 1;
		tag1 ++;
	}
	sprintf(tlv1,"4-%d",tag1);
	if (get_tlv(tlv1,temp_buf,&asn_buf) != -1)	// additional sm delivery outcome
	{
		ptr->param_flag |= 0x40;
		ptr->addsm_deliout = temp_buf[0];
	}
	if (get_tlv("5",temp_buf,&asn_buf) != -1)	// additional absent subscriber diagnostic sm
	{
		ptr->param_flag |= 0x80;
		ptr->add_abssubdiagsm = temp_buf[0];
	}
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding report SM Delivery Status response	*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_repsmdelstatres(struct MapRSMDS_Res *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	
	asn_encode(buf,&asn_buf);
	if (ptr->param_flag & 0x01)	//stored_msisdn
		buf_len = add_tlv("4",ptr->stored_msisdn[0],ptr->stored_msisdn+1,0x00,&asn_buf);			
	return buf_len;	
}

int extract_repsmdelstatres(struct MapRSMDS_Res *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;
	
	ptr->param_flag = 0;
	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("4",temp_buf,&asn_buf)) > 0)//stored_msisdn
	{
		ptr->param_flag |= 0x01;
		ptr->stored_msisdn[0] = len;
		memcpy(ptr->stored_msisdn+1,temp_buf,len);
	}					
	return ROK;		
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding inform service Center argument	*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_infsrvcentarg(struct MapISC_Arg *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			len;
	u8			temp_buf[16],temp_data[16];
	
	asn_encode(buf,&asn_buf);
	if (ptr->param_flag & 0x01)	//stored_msisdn
		buf_len = add_tlv("4-1",ptr->stored_msisdn[0],ptr->stored_msisdn+1,0x00,&asn_buf);
	if (ptr->param_flag & 0x02)	//mw_status
	{
		temp_data[0] = ptr->mw_status;
		len = bytestrtobitstr(temp_buf,temp_data,6);
		buf_len = add_tlv("3-2",len,temp_buf,0x00,&asn_buf);
	}
	return buf_len;
}

int extract_infsrvcentarg(struct MapISC_Arg *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256],temp_data[256];
	int 	len;
	
	ptr->param_flag = 0;
	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if((len=get_tlv("4",temp_buf,&asn_buf)) > 0)//stored_msisdn
	{
		ptr->param_flag |= 0x01;
		ptr->stored_msisdn[0] = len;
		memcpy(ptr->stored_msisdn+1,temp_buf,len);
	}
	if ((len = get_tlv("3",temp_buf,&asn_buf)) > 0)//mw_status
	{
		ptr->param_flag |= 0x02;
		bitstrtobytestr(temp_data,temp_buf,len);
		ptr->mw_status = temp_data[0];
	}
	return ROK;
}

/*	++++++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding alert service Center argument		*/
/*  ++++++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_altsrvcentarg(struct MapASC_Arg *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	
	asn_encode(buf,&asn_buf);
	if (ptr->param_flag & 0x01)		//msisdn
		buf_len = add_tlv("4-1",ptr->msisdn[0],ptr->msisdn+1,0x00,&asn_buf);			
	else
		return RER;
	if (ptr->param_flag & 0x02)		//service center address
		buf_len = add_tlv("4-2",ptr->sc_add[0],ptr->sc_add+1,0x00,&asn_buf);			
	else
		return RER;
	return buf_len;	
}

int extract_altsrvcentarg(struct MapASC_Arg *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_altsrvcentarg buf_len=0");
		return RER;
	}
	if(asn_decode_v3(buf,buf_len,&decErr,&asn_buf)==-1)
		return RER;
	if((len=get_tlv("4-1",temp_buf,&asn_buf)) > 0)//msisdn
	{
		ptr->param_flag |= 0x01;
		ptr->msisdn[0] = len;
		memcpy(ptr->msisdn+1,temp_buf,len);
	}
	else
		return RER;
	if((len=get_tlv("4-2",temp_buf,&asn_buf)) > 0)//sc_add
	{
		ptr->param_flag |= 0x02;
		ptr->sc_add[0] = len;
		memcpy(ptr->sc_add+1,temp_buf,len);
	}
	else
		return RER;
	return ROK;
}

/*	+++++++++++++++++++++++++++++++++++++++		*/
/*	encoding/decoding ready For SM argument		*/
/*  +++++++++++++++++++++++++++++++++++++++		*/
int assign_rdyforsmarg(struct MapRFSM_Arg *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	u8			temp_buf[256];
	
	flag = ptr->param_flag;
	asn_encode(buf,&asn_buf);
	if (flag & 0x01)	//imsi
		buf_len = add_tlv("0",IMSI_LEN,ptr->imsi,0x80,&asn_buf);
	else
		return RER;
	if (flag & 0x02)	//alert_reason
	{
		temp_buf[0] = ptr->alert_reason;
		buf_len = add_tlv("10",1,temp_buf,0x00,&asn_buf);
	}
	else
		return RER;
	if (flag & 0x04)	// alert reason indicator
		buf_len = add_null("5",0x00,&asn_buf);
	return buf_len;	
}

int extract_rdyforsmarg(struct MapRFSM_Arg *ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	u8		temp_buf[256];
	int 	len;

	ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("MAPP--extract_rdyforsmarg buf_len=0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);
	if(len==IMSI_LEN && (temp_buf[IMSI_LEN-1]&0xf0) == 0xf0)//imsi
	{
		ptr->param_flag |= 0x01;
		memcpy(ptr->imsi,temp_buf,len);
	}
	else
		return RER;
	if((len=get_tlv("10",temp_buf,&asn_buf)) >0)//alert_reason
	{
		ptr->param_flag |= 0x02;
		ptr->alert_reason = temp_buf[0];
	}
	else
		return RER;
	if (get_tlv("5",temp_buf,&asn_buf) != -1)	// alert reason indicator
	{
		ptr->param_flag |= 0x04;
		ptr->altreason_flag = 1;
	}
	return ROK;
}

/*	+++++++++++++++++++++++++++++++++++++++		*/
/*	encoding/decoding ready For SM response		*/
/*  +++++++++++++++++++++++++++++++++++++++		*/
int assign_rdyforsmres(struct MapRFSM_Res *ptr,u8 *buf)
{
	return 0;
}

int extract_rdyforsmres(struct MapRFSM_Res *ptr,u32 buf_len,u8 *buf)
{
	return ROK;
}
