📄 cmrasinit.c
字号:
return -13; /* Network problem */
}
/* We're always working with non-blocking sockets */
RvSocketSetBlocking(&app->rasUnicastConnection.socket, RV_FALSE);
/* bind the requested socket */
res = RvSocketBind(&app->rasUnicastConnection.socket, &rasUnicastAddress, app->portRange);
if (res != RV_OK)
{
/* User wanted a RAS port to listen to, but it seems the port is a little bit taken... */
RvSocketDestruct(&app->rasUnicastConnection.socket, RV_FALSE, NULL);
RvAddressDestruct(&rasUnicastAddress);
return -13; /* Network problem */
}
/* set buffer sizes and permit broadcasting */
RvSocketSetBuffers(&app->rasUnicastConnection.socket, 8192, 8192);
RvSocketSetBroadcast(&app->rasUnicastConnection.socket, RV_TRUE);
if (udpPort == 0)
{
/* Update the RAS port inside the configuration - we know it now */
paramLength = sizeof(RvAddress);
res = RvSocketGetLocalAddress(&app->rasUnicastConnection.socket, &rasUnicastAddress);
if (res == RV_OK)
{
RvInt32 port = (RvInt32)RvAddressGetIpPort(&rasUnicastAddress);
pvtSet(app->hVal, nodeId, -1, port, NULL);
}
}
/* Set the TTL value for the ras unicast handle */
{
RvInt32 maxTtl;
if (pvtGetChildByFieldId(app->hVal, app->rasConf, __q931(maxMulticastTTL), &maxTtl, NULL) < 0)
maxTtl = 20;
RvSocketSetMulticastTtl(&app->rasUnicastConnection.socket, maxTtl);
RvSocketSetMulticastInterface(&app->rasUnicastConnection.socket, &rasUnicastAddress);
}
/* Gatekeepers should also set a multicast address for listening */
app->rasMulticastConnection.type = RvH323ConnectionNone;
if (app->gatekeeper)
{
/* Get the multicast address the RAS is working with and set it */
__pvtGetByFieldIds(nodeId, app->hVal, app->rasConf, {_q931(rasMulticastAddress) _q931(ipAddress) LAST_TOKEN}, NULL, NULL, NULL);
if (nodeId >= 0)
{
RvAddress rasMulticastAddress;
RvUint32 multicastIp;
/* Get the address and port of the multicast address from the configuration */
pvtGetChildByFieldId(app->hVal, nodeId, __q931(port), &multicastPort, NULL);
pvtGetString(app->hVal, pvtGetChild(app->hVal, nodeId, __q931(ip), NULL), sizeof(multicastIp), (char*)&multicastIp);
RvAddressConstructIpv4(&rasMulticastAddress, multicastIp, (RvUint16)multicastPort);
res = RvSocketConstruct(&app->rasMulticastConnection.socket, RV_ADDRESS_TYPE_IPV4, RvSocketProtocolUdp);
if (res == RV_OK)
{
RvAddress bindAddr;
RvAddressConstructIpv4(&bindAddr, RV_ADDRESS_IPV4_ANYADDRESS, RvAddressGetIpPort(&rasMulticastAddress));
res = RvSocketBind(&app->rasMulticastConnection.socket, &bindAddr, app->portRange);
}
if (res == RV_OK)
{
/* We're always working with non-blocking sockets */
RvSocketSetBlocking(&app->rasMulticastConnection.socket, RV_FALSE);
/* set buffer sizes */
RvSocketSetBuffers(&app->rasMulticastConnection.socket, 0, 8192); /* We never send on this socket */
/* set multicast group */
RvSocketSetMulticastInterface(&app->rasMulticastConnection.socket, &rasMulticastAddress);
res = RvSocketJoinMulticastGroup(&app->rasMulticastConnection.socket, &rasMulticastAddress, &rasUnicastAddress);
}
if (res == RV_OK)
{
app->rasMulticastConnection.type = RvH323ConnectionRasMulticast;
app->rasMulticastConnection.context = app;
}
else
RvSocketDestruct(&app->rasMulticastConnection.socket, RV_FALSE, NULL);
RvAddressDestruct(&rasMulticastAddress);
if (res != RV_OK)
return res;
}
}
/* Make sure we update the application about its RAS address */
if (app->rasAddessID >= 0)
pvtDelete(app->hVal, app->rasAddessID);
app->rasAddessID = pvtAddRoot(app->hVal, app->hAddrSyn, 0, NULL);
{
cmTransportAddress uniAddr;
if (RvH323CoreToCmAddress(&rasUnicastAddress, &uniAddr) == RV_OK)
{
if (uniAddr.ip == 0)
{
RvAddress localAddr;
RvUint32 numAddrs = 1;
/* Get a local IP address from the machine */
res = RvHostLocalGetAddress(&numAddrs, &localAddr);
if ((res == RV_OK) && (numAddrs > 0))
{
uniAddr.ip = RvAddressIpv4GetIp(RvAddressGetIpv4(&localAddr));
RvAddressDestruct(&localAddr);
}
}
cmTAToVt(app->hVal, app->rasAddessID, &uniAddr);
}
}
/* Start the RAS and set the CS address */
RvRandomGeneratorGetValue(&app->randomGenerator, &randomValue);
cmiRASStart(app->rasManager, app->rasAddessID, (RvUint32)randomValue);
cmiRASUpdateCallSignalingAddress(app->rasManager, app->q931Chan, app->q931AnnexEChan);
/* Make sure we're waiting for unicast messages */
if (app->rasUnicastConnection.type == RvH323ConnectionRasUnicast)
{
RvFdConstruct(&app->rasUnicastConnection.fd, &app->rasUnicastConnection.socket);
RvSelectAdd(app->selectEngine, &app->rasUnicastConnection.fd, RV_SELECT_READ, RvRasSelectCb);
}
/* Wait for multicast messages if we can */
if (app->rasMulticastConnection.type == RvH323ConnectionRasMulticast)
{
RvFdConstruct(&app->rasMulticastConnection.fd, &app->rasMulticastConnection.socket);
RvSelectAdd(app->selectEngine, &app->rasMulticastConnection.fd, RV_SELECT_READ, RvRasSelectCb);
}
/* Start automatic RAS */
if (!app->manualRAS)
{
cmiAutoRASStart((HAPP)app);
if (pvtGetChild(app->hVal, app->rasConf, __q931(manualRegistration), NULL) < 0)
{
/* Seems like our automatic RAS should try and register when starting */
cmRegister((HAPP)app);
}
}
RvAddressDestruct(&rasUnicastAddress);
return 0;
}
/************************************************************************
* rasStop
* purpose: Stop the RAS module and all the network related with
* RAS.
* This makes the RAS ports to be removed and the endpoint to be
* unregistered.
* input : app - Stack handle
* output : none
* return : Non negative value on success
* Negative value on failure
************************************************************************/
int rasStop(IN cmElem* app)
{
int status = 0;
if (!app->manualRAS)
status = cmUnregister((HAPP)app);
if (app->rasUnicastConnection.type == RvH323ConnectionRasUnicast)
{
app->rasUnicastConnection.type = RvH323ConnectionNone;
RvSelectRemove(app->selectEngine, &app->rasUnicastConnection.fd);
RvFdDestruct(&app->rasUnicastConnection.fd);
RvSocketShutdown(&app->rasUnicastConnection.socket, RV_FALSE);
RvSocketDestruct(&app->rasUnicastConnection.socket, RV_FALSE, NULL);
}
if (app->rasMulticastConnection.type == RvH323ConnectionRasMulticast)
{
RvAddress multicastAddress;
RvAddress interfaceAddress;
RvUint32 multicastIp;
RvPvtNodeId nodeId;
app->rasMulticastConnection.type = RvH323ConnectionNone;
__pvtGetByFieldIds(nodeId, app->hVal, app->rasConf, {_q931(rasMulticastAddress) _q931(ipAddress) LAST_TOKEN}, NULL, NULL, NULL);
pvtGetString(app->hVal, pvtGetChild(app->hVal, nodeId, __q931(ip), NULL), sizeof(multicastIp), (char*)&multicastIp);
RvAddressConstructIpv4(&multicastAddress, multicastIp, RV_ADDRESS_IPV4_ANYPORT);
RvSocketGetLocalAddress(&app->rasMulticastConnection.socket, &interfaceAddress);
RvSocketLeaveMulticastGroup(&app->rasMulticastConnection.socket, &interfaceAddress, &interfaceAddress);
RvSelectRemove(app->selectEngine, &app->rasMulticastConnection.fd);
RvFdDestruct(&app->rasMulticastConnection.fd);
RvSocketShutdown(&app->rasMulticastConnection.socket, RV_FALSE);
RvSocketDestruct(&app->rasMulticastConnection.socket, RV_FALSE, NULL);
}
cmiRASStop(app->rasManager);
if (app->rasAddessID >= 0)
pvtDelete(app->hVal, app->rasAddessID);
app->rasAddessID = -1;
return status;
}
/************************************************************************
* rasEnd
* purpose: End the RAS module and all the network related with
* RAS.
* input : app - Stack handle
* output : none
* return : Non negative value on success
* Negative value on failure
************************************************************************/
int rasEnd(IN cmElem* app)
{
if (app->rasManager != NULL)
cmiRASEnd(app->rasManager);
if (app->hAutoRas)
cmiAutoRASEnd((HAPP)app);
return 0;
}
/************************************************************************
*
* Public API functions
*
************************************************************************/
/************************************************************************
* cmGetRASConfigurationHandle
* purpose: Gets the root Node ID of the RAS configuration tree.
* The application can then get and change configuration parameters
* for the control procedures.
* input : hApp - Application's stack handle
* output : none
* return : The PVT Node ID of the RASConfiguration subtree on success
* Negative value on failure
************************************************************************/
RVAPI
RvInt32 RVCALLCONV cmGetRASConfigurationHandle(
IN HAPP hApp)
{
cmElem* app = (cmElem *)hApp;
if (!hApp) return RV_ERROR_UNKNOWN;
cmiAPIEnter(hApp, "cmGetRASConfigurationHandle: hApp(0x%p)", hApp);
cmiAPIExit(hApp, "cmGetRASConfigurationHandle: [%d].", app->rasConf);
return app->rasConf;
}
/************************************************************************
* cmGetLocalRASAddress
* purpose: Gets the local RAS address
* input : hApp - Application's stack handle
* output : tr - The local RAS signal transport address.
* return : Non negative value on success
* Negative value on failure
************************************************************************/
RVAPI
RvInt32 RVCALLCONV cmGetLocalRASAddress(
IN HAPP hApp,
OUT cmTransportAddress* tr)
{
cmElem* app = (cmElem *)hApp;
int status;
if (!hApp) return RV_ERROR_UNKNOWN;
cmiAPIEnter(hApp, "cmGetLocalRASAddress(hApp=0x%p)", hApp);
/* Convert to address */
status = cmVtToTA(app->hVal, app->rasAddessID, tr);
cmiAPIExit(hApp, "cmGetLocalRASAddress: [%d].", status);
return status;
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -