/*
*********************************************************************************
*                                                                               *
* NOTICE:                                                                 *
*                                                                               *
*********************************************************************************
*/
 
    
/*********************************************************************************
 *                              <mgc_mgcp.c>                                                              
 *     This file should provide MGCP related APIs, ind callback and cnf callback, MGCP paramter create
 *
 *    Author                         Date
 *    ------                        ------
 *    Sam Yao                     Aug 2008                                                                                              
 *********************************************************************************/


/*-----------------------------------------------------------------------*/
/*                        INCLUDE HEADER FILES                           */
/*-----------------------------------------------------------------------*/



#include "./include/mgc_mgcp.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_port_info.h"
#include "./include/mgc_conn_info.h"
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_tandem_info.h"

static MGC_MGCP_SAP    mgcMgcpSap;


/*-----------------------------------------------------------------------
            MGCP    M A N A G E R
 ------------------------------------------------------------------------*/	 

BYTE mgc_mgcp_convert_cmd_to_mgcp(MGC_CMD_TYPE mgcCmd)
{
    switch(mgcCmd)
    {
        case MGC_CMD_CRCX:
			return MGCP_CMD_CRCX;
		case MGC_CMD_MDCX:
			return MGCP_CMD_MDCX;
		case MGC_CMD_DLCX:
			return MGCP_CMD_DLCX;
		case MGC_CMD_RQNT:
			return MGCP_CMD_RQNT;
		case MGC_CMD_NTFY:
			return MGCP_CMD_NTFY;
		case MGC_CMD_AUEP:
			return MGCP_CMD_AUEP;
		case MGC_CMD_RSIP:
			return MGCP_CMD_RSIP;
		default:
			return 127;
    }
}


char *mgc_mgcp_print_mgc_mode(MGC_CON_MODE mode)
{
    switch(mode)
    {
        case MGC_CON_MODE_INACTIVE:
			return "MGC_CON_MODE_INACTIVE";
		case MGC_CON_MODE_RECVONLY:
			return "MGC_CON_MODE_RECVONLY";
		case MGC_CON_MODE_SENDONLY:
			return "MGC_CON_MODE_SENDONLY";
		case MGC_CON_MODE_SENDRECV:
			return "MGC_CON_MODE_SENDRECV";
		case MGC_CON_MODE_OWN:
			return "MGC_CON_MODE_OWN";
		default:
			break;
    }

	return "MGC_CON_MODE_UNDEF";
}


MGC_CON_MODE mgc_mgcp_convert_to_mgc_mode(BYTE mode)
{
    switch(mode)
    {
        case MGCP_CON_MODE_INACTIVE:
			return MGC_CON_MODE_INACTIVE;
		case MGCP_CON_MODE_SENDONLY:
			return MGC_CON_MODE_SENDONLY;
		case MGCP_CON_MODE_RECVONLY:
			return MGC_CON_MODE_RECVONLY;
		case MGCP_CON_MODE_SENDRECV:
			return MGC_CON_MODE_SENDRECV;
		default:
			break;
    }

    return MGC_CON_MODE_INACTIVE;
}

BYTE mgc_mgcp_conver_to_mgcp_mode(MGC_CON_MODE mode)
{
    switch(mode)
    {
        case MGC_CON_MODE_INACTIVE:
			return MGCP_CON_MODE_INACTIVE;
		case MGC_CON_MODE_SENDONLY:
			return MGCP_CON_MODE_SENDONLY;
		case MGC_CON_MODE_RECVONLY:
			return MGCP_CON_MODE_RECVONLY;
		case MGC_CON_MODE_SENDRECV:
			return MGCP_CON_MODE_SENDRECV;
		default:
			break;
    }

    return  MGCP_CON_MODE_INACTIVE;
}

MGC_CMD_TYPE mgc_mgcp_convert_mgcp_to_cmd(BYTE mgcpCmd)
{
    switch(mgcpCmd)
    {
        case MGCP_CMD_CRCX:
			return MGC_CMD_CRCX;
		case MGCP_CMD_MDCX:
			return MGC_CMD_MDCX;
		case MGCP_CMD_DLCX:
			return MGC_CMD_DLCX;
		case MGCP_CMD_RQNT:
			return MGC_CMD_RQNT;
		case MGCP_CMD_NTFY:
			return MGC_CMD_NTFY;
		case MGCP_CMD_AUEP:
			return MGC_CMD_AUEP;
		case MGCP_CMD_RSIP:
			return MGC_CMD_RSIP;
		default:
			return MGC_CMD_UNDEF;
    }    
}

 
BOOL mgc_mgcp_check_codec_valid(MGC_VCTYPE codec)
{
    switch(codec)
    {
        case MGC_VCTYPE_PCMA:
		case MGC_VCTYPE_PCMU:
		case MGC_VCTYPE_GSM:
		case MGC_VCTYPE_GSM_EFR:
		case MGC_VCTYPE_AMR_12_2:
		case MGC_VCTYPE_G729B:
		case MGC_VCTYPE_AMR_10_2:
		case MGC_VCTYPE_AMR_7_95:
		case MGC_VCTYPE_AMR_7_4:
		case MGC_VCTYPE_AMR_6_7:
		case MGC_VCTYPE_AMR_5_15:
		case MGC_VCTYPE_AMR_5_9:
		case MGC_VCTYPE_AMR_4_75:
			return TRUE;
		default :
			break;
    }

	return FALSE;
}

/***************************************************************************
 * mgc_mgcp_match_codec_list
 * ------------------------------------------------------------------------
 * General: do codecList negotiate
 * Return Value: if failure return -1 , else return 0
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	
 ***************************************************************************/
int mgc_mgcp_match_codec_list(MGC_CODEC_LIST *dest, MGC_CODEC_LIST *aParty, MGC_CODEC_LIST *bParty)
{
    BYTE    i, j;
    MGC_CODEC_LIST *base = NULL;
	MGC_CODEC_LIST *highPri = NULL;
    MGC_CODEC_LIST base_list , high_list , res_list;
    
    if ((dest == NULL)||(aParty == NULL)||(bParty == NULL))
    {
        MGC_ERROR("mgc_match_codec_list: dest == NULL!\n\r");
        return -1;
    }
    dest->num = 0;
    dest->priority = 0;
    
    if (aParty->priority >= bParty->priority)
    {
        base    = bParty;
        highPri = aParty;
    }
    else
    {
        base    = aParty;
        highPri = bParty;
    }

    if (aParty->codec[0] == MGC_VCTYPE_G729B)
    {
        base    = bParty;
        highPri = aParty;		
    }
    else if (bParty->codec[0] == MGC_VCTYPE_G729B)
    {
        base    = aParty;
        highPri = bParty;
    }
    
    
	mgc_connect_codec_list_init(&base_list);	
	mgc_connect_codec_list_init(&high_list);	
	mgc_connect_codec_list_init(&res_list);
	
    for(i=0 ; i<MGC_VCTYPE_NUM ; i++)
    {
        if(mgc_mgcp_check_codec_valid(base->codec[i]) == TRUE)
    {
			base_list.codec[base_list.num] = base->codec[i];			
            base_list.num++;
        }

		if(mgc_mgcp_check_codec_valid(highPri->codec[i]) == TRUE)
        {
		    high_list.codec[high_list.num] = highPri->codec[i];
			high_list.num++;
		}
        }

    if(base_list.num != base->num)
        {
        MGC_WARN("codeclist rec wrong codec num!");
        }
	base_list.priority= base->priority;
	memcpy(base , &base_list , sizeof(MGC_CODEC_LIST));	

    if(high_list.num!= highPri->num)
    {
        MGC_WARN("codeclist rec wrong codec num!");
    }
    high_list.priority = highPri->priority;
	memcpy(highPri , &high_list , sizeof(MGC_CODEC_LIST));
    

    if((base->num == 0)&&(highPri->num == 0))
    {
        MGC_ERROR("negotiate list all are none!");
		return -1;
    }
    
    if (base->num == 0)
    {
		memcpy(&res_list , highPri , sizeof(MGC_CODEC_LIST));    
    }
    else if (highPri->num == 0)
    {
        memcpy(&res_list , base , sizeof(MGC_CODEC_LIST));
    }
    else if((base->num !=0 )&&(highPri->num != 0))
    {
    for (i = 0; i < highPri->num; i++)
    {
        for (j = 0; j < base->num; j++)
        {
            if (highPri->codec[i] == base->codec[j])
            {
                    res_list.codec[res_list.num] = highPri->codec[i];
					res_list.num++;
                break;
            }
        }
    }
    
	}

    if(res_list.num > 0)
    {
        res_list.priority = highPri->priority;
        memcpy(dest , &res_list , sizeof(MGC_CODEC_LIST));
        return 0;
    }

    MGC_ERROR("%s failed!" , __FUNCTION__);
	MGC_ERROR("base list:");
	for(i=0 ; i<base->num ; i++)
	{
	    MGC_ERROR("%s" , mgc_mgcp_print_vc_codec(base->codec[i]));
	}
	MGC_ERROR("high list:");
	for(i=0 ; i<highPri->num ; i++)
    {
	    MGC_ERROR("%s" , mgc_mgcp_print_vc_codec(highPri->codec[i]));
	}
        return -1;
    }


char *mgc_mgcp_print_ip(DWORD addr)
{
	struct sockaddr_in sin;

	sin.sin_addr.s_addr = addr;
	return ((char *) inet_ntoa(sin.sin_addr) );
}

/***************************************************************************
 * mgc_mgcp_ind_para_valid_check
 * ------------------------------------------------------------------------
 * General: check the incoming ind is valid
 * Return Value:  if valid return TRUE, else return FALSE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pPara - the paramter to be parsed
 ***************************************************************************/
BOOL mgc_mgcp_ind_para_valid_check(MGCP_PARA *pPara)
{
    if(pPara == NULL)
    {
        MGC_ERROR("%s: para is NULL" , __FUNCTION__);
        return FALSE;
    }

    if((pPara->flag & MGCP_PARA_FLAG_SL) != MGCP_PARA_FLAG_SL)	
    {
        MGC_ERROR("%s: start line is lost" , __FUNCTION__);
        return FALSE;
	}

    if(mgc_mgcp_print_ip(pPara->ip) == NULL)
    {
        MGC_ERROR("%s: srcIP is lost" , __FUNCTION__);        
        return FALSE;
    }

    if((pPara->localPort != MGC_MG_NETWORK_PORT)&&(pPara->localPort != MGC_MGC_NETWORK_PORT))
    {
        MGC_ERROR("%s: portNo is illegal" , __FUNCTION__);          
        return FALSE;
    }

    return TRUE;	
}


/***************************************************************************
 * mgc_mgcp_find_conn_by_con_id
 * ------------------------------------------------------------------------
 * General: find CONNCET_INFO object by parameter
 * Return Value:  if failure return NULL ,  else return the pointer of CONNCET_INFO object
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pPara - the paramter to be parsed
 ***************************************************************************/
CONNECT_INFO *mgc_mgcp_find_conn_by_con_id(MGCP_PARA *pPara)
{
    int i , j;
    PHY_PORT_INFO *pPhyPort = NULL;
	CHNL_INFO *pChnlInfo = NULL;
	CONNECT_INFO *pConnect = NULL;
	
    if(pPara == NULL)
	    return NULL;	

    if(pPara->sl.epNameMethod == MGCP_EP_NAME_STRUCTURED)	
    {
         pPhyPort = mgc_mg_info_find_port_by_name_and_portNo(pPara->sl.mgName, pPara->sl.trkNum, pPara->localPort); 
    }
    else
    {
        pPhyPort = mgc_mg_info_find_port_by_name(pPara->sl.mgName, pPara->localPort);
    }
	if(pPhyPort == NULL)
	    return NULL;	

    for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
    {
        pChnlInfo = pPhyPort->pChnlInfo[i];

		if(pChnlInfo == NULL)
		    continue;

		for(j=0 ; j<MGC_MAX_NUM_OF_CHNL_CON ; j++)
		{
		    pConnect = pChnlInfo->pConnection[j];

			if((mgc_connect_get_status(pConnect) != MGC_CONNECT_STATUS_CREATED)&&(mgc_connect_get_status(pConnect) != MGC_CONNECT_STATUS_CREATE))
			    continue;

			if(strcmp(pConnect->mediaAttr.conId , pPara->i.conId) != 0)
			    continue;
            MGC_DEBUG("conn[%d] is found" , pConnect->id);
			return pConnect;
		}
	}

    return NULL;
}


/***************************************************************************
 * mgc_mgcp_ind
 * ------------------------------------------------------------------------
 * General: ind callback func of the MGCP module
 * Return Value:  if failure return -1, else return 0
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	cmd - the MGCP command type
 *            usrPort -  the user id tagged by MGC and will be used in send response
 *            hdlPort - operate tag from MGCP layer
 *            pPara - MGCP msg
 ***************************************************************************/
int mgc_mgcp_ind(BYTE cmd, WORD *usrPort, WORD hdlPort, MGCP_PARA *pPara)
{
	CONNECT_INFO *pConnect = NULL;
    BOOL result = FALSE;
	PORT_INFO *pPortInfo = NULL;
	int retCode = 404;
    MGC_CMD_TYPE mgcCmd;
    MG_INFO *pMgInfo = NULL;
	
    if(mgc_mgcp_ind_para_valid_check(pPara) == FALSE)
	    return -1;	
	
    pPortInfo = mgc_port_info_get_unused_port();
	if(pPortInfo == NULL)
	    return -1;	
    
	mgcCmd = mgc_mgcp_convert_mgcp_to_cmd(cmd);
    
    pConnect = mgc_mgcp_find_conn_by_con_id(pPara);
    if((mgcCmd != MGC_CMD_AUEP)&&(mgcCmd != MGC_CMD_RSIP))
    {
    MGC_DEBUG("receive ind %s " , mgc_port_info_print_cmd(mgcCmd));
    }
	
    switch(mgcCmd)
    {
        case MGC_CMD_MDCX:
			 break;
        case MGC_CMD_DLCX:
			 break;
        case MGC_CMD_CRCX:			 
        case MGC_CMD_RQNT:
		case MGC_CMD_NTFY:			
			 if(pConnect == NULL)
	             pConnect = mgc_connect_assign_conn_by_para(pPara);	     
			 break;			 
        case MGC_CMD_RSIP:	
		case MGC_CMD_AUEP:	
             pMgInfo = mgc_mg_info_find_mg_by_name(pPara->sl.mgName);
			 retCode = 200;
			 if(pMgInfo == NULL)
                 retCode = 404;
             pPara->flag = 0;
	         pPara->sl.cmdRes = MGCP_RESPONSE;
	         pPara->flag |= MGCP_PARA_FLAG_SL;
		     pPara->localPort = MGC_MGCP_MG_PORT;
	         pPara->peerPort = MGC_MGCP_MGC_PORT;		
             MGCP_rsp(mgc_mgcp_get_sap_index(), cmd, *usrPort ,hdlPort, retCode,pPara);		
			 return 0;
		default:
		     break;	
    }

    if(pConnect != NULL)
    {
        result = mgc_connect_req_parse_para(pConnect, pPara);
    }

    if(result == FALSE)
    {
        if(pConnect != NULL)
		    mgc_connect_init(pConnect, pConnect->id);

	    pPara->flag = 0;
	    pPara->sl.cmdRes = MGCP_RESPONSE;
	    pPara->flag |= MGCP_PARA_FLAG_SL;
	    pPara->localPort = MGC_MGCP_MG_PORT;
	    pPara->peerPort = MGC_MGCP_MGC_PORT;		
        MGC_WARN("send ind %s resp %d" , mgc_port_info_print_cmd(mgcCmd) , retCode);
		MGCP_rsp(mgc_mgcp_get_sap_index(), cmd, *usrPort,hdlPort, retCode, pPara);
        /*send some error resp*/
        return 0;
    }

	*usrPort = pConnect->id;
    mgc_port_info_add_ind_to_port(pPortInfo , pConnect , mgcCmd , hdlPort, pPara->ip);
	mgc_port_info_set_oper_id(pPortInfo,MGC_OPER_ID_IND);
	mgc_port_info_set_fsm_time(pPortInfo,MGC_MGCF_TIMER_20MS);
	mgc_port_info_set_step_to_start(pPortInfo);
    return 0;
}


/***************************************************************************
 * mgc_mgcp_cnf
 * ------------------------------------------------------------------------
 * General: cnf callback func of the MGCP module
 * Return Value:  if failure return -1, else return 0
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	cmd - the MGCP command type
 *            usrPort -  the user id tagged by MGC and will be used in send response
 *            hdlPort - operate tag from MGCP layer
 *            pPara - MGCP msg
 ***************************************************************************/
int mgc_mgcp_cnf(BYTE cmd, WORD usrPort, WORD hdlPort, WORD retCode, MGCP_PARA *para)
{
    PORT_INFO *pPortInfo = NULL;
	int ret;
	pPortInfo = mgc_port_info_find_port_by_id(usrPort);
    if(pPortInfo == NULL)
    {
        MGC_WARN("lost mgcp response owner , usrPort[%d]" , usrPort);
		return -1;
    }

	ret = mgc_port_info_cnf(pPortInfo , cmd, hdlPort, retCode, para);
	return ret;
}


/***************************************************************************
 * mgc_bind_mgcp
 * ------------------------------------------------------------------------
 * General: bind MGC to the MGCP module
 * Return Value:  if failure return -1, else return SapIndex of the MGCP module
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pSap - the parameter of MGCP info in MGC module
 ***************************************************************************/
static int mgc_bind_mgcp(MGC_MGCP_SAP *pSap)
{
    if(pSap == NULL)
        return 0;

    sprintf(pSap->sapMgcp.name , "MGC");
	pSap->sapMgcp.MGCP_cnf = mgc_mgcp_cnf;
	pSap->sapMgcp.MGCP_ind = mgc_mgcp_ind;

	pSap->sapIndex = mgcp_bind(&pSap->sapMgcp);
    if(pSap->sapIndex < 0)
    {
        MGC_ERROR("MGCP %s bind failed!" , pSap->sapMgcp.name);
		return -1;
    }
	
    return pSap->sapIndex;
}

int mgc_bind_mgcp_setup(void)
{
	MGC_MGCP_SAP *pSap = NULL;

	pSap = &mgcMgcpSap;

	if(mgc_bind_mgcp(pSap) < 0)
	    return -1;	
    return 0;
}

/***************************************************************************
 * mgc_mgcp_get_sap_index
 * ------------------------------------------------------------------------
 * General: get MGCP sap of MGC module
 * Return Value:  MGCP sap
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	void
 ***************************************************************************/
int mgc_mgcp_get_sap_index(void)
{
    return(mgcMgcpSap.sapIndex);
}


/***************************************************************************
 * mgc_mgcp_str_to_vc_code
 * ------------------------------------------------------------------------
 * General: translate codec string into codec
 * Return Value:  MGC_VCTYPE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	codec -  codec name
 ***************************************************************************/
MGC_VCTYPE mgc_mgcp_str_to_vc_code(char *codec)
{
    if (strcmp(codec, "PCMA") == 0)
        return MGC_VCTYPE_PCMA;
    else if (strcmp(codec, "PCMU") == 0)
        return MGC_VCTYPE_PCMU;
    else if (strcmp(codec, "GSM") == 0)
        return MGC_VCTYPE_GSM;
    else if (strcmp(codec, "GSM-EFR") == 0)
        return MGC_VCTYPE_GSM_EFR;
    else if (strcmp(codec, "AMR") == 0)
        return MGC_VCTYPE_AMR_12_2;
    else if (strcmp(codec, "G729B") == 0)
        return MGC_VCTYPE_G729B;                
    else if (strcmp(codec, "AMR_12_2") == 0)
        return MGC_VCTYPE_AMR_12_2;    	
    else if (strcmp(codec, "AMR_10_2") == 0)
        return MGC_VCTYPE_AMR_10_2;    	
    else if (strcmp(codec, "AMR_7_95") == 0)
        return MGC_VCTYPE_AMR_7_95;    	
    else if (strcmp(codec, "AMR_7_4") == 0)
        return MGC_VCTYPE_AMR_7_4;    	
    else if (strcmp(codec, "AMR_6_7") == 0)
        return MGC_VCTYPE_AMR_6_7;    	
    else if (strcmp(codec, "AMR_5_15") == 0)
        return MGC_VCTYPE_AMR_5_15;    	
    else if (strcmp(codec, "AMR_5_9") == 0)
        return MGC_VCTYPE_AMR_5_9;    	
    else if (strcmp(codec, "AMR_4_75") == 0)
        return MGC_VCTYPE_AMR_4_75;         
    return MGC_VCTYPE_UNSUPPORT;
}


/***************************************************************************
 * mgc_mgcp_print_vc_codec
 * ------------------------------------------------------------------------
 * General: translate codec to string
 * Return Value:  codec name
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: vcCodec - MGC voice codec 
 ***************************************************************************/
char *mgc_mgcp_print_vc_codec(MGC_VCTYPE vcCodec)
{
    switch(vcCodec)
    {
        case MGC_VCTYPE_PCMA:
		    return "PCMA";
		case MGC_VCTYPE_PCMU:
			return "PCMU";
		case MGC_VCTYPE_GSM:
			return "GSM";
		case MGC_VCTYPE_GSM_EFR:
			return "GSM-EFR";
		case MGC_VCTYPE_G729B:
			return "G729B";
		case MGC_VCTYPE_AMR_12_2:
			return "AMR";	
		case MGC_VCTYPE_AMR_10_2:
			return "AMR_10_2";	
		case MGC_VCTYPE_AMR_7_95:
			return "AMR_7_95";	
		case MGC_VCTYPE_AMR_7_4:
			return "AMR_7_4";	
		case MGC_VCTYPE_AMR_6_7:
			return "AMR_6_7";	
		case MGC_VCTYPE_AMR_5_15:
			return "AMR_5_15";	
		case MGC_VCTYPE_AMR_5_9:
			return "AMR_5_9";	
		case MGC_VCTYPE_AMR_4_75:
			return "AMR_4_75";				
		default:
			return "UNSUPPORT";
    }
}

/***************************************************************************
 * mgc_mgcp_print_vc_num
 * ------------------------------------------------------------------------
 * General: translate codec to codec num
 * Return Value:  codec num
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	vcCodec -MGC voice codec
 ***************************************************************************/
int mgc_mgcp_print_vc_num(MGC_VCTYPE vcCodec)
{
    switch(vcCodec)
    {
        case MGC_VCTYPE_PCMA:
		    return 8;
		case MGC_VCTYPE_PCMU:
			return 0;
		case MGC_VCTYPE_GSM:
			return 3;
		case MGC_VCTYPE_GSM_EFR:
			return 84;
		case MGC_VCTYPE_G729B:
			return 118;
		case MGC_VCTYPE_AMR_12_2:
			return 71;			
		case MGC_VCTYPE_AMR_10_2:
			return 70;
		case MGC_VCTYPE_AMR_7_95:
			return 69;
		case MGC_VCTYPE_AMR_7_4:
			return 68;
		case MGC_VCTYPE_AMR_6_7:
			return 67;
		case MGC_VCTYPE_AMR_5_15:
			return 65;
		case MGC_VCTYPE_AMR_5_9:
			return 66;		
		case MGC_VCTYPE_AMR_4_75:
			return 64;				
		default:
			return 8;
    }

}

/***************************************************************************
 * mgc_mgcp_create_connect_dest_ip
 * ------------------------------------------------------------------------
 * General:create mgcp dest ip
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_dest_ip(CONNECT_INFO *pConnect , MGCP_PARA *pPara)	
{
    MG_INFO *pMgInfo = NULL;
	MGC_SAP *pMgcSap = NULL;
	MGCF_OPER_STEP *pStep = NULL;
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    pMgcSap = mgc_connect_get_conn_report_sap(pConnect);
    if(pMgcSap == NULL)
	    return FALSE;	

    pStep = mgc_connect_get_step_info(pConnect);
	if(pStep == NULL)
	    return FALSE;	
         	
    pMgInfo = mgc_connect_get_own_mg_info(pConnect);
    if(pMgInfo == NULL)
        return FALSE;	

    if(pMgcSap->usrType == MGC_USER_TYPE_MGC)
    {
        pPara->ip = pMgInfo->mgAttr.ip;    
    }
	else if(pMgcSap->usrType == MGC_USER_TYPE_MG)
	{
	    pPara->ip = pStep->stepInfo.remoteIp;
	}
	return TRUE;
}

/***************************************************************************
 * mgc_mgcp_create_connect_port
 * ------------------------------------------------------------------------
 * General:create mgcp dest port
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_port(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	PHY_PORT_INFO *pPhyPort = NULL;
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;


    pPhyPort= mgc_connect_get_own_phy_port_info(pConnect);
    if(pPhyPort == NULL)
        return FALSE;	

    if(pPhyPort->pMgcSap == NULL)
    {
        MGC_ERROR("mgcPhyPort[%d] lost owner" , pPhyPort->id);
        return FALSE;	
    }
	    
    switch(pPhyPort->pMgcSap->usrType)
    {
        case MGC_USER_TYPE_MG:
			pPara->localPort = MGC_MGCP_MG_PORT;
			pPara->peerPort = MGC_MGCP_MGC_PORT;
			break;
		case MGC_USER_TYPE_MGC:
			pPara->localPort= MGC_MGCP_MGC_PORT;
			pPara->peerPort= MGC_MGCP_MG_PORT;
			break;
		default:
			MGC_ERROR("mgcSap[%d] %s , unsupport type %d" , pPhyPort->pMgcSap->id , pPhyPort->pMgcSap->usrName, pPhyPort->pMgcSap->usrType);
			return FALSE;
    }

	return TRUE;
}

/***************************************************************************
 * mgc_mgcp_create_connect_resp_start_line
 * ------------------------------------------------------------------------
 * General:create mgcp response  start line
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_resp_start_line(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;
	
	pPara->sl.cmdRes = MGCP_RESPONSE;
	pPara->flag |= MGCP_PARA_FLAG_SL;
    return TRUE;
}

/***************************************************************************
 * mgc_mgcp_create_connect_req_start_line
 * ------------------------------------------------------------------------
 * General:create mgcp request start line
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_req_start_line(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MG_INFO *pMgInfo = NULL;
    MGCP_SL *pSl = NULL;
	PHY_PORT_INFO *pPhyPort = NULL;
	CHNL_INFO *pChnlInfo = NULL;
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    pChnlInfo = mgc_connect_get_own_chnl_info(pConnect);
	if(pChnlInfo == NULL)
	    return FALSE;	

    pPhyPort = mgc_connect_get_own_phy_port_info(pConnect);
    if(pPhyPort == NULL)
	    return FALSE;  	

    pMgInfo = mgc_connect_get_own_mg_info(pConnect);
    if(pMgInfo == NULL)
        return FALSE;	

    pSl = &pPara->sl;
	pSl->cmdRes = MGCP_COMMAND;
	pSl->epNameMethod = pMgInfo->mgAttr.epDes;
	pSl->mgType = pMgInfo->mgAttr.mgType;
	
		
    switch(pPhyPort->portType)
    {
         case MGC_PHY_PORT_TYPE_E1:
		 	pSl->portType = MGC_PHY_PORT_TYPE_E1;
		 	break;
		 case MGC_PHY_PORT_TYPE_T1:
		 	pSl->portType = MGC_PHY_PORT_TYPE_T1;
			break;
		 case MGC_PHY_PORT_TYPE_ANALOG:
			pSl->portType = MGC_PHY_PORT_TYPE_ANALOG;		
		 	break;
		 case MGC_PHY_VIRTUAL_TYPE_INTERNAL:
		 case MGC_PHY_VIRTUAL_TYPE_ANN:		
		 case MGC_PHY_VIRTUAL_TYPE_TANDEM:
		 case MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE:
		 	 pSl->portType = 0 ; //?? uncertain
		 	break;  
		 default:
		 	 MGC_WARN("unsupport port type %d" , pPhyPort->portType);
			 return FALSE;
    }
    
    pSl->trkNum = pPhyPort->portNo;	
	pSl->chlNum = mgc_chnl_info_get_chnl_no_of_phy(pChnlInfo , pPhyPort);
    sprintf(pSl->mgName , "%s" , pMgInfo->mgAttr.domain);
	pPara->flag |= MGCP_PARA_FLAG_SL;

	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_create_connect_con_mode
 * ------------------------------------------------------------------------
 * General:create mgcp mode info
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_con_mode(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MGCF_OPER_STEP *pStep = NULL;
    if((pConnect == NULL) || (pPara == NULL)||(pConnect->pOperStep == NULL))
        return FALSE;

    pStep = pConnect->pOperStep;
    mgc_connect_set_conn_mode(pConnect, pStep->stepInfo.mode);
    pPara->m.mode = mgc_mgcp_conver_to_mgcp_mode(pConnect->mediaAttr.conMode);
    pPara->flag |= MGCP_PARA_FLAG_M;
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_create_connect_con_id
 * ------------------------------------------------------------------------
 * General:create mgcp connection id
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_con_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    if(strlen(pConnect->mediaAttr.conId) == 0)
        return TRUE;
 
    sprintf(pPara->i.conId , "%s" , pConnect->mediaAttr.conId);
    pPara->flag |= MGCP_PARA_FLAG_I;	 

    return TRUE;
}

/***************************************************************************
 * mgc_mgcp_create_connect_call_id
 * ------------------------------------------------------------------------
 * General:create mgcp call id
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_call_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    if(strlen(pConnect->mediaAttr.callId) == 0)
	    return TRUE;
   
	sprintf(pPara->c.callId, "%s" , pConnect->mediaAttr.callId);
    pPara->flag |= MGCP_PARA_FLAG_C;
	return TRUE;	
}


/***************************************************************************
 * mgc_mgcp_create_connect_pkg_sig
 * ------------------------------------------------------------------------
 * General:create mgcp signal event
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_pkg_sig(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MGCF_OPER_STEP *pStep = NULL;
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    pStep = mgc_connect_get_step_info(pConnect);
	if(pStep == NULL)
	    return FALSE;	

    if(pStep->stepInfo.sigEn == FALSE)    // no sig is needed
        return TRUE;
	
    pPara->s.pkg = pStep->stepInfo.pkgSig.pkg;
	pPara->s.signal = pStep->stepInfo.pkgSig.signal;	
	pPara->flag |= MGCP_PARA_FLAG_S;
    MGC_DEBUG("conn[%d] create pkg[%d]sig[%d]" , pConnect->id , pConnect->mediaAttr.pkgSignal.pkg ,pConnect->mediaAttr.pkgSignal.signal);	
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_create_connect_pkg_req
 * ------------------------------------------------------------------------
 * General:create mgcp req event
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_pkg_req(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MGCF_OPER_STEP *pStep = NULL;
    if((pConnect == NULL) || (pPara == NULL))
        return FALSE;

    pStep = mgc_connect_get_step_info(pConnect);
	if(pStep == NULL)
	    return FALSE;	

    if(pStep->stepInfo.reqEn== FALSE)    // no sig is needed
        return TRUE;
	
    pPara->r.pkg = pStep->stepInfo.pkgReq.pkg;
	pPara->r.event= pStep->stepInfo.pkgReq.req;	
	pPara->flag |= MGCP_PARA_FLAG_R;
    MGC_DEBUG("conn[%d] create pkg[%d]req[%d]" , pConnect->id , pConnect->mediaAttr.pkgReq.pkg ,pConnect->mediaAttr.pkgReq.req);	
	return TRUE;
}



/***************************************************************************
 * mgc_mgcp_create_connect_local_opt
 * ------------------------------------------------------------------------
 * General:create mgcp local description
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_local_opt(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	MG_INFO *pMgInfo = NULL;
	MGC_TANDEM_INFO *pTandem = NULL;

	pMgInfo = mgc_connect_get_own_mg_info(pConnect);
    if((pConnect == NULL) || (pPara == NULL)||(pMgInfo == NULL))
        return FALSE;

    if(pConnect->pTandem)
    {
        pTandem = pConnect->pTandem;

		if(mgc_tandem_info_get_conn_pos(pTandem , pConnect) == MGC_TANDEM_CONN_POS_RX)
		{
		    sprintf(pPara->l.esCci , "%s" , pTandem->escci);			
			pPara->l.flag |= MGCP_PARA_L_FLAG_ESS_CCI;
    	}


		if(mgc_tandem_info_get_conn_pos(pTandem , pConnect) == MGC_TANDEM_CONN_POS_TX)
		{
		    sprintf(pPara->l.esCci , "%s" , pTandem->escci);			
			pPara->l.flag |= MGCP_PARA_L_FLAG_ESS_CCI;	
		}		
    }

    if(pMgInfo->mgAttr.mgType == MGC_MG_TYPE_IPBSS)
    {
        switch(pConnect->mediaAttr.vocoderType)
        {
            case MGC_VCTYPE_AMR_12_2: 
			case MGC_VCTYPE_AMR_10_2:
			case MGC_VCTYPE_AMR_7_95:
			case MGC_VCTYPE_AMR_7_4:
			case MGC_VCTYPE_AMR_6_7:
			case MGC_VCTYPE_AMR_5_15:
			case MGC_VCTYPE_AMR_5_9:
			case MGC_VCTYPE_AMR_4_75:  				
				sprintf(pPara->l.codec , "AMR");
				break;
			default:
                sprintf(pPara->l.codec , "%s"  , mgc_mgcp_print_vc_codec(pConnect->mediaAttr.vocoderType));					
				break;
        }	    
    }
	else
	{
        sprintf(pPara->l.codec , "%s"  , mgc_mgcp_print_vc_codec(pConnect->mediaAttr.vocoderType));	
	}

    pPara->l.p = pConnect->mediaAttr.ptime;
	pPara->l.ecDisable = pConnect->mediaAttr.ecDisable;
	pPara->l.ssDisable = pConnect->mediaAttr.ssDisable;

	pPara->flag |= MGCP_PARA_FLAG_L;
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_create_connect_sdp
 * ------------------------------------------------------------------------
 * General:create mgcp sdp info
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP msg
 *           pPara -  the MSG which will be send out
 ***************************************************************************/
BOOL mgc_mgcp_create_connect_sdp(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	CONNECT_INFO *pTmpConnect = NULL;
    MGCF_STEP_INFO *pStep = NULL;
	PUB_SDP_A *pSdpAttr = NULL;
	PUB_SDP_MEDIA *pMedia = NULL;
	int i;
	char tmp[PUB_SDP_MAX_ATTR_LEN];
	
    if((pConnect == NULL) || (pPara == NULL)||(pConnect->pOperStep == NULL))
        return FALSE;

    pStep = &(pConnect->pOperStep->stepInfo);
	pTmpConnect = pStep->pPeerConn;
    pMedia = &pPara->sdp.medias.medias[0];
	if(pTmpConnect == NULL)
		return FALSE;	
	
    memcpy(&pPara->sdp , &(pTmpConnect->mediaAttr.sdp) , sizeof(PUB_SDP_MSG));	
    pMedia->attrs.num = 0;
    if((pMedia->flag & PUB_SDP_FLAG_A) == PUB_SDP_FLAG_A)
    {
         for(i=0 ;  i< pMedia->attrs.num ; i++ )
         {
             pSdpAttr = &pMedia->attrs.attrs[i];
             if(pSdpAttr->aType != 0)
             {
                  pMedia->attrs.num++;
                  continue;	             
             }    

			 memset(pSdpAttr->aValue , 0 , PUB_SDP_MAX_ATTR_LEN);		 
         }
    }

	
    pPara->sdp.medias.num = 1;
	pMedia->m.payloads[0] = mgc_mgcp_print_vc_num(pConnect->mediaAttr.vocoderType);
        
    switch(pConnect->mediaAttr.conMode)
    {
        case MGC_CON_MODE_RECVONLY:
			 sprintf(tmp , "recvonly");
			 break;
		case MGC_CON_MODE_SENDONLY:
			 sprintf(tmp, "sendonly");
			 break;
		case MGC_CON_MODE_SENDRECV:
			 sprintf(tmp , "sendrecv");
			 break;
		default:
			 sprintf(tmp, "inactive");
			 break; 
    }

    pSdpAttr = NULL;
    for(i=0 ; i<PUB_SDP_MAX_ATTR_NUM ; i++)
    {   
        pSdpAttr = &pMedia->attrs.attrs[pMedia->attrs.num];

		if(pSdpAttr->aType != 0)
		    continue;

		sprintf(pSdpAttr->aValue , "%s" , tmp);
		pMedia->attrs.num++;
        pPara->sdp.medias.medias[0].flag |= PUB_SDP_FLAG_A;		
		break;
    }

	pPara->flag |= MGCP_PARA_FLAG_SDP;

	if((pPara->sdp.flag & PUB_SDP_FLAG_O) == 0)
	{
	   MGC_WARN("lost sdp");
	}
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_parse_connect_local_opt
 * ------------------------------------------------------------------------
 * General: parse mgcp local descritpion
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_local_opt(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	MGCP_L *pL = NULL;
    MEDIA_ATTR *pMediaAttr = NULL;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_L) != MGCP_PARA_FLAG_L)
        return TRUE;
	
    pL = &pPara->l;
    pMediaAttr = &pConnect->mediaAttr;
	
	pMediaAttr->ecDisable = pL->ecDisable;
	pMediaAttr->ssDisable = pL->ssDisable;
	pMediaAttr->ptime = pL->p;
	pMediaAttr->vocoderType = mgc_mgcp_str_to_vc_code(pL->codec);
	
    return TRUE;
}


/***************************************************************************
 * mgc_mgcp_parse_connect_mode
 * ------------------------------------------------------------------------
 * General: parse mgcp connection mode
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_mode(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	MGCP_M *pMode = NULL;
    MGC_CON_MODE mode;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_M) != MGCP_PARA_FLAG_M)
        return TRUE;
	
    pMode = &pPara->m;
    mode = mgc_mgcp_convert_to_mgc_mode(pPara->m.mode);
    mgc_connect_set_conn_mode(pConnect, mode);
	return TRUE;
}

/***************************************************************************
 * mgc_mgcp_parse_connect_call_id
 * ------------------------------------------------------------------------
 * General: parse mgcp call id
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_call_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MEDIA_ATTR *pMediaAttr = NULL;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_C) != MGCP_PARA_FLAG_C)
        return TRUE;
	
    pMediaAttr = &pConnect->mediaAttr;

	sprintf(pMediaAttr->callId , "%s" , pPara->c.callId);
	return TRUE;
}

/***************************************************************************
 * mgc_mgcp_parse_connect_pkg_event
 * ------------------------------------------------------------------------
 * General: parse mgcp observed event
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_pkg_event(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MEDIA_ATTR *pMediaAttr = NULL;
	MGCP_O *pPkgEvent = NULL;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_O) != MGCP_PARA_FLAG_O)
        return TRUE;
	
    pMediaAttr = &pConnect->mediaAttr;
    pPkgEvent = &pPara->o;
	
    pMediaAttr->pkgEvent.pkg = pPkgEvent->package;
	pMediaAttr->pkgEvent.event = pPkgEvent->event;
	return TRUE;
}

/***************************************************************************
 * mgc_mgcp_parse_connect_pkg_sig
 * ------------------------------------------------------------------------
 * General: parse mgcp signal event
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_pkg_sig(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
    MEDIA_ATTR *pMediaAttr = NULL;
	MGCP_S *pPkgSig = NULL;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_S) != MGCP_PARA_FLAG_S)
        return TRUE;
	
    pMediaAttr = &pConnect->mediaAttr;
    pPkgSig= &pPara->s;
	
    pMediaAttr->pkgSignal.pkg = pPkgSig->pkg;
	pMediaAttr->pkgSignal.signal= pPkgSig->signal;
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_parse_connect_sdp
 * ------------------------------------------------------------------------
 * General: parse mgcp sdp info
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which handle incoming MGCP msg
 *           pPara -  the MSG which is received
 ***************************************************************************/
BOOL mgc_mgcp_parse_connect_sdp(CONNECT_INFO *pConnect , MGCP_PARA *pPara)
{
	PUB_SDP_MSG *pSdp = NULL;
    MEDIA_ATTR *pMediaAttr = NULL;

    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if((pPara->flag & MGCP_PARA_FLAG_SDP) != MGCP_PARA_FLAG_SDP)
	    return TRUE;

    pSdp = &pPara->sdp;
	pMediaAttr = &pConnect->mediaAttr;

	memcpy(&pMediaAttr->sdp , pSdp , sizeof(PUB_SDP_MSG));
     	
	return TRUE;
}


/***************************************************************************
 * mgc_mgcp_response_msg
 * ------------------------------------------------------------------------
 * General: send mgcp response
 * Return Value:  if failure return FALSE, else return TRUE
 * ------------------------------------------------------------------------
 * Arguments:
 * Input: 	pConnect - the connect which will send out MGCP resp
 *           pPara -  the MSG which will be sent
 *           retCode -  response code
 ***************************************************************************/
BOOL mgc_mgcp_response_msg(CONNECT_INFO *pConnect, MGCP_PARA *pPara, int retCode)
{
    MGCF_OPER_STEP *pStep = NULL;
	BYTE cmd;
	
    if((pConnect == NULL)||(pPara == NULL))
        return FALSE;

    if(mgc_mgcp_create_connect_resp_start_line(pConnect, pPara) == FALSE)
	    return FALSE;	

    if(mgc_mgcp_create_connect_port(pConnect, pPara) == FALSE)
	    return FALSE;	
	
    if(mgc_mgcp_create_connect_dest_ip(pConnect, pPara) == FALSE)
	    return FALSE;	
	
    pStep = mgc_connect_get_step_info(pConnect);
	if(pStep == NULL)
	    return FALSE;	

	cmd = mgc_mgcp_convert_cmd_to_mgcp(pStep->stepInfo.cmd);
    MGCP_rsp(mgc_mgcp_get_sap_index(), cmd, pConnect->id , pStep->hdlPort, retCode, pPara);
    return TRUE;
}
