439 lines
11 KiB
C
439 lines
11 KiB
C
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/string.h>
|
|
#include <asm/uaccess.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/phy.h>
|
|
#include <net/udp.h>
|
|
#include <net/arp.h>
|
|
|
|
#include "debug_info.h"
|
|
#include "log.h"
|
|
#include "../hook.h"
|
|
|
|
extern int sip_send_dtmf(unsigned int sipCh, char *pDtmfChar, int numChars);
|
|
extern int sip_recv_dtmf(unsigned int sipCh);
|
|
extern int config_sip_ch(unsigned int maxSIPCh,
|
|
unsigned int portBase,
|
|
unsigned int portStep,
|
|
unsigned int rtpPortBase);
|
|
extern int config_sip_port(unsigned int chId,
|
|
unsigned int ethId,
|
|
unsigned short chPort,
|
|
unsigned short sipChPort);
|
|
extern int config_eth_ipaddr(unsigned int ethId, __be32 ipaddr);
|
|
extern int eth_sip_link(unsigned int sipCh,
|
|
__be32 dst_ipAddr,
|
|
__be16 dst_ipPort);
|
|
extern int eth_link(unsigned int chId, PORT_TYPE portType,
|
|
__be32 dst_ipAddr,
|
|
__be16 dst_ipPort);
|
|
int eth_unlink(unsigned int chId, int portType);
|
|
extern int sip_recv_dtmf(unsigned int sipCh);
|
|
|
|
static void ucc_eth_config(void);
|
|
static void ucc_eth_unconfig(void);
|
|
|
|
|
|
#define DBGFS_ITEMS (3)
|
|
#define VERSION ("0.92")
|
|
|
|
static char g_TempBuffer[2][64];
|
|
|
|
extern PSIP_CH_INFO eth_get_sip_ch_details(void);
|
|
|
|
static DBGFS_PRIV g_DbgFSUCCConfig[DBGFS_ITEMS];
|
|
|
|
static char GetDTMFValue(char dtmf)
|
|
{
|
|
switch(dtmf)
|
|
{
|
|
case '0':
|
|
return 0;
|
|
|
|
case '1':
|
|
return 1;
|
|
|
|
case '2':
|
|
return 2;
|
|
|
|
case '3':
|
|
return 3;
|
|
|
|
case '4':
|
|
return 4;
|
|
|
|
case '5':
|
|
return 5;
|
|
|
|
case '6':
|
|
return 6;
|
|
|
|
case '7':
|
|
return 7;
|
|
|
|
case '8':
|
|
return 8;
|
|
|
|
case '9':
|
|
return 9;
|
|
|
|
case '*':
|
|
return 10;
|
|
|
|
case '#':
|
|
return 11;
|
|
|
|
case 'A':
|
|
case 'a':
|
|
return 12;
|
|
|
|
case 'B':
|
|
case 'b':
|
|
return 13;
|
|
|
|
case 'C':
|
|
case 'c':
|
|
return 14;
|
|
|
|
case 'D':
|
|
case 'd':
|
|
return 15;
|
|
|
|
case 'F':
|
|
case 'f':
|
|
return 16;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
static int DbgFS_DTMFSendHelp(struct seq_file* seq, void* token)
|
|
{
|
|
printk("==============Options Helps=============\n");
|
|
printk("usage: echo \"<params>\" > /proc/spbx_ucc/dtmf_send\n");
|
|
|
|
printk("params:\n");
|
|
printk("\t[send <ch> <dtmf>]: UCC Send RFC2833 DTMF <dtmf> On SIP Channel <ch>.\n");
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_DTMFSendShow(struct seq_file* seq, void* token)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_DTMFSendIoctl(struct seq_file* seq, char* cmd, char* params)
|
|
{
|
|
// printk("cmd:%s,params:%s\n", cmd, params);
|
|
|
|
if(strcmp(cmd, "send") == 0)
|
|
{
|
|
int ch = GetIntParamValue(params, 0);
|
|
char dtmf = GetCharParamValue(params, 1);
|
|
char buf[4] = {'0', '1', '2', '3'};
|
|
|
|
// char dtmfChar = GetDTMFValue(dtmf);
|
|
//printk("ch = %d, dtmf = (%d)(%c)\n", ch, dtmf, dtmf);
|
|
|
|
int rlt = sip_send_dtmf(ch, buf, 4);
|
|
|
|
printk("Ch %d Send DTMF (%c) Value (%02d) result %d\n", ch, dtmf, GetDTMFValue(dtmf), rlt);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static int DbgFS_DTMFRecvHelp(struct seq_file* seq, void* token)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_DTMFRecvShow(struct seq_file* seq, void* token)
|
|
{
|
|
// UINT32 opt = g_DbgFSUCCConfig[1].params;
|
|
|
|
if(token == SEQ_START_TOKEN)
|
|
{
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_DTMFRecvIoctl(struct seq_file* seq, char* cmd, char* params)
|
|
{
|
|
if(strcmp(cmd, "recv") == 0)
|
|
{
|
|
int ch = GetIntParamValue(params, 0);
|
|
char rlt = (char)sip_recv_dtmf(ch);
|
|
|
|
|
|
if(rlt != 255)
|
|
{
|
|
printk("Ch %d Receive DTMF (%c) Value (0x%02X)\n", ch, rlt, rlt);
|
|
}
|
|
else
|
|
{
|
|
printk("Ch %d Un Receive DTMF\n", ch);
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_LinkShow(struct seq_file* seq, void* token)
|
|
{
|
|
#if 0
|
|
// UINT32 opt = g_DbgFSUCCConfig[2].params;
|
|
int i = 0;
|
|
|
|
if(token == SEQ_START_TOKEN)
|
|
{
|
|
PSIP_CH_INFO pSipChInfo = eth_get_sip_ch_details();
|
|
|
|
seq_printf(seq, "SPI Info:\n");
|
|
|
|
seq_printf(seq, "Total Ch: %d\n", pSipChInfo->iTotalCh);
|
|
seq_printf(seq, "Port Base: %d\n", pSipChInfo->iPortBase);
|
|
seq_printf(seq, "Port Step: %d\n", pSipChInfo->iPortStep);
|
|
seq_printf(seq, "RTP Port Base: %d\n", pSipChInfo->iRTPPortBase);
|
|
|
|
seq_printf(seq, "%s%s\n",
|
|
"------------------------------------------------------------",
|
|
"------------------------------------------------------------");
|
|
|
|
seq_printf(seq, "|%4s|%6s|%8s|%11s|%17s|%11s|%20s|%10s|%12s|%10s|\n",
|
|
" Ch ", " Port ", " Status ", " IP Port ",
|
|
" Link IP ", " Link Port ", " Link MAC ",
|
|
" ETH Recv ", " ETH Switch ", " ETH Mask ");
|
|
|
|
|
|
seq_printf(seq, "%s%s\n",
|
|
"------------------------------------------------------------",
|
|
"------------------------------------------------------------");
|
|
|
|
for(i = 0; i < pSipChInfo->iTotalCh; i++)
|
|
{
|
|
PSIP_CH_DETIAL pCh = pSipChInfo->pSipChDetial + i;
|
|
/*
|
|
seq_printf(seq, "|%4s| IPR |%8d|%11d|%17s|%11d|%20s|%10s|%12s|%10s|\n",
|
|
"",
|
|
pCh->portIPR.chStatus,
|
|
pCh->portIPR.ipPort,
|
|
GetIPAddrString(pCh->portIPR.chLinkInfo.dstTarget.ipAddr),
|
|
pCh->portIPR.chLinkInfo.dstTarget.ipPort,
|
|
GetMACString(pCh->portIPR.chLinkInfo.dstTarget.ethAddr),
|
|
"",
|
|
"",
|
|
""
|
|
);
|
|
*/
|
|
seq_printf(seq, "|%4d| B2B |%8d|%11d|%17s|%11d|%20s|%10d|%12d|%10d|\n",
|
|
i,
|
|
pCh->portB2B.chStatus,
|
|
pCh->portB2B.ipPort,
|
|
GetIPAddrString(pCh->portB2B.chLinkInfo.dstTarget.ipAddr),
|
|
pCh->portB2B.chLinkInfo.dstTarget.ipPort,
|
|
GetMACString(pCh->portB2B.chLinkInfo.dstTarget.ethAddr),
|
|
pCh->sipDebug.cnt_eth0_recv,
|
|
pCh->sipDebug.cnt_eth0_2_ethx,
|
|
pCh->sipDebug.mask_eth0_2_ethx
|
|
);
|
|
/*
|
|
seq_printf(seq, "|%4s| T38 |%8d|%11d|%17s|%11d|%20s|%10s|%12s|%10s|\n",
|
|
"",
|
|
pCh->portT38.chStatus,
|
|
pCh->portT38.ipPort,
|
|
GetIPAddrString(pCh->portT38.chLinkInfo.dstTarget.ipAddr),
|
|
pCh->portT38.chLinkInfo.dstTarget.ipPort,
|
|
GetMACString(pCh->portT38.chLinkInfo.dstTarget.ethAddr),
|
|
"",
|
|
"",
|
|
""
|
|
);
|
|
*/
|
|
seq_printf(seq, "|%4s|%6s|%8s|%11s|%17s|%11s|%20s|%10s|%12s|%10s|\n",
|
|
"",
|
|
"------",
|
|
"--------",
|
|
"-----------",
|
|
"-----------------",
|
|
"-----------",
|
|
"--------------------",
|
|
"----------",
|
|
"------------",
|
|
"----------");
|
|
|
|
seq_printf(seq, "|%4s| RTP |%8d|%11d|%17s|%11d|%20s|%10d|%12d|%10d|\n",
|
|
"",
|
|
pCh->portRTP.chStatus,
|
|
pCh->portRTP.ipPort,
|
|
GetIPAddrString(pCh->portRTP.chLinkInfo.dstTarget.ipAddr),
|
|
pCh->portRTP.chLinkInfo.dstTarget.ipPort,
|
|
GetMACString(pCh->portRTP.chLinkInfo.dstTarget.ethAddr),
|
|
pCh->sipDebug.cnt_ethx_recv,
|
|
pCh->sipDebug.cnt_ethx_2_eth0,
|
|
pCh->sipDebug.mask_ethx_2_eth0);
|
|
|
|
|
|
seq_printf(seq, "%s%s\n",
|
|
"|-----------------------------------------------------------",
|
|
"-----------------------------------------------------------|");
|
|
}
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int DbgFS_LinkHelp(struct seq_file* seq, void* token)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int DbgFS_LinkIoctl(struct seq_file* seq, char* cmd, char* params)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static DBGFS_PRIV g_DbgFSUCCConfig[DBGFS_ITEMS] =
|
|
{
|
|
{
|
|
"dtmf_send", 0, NULL, NULL,
|
|
DbgFS_DTMFSendShow, DbgFS_DTMFSendIoctl, DbgFS_DTMFSendHelp
|
|
},
|
|
|
|
{
|
|
"dtmf_recv", 0, NULL, NULL,
|
|
DbgFS_DTMFRecvShow, DbgFS_DTMFRecvIoctl, DbgFS_DTMFRecvHelp
|
|
},
|
|
|
|
{
|
|
"link", 0, NULL, NULL,
|
|
DbgFS_LinkShow, DbgFS_LinkIoctl, DbgFS_LinkHelp
|
|
},
|
|
};
|
|
|
|
|
|
static int __init ucc_test_init(void)
|
|
{
|
|
int i = 0;
|
|
#ifdef PLATFORM_P1010
|
|
printk("Test UCC Init PLATFORM P1010 Ver:%s Build:%s(%s)\n", VERSION,
|
|
__DATE__, __TIME__);
|
|
#else
|
|
printk("Test UCC Init PLATFORM MPC8309 Ver:%s Build:%s(%s)\n", VERSION,
|
|
__DATE__, __TIME__);
|
|
#endif
|
|
|
|
InitDebugInfoProc();
|
|
|
|
for(i = 0; i < DBGFS_ITEMS; i++)
|
|
{
|
|
if(DebugFsRegister(&g_DbgFSUCCConfig[i]) != ERR_NO_ERROR)
|
|
{
|
|
LOG_EX(LOG_Error, "%d Regisetr %s Error\n",
|
|
i, g_DbgFSUCCConfig[i].name);
|
|
}
|
|
}
|
|
|
|
ucc_eth_config();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static void __exit ucc_test_exit(void)
|
|
{
|
|
int i = 0;
|
|
#ifdef PLATFORM_P1010
|
|
printk("Test UCC Exit PLATFORM P1010 Build:%s(%s)\n", __DATE__, __TIME__);
|
|
#else
|
|
printk("Test UCC Exit PLATFORM MPC8309 Build:%s(%s)\n", __DATE__, __TIME__);
|
|
#endif
|
|
|
|
ucc_eth_unconfig();
|
|
|
|
for(i = 0; i < DBGFS_ITEMS; i++)
|
|
{
|
|
DebugFsUnRegister(&g_DbgFSUCCConfig[i]);
|
|
}
|
|
|
|
DeInitDebugInfoProc();
|
|
|
|
}
|
|
|
|
#define PORT_BASE_SIP (6500)
|
|
#define PORT_BASE_RTP (9000)
|
|
#define PORT_STEP_SIP (3)
|
|
#define MAX_SIP_CH_NUM (1)
|
|
|
|
static void ucc_eth_config(void)
|
|
{
|
|
int i = 0;
|
|
__be32 spbx_ipaddr = 192 << 24 | 168 << 16 | 0 << 8 | 60;
|
|
__be16 spbx_port = 6000;
|
|
|
|
__be32 sip_ipaddr = 192 << 24 | 168 << 16 | 1 << 8 | 30;
|
|
__be16 sip_port = 9000;
|
|
|
|
config_sip_ch(MAX_SIP_CH_NUM, PORT_BASE_SIP, PORT_STEP_SIP, PORT_BASE_RTP);
|
|
|
|
for(i = 0; i < MAX_SIP_CH_NUM; i++)
|
|
{
|
|
config_sip_port(i, ETH_INTERFACE_1, PORT_BASE_SIP + (i * 3), PORT_BASE_RTP + i);
|
|
}
|
|
|
|
config_eth_ipaddr(ETH_INTERFACE_0,
|
|
192 << 24 | 168 << 16 | 0 << 8 | 10);
|
|
|
|
config_eth_ipaddr(ETH_INTERFACE_1,
|
|
192 << 24 | 168 << 16 | 1 << 8 | 20);
|
|
|
|
config_eth_ipaddr(ETH_INTERFACE_2,
|
|
192 << 24 | 168 << 16 | 2 << 8 | 20);
|
|
|
|
#if 1
|
|
for(i = 0; i < MAX_SIP_CH_NUM; i++)
|
|
{
|
|
eth_link(i, PORT_TYPE_B2B, spbx_ipaddr, spbx_port + (i * 3));
|
|
eth_sip_link(i, sip_ipaddr, sip_port + i);
|
|
return;
|
|
}
|
|
#endif
|
|
// sip_send_dtmf(0, 1, 101);
|
|
}
|
|
|
|
static void ucc_eth_unconfig(void)
|
|
{
|
|
int i = 0;
|
|
for(i = 0; i < MAX_SIP_CH_NUM; i++)
|
|
{
|
|
eth_unlink(i, PORT_TYPE_B2B);
|
|
eth_unlink(i, PORT_TYPE_IPR);
|
|
eth_unlink(i, PORT_TYPE_T38);
|
|
eth_unlink(i, PORT_TYPE_SIPRTP);
|
|
}
|
|
}
|
|
|
|
|
|
module_init(ucc_test_init);
|
|
module_exit(ucc_test_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Synway");
|
|
MODULE_DESCRIPTION("spbx ucc test drv");
|
|
MODULE_VERSION("0.92");
|