init ems server code

This commit is contained in:
2024-09-27 15:39:34 +08:00
parent 9d4009aaca
commit 9930e4e58f
1551 changed files with 110216 additions and 102864 deletions

99
plat/tcap/Makefile Normal file
View File

@@ -0,0 +1,99 @@
##----------------------------------------------------------##
## ##
## 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 = tcap
TYPE = plat
DBUG_FLAGS_ADD =
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
MAKE_INCLUDE = $(HOME)/ems.git/include
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include $(MAKE_INCLUDE)/Makefile.rules

269
plat/tcap/src/idmanage.c Normal file
View File

@@ -0,0 +1,269 @@
/* ID management c file */
/* written by Liu zhiguo 2002-08-06 */
/* version 2.0 */
/* ----------------------------- */
#include "../../sccp/src/include/sccp.h"
#include "./include/tcap_public.h"
#include "./include/tcap_struct.h"
/*@ignore@*/
#define ID_VM_KEY 0xa0800000
#define ID_VM_PERM 0664
typedef struct id_struct
{
u32 current_did;
u32 count_did;
u32 count_did_occupied;
u32 count_did_max;
u32 count_did_tmp;
u8 dialogue_id[MAX_DIALOGUEID];
u8 current_iid[MAX_DIALOGUEID];
u8 invoke_id[MAX_DIALOGUEID][MAX_INVOKEID];
}id_struct;
struct id_struct *ID_ptr;
typedef struct _did_queunce_struct
{
u32 head;
u32 tail;
u32 idle_did[MAX_DIALOGUEID*2];
}did_queunce_struct;
did_queunce_struct tcap_did_queunce;
void init_id(int grantdid) // init the ID share memory
{
int shm_id,i;
/* tcap state machine share memory */
if ((shm_id = shmget(ID_VM_KEY,sizeof(id_struct),ID_VM_PERM|IPC_CREAT)) == -1)
{
printf("can not init ID share memory");
exit(0);
}
if ((ID_ptr = (id_struct *)shmat(shm_id,(char *)0,0)) == (id_struct *) -1)
{
printf("can not init ID share memory");
exit(0);
}
memset(ID_ptr,0,sizeof(id_struct));
memset(&tcap_did_queunce,0,sizeof(did_queunce_struct));
for(i=1;i<grantdid;i++)
{
tcap_did_queunce.idle_did[tcap_did_queunce.head++]=i;
tcap_did_queunce.head %= (MAX_DIALOGUEID*2);
}
}
u32 chkcount_did(void)
{
return ID_ptr->count_did;
}
u32 chkcount_did_occupied(void)
{
return ID_ptr->count_did_occupied;
}
u32 chkcount_did_max(void)
{
return ID_ptr->count_did_max;
}
void clrcount_did_max(void)
{
ID_ptr->count_did_max = 0;
}
u8 xapp_check_did_state(u32 did);
u32 assign_did(void)
{
u32 tmp_did=0;
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
if(tcap_did_queunce.head != tcap_did_queunce.tail)
{
tmp_did = tcap_did_queunce.idle_did[tcap_did_queunce.tail++];
tcap_did_queunce.tail %= (MAX_DIALOGUEID*2);
if(ID_ptr->dialogue_id[tmp_did])
{
debug_ptr->watch_dog[218] ++;
assign_did();
}
ID_ptr->dialogue_id[tmp_did] = 1;
ID_ptr->count_did ++;
debug_ptr->watch_dog[223]++;
}
else
{
debug_ptr->watch_dog[218] ++;
}
return tmp_did%MAX_DIALOGUEID;
}
u32 assign_did1(void) // assign dialogue id
{
u32 ii;
u32 jj;
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
for (ii = 1;ii < (tcap_ptr->grantdid);ii++)
{
jj = (ID_ptr->current_did++) % (tcap_ptr->grantdid);
if ((jj != 0) && (ID_ptr->dialogue_id[jj] == 0) && (xapp_check_did_state(jj)))
{
ID_ptr->dialogue_id[jj] = 1;
ID_ptr->count_did ++;
ID_ptr->current_did = ID_ptr->current_did % (tcap_ptr->grantdid);
debug_ptr->watch_dog[223]++;
return jj;
}
}
debug_ptr->watch_dog[218] ++;
return 0;
}
void free_did(u32 did)
{
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
if (did == 0 || did >= (tcap_ptr->grantdid))
{
debug_ptr->watch_dog[219] ++;
return;
}
if (ID_ptr->dialogue_id[did] == 1)
{
ID_ptr->dialogue_id[did] = 0;
if (ID_ptr->count_did != 0)
ID_ptr->count_did --;
memset(ID_ptr->invoke_id[did],0,MAX_INVOKEID); // free all invoke id
debug_ptr->watch_dog[213] ++;
tcap_did_queunce.idle_did[tcap_did_queunce.head++] = did;
tcap_did_queunce.head %= (MAX_DIALOGUEID*2);
}
debug_ptr->watch_dog[220] ++;
}
void free_did1(u32 did) // free dialogue id
{
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
if (did == 0 || did >= (tcap_ptr->grantdid))
{
debug_ptr->watch_dog[219] ++;
return;
}
if (ID_ptr->dialogue_id[did] == 1)
{
ID_ptr->dialogue_id[did] = 0;
if (ID_ptr->count_did != 0)
ID_ptr->count_did --;
memset(ID_ptr->invoke_id[did],0,MAX_INVOKEID); // free all invoke id
debug_ptr->watch_dog[213] ++;
}
debug_ptr->watch_dog[220] ++;
}
int check_did(u32 did)
{
if (did == 0 || did >= (tcap_ptr->grantdid))
return 0;
if (ID_ptr->dialogue_id[did] == 0) // dialogue id is not assigned
return 0;
else
return 1;
}
u8 assign_iid(u32 did) // assign invoke id,need know the dialogue id
{
u32 ii, iid=64;
u8 current_iid;
//char buf[128];
if (did == 0 || did >= (tcap_ptr->grantdid))
return 0xff;
current_iid = ID_ptr->current_iid[did];
for (ii = 0;ii < MAX_INVOKEID;ii ++)
{
iid = (ii + 64 + current_iid) % MAX_INVOKEID;// % MAX_INVOKEID;
if (ID_ptr->invoke_id[did][iid] == 0)
{
//sprintf(buf,"assign iid: iid=%d, ii=%d, current_iid=%d\n",
// iid,ii,current_iid);
// tcap_send_ascout(buf);
ID_ptr->invoke_id[did][iid] = 1;
ID_ptr->current_iid[did]++;
return iid;
}
}
//tcap_send_ascout("assign iid failed\n");
memset(ID_ptr->invoke_id[did],0,MAX_INVOKEID);
return assign_iid(did);
}
void free_iid(u32 did,u8 iid) // free invoke id
{
//u8 info[1024];
//u8 suc = 0;
if (did >= 0 && did < (tcap_ptr->grantdid))
{
ID_ptr->invoke_id[did][iid] = 0;
//suc = 1;
}
//sprintf(info, "free_iid: did: %d, iid: %d suc: %d\r\n", did, iid, suc);
//tcap_send_ascout(info);
}
int check_iid(u32 did,u8 iid) // check invoke id
{
if (did == 0 || did >= (tcap_ptr->grantdid))
return 0;
if (ID_ptr->invoke_id[did][iid] == 0)
return 0;
else
return 1;
}
u8 store_iid(u32 did,u8 iid) // store invoke id
{
//u8 info[1024];
//sprintf(info, "store_iid: did: %d, iid: %d\r\n", did, iid);
//tcap_send_ascout(info);
if (did == 0 || did >= (tcap_ptr->grantdid))
return 0;
//if (iid == 0)
// memset(ID_ptr->invoke_id[did],0,MAX_INVOKEID);
//Change by daniel on 2006-6-19
////tcap do not has state machine for receiving invoke, so no need to look at the iid state everytime,
////just set it to be occupied everytime
//if (ID_ptr->invoke_id[did][iid] == 1)
// return 0;
ID_ptr->invoke_id[did][iid] = 1;
ID_ptr->current_iid[did]++;
return 1;
}
void SetCurrentDid(u_short did)
{
ID_ptr->current_did = did % (tcap_ptr->grantdid);
}
/*@end@*/

View File

@@ -0,0 +1,16 @@
/* ID manage head file */
/* written by Liu Zhiguo 2002-08-06 */
/* Version 2.0 */
/* -------------------------------- */
void init_id();
u32 chkcount_did(void);
u32 chkcount_did_occupied(void);
u32 chkcount_did_max(void);
u32 assign_did();
void free_did(u32 did);
u8 check_did(u32 did);
u8 assign_iid(u32 did);
void free_iid(u32 did,u8 iid);
u8 check_iid(u32 did,u8 iid);
u8 store_iid(u32 did,u8 iid);

View File

@@ -0,0 +1,18 @@
/* itcap head file */
#ifdef _ITCAP_H_
#define _ITCAP_H_
#include "../../../public/src/include/public.h"
#include "tcap_public.h"
#include "tcap_struct.h"
void tcap_disp_dlg(struct CSLdlg_struct *dha_ptr,u8 disp_flag);
void tcap_disp_cmp(struct CSLcmp_struct *cha_ptr,u8 disp_flag);
u8 RecvTcapDlg(struct CSLdlg_struct *dha_ptr,u32 dlg_flag);
u8 RecvTcapCmp(struct CSLcmp_struct *cha_ptr,u32 dlg_flag);
u8 SendTcapDlg(struct CSLdlg_struct *dha_ptr);
u8 SendTcapCmp(struct CSLcmp_struct *cha_ptr);
int itcap_reg_ssn(u8 ssn);
void tcap_change_local_ssn(u32 proc,u8 src_ssn,u8 dst_ssn);
#endif

View File

@@ -0,0 +1,256 @@
/* TCAP head file */
/* Written by Liu Zhiguo 2002-08-06 */
/* Version 2.0 */
/* --------------------------------- */
#ifndef _TCAP_HEAD
#define _TCAP_HEAD
/* TC or TR dialogue portion */
/* TC or TR message type tag */
#define Unidirectional 0x61
#define Begin 0x62
#define End 0x64
#define Continue 0x65
#define P_Abort 0x66 // terminated by service provider
#define U_Abort 0x67 // terminated by TC user
#define Abort 0x67
#define Notice 0x68 // Network Service Provider inform
#define Unidirectional_Ansi 0xE1
#define Query_WithPerm_Ansi 0xE2
#define Query_WithoutPerm_Ansi 0xE3
#define Response_Ansi 0xE4
#define Conversation_WithPerm_Ansi 0xE5
#define Conversation_WithoutPerm_Ansi 0xE6
#define Abort_Ansi 0xF6
#define P_Abort_Ansi 0xF5 // terminated by service provider
#define U_Abort_Ansi 0xF6 // terminated by TC user
/* transaction ID tags */
#define Org_TID 0x48 // originating transaction ID tag
#define Dst_TID 0x49 // destination transaction ID tag
/* P-Abort cause tag */
#define P_Abort_Cause 0x4a
/* coding of P-Abort Cause values */
#define P_Abort_UMT 0x00 // unrecognized message type
#define P_Abort_UTID 0x01 // unrecognized transaction ID
#define P_Abort_BFTP 0x02 // badly formatted transaction portion
#define P_Abort_ITP 0x03 // incorrect transaction portion
#define P_Abort_RL 0x04 // resource limitation
#define P_Abort_ADLG 0x05 // abnormal dialogue
#define P_Abort_NCDP 0x06 // no common dialogue portion
#define P_Abort_UMT_Ansi 0x01 // unrecognized message type
#define P_Abort_ITP_Ansi 0x02 // incorrect transaction portion
#define P_Abort_BFTP_Ansi 0x03 // badly formatted transaction portion
#define P_Abort_UTID_Ansi 0x04 // unrecognized transaction ID
#define P_Abort_PTRP_Ansi 0x05 // permission to release problem
#define P_Abort_RL_Ansi 0x06 // resource limitation
#define P_Abort_UDPID_Ansi 0x07 // unrecognized dialogue portion id
#define P_Abort_BSDP_Ansi 0x08 // badly structured dialogue portion
#define P_Abort_MDP_Ansi 0x09 // missing dialogue portion
#define P_Abort_IDP_Ansi 0x0A // inconsistent dialogue portion
/* dialogue portion tag */
#define Dialogue_Portion 0x6b
/* component portion tag */
#define Component_Portion 0x6c
/* TC Component portion */
/* component type tag */
#define Invoke 0xa1
#define Result_L 0xa2 // return result last
#define Error 0xa3 // indicate operation execution failed
#define U_Error 0xa3
#define Reject 0xa4
#define U_Reject 0xa4 // reject by TC user
#define L_Reject 0xa5 // local reject
#define R_Reject 0xa6 // remote reject
#define Result_NL 0xa7 // return result not last
#define L_Cancel 0xa8 // inform TC user local terminated by timeout
#define U_Cancel 0xa8 // local terminate by TC user
#define Invoke_L_Ansi 0xe9 // Invoke Last
#define Result_L_Ansi 0xea // return result last
#define Error_Ansi 0xeb // indicate operation execution failed
#define U_Error_Ansi 0xeb
#define Reject_Ansi 0xec // Reject
#define U_Reject_Ansi 0xec // reject by TC user
#define L_Reject_Ansi 0xe8 // local reject
#define R_Reject_Ansi 0xe7 // remote reject
#define Invoke_NL_Ansi 0xed // Invoke not last
#define Result_NL_Ansi 0xee // return result not last
/* component ID tag */
#define Invoke_ID 0x02
#define Linked_ID 0x80
/* coding of NULL tag */
#define Invoke_ID_NULL 0x05
/* operation code tag */
#define Local_Operation_Code 0x02
#define Global_Operation_Code 0x06
/* parameter tag */
#define Sequence 0x30
#define Set 0x31
/* error code tag */
#define Local_Error_Code 0x02
#define Global_Error_Code 0x06
/* coding of problem type tag */
#define General_Problem 0x80
#define Invoke_Problem 0x81
#define Return_Result 0x82
#define Return_Error 0x83
#define General_Problem_Ansi 0x01
#define Invoke_Problem_Ansi 0x02
#define Return_Result_Ansi 0x03
#define Return_Error_Ansi 0x04
#define Transaction_Ansi 0x05
/* coding of general problem */
#define General_Problem_UC 0x00 // unrecognized component
#define General_Problem_MC 0x01 // mistyped component
#define General_Problem_BSC 0x02 // badly structured component
#define General_Problem_UC_Ansi 0x01 // unrecognized component
#define General_Problem_MC_Ansi 0x02 // mistyped component/incorrect component portion
#define General_Problem_BSC_Ansi 0x03 // badly structured component
#define General_Problem_ICC_Ansi 0x04 // incorrect component coding
/* coding of invoke problem */
#define Invoke_Problem_DIID 0x00 // duplicate invoke ID
#define Invoke_Problem_UO 0x01 // unrecognized operation
#define Invoke_Problem_MP 0x02 // mistyped parameter
#define Invoke_Problem_RL 0x03 // resource limitation
#define Invoke_Problem_IR 0x04 // initiating release
#define Invoke_Problem_ULID 0x05 // unrecognized linked ID
#define Invoke_Problem_LRU 0x06 // linked response unexpected
#define Invoke_Problem_ULO 0x07 // unexpected linked operation
#define Invoke_Problem_DIID_Ansi 0x01 // duplicate invoke ID
#define Invoke_Problem_UO_Ansi 0x02 // unrecognized operation
#define Invoke_Problem_MP_Ansi 0x03 // mistyped parameter
#define Invoke_Problem_ULID_Ansi 0x04 // unrecognized linked ID
/* coding of return result problem */
#define Return_Result_UIID 0x00 // unrecognized invoke ID
#define Return_Result_RRU 0x01 // return result unexpected
#define Return_Result_MP 0x02 // mistyped parameter
#define Return_Result_UIID_Ansi 0x01 // unrecognized invoke ID
#define Return_Result_RRU_Ansi 0x02 // return result unexpected
#define Return_Result_MP_Ansi 0x03 // mistyped parameter
/* coding of return error problem */
#define Return_Error_UIID 0x00 // unrecognized invoke ID
#define Return_Error_REU 0x01 // return error unexpected
#define Return_Error_URE 0x02 // unrecognized error
#define Return_Error_UEE 0x03 // unexpected error
#define Return_Error_MP 0x04 // mistyped parameter
#define Return_Error_UIID_Ansi 0x01 // unrecognized invoke ID
#define Return_Error_REU_Ansi 0x02 // return error unexpected
#define Return_Error_URE_Ansi 0x03 // unrecognized error
#define Return_Error_UEE_Ansi 0x04 // unexpected error
#define Return_Error_MP_Ansi 0x05 // mistyped parameter
/* Dialogue Portion */
/* external tag */
#define External 0x28
/* object identifier */
#define Object_Identifier 0x06
#define Integer 0x02
/* dialogue tag */
#define PDU_AARQ 0x60
#define PDU_AARE 0x61
#define PDU_ABRT 0x64
/* protocol version tag */
#define Protocol_Version 0x80
/* application context name tag */
#define Application_Context_Name 0xa1
/* user information tag */
#define User_Information 0xbe
/* abort source tag */
#define Abort_Source 0x80
/* result tag in Q.773 this tag is 0x82 */
//#define Result 0xa2
/* result source diagnostic tag */
#define Result_Source_Diagnostic 0xa3
/* encoding tag */
#define Single_ASN1_type 0xa0
#define Octet_Aligned 0x81 // maybe 0xa1
#define Arbitrary 0x82 // maybe 0xa2
/* result value */
#define Accepted 0x00
#define Reject_permanent 0x01
/* dialogue service diagnostic tag in Q.773,value is 0x21 and 0x22 */
#define Dialogue_Service_Provider 0x02
#define Dialogue_Service_User 0x01
/* dialogue service user diagnostic tag */
#define DSU_N 0x00 // null
#define DSU_NRG 0x01 // no reason given
#define DSU_ACNNS 0x02 // application context name not supplied
/* dialogue service provider diagnostic tag */
#define DSP_N 0x00 // null
#define DSP_NRG 0x01 // no reason given
#define DSP_NCDP 0x02 // no common dialogue portion
/* abort source */
#define ABRTDlg_Service_User 0x00
#define ABRTDlg_Service_Provider 0x01
/* unidirectional dialogue tag */
#define PDU_AUDT 0x65
#define PDU_ASUDT 0x66
#define REQUEST 1
#define INDICATE 2
#define RESPONSE 3
#define CONFIRM 4
#define PRE_END 1 // pre arranged end
#define BASIC_END 2 // basic end
#define DERR_ASN1 0x01 // decode error: asn1 decode error
#define DERR_UNTYPE 0x02 // decode error: unknown message type
#define DERR_UNTID 0x03 // decode error: lack transaction id
#define DERR_OTHER 0x04 // decode error: other reason
#define UABORT_NULL 0x00 // uabort reason:no
#define UABORT_SPEC 0x01 // uabort reason:specific reason
#define UABORT_ACNNS 0x02 // uabort reason:application context name not supplied
#define ANSI_TAG_CLASS_CONS 0xE0
#define ANSI_TAG_CLASS_PRIM 0xC0
#define ITU_TCAP 0
#define ANSI_TCAP 1
#define TYPE_NATIONAL 0
#define TYPE_PRIVATE 1
#define TYPE_INT 0
#define TYPE_OID 1
#endif

View File

@@ -0,0 +1,21 @@
/* TCAP monitor head file */
/* written by Liu Zhiguo 2001-10-19 */
/* Version 1.0 */
/* -------------------------------- */
#include "../../../public/src/include/pub_include.h"
#ifndef _TCAP_M
#define _TCAP_M
/* in the m.c */
void init_m();
void tcap_set_local_ip();
void tcap_monitor();
void tcap_send_ascout(char *asc_str);
void tcap_send_error(char *err_str);
void tcap_send_alarm(u8 alarm_code,u8 alarm_level);
void HexToDisplay(u8 *to_asc, u8 *from_hex, u8 from_len);
void tcap_send_info(char *info);
#endif

View File

@@ -0,0 +1,3 @@
void tcap_fsm(void); // TCAP state machine, 10ms
void tcap_init(int didgrant,DWORD localip, DWORD peerip); // init TCAP system

View File

@@ -0,0 +1,68 @@
/* TCAP public define head file */
/* written by Liu Zhiguo 2002-08-06 */
/* Version 2.0 */
/* ------------------------------- */
#ifndef _TCAP_PUBLIC
#define _TCAP_PUBLIC
#include "../../../public/src/include/includes.h"
#include "tcap_head.h"
#define MAX_DIALOGUEID 4096
#define MAX_INVOKEID 256
#define TCAP_ASCIN_LEN 80
#define TCAP_ASCOUT_LEN 4096
#define TCAP_UTILIZE_COUNT 97
#define TCAP_UTILIZE_LEN 76
#define TCAP_HB_LEN 8
#define TCAP_DLG_LEN 128 // max dialogue length
#define TCAP_CMP_LEN 256 // max component length
#define TCAP_ACN_LEN 10 // max context name length
#define TCAP_USERINFO_LEN 64 // max user infomation length
#define TCAP_UABORT_INFO_LEN 64 // max user abort infomation length
#define TCAP_SECURITY_CONTEXT_LEN 64 // max security context infomation length
#define TCAP_CONFIDENTIAL_INFO_LEN 64 // max confidentiality infomation length
#define MAX_TEMPINVOKEID 8
#define TCAP_BUF_LEN 256
#define TCAP_SLS_NUM 16
//#define TCAP_PARAM_LEN 170 // max parameter length when has dialogue portion
#define TCAP_PARAM_LEN 210 // max parameter length when has dialogue portion
#define TCAP_PARAM_LEN_1 210 // max parameter length when has not dialogue portion
#define MAX_TSL_BUF 4
#define MAX_CSL_BUF 4
#define TCAP_MODULE_ID 3
#define TCAP_SYSTEM_ID 4
#define TCAP_LED_CODE 5
/* the state of TSM or DSM */
#define TCAP_INIT 0
#define TCAP_IDLE 1
#define TCAP_IR 2 // initiation received
#define TCAP_IS 3 // initiation send
#define TCAP_ACTIVE 4 // active state
#define TCAP_SUSPEND 7 // suspend state
/* the state of ISM */
#define SENT_STATE1 2
#define SENT_STATE2 3
#define SENT_STATE3 4
#define SENT_STATE4 5
#define WAIT_REJECT_STATE 6
/* the class of ISM */
#define OPERATION_CLASS1 1 // operation class 1
#define OPERATION_CLASS2 2 // operation class 2
#define OPERATION_CLASS3 3 // operation class 3
#define OPERATION_CLASS4 4 // operation class 4
#define INVOKE_TIMER 10
#define REJECT_TIMER 2
#define SUSPEND_TIMER 2
#define IDLE_TIMER 60
#define EXPIRE_TIMER 240
#define TCAP_TIMERHZ 50
#define ISM_TIMERHZ 50
#endif

View File

@@ -0,0 +1,391 @@
/* TCAP structure head file */
/* written by Liu Zhiguo 2002-08-06 */
/* Version 2.0 */
/* ------------------------------- */
#ifndef _TCAP_STRUCT
#define _TCAP_STRUCT
#define TCAP_KEY 0xa0100000
#define TCAP_PERM 0664
typedef struct tcapdebug_struct // tcap debug structure
{
u8 default_invtime; // default invoke time, init is 10s
u8 default_rejtime; // default reject time, init is 1s
u8 error_switch; // show error record switch
u8 sccp_switch; // show receive data from sccp switch
u8 tcu_switch; // show send data to TC-User switch
u8 send_control; // control if can send out tcap message
u8 start_time[6];
u8 current_time[6];
u32 monitor_did;
u32 local_ip;
u32 peer_ip;
u8 watch_dog[256];
u8 ascin_buf[TCAP_ASCIN_LEN];
u8 ascout_buf[TCAP_ASCOUT_LEN];
u8 current_csta;
u32 csta_time[TCAP_UTILIZE_COUNT];
u32 tc_utilize[TCAP_UTILIZE_COUNT][TCAP_UTILIZE_LEN];
u8 hb_status[TCAP_HB_LEN];
} tcapdebug_struct;
/* +++++++++++++++++++++++++++++++ */
/* Transaction sub-layer structure */
/* +++++++++++++++++++++++++++++++ */
typedef struct TRUni_struct // transaction unidirectional struct
{
u8 dialogue_len;
u8 components_len;
u8 dialogue[TCAP_DLG_LEN];
u8 components[TCAP_CMP_LEN];
} TRUni_struct;
typedef struct TRBegin_struct // transaction begin struct
{
u8 tid_flag;
u32 transaction_id;
u8 dialogue_len;
u8 components_len;
u8 dialogue[TCAP_DLG_LEN];
u8 components[TCAP_CMP_LEN];
} TRBegin_struct;
typedef struct TRContinue_struct // transaction continue struct
{
u8 ltid_flag;
u8 ptid_flag;
u32 local_tid;
u32 peer_tid;
u8 dialogue_len;
u8 components_len;
u8 dialogue[TCAP_DLG_LEN];
u8 components[TCAP_CMP_LEN];
} TRContinue_struct;
typedef struct TREnd_struct // transaction end struct
{
u8 tid_flag;
u32 transaction_id;
u8 termination;
u8 dialogue_len;
u8 components_len;
u8 dialogue[TCAP_DLG_LEN];
u8 components[TCAP_CMP_LEN];
} TREnd_struct;
typedef struct TRUAbort_struct // transaction u-abort struct
{
u8 tid_flag;
u32 transaction_id;
u8 dialogue_len;
u8 dialogue[TCAP_DLG_LEN];
u8 uabort_info_len;
u8 uabort_info[TCAP_UABORT_INFO_LEN];
} TRUAbort_struct;
typedef struct TRPAbort_struct // transaction p-abort struct
{
u8 tid_flag;
u32 transaction_id;
u8 abort_reason;
} TRPAbort_struct;
typedef struct TRNotice_struct // transcation notice struct
{
u8 tid_flag;
u32 transaction_id;
u8 report_cause;
} TRNotice_struct;
typedef struct TSL_struct
{
u8 message_type;
u8 message_flag;
u8 peer_tid_len; /* added by Pierre, 2006-08-19 */
struct SCCP_ADDRESS local_add;
struct SCCP_ADDRESS peer_add;
union
{
struct TRUni_struct tr_uni;
struct TRBegin_struct tr_begin;
struct TRContinue_struct tr_continue;
struct TREnd_struct tr_end;
struct TRUAbort_struct tr_uabort;
struct TRPAbort_struct tr_pabort;
struct TRNotice_struct tr_notice;
} tsl_prim;
} TSL_struct;
/* +++++++++++++++++++++++++++++++ */
/* Component sub-layer structure */
/* +++++++++++++++++++++++++++++++ */
/* define dialogue handing primitive structure */
typedef struct AARQ_struct
{
u8 version[2];
u8 acn_len;
u8 acn[TCAP_ACN_LEN];
u8 user_info_len;
u8 user_info[TCAP_USERINFO_LEN];
} AARQ_struct;
typedef struct AARE_struct
{
u8 version[2];
u8 acn_len;
u8 acn[TCAP_ACN_LEN];
u8 result;
u8 diagnostic_flag; // user or provider
u8 diagnostic_type; // reason
u8 user_info_len;
u8 user_info[TCAP_USERINFO_LEN];
} AARE_struct;
typedef struct ABRT_struct
{
u8 abort_source;
u8 user_info_len;
u8 user_info[TCAP_USERINFO_LEN];
} ABRT_struct;
typedef struct ASUDT_struct
{
u8 version;
u8 acn_type;
u8 acn_len;
u8 acn[TCAP_ACN_LEN];
u8 user_info_len;
u8 user_info[TCAP_USERINFO_LEN];
u8 security_context_type;
u8 security_context_len;
u8 security_context[TCAP_SECURITY_CONTEXT_LEN];
u8 confidential_info_len;
u8 confidential_info[TCAP_CONFIDENTIAL_INFO_LEN];
} ASUDT_struct;
typedef struct dlgPDU_struct
{
u8 dialogue_type;
union
{
struct AARQ_struct aarq;
struct AARE_struct aare;
struct ABRT_struct abrt;
struct ASUDT_struct asudt;
} pdu_union;
} dlgPDU_struct;
typedef struct dlgport_struct // dialogue portion in the TC
{
u8 acn_type;
u8 acn_len;
u8 acn[TCAP_ACN_LEN];
u8 user_info_len;
u8 user_info[TCAP_USERINFO_LEN];
u8 security_context_type;
u8 security_context_len;
u8 security_context[TCAP_SECURITY_CONTEXT_LEN];
u8 confidential_info_len;
u8 confidential_info[TCAP_CONFIDENTIAL_INFO_LEN];
} dlgport_struct;
typedef struct TCUni_struct // component unidirectional struct
{
struct SCCP_ADDRESS local_add;
struct SCCP_ADDRESS peer_add;
u8 dialogue_flag;
struct dlgport_struct dlg_data;
u8 component_present;
} TCUni_struct;
typedef struct TCBegin_struct
{
struct SCCP_ADDRESS local_add;
struct SCCP_ADDRESS peer_add;
u8 dialogue_flag;
struct dlgport_struct dlg_data;
u8 component_present;
} TCBegin_struct;
typedef struct TCContinue_struct
{
u8 dialogue_flag;
struct dlgport_struct dlg_data;
u8 component_present;
} TCContinue_struct;
typedef struct TCEnd_struct
{
u8 dialogue_flag;
struct dlgport_struct dlg_data;
u8 component_present;
u8 termination;
} TCEnd_struct;
typedef struct TCUAbort_struct
{
u8 uabort_reason;
u8 dialogue_flag;
struct dlgport_struct dlg_data;
u8 uabort_info_len;
u8 uabort_info[TCAP_UABORT_INFO_LEN];
} TCUAbort_struct;
typedef struct TCPAbort_struct
{
u8 pabort_reason;
} TCPAbort_struct;
typedef struct TCNotice_struct
{
u8 report_reason;
} TCNotice_struct;
typedef struct CSLdlg_struct // dialogue primitive in CSL
{
u32 dialogue_id;
u8 message_type;
u8 message_flag;
union
{
struct TCUni_struct tc_uni;
struct TCBegin_struct tc_begin;
struct TCContinue_struct tc_continue;
struct TCEnd_struct tc_end;
struct TCUAbort_struct tc_uabort;
struct TCPAbort_struct tc_pabort;
struct TCNotice_struct tc_notice;
} dlg_prim;
} CSLdlg_struct;
/* define component handing primitive structure */
typedef struct TCInvoke_struct
{
u8 linkedid_flag;
u8 linked_id;
u8 operation_domain;
u8 operation_family;
u8 operation_code;
u8 parameter_len;
u8 parameter[TCAP_CMP_LEN];
u8 operation_class;
u32 timer;
} TCInvoke_struct;
typedef struct TCResult_struct
{
u8 operation_flag; // the flag indicate if has operation code
u8 operation_domain;
u8 operation_family;
u8 operation_code;
u8 parameter_len;
u8 parameter[TCAP_CMP_LEN];
} TCResult_struct;
typedef struct TCUError_struct
{
u8 error_type; // error tag
u8 error_code; // error code
u8 parameter_len;
u8 parameter[TCAP_CMP_LEN];
} TCUError_struct;
typedef struct TCReject_struct
{
u8 problem_type;
u8 problem_code;
u8 parameter_len;
u8 parameter[TCAP_CMP_LEN];
} TCReject_struct;
typedef struct CSLcmp_struct
{
u32 dialogue_id; // dialogue id
u8 invoke_id; // invoke id
u8 message_type;
u8 message_flag;
u8 last_flag;
union
{
struct TCInvoke_struct tc_invoke;
struct TCResult_struct tc_result;
struct TCUError_struct tc_uerror;
struct TCReject_struct tc_reject;
} cmp_prim;
} CSLcmp_struct;
/* +++++++++++++++++++++++++++++++ */
/* TCAP virtue machine structure */
/* +++++++++++++++++++++++++++++++ */
typedef struct ismvm_data
{
u8 used_flag;
u8 linked_iid;
u8 ism_state;
u8 ism_msgtype;
u8 ism_msgflag;
u8 ism_msgclass;
u8 ism_oper_domain;
u8 ism_oper_family;
u8 ism_oper_code;
u32 ism_timer;
} ismvm_data;
typedef struct tcapvm_struct
{
struct SCCP_ADDRESS local_add;
struct SCCP_ADDRESS peer_add;
u8 peer_tid_len;
u32 peer_tid;
u32 tcap_timer;
u8 tcap_state;
u8 ac_mode;
u8 proto_type;
u8 tcaprecv_head;
u8 tcaprecv_tail;
struct ismvm_data ism_data[MAX_TEMPINVOKEID];
struct TSL_struct tsl_data[MAX_TSL_BUF];
} tcapvm_struct;
typedef struct tcapint_struct // tcap interface structure
{
u8 dlgrecv_head;
u8 dlgrecv_tail;
u8 dlgsend_head;
u8 dlgsend_tail;
struct CSLdlg_struct dlg_recv[MAX_TSL_BUF];
struct CSLdlg_struct dlg_send[MAX_TSL_BUF];
u8 cmprecv_head;
u8 cmprecv_tail;
u8 cmpsend_head;
u8 cmpsend_tail;
struct CSLcmp_struct cmp_recv[MAX_CSL_BUF];
struct CSLcmp_struct cmp_send[MAX_CSL_BUF];
} tcapint_struct;
typedef struct tcapbuf_struct // TCAP buffer structure
{
int grantdid;
struct tcapvm_struct tcapvm_data[MAX_DIALOGUEID];
struct tcapint_struct tcapint_data[MAX_DIALOGUEID];
struct tcapdebug_struct tcap_debug;
} tcapbuf_struct;
struct tcapbuf_struct *tcap_ptr;
u8 tsl_message_decode(struct SCLC_MSG *sccp_ptr,struct TSL_struct *dst_ptr,u8 *err_code);// tsl decode
u8 tsl_message_encode(struct SCLC_MSG *sccp_ptr,struct TSL_struct *tsl_ptr,u8 flag);// tsl encode
u8 extract_dp(struct dlgPDU_struct *pdu_ptr,u8 *databuf,int datalen,u8 proto_type); // extract dialogue portion
u8 build_dp(u8 *content,struct dlgPDU_struct *dlg_ptr,u8 un_flag,u8 proto_type); // build dialogue portion
int extract_component(struct CSLcmp_struct *cmp_ptr,u8 *data_buf,u32 proc,int *section_len); // extract component portion
int assemble_component(u8 *string,struct CSLcmp_struct *cha_ptr); // assemble component portion
void tcapvm_init(); // init share memory
u8 write_ism(CSLcmp_struct *cmp_ptr);
void tco_program(void); // transaction coordinator
void tsm_program(u32 proc);
void ism_program(u32 proc); // invocation state machine
#endif

758
plat/tcap/src/itcap.c Normal file
View File

@@ -0,0 +1,758 @@
/* interface c file */
/* written by Liu zhiguo 2002-08-16 */
/* version 2.0 */
/* ----------------------------- */
#include "../../sccp/src/include/sccp.h"
#include "./include/tcap_public.h"
#include "./include/tcap_struct.h"
#include "./include/idmanage.h"
#include "./include/tcap_m.h"
/*@ignore@*/
static u8 t10ms_flag;
static u32 tcap_proc;
u32 tcap_dlg_h[MAX_DIALOGUEID];
u32 tcap_dlg_t[MAX_DIALOGUEID];
u32 tcap_dlg_stats[MAX_DIALOGUEID];
typedef struct id_struct
{
u32 current_did;
u32 count_did;
u32 count_did_occupied;
u32 count_did_max;
u32 count_did_tmp;
u8 dialogue_id[MAX_DIALOGUEID];
u8 current_iid[MAX_DIALOGUEID];
u8 invoke_id[MAX_DIALOGUEID][MAX_INVOKEID];
}id_struct;
extern struct id_struct *ID_ptr;
void tcap_disp_dlg(struct CSLdlg_struct *dha_ptr,u8 disp_flag)
{
char temp_buf[1024],temp_data[1024];
char info_str[1024];
char *cur_time;
struct TCUni_struct *uni_ptr;
struct TCBegin_struct *begin_ptr;
struct TCContinue_struct *con_ptr;
struct TCEnd_struct *end_ptr;
struct TCUAbort_struct *uabrt_ptr;
struct TCPAbort_struct *pabrt_ptr;
u8 proto_type;
if (tcap_ptr->tcap_debug.send_control == 1)
return;
if (tcap_ptr->tcap_debug.tcu_switch == 0 && dha_ptr->dialogue_id != tcap_ptr->tcap_debug.monitor_did)
return;
if (disp_flag == 1) // send data to tc-user
strcpy(info_str,"Dialogue tcap->tc user, time: ");
else
strcpy(info_str,"Dialogue tc user->tcap, time: ");
cur_time = GetAsciiTime();
strcat(info_str,cur_time);
strcat(info_str,"\rType: ");
if (dha_ptr->message_flag == REQUEST)
sprintf(temp_buf,"\tFlag: Request\tDialogue id: %ld\r\n",dha_ptr->dialogue_id);
else
sprintf(temp_buf,"\tFlag: Indicate\tDialogue id: %ld\r\n",dha_ptr->dialogue_id);
if ((dha_ptr->message_type & 0xE0) == ANSI_TAG_CLASS_CONS)
proto_type = ANSI_TCAP;
else
proto_type = ITU_TCAP;
switch (dha_ptr->message_type)
{
case Unidirectional:
case Unidirectional_Ansi:
if (dha_ptr->message_type == Unidirectional)
strcat(info_str,"Unidirectional");
else
strcat(info_str,"Unidirectional_Ansi");
strcat(info_str,temp_buf);
uni_ptr = (TCUni_struct *) &dha_ptr->dlg_prim.tc_uni;
if (uni_ptr->dialogue_flag == 1)
{
if (uni_ptr->dlg_data.acn_len > 0)
{
HexToDisplay(temp_buf,uni_ptr->dlg_data.acn,uni_ptr->dlg_data.acn_len);
sprintf(temp_data,"ACN is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (uni_ptr->dlg_data.user_info_len > 0)
{
HexToDisplay(temp_buf,uni_ptr->dlg_data.user_info,uni_ptr->dlg_data.user_info_len);
sprintf(temp_data,"User info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (proto_type)
{
if (uni_ptr->dlg_data.security_context_len > 0)
{
HexToDisplay(temp_buf,uni_ptr->dlg_data.security_context,uni_ptr->dlg_data.security_context_len);
sprintf(temp_data,"Security context is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (uni_ptr->dlg_data.confidential_info_len > 0)
{
HexToDisplay(temp_buf,uni_ptr->dlg_data.confidential_info,uni_ptr->dlg_data.confidential_info_len);
sprintf(temp_data,"Confidential info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
}
if (uni_ptr->component_present != 0)
strcat(info_str,"Has component\r\n");
strcat(info_str,"\r\n");
break;
case Begin:
case Query_WithPerm_Ansi:
case Query_WithoutPerm_Ansi:
if (dha_ptr->message_type == Begin)
strcat(info_str,"Begin");
else if (dha_ptr->message_type == Query_WithPerm_Ansi)
strcat(info_str,"Query_WithPerm_Ansi");
else
strcat(info_str,"Query_WithoutPerm_Ansi");
strcat(info_str,temp_buf);
begin_ptr = (TCBegin_struct *) &dha_ptr->dlg_prim.tc_begin;
if (begin_ptr->dialogue_flag == 1)
{
if (begin_ptr->dlg_data.acn_len > 0)
{
HexToDisplay(temp_buf,begin_ptr->dlg_data.acn,begin_ptr->dlg_data.acn_len);
sprintf(temp_data,"ACN is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (begin_ptr->dlg_data.user_info_len != 0)
{
HexToDisplay(temp_buf,begin_ptr->dlg_data.user_info,begin_ptr->dlg_data.user_info_len);
sprintf(temp_data,"User info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (proto_type)
{
if (begin_ptr->dlg_data.security_context_len > 0)
{
HexToDisplay(temp_buf,begin_ptr->dlg_data.security_context,begin_ptr->dlg_data.security_context_len);
sprintf(temp_data,"Security context is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (begin_ptr->dlg_data.confidential_info_len > 0)
{
HexToDisplay(temp_buf,begin_ptr->dlg_data.confidential_info,begin_ptr->dlg_data.confidential_info_len);
sprintf(temp_data,"Confidential info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
}
if (begin_ptr->component_present != 0)
strcat(info_str,"Has component\r\n");
strcat(info_str,"\r\n");
break;
case Continue:
case Conversation_WithPerm_Ansi:
case Conversation_WithoutPerm_Ansi:
if (dha_ptr->message_type == Continue)
strcat(info_str,"Continue");
else if (dha_ptr->message_type == Conversation_WithPerm_Ansi)
strcat(info_str,"Conversation_WithPerm_Ansi");
else
strcat(info_str,"Conversation_WithoutPerm_Ansi");
strcat(info_str,temp_buf);
con_ptr = (TCContinue_struct *) &dha_ptr->dlg_prim.tc_continue;
if (con_ptr->dialogue_flag == 1)
{
if (con_ptr->dlg_data.acn_len > 0)
{
HexToDisplay(temp_buf,con_ptr->dlg_data.acn,con_ptr->dlg_data.acn_len);
sprintf(temp_data,"ACN is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (con_ptr->dlg_data.user_info_len != 0)
{
HexToDisplay(temp_buf,con_ptr->dlg_data.user_info,con_ptr->dlg_data.user_info_len);
sprintf(temp_data,"User info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (proto_type)
{
if (con_ptr->dlg_data.security_context_len > 0)
{
HexToDisplay(temp_buf,con_ptr->dlg_data.security_context,con_ptr->dlg_data.security_context_len);
sprintf(temp_data,"Security context is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (con_ptr->dlg_data.confidential_info_len > 0)
{
HexToDisplay(temp_buf,con_ptr->dlg_data.confidential_info,con_ptr->dlg_data.confidential_info_len);
sprintf(temp_data,"Confidential info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
}
if (con_ptr->component_present != 0)
strcat(info_str,"Has component\r\n");
strcat(info_str,"\r\n");
break;
case End:
case Response_Ansi:
if (dha_ptr->message_type == End)
strcat(info_str,"End");
else
strcat(info_str,"Response");
strcat(info_str,temp_buf);
end_ptr = (TCEnd_struct *) &dha_ptr->dlg_prim.tc_end;
if (end_ptr->dialogue_flag == 1)
{
if (end_ptr->dlg_data.acn_len > 0)
{
HexToDisplay(temp_buf,end_ptr->dlg_data.acn,end_ptr->dlg_data.acn_len);
sprintf(temp_data,"ACN is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (proto_type)
{
if (end_ptr->dlg_data.user_info_len != 0)
{
HexToDisplay(temp_buf,end_ptr->dlg_data.user_info,end_ptr->dlg_data.user_info_len);
sprintf(temp_data,"User info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (end_ptr->dlg_data.security_context_len > 0)
{
HexToDisplay(temp_buf,end_ptr->dlg_data.security_context,end_ptr->dlg_data.security_context_len);
sprintf(temp_data,"Security context is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (end_ptr->dlg_data.confidential_info_len > 0)
{
HexToDisplay(temp_buf,end_ptr->dlg_data.confidential_info,end_ptr->dlg_data.confidential_info_len);
sprintf(temp_data,"Confidential info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
}
if (end_ptr->component_present != 0)
strcat(info_str,"Has component\r\n");
strcat(info_str,"\r\n");
break;
case U_Abort:
case U_Abort_Ansi:
if (dha_ptr->message_type == U_Abort)
strcat(info_str,"U_Abort");
else
strcat(info_str,"U_Abort_Ansi");
strcat(info_str,temp_buf);
uabrt_ptr = (TCUAbort_struct *) &dha_ptr->dlg_prim.tc_uabort;
if (uabrt_ptr->dialogue_flag == 1)
{
if (uabrt_ptr->dlg_data.acn_len != 0)
{
HexToDisplay(temp_buf,uabrt_ptr->dlg_data.acn,uabrt_ptr->dlg_data.acn_len);
sprintf(temp_data,"ACN is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (proto_type)
{
if (uabrt_ptr->dlg_data.user_info_len != 0)
{
HexToDisplay(temp_buf,uabrt_ptr->dlg_data.user_info,uabrt_ptr->dlg_data.user_info_len);
sprintf(temp_data,"User info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (uabrt_ptr->dlg_data.security_context_len > 0)
{
HexToDisplay(temp_buf,uabrt_ptr->dlg_data.security_context,uabrt_ptr->dlg_data.security_context_len);
sprintf(temp_data,"Security context is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
if (uabrt_ptr->dlg_data.confidential_info_len > 0)
{
HexToDisplay(temp_buf,uabrt_ptr->dlg_data.confidential_info,uabrt_ptr->dlg_data.confidential_info_len);
sprintf(temp_data,"Confidential info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
}
if (!proto_type)
{
sprintf(temp_buf,"User abort reason: %d\r\n",uabrt_ptr->uabort_reason);
strcat(info_str,temp_buf);
}
else
{
if (uabrt_ptr->uabort_info_len != 0)
{
HexToDisplay(temp_buf,uabrt_ptr->uabort_info,uabrt_ptr->uabort_info_len);
sprintf(temp_data,"User abort info is: %s\r\n",temp_buf);
strcat(info_str,temp_data);
}
}
strcat(info_str, "\r\n");
break;
case P_Abort:
case P_Abort_Ansi:
if (dha_ptr->message_type == P_Abort)
strcat(info_str,"P_Abort");
else
strcat(info_str,"P_Abort_Ansi");
strcat(info_str,temp_buf);
pabrt_ptr = (TCPAbort_struct *) &dha_ptr->dlg_prim.tc_pabort;
sprintf(temp_buf,"Provider abort reason: %d\r\n",pabrt_ptr->pabort_reason);
strcat(info_str,temp_buf);
strcat(info_str, "\r\n");
break;
default:
break;
}
tcap_send_ascout(info_str);
}
void tcap_disp_cmp(struct CSLcmp_struct *cha_ptr,u8 disp_flag)
{
int ii=0;
char temp_buf[1024];
char info_str[1024];
char *cur_time;
u8 proto_type;
struct TCInvoke_struct *invoke_ptr;
struct TCResult_struct *result_ptr;
struct TCUError_struct *uerror_ptr;
struct TCReject_struct *reject_ptr;
if (tcap_ptr->tcap_debug.send_control == 1)
return;
if (tcap_ptr->tcap_debug.tcu_switch == 0 && cha_ptr->dialogue_id != tcap_ptr->tcap_debug.monitor_did)
return;
if (disp_flag == 1) // send data to tc-user
strcpy(info_str,"Component tcap->tc user, time: ");
else
strcpy(info_str,"Component tc user->tcap, time: ");
cur_time = GetAsciiTime();
strcat(info_str,cur_time);
strcat(info_str,"\rType: ");
if (cha_ptr->message_flag == REQUEST)
sprintf(temp_buf,"\tFlag: Request\tDialogue id: %ld, Invoke id: %d\r\n",cha_ptr->dialogue_id,cha_ptr->invoke_id);
else
sprintf(temp_buf,"\tFlag: Indicate\tDialogue id: %ld, Invoke id: %d\r\n",cha_ptr->dialogue_id,cha_ptr->invoke_id);
if ((cha_ptr->message_type & 0xE0) == ANSI_TAG_CLASS_CONS)
proto_type = ANSI_TCAP;
else
proto_type = ITU_TCAP;
switch (cha_ptr->message_type)
{
case Invoke:
case Invoke_L_Ansi:
case Invoke_NL_Ansi:
if (cha_ptr->message_type == Invoke)
strcat(info_str,"Invoke");
else if (cha_ptr->message_type == Invoke_L_Ansi)
strcat(info_str,"Invoke_L_Ansi");
else
strcat(info_str,"Invoke_NL_Ansi");
strcat(info_str,temp_buf);
invoke_ptr = (TCInvoke_struct *) &cha_ptr->cmp_prim.tc_invoke;
ii = invoke_ptr->parameter_len;
if (cha_ptr->message_type == Invoke)
sprintf(temp_buf,"Operation code: %d\tParameter len: %d\r\n",invoke_ptr->operation_code,ii);
else
sprintf(temp_buf,"Operation family: %d\tOperation code: %d\tParameter len: %d\r\n",invoke_ptr->operation_family,invoke_ptr->operation_code,ii);
strcat(info_str,temp_buf);
if (ii != 0)
{
strcat(info_str,"Parameter: ");
HexToDisplay(temp_buf,invoke_ptr->parameter,ii);
strcat(info_str,temp_buf);
strcat(info_str,"\r\n");
}
strcat(info_str, "\r\n");
break;
case Result_L:
case Result_NL:
case Result_L_Ansi:
case Result_NL_Ansi:
if (cha_ptr->message_type == Result_L)
strcat(info_str,"Result_L");
else if (cha_ptr->message_type == Result_NL)
strcat(info_str,"Result_NL");
else if (cha_ptr->message_type == Result_L_Ansi)
strcat(info_str,"Result_L_Ansi");
else
strcat(info_str,"Result_NL_Ansi");
strcat(info_str,temp_buf);
result_ptr = (TCResult_struct *) &cha_ptr->cmp_prim.tc_result;
ii = result_ptr->parameter_len;
if (ii != 0)
{
if ((cha_ptr->message_type == Result_L_Ansi) ||
(cha_ptr->message_type == Result_NL_Ansi))
sprintf(temp_buf,"Operation family: %d\tOperation code: %d\tParameter len: %d\r\n",result_ptr->operation_family,result_ptr->operation_code,ii);
else
sprintf(temp_buf,"Operation code: %d\tParameter len: %d\r\n",result_ptr->operation_code,ii);
strcat(info_str,temp_buf);
strcat(info_str,"Parameter: ");
HexToDisplay(temp_buf,result_ptr->parameter,ii);
strcat(info_str,temp_buf);
strcat(info_str,"\r\n");
}
strcat(info_str, "\r\n");
break;
case U_Error:
case U_Error_Ansi:
if (cha_ptr->message_type == U_Error)
strcat(info_str,"U_Error");
else
strcat(info_str,"U_Error_Ansi");
strcat(info_str,temp_buf);
uerror_ptr = (TCUError_struct *) &cha_ptr->cmp_prim.tc_uerror;
ii = uerror_ptr->parameter_len;
sprintf(temp_buf,"Error code: %d\tParameter len: %d\r\n",uerror_ptr->error_code,ii);
strcat(info_str,temp_buf);
if (ii != 0)
{
strcat(info_str,"Parameter: ");
HexToDisplay(temp_buf,uerror_ptr->parameter,ii);
strcat(info_str,temp_buf);
strcat(info_str,"\r\n");
}
strcat(info_str, "\r\n");
break;
case U_Reject:
case L_Reject:
case R_Reject:
case U_Reject_Ansi:
case L_Reject_Ansi:
case R_Reject_Ansi:
switch (cha_ptr->message_type)
{
case U_Reject:
strcat(info_str,"U_Reject");
break;
case L_Reject:
strcat(info_str,"L_Reject");
break;
case R_Reject:
strcat(info_str,"R_Reject");
break;
case U_Reject_Ansi:
strcat(info_str,"U_Reject_Ansi");
break;
case L_Reject_Ansi:
strcat(info_str,"L_Reject_Ansi");
break;
case R_Reject_Ansi:
strcat(info_str,"R_Reject_Ansi");
break;
}
strcat(info_str,temp_buf);
reject_ptr = (TCReject_struct *) &cha_ptr->cmp_prim.tc_reject;
sprintf(temp_buf,"Problem type: %d\tProblem code: %d",reject_ptr->problem_type,reject_ptr->problem_code);
strcat(info_str,temp_buf);
if (proto_type)
{
ii = reject_ptr->parameter_len;
if (ii != 0)
{
sprintf(temp_buf,"\tParameter len: %d\r\n",ii);
strcat(info_str,temp_buf);
strcat(info_str,"Parameter: ");
HexToDisplay(temp_buf,reject_ptr->parameter,ii);
strcat(info_str,temp_buf);
}
}
strcat(info_str,"\r\n\r\n");
break;
default:
if (cha_ptr->message_type == L_Cancel)
strcat(info_str,"Local cancel");
else if (cha_ptr->message_type == U_Cancel)
strcat(info_str,"User cancel");
strcat(info_str,temp_buf);
strcat(info_str,"\r\n");
break;
}
tcap_send_ascout(info_str);
}
u8 RecvTcapDlg(struct CSLdlg_struct *dha_ptr,u32 dlg_flag) // receive the dialogue portion
{
struct tcapint_struct *int_ptr;
u8 ii;
if (dlg_flag >= (tcap_ptr->grantdid))
return 0;
int_ptr = (tcapint_struct *) &tcap_ptr->tcapint_data[dlg_flag];
ii = int_ptr->dlgrecv_tail;
if (ii == int_ptr->dlgrecv_head)
return 0;
memcpy(dha_ptr,&int_ptr->dlg_recv[ii],sizeof(CSLdlg_struct));
int_ptr->dlgrecv_tail = (ii + 1) % MAX_TSL_BUF;
tcap_disp_dlg(dha_ptr,1);
return 1;
}
u8 RecvTcapCmp(struct CSLcmp_struct *cha_ptr,u32 dlg_flag) // receive the component portion
{
struct tcapint_struct *int_ptr;
u8 ii;
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
if (dlg_flag >= (tcap_ptr->grantdid))
{
debug_ptr->watch_dog[247]++;
return 0;
}
int_ptr = (tcapint_struct *) &tcap_ptr->tcapint_data[dlg_flag];
ii = int_ptr->cmprecv_tail;
if (ii == int_ptr->cmprecv_head)
return 0;
memcpy(cha_ptr,&int_ptr->cmp_recv[ii],sizeof(CSLcmp_struct));
int_ptr->cmprecv_tail = (ii + 1) % MAX_CSL_BUF;
tcap_disp_cmp(cha_ptr,1);
debug_ptr->watch_dog[246]++;
return 1;
}
u8 SendTcapDlg(struct CSLdlg_struct *dha_ptr) // send the dialogue portion
{
struct tcapint_struct *int_ptr;
u32 dlg_flag;
u8 ii;
char info_str[1024];
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
dlg_flag = dha_ptr->dialogue_id;
if (dlg_flag >= (tcap_ptr->grantdid))
{
debug_ptr->watch_dog[194]++;
return 0;
}
int_ptr = (tcapint_struct *) &tcap_ptr->tcapint_data[dlg_flag];
ii = int_ptr->dlgsend_head;
if (tcap_dlg_h[dlg_flag] != int_ptr->dlgsend_head)
{
debug_ptr->watch_dog[192] ++;
//printf("h: %d-%d\n", tcap_dlg_h[dlg_flag], int_ptr->dlgsend_head);
}
if (((ii + 1) % MAX_TSL_BUF) == int_ptr->dlgsend_tail) // buffer is full
{
tcap_send_error("TCAP error. TCU to TCAP buffer is full");
debug_ptr->watch_dog[193]++;
return 0;
}
memcpy(&int_ptr->dlg_send[ii],dha_ptr,sizeof(CSLdlg_struct));
int_ptr->dlgsend_head = (ii + 1) % MAX_TSL_BUF;
tcap_dlg_h[dlg_flag] = int_ptr->dlgsend_head;
switch (dha_ptr->message_type)
{
case U_Abort:
case U_Abort_Ansi:
if (tcap_ptr->tcap_debug.error_switch)
{
if (dha_ptr->message_type == U_Abort)
sprintf(info_str,"CSL warning. Receive U_Abort from TC-user. Did: %ld",dlg_flag);
else
sprintf(info_str,"CSL warning. Receive U_Abort_Ansi from TC-user. Did: %ld",dlg_flag);
tcap_send_error(info_str);
}
break;
case P_Abort:
case P_Abort_Ansi:
if (tcap_ptr->tcap_debug.error_switch)
{
if (dha_ptr->message_type == P_Abort)
sprintf(info_str,"CSL warning. Receive P_Abort from TC-user. Did: %ld",dlg_flag);
else
sprintf(info_str,"CSL warning. Receive P_Abort_Ansi from TC-user. Did: %ld",dlg_flag);
tcap_send_error(info_str);
}
break;
default:
break;
}
tcap_disp_dlg(dha_ptr,2);
if (dha_ptr->message_type == Begin)
{
if (ID_ptr->dialogue_id[dlg_flag] == 0)
debug_ptr->watch_dog[183]++;
if (++tcap_dlg_stats[dlg_flag] > 1)
debug_ptr->watch_dog[182]++;
debug_ptr->watch_dog[196]++;
}
debug_ptr->watch_dog[195]++;
return 1;
}
u8 SendTcapCmp(struct CSLcmp_struct *cha_ptr) // send the component portion
{
struct tcapint_struct *int_ptr;
u32 dlg_flag;
u8 inv_flag;
u8 ii,jj,kk;
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
dlg_flag = cha_ptr->dialogue_id;
inv_flag = cha_ptr->invoke_id;
if (dlg_flag >= (tcap_ptr->grantdid))
{
debug_ptr->watch_dog[253]++;
return 0;
}
//add by daniel on 2006-06-19, to release invoke id propery, if the component is not invoke, then the iid will be released
if ((cha_ptr->message_type != Invoke ) &&
(cha_ptr->message_type != Result_NL))
{
free_iid(dlg_flag,inv_flag);
//tcap_send_ascout("sendTcapCmp free_iid\r\n");
}
//add by daniel on 2006-06-19, to release invoke id propery, if the component is not invoke, then the iid will be released
int_ptr = (tcapint_struct *) &tcap_ptr->tcapint_data[dlg_flag];
tcap_disp_cmp(cha_ptr,2);
if (cha_ptr->message_type == U_Cancel)
{
ii = int_ptr->cmpsend_tail;
while (ii != int_ptr->cmpsend_head) // search any INV component for this DID and TID
{
if (int_ptr->cmp_send[ii].invoke_id == inv_flag) // has data which is not sent out
{
jj = ii;
kk = (ii + 1) % MAX_CSL_BUF;
while (kk != int_ptr->cmpsend_head)
{
memcpy(&int_ptr->cmp_send[jj],&int_ptr->cmp_send[kk],sizeof(CSLcmp_struct));
jj = (jj + 1) % MAX_CSL_BUF;
kk = (kk + 1) % MAX_CSL_BUF;
}
if (int_ptr->cmpsend_head == 0)
int_ptr->cmpsend_head = MAX_CSL_BUF - 1;
else
int_ptr->cmpsend_head -= 1;
if (int_ptr->cmpsend_head == ii)
{
write_ism(cha_ptr);
debug_ptr->watch_dog[238]++;
debug_ptr->watch_dog[255]++;
return 1;
}
}
ii = (ii + 1) % MAX_CSL_BUF;
debug_ptr->watch_dog[235]++;
}
write_ism(cha_ptr);
debug_ptr->watch_dog[240]++;
debug_ptr->watch_dog[255]++;
return 1;
}
ii = int_ptr->cmpsend_head;
if (((ii + 1) % MAX_CSL_BUF) == int_ptr->cmpsend_tail) // buffer full
{
tcap_send_alarm(3,1);
tcap_send_error("CSL warning. ISM buffer is full");
debug_ptr->watch_dog[254]++;
return 0;
}
memcpy(&int_ptr->cmp_send[ii],cha_ptr,sizeof(CSLcmp_struct));
int_ptr->cmpsend_head = (ii + 1) % MAX_CSL_BUF;
if ((cha_ptr->message_type == U_Reject) ||
(cha_ptr->message_type == U_Reject_Ansi) ||
(cha_ptr->message_type == Invoke) ||
(cha_ptr->message_type == Invoke_L_Ansi) ||
(cha_ptr->message_type == Invoke_NL_Ansi))
{
debug_ptr->watch_dog[239]++;
write_ism(cha_ptr);
}
else
{
debug_ptr->watch_dog[237]++;
if (cha_ptr->message_type != Result_L)
{
debug_ptr->watch_dog[236]++;
// printf("tcap: %d\n", cha_ptr->message_type);
}
}
debug_ptr->watch_dog[255]++;
return 1;
}
void tcap_fsm(void) // TCAP state machine
{
register u32 proc;
struct tcapdebug_struct *debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
// write_paralport(TCAP_LED_CODE,1);
t10ms_flag ++;
if (t10ms_flag >= 2) // 20ms circle
{
t10ms_flag = 0;
tcap_monitor();
}
for (proc = 0;proc < 64;proc++)
tco_program();
for (proc = 0;proc < (tcap_ptr->grantdid)/2;proc ++)
{
ism_program(tcap_proc);
tsm_program(tcap_proc);
if (tcap_proc != 0)
{
if (check_did(tcap_proc) || !xapp_check_did(tcap_proc))
ID_ptr->count_did_tmp++;
}
if (tcap_proc == (tcap_ptr->grantdid - 1))
{
if ((ID_ptr->count_did_occupied = ID_ptr->count_did_tmp) > ID_ptr->count_did_max)
ID_ptr->count_did_max = ID_ptr->count_did_occupied;
ID_ptr->count_did_tmp = 0;
memcpy(&debug_ptr->watch_dog[160], (BYTE *) &ID_ptr->count_did, sizeof(u32));
memcpy(&debug_ptr->watch_dog[164], (BYTE *) &ID_ptr->count_did_occupied, sizeof(u32));
memcpy(&debug_ptr->watch_dog[168], (BYTE *) &ID_ptr->count_did_max, sizeof(u32));
}
tcap_proc = (tcap_proc + 1) % (tcap_ptr->grantdid);
}
// write_paralport(TCAP_LED_CODE,0);
}
int itcap_reg_ssn(u8 ssn)
{
return register_ssn(ssn,0);
}
int tcap_get_grantdid()
{
return ((tcap_ptr->grantdid>MAX_DIALOGUEID) \
? MAX_DIALOGUEID: tcap_ptr->grantdid);
}
void tcap_init(int didgrant,DWORD localip,DWORD peerip) // init TCAP system
{
printf("Tcap init start!\n");
if( didgrant <= 0 || didgrant > MAX_DIALOGUEID)
{
printf( "unexpect tcap did grant number!\r\n");
exit(0);
}
init_id(didgrant);
tcapvm_init(localip,peerip);
tcap_ptr->grantdid = didgrant;
init_m();
t10ms_flag = 0;
tcap_proc = 0;
memset(tcap_dlg_h, 0, sizeof(u32) * MAX_DIALOGUEID);
memset(tcap_dlg_t, 0, sizeof(u32) * MAX_DIALOGUEID);
memset(tcap_dlg_stats, 0, sizeof(u32) * MAX_DIALOGUEID);
printf("Tcap init complete!\n");
}
/*@end@*/

2265
plat/tcap/src/tcap_coding.c Normal file

File diff suppressed because it is too large Load Diff

3003
plat/tcap/src/tcap_fsm.c Normal file

File diff suppressed because it is too large Load Diff

603
plat/tcap/src/tcap_m.c Normal file
View File

@@ -0,0 +1,603 @@
/* TCAP monitor c file */
/* Written by Liu Zhiguo 2002-05-06 */
/* Version 1.0 */
/* ----------------------------------- */
#include "../../public/src/include/pub_include.h"
#include "../../sccp/src/include/sccp.h"
#include "../../debug/src/include/debug.h"
#include "../../snmp/src/include/snmp.h"
#include "../../snmp/src/include/heartbeat.h"
#include "./include/tcap_public.h"
#include "./include/tcap_struct.h"
#include "./include/idmanage.h"
/*@ignore@*/
#define LED_GREEN 9
#define LED_YELLOW 10
#define LED_RED 11
#define MAX_PAGE 8
#define MAX_LINE 22
#define STATE_LINE 20
#define TCAP_CSTA_INTERVAL 15 // tcap CDR interval time:15 minutes
#define TCAP_PREOBJ_LEN 12 // tcap prefix object id length
#define TCAP_HBOBJ_LEN 14 // tcap heartbeat led object id length
#define TCAP_ID_LEN 15
#define TCAP_TITLE_LEN 16
#define TCAP_LINE_LEN 17
#define TCAP_PAGE_POINT 14
#define TCAP_LINE_POINT 15
#define TCAP_VERSION_LEN 3
static struct tcapdebug_struct *debug_ptr;
extern u32 tcap_dlg_stats[MAX_DIALOGUEID];
static u8 tcap_1s_flag;
static u8 tcap_10s_flag;
static u8 sec_page;
static u8 *disp_ptr;
static u8 tcap_status = 1;
static u32 tcap_object_id[] = {1,3,6,1,4,1,1373,1,3,2,2,4};
static u32 tcap_status_id[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,1};
static u32 tcap_version_id[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,2};
static u32 tcap_ascin_id[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,3};
static u32 tcap_ascout_id[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,4};
static u32 tcap_page_title[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,5,1};
static u32 tcap_page_line[] = {1,3,6,1,4,1,1373,1,3,2,3,1,2,TCAP_MODULE_ID + 2,5,2,2};
//static u8 tcap_ver[] = {6,5,10};
static u8 tcap_ver[] = {9,0,6};
static u8 title1[] = {"Page 01\t\tTCAP module information\r\n\nStart time\r\nCurrent time\r\nInvoke timer\r\nReject timer\r\nMonitor did\r\nTcap status\r\n"};
static u8 title2[] = {"Page 02\t\tTCAP watch_dog page\r\n\t\t 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15\r\n"};
static u8 title3[] = {"Page 03\t\tTCAP CSTA information\r\n\t\t 00\t 01\t 02\t 03\t 04\r\nSection page\r\n"};
static u8 ascii[16] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46};
void HexToDisplay(u8 *to_asc, u8 *from_hex, u8 from_len)
{
int i, j = 0;
for (i = 0; i < from_len; i++)
{
to_asc[j] = ascii[from_hex[i] >> 4];
j++;
to_asc[j] = ascii[from_hex[i] & 0x0f];
j++;
to_asc[j] = ' ';
j++;
}
to_asc[j] = '\0';
}
void tcap_send_ascout(char *asc_str)
{
if (debug_ptr->send_control == 1)
return;
if ((strlen(asc_str) + strlen(debug_ptr->ascout_buf)) > TCAP_ASCOUT_LEN/2) // buffer is full
{
debug_ptr->send_control = 1;
// strcat(debug_ptr->ascout_buf,"\r\n--\r\n");
// strcpy(debug_ptr->ascout_buf,asc_str);
}
else
strcat(debug_ptr->ascout_buf,asc_str);
}
void tcap_send_error(char *err_str)
{
char info_str[1024];
if (debug_ptr->error_switch == 0 || debug_ptr->send_control == 1)
return;
sprintf(info_str,"\33[31m%s\33[0m\n\r\n\r",err_str);
tcap_send_ascout(info_str);
}
void tcap_send_info(char *info)
{
char info_str[1024];
if (debug_ptr->sccp_switch == 0 || debug_ptr->send_control == 1)
return;
sprintf(info_str,"%s\n\r",info);
tcap_send_ascout(info_str);
}
u8 tcap_disp_line(u8 page,u8 line)
{
u8 line_len=0;
u32 ii;
disp_ptr = tcap_ver;
switch (page)
{
case 1: // page 1
switch (line)
{
case 0:
disp_ptr = debug_ptr->start_time;
line_len = 6;
break;
case 1:
disp_ptr = debug_ptr->current_time;
line_len = 6;
break;
case 2: // invoke time
disp_ptr = &debug_ptr->default_invtime;
line_len = 1;
break;
case 3: // reject time
disp_ptr = &debug_ptr->default_rejtime;
line_len = 1;
break;
case 4: // monitor dialogue id
disp_ptr = (u8 *) &debug_ptr->monitor_did;
line_len = 4;
break;
case 5: // heartbeat status
disp_ptr = debug_ptr->hb_status;
line_len = TCAP_HB_LEN;
break;
case 6:
line_len = 8;
disp_ptr = (u8 *)&debug_ptr->local_ip;
break;
default:
line_len = 0;
break;
}
break;
case 2: // page 2
if (line < 16)
{
disp_ptr = debug_ptr->watch_dog + line * 16;
line_len = 16;
}
break;
case 3: // page 3
if (line == 0)
{
disp_ptr = &sec_page;
line_len = 1;
}
else if (line < TCAP_UTILIZE_LEN/5+1)
{
ii = sec_page % (TCAP_UTILIZE_COUNT-1);
disp_ptr = (char *)&debug_ptr->tc_utilize[ii][(line-1)*5];
line_len = 20;
}
break;
case 4: // tcap state
if (line < STATE_LINE)
{
ii = (sec_page * STATE_LINE + line) % (tcap_ptr->grantdid);
disp_ptr = (u8 *) &tcap_ptr->tcapvm_data[ii].peer_tid;
line_len = 20;
}
else if (line == STATE_LINE+1)
{
disp_ptr = &sec_page;
line_len = 1;
}
break;
case 5: // ism state
if (line < MAX_TEMPINVOKEID)
{
ii = sec_page % (tcap_ptr->grantdid);
disp_ptr = (u8 *) &tcap_ptr->tcapvm_data[ii].ism_data[line].used_flag;
line_len = 20;
}
else if (line == MAX_TEMPINVOKEID+1)
{
disp_ptr = &sec_page;
line_len = 1;
}
break;
default:
line_len = 0;
break;
}
return line_len;
}
void tcap_disp_page(u8 page)
{
u8 line;
u8 line_len;
tcap_page_line[TCAP_PAGE_POINT] = page + 5;
for (line = 0;line < MAX_LINE;line ++)
{
line_len = tcap_disp_line(page,line);
tcap_page_line[TCAP_LINE_POINT] = line + 2;
debug_set_response(TCAP_LINE_LEN,tcap_page_line,disp_ptr,line_len);
}
}
int tcap_snmp_set(u8 oid_len,u32 *oid,u8 *data_buf,u16 data_len)
{
u8 ii;
ii = TCAP_PREOBJ_LEN;
if (oid_len < ii+2)
return -1;
switch (oid[ii])
{
case 2: // set timer
switch (oid[ii+1])
{
case 1: // set invoke timer
if (data_len == 1) // only one octet
{
debug_ptr->default_invtime = data_buf[0];
return 1;
}
break;
case 2: // set reject timer
if (data_len == 1)
{
debug_ptr->default_rejtime = data_buf[0];
return 1;
}
break;
case 3: // set monitor switch
switch (oid[ii+2])
{
case 1: // monitor SCCP
if (data_len == 1)
{
debug_ptr->sccp_switch = data_buf[0];
return 1;
}
break;
case 2: // monitor tcu
if (data_len == 1)
{
debug_ptr->tcu_switch = data_buf[0];
return 1;
}
break;
case 3: // monitor error
if (data_len == 1)
{
debug_ptr->error_switch = data_buf[0];
return 1;
}
break;
case 4: // monitor dialogue id
if (data_len <= 4)
{
debug_ptr->monitor_did = bcdtou32(data_buf,data_len);
return data_len;
}
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
return -1; // set fail
}
int tcap_snmp_get(u8 oid_len,u32 *oid,u8 *data_buf,u8 *data_type)
{
u8 ii,jj,kk;
int data_len=-1;
ii = TCAP_PREOBJ_LEN;
if (oid_len <= ii+1)
return -1;
switch (oid[ii]) // judge object id
{
case 1: // measure
if (oid_len != ii + 2) // reach instance, get total measure data
return -1; // not support
if (oid[ii+1] > TCAP_UTILIZE_COUNT-2)
return -1;
if (oid[ii+1] == debug_ptr->current_csta)
return -1;
jj = oid[ii+1];
if (debug_ptr->csta_time[jj] == 0)
return 0;
u32tobyte(data_buf,debug_ptr->csta_time[jj]);
data_len = 4;
for (kk = 0;kk < TCAP_UTILIZE_LEN;kk ++)
u32tobyte(data_buf+(kk+1)*4,debug_ptr->tc_utilize[jj][kk]);
data_len += TCAP_UTILIZE_LEN * 4;
*data_type = 4;
break;
case 2: // configure
switch (oid[ii+1])
{
case 1: // invoke timer
data_len = 1;
data_buf[0] = debug_ptr->default_invtime;
*data_type = 2;
break;
case 2: // reject timer
data_len = 1;
data_buf[0] = debug_ptr->default_rejtime;
*data_type = 2;
break;
case 3: // monitro switch
switch (oid[ii+2])
{
case 1: // sccp switch
data_buf[0] = debug_ptr->sccp_switch;
data_len = 1;
*data_type = 2;
break;
case 2: // tcu switch
data_buf[0] = debug_ptr->tcu_switch;
data_len = 1;
*data_type = 2;
break;
case 3: // error switch
data_buf[0] = debug_ptr->error_switch;
data_len = 1;
*data_type = 2;
break;
case 4: // dialogue id switch
u32tobyte(data_buf,debug_ptr->monitor_did);
data_len = 4;
*data_type = 4;
break;
default:
break;
}
break;
default:
break;
}
break;
case 3: // status
switch (oid[ii+1])
{
case 1: // get version
data_len = TCAP_VERSION_LEN;
memcpy(data_buf,tcap_ver,data_len);
*data_type = 4;
break;
case 2: // get tcap status
data_len = TCAP_HB_LEN;
memcpy(data_buf,debug_ptr->hb_status,data_len);
*data_type = 4;
break;
default:
break;
}
break;
default: // can not recognize object id
break;
}
return data_len; // get fail
}
void init_m(void)
{
u8 page,ii;
char info_str[1024];
char temp_str[256];
char *cur_time;
u32 str_len;
debug_ptr = (tcapdebug_struct *) &tcap_ptr->tcap_debug;
tcap_1s_flag = 0;
tcap_10s_flag = 0;
sec_page = 0;
GetCurrentTime(debug_ptr->start_time);
debug_ptr->ascin_buf[0] = '\0';
debug_ptr->ascout_buf[0] = '\0';
debug_set_response(TCAP_ID_LEN,tcap_status_id,&tcap_status,1); // set status id
sprintf(info_str,"R%dV%d_%02d",tcap_ver[0],tcap_ver[1],tcap_ver[2]);
debug_set_response(TCAP_ID_LEN,tcap_version_id,info_str,strlen(info_str)); // set module description
debug_set_response(TCAP_ID_LEN,tcap_ascin_id,debug_ptr->ascin_buf,TCAP_ASCIN_LEN);
debug_set_response(TCAP_ID_LEN,tcap_ascout_id,debug_ptr->ascout_buf,TCAP_ASCOUT_LEN);
for (page = 1;page < MAX_PAGE;page ++)
{
switch (page)
{
case 1:
sprintf(info_str,"Version:R%dV%dT%d\t%s",tcap_ver[0],tcap_ver[1],tcap_ver[2],title1);
str_len = strlen(info_str);
break;
case 2:
sprintf(info_str,"Version:R%dV%dT%d\t%s",tcap_ver[0],tcap_ver[1],tcap_ver[2],title2);
for (ii = 0;ii < 16;ii ++)
{
sprintf(temp_str,"watch_dog%d\r\n",ii*16);
strcat(info_str,temp_str);
}
str_len = strlen(info_str);
break;
case 3:
sprintf(info_str,"Version:R%dV%dT%d\t%s",tcap_ver[0],tcap_ver[1],tcap_ver[2],title3);
for (ii = 0;ii < TCAP_UTILIZE_LEN/5;ii ++)
{
sprintf(temp_str,"Data%d--%d\r\n",ii*5,ii*5+4);
strcat(info_str,temp_str);
}
str_len = strlen(info_str);
break;
case 4:
sprintf(info_str,"Version:R%dV%dT%d\tTCAP state\r\n\n",tcap_ver[0],tcap_ver[1],tcap_ver[2]);
for (ii = 0;ii < STATE_LINE;ii ++)
{
sprintf(temp_str,"TCAP %d\r\n",ii);
strcat(info_str,temp_str);
}
strcat(info_str,"\nCurrent_page\r\n");
str_len = strlen(info_str);
break;
case 5:
sprintf(info_str,"Version:R%dV%dT%d\tISM state\r\n\n",tcap_ver[0],tcap_ver[1],tcap_ver[2]);
for (ii = 0;ii < MAX_TEMPINVOKEID;ii ++)
{
sprintf(temp_str,"ISM %d\r\n",ii);
strcat(info_str,temp_str);
}
strcat(info_str,"\nCurrent_page\r\n");
str_len = strlen(info_str);
break;
default:
strcpy(info_str,title1);
str_len = 0;
break;
}
tcap_page_title[TCAP_PAGE_POINT] = page + 5;
debug_set_response(TCAP_TITLE_LEN,tcap_page_title,info_str,str_len);
tcap_disp_page(page);
}
// init snmp portion
// heartbeat_init(TCAP_SYSTEM_ID); // register tcap heartbeat
inquire_setmsg(TCAP_PREOBJ_LEN,tcap_object_id,tcap_snmp_set);
inquire_getmsg(TCAP_PREOBJ_LEN,tcap_object_id,tcap_snmp_get);
debug_ptr->default_invtime = INVOKE_TIMER;
debug_ptr->default_rejtime = REJECT_TIMER;
cur_time = GetAsciiTime();
sprintf(info_str,"TCAP init process completed. Init time is:%s\r",cur_time);
tcap_send_ascout(info_str);
// init_paralport(); // init parallel port
// write_paralport(TCAP_LED_CODE,1);
}
void tcap_monitor(void)
{
// u8 page_n;
u32 ii,jj;
u8 *time_ptr;
u16 used_id;
char info_str[1024],temp_info[1024];
debug_ptr->send_control = 0;
if (strlen(debug_ptr->ascin_buf) > 0) // has command
{
if (strcmp(debug_ptr->ascin_buf+1,"clear") == 0)
{
memset(debug_ptr->watch_dog,0,256);
memset(tcap_dlg_stats, 0, sizeof(u32) * MAX_DIALOGUEID);
clrcount_did_max();
}
else if (strncmp(debug_ptr->ascin_buf+1,"go to ",6) == 0) // change section page
{
ii = atol(debug_ptr->ascin_buf+7);
sec_page = ii;
}
else if (strncmp(debug_ptr->ascin_buf+1,"log port ",9) == 0) // monitor the did
{
ii = atol(debug_ptr->ascin_buf+10);
if (ii >= (tcap_ptr->grantdid))
tcap_send_ascout("The appointed dialogue id is not expected\r\n");
else
debug_ptr->monitor_did = ii;
}
else if (strcmp(debug_ptr->ascin_buf+1,"list para") == 0)// display parameter
{
tcap_send_ascout("The TCAP system parameters are:\r\n");
sprintf(info_str,"Invoke timer:%d s\r\nReject timer:%d s\r\n",debug_ptr->default_invtime,debug_ptr->default_rejtime);
tcap_send_ascout(info_str);
}
else if (strcmp(debug_ptr->ascin_buf+1,"log none") == 0)// close all switch
{
debug_ptr->error_switch = 0;
debug_ptr->sccp_switch = 0;
debug_ptr->tcu_switch = 0;
}
else if (strcmp(debug_ptr->ascin_buf+1,"log error on") == 0)
{
debug_ptr->error_switch = 1;
}
else if (strcmp(debug_ptr->ascin_buf+1,"log error off") == 0)
{
debug_ptr->error_switch = 0;
}
else if (strcmp(debug_ptr->ascin_buf+1,"log all") == 0)
{
debug_ptr->error_switch = 1;
debug_ptr->sccp_switch = 1;
debug_ptr->tcu_switch = 1;
}
else if (strcmp(debug_ptr->ascin_buf+1,"log sccp") == 0)
{
debug_ptr->sccp_switch = 1;
tcap_send_ascout("tcap monitoring sccp message switch open\n\r");
}
else if (strcmp(debug_ptr->ascin_buf+1,"log tcu") == 0)
{
debug_ptr->tcu_switch = 1;
}
else if (strncmp(debug_ptr->ascin_buf+1,"help",6) == 0) // display help message
{
sprintf(temp_info,"%d-%02d-%02d %02d:%02d:%02d",debug_ptr->start_time[0]+2000,debug_ptr->start_time[1],debug_ptr->start_time[2],debug_ptr->start_time[3],debug_ptr->start_time[4],debug_ptr->start_time[5]);
sprintf(info_str,"TCAP module R%dV%d_%02d, start time: %s\r\n\n",tcap_ver[0],tcap_ver[1],tcap_ver[2],temp_info);
tcap_send_ascout(info_str);
tcap_send_ascout("Command list:\r\n");
tcap_send_ascout("log all --------- Turn on all log items\r\n");
tcap_send_ascout("log none --------- Turn off all log items\r\n");
tcap_send_ascout("log error on/off --------- Turn on/off error log item\r\n");
tcap_send_ascout("log tcu --------- Turn on TCAP<->TCUser log item\r\n");
tcap_send_ascout("log sccp --------- Turn on TCAP<->SCCP log item\r\n");
tcap_send_ascout("log port [did] ---- Monitor the specified dialogue id\r\n");
tcap_send_ascout("list para --------- Display TCAP system parameters\r\n");
}
debug_ptr->ascin_buf[0] = '\0';
}
/* for (page_n = 1;page_n < MAX_PAGE;page_n ++)
tcap_disp_page(page_n);*/
if (++tcap_1s_flag > 24)
tcap_1s_flag = 0;
if (tcap_1s_flag == 0)
{
GetCurrentTime(debug_ptr->current_time);
time_ptr = debug_ptr->current_time;
jj = (time_ptr[3]*60+time_ptr[4])/TCAP_CSTA_INTERVAL;
for (ii = 0;ii < TCAP_UTILIZE_LEN;ii ++)
{
if ((time_ptr[4] % TCAP_CSTA_INTERVAL)==0 && time_ptr[5]==0) // clear CDR
{
debug_ptr->tc_utilize[jj][ii] = 0;
debug_ptr->csta_time[jj] = time(NULL);
debug_ptr->current_csta = jj;
}
debug_ptr->tc_utilize[jj][ii] += debug_ptr->tc_utilize[TCAP_UTILIZE_COUNT-1][ii];
debug_ptr->tc_utilize[TCAP_UTILIZE_COUNT-1][ii] = 0;
}
used_id = chkcount_did_occupied();
debug_ptr->tc_utilize[jj][21] += used_id;
if (debug_ptr->tc_utilize[jj][23] < used_id)
debug_ptr->tc_utilize[jj][23] = used_id;
if (++tcap_10s_flag > 9)
tcap_10s_flag = 0;
if (tcap_10s_flag == 0) // 10s timer, set tcap status
{
set_led(TCAP_LED_CODE,LED_GREEN);
memcpy(debug_ptr->hb_status,tcap_ver,TCAP_VERSION_LEN);
debug_ptr->hb_status[TCAP_VERSION_LEN] = tcap_status;
debug_ptr->hb_status[TCAP_VERSION_LEN+1] = used_id >> 8;
debug_ptr->hb_status[TCAP_VERSION_LEN+2] = used_id;
used_id = chkcount_did_max();
debug_ptr->hb_status[TCAP_VERSION_LEN+3] = used_id >> 8;
debug_ptr->hb_status[TCAP_VERSION_LEN+4] = used_id;
set_status(TCAP_MODULE_ID,TCAP_HB_LEN,debug_ptr->hb_status);
//clrcount_did_max();
}
}
}
void tcap_send_alarm(u8 alarm_code,u8 alarm_level)
{
if (alarm_level == 1) // mini alarm
set_led(TCAP_LED_CODE,LED_YELLOW);
else if (alarm_level == 2) // critical alarm
set_led(TCAP_LED_CODE,LED_RED);
set_alarm(TCAP_MODULE_ID,alarm_code);
}
/*@end@*/