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

📄 cmiras.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
 * return : Non negative value on success
 *          Negative value on failure
 ************************************************************************/
int RVCALLCONV cmiRASStart(
    IN  HRASMGR     hRasMgr,
    IN  int         rasAddressNode,
    IN  RvUint32    startingSeqNum)
{
    rasModule*  ras;
    int         i, j;
    int         nodeId, chNodeId, srcNodeId;
    int         length;
    char        oid[16];

    /* Steps:
     1. Initialize all the messages
     2. Create the default values
     3. Set configuration related default values
     */

    if (hRasMgr == NULL) return RV_ERROR_UNKNOWN;
    ras = (rasModule *)hRasMgr;

    /* Set the starting sequence number to a random value */
    ras->requestSeqNum = (startingSeqNum % 65535) + 2;

    /* Make sure we're working with RAS at all */
    if ((ras->inRa == NULL) && (ras->outRa == NULL))
        return 0;

    /********************************
     * 1. Initialize all the messages
     ********************************/

    /* Initialize all default messages to some root values */
    for (i = 0; i < cmRASMaxTransaction; i++)
        for (j = 1; j < 4; j++)
            ras->defaultMessages[i][j] = pvtAddRoot(ras->hVal, ras->synMessage, 0, NULL);

    /* Encode the object identifier value we're using for our H225 protocol */
    length = utlEncodeOID(sizeof(oid), oid, RAS_OID_VERSION);

    /****************************
     * 2. Create default messages
     ****************************/

    /* gatekeeperRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASGatekeeper][cmRASTrStageRequest], __q931(gatekeeperRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);
    chNodeId = pvtAdd(ras->hVal, nodeId, __q931(endpointType), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(mc), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(undefinedNode), 0, NULL, NULL);

    /* gatekeeperConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASGatekeeper][cmRASTrStageConfirm], __q931(gatekeeperConfirm), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier),length, oid, NULL);

    /* gatekeeperReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASGatekeeper][cmRASTrStageReject], __q931(gatekeeperReject), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(rejectReason) _q931(undefinedReason) LAST_TOKEN}, 0, NULL);

    /* registrationRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASRegistration][cmRASTrStageRequest], __q931(registrationRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal,nodeId, __q931(protocolIdentifier), length, oid, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(discoveryComplete), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(keepAlive), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(willSupplyUUIEs), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(maintainConnection), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callSignalAddress), 0, NULL, NULL);

    chNodeId = pvtAdd(ras->hVal, nodeId, __q931(terminalType), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(mc), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(undefinedNode), 0, NULL, NULL);

    /* registrationConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASRegistration][cmRASTrStageConfirm], __q931(registrationConfirm), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(endpointIdentifier), 4, "\0E\0P", NULL);
    pvtAdd(ras->hVal, nodeId, __q931(willRespondToIRR), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(maintainConnection), 0, NULL, NULL);

    /* registrationReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASRegistration][cmRASTrStageReject], __q931(registrationReject), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(rejectReason) _q931(undefinedReason) LAST_TOKEN}, 0, NULL);

    /* unregistrationRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnregistration][cmRASTrStageRequest], __q931(unregistrationRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callSignalAddress), 0, NULL, NULL);

    /* unregistrationConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnregistration][cmRASTrStageConfirm], __q931(unregistrationConfirm), 0, NULL, NULL);

    /* unregistrationReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnregistration][cmRASTrStageReject], __q931(unregistrationReject), 0, NULL, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId,{_q931(rejectReason) _q931(undefinedReason) LAST_TOKEN}, 0, NULL );

    /* admissionRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASAdmission][cmRASTrStageRequest], __q931(admissionRequest), 0, NULL, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(callType) _q931(pointToPoint) LAST_TOKEN}, 0, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(endpointIdentifier), 4, "\0E\0P", NULL);
    pvtAdd(ras->hVal, nodeId, __q931(bandWidth), 640, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callReferenceValue), 1, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(activeMC), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(answerCall), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(srcInfo), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(canMapAlias), 1, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(willSupplyUUIEs), 0, NULL, NULL);

    /* admissionConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASAdmission][cmRASTrStageConfirm], __q931(admissionConfirm), 0, NULL, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(callModel) _q931(gatekeeperRouted) LAST_TOKEN}, 0, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(bandWidth), 640, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(willRespondToIRR), 0, NULL, NULL);

    chNodeId = pvtAdd(ras->hVal, nodeId, __q931(uuiesRequested), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(setup), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(callProceeding), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(connect), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(alerting), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(information), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(releaseComplete), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(facility), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(progress), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(empty), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(status), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(statusInquiry), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(setupAcknowledge), 0, NULL, NULL);
    pvtAdd(ras->hVal, chNodeId, __q931(notify), 0, NULL, NULL);

    /* admissionReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASAdmission][cmRASTrStageReject], __q931(admissionReject), 0, NULL, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(rejectReason) _q931(undefinedReason) LAST_TOKEN}, 0, NULL);

    /* bandwidthRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASBandwidth][cmRASTrStageRequest], __q931(bandwidthRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(endpointIdentifier), 4, "\0E\0P", NULL);
    pvtAdd(ras->hVal, nodeId, __q931(bandWidth), 0, NULL, NULL);

    /* bandwidthConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASBandwidth][cmRASTrStageConfirm], __q931(bandwidthConfirm), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(bandWidth), 0, NULL, NULL);

    /* bandwidthReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASBandwidth][cmRASTrStageReject], __q931(bandwidthReject), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(allowedBandWidth), 0, NULL, NULL);

    /* locationRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASLocation][cmRASTrStageRequest], __q931(locationRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(canMapAlias), 1, NULL, NULL);

    /* locationConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASLocation][cmRASTrStageConfirm], __q931(locationConfirm), 0, NULL, NULL);

    /* locationReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASLocation][cmRASTrStageReject], __q931(locationReject), 0, NULL, NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(rejectReason) _q931(undefinedReason) LAST_TOKEN}, 0, NULL);

    /* disengageRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASDisengage][cmRASTrStageRequest], __q931(disengageRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(endpointIdentifier), 4,"\0E\0P", NULL);
    __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(disengageReason) _q931(normalDrop) LAST_TOKEN}, 0, NULL);

    /* disengageConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASDisengage][cmRASTrStageConfirm], __q931(disengageConfirm), 0, NULL, NULL);

    /* disengageReject */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASDisengage][cmRASTrStageReject], __q931(disengageReject), 0, NULL, NULL);

    /* infoRequest */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASInfo][cmRASTrStageRequest], __q931(infoRequest), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callReferenceValue), 0, NULL, NULL);
    {
        RvUint8 callId[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        __pvtBuildByFieldIds(chNodeId, ras->hVal, nodeId, {_q931(callIdentifier) _q931(guid) LAST_TOKEN}, 16, (char*)callId);
    }

    /* infoRequestResponse - solicited */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASInfo][cmRASTrStageConfirm], __q931(infoRequestResponse), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callSignalAddress), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(needResponse), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(unsolicited), 0, NULL, NULL);

    /* nonStandardMessage */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASNonStandard][cmRASTrStageRequest], __q931(nonStandardMessage), 0, NULL, NULL);

    /* resourcesAvailableIndicate */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASResourceAvailability][cmRASTrStageRequest], __q931(resourcesAvailableIndicate), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocols), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(endpointIdentifier), 4, "\0E\0P", NULL);

    /* resourcesAvailableConfirm */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASResourceAvailability][cmRASTrStageConfirm], __q931(resourcesAvailableConfirm), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(protocolIdentifier), length, oid, NULL);

    /* infoRequestResponse - unsolicited */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnsolicitedIRR][cmRASTrStageRequest], __q931(infoRequestResponse), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(callSignalAddress), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(needResponse), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(unsolicited), 1, NULL, NULL);

    /* infoRequestAck */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnsolicitedIRR][cmRASTrStageConfirm], __q931(infoRequestAck), 0, NULL, NULL);

    /* infoRequestNak */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASUnsolicitedIRR][cmRASTrStageReject], __q931(infoRequestNak), 0, NULL, NULL);

    /* serviceControlIndication */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASServiceControl][cmRASTrStageRequest], __q931(serviceControlIndication), 0, NULL, NULL);
    pvtAdd(ras->hVal, nodeId, __q931(serviceControl), 0, NULL, NULL);

    /* serviceControlResponse */
    nodeId = pvtAdd(ras->hVal, ras->defaultMessages[cmRASServiceControl][cmRASTrStageConfirm], __q931(serviceControlResponse), 0, NULL, NULL);

    /*********************************************
     * 3. Set configuration related default values
     *********************************************/

    /* set RAS address in all relevant messages */
    /* GRQ */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASGatekeeper][cmRASTrStageRequest], {_anyField _q931(rasAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* GCF */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASGatekeeper][cmRASTrStageConfirm], {_anyField _q931(rasAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* RRQ */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASRegistration][cmRASTrStageRequest], {_anyField _q931(rasAddress) _nul(1) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* LRQ */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASLocation][cmRASTrStageRequest], {_anyField _q931(replyAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* IRQ */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASInfo][cmRASTrStageRequest], {_anyField _q931(replyAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* IRR - solicited */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASInfo][cmRASTrStageConfirm], {_anyField _q931(rasAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);
    /* IRR - unsolicited */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASUnsolicitedIRR][cmRASTrStageRequest], {_anyField _q931(rasAddress) LAST_TOKEN}, 0, NULL);
    pvtSetTree(ras->hVal, nodeId, ras->hVal, rasAddressNode);

    /* Set endpointVendor in RRQ */
    __pvtBuildByFieldIds(nodeId, ras->hVal, ras->defaultMessages[cmRASRegistration][cmRASTrStageRequest], {_anyField _q931(endpointVendor) LAST_TOKEN}, 0, NULL);
    __pvtGetNodeIdByFieldIds(srcNodeId, ras->hVal, ras->confNode, {_q931(registrationInfo) _q931(endpointVendor) LAST_TOKEN});
    if (srcNodeId >= 0)
    {
        /* Get it from configuration - registrationInfo.endpointVendor */
        pvtSetTree(ras->hVal, nodeId, ras->hVal, srcNodeId);
    }
    else
    {
        __pvtGetNodeIdByFieldIds(srcNodeId, ras->hVal, ras->confNode, {_q931(registrationInfo) _q931(terminalType) _q931(vendor) LAST_TOKEN});
        if (srcNodeId >= 0)
        {
            /* Get it from configuration - registrationInfo.terminalType.vendor */
            pvtSetTree(ras->hVal, nodeId, ras->hVal, srcNodeId);
        }
        else
        {
            /* Nothing in configuration - build some default one */
            chNodeId = pvtAdd(ras->hVal, nodeId, __q931(vendor), 0, NULL, NULL);
            pvtAdd(ras->hVal, chNodeId, __q931(t35CountryCode), 0, NULL, NULL);
            pvtAdd(ras->hVal, chNodeId, __q931(t35Extension), 0, NULL, NULL);
            pvtAdd(ras->hVal, chNodeId, __q931(manufacturerCode), 0, NULL, NULL);
        }
    }

    /* Set registration information inside the default messages and return the status */
    return cmiRASUpdateRegInfo((HRASMGR)ras, RV_TRUE);
}


/************************************************************************
 * cmiRASStop
 * purpose: Stop a RAS instance from running
 * input  : hRasMgr - RAS instance handle
 * output : none
 * return : Non negative value on success
 *          Negative value on failure
 ************************************************************************/
int RVCALLCONV cmiRASStop(
    IN  HRASMGR hRasMgr)
{
    rasModule*  ras;
    int i, j;

    if (hRasMgr == NULL) return RV_ERROR_UNKNOWN;
    ras = (rasModule *)hRasMgr;

    /* Delete all the default messages that we have */
    for (i = 0; i < cmRASMaxTransaction; i++)
        for (j = 1; j < 4; j++)

⌨️ 快捷键说明

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