This commit is contained in:
zhangsz
2025-03-03 11:01:26 +08:00
parent 5f1710dc22
commit dae6fc93f7
1057 changed files with 519829 additions and 0 deletions

98
plat/tcp/Makefile Normal file
View File

@@ -0,0 +1,98 @@
##----------------------------------------------------------##
## ##
## Universal Makefile for module template : V1.6.3 ##
## ##
## Created : Wei Liu 07/04/11 ##
## Revision: [Last]Wei Liu 07/07/07 ##
## ##
##----------------------------------------------------------##
##---------------------------------------------------------------------##
##--------------------------------------
##
## Project correlation(Customer define)
##
##--------------------------------------
## MODULE= [Module Name]
## TYPE = app/plat => Module Type
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
## BUILD = lib/exef => Output file format
## CFG = debug/release => Build Configuration
## SRC_PATH = [Source file path]
## INC_PATH = [Include file path]
## APP_PATH = [App Module path]
## PLT_PATH = [Plat Module path]
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
## snmp iptrans debug sccp public
##
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
## LIB_ADD e.g. = -liba3a8 -lm
## OBJ_ADD = [Extend third party object files needed]
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
##---------------------------------------------------------------------##
MODULE = tcp
TYPE = plat
DBUG_FLAGS_ADD = -DDEBUG
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = lib
CFG = debug
PLT_LIB =
APP_LIB =
LIB_ADD =
SRC_PATH = ./src
INC_PATH = ./src/include
PLT_PATH = ../../plat
APP_PATH = ../../mss
OBJ_ADD =
TEST_OBJ_PATH =
PREPROC_CMD =
POSTPROC_CMD =
##---------------------------------------------------------------------##
##--------------------------------------
##
## Make configuration(Customer define)
##
##--------------------------------------
## CCFLAG_SWITCH = on/off => gcc flag show on/off
## COVER_NEED = yes/no => PTF cover report needed
## COVER_REPORT_PATH = [path ] => PTF cover report path
CCFLAG_SWITCH = off
COVER_NEED = no
COVER_REPORT_PATH = ./output
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include Makefile.rules

View File

@@ -0,0 +1,20 @@
#ifndef _TCP_DEBUG_H_
#define _TCP_DEBUG_H_
#include "../../../../plat/debug/src/include/debug.h"
extern void tcp_print_time();
extern void tcp_print_debug(const char *fmt, ...);
extern void tcp_print_warn(const char *fmt, ...);
extern void tcp_print_error(const char *fmt, ...);
extern void tcp_print_func(const char *fmt, ...);
extern int tcp_debug_init();
extern void tcp_debug_timer();
//tcp_port.c
extern BOOL tcp_print_all_port(void);
extern BOOL tcp_print_port(int pid);
extern BOOL tcp_clear_stat(int pid);
#endif

View File

@@ -0,0 +1,32 @@
#ifndef _TCP_IF_H_
#define _TCP_IF_H_
#include "tcp_inc.h"
#include "tcp_port.h"
#define TCP_MAX_NUM_OF_SAP 4
#define TCP_MAX_USER_NAME_LEN 16
typedef int (*tcp_recv_callback)(WORD usr_port, BYTE *pdata, WORD datalen, DWORD param1, DWORD param2, DWORD param3);
typedef struct _tcp_sap_t
{
BYTE id;
char name[TCP_MAX_USER_NAME_LEN];
tcp_recv_callback recv_cb;
}tcp_sap_t;
extern void tcp_init(void);
extern void tcp_timer(void);
extern int tcp_bind(tcp_sap_t *ptr_sap);
extern int tcp_unbind(tcp_sap_t *ptr_sap, BYTE index);
extern tcp_sap_t *tcp_sap_get_by_index(int index);
//rtp_port.c
extern int tcp_port_alloc_port(int sap_id, WORD usr_port, tcp_session_t *pSess);
extern int tcp_port_release_port(int sap_id, WORD usr_port, WORD pid);
extern int tcp_send(int sap_id, WORD usr_port, WORD pid, BYTE *payload, WORD len, DWORD param1, DWORD param2, DWORD param3);
extern tcp_session_t *tcp_port_update_sess(int sap_id, WORD usr_port, WORD pid, tcp_session_t *ptr_sess);
#endif

View File

@@ -0,0 +1,134 @@
#ifndef _TCP_INC_H_
#define _TCP_INC_H_
#include "../../../public/src/include/includes.h"
#include "../../../public/src/include/public.h"
/*
//#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <termio.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/io.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#ifndef _T_BYTE
#define _T_BYTE
typedef unsigned char BYTE;
#endif
#ifndef _T_WORD
#define _T_WORD
typedef unsigned short WORD;
#endif
#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned long DWORD;
#endif
#ifndef _T_ULL
#define _T_ULL
typedef unsigned long long ull;
#endif
#ifndef _T_U8
#define _T_U8
typedef unsigned char u8;
#endif
#ifndef _T_U16
#define _T_U16
typedef unsigned short u16;
#endif
#ifndef _T_U32
#define _T_U32
typedef unsigned long u32;
#endif
#ifndef _T_U64
#define _T_U64
typedef unsigned long long u64;
#endif
#ifndef _T_BOOL
#define _T_BOOL
typedef int BOOL;
#endif
#ifndef SUCCESS
#define SUCCESS (0)
#endif
#ifndef FAILURE
#define FAILURE (-1)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef YES
#define YES (1)
#endif
#ifndef NO
#define NO (0)
#endif
#ifndef ERROR
#define ERROR (-1)
#endif
#ifndef EMPTY
#define EMPTY (0)
#endif
#ifndef NULL
#define NULL 0
#endif
#define BUFSIZE 8192
#define MAXBUFLEN 8192
#define MAXLINE 8192
*/
#endif

View File

@@ -0,0 +1,59 @@
#ifndef _TCP_PORT_H_
#define _TCP_PORT_H_
#include "tcp_inc.h"
#define TCP_MAX_NUM_OF_PORT 16
#define TCP_MAX_RECV_MSG_LEN 1500
#define TCP_MAX_SEND_MSG_LEN 1500
#define TCP_MAX_PAYLOAD_SIZE 1350
#define TCP_MAX_RECV_BUF_LEN 8192
#define TCP_MAX_RECV_COUNT 128
typedef struct _tcp_header_t
{
BYTE ver; // version
BYTE pt; // payload type
WORD sn; // sequence number
DWORD timestamp;
DWORD ssrc; //synchronization src
}tcp_header_t;
typedef struct _tcp_session_t
{
DWORD src_ip;
WORD src_port;
DWORD dst_ip;
WORD dst_port;
BYTE bServer; // tcp client: 0; server: 1;
}tcp_session_t;
typedef struct _tcp_port_t
{
BYTE flag;
int index;
BYTE status;
int timer;
int retry_num;
WORD usr_port;
int fd;
int cli_fd;
BYTE rv_buf[TCP_MAX_RECV_BUF_LEN];
int buf_len;
int connected_num;
int disconnect_num;
int sent_fail_num;
tcp_session_t sess;
struct _tcp_sap_t *ptr_sap;
}tcp_port_t;
extern void tcp_port_init(WORD id);
extern void tcp_port_recv_msg(void);
extern int tcp_link_fsm();
int get_tcp_sess(WORD hdlPort, tcp_session_t *sess);
#endif

429
plat/tcp/src/tcp_debug.c Normal file
View File

@@ -0,0 +1,429 @@
/*
**
*/
#include "./include/tcp_debug.h"
#define TCP_MAX_OPR_LEN 16
#define TCP_MAX_OBJ_LEN 32
#define TCP_MAX_VALUE_LEN 32
#define TCP_LOG_OFF 0
#define TCP_LOG_ON 1
#define TCP_MAX_ASC_IN_LEN 128
#define TCP_MAX_ASC_OUT_LEN 4096
#define TCP_DEBUG_ID 36// menu_page2: m
#define TCP_MAX_LINE 10
/*Color Set */
#define TCP_COL_WHITE 37
#define TCP_COL_RED 31
#define TCP_COL_YELLOW 33
#define TCP_COL_GREEN 32
#define TCP_COL_BLUE 34
#define TCP_COL_BROWN 35
#define TCP_COL_MEGEN 36
#define TCP_COL_GRAY 38
#define TCP_COL_HI_WHI 58
#define TCP_COL_HI_RED 39
#define TCP_COL_HI_YEL 52
#define TCP_COL_HI_GRE 51
#define TCP_COL_HI_BLU 53
#define TCP_COL_HI_BRO 54
#define TCP_COL_HI_MEG 55
#define TCP_COL_BLACK 30
#define TCP_COL_ESC '\033'
typedef struct
{
u8 log_time;
u8 log_debug;
u8 log_warn;
u8 log_err;
u8 log_func;
}tcp_debug_t;
char tcp_ascii_in[TCP_MAX_ASC_IN_LEN];
char tcp_ascii_out[TCP_MAX_ASC_OUT_LEN];
tcp_debug_t tcp_debug;
static u8 TCP_VERSION[4] = {1, 0, 0, 2}; //V1.0.01 T002
static u32 debug_status_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,TCP_DEBUG_ID + 2,1
};
static u32 debug_name_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,TCP_DEBUG_ID + 2,2
};
static u32 debug_ascin_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,TCP_DEBUG_ID + 2,3
};
static u32 debug_ascout_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,TCP_DEBUG_ID + 2,4
};
const BYTE tcp_base_id_len = 15;
static char help_menu[] =
{
"TCP log help page\n\r\
========================================================================\n\r\
| Command | Remark |\n\r\
========================================================================\n\r\
| help | help page |\n\r\
| log all/none | display all/none logs |\n\r\
| log warn on/off | display warn logs |\n\r\
| log error on/off | display error logs |\n\r\
| log func on/off | display function logs |\n\r\
| log time on/off | display time logs |\n\r\
| list port[-id] | display tcp port resource |\n\r\
========================================================================\n\r\
"
};
static void tcp_print(const char *fmt, ...)
{
va_list ap;
char buf[1024];
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
if((strlen((char*)tcp_ascii_out) + strlen(buf)) < TCP_MAX_ASC_OUT_LEN)
strcat((char*)tcp_ascii_out, buf);
else
strcpy((char*) tcp_ascii_out, buf);
va_end(ap);
}
void tcp_print_time()
{
struct timeval tv;
struct timezone tz;
struct tm *t;
char timestr[128];
if(!tcp_debug.log_time)
return;
gettimeofday(&tv, &tz);
t = localtime(&tv.tv_sec);
sprintf(timestr, "[%d:%d:%d.%ld] ", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
tcp_print(timestr);
}
void tcp_print_debug(const char *fmt, ...)
{
va_list ap;
char buf[1024];
// if(!tcp_debug.log_debug)
// return ;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
if((strlen((char*)tcp_ascii_out) + strlen(buf)) < TCP_MAX_ASC_OUT_LEN)
strcat((char*)tcp_ascii_out, buf);
else
strcpy((char*)tcp_ascii_out, buf);
va_end(ap);
}
void tcp_print_warn(const char *fmt, ...)
{
va_list ap;
char buf[1024];
if(!tcp_debug.log_warn)
return ;
sprintf(buf, "\33[33mWARN: ");
tcp_print_time();
va_start(ap, fmt);
vsprintf(buf+strlen(buf), fmt, ap);
strcat(buf, "\33[0m");
if((strlen((char*)tcp_ascii_out) + strlen(buf)) < TCP_MAX_ASC_OUT_LEN)
strcat((char*)tcp_ascii_out, buf);
else
strcpy((char*)tcp_ascii_out, buf);
va_end(ap);
}
void tcp_print_error(const char *fmt, ...)
{
va_list ap;
char buf[1024];
if(!tcp_debug.log_err)
return ;
sprintf(buf, "\33[31mERROR: ");
tcp_print_time();
va_start(ap, fmt);
vsprintf(buf+strlen(buf), fmt, ap);
strcat(buf, "\33[0m");
if((strlen((char*)tcp_ascii_out) + strlen(buf)) < TCP_MAX_ASC_OUT_LEN)
strcat((char*)tcp_ascii_out, buf);
else
strcpy((char*)tcp_ascii_out, buf);
va_end(ap);
}
void tcp_print_func(const char *fmt, ...)
{
va_list ap;
char buf[1024];
if(!tcp_debug.log_func)
return ;
sprintf(buf, "\33[32mFUNC: "); //, TCP_COL_GREEN
tcp_print_time();
va_start(ap, fmt);
vsprintf(buf+strlen(buf), fmt, ap);
strcat(buf, "\33[0m");
if((strlen((char*)tcp_ascii_out) + strlen(buf)) < TCP_MAX_ASC_OUT_LEN)
strcat((char*)tcp_ascii_out, buf);
else
strcpy((char*)tcp_ascii_out, buf);
va_end(ap);
}
static int tcp_set_debug(u8 *log_flag, char *value)
{
if(log_flag == NULL || value == NULL)
return -1;
if(strcmp(value, "on") == 0)
*log_flag = TCP_LOG_ON;
else if(strcmp(value, "off") == 0)
*log_flag = TCP_LOG_OFF;
else
return 0;
return 1;
}
static void tcp_set_all_debug()
{
tcp_debug.log_debug = TCP_LOG_ON;
tcp_debug.log_warn = TCP_LOG_ON;
tcp_debug.log_err = TCP_LOG_ON;
tcp_debug.log_func = TCP_LOG_ON;
}
int tcp_debug_init()
{
u8 debug_status;
u8 data[10];
u8 *ptr;
char version_info[16]={""};
memset(tcp_ascii_in,0,128);
memset(tcp_ascii_out,0,4096);
sprintf(version_info,"V%d.%d.%02d",TCP_VERSION[0],TCP_VERSION[1],TCP_VERSION[2]);
// memcpy(rtp_param.sys.version, TCP_VERSION, 4);
ptr = data;
debug_status = 1;
debug_set_response(tcp_base_id_len, debug_status_id, &debug_status,1);
debug_set_response(tcp_base_id_len, debug_name_id, (u8*)version_info,12); /* module name */
debug_set_response(tcp_base_id_len, debug_ascin_id, (u8*)tcp_ascii_in, 128); /* ascii in buf */
debug_set_response(tcp_base_id_len, debug_ascout_id, (u8*)tcp_ascii_out,4096); /* ascii out buf */
return 1;
}
static void tcp_command_decompose(char *opr, char *obj, char *value, char *cmd)
{
int i;
int len;
char *sep;
if(opr == NULL || obj == NULL || value == NULL || cmd == NULL)
return ;
opr[0] = obj[0] = value[0] = '\0';
for(i = 0; i < 80; i++)
{
sep = strsep(&cmd, " \t"); /* Seprate by SPACE and TAB */
if(sep == NULL) /* Touch the end */
return;
else if((len = strlen(sep)) == 0) /* Touch the SPACE or TAB */
continue;
if(opr[0] == '\0')
{
if(len < TCP_MAX_OPR_LEN)
strcpy(opr, sep);
}
else if(obj[0] == '\0')
{
if(len < TCP_MAX_OBJ_LEN)
strcpy(obj, sep);
}
else if(value[0] == '\0')
{
if(len < TCP_MAX_VALUE_LEN)
{
strcpy(value, sep);
return;
}
}
}
}
static int tcp_debug_cmd_handle(char *cmd)
{
char opr[TCP_MAX_OPR_LEN] = {""};
char obj[TCP_MAX_OBJ_LEN] = {""};
char value[TCP_MAX_VALUE_LEN] = {""};
char *ver = (char*)TCP_VERSION;
char *str_start = NULL;
int port;
if(cmd == NULL)
return -1;
tcp_command_decompose(opr, obj, value, cmd);
if(strcmp(opr, "help") == 0 || strcmp(opr, "?") == 0)
tcp_print("%s\r\nV%d.%d.%02d T%03d\r\n", help_menu, ver[0], ver[1], ver[2], ver[3]);
else if(strcmp(opr, "log") == 0)
{
if(strcmp(obj, "all") == 0)
tcp_set_all_debug();
else if(strcmp(obj, "none") == 0)
memset(&tcp_debug, 0, sizeof(tcp_debug_t));
else if(strcmp(obj, "debug") == 0)
return tcp_set_debug(&tcp_debug.log_debug, value);
else if(strcmp(obj, "warn") == 0)
return tcp_set_debug(&tcp_debug.log_warn, value);
else if(strcmp(obj, "error") == 0)
return tcp_set_debug(&tcp_debug.log_err, value);
else if(strcmp(obj, "func") == 0)
return tcp_set_debug(&tcp_debug.log_func, value);
else if(strcmp(obj, "time") == 0)
return tcp_set_debug(&tcp_debug.log_time, value);
else
return 0;
}
else if(strcmp(opr, "list") == 0)
{
if(strstr(obj, "port") != NULL)
{
if((str_start = strstr(obj, "-")) != NULL)
{
port = strtol(str_start+1, NULL, 10);
return tcp_print_port(port);
}
else
return tcp_print_all_port();
}
else
return 0;
}
else if (strcmp(opr, "reset") == 0)
{
if(strstr(obj, "stat") != NULL)
{
if((str_start = strstr(obj, "-")) != NULL)
{
port = strtol(str_start+1, NULL, 11);
return tcp_clear_stat(port);
}
else
return 0;
}
else
return 0;
}
/* else if(strcmp(opr, "save") == 0)
{
if(strcmp(obj, "para") == 0)
rtpproxy_param_save_para();
else
return 0;
}
else if(strcmp(opr, "load") == 0)
{
if(strcmp(obj, "para") == 0)
{
rtpproxy_modify_para();
}
else
return 0;
}*/
/* else if(strcmp(opr, "save") == 0)
{
if(strcmp(obj, "rz") == 0)
return rtp_save_rz();
else if(strcmp(obj, "mg") == 0)
return rtp_save_mg();
else if(strcmp(obj, "sys") == 0)
return rtp_save_system();
else
return 0;
}
else if(strcmp(opr, "test") == 0)
{
if(strcmp(obj, "port_enable") == 0) //
{
int test_i;
for(test_i = 1; test_i < 3; test_i++)
test_rtp_set_port_enable(test_i);
}
else
return 0;
}*/
else
return 0;
return 1;
}
void tcp_debug_timer()
{
int ret, len;
char cmd[128] = {""};
if(tcp_ascii_in[0] == 0)
return;
len = strlen(tcp_ascii_in);
if(len ==0)
return;
if(strlen((char*)&tcp_ascii_in[1]) >= 128)
return;
strcpy(cmd, (char*)&tcp_ascii_in[1]);
memset(tcp_ascii_in, 0, TCP_MAX_ASC_IN_LEN);
ret = tcp_debug_cmd_handle(cmd);
if(ret == 1)
tcp_print("Command OK!\r\n");
else
tcp_print("Command Error!\r\n");
}

99
plat/tcp/src/tcp_if.c Normal file
View File

@@ -0,0 +1,99 @@
/*
*
*/
#include "./include/tcp_if.h"
#include "./include/tcp_port.h"
#include "./include/tcp_debug.h"
static tcp_sap_t tcp_sap[TCP_MAX_NUM_OF_SAP];
static void tcp_sap_init(tcp_sap_t *ptr_sap, BYTE index)
{
if((ptr_sap == NULL) || (index >= TCP_MAX_NUM_OF_SAP))
{
return;
}
ptr_sap->id = index;
strcpy(ptr_sap->name, "\0");
ptr_sap->recv_cb = NULL;
}
tcp_sap_t *tcp_sap_get_by_index(int index)
{
if(index < 0 || index >= TCP_MAX_NUM_OF_SAP)
return NULL;
return &tcp_sap[index];
}
void tcp_init(void)
{
WORD i;
for(i = 0; i < TCP_MAX_NUM_OF_SAP; i++)
{
tcp_sap_init(&tcp_sap[i], (BYTE)i);
}
for(i = 0; i < TCP_MAX_NUM_OF_PORT; i++)
{
tcp_port_init(i);
}
tcp_debug_init();
return;
}
void tcp_timer(void)
{
tcp_link_fsm();
tcp_port_recv_msg();
tcp_debug_timer();
}
int tcp_bind(tcp_sap_t *ptr_sap)
{
BYTE i;
tcp_sap_t *ptr_tmp = NULL;
if((ptr_sap == NULL) || (ptr_sap->recv_cb == NULL))
{
return -1;
}
for(i = 0; i < TCP_MAX_NUM_OF_SAP; i++)
{
ptr_tmp = &tcp_sap[i];
if(ptr_tmp->recv_cb != NULL)
{
continue;
}
memcpy((BYTE*)ptr_tmp, ptr_sap, sizeof(tcp_sap_t));
ptr_tmp->id = i;
ptr_tmp->name[TCP_MAX_USER_NAME_LEN-1] = '\0';
return i;
}
return -1;
}
int tcp_unbind(tcp_sap_t *ptr_sap, BYTE index)
{
if((ptr_sap == NULL) || (index >= TCP_MAX_NUM_OF_SAP))
{
return -1;
}
if(ptr_sap->id != index)
{
return -1;
}
tcp_sap_init(ptr_sap, index);
return 0;
}

1063
plat/tcp/src/tcp_port.c Normal file

File diff suppressed because it is too large Load Diff