📄 init.c
字号:
/******************************************************************** * * File: init.c * * Description: * Initialization functions. * * Revisions: * 04-may-01 J.H and S.J.M initial version. * * Copyright 2003 Netergy Microelectronics, Inc. All rights reserved. * ********************************************************************/#include <sys/sockio.h>#include "setupnet.h"#include "httpapi.h"#include "configapi.h"#include "audiosys.h" #include "voipdiscoveryapi.h"#include "handsetapi.h"#include "dllist.h"#include "agent_api.h"#include "mib2_api.h"#include "h248app.h"OCTET g_oNumInterfaces = 1;BOOL g_bLANServicesUp = FALSE;BOOL g_bVoipServicesUp = FALSE;DWORD g_dwLocalIPAddr;DWORD g_dwLANIPAddr;OCTET g_oInstMax;BOOL g_bMEGACOInitOK = FALSE;DLLIST *pdllConn;pthread_mutex_t mMutexConn;/* Thread protection */pthread_mutex_t mAppMutex, mInterfaceMutex;char g_sMgIpAddr[30];WORD g_wMgPort = 55555;char g_sMgcIpAddr[30];WORD g_wMgcPort = 2944;OCTET g_oMacAddress[6];END_POINT xEndPoint[MAX_END_POINT_NUM];DWORD dbg_dwInit = 0;char g_sMgDeviceName[30]="";char g_sMacAddr[20];BOOL g_bDHCPMode;void *snmp_handle;/* Service access flags */#ifdef NETWORK_MULTIIFBOOL g_bHttpWanAccess = TRUE;BOOL g_bHttpLanAccess = TRUE;BOOL g_bVoipDiscWanAccess = TRUE;BOOL g_bVoipDiscLanAccess = TRUE;#ifndef NUSE_SNMPBOOL g_bSnmpWanAccess = TRUE;BOOL g_bSnmpLanAccess = TRUE;#endif#endifvoid _StartLANServices(void);void _StopLANServices(void);void _StartVoIPServices(void);void _StopVoIPServices(void);void _InterfaceOpen(OCTET oIfIdx);void _InterfaceClose(OCTET oIfIdx);/************************************************************************** * PRIVATE HELPER FUNCTIONS **************************************************************************//************************************************************************** * _WebPostCallBackFunction * Web post call back function to catch reset request * pp - Pointer to web post parameters **************************************************************************/int _WebPostCallBackFunction(PostParam* pp){ int i; LONG lReturnCode = -1; /* If we are resetting, we need to terminate the MGCP protocol stack so * that an RSIP will be sent to the call-agent */ for (i=0;i<pp->iNumParams;i++) { if (strcmp(pp->stParams[i].pchParamName,"RESET")==0) { struct timespec rqtp = {0,200000000}; SYSLOG(LOG_DEBUG,"RESET - Terminate MGCP protocol stack!\n"); /* This will force an RSIP to be sent during web reset */ if (g_bMEGACOInitOK) { H248ProtocolTerminate(); } /* Give time to shut down */ nanosleep(&rqtp, NULL); } } lReturnCode = DefaultWebPostCallback(pp); SetupNetWebPostCallback((H_WEBDATA)pp); #ifndef NUSE_SNMP SnmpAgentWebPostCallBack(pp);#endif #ifdef NETWORK_ROUTER DHCPServerWebPostCallBack(pp); /* * Change PORT Forwarding settings to the CPE */ for (i=0;i<pp->iNumParams;i++) { if (strcmp(pp->stParams[i].pchParamName,"HTTPWAN") == 0) { if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { SetupNetRegisterWan2CpePortFwd(80, 80, 1); g_bHttpWanAccess = TRUE; } else { SetupNetRegisterWan2CpePortFwd(80, 80, 0); g_bHttpWanAccess = FALSE; } } if (strcmp(pp->stParams[i].pchParamName,"HTTPLAN") == 0) { if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { SetupNetRegisterLan2CpePortBlock(80, 80, 0); g_bHttpLanAccess = TRUE; } else { SetupNetRegisterLan2CpePortBlock(80, 80, 1); g_bHttpLanAccess = FALSE; } } if (strcmp(pp->stParams[i].pchParamName,"VOIPDISCWAN") == 0) { int j; OCTET oIfNum; SetupNetGetIfNum(&oIfNum); if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { g_bVoipDiscWanAccess = TRUE; for (j=1;j<oIfNum;j++) { DWORD dwStatus; SetupNetGetIfStatus(j,&dwStatus); if ((dwStatus & (IFF_UP|IFF_IPUP)) == (IFF_UP|IFF_IPUP)) { DWORD dwIfAddress; DWORD dwProtocols = 0; if (j==1) dwProtocols |= VOIPDISC_PROTOCOL_MGCP; if (g_bHttpWanAccess) dwProtocols |= VOIPDISC_PROTOCOL_HTTP;#ifndef NUSE_SNMP if (g_bSnmpWanAccess) dwProtocols |= VOIPDISC_PROTOCOL_SNMP;#endif SetupNetGetIfIPAddress(j,&dwIfAddress); VoipDiscoveryAddInterface(j, dwProtocols, dwIfAddress, &g_oMacAddress[0]); } } } else { g_bVoipDiscWanAccess = FALSE; for (j=1;j<oIfNum;j++) { VoipDiscoveryRemoveInterface(j); } } } if (strcmp(pp->stParams[i].pchParamName,"VOIPDISCLAN") == 0) { if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { DWORD dwIfAddress; DWORD dwProtocols = 0; SetupNetGetIfIPAddress(0,&dwIfAddress); if (g_bHttpLanAccess) dwProtocols |= VOIPDISC_PROTOCOL_HTTP;#ifndef NUSE_SNMP if (g_bSnmpLanAccess) dwProtocols |= VOIPDISC_PROTOCOL_SNMP;#endif VoipDiscoveryAddInterface(0, dwProtocols, dwIfAddress, &g_oMacAddress[0]); g_bVoipDiscLanAccess = TRUE; } else { g_bVoipDiscLanAccess = FALSE; VoipDiscoveryRemoveInterface(0); } } #ifndef NUSE_SNMP if (strcmp(pp->stParams[i].pchParamName,"SNMPWAN") == 0) { if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { SetupNetRegisterWan2CpePortFwd(161, 161, 1); g_bSnmpWanAccess = TRUE; } else { SetupNetRegisterWan2CpePortFwd(161, 161, 0); g_bSnmpWanAccess = FALSE; } } if (strcmp(pp->stParams[i].pchParamName,"SNMPLAN") == 0) { if (!strcmp(pp->stParams[i].pchParamValue, "YES")) { SetupNetRegisterLan2CpePortBlock(161, 161, 0); g_bSnmpLanAccess = TRUE; } else { SetupNetRegisterLan2CpePortBlock(161, 161, 1); g_bSnmpLanAccess = FALSE; } }#endif }#endif // NETWORK_ROUTER return lReturnCode; /* Return value from Default Callback */}/************************************************************************** * _WebSubstCallBackFunction * To substitute non-config file variables into html files **************************************************************************/int _WebSubstCallBackFunction(SubstParam* sp){ /* Start with default substitutions or this will nuke new substitutions */ DefaultWebSubstCallback(sp); SetupNetWebSubstCallback((H_WEBDATA)sp);#ifdef NETWORK_ROUTER DHCPServerWebSubstCallBack(sp); if (!strcmp(sp->pchParamName,"SUPPORT_ROUTER")) { sprintf(sp->chParamValue, "Y"); }#endif #ifdef NETWORK_BRIDGE if (!strcmp(sp->pchParamName,"SUPPORT_BRIDGE")) { sprintf(sp->chParamValue, "Y"); }#endif #ifdef NETWORK_WIRELESS if (!strcmp(sp->pchParamName,"SUPPORT_WIRELESS")) { sprintf(sp->chParamValue, "Y"); }#endif #ifdef NETWORK_IPSEC if (!strcmp(sp->pchParamName,"SUPPORT_IPSEC")) { sprintf(sp->chParamValue, "Y"); }#endif #ifdef NETWORK_PPP if (!strcmp(sp->pchParamName,"SUPPORT_PPP")) { sprintf(sp->chParamValue, "Y"); }#endif #ifndef NUSE_SNMP if (!strcmp(sp->pchParamName,"SUPPORT_SNMP")) { sprintf(sp->chParamValue, "Y"); }#endif if (!strcmp(sp->pchParamName,"NUMLINES")) { sprintf(sp->chParamValue, "%d", g_oInstMax); } if (!strcmp(sp->pchParamName,"SUPPORTEDCODECS")) { DWORD dwBits = 0;#ifdef AUD_G723 dwBits |= 2;#endif#ifdef AUD_G726 dwBits |= 4;#endif#ifdef AUD_G729 dwBits |= 16;#endif sprintf(sp->chParamValue,"%ld", dwBits); } return 1;}/************************************************************************** * _Initialization * Initialization of all protocol stacks, instances, device drivers etc... **************************************************************************/void _Initialization(){ int i; LONG lReturn; pthread_mutexattr_t attr; /* open hardware drivers */ lReturn = HandsetInitialize(); ASSERT(lReturn == INIT_NO_ERROR); /* detect number of lines (slics) */ g_oInstMax = HandsetQueryNumberOfLines(); if (g_oInstMax == 0 || g_oInstMax >= 16) { ASSERT(0); while(1); } #ifdef NETWORK_ROUTER /* Due to memory/MIPs constraints, limit number of lines to 2 * for a voice/router application */ if (g_oInstMax > 2) { g_oInstMax = 2; }#endif /* Start the handset state machines */ lReturn = HandsetStart(g_oInstMax); ASSERT(lReturn == INIT_NO_ERROR); /* Initialize application mutex */ pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mInterfaceMutex, &attr); pthread_mutex_init(&mMutexConn, &attr); pthread_mutexattr_destroy(&attr); /* Startup the network stack */ printf("Starting network stack ...\n"); HandsetDisplayString("Network Stack ...",3); _InitializeNetwork(); /* Get the number of network interfaces */#ifdef NETWORK_MULTIIF SetupNetGetIfNum(&g_oNumInterfaces);#endif /* startup the webserver */ printf("Starting HTTP Server ...\n"); HandsetDisplayString("HTTP Server ...",3); HttpSubstRegister(_WebSubstCallBackFunction); HttpPostRegister(_WebPostCallBackFunction); HttpWebserverStart();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -