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

📄 init.c

📁 h248另一部分的实现源码
💻 C
📖 第 1 页 / 共 2 页
字号:
  /* startup the voip discovery protocol */  printf("Starting VoIP Discovery Module ...\n");  HandsetDisplayString("VoIP Discovery ...",3);  VoipDiscoveryStart(g_oNumInterfaces);    /* startup SNMP */#ifndef NUSE_SNMP  printf("Starting SNMP ...\n");  HandsetDisplayString("SNMP Stack ...",3);  snmp_handle = SnmpAgentInit();  SnmpRegisterTcpIp(snmp_handle);  Mib2Initialize();#endif    /* Initialize NTP and handset clock */  HandsetDisplayString("Clock (NTP) ...",3);  HandsetInitializeClock();    /* Register callback functions for when an interface   * is closed and/or reopened */  {    int iSocketFd = socket(AF_INET, SOCK_DGRAM, 0);    ASSERT(iSocketFd);    ioctl(iSocketFd, SIOCADDCLOSECBK, _InterfaceClose);    ioctl(iSocketFd, SIOCADDOPENCBK, _InterfaceOpen);    close(iSocketFd);  }    /*   * Start services which use interface 0 (this accounts for   * interface 0 being open before the callback functions   * above are registered)   */  _InterfaceOpen(0);  #ifdef NETWORK_MULTIIF    {    /* We need to wait until the WAN interface is up     * and has an IP address */    struct timespec stTime;        /* set loop time */    stTime.tv_sec=0;    stTime.tv_nsec=200*1000000; /* 200ms */        while(1) {      DWORD dwFlags = 0;            SetupNetGetIfStatus(1, &dwFlags);            if ((dwFlags & IFF_IPUP) &&           (dwFlags & IFF_UP)) {        break;      }            /* give network stack time to execute */      nanosleep(&stTime,NULL);    }  }    /*   * Start services which use interface 1 (this accounts for   * interface 1 being open before the callback functions   * above are registered)   */  _InterfaceOpen(1);  #endif  // NETWORK_MULTIIF     for (i = 0; i < g_oInstMax; i++) {     EndPointInit(&xEndPoint[i], i+1);  }  _InitializeParam();  HandsetDisplayString("Megaco Stack ...",3);  _InitializeH248();  for (i = 0; i < g_oInstMax; i++) {     HandsetRegisterPhoneNumber(i+1, xEndPoint[i].szTermName);    }  HandsetRegisterNetworkInfo(g_sMgIpAddr, g_sMacAddr, g_sMgcIpAddr);  HandsetDisplayHandsetStatus();#ifdef HANDSET_HOOKER  HandsetHookerInit();#endif}void RegisteringComplete(){  HandsetClearDisplay();  HandsetDisplayString("     Megaco Stack",2);  HandsetDisplayString(" loaded successfully",3);}  /************************************************************************** * _InterfaceOpen *   Callback function for when an interface is opened **************************************************************************/void _InterfaceOpen(OCTET oIfIdx){  DWORD dwIfIpAddr;  DWORD dwProtocols = 0;    pthread_mutex_lock(&mInterfaceMutex);    SetupNetGetIfIPAddress(oIfIdx, &dwIfIpAddr);  if (0x0 == dwIfIpAddr) {    pthread_mutex_unlock(&mInterfaceMutex);    return;  }    printf("Interface %d is open\n",oIfIdx);    /*   * SINGLE INTERFACE    * (VoIP Services are on interface 0)   */#ifndef NETWORK_MULTIIF  {    ASSERT(oIfIdx == 0);        g_dwLocalIPAddr = g_dwLANIPAddr = dwIfIpAddr;    _StartVoIPServices();        dwProtocols = VOIPDISC_PROTOCOL_MGCP|VOIPDISC_PROTOCOL_HTTP;#   ifndef NUSE_SNMP    dwProtocols |= VOIPDISC_PROTOCOL_SNMP;#   endif  }    /*   * MULTIPLE INTERFACES    * (Private LAN on interface 0, VoIP Services are on interface 1)   */#else  if (oIfIdx == 0) {    g_dwLANIPAddr = dwIfIpAddr;    _StartLANServices();        if (g_bHttpLanAccess) dwProtocols |= VOIPDISC_PROTOCOL_HTTP;#   ifndef NUSE_SNMP    if (g_bSnmpLanAccess) dwProtocols |= VOIPDISC_PROTOCOL_SNMP;#   endif  }   else {    if (g_bHttpWanAccess) dwProtocols |= VOIPDISC_PROTOCOL_HTTP;#   ifndef NUSE_SNMP    if (g_bSnmpWanAccess) dwProtocols |= VOIPDISC_PROTOCOL_SNMP;#   endif  }    if (oIfIdx == 1) {    g_dwLocalIPAddr = dwIfIpAddr;    _StartVoIPServices();    dwProtocols |= VOIPDISC_PROTOCOL_MGCP;  }    if ((oIfIdx == 0 && g_bVoipDiscLanAccess) ||      (oIfIdx > 0 && g_bVoipDiscWanAccess))#endif      {      VoipDiscoveryAddInterface(oIfIdx, dwProtocols, dwIfIpAddr,                                 &g_oMacAddress[0]);    }      pthread_mutex_unlock(&mInterfaceMutex);}/************************************************************************** * _InterfaceClose *   Callback function for when an interface is closing **************************************************************************/void _InterfaceClose(OCTET oIfIdx){  pthread_mutex_lock(&mInterfaceMutex);    printf("Interface %d is closing !!!\n",oIfIdx);    /*   * SINGLE INTERFACE    * (VoIP Services are on interface 0)   */#ifndef NETWORK_MULTIIF  ASSERT(oIfIdx == 0);  _StopVoIPServices();  g_dwLocalIPAddr = g_dwLANIPAddr = 0;    /*   * MULTIPLE INTERFACES   * (Private LAN on interface 0, VoIP Services are on interface 1)   */#else  if (oIfIdx == 0) {    _StopLANServices();    g_dwLANIPAddr = 0;  }  else if (oIfIdx == 1) {    _StopVoIPServices();    g_dwLocalIPAddr = 0;  }#endif    VoipDiscoveryRemoveInterface(oIfIdx);     pthread_mutex_unlock(&mInterfaceMutex);}/************************************************************************** * _StartVoIPServices *   Start VoIP services on the VoIP interface **************************************************************************/void _StartVoIPServices(void){  sprintf(g_sMgIpAddr, "%d.%d.%d.%d",	  ((OCTET)(g_dwLocalIPAddr>>24)&0xff),	  ((OCTET)(g_dwLocalIPAddr>>16)&0xff),	  ((OCTET)(g_dwLocalIPAddr>>8)&0xff),	  ((OCTET)(g_dwLocalIPAddr)&0xff));  sprintf(g_sMacAddr, "%02x:%02x:%02x:%02x:%02x:%02x",	  g_oMacAddress[0], g_oMacAddress[1],	  g_oMacAddress[2], g_oMacAddress[3],	  g_oMacAddress[4], g_oMacAddress[5]);  SYSLOG(LOG_INFO,"IP address is %s mac is %s\n",	 g_sMgIpAddr, g_sMacAddr);  if (FALSE == g_bVoipServicesUp) {        ASSERT(g_dwLocalIPAddr != 0);        /* Initialize the MediaStream module */    printf("Starting MediaStream Module ...\n");    MediaStreamInit(g_dwLocalIPAddr, g_oMacAddress);        /* Startup the MGCP protocol stack */    if (!g_bMEGACOInitOK) {      printf("Starting MGCP Protocol Stack ...\n");      HandsetDisplayString("MGCP Stack ...",3);      if (_InitializeH248() < 0) {         g_bMEGACOInitOK = FALSE;        HandsetDisplayString("MGCP Stack FAIL",3);        HandsetDisplayString("CA ADDR NOT SET",4);      } else {        g_bMEGACOInitOK = TRUE;      }     }        //    _RegisterHandsetInfo(g_dwLocalIPAddr,g_oMacAddress,g_dwIPCallAgent);        if (g_bMEGACOInitOK) {      HandsetDisplayHandsetStatus();    }        g_bVoipServicesUp = TRUE;  }}/************************************************************************** * _StopVoIPServices *   Stop VoIP services **************************************************************************/void _StopVoIPServices(void){  if (TRUE == g_bVoipServicesUp) {        /* Terminate the MGCP protocol stack */    if (g_bMEGACOInitOK) {      printf("Terminating MGCP Protocol Stack ...\n");      H248ProtocolTerminate();      g_bMEGACOInitOK = FALSE;    }        /* Terminate the MediaStream module */    printf("Terminating MediaStream Module ...\n");    MediaStreamTerm();        //    _RegisterHandsetInfo(0,g_oMacAddress,0);        g_bVoipServicesUp = FALSE;  }}#ifdef NETWORK_MULTIIF/************************************************************************** * _StartLANServices *   Start services which use the LAN interface **************************************************************************/void _StartLANServices(void){  if (FALSE == g_bLANServicesUp) {    #ifdef NETWORK_ROUTER    /* startup the DHCP server (only if at least one active routed leg */    {      BOOL bBridgeOnly = FALSE;      SetupNetCheckBridgeOnly(&bBridgeOnly,-1);            DHCPServerCreate(g_dwLANIPAddr);            if (!bBridgeOnly) {        printf("Starting DHCP Server ...\n");        DHCPServerStart();      }    }#endif        g_bLANServicesUp = TRUE;  }}/************************************************************************** * _StopLANServices *   Stop services which use the LAN interface **************************************************************************/void _StopLANServices(void){  if (TRUE == g_bLANServicesUp) {    #ifdef NETWORK_ROUTER    /* shutdown the DHCP server */    printf("Terminating DHCP Server ...\n");    DHCPServerTerminate();#endif        g_bLANServicesUp = FALSE;  }}#endif  //NETWORK_MULTIIF

⌨️ 快捷键说明

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