📄 cmautorascall.c
字号:
/* Make sure we're trying to register again */
if ((autoras->internalState != autorasRegTrying) && (autoras->internalState != autorasRegFailed))
cmRegister(autoras->hApp);
}
break;
}
default:
/* Shouldn't happen */
break;
}
/* Make sure we close this transaction if it wasn't already closed */
if (call->tx == hsRas)
{
cmRASClose(hsRas);
call->tx = NULL;
}
emaUnlock((EMAElement)hsCall);
}
return 0;
}
/************************************************************************
* autoRasPrepareARQ
* purpose: Prepare and send an ARQ message to start a call (or continue
* after receiving a Setup)
* input : autoras - Automatic RAS module
* hsCall - Stack's call handle
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
static int autoRasPrepareARQ(IN autorasEndpoint* autoras, IN HCALL hsCall)
{
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
cmCallType callType;
cmAlias alias;
cmTransportAddress ta;
char buff[512];
int rate;
int i=0,j=0;
int ret;
RvBool outgoingCall = RV_FALSE;
cmTransportAddress * addrPtr = NULL;
if (call->tx != NULL)
cmRASClose(call->tx);
/* Maybe we already found an Alt GK */
if(autoras->setGK.port) addrPtr = &autoras->setGK;
/* Start an ARQ transaction - default destination (=gk) or the AltGK we found */
if (cmRASStartTransaction(autoras->hApp, (HAPPRAS)call, &call->tx, cmRASAdmission, addrPtr, hsCall) < 0)
return RV_ERROR_UNKNOWN;
/*Copy the required parameters from the call object */
if (cmCallGetParam(hsCall, cmParamCallType, 0, (int*)&callType, NULL) >= 0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamCallType, 0, callType, NULL);
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamCallModel, 0, cmCallModelTypeGKRouted, NULL);
alias.type = (cmAliasType)0;
alias.string = buff;
/* Put the party number in the destination if we're the origin of the call */
cmCallGetOrigin(hsCall, &outgoingCall);
if (outgoingCall)
{
if (cmCallGetParam(hsCall, cmParamCalledPartyNumber, 0, NULL, (char*)&alias)>=0 && alias.type==cmAliasTypeE164)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamDestInfo, i++, 0, (char*)&alias);
if (cmCallGetParam(hsCall,cmParamFullSourceAddress,0,NULL,NULL)<0)
{
/* no aliases set by the user, use terminalAliases */
cmCallSetParam(hsCall,cmParamFullSourceAddress,0,
((rasModule*)cmiGetRasHandle(autoras->hApp))->termAliasesNode, NULL);
}
}
while(cmCallGetParam(hsCall, cmParamDestinationAddress, j++, NULL, (char*)&alias)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamDestInfo, i++, 0, (char*)&alias);
if (cmCallGetParam(hsCall, cmParamRouteCallSignalAddress, 0, NULL, (char*)&ta)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamDestCallSignalAddress, 0, 0, (char*)&ta);
else if (cmCallGetParam(hsCall, cmParamDestCallSignalAddress, 0, NULL, (char*)&ta)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamDestCallSignalAddress, 0, 0, (char*)&ta);
i=0; j=0;
while(cmCallGetParam(hsCall, cmParamDestExtraCallInfo, i++, NULL, (char*)&alias)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamDestExtraCallInfo, j++, 0, (char*)&alias);
i=0; j=0;
while(cmCallGetParam(hsCall, cmParamSourceAddress, i++, NULL, (char*)&alias)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamSrcInfo, j++, 0, (char*)&alias);
if (cmCallGetParam(hsCall, cmParamSrcCallSignalAddress, 0, NULL, (char*)&ta)>=0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamSrcCallSignalAddress, 0, 0, (char*)&ta);
/* Set the bandwidth for this call */
if (cmCallGetParam(hsCall, cmParamRequestedRate, 0, &rate, NULL) >= 0)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamBandwidth, 0, rate * 2, NULL);
/* Set the GKID for this ARQ */
if(autoras->GKID.length)
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamGatekeeperID, 0, sizeof(autoras->GKID), (char *) &(autoras->GKID));
/* Make sure automatic RAS will get the responses */
cmiRASSetTrEventHandler(call->tx, autoRasAdmissionResponse);
/* Send the request */
ret = cmRASRequest(call->tx);
if (ret >= 0)
call->callState = autorasCallConnecting;
else
{
cmRASClose(call->tx);
call->tx = NULL;
}
return ret;
}
/************************************************************************
*
* Public functions
*
************************************************************************/
/************************************************************************
* cmiAutoRASCallStart
* purpose: Start the calls part of the automatic RAS.
* This function sets internal callbacks with the RAS module and
* initializes some autoRAS related variables.
* input : hAutoRas - Automatic RAS instance
* output : none
* return : none
************************************************************************/
void cmiAutoRASCallStart(IN HAUTORASMGR hAutoRas)
{
autorasEndpoint* autoras = (autorasEndpoint *)hAutoRas;
/* Set the event handler for the endpoint related RAS transactions */
cmiRASSetCallTrEventHandler(autoras->hApp, autoRasCallTransaction);
}
/************************************************************************
* cmiAutoRASCallCreate
* purpose: Create the call information needed for automatic RAS for
* a specified call
* input : hsCall - Stack's call handle
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallCreate(IN HCALL hsCall)
{
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
memset(call, 0, sizeof(autorasCall));
call->timer = NULL;
call->irrTimer = NULL;
call->callState = autorasCallIdle;
call->altGKInd = -1;
call->isTempRdrn = RV_FALSE;
return 0;
}
/************************************************************************
* cmiAutoRASCallDial
* purpose: Send an ARQ on a call to start the call with the GK
* input : hsCall - Stack's call handle
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallDial(IN HCALL hsCall)
{
int ret = 0;
autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));
switch (autoras->internalState)
{
case autorasRegistered:
/* We're registered - send ARQ */
ret = autoRasPrepareARQ(autoras, hsCall);
if (ret < 0)
{
/* Notify that we can't make this call */
autoras->event(hsCall, NULL, cmiAutoRasEvFailedOnARQ);
}
break;
case autorasRegFailed:
/* Endpoint failed to register... */
autoras->event(hsCall, NULL, cmiAutoRasEvCantRegister);
break;
case autorasRegNotTried:
/* Make sure we're trying to register... */
ret = cmRegister(autoras->hApp);
/* No break statement needed here - we want to wait with this call for a while... */
case autorasRegTrying:
{
/* Let's wait a little bit */
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
RvH323TimerCancel(autoras->hTimers, &call->timer);
/* Make sure to recheck the registration status every second */
call->timer = RvH323TimerStart(autoras->hTimers, autoRasWaitRegistration, (void*)call, (RvUint64)1000);
break;
}
}
return ret;
}
/************************************************************************
* cmiAutoRASCallSetRate
* purpose: Send a BRQ on a call to change the call bandwidth
* input : hsCall - Stack's call handle
* rate - requested rate for the call
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallSetRate(IN HCALL hsCall, int rate)
{
int res = 0;
autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
/* Make sure we're dealing with a connected call */
if (call->callState == autorasCallConnected)
{
/* We should initiate a DRQ */
if (call->tx != NULL)
cmRASClose(call->tx);
res = cmRASStartTransaction(autoras->hApp, (HAPPRAS)call, &call->tx, cmRASBandwidth, NULL, hsCall);
if (res >= 0)
{
/* Make sure automatic RAS will get the responses */
cmiRASSetTrEventHandler(call->tx, autoRasBandwidthResponse);
cmRASSetParam(call->tx, cmRASTrStageRequest, cmRASParamBandwidth, 0, rate * 2, NULL);
/* Send the request */
res = cmRASRequest(call->tx);
}
}
else
res = RV_ERROR_UNKNOWN;
return res;
}
#if 0 /* 2004.12.24.deleted by fujiangdong. */
/************************************************************************
* cmiAutoRASCallSetUnsolicitedIRR
* purpose: Initilises send of unsolicited IRRs (used for pregranted ARQ only
* input : hsCall - Stack's call handle
* irrFrequency - requested frequency ofIRRs
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallSetUnsolicitedIRR(IN HCALL hsCall, int irrFrequency)
{
autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
if (irrFrequency>0)
{
int res;
/* Create an IRR transaction and fill it in with the call's information
We're leaving this transaction open as we're sending it on each timeout
event for the IRR */
if (call->irrTx != NULL)
cmRASClose(call->irrTx);
res = cmRASStartTransaction(autoras->hApp, (HAPPRAS)call, &call->irrTx,
cmRASUnsolicitedIRR, NULL, hsCall);
if (res >= 0)
{
/* Set a timer for IRR messages sent to the GK */
call->timer = RvH323TimerStartPeriodic(autoras->hTimers, autoRasIrrTimeout, (void*)call, irrFrequency * 1000);
}
}
return 0;
}
#endif
/************************************************************************
* cmiAutoRASCallDrop
* purpose: Send a DRQ on a call to start disengaging the call from the GK
* input : hsCall - Stack's call handle
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallDrop(IN HCALL hsCall)
{
int ret = 0;
autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
/* Make sure we haven't already handled a DRQ for this call - we should ignore it */
switch(call->callState)
{
case autorasCallConnected:
case autorasCallConnecting:
/* We should initiate a DRQ */
if (call->tx != NULL)
cmRASClose(call->tx);
ret = cmRASStartTransaction(autoras->hApp, (HAPPRAS)call, &call->tx, cmRASDisengage, NULL, hsCall);
if (ret >= 0)
{
/* Make sure automatic RAS will get the responses */
cmiRASSetTrEventHandler(call->tx, autoRasDisengageResponse);
/* Send the request */
ret = cmRASRequest(call->tx);
}
if (ret >= 0)
call->callState = autorasCallDisconnecting;
else
{
cmRASClose(call->tx);
call->tx = NULL;
}
break;
case autorasCallDisconnecting:
/* do not close the call, wait for DCF */
return 0;
case autorasCallIdle:
/* close the call */
return RV_ERROR_UNKNOWN;
}
return ret;
}
/************************************************************************
* cmiAutoRASCallClose
* purpose: Free auto ras resources for the call
* input : hsCall - Stack's call handle
* output : none
* return : Non-negative value on success
* Negative value on failure
************************************************************************/
int cmiAutoRASCallClose(IN HCALL hsCall)
{
autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));
autorasCall* call = (autorasCall *)cmiGetAutoRas(hsCall);
autoRasCallIdleState(autoras, call);
return 0;
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -