⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmrasinit.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 3 页
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/

#include "rvhost.h"
#include "q931asn1.h"
#include "cmutils.h"
#include "cmAutoRas.h"
#include "cmAutoRasEP.h"
#include "cmAutoRasCall.h"
#include "cmrasinit.h"
#include "cmdebprn.h"
#include "cmCall.h"


#ifdef __cplusplus
extern "C" {
#endif

/************************************************************************
 *
 *                          Private functions
 *
 ************************************************************************/


/************************************************************************
 * handleAutoRasEvent
 * purpose: Callback function that handles Automatic RAS events
 * input  : hsCall  - Call handle of the transaction (NULL if not applicable)
 *          hsRas   - RAS transaction handle
 *          event   - Event that occured
 * output : none
 * return : Non negative value on success
 *          Negative value on failure
 ************************************************************************/
int RVCALLCONV handleAutoRasEvent(
    IN HCALL            hsCall,
    IN HRAS             hsRas,
    IN cmiAutoRasEvent  event)
{
    callElem* call = (callElem *)hsCall;
    HAPP hApp;
    cmElem* app;
    int chNodeId;
    HPVT hVal;

    if (hsRas != NULL)
        hApp = (HAPP)emaGetInstance((EMAElement)hsRas);
    else
        hApp=(HAPP)emaGetInstance((EMAElement)hsCall);
    app=(cmElem*)hApp;

    hVal = app->hVal;

    switch (event)
    {
        case cmiAutoRasEvGotRCF:
        {
            int responseId=cmiRASGetResponse(hsRas);
            responseId=pvtChild(app->hVal,responseId);

            app->rasGranted=0;
            if ((chNodeId = pvtGetChild(hVal, responseId, __q931(preGrantedARQ), NULL)) >= 0)
            {
                int tmpNodeId;
                int value;
                value=0;
                pvtGet(hVal,pvtGetChild(hVal,chNodeId,__q931(makeCall),NULL),NULL,NULL,&value,NULL);
                if (value) app->rasGranted|=makeCall;
                value=0;
                pvtGet(hVal,pvtGetChild(hVal,chNodeId,__q931(useGKCallSignalAddressToMakeCall),NULL),NULL,NULL,&value,NULL);
                if (value) app->rasGranted|=useGKCallSignalAddressToMakeCall;
                value=0;
                pvtGet(hVal,pvtGetChild(hVal,chNodeId,__q931(answerCall),NULL),NULL,NULL,&value,NULL);
                if (value) app->rasGranted|=answerCall;
                value=0;
                pvtGet(hVal,pvtGetChild(hVal,chNodeId,__q931(useGKCallSignalAddressToAnswer),NULL),NULL,NULL,&value,NULL);
                if (value) app->rasGranted|=useGKCallSignalAddressToAnswer;

                value=0;
                pvtGet(hVal,pvtGetChild(hVal,chNodeId,__q931(irrFrequencyInCall),NULL),NULL,NULL,&value,NULL);
                if (value) app->irrFrequencyInCall=value;


                tmpNodeId=pvtChild(hVal,pvtGetChild2(hVal,chNodeId,__q931(alternateTransportAddresses),__q931(annexE)));
                if (tmpNodeId>=0)
                {
                      cmVtToTA(hVal,tmpNodeId,&(app->annexEAddress));
                }
                if ((chNodeId=pvtGetChild(hVal,chNodeId,__q931(useSpecifiedTransport),NULL)>=0))
                {
                    /* check if we must use annex E */
                    if(pvtGetChild(hVal,chNodeId,__q931(annexE),NULL)>=0)
                        app->rasGrantedProtocol=1;

                    /* check if we must use TCP */
                    if(pvtGetChild(hVal,chNodeId,__q931(tcp),NULL)>=0)
                        app->rasGrantedProtocol=0;
                }
            }
            break;
        }

        case cmiAutoRasEvGotACF:
        {
            cmTransportAddress tpktAddress,annexEAddess;
            int bandwidth,chNodeId, tpktAddressNodeId, annexEAddressNodeId,
                destinationInfoNodeId, destExtraCallInfoNodeId, remoteExtensionAddressNodeId;
            int responseId=cmiRASGetResponse(hsRas);
            responseId=pvtChild(hVal,responseId);
            tpktAddressNodeId=pvtGetChild(hVal,responseId,__q931(destCallSignalAddress),NULL);

            /* This part of the code implements the CanMapAlias feature */
            /* When the stack receives an ACF with either one of the fields below, it copies the
               field to the setup message */
            if((destinationInfoNodeId=pvtGetChild(hVal,responseId,__q931(destinationInfo),NULL))>=0)
            {
                cmRASAlias RASAlias;
                char alias[64] = { 0 };
                int res;
                RvInt32 size=sizeof(RASAlias);
                RASAlias.string = alias;
                cmCallSetParam((HCALL)hsCall,cmParamFullDestinationAddress,0,destinationInfoNodeId,NULL);
                /* For Destination address, the addresses are scanned for an E-164 address, and if
                   found, it is set in the CalledPartyNumber param */
                for(res=pvtChild(hVal, destinationInfoNodeId);   /*start with first*/
                    res>=0;                                      /*as long as there are still children*/
                    res=pvtBrother(hVal, res))                   /*go down the sequence*/
                {
                    if(pvtGetChild(hVal, res, __q931(e164),NULL) >= 0)
                    {/* the child is of type E-164 */
                        vtToAlias(hVal, &RASAlias, res);
                        cmCallSetParam((HCALL)hsCall,cmParamCalledPartyNumber,0,size,(char *)&RASAlias);
                        break;
                    }
                }
            }
            if((destExtraCallInfoNodeId=pvtGetChild(hVal,responseId,__q931(destExtraCallInfo),NULL))>=0)
                cmCallSetParam((HCALL)hsCall,cmParamFullDestExtraCallInfo,0, destExtraCallInfoNodeId, NULL);
            if((remoteExtensionAddressNodeId=pvtGetChild(hVal,responseId,__q931(remoteExtensionAddress),NULL))>=0)
                cmCallSetParam((HCALL)hsCall,cmParamFullExtension,0, remoteExtensionAddressNodeId, NULL);

            if (cmCallGetOrigin((HCALL)call,NULL))
            {
                /* if there is a clear instruction from GK about the protocol to be used */
                if ((chNodeId=pvtGetChild(hVal,responseId,__q931(useSpecifiedTransport),NULL)>=0))
                {
                    /* check if we must use TCP */
                    if(pvtGetChild(hVal,chNodeId,__q931(tcp),NULL)>=0)
                    {
                        cmCallSetParam((HCALL)hsCall,cmParamAnnexE,0, 0, NULL);
                    }
                    /* check if we must use annex E */
                    if(pvtGetChild(hVal,chNodeId,__q931(annexE),NULL)>=0)
                    {
                        cmCallSetParam((HCALL)hsCall,cmParamAnnexE,0, 1, NULL);
                        annexEAddressNodeId=pvtChild(hVal,pvtGetChild2(hVal,responseId,__q931(alternateTransportAddresses),__q931(annexE)));
                        cmVtToTA(hVal,annexEAddressNodeId,&annexEAddess);
                        cmCallSetParam((HCALL)hsCall,cmParamDestinationAnnexEAddress,0, sizeof(cmTransportAddress),(char*)&annexEAddess);
                    }
                }
                /* GK doesn't specify the protocol to be used */
                /* Do nothing , save the default of cmParamAnnexE */

                cmVtToTA(hVal,tpktAddressNodeId,&tpktAddress);
                cmCallSetParam((HCALL)hsCall,cmParamDestinationIpAddress,0, sizeof(cmTransportAddress),(char*)&tpktAddress);
                if (call->routeCallSignalAddress<0)
                {
                    cmCallSetParam((HCALL)hsCall,cmParamDestCallSignalAddress,0, sizeof(cmTransportAddress),(char*)&tpktAddress);
                }
            }

            /* Get the bandwidth */
            pvtGetChildValue(hVal,responseId,__q931(bandWidth),&bandwidth,NULL);
            call->rate=bandwidth*50;

            /* Check and set the call model */
            {
                RvPstFieldId fieldId;
                pvtGet(hVal, pvtChild(hVal, pvtGetChild(hVal, responseId, __q931(callModel), NULL)), &fieldId, NULL, NULL, NULL);
                m_callset(call, gatekeeperRouted, (int)(fieldId != __q931(direct)));
            }

            callStartOK(call);
            break;
        }

        case cmiAutoRasEvCantRegister:
        {
            /* The endpoint couldn't register to a gatekeeper.
               We can only make this call if we have the DestCallSignalAddress and if
               the configuration allows IP calls without a gatekeeper */
            cmTransportAddress tpktAddress,annexEAddess;
            int size=sizeof(cmTransportAddress);
            if (pvtGetChild(hVal,app->rasConf,__q931(allowCallsWhenNonReg),NULL)>=0 &&
                (!cmCallGetOrigin((HCALL)call,NULL) ||
                 cmCallGetParam((HCALL)hsCall,cmParamDestinationIpAddress,0,&size ,(char*)&tpktAddress)>=0 ||
                 cmCallGetParam((HCALL)hsCall,cmParamDestinationAnnexEAddress,0, &size,(char*)&annexEAddess)>=0))
            {
                m_callset(call,dummyRAS,RV_TRUE);
                callStartOK(call);
            }
            else
            {
                callStartError(call);
                cmiAutoRASCallClose(hsCall);
            }
            break;
        }

        case cmiAutoRasEvTimedout:
        case cmiAutoRasEvFailedOnARQ:
        {
            cmiAutoRASCallClose(hsCall);
            /* if we received the call, we must raise the disconnected and idle events.
            otherwise, we are the initiators, and cmCallMake/Dial will just fail */
            if ((event == cmiAutoRasEvTimedout) || (!m_callget(call,callInitiator)))
                callStartError(call);
            break;
        }

        case cmiAutoRasEvCallRejected:
        {
            int responseId = cmiRASGetResponse(hsRas);
            int rejectId;
            RvPstFieldId reasonType;

            /* Find the reason - we'll know what to do from there */
            rejectId = pvtChild(hVal, responseId);
            rejectId = pvtGetChild(hVal, rejectId, __q931(rejectReason), NULL);
            rejectId = pvtChild(hVal, rejectId);
            pvtGet(hVal, rejectId, &reasonType, NULL, NULL, NULL);

            /* See what's the reason */
            switch(reasonType)
            {
                case __q931(callerNotRegistered):
                case __q931(invalidEndpointIdentifier):
                    cmRegister((HAPP)hApp);
                    cmiAutoRASCallClose(hsCall);
                    callStartError(call);
                    break;

                case __q931(routeCallToGatekeeper):
                    cmiAutoRASCallClose(hsCall);
                    callStartRoute(call);
                    break;

                case __q931(incompleteAddress):
                    if (cmCallGetOrigin(hsCall,NULL))
                    {
                        if(callIncompleteAddress(call) < 0)
                            cmiAutoRASCallClose(hsCall);
                    }
                    else
                    {
                        cmiAutoRASCallClose(hsCall);
                        callStartError(call);
                    }
                break;
                default:
                    cmiAutoRASCallClose(hsCall);
                    callStartError(call);
                break;
            }
            break;
        }

        case cmiAutoRasEvRateChanged:
        {
            /* BCF/BRQ received */
            int bandwidth;
            int rasMessageId=cmiRASGetResponse(hsRas);
            if (rasMessageId>=0)
            {
                /* We've got a response message - get bandwidth from there */
                rasMessageId=pvtChild(hVal,rasMessageId);
                if ((pvtGetChildValue(hVal,rasMessageId,__q931(bandWidth),&bandwidth,NULL))>=0)
                    call->rate=bandwidth*50;
            }
            else
            {
                /* We've got a BRQ */
                rasMessageId=cmiRASGetRequest(hsRas);
                rasMessageId=pvtChild(hVal,rasMessageId);
                if ((pvtGetChildValue(hVal,rasMessageId,__q931(bandWidth),&bandwidth,NULL))>=0)
                    call->rate=bandwidth*50;
            }

            /* Notify the application about the change of rate */
            callNewRate(call);
            break;
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -