#include "./include/inc.h"
#include "./include/var_ext.h"
#include "./include/q1902_3e.h"
/**********************************************/
/******* BICC Message&Primitive Mapping *******/
/**********************************************/
void app_msg2prm(AppTransM_struct *dst_ptr, AppTrans_struct *src_ptr)
{
	dst_ptr->pres = src_ptr->pres;
	if(src_ptr->pres == 1)
	{
		memcpy(&dst_ptr->apm_info, &src_ptr->apm_info, sizeof(ApmUser_struct));
		dst_ptr->apm_info.sni = src_ptr->sni;
		dst_ptr->apm_info.rci = src_ptr->rci;
	}
}

void app_prm2msg(AppTrans_struct *dst_ptr, AppTransM_struct *src_ptr)
{
	dst_ptr->pres = src_ptr->pres;
	if(src_ptr->pres == 1)
	{
		dst_ptr->aci[0] = 0x00;
		dst_ptr->aci[1] = 0x00;
		dst_ptr->sni = src_ptr->apm_info.sni;
		dst_ptr->rci = src_ptr->apm_info.rci;
		dst_ptr->si = 0;			//subsequent segment to first segment
		dst_ptr->segment = 0;		//final segment
		dst_ptr->slr = 0;
		memcpy(&dst_ptr->apm_info, &src_ptr->apm_info, sizeof(ApmUser_struct));
	}
}

void bicc_msg2prm(BiccReadPrim_union *prm_ptr, BiccMsg_union *msg_ptr, u8 msg_type)
{
	memset(prm_ptr, 0, sizeof(BiccReadPrim_union));
	switch(msg_type)
	{
		case M_ACM:
			memcpy(&prm_ptr->alert_ind.backCall, &msg_ptr->acm.backCall, sizeof(BackCallInd_struct));
			app_msg2prm(&prm_ptr->alert_ind.app, &msg_ptr->acm.app);
			memcpy(&prm_ptr->alert_ind.cause, &msg_ptr->acm.cause, sizeof(CauseInd_struct));
			memcpy(&prm_ptr->alert_ind.confTreat, &msg_ptr->acm.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&prm_ptr->alert_ind.optBackCall, &msg_ptr->acm.optBackCall, sizeof(OptBackCallInd_struct));
			memcpy(&prm_ptr->alert_ind.utuInd, &msg_ptr->acm.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->alert_ind.utuInfo, &msg_ptr->acm.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_ANM:
			app_msg2prm(&prm_ptr->setup_cnf.app, &msg_ptr->anm.app);
			memcpy(&prm_ptr->setup_cnf.backCall, &msg_ptr->anm.backCall, sizeof(BackCallInd_struct));
			memcpy(&prm_ptr->setup_cnf.confTreat, &msg_ptr->anm.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&prm_ptr->setup_cnf.connNum, &msg_ptr->anm.connNum, sizeof(ConnNum_struct));
			memcpy(&prm_ptr->setup_cnf.utuInd, &msg_ptr->anm.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->setup_cnf.utuInfo, &msg_ptr->anm.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_APM:
			app_msg2prm(&prm_ptr->apm_ind.app, &msg_ptr->apm.app);
			break;
		case M_CPG:
			memcpy(&prm_ptr->cpg_ind.eventInfo, &msg_ptr->cpg.eventInfo, sizeof(EventInfo_struct));
			app_msg2prm(&prm_ptr->cpg_ind.app, &msg_ptr->cpg.app);
			memcpy(&prm_ptr->cpg_ind.backCall, &msg_ptr->cpg.backCall, sizeof(BackCallInd_struct));
			memcpy(&prm_ptr->cpg_ind.calldiver,&msg_ptr->cpg.calldiver, sizeof(BiccCpg_struct));
			memcpy(&prm_ptr->cpg_ind.cause, &msg_ptr->cpg.cause, sizeof(CauseInd_struct));
			memcpy(&prm_ptr->cpg_ind.confTreat, &msg_ptr->cpg.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&prm_ptr->cpg_ind.connNum, &msg_ptr->cpg.connNum, sizeof(ConnNum_struct));
			memcpy(&prm_ptr->cpg_ind.utuInd, &msg_ptr->cpg.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->cpg_ind.utuInfo, &msg_ptr->cpg.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_CGB:
			memcpy(&prm_ptr->cgb_ind.cicGrpSpv, &msg_ptr->cgb.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&prm_ptr->cgb_ind.rangeStatus, &msg_ptr->cgb.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGBA:
			memcpy(&prm_ptr->cgb_cnf.cicGrpSpv, &msg_ptr->cgb.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&prm_ptr->cgb_cnf.rangeStatus, &msg_ptr->cgb.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGU:
			memcpy(&prm_ptr->cgu_ind.cicGrpSpv, &msg_ptr->cgu.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&prm_ptr->cgu_ind.rangeStatus, &msg_ptr->cgu.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGUA:
			memcpy(&prm_ptr->cgu_cnf.cicGrpSpv, &msg_ptr->cgu.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&prm_ptr->cgu_cnf.rangeStatus, &msg_ptr->cgu.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_GRS:
			memcpy(&prm_ptr->grs_ind.rangeStatus, &msg_ptr->grs.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_GRA:
			memcpy(&prm_ptr->grs_cnf.rangeStatus, &msg_ptr->grs.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CON:
			app_msg2prm(&prm_ptr->setup_cnf.app, &msg_ptr->con.app);
			memcpy(&prm_ptr->setup_cnf.backCall, &msg_ptr->con.backCall, sizeof(BackCallInd_struct));
			memcpy(&prm_ptr->setup_cnf.confTreat, &msg_ptr->con.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&prm_ptr->setup_cnf.connNum, &msg_ptr->con.connNum, sizeof(ConnNum_struct));
			memcpy(&prm_ptr->setup_cnf.utuInd, &msg_ptr->con.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->setup_cnf.utuInfo, &msg_ptr->con.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_IAM:
			memcpy(&prm_ptr->setup_ind.natConn, &msg_ptr->iam.natConn, sizeof(NatConnInd_struct));
			memcpy(&prm_ptr->setup_ind.fwdCall, &msg_ptr->iam.fwdCall, sizeof(FwdCallInd_struct));
			memcpy(&prm_ptr->setup_ind.callingPtyCat, &msg_ptr->iam.callingPtyCat, sizeof(CallingPtyCat_struct));
			memcpy(&prm_ptr->setup_ind.transMedReq, &msg_ptr->iam.transMedReq, sizeof(TransMedReq_struct));
			memcpy(&prm_ptr->setup_ind.calledPtyNum, &msg_ptr->iam.calledPtyNum, sizeof(CalledPtyNum_struct));
			app_msg2prm(&prm_ptr->setup_ind.app, &msg_ptr->apm.app);
			memcpy(&prm_ptr->setup_ind.callingPtyNum, &msg_ptr->iam.callingPtyNum, sizeof(CallingPtyNum_struct));
			memcpy(&prm_ptr->setup_ind.collectCallReq, &msg_ptr->iam.collectCallReq, sizeof(CollectCallReq_struct));
			memcpy(&prm_ptr->setup_ind.confTreat, &msg_ptr->iam.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&prm_ptr->setup_ind.correlationId, &msg_ptr->iam.correlationId, sizeof(CorrelationId_struct));
			memcpy(&prm_ptr->setup_ind.origCalledNum, &msg_ptr->iam.origCalledNum, sizeof(OrigCalledNum_struct));
			memcpy(&prm_ptr->setup_ind.redirgNum, &msg_ptr->iam.redirgNum, sizeof(RedirgNum_struct));
			memcpy(&prm_ptr->setup_ind.redirInfo, &msg_ptr->iam.redirInfo, sizeof(RedirInfo_struct));
			memcpy(&prm_ptr->setup_ind.scfId, &msg_ptr->iam.scfId, sizeof(ScfId_struct));
			memcpy(&prm_ptr->setup_ind.utuInd, &msg_ptr->iam.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->setup_ind.utuInfo, &msg_ptr->iam.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_REL:
			memcpy(&prm_ptr->rel_ind.cause, &msg_ptr->rel.cause, sizeof(CauseInd_struct));
			memcpy(&prm_ptr->rel_ind.utuInd, &msg_ptr->rel.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&prm_ptr->rel_ind.utuInfo, &msg_ptr->rel.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_RLC:
			memcpy(&prm_ptr->rel_cnf.cause, &msg_ptr->rlc.cause, sizeof(CauseInd_struct));
			break;
		case M_RES:
			memcpy(&prm_ptr->res_ind.susRes, &msg_ptr->res.susRes, sizeof(SusResInd_struct));
			break;
		case M_SUS:
			memcpy(&prm_ptr->sus_ind.susRes, &msg_ptr->sus.susRes, sizeof(SusResInd_struct));
			break;
		case M_SAM:
			memcpy(&prm_ptr->info_ind.subseqNum, &msg_ptr->sam.subseqNum, sizeof(SubseqNum_struct));
			break;
		default:
			break;
	}
}

void bicc_prm2msg(BiccMsg_union *msg_ptr, BiccWritePrim_union *prm_ptr, u8 msg_type)
{
	memset(msg_ptr, 0, sizeof(BiccMsg_union));
	switch(msg_type)
	{
		case M_ACM:
			memcpy(&msg_ptr->acm.backCall, &prm_ptr->alert_req.backCall, sizeof(BackCallInd_struct));
			app_prm2msg(&msg_ptr->acm.app, &prm_ptr->alert_req.app);
			memcpy(&msg_ptr->acm.cause, &prm_ptr->alert_req.cause, sizeof(CauseInd_struct));
			memcpy(&msg_ptr->acm.confTreat, &prm_ptr->alert_req.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&msg_ptr->acm.optBackCall, &prm_ptr->alert_req.optBackCall, sizeof(OptBackCallInd_struct));
			memcpy(&msg_ptr->acm.utuInd, &prm_ptr->alert_req.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->acm.utuInfo, &prm_ptr->alert_req.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_ANM:
			app_prm2msg(&msg_ptr->anm.app, &prm_ptr->setup_rsp.app);
			memcpy(&msg_ptr->anm.backCall, &prm_ptr->setup_rsp.backCall, sizeof(BackCallInd_struct));
			memcpy(&msg_ptr->anm.confTreat, &prm_ptr->setup_rsp.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&msg_ptr->anm.connNum, &prm_ptr->setup_rsp.connNum, sizeof(ConnNum_struct));
			memcpy(&msg_ptr->anm.utuInd, &prm_ptr->setup_rsp.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->anm.utuInfo, &prm_ptr->setup_rsp.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_APM:
			app_prm2msg(&msg_ptr->apm.app, &prm_ptr->apm_req.app);
			break;
		case M_CPG:
			memcpy(&msg_ptr->cpg.eventInfo, &prm_ptr->cpg_req.eventInfo, sizeof(EventInfo_struct));
			app_prm2msg(&msg_ptr->cpg.app, &prm_ptr->cpg_req.app);
			memcpy(&msg_ptr->cpg.backCall, &prm_ptr->cpg_req.backCall, sizeof(BackCallInd_struct));
			memcpy(&msg_ptr->cpg.calldiver, &prm_ptr->cpg_req.calldiver, sizeof(BiccCpg_struct));
			memcpy(&msg_ptr->cpg.cause, &prm_ptr->cpg_req.cause, sizeof(CauseInd_struct));
			memcpy(&msg_ptr->cpg.confTreat, &prm_ptr->cpg_req.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&msg_ptr->cpg.connNum, &prm_ptr->cpg_req.connNum, sizeof(ConnNum_struct));
			memcpy(&msg_ptr->cpg.utuInd, &prm_ptr->cpg_req.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->cpg.utuInfo, &prm_ptr->cpg_req.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_CGB:
			memcpy(&msg_ptr->cgb.cicGrpSpv, &prm_ptr->cgb_req.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&msg_ptr->cgb.rangeStatus, &prm_ptr->cgb_req.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGBA:
			memcpy(&msg_ptr->cgb.cicGrpSpv, &prm_ptr->cgb_rsp.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&msg_ptr->cgb.rangeStatus, &prm_ptr->cgb_rsp.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGU:
			memcpy(&msg_ptr->cgu.cicGrpSpv, &prm_ptr->cgu_req.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&msg_ptr->cgu.rangeStatus, &prm_ptr->cgu_req.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CGUA:
			memcpy(&msg_ptr->cgu.cicGrpSpv, &prm_ptr->cgu_rsp.cicGrpSpv, sizeof(CicGrpSpv_struct));
			memcpy(&msg_ptr->cgu.rangeStatus, &prm_ptr->cgu_rsp.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_GRS:
			memcpy(&msg_ptr->grs.rangeStatus, &prm_ptr->grs_req.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_GRA:
			memcpy(&msg_ptr->grs.rangeStatus, &prm_ptr->grs_rsp.rangeStatus, sizeof(RangeStatus_struct));
			break;
		case M_CON:
			app_prm2msg(&msg_ptr->con.app, &prm_ptr->setup_rsp.app);
			memcpy(&msg_ptr->con.backCall, &prm_ptr->setup_rsp.backCall, sizeof(BackCallInd_struct));
			memcpy(&msg_ptr->con.confTreat, &prm_ptr->setup_rsp.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&msg_ptr->con.connNum, &prm_ptr->setup_rsp.connNum, sizeof(ConnNum_struct));
			memcpy(&msg_ptr->con.utuInd, &prm_ptr->setup_rsp.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->con.utuInfo, &prm_ptr->setup_rsp.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_IAM:
			memcpy(&msg_ptr->iam.natConn, &prm_ptr->setup_req.natConn, sizeof(NatConnInd_struct));
			memcpy(&msg_ptr->iam.fwdCall, &prm_ptr->setup_req.fwdCall, sizeof(FwdCallInd_struct));
			memcpy(&msg_ptr->iam.callingPtyCat, &prm_ptr->setup_req.callingPtyCat, sizeof(CallingPtyCat_struct));
			memcpy(&msg_ptr->iam.transMedReq, &prm_ptr->setup_req.transMedReq, sizeof(TransMedReq_struct));
			memcpy(&msg_ptr->iam.calledPtyNum, &prm_ptr->setup_req.calledPtyNum, sizeof(CalledPtyNum_struct));
			app_prm2msg(&msg_ptr->iam.app, &prm_ptr->setup_req.app);
			memcpy(&msg_ptr->iam.callingPtyNum, &prm_ptr->setup_req.callingPtyNum, sizeof(CallingPtyNum_struct));
			memcpy(&msg_ptr->iam.collectCallReq, &prm_ptr->setup_req.collectCallReq, sizeof(CollectCallReq_struct));
			memcpy(&msg_ptr->iam.confTreat, &prm_ptr->setup_req.confTreat, sizeof(ConfTreatInd_struct));
			memcpy(&msg_ptr->iam.correlationId, &prm_ptr->setup_req.correlationId, sizeof(CorrelationId_struct));
			memcpy(&msg_ptr->iam.origCalledNum, &prm_ptr->setup_req.origCalledNum, sizeof(OrigCalledNum_struct));
			memcpy(&msg_ptr->iam.redirgNum, &prm_ptr->setup_req.redirgNum, sizeof(RedirgNum_struct));
			memcpy(&msg_ptr->iam.redirInfo, &prm_ptr->setup_req.redirInfo, sizeof(RedirInfo_struct));
			memcpy(&msg_ptr->iam.scfId, &prm_ptr->setup_req.scfId, sizeof(ScfId_struct));
			memcpy(&msg_ptr->iam.utuInd, &prm_ptr->setup_req.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->iam.utuInfo, &prm_ptr->setup_req.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_REL:
			memcpy(&msg_ptr->rel.cause, &prm_ptr->rel_req.cause, sizeof(CauseInd_struct));
			memcpy(&msg_ptr->rel.utuInd, &prm_ptr->rel_req.utuInd, sizeof(UserToUserInd_struct));
			memcpy(&msg_ptr->rel.utuInfo, &prm_ptr->rel_req.utuInfo, sizeof(UserToUserInfo_struct));
			break;
		case M_RLC:
			memcpy(&msg_ptr->rlc.cause, &prm_ptr->rel_rsp.cause, sizeof(CauseInd_struct));
			break;
		case M_RES:
			memcpy(&msg_ptr->res.susRes, &prm_ptr->res_req.susRes, sizeof(SusResInd_struct));
			break;
		case M_SUS:
			memcpy(&msg_ptr->sus.susRes, &prm_ptr->sus_req.susRes, sizeof(SusResInd_struct));
			break;
		case M_SAM:
			memcpy(&msg_ptr->sam.subseqNum, &prm_ptr->info_req.subseqNum, sizeof(SubseqNum_struct));
			break;
		default:
			break;
	}
}
