📄 common.c
字号:
/************************************************************************
*
* Version %I%
*
* Copyright (C) 2002 By BEP Corporation.
* This Document Contains Proprietary Information Of BEP Corporation.
* No Distribution Is Granted Except With Written Permission From
* BEP Corporation.
*************************************************************************/
/*
**
** MODULE: common.c
**
** PURPOSE:
**
** LIMITATIONS:
**
** DATE CREATED: 11-05-2003
**
** AUTHOR(S): luozheru
**
** MODIFICATIONS:
** userId Date Description
**
** QA Status:
** status Date Owner
**
*/
#include "string.h"
#include "inetLib.h"
#include "task.h"
#include "configuration.h"
#include "phonerecord.h"
#include "dspinterface.h"
#include "pgi_klc.h"
#include "pgi_lcd.h"
#include "bepcommon.h"
#include "event.h"
#include "rvwpt.h"
#include "pgi_time.h"
#include "http/httpLib.h"
#include "http/httpRpms.h"
#include "sockLib.h"
#include "inetLib.h"
#ifdef HC
#include "h323.h"
#endif
#ifdef SIP
#include "sip.h"
#endif
#ifdef MGCP
#include "mgcp.h"
#endif
#define LCD_WIDTH 20
#define SNTP_RECFG_TIMER (ONE_SEC * 60 * 60 * 24)
#ifdef __cplusplus
extern "C"
{
#endif
/**
* phone config
*/
extern struct s_config phoneconfig;
extern SEM_ID dhcpClientSem;
#ifdef INCLUDE_PPPOE_APP
extern int pppoeStatus;
#endif
/**
* define phonebook
*/
SEM_ID callSem;
unsigned char needSetCall = FALSE;
struct s_phonebook phonebook[MAX_PHONE_BOOK + 1];
struct s_callrecord incomingcall[MAX_CALL_RECORD + 1];
struct s_callrecord outgoingcall[MAX_CALL_RECORD + 1];
struct s_callrecord noanswercall[MAX_CALL_RECORD + 1];
#ifdef HC
unsigned char isReinitStack = 0;
unsigned char isRestartAgent = 0;
SEM_ID cfgSem;
#endif
/**
*event for menu process
*/
int menu_event = null_event;
/**
*ponit of the wapper message received
*/
WrapperMsg* wp_msg;
NonWrapperMsg* msg;
/**
*used by AppTerminateAction for sending BYE message or not
*/
int send_bye = FALSE;
/**
*
*used by show string in LCD or not
*/
int* menu_inuse = NULL;
/*
* 用于测试按键
*/
int IfTestingKey = 0;
/**
*show mute key is on or off
*/
int mute = FALSE;
/**
*whether speaker is on
*/
int on_speakerphone = FALSE;
/* The KLC driver uses these to keep track of the state of the handset and speakerphone. */
int handset_up = FALSE;
/**
*timer in our system
*/
/*int timer = -1;*/
int sntp_timer = -1; /* SNTP同步计时器 */
/**
*used by receiving call
*/
char remoteName[32+1];
char remoteLogin[32];
char remoteDomain[32];
char remoteNum[32];
s_task callTask;
s_task* psMenuTask = NULL;
/**
*for calling out or saving recorder when talking
*/
char toAddr[32+1];
int num_digits = 0;
int digitCollectAmount = -1;
int prev_num_digits = 0;
unsigned char noAnswerCall = 0;
/**
*for menu action
*/
unsigned char canStopRingInMenu = TRUE;
static SEM_ID sntpSem;
/**
*used by sip
*/
#ifdef SIP
/**
*whether REGISTER message is send
*/
int register_sent = 0;
/**
*for redialing
*/
char redialAddr[32];
/**
*for receive invite
*/
unsigned receive;
char recNum[32];
int p2pFlag = TRUE;
#endif
/**
*used by h323
*/
#ifdef HC
char remoteNumber[MAX_PHONE_NUMBER_LEN+1];
#endif
#ifdef MGCP
char remoteNum[32];
#endif
/**
* 恢复默认设置
*/
void LoadDefaultParam()
{
int i;
unsigned char* tempBook = (unsigned char*)phonebook;
int sizePhoneBook = sizeof(phonebook);
int count = 0;
char *codecName[AUDIO_CODEC_NUM] ={"g7231", "g729AnnexA", "g711Ulaw64k", "g711Alaw64k"};
for (i = 0; i < sizePhoneBook; i++)
{
if (tempBook[i] == 0xff) count++;
}
if (count >= sizePhoneBook * 9 / 10)
{
memset(&phonebook, 0, sizeof(phonebook));
semTake(callSem, WAIT_FOREVER);
memset(&incomingcall, 0, sizeof(incomingcall));
memset(&outgoingcall, 0, sizeof(outgoingcall));
memset(&noanswercall, 0, sizeof(noanswercall));
semGive(callSem);
}
memset(&phoneconfig, 0, sizeof(phoneconfig));
strcpy(phoneconfig.conf_basic.password, "000000");
phoneconfig.conf_basic.linenumber[0] = '\0';
/*memset(phoneconfig.conf_basic.linenumber, '0', 16);*/
/*time*/
phoneconfig.conf_basic.ringtype = 1;
phoneconfig.conf_basic.ringvolume = 12;
phoneconfig.conf_basic.handsetvolume = 5;
phoneconfig.conf_basic.speakerphonevolume = 5;
for (i = 0; i < MAX_SPEED_DIAL_KEY; i++)
{
phoneconfig.conf_speedDial[i] = MAX_PHONE_BOOK;
}
phoneconfig.conf_network.ipaddr = 0xC0A87BF6;/* "192.168.123.246" */
phoneconfig.conf_network.subnetmask = 0xFFFFFF00; /* "255.255.255.0"*/
phoneconfig.conf_network.gateway = 0xC0A87BFE; /* "192.168.123.254" */
phoneconfig.conf_network.ipType = DHCPIP;
#ifdef INCLUDE_PPPOE_APP
phoneconfig.conf_network.retryCount = 3;
#endif
phoneconfig.conf_network.netspeed = 1; /* net speed */
phoneconfig.bootFileHead[0] = 0xFE;
phoneconfig.bootFileHead[1] = 0x03;
phoneconfig.bootFileHead[2] = 0x00;
phoneconfig.bootFileHead[3] = 0xEA;
phoneconfig.appFileHead[0] = 0x08;
phoneconfig.appFileHead[1] = 0x78;
phoneconfig.appFileHead[2] = 0x9C;
phoneconfig.appFileHead[3] = 0xDC;
#ifdef HC
phoneconfig.conf_h323.isFastStart = 1; /* default open faststart*/
phoneconfig.conf_h323.isH245Tunneling = 1; /* default open h245tunneling */
#ifdef FOR_HW
phoneconfig.ifEchoInput = 1;
#else
phoneconfig.ifEchoInput = 0;
#endif
#endif
phoneconfig.conf_ftp.mode = MODE_FTP;
phoneconfig.conf_forward.interval = 30;
/* SNTP */
phoneconfig.conf_sntp.timezone = 8;
phoneconfig.conf_sntp.serverip = 0xd8984410; /* 216.152.68.16 */
phoneconfig.conf_sntp.ifsntp = 1;
for (i = 0; i < AUDIO_CODEC_NUM; i++)
{
phoneconfig.conf_audio.codecPrefOrder[i].isUsed = 1;
phoneconfig.conf_audio.codecPrefOrder[i].codecType = cmCapAudio;
strcpy(phoneconfig.conf_audio.codecPrefOrder[i].codecName, codecName[i]);
}
#ifdef HC
phoneconfig.conf_service.dtmftype = DTMF_RFC2833EVENT;
#endif
#ifdef SIP
phoneconfig.conf_service.serviceport = 5060;
phoneconfig.conf_service.serverip = 0xC0A87B6F; /* "192.168.123.111" */
phoneconfig.conf_service.rtpport = 5678;
phoneconfig.conf_service.registerport = 5060;
#endif
#ifdef MGCP
phoneconfig.conf_mgcp.callagentport = 2727;
phoneconfig.conf_mgcp.localport = 2427;
phoneconfig.conf_mgcp.reqtimeout = 30000;
phoneconfig.conf_mgcp.delmsgtimeout = 10000;
#endif
}
#ifdef SIP
int getErrStr(enum errType e, char* errStr, int len)
{
switch (e)
{
/* 3** error code */
case MulChoice :
strncpy(errStr, "Multiple Choices", len);
break;
case MovPer :
strncpy(errStr, "Moved Permanently", len);
break;
case MovTemp :
strncpy(errStr, "Moved Temporarily", len);
break;
case UsedProxy :
strncpy(errStr, "Use Proxy", len);
break;
case AltSer :
strncpy(errStr, "Alternative Service", len);
break;
/* 4** error code */
case BadReq :
strncpy(errStr, "Bad Request", len);
break;
case Unauth :
strncpy(errStr, "Unauthorized", len);
break;
case PayReq :
strncpy(errStr, "Payment Required", len);
break;
case Forb :
strncpy(errStr, "Forbidden", len);
break;
case NotFound :
strncpy(errStr, "Not Found", len);
break;
case MethNAll :
strncpy(errStr, "Method Not Allowed", len);
break;
case NotAcc :
strncpy(errStr, "Not Acceptable", len);
break;
case ProAuReq :
strncpy(errStr, "Proxy Authentication Required", len);
break;
case ReqTmOut :
strncpy(errStr, "Request Timeout", len);
break;
case Gone :
strncpy(errStr, "Gone", len);
break;
case ReqTooLag :
strncpy(errStr, "Request Entity Too Large", len);
break;
case ReqURL :
strncpy(errStr, "Request-URI Too Large", len);
break;
case UnsupMed :
strncpy(errStr, "Unsupported Media Type", len);
break;
case UnsupURI :
strncpy(errStr, "Unsupported URI Scheme", len);
break;
case BadExt :
strncpy(errStr, "Bad Extension", len);
break;
case ExtReq :
strncpy(errStr, "Extension Required", len);
break;
case IntTooBrf :
strncpy(errStr, "Interval Too Brief", len);
break;
case TempMAva :
strncpy(errStr, "Temporarily not available", len);
break;
case CallNExt :
strncpy(errStr, "Call Leg/Transaction Does Not Exist", len);
break;
case LoopDet :
strncpy(errStr, "Loop Detected", len);
break;
case TooMyHop :
strncpy(errStr, "Too Many Hops", len);
break;
case AddIncom :
strncpy(errStr, "Address Incomplete", len);
break;
case Ambiguous :
strncpy(errStr, "Ambiguous", len);
break;
case BusyHere :
strncpy(errStr, "Busy Here", len);
break;
case ReqTerm :
strncpy(errStr, "Request Terminated", len);
break;
case NotAccH :
strncpy(errStr, "Not Acceptable Here", len);
break;
case ReqPend :
strncpy(errStr, "Request Pending", len);
break;
case Undec :
strncpy(errStr, "Undecipherable", len);
break;
case IntSerErr :
strncpy(errStr, "Internal Server Error", len);
break;
case NotImp :
strncpy(errStr, "Not Implemented", len);
break;
case BadGw :
strncpy(errStr, "Bad Gateway", len);
break;
case SerUnava :
strncpy(errStr, "Service Unavailable", len);
break;
case SerTmOut :
strncpy(errStr, "Server Time-out", len);
break;
case SipVerErr :
strncpy(errStr, "SIP Version not supported", len);
break;
case MsgTooLag :
strncpy(errStr, "Message Too Large", len);
break;
case BusyEvy :
strncpy(errStr, "Busy Everywhere", len);
break;
case Decline :
strncpy(errStr, "Decline", len);
break;
case DoNotExt :
strncpy(errStr, "Does not exist anywhere", len);
break;
case GlbNotAcc :
strncpy(errStr, "Not Acceptable", len);
break;
default:
printf("error no is not matched, %d!\n", e);
strncpy(errStr, "Unknown Error", len);
return -1;
}
return 0;
}
#endif
void SetCallInfo()
{
/*write flash per 4 hours */
struct timespec callTime = { 4 * 60 * 60, 0};
while (1)
{
nanosleep(&callTime, NULL);
recordAllCall();
}
}
/**
* 初始化话机配置
*/
void InitPhoneParam()
{
int sizePhoneConfig = sizeof(phoneconfig);
int sizePhoneBook = sizeof(phonebook);
int sizeCallRecord = sizeof(incomingcall);
int offset = CONFIG_LOCATION;
callSem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY );
semGive(callSem);
sntpSem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY );
semGive(sntpSem);
cfgSem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY );
semGive(cfgSem);
dhcpClientSem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY );
semGive(dhcpClientSem);
memset(&phonebook, 0, sizeof(phonebook));
memset(&incomingcall, 0, sizeof(incomingcall));
memset(&outgoingcall, 0, sizeof(outgoingcall));
memset(&noanswercall, 0, sizeof(noanswercall));
memset(&phoneconfig, 0, sizeof(phoneconfig));
if (sysNvRamGet((char *) &phonebook, sizePhoneBook - 1, offset) != OK)
{
printf("Init phone book error. load default param!\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -