/*	MAP Update Location c file			*/
/*	written by Liu zhiguo 2003-03-04	*/
/*	version 2.0							*/
/*	--------------------------------	*/

#include "map_includes.h"
#include "../xap_interfunc.h"
#include "map_code.h"
#include "map_opr_func.h"

int	build_mapparam(struct MapOprSrv_struct *opr_ptr,u8 *buf) // build map service paramter
{
	ASN_BUF	asn_buf;
	u8	 	seq_flag=1;
	int		param_len = 0;
	u8		info_str[1024];

	if (opr_ptr == NULL || buf == NULL) 
		return RER;
	switch (opr_ptr->message_type)
	{
/*	MAP V1--lw add */
/* daniel */
		/*
		case SendParam://sendParameters
			if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_sendParameterres(&opr_ptr->msg_list.sp_res,buf);
			break;
		*/
/* daniel */
		case SendParam	:// send parameters
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 0;	
				param_len = assign_SendParaArg(&opr_ptr->msg_list.sp_arg,buf);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_SendParaRes(&opr_ptr->msg_list.sp_res,buf);
			}
			break;
		case NoteSubPrnt :// not subscriber present
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 0; 
				param_len = assign_NotPresentArg(&opr_ptr->msg_list.np_arg,buf);
			}
			break;
		case ProcUnstrctSSData:// process unstructure SS data
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 0;
				param_len = assign_ProcessUSSDArg(&opr_ptr->msg_list.pussd_arg,buf);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_ProcessUSSDRes(&opr_ptr->msg_list.pussd_res,buf);
			}
			break;
		case BeginSubAct:// beging subscriber activity
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 1;
				param_len = assign_BSAArg(&opr_ptr->msg_list.bsa_arg,buf);
			}
			break;
		case PerformHo	:// perform handover
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 1;
				param_len = assign_HOArg(&opr_ptr->msg_list.ho_arg,buf);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 1;
				param_len = assign_HORes(&opr_ptr->msg_list.ho_res,buf);
			}
			break;
		case PerformSubsHo:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag =1;
				param_len = assign_PFSHOArg(&opr_ptr->msg_list.pfsho_arg,buf);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 1;
				param_len = assign_PFSHORes(&opr_ptr->msg_list.pfsho_res,buf);
			}
			break;
		case NoteInterHo:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 1;
				param_len = assign_NIHOArg(&opr_ptr->msg_list.niho_arg,buf);
			}
			break;
		case TraceSubAct:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 1;
				param_len = assign_TSAArg(&opr_ptr->msg_list.tsa_arg,buf);
			}
			break;
		case AlrtSCWithoutRes:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_altsrvcentarg(&opr_ptr->msg_list.asc_arg,buf);
			break;
		/*
		case BeginSubAct:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 1;
				return assign_BSAArg(&opr_ptr->msg_list.bsa_arg,buf);
			}
			break;
		*/
		case FwdSM   :
		//case MOFwdSM :
		//case MTFwdSM :
			/*
			if( opr_ptr->version == 1)
			{
				if (opr_ptr->message_flag == MAP_REQUEST)
				{
					seq_flag = 1;
					param_len = assign_fwdsmarg(&opr_ptr->msg_list.fsm_arg,buf);
				}
			} 
			else
			*/
			if (opr_ptr->message_flag == MAP_REQUEST)
					param_len = assign_mofwdsmarg(&opr_ptr->msg_list.mofsm_arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
					param_len = assign_mofwdsmres(&opr_ptr->msg_list.mofsm_res,buf,opr_ptr->version);
					if(opr_ptr->version<3)
						seq_flag = 0;
			}
			break;  
		case MTFwdSM_v3:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_mtfwdsmarg(&opr_ptr->msg_list.mtfsm_arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				param_len = assign_mtfwdsmres(&opr_ptr->msg_list.mtfsm_res,buf,opr_ptr->version);
				if(param_len <=0)
				{
					seq_flag = 0; 
					/* older version mo fwd doesn't take any parameter */
				}
			}
			break;	
/*	MAP V1--lw add */
		// mobile service operation
		case UpLoc:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				param_len = assign_uplocarg(&opr_ptr->msg_list.ul_arg,buf,opr_ptr->version);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				param_len = assign_uplocres(&opr_ptr->msg_list.ul_res,buf);
			} 
			break;
		case CancelLoc:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				param_len = assign_cancellocarg(&opr_ptr->msg_list.cl_arg,buf,opr_ptr->version);
				if(opr_ptr->version != 3)
					seq_flag = 0;
				else
					seq_flag = 2;
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE && opr_ptr->version == 3)
				param_len = assign_cancellocres(&opr_ptr->msg_list.cl_res,buf);
			break;
		case PurgeMS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_purgemsarg(&opr_ptr->msg_list.pms_arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_purgemsres(&opr_ptr->msg_list.pms_res,buf);
			break;
		case SndIdent:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				seq_flag = 0;
				param_len = assign_sndidentarg(&opr_ptr->msg_list.si_arg,buf);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_sndidentres(&opr_ptr->msg_list.si_res,buf);
			break;
		case UpGprsLoc:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_upgprslocarg(&opr_ptr->msg_list.ugl_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_upgprslocres(&opr_ptr->msg_list.ugl_res,buf);
			break;
		case ProvSubInfo:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_prvsubinfoarg(&opr_ptr->msg_list.psi_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_prvsubinfores(&opr_ptr->msg_list.psi_res,buf);
			break;
		case AnyTimeInter:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_anytimeintarg(&opr_ptr->msg_list.ati_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_anytimeintres(&opr_ptr->msg_list.ati_res,buf);
			break;
		case AnyTimeSubInter:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_anytimesubintarg(&opr_ptr->msg_list.atsi_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_anytimesubintres(&opr_ptr->msg_list.atsi_res,buf);
			break;			
		case PreHo:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_prehoarg(&opr_ptr->msg_list.pho_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_prehores(&opr_ptr->msg_list.pho_res,buf);
			break;
		case SndEndSig:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_sndendsigarg(&opr_ptr->msg_list.ses_arg,buf);
			break;
		case ProcAccSig:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_prcaccsigarg(&opr_ptr->msg_list.pas_arg,buf);
			break;
		case FwdAccSig:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_fwdaccsigarg(&opr_ptr->msg_list.fas_arg,buf);
			break;
		case PreSubsHo:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_presubshoarg(&opr_ptr->msg_list.psho_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_presubshores(&opr_ptr->msg_list.psho_res,buf);
			break;
		case SndAuthInfo:		//modify by gxchen
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				if(opr_ptr->version < 3)
					seq_flag = 0;
				param_len = assign_sndauthinfoarg(&opr_ptr->msg_list.sai_arg,buf,opr_ptr->version);
			}
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				param_len = assign_sndauthinfores(&opr_ptr->msg_list.sai_res,buf,opr_ptr->version);
				if(opr_ptr->version == 3)
					seq_flag = 2;
			}
			break;
		case AuthFailReport:	//add by gxchen
			if(opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_authfailreportarg(&opr_ptr->msg_list.authfr_arg, buf);
//			else if(opr_ptr->message_flag == MAP_RESPONSE)
//				param_len = assign_authfailreportres(&opr_ptr->msg_list.authfr_res, buf);
			break;
		case ChkIMEI:
			seq_flag = 0;
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_chkimeiarg(&opr_ptr->msg_list.cimei_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_chkimeires(&opr_ptr->msg_list.cimei_res,buf);
			break;
		case InsSubData:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_inssubdataarg(&opr_ptr->msg_list.isd_arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_inssubdatares(&opr_ptr->msg_list.isd_res,buf);
			break;
		case DelSubData:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_delsubdataarg(&opr_ptr->msg_list.dsd_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_delsubdatares(&opr_ptr->msg_list.dsd_res,buf);
			break;	
		case Reset:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_resetarg(&opr_ptr->msg_list.reset_arg,buf);
			break;			
		case RestoreData:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_restdataarg(&opr_ptr->msg_list.rd_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_restdatares(&opr_ptr->msg_list.rd_res,buf);
			break;
		case SndRoutInfoForGprs:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_sndroutinfogprsarg(&opr_ptr->msg_list.srifg_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_sndroutinfogprsres(&opr_ptr->msg_list.srifg_res,buf);
			break;
		case FailRep:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_failreportarg(&opr_ptr->msg_list.fr_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_failreportres(&opr_ptr->msg_list.fr_res,buf);
			break;
		case NoteMsPresForGprs:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_notemspregprsarg(&opr_ptr->msg_list.nmpfg_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_notemspregprsres(&opr_ptr->msg_list.nmpfg_res,buf);
			break;
		// operation and maintenance operations
		case ActvTraceMode:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_acttrcmodearg(&opr_ptr->msg_list.atm_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_acttrcmoderes(&opr_ptr->msg_list.atm_res,buf);
			break;
		case DeactvTraceMode:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_deacttrcmodearg(&opr_ptr->msg_list.dtm_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_deacttrcmoderes(&opr_ptr->msg_list.dtm_res,buf);
			break;
		case SndIMSI:
			seq_flag = 0;
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_sndimsiarg(&opr_ptr->msg_list.simsi_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_sndimsires(&opr_ptr->msg_list.simsi_res,buf);
			break;
		// call handling operation
		case SndRoutInfo:			
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_sndroutinfoarg(&opr_ptr->msg_list.sri_arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				param_len = assign_sndroutinfores(&opr_ptr->msg_list.sri_res,buf,opr_ptr->version);
				if(opr_ptr->version == 3)
					seq_flag = 2;
			}
			break;
		case ProvRoamNum:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_provroamnumarg(&opr_ptr->msg_list.prn_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_provroamnumres(&opr_ptr->msg_list.prn_res,buf);
			break;
		case ResumeCH:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_rescallhandarg(&opr_ptr->msg_list.rch_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_rescallhandres(&opr_ptr->msg_list.rch_res,buf);
			break;
		case ProvSIWFSNum:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_prvsiwfsnumarg(&opr_ptr->msg_list.psn_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_prvsiwfsnumres(&opr_ptr->msg_list.psn_res,buf);
			break;
		case SIWFSSigMdf:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_siwfssigmodarg(&opr_ptr->msg_list.ssm_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_siwfssigmodres(&opr_ptr->msg_list.ssm_res,buf);
			break;
		case SetRepState:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_setrepstatearg(&opr_ptr->msg_list.srs_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_setrepstateres(&opr_ptr->msg_list.srs_res,buf);
			break;
		case StatusRep:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_statreparg(&opr_ptr->msg_list.sr_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_statrepres(&opr_ptr->msg_list.sr_res,buf);
			break;
		case RmtUserFree:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_rmtuserfreearg(&opr_ptr->msg_list.ruf_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_rmtuserfreeres(&opr_ptr->msg_list.ruf_res,buf);
			break;
		case IstAlert:		//ist-Alert		umts		add by gxchen
			if(opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_istalertarg(&opr_ptr->msg_list.istalt_arg, buf);
			else if(opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_istalertres(&opr_ptr->msg_list.istalt_res, buf);
			break;
		case IstCommand:	//ist-Command		umts		add by gxchen
			if(opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_istcmdarg(&opr_ptr->msg_list.istcmd_arg, buf);
//			else if(opr_ptr->message_flag == MAP_RESPONSE)
//				param_len = assign_istcmdres(&opr_ptr->msg_list.istcmd_res, buf);
			break;
		// supplementary service operation
		case RegSS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_regssarg(&opr_ptr->msg_list.rss_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_regssres(&opr_ptr->msg_list.rss_res,buf);
			}	
			break;
		case EraseSS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_erassarg(&opr_ptr->msg_list.ess_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_erassres(&opr_ptr->msg_list.ess_res,buf);
			}
			break;
		case ActvSS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_actssarg(&opr_ptr->msg_list.ass_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_actssres(&opr_ptr->msg_list.ass_res,buf);
			}	
			break;
		case DeactvSS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_deactssarg(&opr_ptr->msg_list.dass_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag=0;
				param_len = assign_deactssres(&opr_ptr->msg_list.dass_res,buf);
			}	
			break;
		case InterSS:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_intrssarg(&opr_ptr->msg_list.intss_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
				seq_flag = 0;
				param_len = assign_intrssres(&opr_ptr->msg_list.intss_res,buf);
			}
			break;
		case ProcUnstrctSSReq:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_prcunssreqarg(&opr_ptr->msg_list.pussr_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_prcunssreqres(&opr_ptr->msg_list.pussr_res,buf);
			break;
		case UnstrctSSReq:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_unssreqarg(&opr_ptr->msg_list.ussr_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_unssreqres(&opr_ptr->msg_list.ussr_res,buf);
			break;
		case UnstrctSSNoti:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_unssnotarg(&opr_ptr->msg_list.ussn_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
			{
			    param_len = assign_unssnotres(&opr_ptr->msg_list.ussn_res,buf);
			    seq_flag=0;
			}
			break;
		case RegPasswd:
			seq_flag=0;
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_regpswdarg(&opr_ptr->msg_list.rpss_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_regpswdres(&opr_ptr->msg_list.rpss_res,buf);
			break;	
		case GetPasswd:
			seq_flag=0;
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_getpswdarg(&opr_ptr->msg_list.gpss_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_getpswdres(&opr_ptr->msg_list.gpss_res,buf);
			break;
		case SSInvNoti:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_ssinvnotarg(&opr_ptr->msg_list.ssin_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_ssinvnotres(&opr_ptr->msg_list.ssin_res,buf);
			break;
		case RegCCEntry:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_regccentarg(&opr_ptr->msg_list.rcce_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_regccentres(&opr_ptr->msg_list.rcce_res,buf);
			break;
		case EraseCCEntry:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_eraseccentarg(&opr_ptr->msg_list.ecce_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_eraseccentres(&opr_ptr->msg_list.ecce_res,buf);
			break;
		// short message service operation
		case SndRoutInfoForSM:
			if( opr_ptr->version == 1 )
			{
				if (opr_ptr->message_flag == MAP_REQUEST)
					param_len = assign_routinfoforsm_v1_arg(&opr_ptr->msg_list.rifsm_v1_arg,buf);
				else if (opr_ptr->message_flag == MAP_RESPONSE)
					param_len = assign_routinfoforsm_v1_res(&opr_ptr->msg_list.rifsm_v1_res,buf);
			}
			else
			{
				if (opr_ptr->message_flag == MAP_REQUEST)
					param_len = assign_routinfoforsmarg(&opr_ptr->msg_list.rifsm_arg,buf);
				else if (opr_ptr->message_flag == MAP_RESPONSE)
					param_len = assign_routinfoforsmres(&opr_ptr->msg_list.rifsm_res,buf);
			}
			break;		
		case RptSMDelvStat:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_repsmdelstatarg(&opr_ptr->msg_list.rsmds_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_repsmdelstatres(&opr_ptr->msg_list.rsmds_res,buf);
			break;
		case AlrtSC:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_altsrvcentarg(&opr_ptr->msg_list.asc_arg,buf);
			break;																																													
		case InfSC:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_infsrvcentarg(&opr_ptr->msg_list.isc_arg,buf);
			break;
		case RdyForSM:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_rdyforsmarg(&opr_ptr->msg_list.rfsm_arg,buf);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_rdyforsmres(&opr_ptr->msg_list.rfsm_res,buf);
			break;	
		/*MAP-H (AUC and HLR) */
		case SecuTrip:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_securityTriplets_arg(&opr_ptr->msg_list.st_arg,buf, opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_securityTriplets_res(&opr_ptr->msg_list.st_res,buf);
			break;			
		case InterrSubs:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_interrogateSubscriber_arg(&opr_ptr->msg_list.is_arg,buf);
			break;
		case CreateSubs:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_createSubscriber_arg(&opr_ptr->msg_list.cs_arg,buf);
			break;
		case DelSubs:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_deleteSubscriber_arg(&opr_ptr->msg_list.ds_arg,buf);
			break;
				/**********	map opr	**********/ 
		case DetermineOprUser:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_MapDetermineOprUserArg(&opr_ptr->msg_list.DetermineOprUser_Arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_MapDetermineOprUserRes(&opr_ptr->msg_list.DetermineOprUser_Res,buf,opr_ptr->version);
		break;		
		case VlrUpdateLocation:							
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_MapVlrUpdateLocationArg(&opr_ptr->msg_list.VlrUpdateLocation_Arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_MapVlrUpdateLocationRes(&opr_ptr->msg_list.VlrUpdateLocation_Res,buf,opr_ptr->version);
		break;
		case CreateUserWithMsisdnImsi:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len =  assign_MapCreateUserWithMsisdnImsiArg(&opr_ptr->msg_list.CreateUserWithMsisdnImsi_Arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_MapCreateUserWithMsisdnImsiRes(&opr_ptr->msg_list.CreateUserWithMsisdnImsi_Res,buf,opr_ptr->version);
		break;		
		case DeleteOprUser:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_MapDeleteOprUserArg(&opr_ptr->msg_list.DeleteOprUser_Arg,buf,opr_ptr->version);
			else if (opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_MapDeleteOprUserRes(&opr_ptr->msg_list.DeleteOprUser_Res,buf,opr_ptr->version);
		break;		
		case VlrEnquiryIMDMStatus:
			if (opr_ptr->message_flag == MAP_REQUEST)
				param_len = assign_MapVlrEnquiryIMDM_Arg(&opr_ptr->msg_list.EnquiryIMDM_Arg,buf,opr_ptr->version);
			else if(opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_MapVlrEnquiryIMDM_Res(&opr_ptr->msg_list.EnquiryIMDM_Res,buf,opr_ptr->version);
		break;
		case RoutingInfoForLCS:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				xap_send_error("RoutingInfoForLCS Arg is not support to assign");
				return RER;
			}
			else if(opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_RoutingInfoForLCS_Res(&opr_ptr->msg_list.routingInfoForLCS_Res,buf,opr_ptr->version);
		break;
		case ProvideSubscriberLocation:
			if (opr_ptr->message_flag == MAP_REQUEST)
			{
				xap_send_error("ProvideSubscriberLocation Arg is not support to assign");
				return RER;
			}
			else if(opr_ptr->message_flag == MAP_RESPONSE)
				param_len = assign_ProvideSubscriberLocation_Res(&opr_ptr->msg_list.provideSubscriberLocation_Res,buf,opr_ptr->version);
		break;
		/*********	map opr	**********/ 
		default:	// unknown operation
			xap_send_error("MAPP error:the operation is unknown:%d",opr_ptr->message_type);
			return RER;
	}

//	if(param_len <= 0)
	if(param_len < 0)
		return 0;

	switch(seq_flag)
	{
	case 0:
		break;
	case 1:		
		memcpy(info_str,buf,param_len%1024);
		asn_encode(buf,&asn_buf);
		param_len = add_tlv("16",param_len,info_str,0x20,&asn_buf);
		break;
	case 2:
		memcpy(info_str,buf,param_len%1024);
		asn_encode(buf,&asn_buf); 
		param_len = add_tlv("3",param_len,info_str,0xA0,&asn_buf);
		break;
	}
    //Bcd2Str_Space(info_str, buf, param_len); 
	  //printf("\r\nassign code :[%d] len :[%d]\r\n%s\r\n",opr_ptr->message_type,param_len,info_str);
	return param_len;
}

u8 extract_mapparam(struct MapOprSrv_struct *opr_ptr,u8 opr_code,u8 opr_flag,u32 pre_param_len,u8 *pre_param)
{
	ASN_BUF		asn_buf;
	u8			param[1024];
	int			param_len;
	//char		info_str[1024];

	asn_decode(pre_param,1,&asn_buf);
	//Bcd2Str_Space(info_str, pre_param, pre_param_len); 
	//printf("\r\nextract code :[%d] len :[%ld]\r\n%s\r\n",opr_code,pre_param_len,info_str);
	if(opr_ptr->version == 3 && (  
		(opr_code == SndRoutInfo && opr_flag == MAP_CONFIRM) || 
		(opr_code == SndAuthInfo && opr_flag == MAP_CONFIRM) || 
		(opr_code == CancelLoc && opr_flag == MAP_INDICATE) || 
		(opr_code == PurgeMS && opr_flag == MAP_INDICATE)))
	{
		param_len = get_tlv("3",param,&asn_buf);
	}
	else if( !( opr_code == SendParam  && opr_flag == MAP_CONFIRM ))
	{
		param_len = get_tlv("16",param,&asn_buf);
	}
	if (param_len == -1 || (opr_code == SendParam  && opr_flag == MAP_CONFIRM) )	// not has sequence id
	{
		param_len = pre_param_len;
		memcpy(param,pre_param,param_len);		
	}

	switch (opr_code)
	{
/* ------------->>>>>>>>>>>>>. MAP V1 <<<<<<<<<<<<<<<<<--------------------*/
/* daniel */
		/*
		case SendParam:
			if (opr_flag == MAP_INDICATE)
				return extract_sendParameterArg(&opr_ptr->msg_list.sp_arg,param_len,param,opr_ptr->dialogue_id);
			break;
		*/
/* daniel */
		case SendParam	:// send parameters
			if (opr_flag == MAP_INDICATE)
				return extract_SendParaArg(&opr_ptr->msg_list.sp_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_SendParaRes(&opr_ptr->msg_list.sp_res,param_len,param);
			break;
		case NoteSubPrnt :// not subscriber present
			if (opr_flag == MAP_INDICATE)
				return extract_NotPresentArg(&opr_ptr->msg_list.np_arg,param_len,param);
			break;
		case ProcUnstrctSSData:// process unstructure SS data
			if (opr_flag == MAP_INDICATE)
				return extract_ProcessUSSDArg(&opr_ptr->msg_list.pussd_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_ProcessUSSDRes(&opr_ptr->msg_list.pussd_res,param_len,param);
			break;
		case BeginSubAct:// beging subscriber activity
			if (opr_flag == MAP_INDICATE)
				return extract_BSAArg(&opr_ptr->msg_list.bsa_arg,param_len,param);
			break;
		case PerformHo	:// perform handover
			if (opr_flag == MAP_INDICATE)
				return extract_HOArg(&opr_ptr->msg_list.ho_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_HORes(&opr_ptr->msg_list.ho_res,param_len,param);
			break;
		case PerformSubsHo:
			if (opr_flag == MAP_INDICATE)
				return extract_PFSHOArg(&opr_ptr->msg_list.pfsho_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_PFSHORes(&opr_ptr->msg_list.pfsho_res,param_len,param);
			break;
		case NoteInterHo:
			if (opr_flag == MAP_INDICATE)
				return extract_NIHOArg(&opr_ptr->msg_list.niho_arg,param_len,param);
			break;
		case TraceSubAct:
			if (opr_flag == MAP_INDICATE)
				return extract_TSAArg(&opr_ptr->msg_list.tsa_arg,param_len,param);
			break;
		case AlrtSCWithoutRes:
			if (opr_flag == MAP_INDICATE)
				return extract_altsrvcentarg(&opr_ptr->msg_list.asc_arg,param_len,param);
			break;
		/*
		case BeginSubAct:
			if (opr_flag == MAP_INDICATE)
				return extract_BSAArg(&opr_ptr->msg_list.bsa_arg,param_len,param);
			break;
		*/
/* ------------->>>>>>>>>>>>>. MAP V1 <<<<<<<<<<<<<<<<<--------------------*/
		case UpLoc:
			if (opr_flag == MAP_INDICATE)
				return extract_uplocarg(&opr_ptr->msg_list.ul_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_uplocres(&opr_ptr->msg_list.ul_res,param_len,param);
			break;
		case CancelLoc:
			if (opr_flag == MAP_INDICATE)
				return extract_cancellocarg(&opr_ptr->msg_list.cl_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_cancellocres(&opr_ptr->msg_list.cl_res,param_len,param);
			break;
		case PurgeMS:
			if (opr_flag == MAP_INDICATE)
				return extract_purgemsarg(&opr_ptr->msg_list.pms_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_purgemsres(&opr_ptr->msg_list.pms_res,param_len,param);
			break;
		case SndIdent:
			if (opr_flag == MAP_INDICATE)
				return extract_sndidentarg(&opr_ptr->msg_list.si_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_sndidentres(&opr_ptr->msg_list.si_res,param_len,param);
			break;
		case UpGprsLoc:
			if (opr_flag == MAP_INDICATE)
				return extract_upgprslocarg(&opr_ptr->msg_list.ugl_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_upgprslocres(&opr_ptr->msg_list.ugl_res,param_len,param);
			break;
		case ProvSubInfo:
			if (opr_flag == MAP_INDICATE)
				return extract_prvsubinfoarg(&opr_ptr->msg_list.psi_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_prvsubinfores(&opr_ptr->msg_list.psi_res,param_len,param);
			break;
		case AnyTimeInter:
			if (opr_flag == MAP_INDICATE)
				return extract_anytimeintarg(&opr_ptr->msg_list.ati_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_anytimeintres(&opr_ptr->msg_list.ati_res,param_len,param);
			break;
		case AnyTimeSubInter:
			if (opr_flag == MAP_INDICATE)
				return extract_anytimesubintarg(&opr_ptr->msg_list.atsi_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_anytimesubintres(&opr_ptr->msg_list.atsi_res,param_len,param);
			break;			
		case PreHo:
			if (opr_flag == MAP_INDICATE)
				return extract_prehoarg(&opr_ptr->msg_list.pho_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_prehores(&opr_ptr->msg_list.pho_res,param_len,param);
			break;
		case SndEndSig:
			if (opr_flag == MAP_INDICATE)
				return extract_sndendsigarg(&opr_ptr->msg_list.ses_arg,param_len,param);
			break;
		case ProcAccSig:
			if (opr_flag == MAP_INDICATE)
				return extract_prcaccsigarg(&opr_ptr->msg_list.pas_arg,param_len,param);
			break;
		case FwdAccSig:
			if (opr_flag == MAP_INDICATE)
				return extract_fwdaccsigarg(&opr_ptr->msg_list.fas_arg,param_len,param);
			break;
		case PreSubsHo:
			if (opr_flag == MAP_INDICATE)
				return extract_presubshoarg(&opr_ptr->msg_list.psho_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_presubshores(&opr_ptr->msg_list.psho_res,param_len,param);
			break;
		case SndAuthInfo:		//modify by gxchen
			if (opr_flag == MAP_INDICATE)
				return extract_sndauthinfoarg(&opr_ptr->msg_list.sai_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_sndauthinfores(&opr_ptr->msg_list.sai_res,param_len,param,opr_ptr->version);
			break;
		case AuthFailReport:	//add by gxchen
			if(opr_flag == MAP_INDICATE)
				return extract_authfailreportarg(&opr_ptr->msg_list.authfr_arg, param_len, param);
//			else if(opr_flag == MAP_CONFIRM)
//				return extract_authfailreportres(&opr_ptr->msg_list.authfr_res, param_len, param);
			break;
		case ChkIMEI:
			if (opr_flag == MAP_INDICATE)
				return extract_chkimeiarg(&opr_ptr->msg_list.cimei_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_chkimeires(&opr_ptr->msg_list.cimei_res,param_len,param);
			break;
		case InsSubData:
			if (opr_flag == MAP_INDICATE)
				return extract_inssubdataarg(&opr_ptr->msg_list.isd_arg,param_len,param);
			if (opr_flag == MAP_CONFIRM)
				return extract_inssubdatares(&opr_ptr->msg_list.isd_res,param_len,param);
			break;
		case DelSubData:
			if (opr_flag == MAP_INDICATE)
				return extract_delsubdataarg(&opr_ptr->msg_list.dsd_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_delsubdatares(&opr_ptr->msg_list.dsd_res,param_len,param);
			break;
		case Reset:
			if (opr_flag == MAP_INDICATE)
				return extract_resetarg(&opr_ptr->msg_list.reset_arg,param_len,param);
			break;
		case RestoreData:
			if (opr_flag == MAP_INDICATE)
				return extract_restdataarg(&opr_ptr->msg_list.rd_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_restdatares(&opr_ptr->msg_list.rd_res,param_len,param);
			break;
		case SndRoutInfoForGprs:
			if (opr_flag == MAP_INDICATE)
				return extract_sndroutinfogprsarg(&opr_ptr->msg_list.srifg_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_sndroutinfogprsres(&opr_ptr->msg_list.srifg_res,param_len,param);
			break;
		case FailRep:
			if (opr_flag == MAP_INDICATE)
				return extract_failreportarg(&opr_ptr->msg_list.fr_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_failreportres(&opr_ptr->msg_list.fr_res,param_len,param);
			break;
		case NoteMsPresForGprs:
			if (opr_flag == MAP_INDICATE)
				return extract_notemspregprsarg(&opr_ptr->msg_list.nmpfg_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_notemspregprsres(&opr_ptr->msg_list.nmpfg_res,param_len,param);
			break;
		case ActvTraceMode:
			if (opr_flag == MAP_INDICATE)
				return extract_acttrcmodearg(&opr_ptr->msg_list.atm_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_acttrcmoderes(&opr_ptr->msg_list.atm_res,param_len,param);
			break;
		case DeactvTraceMode:
			if (opr_flag == MAP_INDICATE)
				return extract_deacttrcmodearg(&opr_ptr->msg_list.dtm_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_deacttrcmoderes(&opr_ptr->msg_list.dtm_res,param_len,param);
			break;
		case SndIMSI:
			if (opr_flag == MAP_INDICATE)
				return extract_sndimsiarg(&opr_ptr->msg_list.simsi_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_sndimsires(&opr_ptr->msg_list.simsi_res,param_len,param);
			break;
		case SndRoutInfo:
			if (opr_flag == MAP_INDICATE)
				return extract_sndroutinfoarg(&opr_ptr->msg_list.sri_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_sndroutinfores(&opr_ptr->msg_list.sri_res,param_len,param,opr_ptr->version);
			break;
		case ProvRoamNum:
			if (opr_flag == MAP_INDICATE)
				return extract_provroamnumarg(&opr_ptr->msg_list.prn_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_provroamnumres(&opr_ptr->msg_list.prn_res,param_len,param);
			break;
		case ResumeCH:
			if (opr_flag == MAP_INDICATE)
				return extract_rescallhandarg(&opr_ptr->msg_list.rch_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_rescallhandres(&opr_ptr->msg_list.rch_res,param_len,param);
			break;
		case ProvSIWFSNum:
			if (opr_flag == MAP_INDICATE)
				return extract_prvsiwfsnumarg(&opr_ptr->msg_list.psn_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_prvsiwfsnumres(&opr_ptr->msg_list.psn_res,param_len,param);
			break;
		case SIWFSSigMdf:
			if (opr_flag == MAP_INDICATE)
				return extract_siwfssigmodarg(&opr_ptr->msg_list.ssm_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_siwfssigmodres(&opr_ptr->msg_list.ssm_res,param_len,param);
			break;
		case SetRepState:
			if (opr_flag == MAP_INDICATE)
				return extract_setrepstatearg(&opr_ptr->msg_list.srs_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_setrepstateres(&opr_ptr->msg_list.srs_res,param_len,param);
			break;
		case StatusRep:
			if (opr_flag == MAP_INDICATE)
				return extract_statreparg(&opr_ptr->msg_list.sr_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_statrepres(&opr_ptr->msg_list.sr_res,param_len,param);
			break;
		case RmtUserFree:
			if (opr_flag == MAP_INDICATE)
				return extract_rmtuserfreearg(&opr_ptr->msg_list.ruf_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_rmtuserfreeres(&opr_ptr->msg_list.ruf_res,param_len,param);
			break;
		case IstAlert:		//ist-Alert		umts		add by gxchen
			if(opr_flag == MAP_INDICATE)
				return extract_istalertarg(&opr_ptr->msg_list.istalt_arg, param_len, param);
			else if(opr_flag == MAP_CONFIRM)
				return extract_istalertres(&opr_ptr->msg_list.istalt_res, param_len, param);
			break;
		case IstCommand:	//ist-Command		umts		add by gxchen
			if(opr_flag == MAP_INDICATE)
				return extract_istcmdarg(&opr_ptr->msg_list.istcmd_arg, param_len, param);
//			else if(opr_flag == MAP_CONFIRM)
//				return extract_istcmdres(&opr_ptr->msg_list.istcmd_res, param_len, param);
			break;
		case RegSS:
			if (opr_flag == MAP_INDICATE)
				return extract_regssarg(&opr_ptr->msg_list.rss_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_regssres(&opr_ptr->msg_list.rss_res,param_len,param);
			break;
		case EraseSS:
			if (opr_flag == MAP_INDICATE)
				return extract_erassarg(&opr_ptr->msg_list.ess_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_erassres(&opr_ptr->msg_list.ess_res,param_len,param);
			break;
		case ActvSS:
			if (opr_flag == MAP_INDICATE)
				return extract_actssarg(&opr_ptr->msg_list.ass_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_actssres(&opr_ptr->msg_list.ass_res,param_len,param);
			break;
		case DeactvSS:
			if (opr_flag == MAP_INDICATE)
				return extract_deactssarg(&opr_ptr->msg_list.dass_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_deactssres(&opr_ptr->msg_list.dass_res,param_len,param);
			break;
		case InterSS:
			if (opr_flag == MAP_INDICATE)
				return extract_intrssarg(&opr_ptr->msg_list.intss_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_intrssres(&opr_ptr->msg_list.intss_res,param_len,param);
			break;
		case ProcUnstrctSSReq:
			if (opr_flag == MAP_INDICATE)
				return extract_prcunssreqarg(&opr_ptr->msg_list.pussr_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_prcunssreqres(&opr_ptr->msg_list.pussr_res,param_len,param);
			break;
		case UnstrctSSReq:
			if (opr_flag == MAP_INDICATE)
				return extract_unssreqarg(&opr_ptr->msg_list.ussr_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_unssreqres(&opr_ptr->msg_list.ussr_res,param_len,param);
			break;
		case UnstrctSSNoti:
			if (opr_flag == MAP_INDICATE)
				return extract_unssnotarg(&opr_ptr->msg_list.ussn_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_unssnotres(&opr_ptr->msg_list.ussn_res,param_len,param);
			break;
		case RegPasswd:
			if (opr_flag == MAP_INDICATE)
				return extract_regpswdarg(&opr_ptr->msg_list.rpss_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_regpswdres(&opr_ptr->msg_list.rpss_res,param_len,param);
			break;
		case GetPasswd:
			if (opr_flag == MAP_INDICATE)
				return extract_getpswdarg(&opr_ptr->msg_list.gpss_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_getpswdres(&opr_ptr->msg_list.gpss_res,param_len,param);
			break;
		case SSInvNoti:
			if (opr_flag == MAP_INDICATE)
				return extract_ssinvnotarg(&opr_ptr->msg_list.ssin_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_ssinvnotres(&opr_ptr->msg_list.ssin_res,param_len,param);
			break;
		case RegCCEntry:
			if (opr_flag == MAP_INDICATE)
				return extract_regccentarg(&opr_ptr->msg_list.rcce_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_regccentres(&opr_ptr->msg_list.rcce_res,param_len,param);
			break;
		case EraseCCEntry:
			if (opr_flag == MAP_INDICATE)
				return extract_eraseccentarg(&opr_ptr->msg_list.ecce_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_eraseccentres(&opr_ptr->msg_list.ecce_res,param_len,param);
			break;
		case SndRoutInfoForSM:
			if( opr_ptr->version == 1)
			{
					if (opr_flag == MAP_INDICATE)
					return extract_routinfoforsm_v1_arg(&opr_ptr->msg_list.rifsm_v1_arg,param_len,param);
				else if (opr_flag == MAP_CONFIRM)
					return extract_routinfoforsm_v1_res(&opr_ptr->msg_list.rifsm_v1_res,param_len,param);
			}
			else
			{
				if (opr_flag == MAP_INDICATE)
					return extract_routinfoforsmarg(&opr_ptr->msg_list.rifsm_arg,param_len,param);
				else if (opr_flag == MAP_CONFIRM)
					return extract_routinfoforsmres(&opr_ptr->msg_list.rifsm_res,param_len,param);
			}
			break;
		case FwdSM:
		//case MOFwdSM:
		//case MTFwdSM:
			if (opr_flag == MAP_INDICATE)
					return extract_mofwdsmarg(&opr_ptr->msg_list.mofsm_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
			{
					if(opr_ptr->version<3)
						return ROK;
					return extract_mofwdsmres(&opr_ptr->msg_list.mofsm_res,param_len,param);
			}
			break;
		case MTFwdSM_v3:
			if (opr_flag == MAP_INDICATE)
				return extract_mtfwdsmarg(&opr_ptr->msg_list.mtfsm_arg,param_len,param,opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_mtfwdsmres(&opr_ptr->msg_list.mtfsm_res,param_len,param,opr_ptr->version);
			break;			
		case RptSMDelvStat:
			if (opr_flag == MAP_INDICATE)
				return extract_repsmdelstatarg(&opr_ptr->msg_list.rsmds_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_repsmdelstatres(&opr_ptr->msg_list.rsmds_res,param_len,param);
			break;
		case AlrtSC:
			if (opr_flag == MAP_INDICATE)
				return extract_altsrvcentarg(&opr_ptr->msg_list.asc_arg,param_len,param);
			break;
		case InfSC:
			if (opr_flag == MAP_INDICATE)
				return extract_infsrvcentarg(&opr_ptr->msg_list.isc_arg,param_len,param);
			break;
		case RdyForSM:
			if (opr_flag == MAP_INDICATE)
				return extract_rdyforsmarg(&opr_ptr->msg_list.rfsm_arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_rdyforsmres(&opr_ptr->msg_list.rfsm_res,param_len,param);
			break;	
		case SecuTrip:
			if (opr_flag == MAP_INDICATE)
				return extract_securityTriplets_arg(&opr_ptr->msg_list.st_arg,param_len,param, opr_ptr->version);
			else if (opr_flag == MAP_CONFIRM)
				return extract_securityTriplets_res(&opr_ptr->msg_list.st_res,param_len,param);
			break;	
		case InterrSubs:
			if (opr_flag == MAP_INDICATE)
				return extract_interrogateSubscriber_arg(&opr_ptr->msg_list.is_arg,param_len,param);
			break;
		case CreateSubs:
			if (opr_flag == MAP_INDICATE)
				return extract_createSubscriber_arg(&opr_ptr->msg_list.cs_arg,param_len,param);
			break;
		case DelSubs:
			if (opr_flag == MAP_INDICATE)
				return extract_deleteSubscriber_arg(&opr_ptr->msg_list.ds_arg,param_len,param);
			break;
		/****	map opr	**********/ 
		case DetermineOprUser:
			if (opr_flag == MAP_INDICATE)
				return extract_MapDetermineOprUserArg(&opr_ptr->msg_list.DetermineOprUser_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_MapDetermineOprUserRes(&opr_ptr->msg_list.DetermineOprUser_Res,param_len,param);
		break;		
		case VlrUpdateLocation:
			if (opr_flag == MAP_INDICATE)
				return extract_MapVlrUpdateLocationArg(&opr_ptr->msg_list.VlrUpdateLocation_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_MapVlrUpdateLocationRes(&opr_ptr->msg_list.VlrUpdateLocation_Res,param_len,param);
		break;
		case CreateUserWithMsisdnImsi:
			if (opr_flag == MAP_INDICATE)
				return extract_MapCreateUserWithMsisdnImsiArg(&opr_ptr->msg_list.CreateUserWithMsisdnImsi_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_MapCreateUserWithMsisdnImsiRes(&opr_ptr->msg_list.CreateUserWithMsisdnImsi_Res,param_len,param);
		break;		
		case DeleteOprUser:
			if (opr_flag == MAP_INDICATE)
				return extract_MapDeleteOprUserArg(&opr_ptr->msg_list.DeleteOprUser_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return extract_MapDeleteOprUserRes(&opr_ptr->msg_list.DeleteOprUser_Res,param_len,param);
		break;		
		case VlrEnquiryIMDMStatus:
			if  (opr_flag == MAP_INDICATE)
				return  extract_MapVlrEnquiryIMDM_Arg(&opr_ptr->msg_list.EnquiryIMDM_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
				return  extract_MapVlrEnquiryIMDM_Res(&opr_ptr->msg_list.EnquiryIMDM_Res,param_len,param);
		break;
		case RoutingInfoForLCS:
			if (opr_flag == MAP_INDICATE)
				return extract_RoutingInfoForLCS_Arg(&opr_ptr->msg_list.routingInfoForLCS_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
			{
				xap_send_error("RoutingInfoForLCS Res is not support to extract");
				return RER;
			}
		break;
		case ProvideSubscriberLocation:
			if (opr_flag == MAP_INDICATE)
				return extract_ProvideSubscriberLocation_Arg(&opr_ptr->msg_list.provideSubscriberLocation_Arg,param_len,param);
			else if (opr_flag == MAP_CONFIRM)
			{
				xap_send_error("ProvideSubscriberLocation Res is not support to extract");
				return RER;
			}
		break;
		/****	map opr	**********/ 
		default:
			xap_send_error("the operation is not support:%d",opr_code);
			return 0;
	}
	return 1;
}

/*	++++++++++++++++++++++++++++++++++++++++++	*/
/*	+++++		Common types  			+++++	*/
/*	++++++++++++++++++++++++++++++++++++++++++	*/
int assign_authset(struct AuthSet_struct *auth_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf,&asn_buf);
	if (auth_ptr->param_flag != 0x07)
		return RER;
	buf_len = add_tlv("4-1",RAND_LEN,auth_ptr->rand,0x00,&asn_buf);
	buf_len = add_tlv("4-2",SRES_LEN,auth_ptr->sres,0x00,&asn_buf);
	buf_len = add_tlv("4-3",KC_LEN,auth_ptr->kc,0x00,&asn_buf);
	return buf_len;
}

int extract_authset(struct AuthSet_struct *auth_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;	
	if (get_tlv("4-1",temp_buf,&asn_buf) == RAND_LEN)
		memcpy(auth_ptr->rand,temp_buf,RAND_LEN);
	else
		return RER;
	if(get_tlv("4-2",temp_buf,&asn_buf) == SRES_LEN)
		memcpy(auth_ptr->sres,temp_buf,SRES_LEN);
	else
		return RER;
	if(get_tlv("4-3",temp_buf,&asn_buf) == KC_LEN)
		memcpy(auth_ptr->kc,temp_buf,KC_LEN);
	else
		return RER;
	auth_ptr->param_flag = 0x07;
	return ROK;
}

//add by gxchen	start
int assign_triplet(Triplet_st *auth_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf,&asn_buf);
	if (auth_ptr->param_flag != 0x07)
		return RER;
	buf_len = add_tlv("4-1",RAND_LEN,auth_ptr->rand,0x00,&asn_buf);
	buf_len = add_tlv("4-2",SRES_LEN,auth_ptr->sres,0x00,&asn_buf);
	buf_len = add_tlv("4-3",KC_LEN,auth_ptr->kc,0x00,&asn_buf);
	return buf_len;
}

int extract_triplet(Triplet_st *auth_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;	
	if (get_tlv("4-1",temp_buf,&asn_buf) == RAND_LEN)
		memcpy(auth_ptr->rand,temp_buf,RAND_LEN);
	else
		return RER;
	if(get_tlv("4-2",temp_buf,&asn_buf) == SRES_LEN)
		memcpy(auth_ptr->sres,temp_buf,SRES_LEN);
	else
		return RER;
	if(get_tlv("4-3",temp_buf,&asn_buf) == KC_LEN)
		memcpy(auth_ptr->kc,temp_buf,KC_LEN);
	else
		return RER;
	auth_ptr->param_flag = 0x07;
	return ROK;
}

int assign_quintuplet(Quintuplet_st *auth_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf, &asn_buf);
	if (auth_ptr->param_flag != 0x1F)
		return RER;
	buf_len = add_tlv("4-1", RAND_LEN, auth_ptr->rand, 0x00, &asn_buf);
	buf_len = add_tlv("4-2", XRES_LEN, auth_ptr->xres, 0x00, &asn_buf);
	buf_len = add_tlv("4-3", CK_LEN, auth_ptr->ck, 0x00, &asn_buf);
	buf_len = add_tlv("4-4", IK_LEN, auth_ptr->ik, 0x00, &asn_buf);
	buf_len = add_tlv("4-5", AUTN_LEN, auth_ptr->autn, 0x00, &asn_buf);
	return buf_len;
}

int extract_quintuplet(Quintuplet_st *auth_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("4-1", temp_buf, &asn_buf) == RAND_LEN)
		memcpy(auth_ptr->rand, temp_buf, RAND_LEN);
	else
		return RER;
	if(get_tlv("4-2", temp_buf, &asn_buf) == XRES_LEN)
		memcpy(auth_ptr->xres, temp_buf, XRES_LEN);
	else
		return RER;
	if(get_tlv("4-3", temp_buf, &asn_buf) == CK_LEN)
		memcpy(auth_ptr->ck, temp_buf, CK_LEN);
	else
		return RER;
	if(get_tlv("4-4", temp_buf, &asn_buf) == IK_LEN)
		memcpy(auth_ptr->ik, temp_buf, IK_LEN);
	else
		return RER;
	if(get_tlv("4-5", temp_buf, &asn_buf) == AUTN_LEN)
		memcpy(auth_ptr->autn, temp_buf, AUTN_LEN);
	else
		return RER;
	auth_ptr->param_flag = 0x1F;
	return ROK;
}

int assign_gsmSecCon(GsmSecCon_st *con_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf, &asn_buf);
	if (con_ptr->param_flag != 0x03)
		return RER;
	buf_len = add_tlv("4-1", KC_LEN, con_ptr->kc, 0x00, &asn_buf);
	buf_len = add_tlv("4-2", 1, &con_ptr->cksn, 0x00, &asn_buf);
	return buf_len;
}

int extract_gsmSecCon(GsmSecCon_st *con_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("4-1", temp_buf, &asn_buf) == KC_LEN)
		memcpy(con_ptr->kc, temp_buf, KC_LEN);
	else
		return RER;
	if(get_tlv("4-2", temp_buf, &asn_buf) == 1)
		con_ptr->cksn = temp_buf[0];
	else
		return RER;
	con_ptr->param_flag = 0x03;
	return ROK;
}

int assign_umtsSecCon(UmtsSecCon_st *con_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf, &asn_buf);
	if (con_ptr->param_flag != 0x07)
		return RER;
	buf_len = add_tlv("4-1", CK_LEN, con_ptr->ck, 0x00, &asn_buf);
	buf_len = add_tlv("4-2", IK_LEN, con_ptr->ik, 0x00, &asn_buf);
	buf_len = add_tlv("4-3", 1, &con_ptr->ksi, 0x00, &asn_buf);
	return buf_len;
}

int extract_umtsSecCon(UmtsSecCon_st *con_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("4-1", temp_buf, &asn_buf) == CK_LEN)
		memcpy(con_ptr->ck, temp_buf, CK_LEN);
	else
		return RER;
	if (get_tlv("4-2", temp_buf, &asn_buf) == IK_LEN)
		memcpy(con_ptr->ik, temp_buf, IK_LEN);
	else
		return RER;
	if(get_tlv("4-3", temp_buf, &asn_buf) == 1)
		con_ptr->ksi= temp_buf[0];
	else
		return RER;
	con_ptr->param_flag = 0x07;
	return ROK;
}

int assign_authReSynInfo(AuthReSynInfo_st *resyn_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;

	asn_encode(buf, &asn_buf);
	if (resyn_ptr->param_flag != 0x03)
		return RER;
	buf_len = add_tlv("4-1", RAND_LEN, resyn_ptr->rand, 0x00, &asn_buf);
	buf_len = add_tlv("4-2", AUTS_LEN, resyn_ptr->auts, 0x00, &asn_buf);
	return buf_len;
}

int extract_authReSynInfo(AuthReSynInfo_st *resyn_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("4-1", temp_buf, &asn_buf) == RAND_LEN)
		memcpy(resyn_ptr->rand, temp_buf, RAND_LEN);
	else
		return RER;
	if (get_tlv("4-2", temp_buf, &asn_buf) == AUTS_LEN)
		memcpy(resyn_ptr->auts, temp_buf, AUTS_LEN);
	else
		return RER;
	resyn_ptr->param_flag = 0x03;
	return ROK;
}

int assign_sgsnCapability(struct SgsnCap_s *cap_ptr, u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			tag1=1;
	char			tlv1[32];
	
	asn_encode(buf, &asn_buf);
	if(cap_ptr->param_flag & 0x04)
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_null(tlv1, 0x80, &asn_buf);
	}
	return buf_len;
}

int extract_sgsnCapability(struct SgsnCap_s *cap_ptr, u32 buf_len, u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			tag1=1;
	char			tlv1[32];
	//u8			temp_buf[256];

	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	sprintf(tlv1,"3-%d",tag1++);
	len = get_null(tlv1, &asn_buf);	//get_tlv
	if(len > 0)
	{
		cap_ptr->gprs_supp_ind = 1;
		cap_ptr->param_flag |= 0x04;
	}	
	return ROK;
}

//add by gxchen	end

int assign_extsiginfo(struct ExtSigInfo_struct *sig_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			temp_buf[2];

	asn_encode(buf,&asn_buf);
	if (sig_ptr->param_flag & 0x01)		//prt_id
	{
		temp_buf[0] = sig_ptr->prt_id;
		buf_len = add_tlv("10-1",1,temp_buf,0x00,&asn_buf);
	}
	if (sig_ptr->param_flag & 0x02)		//siginfo
		buf_len = add_tlv("4-2",sig_ptr->siginfo.siginfo_len,sig_ptr->siginfo.signal_info,0x00,&asn_buf);
	return buf_len;
}

int	extract_extsiginfo(struct ExtSigInfo_struct *sig_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];

	sig_ptr->param_flag = 0;
	if (buf_len == 0)
		return RER;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("10",temp_buf,&asn_buf) == 1)
	{
		sig_ptr->prt_id = temp_buf[0];
		sig_ptr->param_flag |= 0x01;
	}
	len = get_tlv("4",temp_buf,&asn_buf);
	if (len > 0 && len < SIGNALINFO_LEN)
	{
		sig_ptr->siginfo.siginfo_len = len;
		memcpy(sig_ptr->siginfo.signal_info,temp_buf,len);
		sig_ptr->param_flag |= 0x02;
	}
	return ROK;
}

int assign_bscode(struct BSCode_struct *bs_ptr,u8 *buf,u8 flag)
{
	ASN_BUF		asn_buf;
	int			ii;
	int			buf_len=0;
	int			temp_len;
	u8			temp_buf[256];
	char			tlv1[32];

	asn_encode(buf,&asn_buf);
	if (bs_ptr->param_flag & 0x01)
	{
		temp_len = tele_bittostr(bs_ptr->tele_code,temp_buf,flag);
		for (ii = 0;ii < temp_len;ii ++)
		{
			sprintf(tlv1,"3-%d",ii+1);
			buf_len = add_tlv(tlv1,1,temp_buf+ii,0x80,&asn_buf);
		}
	}
	if (bs_ptr->param_flag & 0x02)
	{
		temp_len = bearer_bittostr(bs_ptr->bearer_code,temp_buf,flag);
		for (ii = 0;ii < temp_len;ii ++)
		{
			sprintf(tlv1,"2-%d",ii+1);
			buf_len = add_tlv(tlv1,1,temp_buf+ii,0x80,&asn_buf);
		}
	}
	return buf_len;
}

int extract_bscode(struct BSCode_struct *bs_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			ii;
	u8			temp_buf[256],temp_data[256];
	char			tlv1[32];

	bs_ptr->param_flag = 0;
	if (buf_len == 0)
		return RER;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	for (ii = 0;ii < TSLIST_LEN;ii ++)	// tele
	{
		sprintf(tlv1,"3-%d",ii+1);
		if (get_tlv(tlv1,temp_buf,&asn_buf) < 1)
		{
			bs_ptr->tele_code = tele_strtobit(temp_data,ii);
			bs_ptr->param_flag |= 0x01;
			break;
		}
		temp_data[ii] = temp_buf[0];
	}
	for (ii = 0;ii < BSLIST_LEN;ii ++)	// bearer
	{
		sprintf(tlv1,"2-%d",ii+1);
		if (get_tlv(tlv1,temp_buf,&asn_buf) < 1)
		{
			bs_ptr->bearer_code = bearer_strtobit(temp_data,ii);	
			bs_ptr->param_flag |= 0x02;
			break;
		}
		temp_data[ii] = temp_buf[0];
	}
	return ROK;
}

int assign_subinfo(struct SubInfo_struct *info_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u8			tag1=1,tag2;
	char			tlv1[32],tlv2[32];

	asn_encode(buf,&asn_buf);
	if (info_ptr->param_flag & 0x01)	// location info
	{
		tag2 = 1;
		if (info_ptr->loc_info.param_flag & 0x01)	// age of location info
		{
			sprintf(tlv1,"0-%d.2-%d",tag1,tag2++);
			buf_len = add_int(tlv1,info_ptr->loc_info.age_info,0x00,&asn_buf);
		}
		if (info_ptr->loc_info.param_flag & 0x02)	// geographical info
		{
			sprintf(tlv1,"0-%d.0-%d",tag1,tag2++);
			buf_len = add_tlv(tlv1,8,info_ptr->loc_info.geog_info,0x80,&asn_buf);
		}
		if (info_ptr->loc_info.param_flag & 0x04)	// vlr number
		{
			sprintf(tlv1,"0-%d.1-%d",tag1,tag2++);
			buf_len = add_tlv(tlv1,info_ptr->loc_info.vlr_num[0],info_ptr->loc_info.vlr_num+1,0x80,&asn_buf);
		}
		if (info_ptr->loc_info.param_flag & 0x08)	// location number
		{
			sprintf(tlv1,"0-%d.2-%d",tag1,tag2++);
			buf_len = add_tlv(tlv1,info_ptr->loc_info.loc_num[0],info_ptr->loc_info.loc_num+1,0x80,&asn_buf);
		}
		if (info_ptr->loc_info.param_flag & 0x10)	// cell id or LAI
		{
			sprintf(tlv1,"0-%d.3-%d",tag1,tag2++);
			if (info_ptr->loc_info.cell_lai.choice_flag == 1)	// cell id
			{
				sprintf(tlv2,"%s.0",tlv1);
				buf_len = add_tlv(tlv2,GCID_LEN,info_ptr->loc_info.cell_lai.cell_choice.cellid,0x80,&asn_buf);
			}
			else	// lai
			{
				sprintf(tlv2,"%s.1",tlv1);
				buf_len = add_tlv(tlv2,LAI_LEN,info_ptr->loc_info.cell_lai.cell_choice.lai,0x80,&asn_buf);
			}
		}
		tag1 ++;
	}
	if (info_ptr->param_flag & 0x02)	// subscriber state
	{
		switch (info_ptr->sub_state.choice_flag)
		{
			case 0x01:	// assume idle
				sprintf(tlv1,"1-%d.0",tag1);
				buf_len = add_null(tlv1,0x80,&asn_buf);
				break;
			case 0x02:	// camel busy
				sprintf(tlv1,"1-%d.1",tag1);
				buf_len = add_null(tlv1,0x80,&asn_buf);
				break;
			case 0x04:	// net not reachable
				sprintf(tlv1,"1-%d.10",tag1);
				buf_len = add_int(tlv1,info_ptr->sub_state.choice.net_reason,0x00,&asn_buf);
				break;
			case 0x08:	// not provided from vlr
				sprintf(tlv1,"1-%d.2",tag1);
				buf_len = add_null(tlv1,0x80,&asn_buf);
				break;
			default:
				break;
		}
	}
    if (info_ptr->param_flag & 0x04)    // location info GPRS
    {
        tag1 = 3;
        sprintf(tlv1,"%d",tag1);
        buf_len = add_int(tlv1,info_ptr->locationInfoGPRS,0x80,&asn_buf);
    }
    if (info_ptr->param_flag & 0x08)    // ps subscriber state
    {
        tag1 = 4;
        sprintf(tlv1,"%d",tag1);
        buf_len = add_int(tlv1,info_ptr->locationInfoGPRS,0x80,&asn_buf);
    }
    if (info_ptr->param_flag & 0x10)    // imei
    {
        tag1 = 5;
        sprintf(tlv1,"%d",tag1);
        buf_len = add_tlv(tlv1,IMEI_LEN,
        info_ptr->imei,0x80,&asn_buf);
    }
	if (info_ptr->param_flag & 0x20)    // ms classmark
	{
	    tag1 = 6;
	    sprintf(tlv1,"%d",tag1);
	    buf_len = add_int(tlv1,info_ptr->ms_classmark,0x80,&asn_buf);
	}
	if (info_ptr->param_flag & 0x40)    // gprs class mark
	{
	    tag1 = 7;
	    sprintf(tlv1,"%d",tag1);
	    buf_len = add_int(tlv1,info_ptr->gprs_ms_class,0x80,&asn_buf);
	}
    if (info_ptr->param_flag & 0x80)    // mnp info response
    {
        struct MnpInfoRes *mnpInfoResPtr;
        mnpInfoResPtr = &info_ptr->mnp_info_res;
        tag1 = 8;
        if(mnpInfoResPtr->param_flag & 0x01)
        {
            sprintf(tlv1,"%d.0",tag1);
            buf_len = add_tlv(tlv1,
                mnpInfoResPtr->routing_number[0]%(ISDN_LEN+1),
                mnpInfoResPtr->routing_number+1,
                0x80,
		        &asn_buf);
        }
        if(mnpInfoResPtr->param_flag & 0x02)
        {
            sprintf(tlv1,"%d.1",tag1);
	        buf_len = add_tlv(tlv1,
	            IMSI_LEN,
	            mnpInfoResPtr->imsi,
	            0x80,
	            &asn_buf);
	    }
	    if(mnpInfoResPtr->param_flag & 0x04)
	    {
	         sprintf(tlv1,"%d.2",tag1);
		     buf_len = add_tlv(tlv1,
		          mnpInfoResPtr->msisdn[0]%(ISDN_LEN+1),
		          mnpInfoResPtr->msisdn+1,
		          0x80,
		          &asn_buf);
		}
		if(mnpInfoResPtr->param_flag & 0x08)
		{
		     sprintf(tlv1,"%d.3",tag1);
		     buf_len = add_tlv(tlv1,
		          1,
		          (u_char *)&mnpInfoResPtr->mnp_status,
		          0x80,
		          &asn_buf);
		}
    }
	return buf_len;
}

int extract_subinfo(struct SubInfo_struct *info_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u8			tag1;
	char			tlv1[32];

	if (buf_len == 0)
		return RER;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("0",temp_buf,&asn_buf) != -1)	// location info
	{
		info_ptr->param_flag |= 0x01;
		tag1 = 1;
		len = get_int("0.2-1",&asn_buf);	// age of location info
		if (len != -1)
		{
			info_ptr->loc_info.param_flag |= 0x01;
			info_ptr->loc_info.age_info = len;
			tag1 ++;
		}
		if (get_tlv("0.0",temp_buf,&asn_buf) == 8)	// geographical info
		{
			info_ptr->loc_info.param_flag |= 0x02;
			memcpy(info_ptr->loc_info.geog_info,temp_buf,8);
			tag1 ++;
		}
		len = get_tlv("0.1",temp_buf,&asn_buf);		// vlr num
		if (len != -1 && len < ISDN_LEN)
		{
			info_ptr->loc_info.param_flag |= 0x04;
			info_ptr->loc_info.vlr_num[0] = len;
			memcpy(info_ptr->loc_info.vlr_num+1,temp_buf,len);
			tag1 ++;
		}
		sprintf(tlv1,"0.2-%d",tag1);
		len = get_tlv(tlv1,temp_buf,&asn_buf);		// location num
		if (len != -1 && len < LOCATION_NUM)
		{
			info_ptr->loc_info.param_flag |= 0x08;
			info_ptr->loc_info.loc_num[0] = len;
			memcpy(info_ptr->loc_info.loc_num+1,temp_buf,len);
		}
		if (get_tlv("0.3",temp_buf,&asn_buf) != -1)	// cell id or lai
		{
			info_ptr->loc_info.param_flag |= 0x10;
			if (get_tlv("0.3.0",temp_buf,&asn_buf) == GCID_LEN)
			{
				info_ptr->loc_info.cell_lai.choice_flag = 1;
				memcpy(info_ptr->loc_info.cell_lai.cell_choice.cellid,temp_buf,GCID_LEN);
			}
			else if (get_tlv("0.3.1",temp_buf,&asn_buf) == LAI_LEN)
			{
				info_ptr->loc_info.cell_lai.choice_flag = 2;
				memcpy(info_ptr->loc_info.cell_lai.cell_choice.lai,temp_buf,LAI_LEN);
			}
		}
	}
	if (get_tlv("1",temp_buf,&asn_buf) != -1)	// location info
	{
		info_ptr->param_flag |= 0x02;
		if (get_tlv("1.0",temp_buf,&asn_buf) != -1)	// assume idle
			info_ptr->sub_state.choice_flag = 1;
		else if (get_tlv("1.1",temp_buf,&asn_buf) != -1)	// camel busy
			info_ptr->sub_state.choice_flag = 2;
		else if (get_tlv("1.10",temp_buf,&asn_buf) != -1)	// not reachalbe reason
		{
			info_ptr->sub_state.choice_flag = 0x04;
			info_ptr->sub_state.choice.net_reason = temp_buf[0];
		}
		else if (get_tlv("1.2",temp_buf,&asn_buf) != -1)	// not provided from vlr
			info_ptr->sub_state.choice_flag = 0x08;
	}
	if(get_tlv("3",temp_buf,&asn_buf) != -1)   // location info GPRS
	{
	    info_ptr->param_flag |= 0x04;
	    info_ptr->locationInfoGPRS = temp_buf[0];
	}
    if (get_tlv("4",temp_buf,&asn_buf) != -1)   // ps subscriber state
	{
	    info_ptr->param_flag |= 0x08;
	    info_ptr->ps_subscriber_state = temp_buf[0];
	}
    if ((len=get_tlv("5",temp_buf,&asn_buf)) != -1) // imei
	{
	    info_ptr->param_flag |= 0x10;
	    info_ptr->imei[0] = len%(IMEI_LEN+1);
	    memcpy(&info_ptr->imei[1],temp_buf,IMEI_LEN);
	}
    if (get_tlv("6",temp_buf,&asn_buf) != -1)   // ms class mark
	{
	    info_ptr->param_flag |= 0x20;
	    info_ptr->ms_classmark = temp_buf[0];
	}
    if (get_tlv("7",temp_buf,&asn_buf) != -1)   // GPRS MS cla
	{
		info_ptr->param_flag |= 0x40;
		info_ptr->gprs_ms_class = temp_buf[0];
	}
	if (get_tlv("8",temp_buf,&asn_buf) != -1)       // MNP info res
	{
	    struct MnpInfoRes *mnpInfoResPtr;
        mnpInfoResPtr = &info_ptr->mnp_info_res;
        info_ptr->param_flag |= 0x80;
        mnpInfoResPtr->param_flag = 0x00;
        if ((len=get_tlv("8.0",temp_buf,&asn_buf)) != -1)       // routing number
		{
		     mnpInfoResPtr->param_flag |= 0x01;
		     len %= (ISDN_LEN+1);
		     mnpInfoResPtr->routing_number[0] = len;
		     memcpy(&mnpInfoResPtr->routing_number[1],
		        temp_buf,
		        len);
		}
        if((len=get_tlv("8.1",temp_buf,&asn_buf)) == IMSI_LEN)
		{
		     mnpInfoResPtr->param_flag |= 0x02;
		     memcpy(mnpInfoResPtr->imsi,temp_buf,IMSI_LEN);
	    }
        if((len=get_tlv("8.2",temp_buf,&asn_buf)) != -1)
		{
		     mnpInfoResPtr->param_flag |= 0x04;
		     len %= (ISDN_LEN+1);
		     mnpInfoResPtr->msisdn[0] = len;
		     memcpy(&mnpInfoResPtr->msisdn[1],temp_buf,len);
		}
        if((len=get_tlv("8.3",temp_buf,&asn_buf)) != -1)
		{
			 mnpInfoResPtr->param_flag |= 0x08;
			 mnpInfoResPtr->mnp_status = temp_buf[0];
		}
	 }	  
	 return ROK;
}

int assign_ocsi(struct OCsi_struct *ocsi_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			ii;
	int			buf_len=0;
	u8			temp_len;
	char			tlv1[32];

	asn_encode(buf,&asn_buf);
	if (ocsi_ptr->tdpdata_list.tdpdata_len > TDPDATA_NUM)
		return RER;
	buf_len = add_null("16",0x20,&asn_buf);
	for(ii = 0;ii < ocsi_ptr->tdpdata_list.tdpdata_len;ii ++)	//o-BCSM Camel TDP Data List
	{
		sprintf(tlv1,"16.16-%d",ii+1);
		buf_len = add_null(tlv1,0x20,&asn_buf);
		sprintf(tlv1,"16.16-%d.10-1",ii+1);
		buf_len = add_int(tlv1,ocsi_ptr->tdpdata_list.tdp_data[ii].det_point,0x00,&asn_buf);
		sprintf(tlv1,"16.16-%d.2-2",ii+1);
		buf_len = add_int(tlv1,ocsi_ptr->tdpdata_list.tdp_data[ii].service_key,0x00,&asn_buf);
		sprintf(tlv1,"16.16-%d.0-3",ii+1);
		temp_len = ocsi_ptr->tdpdata_list.tdp_data[ii].scf_add[0];
		buf_len = add_tlv(tlv1,temp_len,ocsi_ptr->tdpdata_list.tdp_data[ii].scf_add+1,0x80,&asn_buf);
		sprintf(tlv1,"16.16-%d.1-4",ii+1);
		buf_len = add_int(tlv1,ocsi_ptr->tdpdata_list.tdp_data[ii].def_hand,0x80,&asn_buf);
	}
	if (ocsi_ptr->param_flag & 0x02)		//camel capability Handling
		buf_len = add_int("0-2",ocsi_ptr->camel_caphand,0x80,&asn_buf);
	return buf_len;
}

int extract_ocsi(struct OCsi_struct *ocsi_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			ii,jj;
	u8			temp_buf[256];
	char			tlv1[32];

	if (buf_len == 0)
		return RER;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	ocsi_ptr->tdpdata_list.tdpdata_len = 0;
	for (ii = 0;ii < TDPDATA_NUM;ii ++)
	{
		jj = ocsi_ptr->tdpdata_list.tdpdata_len;
		sprintf(tlv1,"16.16-%d",ii+1);
		len = get_tlv(tlv1,temp_buf,&asn_buf);
		if (len == -1)
			break;
		sprintf(tlv1,"16.16-%d.10",ii+1);	// det_point
		if (get_tlv(tlv1,temp_buf,&asn_buf) != 1)
			return RER;
		ocsi_ptr->tdpdata_list.tdp_data[jj].det_point = temp_buf[0];
		sprintf(tlv1,"16.16-%d.2",ii+1);	// service key
		len = get_int(tlv1,&asn_buf);
		if (len == -1)
			return RER;
		ocsi_ptr->tdpdata_list.tdp_data[jj].service_key = len;
		sprintf(tlv1,"16.16-%d.0",ii+1);	// scf address
		len = get_tlv(tlv1,temp_buf,&asn_buf);
		if (len == -1 || len > ISDN_LEN)
			return RER;
		ocsi_ptr->tdpdata_list.tdp_data[jj].scf_add[0] = len;
		memcpy(ocsi_ptr->tdpdata_list.tdp_data[jj].scf_add+1,temp_buf,len);
		sprintf(tlv1,"16.16-%d.1",ii+1);	// default call handling
		len = get_tlv(tlv1,temp_buf,&asn_buf);
		if (len != 1)
			return RER;
		ocsi_ptr->tdpdata_list.tdp_data[jj].def_hand = temp_buf[0];
		ocsi_ptr->tdpdata_list.tdpdata_len ++;
	}
	if (get_tlv("0",temp_buf,&asn_buf) == 1)
	{
		ocsi_ptr->param_flag |= 0x02;
		ocsi_ptr->camel_caphand = temp_buf[0];
	}
	return ROK;
}

int assign_tdpcritlist(struct OBCritLst_struct *list_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	u8			ii,jj;
	int			buf_len=0;
	u8			tag1,tag2;
	int			temp_len;
	u8			temp_buf[256];
	char			tlv1[32],tlv2[32],tlv3[32];
	struct		DstNumCrit_struct	*dst_ptr;

	asn_encode(buf,&asn_buf);
	if (list_ptr->list_len > TDPDATA_NUM)
		return RER;
	for (ii = 0;ii < list_ptr->list_len;ii ++)
	{
		sprintf(tlv1,"16-%d",ii+1);
		buf_len = add_null(tlv1,0x20,&asn_buf);
		sprintf(tlv2,"%s.10-1",tlv1);
		buf_len = add_int(tlv2,list_ptr->crit_data[ii].det_point,0x00,&asn_buf);
		tag1 = 2;
		if (list_ptr->crit_data[ii].param_flag & 0x02)	// dest number criteria
		{
			dst_ptr = (DstNumCrit_struct *) &list_ptr->crit_data[ii].dstCriteria;
			if (dst_ptr->param_flag & 0x01)	// match type
			{
				sprintf(tlv2,"%s.0-%d.0-1",tlv1,tag1);
				buf_len = add_int(tlv2,dst_ptr->match_type,0x80,&asn_buf);
			}
			tag2 = 2;
			if (dst_ptr->param_flag & 0x02)	// dest number list
			{
				sprintf(tlv2,"%s.0-%d.1-%d",tlv1,tag1,tag2++);
				if (dst_ptr->dstnum_list.dstnum_len > MAX_DSTNUM)
					return RER;
				for (jj = 0;jj < dst_ptr->dstnum_list.dstnum_len;jj ++)
				{
					sprintf(tlv3,"%s.4-%d",tlv2,jj+1);
					buf_len = add_tlv(tlv3,dst_ptr->dstnum_list.dst_num[jj][0],dst_ptr->dstnum_list.dst_num[jj]+1,0x00,&asn_buf);
				}
			}
			if (dst_ptr->param_flag & 0x04)	// dest number length list
			{
				sprintf(tlv2,"%s.0-%d.2-%d",tlv1,tag1,tag2++);
				if (dst_ptr->dstnumlen_list.numlength_len > DSTNUM_LEN)
					return RER;
				for (jj = 0;jj < dst_ptr->dstnumlen_list.numlength_len;jj ++)
				{
					sprintf(tlv3,"%s.2-%d",tlv2,jj+1);
					buf_len = add_int(tlv3,dst_ptr->dstnumlen_list.num_length[jj],0x00,&asn_buf);
				}
			}
			tag1 ++;
		}
		if (list_ptr->crit_data[ii].param_flag & 0x04)	// basic service criteria
		{
			temp_len = assign_bscode(&list_ptr->crit_data[ii].bs_code,temp_buf,0);
			sprintf(tlv2,"%s.1-%d",tlv1,tag1++);
			buf_len = add_tlv(tlv2,temp_len,temp_buf,0x10,&asn_buf);
		}
		if (list_ptr->crit_data[ii].param_flag & 0x08)	// call type criteria
		{
			sprintf(tlv2,"%s.2-%d",tlv1,tag1++);
			buf_len = add_int(tlv2,list_ptr->crit_data[ii].call_crit,0x80,&asn_buf);
		}
	}
	return buf_len;
}

int extract_tdpcritlist(struct OBCritLst_struct *list_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			ii,jj;
	u8			aa,bb;
	u8			temp_buf[256];
	char			tlv1[32];
	struct		DstNumCrit_struct	*dst_ptr;

	if (buf_len == 0)
		return RER;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	list_ptr->list_len = 0;
	for (ii = 0;ii < TDPDATA_NUM;ii ++)
	{
		jj = list_ptr->list_len;
		list_ptr->crit_data[jj].param_flag = 0;
		sprintf(tlv1,"16-%d",ii+1);
		if (get_tlv(tlv1,temp_buf,&asn_buf) == -1)
			break;
		sprintf(tlv1,"16-%d.10",ii+1);	// detection point
		if (get_tlv(tlv1,temp_buf,&asn_buf) != 1)
			return RER;
		list_ptr->crit_data[jj].det_point = temp_buf[0];
		list_ptr->crit_data[jj].param_flag |= 0x01;
		sprintf(tlv1,"16-%d.0",ii+1);	// dest criteria
		if (get_tlv(tlv1,temp_buf,&asn_buf) != -1)
		{
			list_ptr->crit_data[jj].param_flag |= 0x02;
			dst_ptr = (DstNumCrit_struct *) &list_ptr->crit_data[jj].dstCriteria;
			sprintf(tlv1,"16-%d.0.0",ii+1);	// match type
			if (get_tlv(tlv1,temp_buf,&asn_buf) != 1)
				return RER;
			dst_ptr->match_type = temp_buf[0];
			dst_ptr->param_flag = 0x01;
			sprintf(tlv1,"16-%d.0.1",ii+1);	// dest num list
			if (get_tlv(tlv1,temp_buf,&asn_buf) != -1)
			{
				dst_ptr->param_flag |= 0x02;
				dst_ptr->dstnum_list.dstnum_len = 0;
				for (aa = 0;aa < MAX_DSTNUM;aa ++)
				{
					bb = dst_ptr->dstnum_list.dstnum_len;
					sprintf(tlv1,"16-%d.0.1.4-%d",ii+1,aa+1);	// dest num list
					len = get_tlv(tlv1,temp_buf,&asn_buf);
					if (len == -1 || len < ISDN_LEN)
						break;
					dst_ptr->dstnum_list.dst_num[bb][0] = len;
					memcpy(dst_ptr->dstnum_list.dst_num[bb]+1,temp_buf,len);
					dst_ptr->dstnum_list.dstnum_len ++;
				}
			}
			sprintf(tlv1,"16-%d.0.2",ii+1);	// dest num length list
			if (get_tlv(tlv1,temp_buf,&asn_buf) != -1)
			{
				dst_ptr->param_flag |= 0x04;
				dst_ptr->dstnumlen_list.numlength_len = 0;
				for (aa = 0;aa < DSTNUM_LEN;aa ++)
				{
					bb = dst_ptr->dstnumlen_list.numlength_len;
					sprintf(tlv1,"16-%d.0.2.2-%d",ii+1,aa+1);	// dest num list
					len = get_tlv(tlv1,temp_buf,&asn_buf);
					if (len != 1)
						break;
					dst_ptr->dstnumlen_list.num_length[bb] = temp_buf[0];
					dst_ptr->dstnumlen_list.numlength_len ++;
				}
			}
		}
		sprintf(tlv1,"16-%d.1",ii+1);	// bs criteria
		if ((len=get_tlv(tlv1,temp_buf,&asn_buf)) != -1)
		{
			if (!extract_bscode(&list_ptr->crit_data[jj].bs_code,len,temp_buf))
				return RER;
			list_ptr->crit_data[jj].param_flag |= 0x04;
		}
		sprintf(tlv1,"16-%d.2",ii+1);	// call type criteria
		if (get_tlv(tlv1,temp_buf,&asn_buf) == 1)
		{
			list_ptr->crit_data[jj].param_flag |= 0x08;
			list_ptr->crit_data[jj].call_crit = temp_buf[0];
		}
		list_ptr->list_len ++;
	}
	return ROK;
}

int	assign_ccbsfeat(struct CcbsFeat_struct *cf_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	int			temp_len;
	u8			tag1=1;
	u8			temp_buf[256];
	char			tlv1[32];

	asn_encode(buf,&asn_buf);
	if (cf_ptr->param_flag & 0x01)	// ccbs index
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cf_ptr->ccbs_index,0x80,&asn_buf);
	}
	if (cf_ptr->param_flag & 0x02)	// b-subscriber number
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,cf_ptr->bsub_num[0],cf_ptr->bsub_num+1,0x80,&asn_buf);
	}
	if (cf_ptr->param_flag & 0x04)	// bs code
	{
		sprintf(tlv1,"3-%d",tag1++);
		temp_len = assign_bscode(&cf_ptr->bs_code,temp_buf,0);
		buf_len = add_tlv(tlv1,temp_len,temp_buf,0x80,&asn_buf);
	}
	return buf_len;
}

int extract_ccbsfeat(struct CcbsFeat_struct *cf_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int 		len;
	u8			temp_buf[256];

	cf_ptr->param_flag = 0;
	if (buf_len == 0)
		return ROK;
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	if (get_tlv("0",temp_buf,&asn_buf) == 1)	// ccbs index
	{
		cf_ptr->param_flag |= 0x01;
		cf_ptr->ccbs_index = temp_buf[0];
	}
	len = get_tlv("1",temp_buf,&asn_buf);	// b-subscriber number
	if (len > 0 && len <= ISDN_LEN)
	{
		cf_ptr->param_flag |= 0x02;
		cf_ptr->bsub_num[0] = len;
		memcpy(cf_ptr->bsub_num+1,temp_buf,len);
	}
	len = get_tlv("3",temp_buf,&asn_buf);	// bs code
	if (len > 0)
	{
		if (!extract_bscode(&cf_ptr->bs_code,len,temp_buf))
			return RER;
		cf_ptr->param_flag |= 0x04;
	}
	return ROK;
}

int assign_ProvideInstructionStart(struct _ProvideInstructionStart *pis, u8 *buf)
{
	ASN_BUF		asn_buf;
	int			flag,buf_len=0;
	u8		info_str[1024];
	//int			temp_index;
	//int			param_num;
	
	asn_encode(buf,&asn_buf); 
	flag = pis->param_flag;
	//add_null("16", 0x20, &asn_buf);

	if(flag & BIT0_TRUE)
	{
		buf_len = add_tlv("10.4-1", pis->calledPartyNumber[0], pis->calledPartyNumber+1, 0x80, &asn_buf);
		
	}
	if(flag & BIT1_TRUE)
	{
		buf_len = add_tlv("4-2", pis->callingPartyNumber[0], pis->callingPartyNumber+1, 0x80, &asn_buf);
	}
	if(flag & BIT2_TRUE)
	{
		buf_len = add_tlv("4-3", pis->LATA[0], pis->LATA+1, 0x80, &asn_buf);
	}
	if(flag & BIT3_TRUE)
	{
		buf_len = add_tlv("69", 1, &pis->OriginatingStationType, 0xC0, &asn_buf);
	}
	
	memcpy(info_str,buf,buf_len%1024);
	asn_encode(buf,&asn_buf);
	buf_len = add_tlv("18",buf_len%1024,info_str,0xe0,&asn_buf);	
	return buf_len;
}

int assign_ConnectionControlConnect(struct _ConnectionControlConnect *pis, u8 *buf)
{
	ASN_BUF		asn_buf;
	int			flag,buf_len=0;
	u8		info_str[1024];
	//int			temp_index;
	//int			param_num;
	
	asn_encode(buf,&asn_buf); 
	flag = pis->param_flag;

	if(flag & BIT0_TRUE)
	{
		buf_len = add_tlv("4-1", pis->CIC[0], pis->CIC+1, 0x80, &asn_buf);
		
	}
	if(flag & BIT1_TRUE)
	{
		buf_len = add_tlv("4-2", pis->RoutingNumber[0], pis->RoutingNumber+1, 0x80, &asn_buf);
	}
	if(flag & BIT2_TRUE)
	{
		buf_len = add_tlv("65", 1, &pis->BillingIndicator, 0xc0, &asn_buf);
	}

	memcpy(info_str,buf,buf_len%1024);
	asn_encode(buf,&asn_buf);
	buf_len = add_tlv("18",buf_len%1024,info_str,0xe0,&asn_buf);		
	return buf_len;
}

int	build_ainparam(struct MapOprSrv_struct *opr_ptr,u8 *buf) // build ain service paramter
{
	//ASN_BUF	asn_buf;
	//u8	 	seq_flag=1;
	int		param_len = 0;
	//u8		info_str[1024];
	u32		param_flag;

	param_flag = opr_ptr->msg_list.provideInstructionStart.param_flag;
	if (opr_ptr == NULL || buf == NULL) 
		return RER;
	switch (opr_ptr->message_type & 0x7f)
	{
		case ProvideInstructionStart:
			if(opr_ptr->message_flag == MAP_REQUEST)
			{
				param_len = assign_ProvideInstructionStart(&opr_ptr->msg_list.provideInstructionStart, buf);
			}
			break;
		case ConnectionControlConnect:
			if(opr_ptr->message_flag == MAP_REQUEST)
			{
				param_len = assign_ConnectionControlConnect(&opr_ptr->msg_list.connectionControlConnect,  buf);
			}
			break;
		default:
			break;
	}
	return param_len;
}

int code_ansitcap_digits(struct _ansiTcapDigits *digits, u8 *outBuf)
{
	int len=0;

	if(digits == NULL || outBuf == NULL)
		return 0;
	
	outBuf[0] = digits->typeOfDigits;
	outBuf[1] = digits->natureOfNumber;
	outBuf[2] = (digits->numberingPlan<<4) | (digits->encoding&0xf);
	outBuf[3] = digits->numberOfDigits;
	len = (digits->numberOfDigits + 1)/2;
	memcpy(outBuf+4, digits->digits, len);
	return len+4;
}

int decode_ansitcap_digits(struct _ansiTcapDigits *digits, u8 *inBuf)
{
	int len = 0;

	if(digits == NULL || inBuf == NULL)
		return 0;
	digits->typeOfDigits = inBuf[0];
	digits->natureOfNumber = inBuf[1];
	digits->numberingPlan = (inBuf[2]>>4)&0xf;
	digits->encoding = inBuf[2]&0xf;
	digits->numberOfDigits = inBuf[3] % 20;
	len = (inBuf[3]+1)/2;
	memcpy(digits->digits, inBuf+4, len);
	return len+4;
}

u8 extract_ainparam(struct MapOprSrv_struct *opr_ptr,u8 opr_code,u8 opr_flag,u32 pre_param_len,u8 *pre_param)
{
	ASN_BUF		asn_buf;
	u8			param[1024];
	int			param_len;
	u32			*param_flag;
	//char		info_str[1024];

	asn_decode(pre_param,1,&asn_buf);
	param_len = get_tlv(SET_NATIONAL,param,&asn_buf);

	if (param_len == -1)	// not has sequence id
	{
		param_len = pre_param_len;
		memcpy(param,pre_param,param_len);
	}

	opr_code &=0x7f;

	switch (opr_code)
	{
		case ProvideInstructionStart:
			param_flag = &opr_ptr->msg_list.provideInstructionStart.param_flag;
			param_len = get_tlv("18.10.4-1", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT0_TRUE;
				memcpy(opr_ptr->msg_list.provideInstructionStart.calledPartyNumber+1, param, param_len);
				opr_ptr->msg_list.provideInstructionStart.calledPartyNumber[0] = param_len;
			}
			else
			{
				xap_send_error("extract provideInstructionStart error,  miss calledPartyNumber\n");
			}
			param_len = get_tlv("18.4-2", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT1_TRUE;			
				memcpy(opr_ptr->msg_list.provideInstructionStart.callingPartyNumber+1, param, param_len);
				opr_ptr->msg_list.provideInstructionStart.callingPartyNumber[0] = param_len;
			}else
			{
				xap_send_error("extract provideInstructionStart error,  miss callingPartyNumber\n");
			}
			param_len = get_tlv("18.4-3", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT2_TRUE;			
				memcpy(opr_ptr->msg_list.provideInstructionStart.LATA+1, param, param_len);
				opr_ptr->msg_list.provideInstructionStart.LATA[0] = param_len; 
			}else
			{
				xap_send_error("extract provideInstructionStart error,  miss LATA\n");
			}
			param_len = get_tlv("18.69", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT3_TRUE;			
				opr_ptr->msg_list.provideInstructionStart.OriginatingStationType = param[0];
			}else
			{
				xap_send_error("extract provideInstructionStart error,  miss OriginatingStationType\n");
			}

			break;
		case ConnectionControlConnect:
			param_flag = &opr_ptr->msg_list.connectionControlConnect.param_flag;
			param_len = get_tlv("18.4-1", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT0_TRUE;
				memcpy(opr_ptr->msg_list.connectionControlConnect.CIC+1, param, param_len);
				opr_ptr->msg_list.connectionControlConnect.CIC[0] = param_len;
			}
			else
			{
				xap_send_error("extract connectionControlConnect error,  miss CIC\n");
			}
			param_len = get_tlv("18.4-2", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT1_TRUE;
				memcpy(opr_ptr->msg_list.connectionControlConnect.RoutingNumber+1, param, param_len);
				opr_ptr->msg_list.connectionControlConnect.RoutingNumber[0] = param_len;
			}
			else
			{
				xap_send_error("extract connectionControlConnect error,  miss RoutingNumber\n");
				return 0;
			}		
			param_len = get_tlv("18.65", param, &asn_buf);
			if(param_len != -1)
			{
				*param_flag |= BIT2_TRUE;
				opr_ptr->msg_list.connectionControlConnect.BillingIndicator = param[0];
			}
			else
			{
				xap_send_error("extract connectionControlConnect error,  miss BillingIndicator\n");
			}
			break;
		default:
			break;
				
	}
	return 1;
}

