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/sccp/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 = sccp
TYPE = plat
DBUG_FLAGS_ADD = -D_CDMA_SNMP -DDEBUG ##-DMEMWATCH -DMEMWATCH_STDIO ##-D_WXC_FSM_TEST
RELS_FLAGS_ADD = -D_CDMA_SNMP -DDEBUG
##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 = ../../app
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

View File

@@ -0,0 +1,324 @@
/******************************************************/
/*Title: sccp.h */
/*Descr: Definition of SCCP */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/******************************************************/
#ifndef _SCCP_HEAD_FILE
#define _SCCP_HEAD_FILE
#include "../../../public/src/include/pub_wnet.h"
#include "../../../snmp/src/include/heartbeat.h"
#include "../../../snmp/src/include/snmp.h"
#include "../../../debug/src/include/debug.h"
#include "../../../mtp3/src/include/mtp3.h"
#include "sccpconst.h"
#ifdef _WXC_FSM_TEST
#define spLogFsm printf
#define spWxcBackTrace() WxcBackTrace()
#else
#define spLogFsm
#define spWxcBackTrace()
#endif
#define MAX_SCLC_BUF 4
#define SCCP_VERSION { 9,1,5}
//////////////////////////////////////////////////////////////////
#define SEG_RS_LEN 3
typedef struct SCCP_Segmnt
{
unsigned RSBits:4;
unsigned SpaceBits:2;
unsigned CBit:1;
unsigned FBit:1;
u8 SegLR[SEG_RS_LEN];
}
SCCP_Segmnt;
typedef struct SCCP_SegUnID
{
int OPC;
int DPC;
u8 SLS;
SCCP_ADDR CGA;
u8 SegLR[SEG_RS_LEN];
}
SCCP_SegUnID;
#define MAX_SEGBLOCK_LEN 256
typedef struct SCCP_SegStream
{
u8 SegDataLen;
u8 SegDataBlock[MAX_SEGBLOCK_LEN];
}
SCCP_SegStream;
#define MAX_SEGSTREAM_SIZE 10
#define MAX_SEGMSG_TIMER 2000
#define SEGSTREAM_IDLE 0x00
#define SEGSTREAM_BUSY 0x01
typedef struct SCCP_SegMsgBuf
{
u8 MsgState;
u8 MsgClass;
u8 MsgTotal;
DWORD SegMsgTimer;
u8 RSE;
SCCP_SegUnID SegID;
SCCP_SegStream SegStream[MAX_SEGSTREAM_SIZE];
}
SCCP_SegMsgBuf;
#define MAX_SEGMSG_BUF 256
/* by simon at 23/9/26 */
//SCCP_SegMsgBuf sccp_segmsgbuf[MAX_SEGMSG_BUF];
typedef struct Intra_Message
{
u8 msgsource; //FROM_MTP:0,FROM_SCLC:1,FROM_SCOC:2,FROM_SCMG:3
u8 msgtype;
u8 msgclass;
u8 msgMNP; /* mnp flag , added by pierre , 11-07 */
int OPC;
int DPC;
u8 SLS;
u8 link;
u8 NetID;
SCCP_ADDR CGA;
SCCP_ADDR CDA;
BOOL EOD;
u8 aSLR[SP_REF_LEN];
u8 aDLR[SP_REF_LEN];
u_short msglen;
u8 data[SCCP_MSG_MAXLEN];
u8 PS;
u8 PR;
u8 RO;
u8 cause;
u8 Hop;
SCCP_Segmnt Segmnt; //
u8 SegPresent;
u8 redirectFlag;
u8 sequenceFlag;
}
Intra_Msg;
//Intra_Msg CurMsg;
typedef struct SCCP_OPT
{
DWORD ip;
long spc[4];
u8 spclen[4];
u8 version[3];
u8 status;
u8 RegSSN[32];
u8 RegNum;
u8 CO_SSN;
long T_reset;
DWORD OMCIP[2];
}
SCCP_OPT;
/* by simon at 23/9/26 */
// SCCP_OPT SCCP_Param;
typedef struct _SCOC_BUF
{
short rcvsub[2];
short sndsub[2];
up_message msgin[SS_MSG_NUM];
up_message msgout[SS_MSG_NUM];
}
SCOC_BUF;
/* by simon at 23/9/26 */
// SCOC_BUF ScocBuf;
#define MAX_SCLCMSG_LEN 256
typedef struct SCLC_MSG
{
u8 primitive;
u8 msg[MAX_SCLCMSG_LEN];
u_short msglen;
u8 sls;
u8 sequence_control; //Class 0: The basic connectionless class without guaranteed in-sequence delivery
//Class 1: The in-sequence delivery connectionless class with guaranteed in-sequence delivery
u8 ret_reason;
SCCP_ADDR src_addr;
SCCP_ADDR dst_addr;
}
SCLC_MSG;
typedef struct _SCLC_BUF
{
short readsub;
short writesub;
SCLC_MSG msglist[SS_MSG_NUM];
}
SCLC_BUF;
typedef struct LOCAL_SSN
{
u8 msisdn[MAX_DIGITS];
u8 status[2]; //0:no 1:equipped(disable) 2:congest 3:enable 4:local&equipped(disable) 5:local&congest 6:local&enable
u8 nbuf;
u8 local;
u8 NetID;
u8 RegFlag;
DWORD ip[2];
short timeout[2];
u8 msisdn_len;
}
LOCAL_SSN;
/* by simon at 23/9/26 */
// LOCAL_SSN LocalSSN[256];
// u8 ExistSSN[64];
// u8 ExistSSNNum;
// u8 MNP_Flag[2];
/* by simon at 23/9/26 */
// struct _dpc2sls
// {
// int dpc;
// u8 sls;
// }dpc2sls[256]; //used for sequence control, add by Roy Jiang, 2007-09-17
/* u80:0/1/2=not support MNP/IN_based/MNP_SRF */
/* u81:0-1/2=direct/indirect routing */
/* added by Pierre, 2005-11-07 for MNP */
/*===================================*/
//MIB===================>
/*===================================*/
typedef struct SCCP_ROUTE
{
u8 avail;
u8 NP;
u8 TT;
u8 StartDigits[MAX_DIGITS];
u8 EndDigits[MAX_DIGITS];
u8 NetID;
u8 DPC[3];
u8 SSN;
u8 RI;
u8 AI; //Address indicator,indicate the Address include GT,DPC,SSN or not,BIT0:point code, bit1:ssn, bit2:GT
u8 ReplaceStart;
u8 ReplaceEnd;
u8 OutNP;
u8 ReplaceDigits[MAX_DIGITS];
u8 acn_ver[48];
u8 convert;
u8 len;
u8 replace_len;
}
SCCP_ROUTE;
/* by simon at 23/9/26 */
// SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
typedef struct SCCP_ROUTE_NODE
{
u_short nItem;
struct SCCP_ROUTE_NODE *psub[10];
}
SCCP_ROUTE_NODE;
typedef struct RL_SSN
{
BOOL status; //0 NULL
u8 SST;
u8 NetID;
u8 SSN;
int DPC;
int timeout;
}
RL_SSN;
/* by simon at 23/09/26 */
// int RelatedSSNNum;
// RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
typedef struct RL_SPC
{
int DPC;
u8 NetID;
BOOL status; //0 NULL
}
RL_SPC;
/* by simon at 23/09/26 */
// int RelatedSPCNum;
// RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
#define SCCP_MAX_GTT_ATTRIBUTE 16
typedef struct GTTATT_OMC
{
u8 attribute[SCCP_MAX_GTT_ATTRIBUTE];
}
GTTATT_OMC;
/* by simon at 23/9/26 */
// GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
typedef struct SCCP_FILTER
{
u8 flag;
u8 src_ssn;
u8 dst_ssn;
int opc;
int dpc;
}
SCCP_FILTER;
typedef struct SCCP_CSTA
{
DWORD timestamp;
DWORD error[21]; //.1.1.?
DWORD avail[12]; //.1.2.?
DWORD utilization[12]; //.1.3.?
DWORD quality[20]; //.1.4.?
}
SCCP_CSTA;
/* by simon at 23/9/26 */
// SCCP_CSTA SccpCsta[96];
// DWORD SccpCstaInd;
/* by simon at 23/9/26 */
// struct sccp_msg_statistic
// {
// DWORD msg_mtp_scoc;
// DWORD msg_scoc_up;
// DWORD mnp_send;
// DWORD mnp_route;
// }
// sccpmsg_st;
typedef struct SCCP_Capture_Buf
{
u8 Pointer;
u8 Buffer[2560];
u8 watch_dog[256];
}
SCCP_Capture_Buf;
/* by simon at 23/9/26 */
// SCCP_Capture_Buf SCCPCapBuf;
#endif

View File

@@ -0,0 +1,165 @@
//////////////////////////////////////////////////
//Title : sccp_func.h
//Auhtor : Liu Wei
//Desc : SCCP function decl
//Created : 2007-04-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
/* sccp.c */
void sccp_init(void);
void sccp_init_serial_number(BYTE *Serial);
void sccp_timer(void);
void sccp_reset(void);
int AddToIpList(DWORD ip, BYTE ssn);
int CollectLocalInfo(void);
int sccp_mnp_register(BYTE flag, BYTE routing_method, BYTE usertype);
int spSetGttAddr(u8 uGtType, u8 uSSN, u8 *uGtNum, struct SCCP_ADDRESS *pSpAddr);
/* sccp_debug.c */
void spLogDebug_setup(void);
void spLogDebug_timer(void);
int parsecmd(char *cmdstr);
int sccp_filter_msg(SCCP_ADDR *pSrcAddr, SCCP_ADDR *pDstAddr);
void spLogDebug_info(BYTE npage, BYTE nline, BYTE *pt, BYTE len);
void spLogDebug_csta(BYTE npage, int instance);
void spLogDebug_local(BYTE npage, BYTE nline);
void spLogDebug_related(BYTE npage, BYTE nline);
void spLogDebug_buffer(BYTE npage);
void spLogDebug_errorCapture(BYTE npage, BYTE nline);
void spLogDebug_WatchDog(BYTE npage);
void sccp_list_route(void);
void sccp_put_capture_logs(BYTE person, BYTE *pictures, int len);
/* sccp_func.c */
int ParseLine(char *str, char (*row)[128], int maxrow);
int GetEnt(FILE *fp, char *key, char *str);
BOOL isco(Intra_Msg *intramsg);
BOOL iscl(Intra_Msg *intramsg);
BOOL iscr(Intra_Msg *intramsg);
/* sccp_gtt.c */
int BuildRouteIndex(void);
u_short SelectRoute(BYTE *pDigits, BYTE DigitsLen);
int GetACNInfo(SCCP_ADDR *pAddr, BYTE **pAcnInfo);
void TranslateGT(SCCP_ADDR *pAddr, SCCP_ROUTE *pRoute);
int AddRoute(BYTE *pStartDigits, BYTE *pEndDigits, BYTE DigitsLen, u_short index);
int AddLargerNode(SCCP_ROUTE_NODE *pNode, BYTE *pDigits, BYTE DigitsLen, u_short index);
int AddLessNode(SCCP_ROUTE_NODE *pNode, BYTE *pDigits, BYTE DigitsLen, u_short index);
SCCP_ROUTE_NODE *NewNode(void);
int CheckGT(BYTE np, BYTE tt, BYTE *gt, BYTE gt_len);
/* sccp_mib.c */
void sccpmib_init(void);
void sccp_sethb(void);
int sccp_setmib(BYTE oidlen, DWORD *oid, BYTE *pdata, WORD datalen);
int sccp_getmib(BYTE oidlen, DWORD *oid, BYTE *pdata, BYTE *vartype);
void sccp_OMCIP_detect(DWORD ip);
void sccp_trapcallback(BYTE oidlen, DWORD *oid, BYTE *pdata, WORD len, snmp_addr *addr);
/* sccp_msg.c */
int build_msg(BYTE *buf, Intra_Msg *intramsg, BYTE NetID, BYTE ansi_flag);
int parse_msg(BYTE *buf, Intra_Msg *intramsg, int len, BYTE NetID, BYTE ansi_flag);
int parse_oparam(BYTE *buf, int len, Intra_Msg *intramsg, BYTE NetID, BYTE ansi_flag);
int encode_int(BYTE *buf, unsigned int val, BYTE len);
unsigned int decode_int(BYTE *buf, BYTE len);
int encode_addr(BYTE *buf, SCCP_ADDR *addr, BYTE NetID);
int decode_addr(BYTE *buf, SCCP_ADDR *addr, BYTE NetID);
int encode_addr_Ansi(BYTE *buf, SCCP_ADDR *addr);
int decode_addr_Ansi(BYTE *buf, SCCP_ADDR *addr);
/* sclc.c */
int scrc2sclc(Intra_Msg *pIntraMsg);
int sclc_rf(Intra_Msg *pIntraMsg);
int scmg2sclc(Intra_Msg *pIntraMsg);
int sclc_send(SCLC_MSG *pmsg);
int sclc_receive(SCLC_MSG *pmsg, BYTE usertype);
void sclc_timer(void);
int sclc_mnp_send(SCLC_MSG *pmsg);
int SegmentingMsg(Intra_Msg *pIntraMsg);
int RecvXUDTMsg(Intra_Msg *pIntraMsg, BYTE nbuf);
int CheckSegUnID(Intra_Msg *pIntraMsg);
int RsmRegMsg(SCLC_MSG *pmsg, SCCP_SegMsgBuf *pSegMsgbuf, Intra_Msg *pIntraMsg);
/* sccp_param.c */
int GetMSISDNOfSSN(BYTE ssn, BYTE *msisdn);
int sccp_GetSSNType(BYTE ssn);
int sccp_loadparam(void);
void sccp_saveparam(void);
int sccp_setparam(DWORD *oid, BYTE *pdata, WORD datalen);
int sccp_getparam(DWORD *oid, BYTE *pdata, BYTE *vartype);
int SccpGetLocalIP(void);
int ParseLocalNode(char *str);
void ParseRouteInfo(char *str);
void ParseRLSSN(char *str);
/* scmg.c */
void localssn_timer(void);
int sclc2scmg(Intra_Msg *intramsg);
BOOL CheckAvail(SCCP_ADDR *addr);
BYTE ssn_status(int spc, BYTE ssn, BYTE NetID);
void spac(int spc, BYTE NetID);
void sppc(int spc, BYTE NetID);
void spcc(int spc, BYTE NetID);
int register_ssn(BYTE ssn, BYTE usertype);
void ssac(int spc, BYTE ssn, BYTE NetID, BOOL relay);
void sscc(int spc, BYTE ssn, BYTE NetID);
int stop_ssn(BYTE ssn);
void sspc(int spc, BYTE ssn, BYTE NetID, BOOL relay);
void sst_timer(void);
void lcst(int spc, BYTE ssn, BYTE ntype, BYTE NetID);
void bcst(BYTE ssn, BYTE ntype);
void bcst_relay(int spc, BYTE ssn, BYTE ntype, BYTE NetID);
int build_scmgmsg(BYTE *data, BYTE type, int spc, BYTE ssn, BYTE NetID);
int parse_scmgmsg(BYTE *data, BYTE *type, int *spc, BYTE *ssn, BYTE NetID);
/* scrc.c */
void scrc_timer(void);
int scrc_route(Intra_Msg *pIntraMsg, BOOL ForceAnsi);
int scrc_mnp_route(Intra_Msg *pIntraMsg, BOOL ForceAnsi);
int send_msg(Intra_Msg *pIntraMsg, BYTE ansi_flag);
int scrc_rf(Intra_Msg *pIntraMsg, BYTE AnsiFlag);
DWORD SelectIPOfSSN(BYTE ssn, BYTE sls, BOOL from_mtp);
/* scoc_fsm.c */
void coFsm ( );
/* scoc_func.c */
void coInit ( u32 sysID, u32 localIP, u32 alterIP );
void cr2coFailHandle(Intra_Msg *pIntraMsg, u8 uAnsiFlag, u8 uMsgtype);
int cr2co(Intra_Msg *pIntraMsg, u8 uAnsiFlag);
void co2cr(u16 wConnId, u8 uMsgType);
void co2ul(u16 wConnId, u8 uPri);
void co2scmg(void);
void co2co(u16 wConnId, u8 uPri);
int spCheckAudit(void);
int coNewCS(u16 wConnId, SCCP_ADDR *pAddr);
void coFreeCS(u16 wConnId);
void coFillCS(SP_PriPoolEle *pPri);
int coCheckCS(u16 wConnId, u8 uCState, u8 uSide);
void coTimerOut(u16 wConnId, u8 uPri);
void coTimerMng(void);
int coNewConnId(u8 uPri);
int coGetConnId(u8 *pSLR);
extern inline int coCheckResource ( );
void spWatchDogStatic(u8 uDebugStaticMask);
/* sccp_log.c */
void spLog(char *info);
void spShowAddr(SCCP_ADDR *pAddr, const char *sAddrName);
void spLogDebug(DWORD mask, const char *fmt, ...);
void spShowBCD(DWORD mask, BYTE *buf, int len);
void spLogSeg(SCCP_SegMsgBuf *pSegMsgbuf);
void spShowMsg(DWORD mask, const char *pDesc, Intra_Msg *pIntraMsg);
void spShowPrimitive(SP_UiPriPara *pUiPriParam, u8 uDirection);
void spLogStateError(u16 wConnId, u8 uErrCode);
void spLogTimerOut(u16 wConnId, u8 uTimerID);
void spShowUserData(SP_UiPriPara *pPri);
/* scoc_pool.c */
void spPoolInit(void);
int spPoolGet(SP_PriPoolEle *pPri, CO_Pool *pCoPool);
int spPoolPut(SP_PriPoolEle *pPri, CO_Pool *pCoPool);

View File

@@ -0,0 +1,27 @@
//////////////////////////////////////////////////
//Title : sccp_pub.h
//Auhtor : Liu Wei
//Desc : SCCP public header
//Created : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _SCCP_PUB_H_
#define _SCCP_PUB_H_
#include "../../../public/src/include/includes.h"
#include "../../../public/src/include/public.h"
#include "../../../public/src/include/pub_debug.h"
#include "../../../public/src/include/pub_wnet.h"
#include "../../../public/src/include/pub_fmt.h"
#include "sccp.h"
#include "scoc.h"
#include "sccp_func.h"
#endif

View File

@@ -0,0 +1,510 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/io.h>
#include <netdb.h>
#include "scoc_if.h"
#include "../../../public/src/include/includes.h"
#ifndef _SCCP_CONST_DEF
#define _SCCP_CONST_DEF
#define SCCP_CONF_FILE "./conf/sccp.conf"
#define SINGLE_MODE 1
#define spLogDebug_MASK 0xFFFFFFFF
#define GetValueString(i,p,Maxtrix,IdMax) \
{ \
if( (i) >= (IdMax) ) \
{ \
(p) = Maxtrix[(IdMax)].pStr; \
} \
else \
{ \
(p) = Maxtrix[(i)].pStr; \
} \
}
typedef enum SCCP_WATCH_DOG
{
WDS_RECV_PRI,
}
SP_WatchDog;
#define SCCP_SHM_KEY 0x00116688
#define SCCP_SHM_PERM 0666
//#define SCCP_OID {1,3,6,1,4,1,1373,1,3,2,2,3}
#define SCCP_OID {1,3,6,1,4,1,1373,2,3,2,3}
#define SCCP_OIDLEN 11
#define SCCP_SERNUM_LEN 4
/*Message type-----> */
#define CR_MSG 1
#define CC_MSG 2
#define CREF_MSG 3
#define RLSD_MSG 4
#define RLC_MSG 5
#define DT1_MSG 6
#define DT2_MSG 7
#define AK_MSG 8
#define UDT_MSG 9
#define UDTS_MSG 10
#define ED_MSG 11
#define EA_MSG 12
#define RSR_MSG 13
#define RSC_MSG 14
#define ERR_MSG 15
#define IT_MSG 16
#define XUDT_MSG 17
#define XUDTS_MSG 18
#define LUDT_MSG 19
#define LUDTS_MSG 20
//Intra message type
#define RF_MSG 100
/*SCMG Message */
#define SSA_MSG 1 //subsystem allowed
#define SSP_MSG 2 //subsystem prohibited
#define SST_MSG 3 //subsystem status test
#define SOR_MSG 4 //subsystem out of service request
#define SOG_MSG 5 //subsystem out of service grant
#define SSC_MSG 6 //SCCP/subsystem congested
/*SCCP parameter name codes */
#define P_EOP 0
#define P_DLR 1
#define P_SLR 2
#define P_CDA 3
#define P_CGA 4
#define P_PLC 5
#define P_EOD 6
#define P_PR 7
#define P_SEQ 8
#define P_Credit 9
#define P_RLC 10
#define P_RTC 11
#define P_RSC 12
#define P_ERC 13
#define P_RFC 14
#define P_Data 15
#define P_SEG 16
#define P_HC 17
#define P_Importance 18
#define P_Ldata 19
//////////////////////////////////////////////////
#define SCCP_SSN_NUM 256
#define SCCP_RLSSN_NUM 128
#define SCCP_RLSPC_NUM 64
#define SCCP_ROUTE_NUM 1024
#define SCCP_ROUTE_NODE_NUM 65535
#define LR_NUM 1024
#define LR_MSG_NUM 50
#define SS_MSG_NUM 1024
#define SLS_NUM 16
#define SCCP_MSG_MAXLEN 256
#define MAX_HC 15
#define SCOC_SSN 10
#define Unrestricted 1
#define Restricted 0
#define RI_GT 0 //Route on GT
#define RI_SSN 1 //Route on SSN
#define NP_IMSI 6
#define NP_MSISDN 1
#define NP_GT 7
#define TT_0 0
#define TT_1 1
#define TT_4 4
//message source---->
#define FROM_MTP 1
#define FROM_SCLC 2
#define FROM_SCOC 3
#define FROM_SCMG 4
//subsystem number
#define SSN_NOTUSE 0
#define SSN_SCMG 1
#define SSN_ITU 2 //reserved for ITU-T allocation
#define SSN_ISUP 3
#define SSN_OMC 4
#define SSN_MAP 5
#define SSN_HLR 6
#define SSN_VLR 7
#define SSN_MSC 8
#define SSN_EIC 9 //Equipment Identifier Certer
//scoc state
#define SCOC_IDLE 0
#define SCOC_CPO 1 //connection pending outgoing
#define SCOC_CPI 2 //connection pending incoming
#define SCOC_CPMID 3 //connection pending(intermediate node)
#define SCOC_WCC 4 //Wait connection confirm
#define SCOC_ACTIVE 5 //Active
#define SCOC_MID 6 //Active(intermediate node)
#define SCOC_DP 7 //disconnect pending
#define SCOC_DPMID 8 //disconnect pending(intermediate node)
#define SCOC_Interval 20*1000 //20ms
//Timer (SCMG)
#define T_idle 30 //(s)
#define T_sst 2 //20s interval = 10s
#define T_hbrecv 3 //30s interval = 10s
//#define SST_Start 0
//#define SST_Pend 1
//#define SST_Stop 2
//SP/SCCP/SS status
#define ST_Disable 1
#define ST_Congest 2
#define ST_Enable 3
#define SCCPDB_TCAP 0x01
#define SCCPDB_UDT 0x02
#define SCCPDB_AIF 0x04
#define SCCPDB_ERR 0x08
#define SCCPDB_SCMG 0x10
#define SCCPDB_TIME 0x20
#define SCCPDB_SNMP 0x40
#define SCCPDB_MSG 0x80
#define SCCPDB_ADDR 0x100
#define SCCPDB_STP 0x1000
#define SCCPDB_USER 0x2000
#define SCCPDB_MTP3 0x4000
#define SCCPDB_XUDT 0x8000
/*******************Release cause*******************/
#define RL_EUO 0 //end user originated
#define RL_EUC 1 //end user congestion
#define RL_EUF 2 //end user failure
#define RL_SUO 3 //SCCP user originated
#define RL_RPL 4 //remote procedure error
#define RL_ICD 5 //inconsistent connection data
#define RL_AF 6 //access failure
#define RL_AC 7 //access congestion
#define RL_SF 8 //subsystem failure
#define RL_SC 9 //subsystem congestion
#define RL_MF 10 //MTP failure
#define RL_NC 11 //network congestion
#define RL_EORT 12 //expiration of reset timer
#define RL_EORIT 13 //expriation of receive inactivity timer
#define RL_R 14 //reserved
#define RL_U 15 //unqualified
#define RL_SCCPF 16 //SCCP failure
/*******************return cause*******************/
#define RT_NTFN 0 //no translation for an address of such nature
#define RT_NTFA 1 //no translation for this specific address
#define RT_SC 2 //subsystem congestion
#define RT_SF 3 //subsystem failure
#define RT_UU 4 //unequipped user
#define RT_MF 5 //MTP failure
#define RT_NF 6 //network congestion
#define RT_U 7 //unqulified
#define RT_EIMT 8 //error in message transport
#define RT_EILP 9 //error in local processing
#define RT_DCPR 10 //destination cannot perform reassembly
#define RT_SCCPF 11 //SCCP failure
#define RT_HCV 12 //hop counter violation
#define RT_SNS 13 //segmentation not supported
#define RT_SMTF 14 //segmentation failure
/*******************reset cause*******************/
#define RS_EUO 0 //end user originated
#define RS_SUO 1 //SCCP user originated
#define RS_IPS 2 //incorrect P(S)
#define RS_IPR 3 //incorrect P(R)
#define RS_OFW 4 //remote procedure error-message out of window
#define RS_IPSAI 5 //remote procedure error-incorrect P(S) after initialization
#define RS_G 6 //remote procedure error-general
#define RS_REUO 7 //remote end user operational
#define RS_NO 8 //network operational
#define RS_AO 9 //access operational
#define RS_NC 10 //network congestion
#define RS_R 11 //reserved
#define RS_U 12 //unqualified
#endif
static const StringVal spUlPrimitiveStr[] =
{
{N_UNITDATA_REQ , "N-Unit Data Request "},
{N_UNITDATA_IND , "N-Unit Data Indicate "},
{N_NOTICE_IND , "N-Notice Indicate "},
{N_CONNECT_REQ , "N-Connect Request "},
{N_CONNECT_IND , "N-Connect Indicate "},
{N_CONNECT_RSP , "N-Connect Response "},
{N_CONNECT_CFM , "N-Connect Confirm "},
{N_DISCONNECT_REQ, "N-Disconnect Request "},
{N_DISCONNECT_IND, "N-Disconnect Indicate"},
{N_DATA_REQ , "N-DATA Request "},
{N_DATA_IND , "N-DATA Indicate "},
{N_DATAAK_REQ , "N-DataAk Request "},
{N_DATAAK_IND , "N-DataAk Indicate "},
{N_EDATA_REQ , "N-EData Request "},
{N_EDATA_IND , "N-EData Indicate "},
{N_RESET_REQ , "N-Reset Request "},
{N_RESET_IND , "N-Reset Indicate "},
{N_RESET_RSP , "N-Reset Response "},
{N_RESET_CFM , "N-Reset Confirm "},
{N_INFORM_REQ , "N-Inform Request "},
{N_INFORM_IND , "N-Inform Indicate "},
{SPUI_PRI_MAX , "Unknow SCCP Primitive"},
};
#define spGetUlPrimitiveStr(e,p)\
WxcAssert( (e) < SP_PRI_MAX ,\
"spGetUlPrimitiveStr Primitive id error" );\
GetValueString(e,p,spUlPrimitiveStr,SPUI_PRI_MAX)
typedef enum SCOC_MESSAGE_TYPE
{
SP_MSG0_RESERVED, /* Reserved */
SP_MSG_CR = 1, /* connection request */
SP_MSG_CC = 2, /* connection confirm */
SP_MSG_CREF = 3, /* connection refused */
SP_MSG_RLSD = 4, /* release request */
SP_MSG_RLC = 5, /* release confirm */
SP_MSG_DT1 = 6, /* Data Form 1 */
SP_MSG_DT2 = 7, /* Data Form 2 */
SP_MSG_AK = 8, /* Data acknowledge */
SP_MSG_UDT = 9, /* Unit data */
SP_MSG_UDTS = 10, /* Unit data */
SP_MSG_ED = 11, /* Expedited data */
SP_MSG_EA = 12, /* Expedited data acknowledge */
SP_MSG_RSR = 13, /* Reset request */
SP_MSG_RSC = 14, /* Reset confirm */
SP_MSG_ERR = 15, /* PDU error */
SP_MSG_IT = 16, /* Inactivity test */
SP_MSG_XUDT = 17, /* XUDT */
SP_MSG_XUDTS= 18, /* XUDTS */
SP_MSG_LUDT = 19, /* LUDT */
SP_MSG_LUDTS= 20, /* LUDTS */
SP_MSG_RF = 21, /* Routing Fail */
SP_MSG_MAX , /* MAX message type undefine */
}
CO_MsgType;
static const StringVal sp_messagetype_str[] =
{
{SP_MSG0_RESERVED, " Message Reserved" },
{SP_MSG_CR, " Connection request" },
{SP_MSG_CC, " Connection confirm" },
{SP_MSG_CREF, " Connection refused" },
{SP_MSG_RLSD, " Release request" },
{SP_MSG_RLC, " Release confirm" },
{SP_MSG_DT1, " Data Form 1" },
{SP_MSG_DT2, " Data Form 2" },
{SP_MSG_AK, " Data acknowledge" },
{SP_MSG_UDT, " Unit data" },
{SP_MSG_UDTS, " Unit data service" },
{SP_MSG_ED, " Data acknowledge" },
{SP_MSG_EA, " EData acknowledge" },
{SP_MSG_RSR, " Reset request" },
{SP_MSG_RSC, " Reset confirm" },
{SP_MSG_ERR, " PDU error" },
{SP_MSG_IT, " Inactivity test" },
{SP_MSG_XUDT, " XUDT" },
{SP_MSG_XUDTS, " XUDTS" },
{SP_MSG_LUDT, " LUDT" },
{SP_MSG_LUDTS, " LUDTS" },
{SP_MSG_RF , " Routing Fail" },
{SP_MSG_MAX, " Undefine" },
};
#define spGetMsgStr(MsgId,pStr)\
WxcAssert( (MsgId) >= SP_MSG_CR && (MsgId) < SP_MSG_MAX ,\
"spGetMsgStr MsgId error" );\
GetValueString(MsgId,pStr,sp_messagetype_str,SP_MSG_MAX)
//temp define , define in pub_base.h
#define STR(s) #s
#define FILL_VALSTR(n) {n,#n}
static const StringVal spTimerOutStr[] =
{
FILL_VALSTR(T_CONNEST_OUT),
FILL_VALSTR(T_IAS_OUT),
FILL_VALSTR(T_IAR_OUT),
FILL_VALSTR(T_REPEATE_RLS_OUT),
FILL_VALSTR(T_RLS_OUT),
FILL_VALSTR(T_RESET_OUT),
FILL_VALSTR(T_GUARD_OUT),
FILL_VALSTR(T_INTERNAL_OUT),
FILL_VALSTR(SPTM_PRI_MAX),
};
#define spGetTimerOutStr(MsgId,pStr)\
WxcAssert( (MsgId) >= T_CONNEST_OUT && (MsgId) < SPTM_PRI_MAX ,\
"spGetTimerOutStr MsgId error" );\
GetValueString(((MsgId)-SPCR_PRI_MAX-1),pStr,spTimerOutStr,SPTM_PRI_MAX)
#define T_UNDEFINE 100000
#define T_SP_10ms 1
#define T_SP_1s T_SP_10ms*100
#define T_SP_1MIN T_SP_1s*60
#define T_CONNEST_MAX T_SP_1s*2 //1~2 sec
#define T_IAS_MAX T_SP_1MIN*5 //5~10 mins
#define T_IAR_MAX T_SP_1MIN*11 //11~21 mins
#define T_RLS_MAX T_SP_1s*15 //10~20 sec
#define T_REPEATE_RLS_MAX T_SP_1s*15 //10~20 sec
#define T_RESET_MAX T_SP_1s*15 //10~20 sec
#define T_GUARD_MAX T_SP_1MIN*24 //23~25 mins
#define T_INTERNAL_MAX T_SP_1MIN //1 mins
typedef enum SCOC_TRANSITION_STATUS
{
CO_STATUS_INIT, //Transtion initialed
CO_STATUS_IDLE, //status Idle
CO_STATUS_WTCC, //Wait Connection confirm
CO_STATUS_ACTV, //Active
CO_STATUS_CONP, //Connection pending
CO_STATUS_CPIC, //Connection pending incoming
CO_STATUS_CPOG, //Connection pending outgoing
CO_STATUS_DSCP, //Disconnect pending
CO_STATUS_DPIC, //Disconnect pending incoming
CO_STATUS_DPOG, //Disconnect pending outgoing
CO_STATUS_DPBH, //Disconnect pending both
CO_STATUS_NMOP, //Normal operation
CO_STATUS_WSEA, //Wait for sending EA Message
CO_STATUS_RSIC, //Reset outgoing
CO_STATUS_RSOG, //Reset incoming
CO_STATUS_RSBH, //Reset both
CO_STATUS_MTBK, //Maintenance blocking
CO_STATUS_RSTA, //Restart
CO_STATUS_MAX,
}
CO_Status;
static const StringVal sp_co_state_str[] =
{
{CO_STATUS_INIT, "Transtion initialed" },
{CO_STATUS_IDLE, "status Idle" },
{CO_STATUS_WTCC, "Wait Connection confirm" },
{CO_STATUS_ACTV, "Active" },
{CO_STATUS_CONP, "Connection pending " },
{CO_STATUS_CPIC, "Connection pending incoming"},
{CO_STATUS_CPOG, "Connection pending outgoing"},
{CO_STATUS_DSCP, "Disconnect pending" },
{CO_STATUS_DPIC, "Disconnect pending incoming"},
{CO_STATUS_DPOG, "Disconnect pending outgoing"},
{CO_STATUS_DPBH, "Disconnect pending both" },
{CO_STATUS_NMOP, "Normal operation" },
{CO_STATUS_WSEA, "Wait for sending EA Message"},
{CO_STATUS_RSIC, "Reset outgoing" },
{CO_STATUS_RSOG, "Reset incoming" },
{CO_STATUS_RSBH, "Reset both" },
{CO_STATUS_MTBK, "Maintenance blocking" },
{CO_STATUS_RSTA, "Restart" },
{CO_STATUS_MAX, "Error Transtion state" },
};
#define spGetCoStateStr(s,p)\
WxcAssert( (s) < CO_STATUS_MAX ,\
"spGetCoStateStr co status error" );\
GetValueString(s,p,sp_co_state_str,CO_STATUS_MAX)
typedef enum CO_INSTANCE_SIDE
{
CO_INST_SIDE_ORG,
CO_INST_SIDE_DST,
CO_INST_SIDE_MID,
CO_INST_SIDE_MAX,
}
CO_InstSide;
static const StringVal sp_co_instanceside_str[] =
{
{CO_INST_SIDE_ORG, "Originating node side" },
{CO_INST_SIDE_DST, "Destination node side" },
{CO_INST_SIDE_MID, "intermidediate node side"},
{CO_INST_SIDE_MAX, "Undefine Node Side" },
};
#define spGetCoInstanceSide(s,p)\
WxcAssert( (s) < CO_INST_SIDE_MAX ,\
"spGetCoInstanceSide co sideid error" );\
GetValueString(s,p,sp_co_instanceside_str,CO_INST_SIDE_MAX)
static const StringVal co_reason_str[] = {
//reason : originated network serice provider
{REA_PDISC_ACNN,
"disconnection <20>Cabnormal condition(non-transient nature)" },
{REA_PDISC_ACTN, "disconnection <20>Cabnormal condition of transient nature"},
{REA_PDISC_IS, "disconnection <20>Cinvalid state1" },
{REA_PDISC_RIP, "disconnection <20>Crelease in progress1" },
{REA_PCREF_DAU, "CREF2 <20>Cdestination address unknown " },
{REA_PCREF_DINC,
"CREF2 <20>Cdestination inaccessible/non-transient condition" },
{REA_PCREF_DITCs, "CREF2 <20>Cdestination inaccessible/transient condition" },
{REA_PCREF_QNANC, "CREF2 <20>CQOS not available/non-transient condition" },
{REA_PCREF_QNATC, "CREF2 <20>CQOS not available/transient condition" },
{REA_PCREF_RUNC, "CREF2 <20>Creason unspecified/non-transient condition" },
{REA_PCREF_RUTC, "CREF2 <20>Creason unspecified/transient condition" },
{REA_PCREF_LE, "CREF2 <20>Clocal error1" },
{REA_PCREF_IS, "CREF2 <20>Cinvalid state1" },
{REA_PCREF_NT, "CREF2 <20>Cno translation1" },
{REA_PCREF_IRP, "CREF2 <20>Cin restart phase1" },
{REA_PCREF_HCV, "CREF2 <20>Chop counter violation" },
//reason : originated network serice user
{REA_UDISC_NC, "disconnection <20>Cnormal condition" },
{REA_UDISC_ABC, "disconnection <20>Cabnormal condition" },
{REA_UDISC_EUC, "disconnection <20>Cend user congestion" },
{REA_UDISC_EUF, "disconnection <20>Cend user failure" },
{REA_UDISC_SUO, "disconnection <20>CSCCP user originated" },
{REA_UDISC_ACC, "disconnection <20>Caccess congestion" },
{REA_UDISC_AF, "disconnection <20>Caccess failure" },
{REA_UDISC_SC, "disconnection <20>Csubsystem congestion" },
{REA_UCREF_NTC, "CREF2<EFBFBD>Cnon-transient condition" },
{REA_UCREF_TC, "CREF2<EFBFBD>Ctransient condition" },
{REA_UCREF_IIIN, "CREF2<EFBFBD>Cincompatible information in NSDUs" },
{REA_UCREF_EUO, "CREF2<EFBFBD>Cend user originated" },
{REA_UCREF_EUC, "CREF2<EFBFBD>Cend user congestion" },
{REA_UCREF_EUF, "CREF2<EFBFBD>Cend user failure" },
{REA_UCREF_SUO, "CREF2 <20>CSCCP user originated" },
{REA_UCREF_ACC, "CREF2 <20>Caccess congestion" },
{REA_UCREF_AF, "CREF2 <20>Caccess failure" },
{REA_UCREF_SC, "CREF2 <20>Csubsystem congestion" },
//Notice service reason : N-inform values
{REA_NINFO_FAIL, "work service provider failure" },
{REA_NINFO_CONG, "work service congestion" },
{REA_NINFO_PQC, "work service provider QOS change" },
{REA_UINFO_FAIL, "work service user failure" },
{REA_UINFO_CONG, "work service user congestion" },
{REA_UINFO_PQC, "work service user QOS change" },
{REA_INFO_USPC, "reason unspecified" },
{REA_UNDEFINED, "Undefined" },
};
#define coGetReasonStr(r,p)\
WxcAssert( (r) >= REA_PDISC_ACNN && (r) < REA_UNDEFINED ,\
"coGetReasonStr reason id error" );\
GetValueString(r,p,co_reason_str,REA_UNDEFINED)
typedef enum SCOC_INTERNAL_ERROR
{
CO_FATAL_STATE,
CO_FATAL_SIDE,
}
CO_InterErr;

View File

@@ -0,0 +1,274 @@
//////////////////////////////////////////////////
//Title : scoc.h
//Auhtor : Liu Wei
//Desc : SCCP Connection-Oriented Control
//Created : 2007-04-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _SCOC_H_
#define _SCOC_H_
#include "scoc_if.h"
#include "../../../public/src/include/pub_list.h"
#define spLogDebug_STATIC
typedef struct SCCP_PRIMITIVE_CR_PRIMITIVE
{
u8 uUiPri;
u8 uAnsiFlag;
u16 wConnId;
Intra_Msg tIntraMsg;
}
SP_CrPriPara;
typedef union SCCP_PRIMITVE_POOL_Elemnet
{
SP_UiPriPara tUiPri;
SP_CrPriPara tCrPri;
}
SP_PriPoolEle;
typedef enum SCOC_FSM_ERROR
{
ERR_NONE, //show state string
ERR_FSM_DISCARD,
ERR_FSM_ERROR,
ERR_FSM_FATAL,
ERR_FSM_UNEXPECT_SIDE,
ERR_FSM_RESERVED,
ERR_FSM_UNEXPECT_PRI,
ERR_FSM_UNKOWN_ERROR_CODE,
ERR_TIMER_OUT,
}
CO_FsmErr;
typedef struct SCOC_QOS
{
u8 uInSequence;
u8 uReturnOnErr;
u8 uImportance;
u8 uHopcount;
u8 uMbit;
u8 uRecvSequnce;
u8 uSendSequnce;
}
CO_Qos;
typedef struct SCOC_CAUSE
{
u8 uRelCause;
u8 uReturnCause;
u8 uResetCause;
u8 uErrorCause;
u8 uRejectCause;
}
CO_Cause;
#define MAX_SCCP_MSG 256
typedef struct SCOC_Message
{
u8 uMsgType;
u8 uMsgClass;
u8 uMsgFlag;
u8 aSLR[SP_REF_LEN]; // 0x01 SLR present
u8 aDLR[SP_REF_LEN]; // 0x02 DLR present
SCCP_ADDR tCDA; // 0x04 CDA present
SCCP_ADDR tCGA; // 0x08 CGA present
CO_Qos tQos; // 0x10 QOS present
CO_Cause tCause; // 0x20 CAUSE present
u8 aMsgConent[MAX_SCCP_MSG]; // 0x40 DATA present
}
CO_Msg;
typedef struct CO_TIMER
{
u32 tmConnEst;
u32 tmIas;
u32 tmIar;
u32 tmRepeatRel;
u32 tmRel;
u32 tmReset; //unsupportted now
u32 tmGuard; //unsupportted now
//u32 tmIas;
//u32 tmIar;
//u32 tmIT;
u32 tmInternal;
}
CO_Timer;
typedef struct CO_CONNECTION_Section
{
CO_Status uCState;
SP_Pri uPri;
u8 uAnsiFlag;
CO_InstSide uSide;
u8 uSLS;
u8 uNetId;
int nDPC;
int nOPC;
u8 aSLR[SP_REF_LEN];
u8 aDLR[SP_REF_LEN];
u8 uClass;
u8 uCredit;
u8 eREA;
u8 eOR;
SCCP_ADDR tCDA;
SCCP_ADDR tCGA;
SCCP_ADDR tSPA;
SP_UD tUD;
CO_Timer tmSCOC;
}
CO_ConnSection;
typedef struct SCOC_POOL_PRIMITIVE_IN
{
}
CO_PoolPriIn;
typedef struct SCLC_DATA_BLOCK
{
}
CL_DataBlock;
typedef struct SCRC_DATA_BLOCK
{
}
CR_DataBlock;
typedef struct SCMG_DATA_BLOCK
{
}
CM_DataBlock;
#define CO_CS_MPORT 8192
#ifdef DEBUG
typedef enum SCOC_DEBUG_STATIC_VALUE
{
GET_IN_POOL = 30,
PUT_IN_POOL,
READ_IN_POOL,
WRITE_IN_POOL,
GET_OUT_POOL,
PUT_OUT_POOL,
PUT_ELE_APT,
PUT_ELE_SUC,
UL_POST_CO_APT,
UL_POST_CO,
CO_SUBMIT_UL_APT,
CO_SUBMIT_UL,
CO_TO_CR_APT,
CO_TO_CR,
CR_TO_CO_APT,
CR_TO_CO,
SP_TIMER_OUT,
}
CO_DebugStaticVal;
typedef struct SCOC_DEBUG_STATIC
{
u32 dGetInPool;
u32 dPutInPool;
u32 dReadInPool;
u32 dWriteInPool;
u32 dGetOutPool;
u32 dPutOutPool;
u32 dPutEleApt;
u32 dPutEleSuc;
u32 dCoSubmitUlApt;
u32 dCoSubmitUl;
u32 dUlPostCoApt;
u32 dUlPostCo;
u32 dCo2CrApt;
u32 dCo2Cr;
u32 dCr2CoApt;
u32 dCr2Co;
u32 dTimerOut;
u32 dbusyElem;
}
CO_DebugStatic;
#endif
typedef struct SCOC_DATA_BLOCK
{
u32 wConnIdCount;
CO_ConnSection tCSInst[CO_CS_MPORT];
CO_DebugStatic tCoDebugStatic;
}
CO_DataBlock;
typedef struct SCCP_ENTITY
{
u32 dLocalIP;
u32 dAlterIP;
u32 dSysID;
CL_DataBlock tCl;
CO_DataBlock tCo;
CR_DataBlock tCr;
CM_DataBlock tCm;
}
SP_Entity;
/* by simon at 23/9/26 */
extern SP_Entity tSpEntity;
extern SP_Entity *pSp;
typedef enum SCOC_POOL_OP
{
CO_GET_POOL,
CO_READ_POOL,
CO_PUT_POOL,
CO_WRITE_POOL,
}
CO_PoolOp;
typedef struct SCOC_POOL_ELEMENT
{
POOL_ENTRY ( SCOC_POOL_ELEMENT ) tPointer;
SP_PriPoolEle tPri;
BYTE flag;
}
CO_PoolEle;
typedef struct SCOC_POOL
{
POOL_HEAD ( CO_PriPool, SCOC_POOL_ELEMENT ) tPoolHead;
struct CO_PriPool *pPoolHead;
int uMaxPoolSize;
int uPoolCount;
}
CO_Pool;
#define MAX_IN_POOL 1024
#define MAX_OUT_POOL 512
extern CO_Pool *pInCoPool;
extern CO_Pool *pOutCoPool;
#endif

View File

@@ -0,0 +1,559 @@
//////////////////////////////////////////////////
//Title : SCCP_if.h
//Auhtor : Liu Wei
//Desc : SCOC interface header
//Created : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _SCCP_IF_H_
#define _SCCP_IF_H_
#include "../../../public/src/include/public.h"
#define MAX_DIGITS 10
#define SP_REF_LEN 3
///////////////////////////////////////////////////
typedef struct SCCP_ADDRESS
{
DWORD ip;
int DPC;
BYTE NetID;
BYTE SSN;
BYTE RI;
BYTE GTI;
BYTE TT;
BYTE NP;
BYTE ES;
BYTE NAI;
BYTE len;
BYTE GTAI[MAX_DIGITS];
BYTE AI;
}
SCCP_ADDR;
typedef enum SCCP_LI_MTP_PRIMITIVE
{
MTP_TARNSFER,
MTP_RESUME,
MTP_STATUS,
MTP_UPU,
}
SP_LiMTPPri;
typedef enum SCCP_UI_N_PRIMITIVE
{
N_UNITDATA_REQ,
N_UNITDATA_IND,
N_NOTICE_IND,
N_CONNECT_REQ,
N_CONNECT_IND,
N_CONNECT_RSP,
N_CONNECT_CFM,
N_DISCONNECT_REQ,
N_DISCONNECT_IND,
N_DATA_REQ,
N_DATA_IND,
N_DATAAK_REQ,
N_DATAAK_IND,
N_EDATA_REQ,
N_EDATA_IND,
N_RESET_REQ,
N_RESET_IND,
N_RESET_RSP,
N_RESET_CFM,
N_INFORM_REQ,
N_INFORM_IND,
SPUI_PRI_MAX,
R_CR , /* connection request */
R_CC , /* connection confirm */
R_CREF , /* connection refused */
R_RLSD , /* release request */
R_RLC , /* release confirm */
R_DT1 , /* Data Form 1 */
R_DT2 , /* Data Form 2 */
R_AK , /* Data acknowledge */
R_UDT , /* Unit data */
R_UDTS , /* Unit data */
R_ED , /* Expedited data */
R_EA , /* Expedited data acknowledge */
R_RSR , /* Reset request */
R_RSC , /* Reset confirm */
R_ERR , /* PDU error */
R_IT , /* Inactivity test */
R_XUDT , /* XUDT */
R_XUDTS, /* XUDTS */
R_LUDT , /* LUDT */
R_LUDTS, /* LUDTS */
R_RF , /* Routing Fail */
R_RLS_ERR, /* Release err */
R_CR2 , /* connection request type 2 */
SPCR_PRI_MAX , /* MAX CR2CO Primitive */
T_CONNEST_OUT,
T_IAS_OUT,
T_IAR_OUT,
T_REPEATE_RLS_OUT,
T_RLS_OUT,
T_RESET_OUT,
T_GUARD_OUT,
T_INTERNAL_OUT,
SPTM_PRI_MAX,
N_CONNECT_T1,
RELAY,
TRAFFIC,
NO_TRAFFIC,
I_DISCONNECT,
I_RESET,
I_CONGESTED,
I_UNCONGESTED,
I_RESET_REQ,
SP_PRI_MAX,
}
SP_Pri;
/*
* /SCOC upper layer primitive parameters
*
* /CDA : Called address CGA : Calling address
* /CI : Connection identification
* /CRS : Confirm request slecttion
* /EDS : Expedited data selection
* /QOS : Quality of service parameter set
* /OR : Originator RA : Responding address
* /RCS : Receipt confirmation selection
* /REA : Reason OR : Originator
* /RR : Return Resaon SEQ : Sequence Control
* /UD : User data RO : Return Optinal selection
*
*/
typedef struct SCCP_QUALITY_OF_SERVICE
{
//reserved
u8 uQOS;
}
SP_QOS; //Quality of service parameter set
typedef enum SCCP_ORIGINATOR
{
NSP, //the network service provider
NSU, //the network service user
UNDEFINED, //undefined
}
SP_OR; //Originator
typedef struct SCCP_REQUEST_CONFIRM_SELECTION
{
//reserved
u8 uRCS;
}
SP_RCS; //Confirm request slecttion
/*
* Reason parameter
*
* Note: coGetReasonStr(u8 Reason , char *pReasonStr)
*
*/
typedef enum SCCP_REASON
{
//reason : originated network serice provider
REA_PDISC_ACNN, //Disconn <20>Cabnormal condition of non-transient nature
REA_PDISC_ACTN, //Disconn <20>Cabnormal condition of transient nature
REA_PDISC_IS, //Disconn <20>Cinvalid state1
REA_PDISC_RIP, //Disconn -release in progress1
REA_PCREF_DAU, //CREF <20>Cdestination address unknown(non-transient condition)
REA_PCREF_DINC, //CREF2 <20>Cdestination inaccessible/non-transient condition
REA_PCREF_DITCs, //CREF2 <20>Cdestination inaccessible/transient condition
REA_PCREF_QNANC, //CREF2 <20>CQOS not available/non-transient condition
REA_PCREF_QNATC, //CREF2 <20>CQOS not available/transient condition;
REA_PCREF_RUNC, //CREF2 <20>Creason unspecified/non-transient condition
REA_PCREF_RUTC, //CREF2 <20>Creason unspecified/transient condition;
REA_PCREF_LE, //CREF2 <20>Clocal error1;
REA_PCREF_IS, //CREF2 <20>Cinvalid state1;
REA_PCREF_NT, //CREF2 <20>Cno translation1;
REA_PCREF_IRP, //CREF2 <20>Cin restart phase1;
REA_PCREF_HCV, //CREF2 <20>Chop counter violation.
//reason : originated network serice user
REA_UDISC_NC, //Disconn <20>Cnormal condition;
REA_UDISC_ABC, //Disconn <20>Cabnormal condition;
REA_UDISC_EUC, //Disconn <20>Cend user congestion;
REA_UDISC_EUF, //Disconn <20>Cend user failure;
REA_UDISC_SUO, //Disconn <20>CSCCP user originated;
REA_UDISC_ACC, //Disconn <20>Caccess congestion;
REA_UDISC_AF, //Disconn <20>Caccess failure;
REA_UDISC_SC, //Disconn <20>Csubsystem congestion;
REA_UCREF_NTC, //CREF2 -non-transient condition;
REA_UCREF_TC, //CREF2 -transient condition;
REA_UCREF_IIIN, //CREF2 -incompatible information in NSDUs;
REA_UCREF_EUO, //CREF2 -end user originated;
REA_UCREF_EUC, //CREF2 -end user congestion;
REA_UCREF_EUF, //CREF2 -end user failure;
REA_UCREF_SUO, //CREF2 <20>CSCCP user originated;
REA_UCREF_ACC, //CREF2 <20>Caccess congestion;
REA_UCREF_AF, //CREF2 <20>Caccess failure;
REA_UCREF_SC, //CREF2 <20>Csubsystem congestion.
//Notice service reason : N-inform values
REA_NINFO_FAIL, //N-Inform <20>C network service provider failure;
REA_NINFO_CONG, //N-Inform <20>C network service congestion;
REA_NINFO_PQC, //N-Inform <20>C network service provider QOS change;
REA_UINFO_FAIL, //N-Inform <20>C network service user failure;
REA_UINFO_CONG, //N-Inform <20>C network service user congestion;
REA_UINFO_PQC, //N-Inform <20>C network service user QOS change;
REA_INFO_USPC, //N-Inform <20>C reason unspecified.
REA_UNDEFINED, //undefined
}
SP_REA; //Reason
typedef struct SCCP_RETURN_OPTINAL
{
//reserved
u8 uRO;
}
SP_RO; //return Optinal
typedef struct SCCP_RETURN_REASON
{
//reserved
u8 uRR;
}
SP_RR; //Return Reason
typedef struct SCCP_SEQUENCE
{
//reserved
u8 uSEQ;
}
SP_SEQ; //Sequence control
#define SP_MAX_UD 256
typedef struct SCCP_USER_DATA
{
u8 uDataLen;
u8 aUserData[SP_MAX_UD];
}
SP_UD; //User data
typedef union SCCP_UI_PRIMITIVE_UNION
{
struct PriNUnitDataReq //reserved for sclc ,not used now
{
u8 uSLS;
SP_SEQ tSEQ;
SCCP_ADDR tCDA;
SCCP_ADDR tCGA;
SP_RO tRO;
SP_UD tUD;
}
tPriNUDataReq;
struct PriNUnitDataInd //reserved for sclc ,not used now
{
u8 uSLS;
SP_UD tUD;
SCCP_ADDR tCDA;
SCCP_ADDR tCGA;
}
tPriNUDataInd;
struct PriNNoticeInd //reserved for sclc ,not used now
{
SP_RR tRR;
SP_UD tUD;
SCCP_ADDR tCDA;
SCCP_ADDR tCGA;
}
tPriNNoticeInd;
struct PriNConnectReq
{
//Mandatory
SCCP_ADDR tCDA;
SP_QOS tQOS;
//Optianal
u8 uOptFlag;
u8 tEDS;
u8 uImp;
SCCP_ADDR tCGA;
SP_UD tUD;
}
tPriNConnReq;
struct PriNConnectInd
{
//Mandatory
SCCP_ADDR tCDA;
SP_QOS tQOS;
u8 aSLR[SP_REF_LEN];
u8 uSLS;
u32 OPC;
u8 NetID;
//Optianal
u8 uOptFlag;
u8 uImp;
SCCP_ADDR tCGA;
SP_UD tUD;
}
tPriNConnInd;
struct PriNConnectRsp
{
//Mandatory
SP_QOS tQOS;
//Optianal
u8 uOptFlag;
u8 tEDS;
u8 uImp;
SCCP_ADDR tRA;
SP_UD tUD;
}
tPriNConnRsp;
struct PriNConnectCfm
{
//Mandatory
SP_QOS tQOS;
//Optianal
u8 uOptFlag;
u8 uImp;
SCCP_ADDR tRA;
SP_UD tUD;
}
tPriNConnCfm;
struct PriNDisconnectReq
{
//Mandatory
//SP_OR eOR; //always NSU
SP_REA eREA;
//Optianal
u8 uOptFlag;
u8 uImp;
SCCP_ADDR tRA;
SP_UD tUD;
}
tPriNDisconnReq;
struct PriNDisconnectInd
{
//Mandatory
SP_OR eOR;
SP_REA eREA;
//Optianal
u8 uOptFlag;
u8 uImp;
SCCP_ADDR tRA;
SP_UD tUD;
}
tPriNDisconnInd;
struct PriNDataReq
{
//Mandatory
SP_UD tUD;
//Optianal
u8 uImp;
}
tPriNDataReq;
struct PriNDataInd
{
//Mandatory
SP_UD tUD;
//Optianal
u8 uImp;
}
tPriNDataInd;
struct PriNDataAkReq
{
}
tPriNDataAkReq;
struct PriNDataAkInd
{
}
tPriNDataAkInd;
struct PriNEDataReq
{
SP_UD tUD;
}
tPriNEDataReq;
struct PriNEDataInd
{
SP_UD tUD;
}
tPriNEDataInd;
struct PriNResetReq
{
//SP_OR tOR; //always NSU
SP_REA eREA;
}
tPriNResetReq;
struct PriNResetInd
{
SP_REA eREA;
SP_OR tOR;
}
tPriNResetInd;
struct PriNResetRsp
{
}
tPriNResetRsp;
struct PriNResetCfm
{
}
tPriNResetCfm;
struct PriNInformReq
{
SP_SEQ tQOS;
SP_REA eREA;
}
tPriNInformRsp;
struct PriNInformInd
{
SP_SEQ tQOS;
SP_REA eREA;
}
tPriNInformInd;
}
SP_UiPriUnion;
typedef struct SCCP_UI_PRIMITIVE_PARAMETERS
{
u8 uUiPri;
u8 uAnsiFlag;
u16 wConnId; //return by SCCP while PostSp for N_CONN_REQ
SP_UiPriUnion tPriUnion;
}
SP_UiPriPara;
///////////////////////////////////////////////////////////////////////////
//
// Name : PostSp
// Function : Upper layer post request/response primitive to sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
// Note : Sccp Connid is implicit returned in "pUiPriParam" buffer
// : while N-Connect requesing
// Return : 0 Post Fail 1 Post Successful
//
///////////////////////////////////////////////////////////////////////////
int PostSp ( SP_UiPriPara * pUiPriParam );
///////////////////////////////////////////////////////////////////////////
//
// Name : SpSubmit
// Function : Upper layer fetch indicate/confirm primitive submited form sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
// Return : 0 Fetch Fail 1 Fetch Successful
//
///////////////////////////////////////////////////////////////////////////
int SpSubmit ( SP_UiPriPara * pUiPriParam, u8 uUlSapId );
/////////////////////Below is reserved, do not need to read/////////////////////
/*
* \Inter-Layer Communication interface mode
* \
* \Loose coupling mode :
* interface implementation based on message pool engine
* \Tight coupling mode :
* interface implementation based on function call and callback
*
* \Note : In order to be compatible with old user , use Loose coupling mode now
*
*/
#define LOOSE_COUPLING_MODE 0 //Loose coupling mode
//#define TIGHT_COUPING_MODE
#ifdef LOOSE_COUPLING_MODE //Loose coupling mode
#else
#ifdef TIGHT_COUPING_MODE //Tight coupling mode
#error "Do not support Tight coupling mode ,please use \"LOOSE_COUPLING_MODE\" flag \n"
/*
* \CFS(CallBack function Set) for SCCP sumbit primitives to SCCP user
*
* \The following Callback Fucntion set define the mapping of the primitives
* \which is submited to SCCP serivce user(s). It is used in tight coupling mode.
*
* \User A : Reserved for ISUP
* \User B : Q.711 Page 2 user part B not define
* \User C : Other SCCCP user e.g. AIF
*/
typedef struct SCCP_SUBMIT_USERA_CFS
{
//For Isup ,Not supported now
}
SP_UserA_CFS;
typedef struct SCCP_SUBMIT_USERB_CFS
{
//NULL Undefined in Q.711
}
SP_UserB_CFS;
typedef struct SCCP_SUBMIT_USERC_CFS
{
void ( *spCBUi_N_UnitDataInd ) ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_UD * pUD );
void ( *spCBUi_N_NoticeInd ) ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_RR * pRR, SP_UD * pUD );
void ( *spCBUi_N_ConnectInd ) ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI );
void ( *spCBUi_N_ConnectCfm ) ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI );
void ( *spCBUi_N_DisconnectInd ) ( SP_OR * pOR, SP_OR * pRA, SP_REA * pREA, SP_UD * pUD, u8 uCI );
void ( *spCBUi_N_DataInd ) ( );
void ( *spCBUi_N_DataAkInd ) ( );
void ( *spCBUi_N_EDataInd ) ( );
void ( *spCBUi_N_ResetInd ) ( SP_OR * pOR, SP_REA * pREA, u8 uCI );
void ( *spCBUi_N_ResetCfm ) ( );
void ( *spCBUi_N_InformInd ) ( );
}
SP_UserC_CFS;
#endif
#endif
/////////////////////Above is reserved, do not need to read/////////////////////
#endif

390
plat/sccp/src/sccp.c Normal file
View File

@@ -0,0 +1,390 @@
/**********************************************/
/*Title: sccp.c */
/*Descr: SCCP common procedure */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2002-7-18 */
/**********************************************/
#include "./include/sccp.h"
extern BYTE sccpDebugFull;
ull SCCPSerialNumber;
/*===========export================*/
void sccp_reset ( );
/*===========import================*/
extern void scrc_timer ( void );
extern void sclc_timer ( void );
extern void sccpmib_init ( void ); //sccpmib.c
extern void sccp_sethb ( void ); //sccpmib.c
extern void spLogDebug_setup ( void ); //sccpdebug.c
extern void spLogDebug_timer ( void ); //sccpdebug.c
extern void spLogDebug_csta ( BYTE npage, int instance ); //sccpdebug.c
extern void spLogDebug_local ( BYTE npage, BYTE nline );
extern void localssn_timer ( void ); //scmg.c
extern void sst_timer ( void ); //scmg.c
extern int sccp_loadparam ( void ); //sccpparam.c
extern int BuildRouteIndex ( void );
extern int GetMSISDNOfSSN(BYTE ssn, BYTE *msisdn);
extern int sccp_GetSSNType(BYTE ssn);
extern void coInit( );
extern void coFsm( );
extern void coTimerMng ( );
/* by simon at 23/9/25 */
extern DWORD ExistIP[64];
extern DWORD ExistIPNum;
SCOC_BUF ScocBuf;
LOCAL_SSN LocalSSN[256];
u8 ExistSSN[64];
u8 ExistSSNNum;
struct _dpc2sls
{
int dpc;
u8 sls;
} dpc2sls[256]; // used for sequence control, add by Roy Jiang, 2007-09-17
struct sccp_msg_statistic
{
DWORD msg_mtp_scoc;
DWORD msg_scoc_up;
DWORD mnp_send;
DWORD mnp_route;
} sccpmsg_st;
SCCP_OPT SCCP_Param;
u8 MNP_Flag[2];
SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
int RelatedSSNNum;
RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
int RelatedSPCNum;
RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
SCCP_CSTA SccpCsta[96];
DWORD SccpCstaInd;
SCCP_Capture_Buf SCCPCapBuf;
/*===========private================*/
int CollectLocalInfo ( );
extern u32 dAlterIpBackup; //for protection
void sccp_init ( u32 sysID, u32 localIP, u32 alterIP )
{
time_t l_time;
struct tm *t;
static BYTE initonce = 0;
int i;
BYTE version[3] = SCCP_VERSION;
if( initonce == 1 )
return;
memcpy ( SCCP_Param.version, version, 3 );
SCCPSerialNumber = 0;
sccp_reset ( );
/*initialize global parameter */
memset(dpc2sls, 0xFF, sizeof(dpc2sls));
LocalSSN[1].ip[0] = INADDR_NONE;
LocalSSN[1].status[0] = ST_Enable;
for ( i = 0; i < 256; i++ )
LocalSSN[i].RegFlag = 0;
l_time = time ( NULL );
t = localtime ( &l_time );
if( t == NULL )
{
assert( 0 && "syscall: localtime fail ");
exit(0);
}
SccpCstaInd = t->tm_hour * 4 + t->tm_min / 15;
SccpCsta[SccpCstaInd].timestamp = l_time;
coInit ( sysID, localIP, alterIP );
dAlterIpBackup = alterIP;
sccpmib_init ( );
spLogDebug_setup ( );
spLogDebug_csta ( 1, SccpCstaInd );
printf ( "%ld-%d-%d %d:%d:%d\n", l_time, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec );
printf ( "SCCP Version R%dV%d_%02d ...... Finish initialization!\n", SCCP_Param.version[0], SCCP_Param.version[1], SCCP_Param.version[2] );
initonce = 1;
}
void sccp_init_serial_number ( BYTE * Serial )
{
SCCPSerialNumber = Str2Ull ( Serial );
}
void sccp_timer ( ) //called per 10ms
{
static WORD m_state = 0, ch = 0;
struct tm *t;
time_t l_time;
// BYTE flag;
// flag = inb(0x0378);
// outb((flag | 0x04), 0x0378);
//20ms task===>
sccpDebugFull = 0;
sclc_timer ( );
scrc_timer ( );
coFsm ( );
spLogDebug_timer ( );
coTimerMng();
if( SCCP_Param.T_reset > 0 )
SCCP_Param.T_reset--;
else if( SCCP_Param.T_reset == 0 )
{
spLogDebug_local ( 2, 1 );
BuildRouteIndex ( );
CollectLocalInfo ( );
SCCP_Param.T_reset = -1;
}
//10s task===>
switch ( ( m_state++ ) % 500 )
{
case 0: //switch csta buffer
l_time = time ( NULL );
t = localtime ( &l_time );
if( t == NULL )
{
assert( 0 && "syscall: localtime fail ");
exit(0);
}
if( ch == 0 && t->tm_min % 15 == 0 )
{
SccpCstaInd = t->tm_hour * 4 + t->tm_min / 15;
memset ( &SccpCsta[SccpCstaInd], 0, sizeof ( SCCP_CSTA ) );
SccpCsta[SccpCstaInd].timestamp = l_time;
spLogDebug_csta ( 1, SccpCstaInd );
ch = 1;
}
if( t->tm_min % 15 != 0 )
ch = 0;
break;
case 100: //SST
sst_timer ( );
break;
case 200:
sccp_sethb ( );
break;
case 300:
localssn_timer ( );
break;
case 400:
break;
}
// outb(flag & 0xFB,0x0378);
}
void sccp_reset ( )
{
DWORD oid[20] = { 1, 3, 6, 1, 4, 1, 1373, 2, 3, 2, 2, 2, 2, 0, 0 };//MTP3_OID
BYTE msg[64];
BYTE spclen, temp;
int i, len;
//get parameter from mtp3
SCCP_Param.status = 2;
if( get_response ( 14, oid, msg, &temp ) < 0 )
{
SCCP_Param.status = 0;
return;
}
spclen = msg[0];
SCCP_Param.spclen[0] = ( spclen & 0x01 ) == 0x01 ? 3 : 2;
SCCP_Param.spclen[1] = ( spclen & 0x02 ) == 0x02 ? 3 : 2;
SCCP_Param.spclen[2] = ( spclen & 0x04 ) == 0x04 ? 3 : 2;
SCCP_Param.spclen[3] = ( spclen & 0x08 ) == 0x08 ? 3 : 2;
oid[12] = 3;
for ( i = 0; i < 4; i++ )
{
if( SCCP_Param.spclen[i] == 2 )
{
oid[13] = i + 1;
}
else
{
oid[13] = i + 5;
}
if( ( len = get_response ( 15, oid, msg, &temp ) ) < 0 )
{
SCCP_Param.status = 0;
return;
}
SCCP_Param.spc[i] = decode_integer ( msg, len );
}
SCCP_Param.OMCIP[0] = 0;
SCCP_Param.OMCIP[1] = 0;
sccp_loadparam ( );
CollectLocalInfo ( );
spLogDebug_local ( 2, 1 );
BuildRouteIndex ( );
SCCP_Param.T_reset = -1;
}
int AddToIpList ( DWORD ip, BYTE ssn )
{
int i;
if( ip == SCCP_Param.ip && ssn != 4 )
return 0;
for ( i = 0; i < ExistIPNum; i++ )
{
if( ExistIP[i] == ip )
return 0;
}
ExistIP[ExistIPNum] = ip;
ExistIPNum = ( ExistIPNum + 1 ) % 64;
return 1;
}
int CollectLocalInfo ( )
{
int i;
BYTE RegNum = 0;
SCCP_Param.OMCIP[0] = 0;
SCCP_Param.OMCIP[1] = 0;
ExistSSNNum = 0;
ExistIPNum = 0;
for ( i = 2; i < 256; i++ )
{
if( i != 4 )
{
if( LocalSSN[i].status[0] )
AddToIpList ( LocalSSN[i].ip[0], i );
else if( LocalSSN[i].status[1] == 0 )
continue;
if( LocalSSN[i].status[1] )
AddToIpList ( LocalSSN[i].ip[1], i );
}
if( LocalSSN[i].RegFlag && LocalSSN[i].local )
{
LocalSSN[i].status[( LocalSSN[i].local - 1 ) % 2] = 3;
SCCP_Param.RegSSN[RegNum] = i;
RegNum = ( RegNum + 1 ) % 32;
}
ExistSSN[ExistSSNNum++] = i;
}
SCCP_Param.RegNum = RegNum;
return 1;
}
/*int LocalSSN_ANSIFlag(BYTE SSN)
{
return LocalSSN[SSN].ANSIFlag;
} */
int sccp_mnp_register ( BYTE flag, BYTE routing_method, BYTE usertype )
{
MNP_Flag[0] = flag % 3;
MNP_Flag[1] = routing_method % 3;
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
// spSetGttAddr ///
// uGtType : 0 Setting by SSN ///
// 1 Setting by GtNum [MSISDN] ///
// 2 Setting by GtNum [IMSI ] ///
// ///
///////////////////////////////////////////////////////////////////////////
int spSetGttAddr ( u8 uGtType , u8 uSSN, u8 *uGtNum , struct SCCP_ADDRESS *pSpAddr )
{
int nFlag;
pSpAddr->SSN = uSSN;
pSpAddr->DPC = 0; // set SCCP address
pSpAddr->NetID = 4; // dedicate by GT table
pSpAddr->RI = 0; // Routing by GT
pSpAddr->NAI = 4; //
pSpAddr->ip = 0;
nFlag = sccp_GetSSNType ( uSSN ); //0=ITU,1=ANSI
pSpAddr->ip = 0;
if( nFlag == 1 ) //ANSI SCCP
{
if( uGtType < 2 )
{
pSpAddr->NP = 0; // MSISDN
pSpAddr->TT = 14;
}
else
{
pSpAddr->NP = 6; // IMSI
pSpAddr->TT = 9;
}
pSpAddr->GTI = 0x02;
}
else if( nFlag == 0 ) //ITU SCCP
{
pSpAddr->TT = 0;
if( uGtType < 2 )
{
pSpAddr->NP = 1; // MSISDN
}
else
{
pSpAddr->NP = 6; // IMSI
}
pSpAddr->GTI = 0x04;
}
if( 0 == uGtType )
{
u8 aGTT[ISDN_LEN];
if( GetMSISDNOfSSN ( uSSN, aGTT ) )
{
u8 aISDN[ISDN_LEN];
GttToIsdn ( aISDN, aGTT );
pSpAddr->len = IsdnToGtai( pSpAddr->GTAI ,aISDN );
return pSpAddr->len;
}
}
else if( 1 == uGtType )
{
pSpAddr->len = IsdnToGtai ( pSpAddr->GTAI, uGtNum );
return pSpAddr->len;
}
else if( 2 == uGtType )
{
ImsiNtoA( pSpAddr->GTAI , uGtNum);
pSpAddr->len = IMSI_LEN;
return pSpAddr->len;
}
return 0;
}

684
plat/sccp/src/sccp_debug.c Normal file
View File

@@ -0,0 +1,684 @@
/**************************************************/
/*Title: sccpdebug.c */
/*Descr: SCCP Debug Tool */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2003-5-9 */
/**************************************************/
#include "./include/sccp.h"
#include "./include/scoc.h"
int sccp_send_netcap = 0;
char sccp_debug_buf[5120];
static char asc_in[256];
static DWORD title_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 8, 1 };
unsigned long spLogDebug_mask = 0;
static char sccp_ver[16];
/* by simon at 23/9/26 */
extern struct sccp_msg_statistic
{
DWORD msg_mtp_scoc;
DWORD msg_scoc_up;
DWORD mnp_send;
DWORD mnp_route;
} sccpmsg_st;
extern SCCP_Capture_Buf SCCPCapBuf;
extern DWORD SccpCstaInd;
extern LOCAL_SSN LocalSSN[256];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
extern void spLog ( char *info );
void spLogDebug_WatchDog ( BYTE npage );
SCCP_FILTER sccpFilter[8];
BYTE sccpFilterIndex = 0;
int spLog_fd = -1;
static char help_info[] = "Commands provided now:\r\n\
help\r\n\
log all Output all debug information\r\n\
log none Turn off all information\r\n\
log error on/off Show error information\r\n\
log addr on/off Show address of sccp message\r\n\
log data on/off Show data party of sccp message\r\n\
log time on/off Show time when generate log\r\n\
log udt on/off Show UDT message\r\n\
log user on/off Show (UDT) message from user\r\n\
log mtp3 on/off Show (UDT) message from mtp3\r\n\
log aif on/off Show AIF message\r\n\
log scmg on/of Show SCMG message\r\n\
log snmp on/off Show SNMP message\r\n\
log cond1 (and cond2...) Show message due to specified condition\r\n\
One or more conditions could be taken:\r\n\
src ssn=xx/dst ssn=xx/opc=xx/dpc=xx.\r\n\
For example:log src ssn=7 and dst ssn=6\r\n\
list route.x Print GTT Table, start from x, default 0 if not specified\r\n\
list spc Print SPC of local node\r\n\
save Save parameter\r\n\
reset Reset SCCP Module\
";
/*===========export===============*/
void spLogDebug_setup ( );
void spLogDebug_timer ( );
void spLogDebug_csta ( BYTE npage, int instance );
void spLogDebug_local ( BYTE npage, BYTE nline );
/* by simon at 23/09/26 */
extern SCCP_CSTA SccpCsta[96];
/*===========import================*/
extern void sccp_saveparam ( );
extern void sccp_reset ( );
extern int ParseLine ( char *str, char ( *row )[128], int maxrow );
//extern int Bcd2Str ( char *pStr, const BYTE * pBcd, int len );
extern int Digits2Str ( char *pStr, BYTE * pDigits, int DigitsLen );
/*===========private===============*/
static int parsecmd ( char *cmdstr );
static void spLogDebug_info ( BYTE npage, BYTE nline, BYTE * pt, BYTE len );
static void spLogDebug_related ( BYTE npage, BYTE nline );
static void spLogDebug_buffer ( BYTE npage );
static void spLogDebug_errorCapture ( BYTE npage, BYTE nline );
static void sccp_list_route ( int pos );
void spLogDebug_setup ( )
{
DWORD ascout_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 4 };
DWORD ascin_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 3 };
DWORD status_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 1 };
DWORD name_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 2 };
BYTE debug_status = 1;
sprintf ( sccp_ver, "R%dV%d_%02d", SCCP_Param.version[0], SCCP_Param.version[1], SCCP_Param.version[2] );
debug_set_response ( 15, ascout_id, sccp_debug_buf, 4096 );
debug_set_response ( 15, ascin_id, asc_in, 1 );
debug_set_response ( 15, status_id, &debug_status, 1 );
debug_set_response ( 15, name_id, sccp_ver, strlen ( sccp_ver ) );
spLogDebug_local ( 2, 1 );
spLogDebug_related ( 3, 0 );
spLogDebug_buffer ( 4 );
spLogDebug_errorCapture ( 5, 0 );
spLogDebug_WatchDog ( 6 );
}
void spLogDebug_timer ( )
{
BYTE npage, nline;
if( strlen ( asc_in ) <= 1 )
return;
sccp_debug_buf[0] = '\0';
npage = asc_in[0] - 1;
if( npage == 0 )
{
parsecmd ( asc_in + 1 );
asc_in[0] = '\0';
return;
}
else if( asc_in[1] == 'c' || asc_in[1] == 'C' )
{
memset ( &sccpmsg_st, 0, sizeof ( sccpmsg_st ) );
memset ( &SCCPCapBuf, 0, sizeof ( SCCP_Capture_Buf ) );
}
else
nline = atoi ( asc_in + 1 );
switch ( npage )
{
case 1: //csta
spLogDebug_csta ( npage, nline );
break;
case 2: //local subsystem
spLogDebug_local ( npage, nline );
break;
case 3: //related subsystem
spLogDebug_related ( npage, nline );
break;
case 5: //capture buffer
spLogDebug_errorCapture ( npage, nline );
break;
}
asc_in[0] = '\0';
}
static int str2value ( char *str )
{
BYTE i = 0;
char *pHead = str, xstr[8] = "0";
while ( !isxdigit ( *pHead ) ) //8 lead-space max
{
if( i++ >= 8 )
return -1;
pHead++;
}
i = 0;
while ( isxdigit ( pHead[i] ) && i < 6 )
{
xstr[i] = pHead[i];
i++;
}
xstr[6] = 0;
return strtoul ( xstr, NULL, 16 );
}
static int parsecond ( char *cmdstr )
{
char *pKey = cmdstr, *pEQ, info[256] = "log ", tmpStr[64];
sccpFilter[sccpFilterIndex].flag = 0;
if( ( pKey = strstr ( cmdstr, "opc" ) ) != NULL && ( pEQ = strchr ( pKey, '=' ) ) != NULL )
{
sccpFilter[sccpFilterIndex].opc = str2value ( pEQ + 1 );
if( sccpFilter[sccpFilterIndex].flag > 0 )
strcat ( info, " and " );
sprintf ( tmpStr, "opc = 0x%06x", sccpFilter[sccpFilterIndex].opc );
strcat ( info, tmpStr );
sccpFilter[sccpFilterIndex].flag |= 0x01;
}
if( ( pKey = strstr ( cmdstr, "dpc" ) ) != NULL && ( pEQ = strchr ( pKey, '=' ) ) != NULL )
{
sccpFilter[sccpFilterIndex].dpc = str2value ( pEQ + 1 );
if( sccpFilter[sccpFilterIndex].flag > 0 )
strcat ( info, " and " );
sprintf ( tmpStr, "dpc = 0x%06x", sccpFilter[sccpFilterIndex].opc );
strcat ( info, tmpStr );
sccpFilter[sccpFilterIndex].flag |= 0x02;
}
if( ( pKey = strstr ( cmdstr, "src ssn" ) ) != NULL && ( pEQ = strchr ( pKey, '=' ) ) != NULL )
{
sccpFilter[sccpFilterIndex].src_ssn = str2value ( pEQ + 1 );
if( sccpFilter[sccpFilterIndex].flag > 0 )
strcat ( info, " and " );
sprintf ( tmpStr, "src ssn = 0x%02x", sccpFilter[sccpFilterIndex].src_ssn );
strcat ( info, tmpStr );
sccpFilter[sccpFilterIndex].flag |= 0x04;
}
if( ( pKey = strstr ( cmdstr, "dst ssn" ) ) != NULL && ( pEQ = strchr ( pKey, '=' ) ) != NULL )
{
sccpFilter[sccpFilterIndex].dst_ssn = str2value ( pEQ + 1 );
if( sccpFilter[sccpFilterIndex].flag > 0 )
strcat ( info, " and " );
sprintf ( tmpStr, "dst ssn = 0x%02x", sccpFilter[sccpFilterIndex].dst_ssn );
strcat ( info, tmpStr );
sccpFilter[sccpFilterIndex].flag |= 0x08;
}
if( sccpFilter[sccpFilterIndex].flag == 0 )
{
spLog ( "Wrong condition" );
return 0;
}
sccpFilterIndex++;
spLog ( info );
spLog ( "command OK" );
return 1;
}
int parsecmd ( char *cmdstr )
{
int i;
char info[256], *pCh;
if( strstr ( cmdstr, "list route" ) != NULL ){
int i = 0;
const int start_pos = 11;
while(isdigit(cmdstr[start_pos+i++])){
if(i > 3){
break;
}
}
if (i > 0)
{
cmdstr[start_pos + i] = '\0';
i = strtoul(cmdstr+start_pos, NULL, 10);
if (i > SCCP_ROUTE_NUM){
char tmp_str[128];
sprintf(tmp_str, "Invalid parameter value %d, max %d. replace with default 0", i, SCCP_ROUTE_NUM);
spLog ( tmp_str );
i = 0;
}
}
sccp_list_route ( i );
}
else if( strstr ( cmdstr, "help" ) != NULL || strstr ( cmdstr, "?" ) != NULL )
spLog ( help_info );
else if( strstr ( cmdstr, "save" ) != NULL )
sccp_saveparam ( );
else if( strstr ( cmdstr, "reset" ) != NULL )
sccp_reset ( );
else if( strstr ( cmdstr, "log all" ) != NULL )
{
sccpFilterIndex = 0;
spLogDebug_mask = 0xFFFFFFFF;
}
else if( strstr ( cmdstr, "log none" ) != NULL )
{
sccpFilterIndex = 0;
spLogDebug_mask = 0;
}
else if( strstr ( cmdstr, "log error on" ) != NULL )
spLogDebug_mask |= SCCPDB_ERR;
else if( strstr ( cmdstr, "log error off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_ERR );
else if( strstr ( cmdstr, "log udt on" ) != NULL )
spLogDebug_mask |= SCCPDB_UDT;
else if( strstr ( cmdstr, "log udt off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_UDT );
else if( strstr ( cmdstr, "log aif on" ) != NULL )
spLogDebug_mask |= SCCPDB_AIF;
else if( strstr ( cmdstr, "log aif off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_AIF );
else if( strstr ( cmdstr, "log mtp3 on" ) != NULL )
spLogDebug_mask |= SCCPDB_MTP3;
else if( strstr ( cmdstr, "log mtp3 off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_MTP3 );
else if( strstr ( cmdstr, "log user on" ) != NULL )
spLogDebug_mask |= SCCPDB_USER;
else if( strstr ( cmdstr, "log user off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_USER );
else if( strstr ( cmdstr, "log scmg on" ) != NULL )
spLogDebug_mask |= SCCPDB_SCMG;
else if( strstr ( cmdstr, "log scmg off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_SCMG );
else if( strstr ( cmdstr, "log snmp on" ) != NULL )
spLogDebug_mask |= SCCPDB_SNMP;
else if( strstr ( cmdstr, "log snmp off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_SNMP );
else if( strstr ( cmdstr, "log data on" ) != NULL )
spLogDebug_mask |= SCCPDB_MSG;
else if( strstr ( cmdstr, "log data off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_MSG );
else if( strstr ( cmdstr, "log addr on" ) != NULL )
spLogDebug_mask |= SCCPDB_ADDR;
else if( strstr ( cmdstr, "log addr off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_ADDR );
else if( strstr ( cmdstr, "log time on" ) != NULL )
spLogDebug_mask |= SCCPDB_TIME;
else if( strstr ( cmdstr, "log time off" ) != NULL )
spLogDebug_mask &= ( ~SCCPDB_TIME );
else if( strstr(cmdstr, "net cap start") !=NULL )
{
sccp_send_netcap = 1;
spLog("sccp send netcap start");
}
else if( strstr(cmdstr, "net cap stop") !=NULL )
{
sccp_send_netcap = 0;
spLog("sccp send netcap end");
}
else if( strncasecmp ( cmdstr, "log file on", 11 ) == 0 )
{
if( spLog_fd != -1 )
{
close ( spLog_fd );
}
spLog_fd = open ( "./sccp.log", O_WRONLY | O_CREAT | O_TRUNC );
}
else if( strncasecmp ( cmdstr, "log file off", 12 ) == 0 )
{
if( spLog_fd != -1 )
{
close ( spLog_fd );
spLog_fd = -1;
}
}
else if( ( pCh = strstr ( cmdstr, "log" ) ) != NULL && strstr ( cmdstr, "=" ) != NULL )
{
if( sccpFilterIndex >= 8 )
{
spLog ( "Only 8 conditions can be set" );
return 0;
}
return parsecond ( pCh + 4 );
}
else if( strstr ( cmdstr, "list spc" ) != NULL )
{
spLog ( "NI SPC_Len SPC" );
for ( i = 0; i < 4; i++ )
{
sprintf ( info, "%d %d %06lx", i, SCCP_Param.spclen[i], SCCP_Param.spc[i] );
spLog ( info );
}
}
else
{
spLog ( "Invalid command/parameter(s)." );
return 0;
}
spLog ( "Command OK." );
return 1;
}
int sccp_filter_msg ( SCCP_ADDR * pSrcAddr, SCCP_ADDR * pDstAddr )
{
int i;
for ( i = 0; i < sccpFilterIndex % 9; i++ )
{
if( sccpFilter[i].flag & 0x01 )
{
if( sccpFilter[i].opc != pSrcAddr->DPC )
continue;
}
if( sccpFilter[i].flag & 0x02 )
{
if( sccpFilter[i].dpc != pDstAddr->DPC )
continue;
}
if( sccpFilter[i].flag & 0x04 )
{
if( sccpFilter[i].src_ssn != pSrcAddr->SSN )
continue;
}
if( sccpFilter[i].flag & 0x08 )
{
if( sccpFilter[i].dst_ssn != pDstAddr->SSN )
continue;
}
return 1;
}
return 0;
}
void spLogDebug_info ( BYTE npage, BYTE nline, BYTE * pt, BYTE len )
{
DWORD oid[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 4, 5, 2, 2 };
oid[14] = 5 + npage;
oid[15] = 2 + nline;
debug_set_response ( 17, oid, pt, len );
}
/*-----------------------------------------------*/
/*-------------------CSTA------------------------*/
/*-----------------------------------------------*/
void spLogDebug_csta ( BYTE npage, int instance )
{
char title[256];
SCCP_CSTA *pcsta = &SccpCsta[SccpCstaInd % 96];
sprintf ( title, "\tSCCP-%s\tPage %02d\t\tMIB-CSTA(ID:1 Instance:%d)\r\n"
" [----1----] [----2----] [----3----] [----4----] [----5----]\r\n"
"Error(1)\r\n" "\r\n" "\r\n" "\r\n" "\r\n" "availability(2)\r\n" "\r\n" "\r\n" "Utilization(3)\r\n" "\r\n" "\r\n" "Quality(4)\r\n" "\r\n" "\r\n" "\r\n", sccp_ver, npage, instance );
title_id[14] = 5 + npage;
debug_set_response ( 16, title_id, title, strlen ( title ) );
spLogDebug_info ( npage, 0, ( BYTE * ) pcsta->error, 20 );
spLogDebug_info ( npage, 1, ( BYTE * ) pcsta->error + 20, 20 );
spLogDebug_info ( npage, 2, ( BYTE * ) pcsta->error + 40, 20 );
spLogDebug_info ( npage, 3, ( BYTE * ) pcsta->error + 60, 20 );
spLogDebug_info ( npage, 4, ( BYTE * ) pcsta->error + 80, 4 );
spLogDebug_info ( npage, 5, ( BYTE * ) pcsta->avail, 20 );
spLogDebug_info ( npage, 6, ( BYTE * ) pcsta->avail + 20, 20 );
spLogDebug_info ( npage, 7, ( BYTE * ) pcsta->avail + 40, 8 );
spLogDebug_info ( npage, 8, ( BYTE * ) pcsta->utilization, 20 );
spLogDebug_info ( npage, 9, ( BYTE * ) pcsta->utilization + 20, 20 );
spLogDebug_info ( npage, 10, ( BYTE * ) pcsta->utilization + 40, 16 );
spLogDebug_info ( npage, 11, ( BYTE * ) pcsta->quality, 20 );
spLogDebug_info ( npage, 12, ( BYTE * ) pcsta->quality + 20, 20 );
spLogDebug_info ( npage, 13, ( BYTE * ) pcsta->quality + 40, 20 );
spLogDebug_info ( npage, 14, ( BYTE * ) pcsta->quality + 60, 20 );
}
/*-----------------------------------------------*/
/*-------------------Local subsystem-------------*/
/*-----------------------------------------------*/
void spLogDebug_local ( BYTE npage, BYTE nline )
{
short loop, ssnindex = 0;
char str[256], digits[24];
char title[1024], *pCh = NULL;
nline = nline % 256;
if( nline < 2 )
nline = 2;
spLog ( "Refresh Local Node List..." );
sprintf ( title, "\tSCCP-%s\tPage %02d\tMIB-Status Of Local Subsystem\r\n\
[ SSN ] S1 S2 N Lc NI RG [ IP1 ] [ IP2 ] F\r\n", sccp_ver, npage );
for ( loop = nline; ssnindex < 22 && loop < 256; loop++ )
{
if( LocalSSN[loop].status[0] == 0 && LocalSSN[loop].status[1] == 0 )
continue;
Bcd2Str ( digits, LocalSSN[loop].msisdn, LocalSSN[loop].msisdn_len % ( MAX_DIGITS + 1 ) );
if( ( pCh = strchr ( digits, 'F' ) ) != NULL )
*pCh = 0;
if( strlen ( digits ) == 0 )
strcpy ( digits, " " );
sprintf ( str, "%02X-%-18s\n\r", loop, digits );
strcat ( title, str );
spLogDebug_info ( npage, ssnindex++, LocalSSN[loop].status, 14 );
}
while ( ssnindex < 22 )
spLogDebug_info ( npage, ssnindex++, LocalSSN[0].status, 0 );
title_id[14] = 5 + npage;
debug_set_response ( 16, title_id, title, strlen ( title ) );
return;
}
void spLogDebug_related ( BYTE npage, BYTE nline )
{
short loop;
char str[64];
char title[500];
nline = nline % SCCP_RLSSN_NUM;
sprintf ( title, "\tSCCP-%s\tPage %02d\tMIB-Status Of Related Subsystem(Num=%d)\r\n" " S SST ID SN [ SPC ] [Timeoute]\r\n", sccp_ver, npage, RelatedSSNNum );
for ( loop = nline; loop < nline + 20 && loop < SCCP_RLSSN_NUM; loop++ )
{
sprintf ( str, "Instance=%d\r\n", loop );
strcat ( title, str );
}
title_id[14] = 5 + npage;
debug_set_response ( 16, title_id, title, strlen ( title ) );
for ( loop = nline; loop < nline + 20 && loop < RelatedSSNNum; loop++ )
spLogDebug_info ( npage, loop - nline, ( BYTE * ) & RelatedSSN[loop], 12 );
}
void spLogDebug_buffer ( BYTE npage )
{
char title[500];
sprintf ( title, "\tSCCP-%s\tPage %02d\t\tBuffer\r\n"
" [ R ] [ W ]\r\n" "SCLC(in-0)\r\n" "SCLC(in-1)\r\n" "SCLC(in-2)\r\n" "SCLC(out)\r\n" "SCOC\r\n" "AIF Msg\r\n" "\r\n" "OMCIP\r\n", sccp_ver, npage );
title_id[14] = 5 + npage;
debug_set_response ( 16, title_id, title, strlen ( title ) );
// spLogDebug_info(npage,0,(BYTE *)&SCLC_InBuf[0].readsub, 4);
// spLogDebug_info(npage,1,(BYTE *)&SCLC_InBuf[1].readsub, 4);
// spLogDebug_info(npage,2,(BYTE *)&SCLC_InBuf[2].readsub, 4);
// spLogDebug_info(npage,3,(BYTE *)&SCLC_OutBuf.readsub, 4);
spLogDebug_info ( npage, 4, ( BYTE * ) ScocBuf.rcvsub, 4 );
spLogDebug_info ( npage, 5, ( BYTE * ) & sccpmsg_st.msg_mtp_scoc, 8 );
spLogDebug_info ( npage, 6, NULL, 0 );
spLogDebug_info ( npage, 7, ( BYTE * ) & SCCP_Param.OMCIP, 8 );
}
void spLogDebug_errorCapture ( BYTE npage, BYTE nline )
{
char title[500];
int i;
static BYTE subpage;
int base;
subpage = nline % 10;
sprintf ( title, "\tSCCP-%s\tPage %02d\tSubPage %02d\tErrCap\r\n"
" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r"
"Pointer\n\r"
"ErrCap\r\n" "01\r\n" "02\r\n" "03\r\n" "04\r\n" "05\r\n" "06\r\n" "07\r\n" "08\r\n" "09\r\n" "10\r\n" "11\r\n" "12\r\n" "13\r\n" "14\r\n" "15\r\n" "Dog\r\n", sccp_ver, npage, subpage );
title_id[14] = 5 + npage;
debug_set_response ( 16, title_id, title, strlen ( title ) );
spLogDebug_info ( npage, 0, ( BYTE * ) & SCCPCapBuf.Pointer, 1 );
base = subpage * 256;
for ( i = 1; i < 17; i++ )
{
spLogDebug_info ( npage, i, ( BYTE * ) & SCCPCapBuf.Buffer[base + ( i - 1 ) * 16], 16 );
}
for ( i = 17; i < 22; i++ )
{
spLogDebug_info ( npage, i, ( BYTE * ) & SCCPCapBuf.watch_dog[( i - 17 ) * 16], 16 );
}
}
void spLogDebug_WatchDog ( BYTE npage )
{
char title[500];
CO_DebugStatic *pDs = &pSp->tCo.tCoDebugStatic;
sprintf ( title, "\tSCCP-%s\tPage %02d\t\tDebug watchdog\r\n\r\n"
"Get InPool\r\n"
"Put InPool\r\n"
"Read InPool\r\n"
"Write InPool\r\n"
"Get OutPool\r\n"
"Put OutPool\r\n"
"Put element atp\r\n"
"Put element suc\r\n"
"CoSubmitUl attempt\r\n"
"CoSubmitUl \r\n"
"UlPostCo attempt\r\n"
"UlPostCo \r\n"
"Co2Cr attempt\r\n"
"Co2Cr \r\n"
"Cr2Co attempt\r\n"
"Cr2Co \r\n"
"Timer Out\r\n"
"Busy element\r\n"
"Busy connection\r\n", sccp_ver, npage );
title_id[14] = 5 + npage;
debug_set_response ( 17, title_id, title, strlen ( title ) );
spLogDebug_info ( npage, 0, ( BYTE * ) & pDs->dGetInPool, 4 );
spLogDebug_info ( npage, 1, ( BYTE * ) & pDs->dPutInPool, 4 );
spLogDebug_info ( npage, 2, ( BYTE * ) & pDs->dReadInPool, 4 );
spLogDebug_info ( npage, 3, ( BYTE * ) & pDs->dWriteInPool, 4 );
spLogDebug_info ( npage, 4, ( BYTE * ) & pDs->dGetOutPool, 4 );
spLogDebug_info ( npage, 5, ( BYTE * ) & pDs->dPutOutPool, 4 );
spLogDebug_info ( npage, 6, ( BYTE * ) & pDs->dPutEleApt, 4 );
spLogDebug_info ( npage, 7, ( BYTE * ) & pDs->dPutEleSuc, 4 );
spLogDebug_info ( npage, 8, ( BYTE * ) & pDs->dCoSubmitUlApt, 4 );
spLogDebug_info ( npage, 9, ( BYTE * ) & pDs->dCoSubmitUl, 4 );
spLogDebug_info ( npage, 10, ( BYTE * ) & pDs->dUlPostCoApt, 4 );
spLogDebug_info ( npage, 11, ( BYTE * ) & pDs->dUlPostCo, 4 );
spLogDebug_info ( npage, 12, ( BYTE * ) & pDs->dCo2CrApt, 4 );
spLogDebug_info ( npage, 13, ( BYTE * ) & pDs->dCo2Cr, 4 );
spLogDebug_info ( npage, 14, ( BYTE * ) & pDs->dCr2CoApt, 4 );
spLogDebug_info ( npage, 15, ( BYTE * ) & pDs->dCr2Co, 4 );
spLogDebug_info ( npage, 16, ( BYTE * ) & pDs->dTimerOut, 4 );
spLogDebug_info ( npage, 17, ( BYTE * ) & pDs->dbusyElem, 4 );
spLogDebug_info ( npage, 18, ( BYTE * ) & pSp->tCo.wConnIdCount, 4 );
}
void sccp_list_route ( int pos )
{
SCCP_ROUTE *pRoute;
int i;
char tempstr[1024], str1[64], str2[256], *pCh = NULL;
char cNP[8], cTT[8];
if(pos >= SCCP_ROUTE_NUM)
return;
spLog ( "#No NP TT StartDigits EndDigits NI SPC SSN RI AI S E N Rep" );
for ( i = pos; i < SCCP_ROUTE_NUM; i++ )
{
if( RouteList[i].avail == 0 )
continue;
pRoute = &RouteList[i];
if( pRoute->len > 0 )
{
Bcd2Str ( str1, pRoute->StartDigits, pRoute->len % MAX_DIGITS );
if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
*pCh = 0;
Bcd2Str ( str2, pRoute->EndDigits, pRoute->len % MAX_DIGITS );
if( ( pCh = strchr ( str2, 'F' ) ) != NULL )
*pCh = 0;
}
else
{
strcpy ( str1, "-" );
strcpy ( str2, "-" );
}
if( pRoute->NP == 0 )
sprintf ( cNP, "-" );
else
sprintf ( cNP, "%d", pRoute->NP );
if( pRoute->TT == 0 )
sprintf ( cTT, "-" );
else
sprintf ( cTT, "%d", pRoute->TT );
sprintf ( tempstr, "%-3d %s %s %-15s %-15s %d %02X%02x%02X %d %d %d ", i, cNP, cTT, str1, str2, pRoute->NetID, pRoute->DPC[0], pRoute->DPC[1], pRoute->DPC[2], pRoute->SSN, pRoute->RI,
pRoute->AI );
if( pRoute->convert )
{
Bcd2Str ( str1, pRoute->ReplaceDigits, pRoute->replace_len % MAX_DIGITS );
if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
*pCh = 0;
sprintf ( str2, "%-1d% -1d %-1d %-15s", pRoute->ReplaceStart, pRoute->ReplaceEnd, pRoute->OutNP, str1 );
strcat ( tempstr, str2 );
}
spLog ( tempstr );
}
}
void sccp_put_capture_logs ( BYTE person, BYTE * pictures, int len )
{
int base;
if( len >= 512 )
return;
base = SCCPCapBuf.Pointer * 16;
SCCPCapBuf.Buffer[base + 0] = person;
SCCPCapBuf.Buffer[base + 1] = len;
base = base + 16;
SCCPCapBuf.Pointer = SCCPCapBuf.Pointer + 1;
if( SCCPCapBuf.Pointer >= 128 )
SCCPCapBuf.Pointer = 0;
memcpy ( &SCCPCapBuf.Buffer[base], pictures, len );
SCCPCapBuf.Pointer = ( SCCPCapBuf.Pointer ) + ( ( len + 15 ) / 16 );
if( SCCPCapBuf.Pointer >= 128 )
SCCPCapBuf.Pointer = 0;
}

113
plat/sccp/src/sccp_func.c Normal file
View File

@@ -0,0 +1,113 @@
/******************************************************/
/*Title: sccpfun.c */
/*Descr: Common Function */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2003-5-9 */
/******************************************************/
//All the funtions base on following assuming:
//BCD: 0x123456
//Digits: 0x214356
//Str: "123456"
//Ull: 123456
//Array: {0x01,0x02,0x03,0x04,0x05,0x06};
#include "./include/sccp.h"
int ParseLine ( char *str, char ( *row )[128], int maxrow )
{
char *pstr = str;
int len, index = 0, i;
BOOL black = 0;
len = strlen ( str );
for ( i = 0; i < len && index < maxrow; i++ )
{
if( isspace ( str[i] ) )
{
if( black == 0 )
pstr = str + i + 1;
else
{
str[i] = '\0';
if( strlen ( pstr ) > 128 )
pstr[127] = 0;
sprintf ( row[index++], "%s", pstr );
pstr = str + i + 1;
}
black = 0;
}
else
black = 1;
}
if( black == 1 )
{
if( strlen ( pstr ) > 128 )
pstr[127] = 0;
sprintf ( row[index++], "%s", pstr );
}
return index;
}
int GetEnt ( FILE * fp, char *key, char *str )
{
char *pval, *pkey, *pchr;
int i = 1, len;
fseek ( fp, 0, SEEK_SET );
pval = NULL;
while ( fgets ( str, 200, fp ) != NULL )
{
if( ( pchr = strchr ( str, '#' ) ) != NULL )
pchr[0] = '\0';
if( ( pkey = strstr ( str, key ) ) != NULL )
{
if( ( pval = strchr ( str, '=' ) ) == NULL || pkey >= pval )
continue;
else
break;
}
}
if( pval == NULL )
return -1;
pval++;
len = strlen ( pval );
while ( isspace ( pval[len - i] ) && i <= len )
{
pval[len - i] = '\n';
pval[len - i + 1] = '\0';
i++;
}
i = 0;
while ( isspace ( pval[i++] ) && i < len );
sprintf ( str, "%s", pval + i - 1 );
return 1;
}
BOOL isco ( Intra_Msg * intramsg )
{
if( intramsg->msgtype == 9 || intramsg->msgtype == 10 || intramsg->msgtype == 17 || intramsg->msgtype == 18 || intramsg->msgtype == 19 || intramsg->msgtype == 20 )
return 0;
else if( intramsg->msgtype > 0 && intramsg->msgtype <= 20 )
return 1;
return 0;
}
BOOL iscl ( Intra_Msg * intramsg )
{
if( intramsg->msgtype == 9 || intramsg->msgtype == 10 || intramsg->msgtype == 17 || intramsg->msgtype == 18 || intramsg->msgtype == 19 || intramsg->msgtype == 20 )
return 1;
else
return 0;
}
BOOL iscr ( Intra_Msg * intramsg )
{
if( intramsg->msgtype == 1 || intramsg->msgtype == 2 )
return 1;
else
return 0;
}

417
plat/sccp/src/sccp_gtt.c Normal file
View File

@@ -0,0 +1,417 @@
/****************************************************/
/*Title: gtt.c */
/*Descr: GTT Table Management */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2003-4-30 */
/****************************************************/
#include "./include/sccp.h"
/*===========export================*/
int BuildRouteIndex ( );
u_short SelectRoute ( BYTE * pDigits, BYTE DigitsLen );
void TranslateGT ( SCCP_ADDR * addr, SCCP_ROUTE * pRoute );
/*===========import================*/
extern void spLog ( char *info );
extern int ParseLine ( char *str, char ( *row )[128], int maxrow );
extern int Digits2Array ( BYTE * pArray, BYTE * pDigits, int DigitsLen );
extern int Bcd2Array ( BYTE * pArray, BYTE * pBcd, int BcdLen );
extern int Array2Digits ( BYTE * pDigits, BYTE * pArray, int ArrayLen );
/* by simon at 23/9/26*/
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern LOCAL_SSN LocalSSN[256];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
/*===========private================*/
static int AddRoute ( BYTE * pStartDigits, BYTE * pEndDigits, BYTE DigitsLen, u_short index );
static int AddLargerNode ( SCCP_ROUTE_NODE * pNode, BYTE * pDigits, BYTE DigitsLen, u_short index );
static int AddLessNode ( SCCP_ROUTE_NODE * pNode, BYTE * pDigits, BYTE DigitsLen, u_short index );
static SCCP_ROUTE_NODE *NewNode ( );
static SCCP_ROUTE_NODE RouteNode[SCCP_ROUTE_NODE_NUM];
static SCCP_ROUTE_NODE *pHead = &RouteNode[0];
static u_short heap_index = 1, item_index = 0;
int BuildRouteIndex ( )
{
int i;
BYTE StartNum[32], EndNum[32], NumLen;
BYTE TTmod10, TTdiv10, TTdiv100;
BYTE field = 0;
TTmod10 = TTdiv10 = TTdiv100 = 0;
spLog ( "Build GTT Index..." );
memset ( &RouteNode[0], 0, SCCP_ROUTE_NODE_NUM * sizeof ( SCCP_ROUTE_NODE ) );
heap_index = 1;
item_index = 0;
for ( i = 2; i < 256; i++ )
{
field = 0;
if( LocalSSN[i].status[0] == 0 && LocalSSN[i].status[1] == 0 )
continue;
if( LocalSSN[i].msisdn_len < 1 )
continue;
// if (mtp3_ansiFlag(LocalSSN[i].NetID) != 1)/* ITU */
StartNum[field++] = NP_MSISDN;
// else
{ //ANSI
StartNum[field++] = TT_0;
StartNum[field++] = TT_1;
StartNum[field++] = TT_4;
}
NumLen = Bcd2Array ( StartNum + field, LocalSSN[i].msisdn, LocalSSN[i].msisdn_len % MAX_DIGITS ) + field;
if( NumLen < 2 || NumLen > 26 )
continue;
if( StartNum[NumLen - 1] > 9 )
NumLen--;
if( AddRoute ( StartNum, StartNum, NumLen, 1024 + i ) == 0 )
spLog ( "Error: Fail to add local node, resource limit..." );
}
field = 0;
for ( i = 0; i < SCCP_ROUTE_NUM; i++ )
{
if( RouteList[i].avail == 0 )
continue;
TTmod10 = RouteList[i].TT % 10;
TTdiv10 = ( RouteList[i].TT / 10 ) % 10;
TTdiv100 = RouteList[i].TT / 100;
field = 0;
if( RouteList[i].NP != 0 )
StartNum[field++] = RouteList[i].NP;
else
StartNum[field++] = NP_MSISDN;
if( RouteList[i].TT != 0 )
{
StartNum[field++] = TTdiv100;
StartNum[field++] = TTdiv10;
StartNum[field++] = TTmod10;
}
else
{
StartNum[field++] = TT_0;
StartNum[field++] = TT_1;
StartNum[field++] = TT_4;
}
field = 0;
if( RouteList[i].NP != 0 )
EndNum[field++] = RouteList[i].NP;
else
EndNum[field++] = NP_MSISDN;
if( RouteList[i].TT != 0 )
{
EndNum[field++] = TTdiv100;
EndNum[field++] = TTdiv10;
EndNum[field++] = TTmod10;
}
else
{
EndNum[field++] = TT_0;
EndNum[field++] = TT_1;
EndNum[field++] = TT_4;
}
NumLen = Bcd2Array ( StartNum + field, RouteList[i].StartDigits, RouteList[i].len % MAX_DIGITS ) + field;
if( NumLen < 2 || NumLen > 26 )
continue;
if( StartNum[NumLen - 1] > 9 )
NumLen--;
Bcd2Array ( EndNum + field, RouteList[i].EndDigits, RouteList[i].len );
if( AddRoute ( StartNum, EndNum, NumLen, i ) == 0 ){
spLog ( "Error: Fail to add route, resource limit..." );
break;
}
}
return 1;
}
u_short SelectRoute ( BYTE * pDigits, BYTE DigitsLen )
{
SCCP_ROUTE_NODE *pNode = pHead;
int i;
u_short result = 0xFFFF;
BYTE num;
for ( i = 0; i < DigitsLen; i++ )
{
num = pDigits[i];
if( pNode->psub[num] >= &RouteNode[0] && pNode->psub[num] <= &RouteNode[SCCP_ROUTE_NODE_NUM-1] )
{
pNode = pNode->psub[num];
if( pNode->nItem != 0xFFFF )
result = pNode->nItem;
}
else
{
return result;
}
}
return result;
}
int GetACNInfo ( SCCP_ADDR * pAddr, BYTE ** pAcnInfo )
{
DWORD spc;
u_short nRoute = 0xFFFF;
BYTE Num[MAX_DIGITS * 2], NumLen;
BYTE NetID;
BYTE field = 0;
if( pAddr->NP > 0 )
Num[field++] = pAddr->NP;
else
Num[field++] = NP_MSISDN;
if( pAddr->TT > 0 )
{
Num[field++] = pAddr->TT / 100;
Num[field++] = ( pAddr->TT / 10 ) % 10;
Num[field++] = pAddr->TT % 10;
}
else
{
Num[field++] = TT_0;
Num[field++] = TT_1;
Num[field++] = TT_4;
}
NumLen = pAddr->len % ( MAX_DIGITS * 2 );
Digits2Array ( Num + field, pAddr->GTAI, ( NumLen + 1 ) / 2 );
if( pAddr->GTI )
{
nRoute = SelectRoute ( Num, NumLen + field );
if( nRoute < SCCP_ROUTE_NUM )
{
if( pAddr->NetID > 3 )
NetID = RouteList[nRoute].NetID;
else
NetID = pAddr->NetID;
spc = RouteList[nRoute].DPC[0] * 0x10000 + RouteList[nRoute].DPC[1] * 0x100 + RouteList[nRoute].DPC[2];
}
else if( nRoute >= 1024 && nRoute < 1024 + 256 )
{
if( pAddr->NetID > 3 )
NetID = LocalSSN[nRoute - 1024].NetID % 4;
else
NetID = pAddr->NetID;
spc = SCCP_Param.spc[NetID];
}
else
return 0;
}
else
{
NetID = pAddr->NetID;
spc = pAddr->DPC;
}
*pAcnInfo = spc_to_acn ( NetID, spc );
if( *pAcnInfo == NULL )
return 0;
return 36;
}
void TranslateGT ( SCCP_ADDR * pAddr, SCCP_ROUTE * pRoute )
{
BYTE swap[MAX_DIGITS * 2], temp[MAX_DIGITS * 2];
BYTE ReplaceNum[MAX_DIGITS * 2], len;
BYTE ReplaceEnd;
len = Bcd2Array ( ReplaceNum, pRoute->ReplaceDigits, pRoute->replace_len % MAX_DIGITS );
Digits2Array ( temp, pAddr->GTAI, ( ( pAddr->len + 1 ) / 2 ) % MAX_DIGITS );
pAddr->NP = NP_GT;
if( pRoute->ReplaceStart > 1 )
{
memcpy ( swap, temp, pRoute->ReplaceStart - 1 );
}
memcpy ( swap + pRoute->ReplaceStart - 1, ReplaceNum, len );
ReplaceEnd = pRoute->ReplaceEnd;
if( pAddr->len < ReplaceEnd )
ReplaceEnd = pAddr->len;
memcpy ( swap + pRoute->ReplaceStart - 1 + len, temp + ReplaceEnd, ( pAddr->len - ReplaceEnd ) % 16 );
pAddr->len = pRoute->ReplaceStart - 1 + len + pAddr->len - ReplaceEnd;
pAddr->NP = pRoute->OutNP;
Array2Digits ( pAddr->GTAI, swap, pAddr->len );
}
int AddRoute ( BYTE * pStartDigits, BYTE * pEndDigits, BYTE DigitsLen, u_short index )
{
SCCP_ROUTE_NODE *pNode = pHead;
int i, j;
BYTE startNum, endNum;
for ( i = 0; i < DigitsLen; i++ )
{
startNum = pStartDigits[i] % 10;
endNum = pEndDigits[i] % 10;
if( startNum < endNum )
{
for ( j = startNum + 1; j < endNum; j++ )
{
if( pNode->psub[j] == NULL && ( pNode->psub[j] = NewNode ( ) ) == NULL )
return 0;
/* add by daniel on 2006-5-15 */
if( pNode->psub[j]->nItem == 0xFFFF ) //if this node has empty index then mark it with the new index, else do nothing
/* add by daniel on 2006-5-15 */
pNode->psub[j]->nItem = index;
}
if( pNode->psub[startNum] == NULL && ( pNode->psub[startNum] = NewNode ( ) ) == NULL )
return 0;
if( pNode->psub[endNum] == NULL && ( pNode->psub[endNum] = NewNode ( ) ) == NULL )
return 0;
if( AddLargerNode ( pNode->psub[startNum], pStartDigits + i + 1, DigitsLen - i - 1, index ) == 0 )
return 0;
if( AddLessNode ( pNode->psub[endNum], pEndDigits + i + 1, DigitsLen - i - 1, index ) == 0 )
return 0;
return 1;
}
else if( startNum == endNum )
{
if( pNode->psub[startNum] == NULL && ( pNode->psub[startNum] = NewNode ( ) ) == NULL )
{
//send alarm here
pNode = NULL;
return 0;
}
pNode = pNode->psub[startNum];
if( i >= DigitsLen - 1 )
{
pNode->nItem = index;
return 1;
}
continue;
}
else if( startNum > endNum )
return 0;
}
return 1;
}
int AddLargerNode ( SCCP_ROUTE_NODE * pNode, BYTE * pDigits, BYTE DigitsLen, u_short index )
{
int i, j;
BYTE startNum;
for ( i = 0; i < DigitsLen; i++ )
{
startNum = pDigits[i] % 10;
for ( j = startNum + 1; j <= 9; j++ )
{
if( pNode->psub[j] == NULL && ( pNode->psub[j] = NewNode ( ) ) == NULL )
return 0;
/* add by daniel on 2006-5-15 */
if( pNode->psub[j]->nItem == 0xFFFF ) //if this node has empty index then mark it with the new index, else do nothing
/* add by daniel on 2006-5-15 */
pNode->psub[j]->nItem = index;
}
if( pNode->psub[startNum] == NULL && ( pNode->psub[startNum] = NewNode ( ) ) == NULL )
return 0;
pNode = pNode->psub[startNum];
}
pNode->nItem = index;
return 1;
}
int AddLessNode ( SCCP_ROUTE_NODE * pNode, BYTE * pDigits, BYTE DigitsLen, u_short index )
{
int i, j;
BYTE endNum;
for ( i = 0; i < DigitsLen; i++ )
{
endNum = pDigits[i] % 10;
for ( j = 0; j < endNum; j++ )
{
if( pNode->psub[j] == NULL && ( pNode->psub[j] = NewNode ( ) ) == NULL )
return 0;
/* add by daniel on 2006-5-15 */
if( pNode->psub[j]->nItem == 0xFFFF ) //if this node has empty index then mark it with the new index, else do nothing
/* add by daniel on 2006-5-15 */
pNode->psub[j]->nItem = index;
}
if( pNode->psub[endNum] == NULL && ( pNode->psub[endNum] = NewNode ( ) ) == NULL )
return 0;
pNode = pNode->psub[endNum];
}
pNode->nItem = index;
return 1;
}
SCCP_ROUTE_NODE *NewNode ( )
{
if( heap_index >= SCCP_ROUTE_NODE_NUM ){
spLog ( "Fatal Error: Fail to add GT node, no resource" );
return NULL;
}
RouteNode[heap_index].nItem = 0xFFFF;
return &RouteNode[heap_index++];
}
/*
*Purpose: check whether a GT is in the SCCP GT table
*Param: np: Number Plan
* tt: Translation Type
* gt: Global title
* gt_len: length of gt
*Return: 0 - the GT is not in SCCP GTT
* 1 - the GT is in SCCP GTT
*/
int CheckGT(BYTE np, BYTE tt, BYTE *gt, BYTE gt_len)
{
BYTE Num[32], NumLen;
BYTE field = 0;
int nRoute;
assert(gt_len < 32);
assert(gt != NULL);
if( np > 0 )
Num[field++] = np;
else
Num[field++] = NP_MSISDN;
if( tt > 0 )
{
Num[field++] = tt / 100;
Num[field++] = ( tt / 10 ) % 10;
Num[field++] = tt % 10;
}
else
{
Num[field++] = TT_0;
Num[field++] = TT_1;
Num[field++] = TT_4;
}
NumLen = gt_len % ( MAX_DIGITS * 2 );
Digits2Array ( Num + field, gt, ( NumLen + 1 ) / 2 );
nRoute = SelectRoute ( Num, NumLen + field );
if( nRoute < SCCP_ROUTE_NUM )
return 1;
else
return 0;
}

415
plat/sccp/src/sccp_log.c Normal file
View File

@@ -0,0 +1,415 @@
//////////////////////////////////////////////////
//Title : spLog.c
//Auhtor : Liu Wei
//Desc : sccp log implementation
//Created : 2007-05-19
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/sccp.h"
#include "./include/sccp_pub.h"
#include "./include/sccp_func.h"
BYTE sccpDebugFull = 0;
/* by simon at 23/9/26 */
extern SCCP_SegMsgBuf sccp_segmsgbuf[MAX_SEGMSG_BUF];
extern void spWatchDogStatic ( u8 uDebugStaticMask );
extern char sccp_debug_buf[5120];
extern int spLog_fd;
extern unsigned long spLogDebug_mask;
void spLog ( char *info )
{
#ifdef DEBUG_TEST
if( strlen ( info ) < 2048 )
{
printf ( "[SCCP]: %s\n", info );
}
#else
if( strlen ( sccp_debug_buf ) + strlen ( info ) > 2048 )
{
sccpDebugFull = 1;
return;
}
strncat ( sccp_debug_buf, info, 2048 );
strcat ( sccp_debug_buf, "\r\n" );
if( spLog_fd != -1 )
{
write ( spLog_fd, info, strlen ( info ) );
write ( spLog_fd, "\r\n", 2 );
}
if( strlen ( sccp_debug_buf ) > 2050 )
{
printf ( "sccp debug buffer overflow, len=%d\n", strlen ( sccp_debug_buf ) );
}
#endif
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spShowAddr ( SCCP_ADDR * pAddr, const char *sAddrName )
{
char srcAddr[128], digits[24];
Digits2Str ( digits, pAddr->GTAI, ( ( pAddr->len + 1 ) / 2 ) % MAX_DIGITS );
digits[pAddr->len] = 0;
sprintf ( srcAddr, "%s: SPC=%06X SSN=%d RI=%d GTI=%d NP=%d TT=%d GT=%s", sAddrName, pAddr->DPC, pAddr->SSN, pAddr->RI, pAddr->GTI, pAddr->NP, pAddr->TT, digits );
spLog ( srcAddr );
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
void spLogDebug ( DWORD mask, const char *fmt, ... )
{
va_list ap;
char buf[1024];
if( ( mask & spLogDebug_mask ) == 0 || sccpDebugFull )
{
return;
}
if( spLogDebug_mask & SCCPDB_TIME )
{
struct timeval tv;
struct timezone tz;
struct tm *t;
char timestr[32];
gettimeofday ( &tv, &tz );
t = localtime ( &tv.tv_sec );
if( t == NULL )
{
assert( 0 && "syscall : localtime fail");
exit(0);
}
sprintf ( timestr, "(%d:%d:%d.%ld):", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec );
spLog ( timestr );
}
if( ( mask & SCCPDB_ERR ) && ( strlen ( sccp_debug_buf ) + 5 < 2048 ) )
{
strcat ( sccp_debug_buf, "\33[31m" );
}
va_start ( ap, fmt );
vsnprintf ( buf, 1024, fmt, ap );
va_end ( ap );
strcat ( buf, "\33[37m" );
spLog ( buf );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spShowBCD ( DWORD mask, BYTE * buf, int len )
{
// int i = 0, j = 0, linemax = 24;
char info[1024];
if( ( spLogDebug_mask & SCCPDB_MSG ) == 0 || ( spLogDebug_mask & mask ) == 0 || sccpDebugFull )
{
return;
}
if( len >= 256 )
{
len = 256;
}
MsgToFmtLog ( buf, len, info, 1024 );
spLog ( info );
}
void spLogSeg ( SCCP_SegMsgBuf * pSegMsgbuf )
{
char digits[24], info[256];
spShowAddr ( &pSegMsgbuf->SegID.CGA, "spShowAddr" );
BcdToAscii ( digits, pSegMsgbuf->SegID.SegLR, 6 );
digits[6] = 0;
sprintf ( info, "Seginfo: Total=%d RSE=%d DPC=%06X SLS=%d Class=%d SegLR=0x%s", pSegMsgbuf->MsgTotal, pSegMsgbuf->RSE, pSegMsgbuf->SegID.DPC, pSegMsgbuf->SegID.SLS, pSegMsgbuf->MsgClass, digits );
spLog ( info );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spShowMsg ( DWORD mask, const char *pDesc, Intra_Msg * pIntraMsg )
{
// int i = 0, j = 0, linemax = 24;
int len;
// char srcAddr[128], dstAddr[128];
char digits[24], info[1024];
char *pStr;
if( ( mask & spLogDebug_mask ) == 0 && ( sccp_filter_msg ( &pIntraMsg->CGA, &pIntraMsg->CDA ) == 0 || mask >= SCCPDB_STP ) )
{
return;
}
if( sccpDebugFull )
{
return;
}
if( strlen ( sccp_debug_buf ) + 2 < 2048 )
{
strcat ( sccp_debug_buf, "\r\n" );
}
if( spLogDebug_mask & SCCPDB_TIME )
{
struct timeval tv;
struct timezone tz;
struct tm *t;
char timestr[32];
gettimeofday ( &tv, &tz );
t = localtime ( &tv.tv_sec );
if( t == NULL )
{
assert( 0 && "syscall : localtime fail");
exit(0);
}
sprintf ( timestr, "(%d:%d:%d.%ld):", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec );
spLog ( timestr );
}
if( mask & SCCPDB_ERR && ( strlen ( sccp_debug_buf ) + 5 < 2048 ) )
{
strcat ( sccp_debug_buf, "\33[31m" );
}
spGetMsgStr ( pIntraMsg->msgtype, pStr );
sprintf ( info, "%s %s[%d->%d], SLS=%02x, NetID=%d, msglen=%d\33[37m", pDesc, pStr, pIntraMsg->CGA.SSN, pIntraMsg->CDA.SSN, pIntraMsg->SLS, pIntraMsg->NetID, pIntraMsg->msglen );
spLog ( info );
if( ( spLogDebug_mask & SCCPDB_ADDR ) || ( mask & SCCPDB_ERR ) )
{
spShowAddr ( &pIntraMsg->CGA, "SrcAddr" );
spShowAddr ( &pIntraMsg->CDA, "DstAddr" );
}
if( mask & SCCPDB_AIF )
{
char digits1[24], digits2[24];
BcdToAscii ( digits1, pIntraMsg->aSLR, 6 );
digits1[6] = 0;
BcdToAscii ( digits2, pIntraMsg->aDLR, 6 );
digits2[6] = 0;
sprintf ( info, "SLR = %s DLR = %s ", digits1, digits2 );
spLog ( info );
}
if( mask & SCCPDB_XUDT )
{
BcdToAscii ( digits, pIntraMsg->Segmnt.SegLR, 6 );
digits[6] = 0;
sprintf ( info, "Seginfo: RS=%d SegLR=0x%s", pIntraMsg->Segmnt.RSBits, digits );
spLog ( info );
}
if( ( spLogDebug_mask & SCCPDB_MSG ) == 0 )
{
return;
}
len = pIntraMsg->msglen % 256;
MsgToFmtLog ( pIntraMsg->data, len, info, 1024 );
spLog ( info );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spShowPrimitive ( SP_UiPriPara * pUiPriParam, u8 uDirection )
{
u8 *pStr;
spGetUlPrimitiveStr ( pUiPriParam->uUiPri, pStr );
if( uDirection )
{
spLogDebug ( SCCPDB_TIME, "AIF ==> SCCP : %s", pStr );
}
else
{
spLogDebug ( SCCPDB_TIME, "SCCP ==> AIF : %s", pStr );
}
spShowUserData ( pUiPriParam );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLogStateError ( u16 wConnId, u8 uErrCode )
{
CO_ConnSection *pCS;
u8 *pStateStr;
u8 *pPriStr;
u8 *pSideStr;
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP spLogStateError unexpected connection id" );
pCS = &pSp->tCo.tCSInst[wConnId];
spGetCoStateStr ( pCS->uCState, pStateStr );
spGetUlPrimitiveStr ( pCS->uPri, pPriStr );
spGetCoInstanceSide ( pCS->uSide, pSideStr );
switch ( uErrCode )
{
case ERR_NONE:
{
#ifdef _WXC_FSM_TEST
char str[512];
sprintf ( str, "]coFsm[: call back state %s , side :%s \n", pStateStr, pSideStr );
spLog ( str );
#endif
}
break;
case ERR_FSM_UNEXPECT_SIDE:
spLogDebug ( SCCPDB_ERR, "Recieve unexpected side: %s ", pSideStr );
spWatchDogStatic ( ERR_FSM_UNEXPECT_SIDE );
break;
case ERR_FSM_UNEXPECT_PRI:
spLogDebug ( SCCPDB_ERR, "Recieve unexpected primitive in the state machine ," "Discard the primtive . \nstate: %s primtive :%s side :%s\n", pStateStr, pPriStr, pSideStr );
spWatchDogStatic ( ERR_FSM_UNEXPECT_PRI );
break;
case ERR_FSM_DISCARD:
spLogDebug ( SCCPDB_ERR, "Unexpected state machine ,Discard the state : %s side :%s", pStateStr, pSideStr );
spWatchDogStatic ( ERR_FSM_DISCARD );
break;
case ERR_FSM_ERROR:
spLogDebug ( SCCPDB_ERR, "Unexpected state machine ,error state : %s side :%s", pStateStr, pSideStr );
spWatchDogStatic ( ERR_FSM_ERROR );
break;
case ERR_FSM_FATAL:
spLogDebug ( SCCPDB_ERR, "Unexpected state machine ,fatal error : %s side :%s", pStateStr, pSideStr );
spWatchDogStatic ( ERR_FSM_FATAL );
case ERR_FSM_RESERVED:
spLogDebug ( SCCPDB_ERR, "Unexpected reserved state machine, unsupported now state : %s side :%s", pStateStr, pSideStr );
spWatchDogStatic ( ERR_FSM_RESERVED );
break;
default:
spLogDebug ( SCCPDB_ERR, "SCCP log state error , but unkonw eror code" );
spWatchDogStatic ( ERR_FSM_UNKOWN_ERROR_CODE );
break;
}
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLogTimerOut ( u16 wConnId, u8 uTimerID )
{
u8 *pTimerStr;
spGetTimerOutStr ( uTimerID, pTimerStr );
spLogDebug ( SCCPDB_ERR, "SCCP Timer Out Timer ID : %s ConnID : %d ", pTimerStr, wConnId );
spWatchDogStatic ( SP_TIMER_OUT );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spShowUserData ( SP_UiPriPara * pPri )
{
SP_UD *pUd;
SP_UiPriUnion *pPriUn;
pPriUn = &pPri->tPriUnion;
switch ( pPri->uUiPri )
{
case N_CONNECT_REQ:
if( !( pPriUn->tPriNConnReq.uOptFlag & 0x08 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Connect Req primitive Flag :0x%X ", pPriUn->tPriNConnReq.uOptFlag );
pUd = &pPriUn->tPriNConnReq.tUD;
break;
case N_CONNECT_IND:
if( !( pPriUn->tPriNConnInd.uOptFlag & 0x04 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Connect Ind primitive Flag :0x%X NetID : %d "
"RI : %d SSN : %d" , pPriUn->tPriNConnInd.uOptFlag
,pPriUn->tPriNConnInd.tCDA.NetID
,pPriUn->tPriNConnInd.tCDA.RI
,pPriUn->tPriNConnInd.tCDA.SSN );
pUd = &pPriUn->tPriNConnInd.tUD;
break;
case N_CONNECT_CFM:
if( !( pPriUn->tPriNConnCfm.uOptFlag & 0x04 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Connect Cfm primitive Flag :0x%X ", pPriUn->tPriNConnCfm.uOptFlag );
pUd = &pPriUn->tPriNConnCfm.tUD;
break;
case N_CONNECT_RSP:
if( !( pPriUn->tPriNConnRsp.uOptFlag & 0x04 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Connect Rsp primitive Flag :0x%X ", pPriUn->tPriNConnRsp.uOptFlag );
pUd = &pPriUn->tPriNConnRsp.tUD;
break;
case N_DISCONNECT_REQ:
if( !( pPriUn->tPriNDisconnReq.uOptFlag & 0x04 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Disconnect Req primitive Flag :0x%X ", pPriUn->tPriNDisconnReq.uOptFlag );
pUd = &pPriUn->tPriNDisconnReq.tUD;
break;
case N_DISCONNECT_IND:
if( !( pPriUn->tPriNDisconnInd.uOptFlag & 0x04 ) )
{
return;
}
spLogDebug ( SCCPDB_AIF, "Disconnect Ind primitive Flag :0x%X ", pPriUn->tPriNDisconnInd.uOptFlag );
pUd = &pPriUn->tPriNDisconnInd.tUD;
break;
case N_DATA_REQ:
pUd = &pPriUn->tPriNDataReq.tUD;
break;
case N_DATA_IND:
pUd = &pPriUn->tPriNDataInd.tUD;
break;
case N_DATAAK_REQ:
case N_EDATA_REQ:
case N_RESET_REQ:
case N_RESET_RSP:
case N_INFORM_REQ:
return;
default:
return;
}
if( pUd->uDataLen > 0 )
{
spShowBCD ( SCCPDB_AIF, pUd->aUserData, ( pUd->uDataLen ) % 256 );
}
}

241
plat/sccp/src/sccp_mib.c Normal file
View File

@@ -0,0 +1,241 @@
/*********************************************************/
/*Title: sccpmib.c */
/*Descr: SCCP Management information Base Interface */
/*Author: Liang Hanxi */
/*Create: 2002-4-16 */
/*Modify: */
/*********************************************************/
#include "./include/sccp.h"
/*===========import================*/
extern int BuildRouteIndex ( ); //gtt.c
extern int sccp_loadparam ( ); //sccpparam.c
extern void sccp_saveparam ( );
extern int sccp_setparam ( DWORD * oid, BYTE * pdata, WORD datalen );
extern int sccp_getparam ( DWORD * oid, BYTE * pdata, BYTE * vartype );
extern void sccp_reset ( ); //sccp.c
extern void DWORD2BYTE ( BYTE * pdword, BYTE * pbyte, int len ); //sccpfun.c
extern void spLogDebug ( DWORD mask, const char *fmt, ... );
/* by simon at 23/9/26 */
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
/* by simon at 23/9/26*/
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern LOCAL_SSN LocalSSN[256];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
/*===========export================*/
void sccpmib_init ( );
void sccp_sethb ( );
/*===========private===============*/
int sccp_setmib ( BYTE oidlen, DWORD * oid, BYTE * pdata, WORD datalen );
int sccp_getmib ( BYTE oidlen, DWORD * oid, BYTE * pdata, BYTE * vartype );
void sccp_trapcallback ( BYTE oidlen, DWORD * oid, BYTE * pdata, WORD len, snmp_addr * addr );
void sccpmib_init ( )
{
DWORD oid[20] = SCCP_OID;
inquire_setmsg ( SCCP_OIDLEN, oid, sccp_setmib );
inquire_getmsg ( SCCP_OIDLEN, oid, sccp_getmib );
inquire_trapmsg ( sccp_trapcallback );
}
void sccp_sethb ( )
{
set_status ( 2, 4 + SCCP_Param.RegNum, SCCP_Param.version );
set_led ( 4, 9 );
}
/************************************************/
//MIB Interface=================================>
/************************************************/
int sccp_setmib ( BYTE oidlen, DWORD * oid, BYTE * pdata, WORD datalen )
{
switch ( oid[SCCP_OIDLEN] )
{
case 1: //CSTA, read only
return -1;
case 2: //Paramter
return sccp_setparam ( &oid[SCCP_OIDLEN + 1], pdata, datalen );
case 3: //Status
switch ( oid[SCCP_OIDLEN + 1] )
{
case 1: //version, read only
return -1;
case 2: //command
switch ( pdata[0] )
{
case 0: //reset
spLogDebug ( SCCPDB_SNMP, "Reset SCCP..." );
sccp_reset ( );
break;
case 1: //load
return -1;
case 2: //save
spLogDebug ( SCCPDB_SNMP, "Save Parameter..." );
sccp_saveparam ( );
break;
}
return 1;
case 3: //status, read only
return -1;
}
break;
}
return -1;
}
int sccp_getmib ( BYTE oidlen, DWORD * oid, BYTE * pdata, BYTE * vartype )
{
DWORD instance;
SCCP_CSTA *pcsta;
spLogDebug ( SCCPDB_SNMP, "get sccp mib..." );
switch ( oid[SCCP_OIDLEN] )
{
case 1: //CSTA
instance = oid[SCCP_OIDLEN + 1];
if( instance == SccpCstaInd || instance > 95 )
{
*vartype = NosuchInstance;
spLogDebug ( SCCPDB_SNMP, "csta message not ready. instance=%d", instance );
return 0;
}
pcsta = &SccpCsta[instance];
if( pcsta->timestamp == 0 )
{
spLogDebug ( SCCPDB_SNMP, "csta message is expired" );
*vartype = 5;
return 0;
}
*vartype = 4;
spLogDebug ( SCCPDB_SNMP, "Respond csta message" );
DWORD2BYTE ( ( BYTE * ) & pcsta->timestamp, pdata, sizeof ( SCCP_CSTA ) );
return sizeof ( SCCP_CSTA );
case 2: //Config
return sccp_getparam ( &oid[SCCP_OIDLEN + 1], pdata, vartype );
case 3: //Status
switch ( oid[SCCP_OIDLEN + 1] )
{
case 1: //version
spLogDebug ( SCCPDB_SNMP, "Get SCCP Version" );
memcpy ( pdata, SCCP_Param.version, 3 );
*vartype = 4;
return 3;
case 2: //command, write only
return -1;
case 3: //status
pdata[0] = SCCP_Param.status;
*vartype = 2;
return 1;
}
break;
}
return -1;
}
//#define OMC_HB_OID {1,3,6,1,4,1,1373,1,4,1,1}
#define OMC_HB_OID {1,3,6,1,4,1,1373,2,4,1}
#define OMC_HB_OIDLEN 10
int AddToIpList ( DWORD ip, BYTE ssn );
void sccp_OMCIP_detect ( DWORD ip )
{
int i;
BYTE index = 0;
for ( i = 0; i <= 1; i++ )
{
if( SCCP_Param.OMCIP[i] == ip )
return;
else if( SCCP_Param.OMCIP[i] == 0 )
index = i;
}
SCCP_Param.OMCIP[index] = ip;
AddToIpList ( ip, 4 );
}
extern ull SCCPSerialNumber;
void sccp_trapcallback ( BYTE oidlen, DWORD * oid, BYTE * pdata, WORD len, snmp_addr * addr )
{
DWORD ObjID[20] = FLATFORM_HB_OID;
BYTE ssn;
short infolen, i, pos = 2; //component_id=0:iptrans
heartbeat_msg *phbmsg = ( heartbeat_msg * ) pdata;
BYTE *pstatus = phbmsg->info;
DWORD OMCHLObjID[20] = OMC_HB_OID;
BYTE newHeartbeat = 0;
if( memcmp ( &oid[7], &OMCHLObjID[7], ( OMC_HB_OIDLEN - 7 ) * 4 ) == 0 ) //omc heartbeat
{ //automatic add omc ip into ip list,
//if receive omc heartbeat and the omc serial number is equial to the local serial number,
//then the platform will send heartbeat if received omc heartbeat
if( ( SCCPSerialNumber == 0 ) || //support old version, do not have serial number
( Bcd2Ull ( &pdata[39], SCCP_SERNUM_LEN ) == SCCPSerialNumber ) )
sccp_OMCIP_detect ( addr->remote_ip );
}
if( memcmp ( &oid[9], &ObjID[9], ( FLATFORM_HB_OIDLEN - 9 ) * 4 ) != 0 || addr->remote_ip == SCCP_Param.ip )
return;
if( sizeof ( struct heartbeat_msg ) > ( INFO_LEN + 18 ) )
newHeartbeat = 1;
if( !newHeartbeat )
{ //old version heartbeat, length and component_id are one octet
pos = 1;
pos += pstatus[pos] + 1; //length of iptrans status
pos++; //component_id=1:mtp3
pos += pstatus[pos] + 1; //length of mtp3
pos++; //component_id=2:sccp
}
else
{ //new version heartbeat, length and component_id are 2 octets
pos++; //length is 2 octets
pos += pstatus[pos] + 1; //length of iptrans status
pos++; //component_id=1:mtp3
pos++; //component_id is 2 octets
pos++; //length is 2 octets
pos += pstatus[pos] + 1; //length of mtp3
pos++; //component_id=2:sccp
pos++; //component_id is 2 octets
pos++; //sccp length 1
}
infolen = pstatus[pos++];
if( infolen <= 4 || infolen > 32 )
return;
for ( i = pos + 4; i < pos + infolen; i++ )
{
ssn = pstatus[i];
// printf("beat recieve,ssn=%d\n",ssn);
if( ssn <= 1 )
continue;
if( addr->remote_ip == LocalSSN[ssn].ip[0] )
{
LocalSSN[ssn].status[0] = ST_Enable;
LocalSSN[ssn].timeout[0] = T_hbrecv;
}
else if( addr->remote_ip == LocalSSN[ssn].ip[1] )
{
LocalSSN[ssn].status[1] = ST_Enable;
LocalSSN[ssn].timeout[1] = T_hbrecv;
}
}
}

777
plat/sccp/src/sccp_msg.c Normal file
View File

@@ -0,0 +1,777 @@
/*****************************************/
/*Title:sccpmsg.c */
/*Descr:SCCP message Procedure */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2003-5-9 */
/*****************************************/
#include "./include/sccp.h"
/* =========== export ================ */
int build_msg ( BYTE * buf, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag );
int parse_msg ( BYTE * buf, Intra_Msg * intramsg, int len, BYTE NetID, BYTE ansi_flag );
/* =========== private ================ */
static int parse_oparam ( BYTE * buf, int len, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag );
static int encode_addr ( BYTE * buf, SCCP_ADDR * addr, BYTE NetID );
static int decode_addr ( BYTE * buf, SCCP_ADDR * addr, BYTE NetID );
/* ansi */
static int encode_addr_Ansi ( BYTE * buf, SCCP_ADDR * addr );
static int decode_addr_Ansi ( BYTE * buf, SCCP_ADDR * addr );
/* ansi */
//static int encode_int ( BYTE * buf, unsigned int val, BYTE len );
//static unsigned int decode_int ( BYTE * buf, BYTE len );
extern void spLogDebug ( DWORD mask, const char *fmt, ... );
/* by simon at 23/9/26 */
extern SCCP_Capture_Buf SCCPCapBuf;
extern DWORD SccpCstaInd;
extern LOCAL_SSN LocalSSN[256];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
////////////////////////////////////////////////////////////
int build_msg ( BYTE * buf, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag )
{
int msglen = 0, vnum = 0, vlen = 0;
buf[msglen++] = intramsg->msgtype;
if( intramsg->msglen > 256 )
{
intramsg->msglen = 256;
}
switch ( intramsg->msgtype )
{
case CR_MSG:
vnum = 1 + 1;
memcpy ( buf + msglen, &intramsg->aSLR, 3 ); //SLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aSLR, 3 ); //SLR
buf[msglen++] = intramsg->msgclass; //protocol class
/*Mandatory variable part */
buf[msglen++] = vnum--; //pointer of CDA
if( !ansi_flag )
vlen += encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CDA ), NetID );
else
vlen += encode_addr_Ansi ( buf + msglen + vnum + vlen, &( intramsg->CDA ) );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of optional part
msglen += vlen;
/*optional part */
/*
buf[msglen++] = P_CGA; //codes of CGA
msglen += encode_addr(buf + msglen, &(intramsg->CGA), NetID);
*/
buf[msglen++] = P_Data;
if( intramsg->msglen > 0 )
{
buf[msglen++] = intramsg->msglen;
memcpy ( buf + msglen, intramsg->data, intramsg->msglen );
msglen += intramsg->msglen;
}
buf[msglen++] = P_EOP;
break;
case CC_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
memcpy ( buf + msglen, &intramsg->aSLR, 3 ); //SLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aSLR, 3 );
buf[msglen++] = intramsg->msgclass;
buf[msglen++] = 1; // pointer ot end of optional
buf[msglen++] = 0; // end of optional
break;
case CREF_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
buf[msglen++] = intramsg->cause;
buf[msglen++] = 1; // pointer ot end of optional
buf[msglen++] = 0; // end of optional
break;
case UDT_MSG:
vnum = 3;
buf[msglen++] = intramsg->msgclass;
/*mandatory variable part */
buf[msglen++] = vnum--; //pointer of CDA
if( !ansi_flag )
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CDA ), NetID ) % 64 );
else
vlen += ( encode_addr_Ansi ( buf + msglen + vnum + vlen, &( intramsg->CDA ) ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of CGA
if( !ansi_flag )
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CGA ), NetID ) % 64 );
else
vlen += ( encode_addr_Ansi ( buf + msglen + vnum + vlen, &( intramsg->CGA ) ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of Data
buf[msglen + vnum + vlen] = intramsg->msglen; //Length of Data
memcpy ( buf + msglen + vnum + vlen + 1, intramsg->data, intramsg->msglen );
vlen = vlen + intramsg->msglen + 1;
msglen += vlen;
break;
case UDTS_MSG:
vnum = 3;
buf[msglen++] = intramsg->cause;
/*mandatory variable part */
buf[msglen++] = vnum--; //pointer of CDA
if( !ansi_flag )
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CDA ), NetID ) % 64 );
else
vlen += ( encode_addr_Ansi ( buf + msglen + vnum + vlen, &( intramsg->CDA ) ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of CGA
if( !ansi_flag )
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CGA ), NetID ) % 64 );
else
vlen += ( encode_addr_Ansi ( buf + msglen + vnum + vlen, &( intramsg->CGA ) ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of Data
buf[msglen + vnum + vlen] = intramsg->msglen; //Length of Data
memcpy ( buf + msglen + vnum + vlen + 1, intramsg->data, intramsg->msglen );
vlen = vlen + intramsg->msglen + 1;
msglen += vlen;
break;
case XUDT_MSG:
vnum = intramsg->SegPresent ? 4 : 3;
buf[msglen++] = intramsg->msgclass;
buf[msglen++] = intramsg->Hop;
/*mandatory variable part */
buf[msglen++] = vnum--; //pointer of CDA
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CDA ), NetID ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of CGA
vlen += ( encode_addr ( buf + msglen + vnum + vlen, &( intramsg->CGA ), NetID ) % 64 );
buf[msglen++] = ( vnum-- ) + vlen; //Pointer of Data
buf[msglen + vnum + vlen] = intramsg->msglen; //Length of Data
memcpy ( buf + msglen + vnum + vlen + 1, intramsg->data, intramsg->msglen );
vlen = vlen + intramsg->msglen + 1;
if( intramsg->SegPresent )
{
buf[msglen++] = ( vnum-- ) + vlen; //Pointer to Segmentation
buf[msglen + vnum + vlen] = P_SEG; //Segmentation tag
buf[msglen + vnum + vlen + 1] = 4; //Segmentation len
memcpy ( buf + msglen + vnum + vlen + 2, &intramsg->Segmnt, 4 );
msglen += 6;
}
msglen += vlen;
break;
case DT1_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
buf[msglen++] = intramsg->EOD;
buf[msglen++] = 1; //Pointer of Data
buf[msglen++] = intramsg->msglen; //Length of Data
memcpy ( buf + msglen, intramsg->data, intramsg->msglen );
msglen += intramsg->msglen;
break;
case DT2_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
buf[msglen++] = 2 * intramsg->PS;
buf[msglen++] = 2 * intramsg->PR + intramsg->EOD;
buf[msglen++] = 1; //Pointer of Data
buf[msglen++] = intramsg->msglen; //Length of Data
memcpy ( buf + msglen, intramsg->data, intramsg->msglen );
msglen += intramsg->msglen;
break;
case RLSD_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
memcpy ( buf + msglen, &intramsg->aSLR, 3 ); //SLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
//msglen += encode_int ( buf + msglen, intramsg->aSLR, 3 );
buf[msglen++] = intramsg->cause;
buf[msglen++] = 1; // pointer ot end of optional
buf[msglen++] = 0; // end of optional
break;
case RLC_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
memcpy ( buf + msglen, &intramsg->aSLR, 3 ); //SLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
//msglen += encode_int ( buf + msglen, intramsg->aSLR, 3 );
break;
case IT_MSG:
memcpy ( buf + msglen, &intramsg->aDLR, 3 ); //DLR
msglen += 3;
memcpy ( buf + msglen, &intramsg->aSLR, 3 ); //SLR
msglen += 3;
//msglen += encode_int ( buf + msglen, intramsg->aDLR, 3 );
//msglen += encode_int ( buf + msglen, intramsg->aSLR, 3 );
buf[msglen++] = 2; //class = 2
buf[msglen++] = 0; //Sequencing/segmenting octet 0
buf[msglen++] = 0; //Sequencing/segmenting octet 1
buf[msglen++] = 0; //Credit
break;
}
//buf[0] = msglen-1;
return msglen;
}
int parse_msg ( BYTE * buf, Intra_Msg * intramsg, int len, BYTE NetID, BYTE ansi_flag )
{
int pos = 0;
BYTE ptv, vlen;
intramsg->msgtype = buf[pos++];
switch ( intramsg->msgtype )
{
case CR_MSG:
if( len < 4 )
SCCPCapBuf.watch_dog[2]++; //invalid CR message
memcpy ( &intramsg->aSLR, buf + pos, 3 ); //SLR
pos += 3;
//intramsg->aSLR = decode_int ( buf + pos, 3 );
intramsg->msgclass = buf[pos++];
ptv = pos + buf[pos];
pos++;
if( !ansi_flag )
vlen = decode_addr ( buf + ptv, &( intramsg->CDA ), NetID );
else
vlen = decode_addr_Ansi ( buf + ptv, &( intramsg->CDA ) );
if( vlen + ptv >= len )
return 1;
ptv = pos + buf[pos];
pos++;
parse_oparam ( buf + ptv, len - ptv, intramsg, NetID, ansi_flag );
break;
case CC_MSG:
if( len < 8 )
SCCPCapBuf.watch_dog[3]++; //invalid CC message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
memcpy ( &intramsg->aSLR, buf + pos, 3 ); //SLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
//intramsg->aSLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->msgclass = buf[pos++];
ptv = pos + buf[pos];
/* if (buf[ptv++] == 0x0F)
{
intramsg->msglen = buf[ptv++];
memcpy ( intramsg->data, buf + ptv, intramsg->msglen );
}
*/
parse_oparam ( buf + ptv, len - ptv, intramsg, NetID, ansi_flag );
break;
case CREF_MSG:
if( len < 5 )
SCCPCapBuf.watch_dog[4]++; //invalid CREF message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->cause = buf[pos++];
ptv = pos + buf[pos];
parse_oparam ( buf + ptv, len - ptv, intramsg, NetID, ansi_flag );
break;
case UDT_MSG:
if( len < 2 )
SCCPCapBuf.watch_dog[5]++; //invalid UDT message
intramsg->msgclass = buf[pos++];
ptv = pos + buf[pos];
pos++;
if( !ansi_flag )
vlen = decode_addr ( buf + ptv, &( intramsg->CDA ), NetID );
else
vlen = decode_addr_Ansi ( buf + ptv, &( intramsg->CDA ) );
ptv = pos + buf[pos];
pos++;
if( !ansi_flag )
vlen = decode_addr ( buf + ptv, &( intramsg->CGA ), NetID );
else
vlen = decode_addr_Ansi ( buf + ptv, &( intramsg->CGA ) );
ptv = pos + buf[pos];
pos++;
intramsg->msglen = buf[ptv];
memcpy ( intramsg->data, buf + ptv + 1, intramsg->msglen );
break;
case UDTS_MSG:
if( len < 2 )
SCCPCapBuf.watch_dog[6]++; //invalid UDTs message
intramsg->cause = buf[pos++];
ptv = pos + buf[pos];
pos++;
if( !ansi_flag )
vlen = decode_addr ( buf + ptv, &( intramsg->CDA ), NetID );
else
vlen = decode_addr_Ansi ( buf + ptv, &( intramsg->CDA ) );
ptv = pos + buf[pos];
pos++;
if( !ansi_flag )
vlen = decode_addr ( buf + ptv, &( intramsg->CGA ), NetID );
else
vlen = decode_addr_Ansi ( buf + ptv, &( intramsg->CGA ) );
ptv = pos + buf[pos];
pos++;
intramsg->msglen = buf[ptv];
memcpy ( intramsg->data, buf + ptv + 1, intramsg->msglen );
break;
case XUDT_MSG:
//if (len < 2)
// SCCPCapBuf.watch_dog[5]++;//invalid XUDT message
intramsg->msgclass = buf[pos++];
intramsg->Hop = buf[pos++];
ptv = pos + buf[pos];
pos++;
vlen = decode_addr ( buf + ptv, &( intramsg->CDA ), NetID );
ptv = pos + buf[pos];
pos++;
vlen = decode_addr ( buf + ptv, &( intramsg->CGA ), NetID );
if( vlen + ptv >= len )
return 1;
ptv = pos + buf[pos];
pos = ptv;
intramsg->msglen = buf[pos++];
memcpy ( intramsg->data, buf + pos, intramsg->msglen );
pos += intramsg->msglen;
parse_oparam ( buf + pos, len - pos, intramsg, NetID, ansi_flag );
break;
case DT1_MSG:
if( len < 5 )
SCCPCapBuf.watch_dog[7]++; //invalid DT1 message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->EOD = buf[pos++];
ptv = pos + buf[pos];
pos++;
intramsg->msglen = buf[ptv];
memcpy ( intramsg->data, buf + ptv + 1, intramsg->msglen );
break;
case DT2_MSG:
if( len < 7 )
SCCPCapBuf.watch_dog[8]++; //invalid DT2 message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->PS = buf[pos++] / 2;
intramsg->PR = buf[pos] / 2;
intramsg->EOD = buf[pos++] % 2;
ptv = pos + buf[pos];
pos++;
intramsg->msglen = buf[ptv];
memcpy ( intramsg->data, buf + ptv + 1, intramsg->msglen );
break;
case RLSD_MSG:
if( len < 8 )
SCCPCapBuf.watch_dog[9]++; //invalid RLSD message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
memcpy ( &intramsg->aSLR, buf + pos, 3 ); //SLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
//intramsg->aSLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->cause = buf[pos++];
break;
case RLC_MSG:
if( len < 7 )
SCCPCapBuf.watch_dog[10]++; //invalid RLC message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
memcpy ( &intramsg->aSLR, buf + pos, 3 ); //SLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
//intramsg->aSLR = decode_int ( buf + pos, 3 );
//pos += 3;
break;
case IT_MSG:
if( len < 8 )
SCCPCapBuf.watch_dog[11]++; //invalid IT message
memcpy ( &intramsg->aDLR, buf + pos, 3 ); //DLR
pos += 3;
memcpy ( &intramsg->aSLR, buf + pos, 3 ); //SLR
pos += 3;
//intramsg->aDLR = decode_int ( buf + pos, 3 );
//pos += 3;
//intramsg->aSLR = decode_int ( buf + pos, 3 );
//pos += 3;
intramsg->msgclass = buf[pos++];
break;
}
return 1;
}
int parse_oparam ( BYTE * buf, int len, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag )
{
int pos = 0;
BYTE nparam;
while ( pos < len )
{
nparam = buf[pos++];
switch ( nparam )
{
case P_EOP:
return 1;
case P_CDA:
/* if (!ansi_flag)
pos += decode_addr(buf + pos, &(intramsg->CDA), NetID);
else
pos += decode_addr_Ansi(buf + pos, &(intramsg->CDA)); */
break;
case P_CGA:
if( !ansi_flag )
pos += decode_addr ( buf + pos, &( intramsg->CGA ), NetID );
else
pos += decode_addr_Ansi ( buf + pos, &( intramsg->CGA ) );
break;
case P_Data:
intramsg->msglen = buf[pos++];
memcpy ( intramsg->data, buf + pos, intramsg->msglen );
pos += intramsg->msglen;
break;
case P_SEG:
if( buf[pos] != 4 )
{
spLogDebug ( SCCPDB_USER, "SCCP XUDT Msg Segmentaion Parameters length error!" );
}
pos++;
memcpy ( &intramsg->Segmnt, &buf[pos], 4 );
intramsg->SegPresent = 1;
pos += 4;
break;
case P_DLR:
case P_SLR:
case P_PLC:
case P_EOD:
case P_PR:
case P_SEQ:
case P_Credit:
case P_RLC:
case P_RTC:
case P_RSC:
case P_ERC:
case P_RFC:
case P_HC:
case P_Importance:
case P_Ldata:
break;
}
}
return 1;
}
/*
int encode_int ( BYTE * buf, unsigned int val, BYTE len )
{
BYTE temp[4];
temp[0] = ( BYTE ) ( ( val & 0xFF000000 ) >> 24 );
temp[1] = ( BYTE ) ( ( val & 0xFF0000 ) >> 16 );
temp[2] = ( BYTE ) ( ( val & 0xFF00 ) >> 8 );
temp[3] = ( BYTE ) ( val & 0xFF );
memcpy ( buf, temp + 4 - len, len );
return len;
}
unsigned int decode_int ( BYTE * buf, BYTE len )
{
unsigned int rtn = 0, i;
for ( i = 0; i < len; i++ )
rtn = rtn << 8 | buf[i];
return rtn;
}
*/
int encode_addr ( BYTE * buf, SCCP_ADDR * addr, BYTE NetID )
{
BYTE len = 0, cp_len;
BYTE RI_MASK = 0x40, SSN_MASK = 0x02, DPC_MASK = 0x01, GT_MASK = 0x04;
/*GTI*/ len = 2;
//if(addr->RI == RI_SSN && addr->SSN > 0)
// addr->GTI = 0;
buf[1] = ( RI_MASK * addr->RI ) | ( SSN_MASK ) | ( DPC_MASK & ( addr->DPC > 0 ? 1 : 0 ) & ( addr->AI & 1 ) ) | ( GT_MASK * addr->GTI );
if( ( addr->DPC > 0 ) & ( addr->AI & 1 ) )
{
memcpy ( buf + len, ( BYTE * ) & addr->DPC, SCCP_Param.spclen[NetID] );
len += SCCP_Param.spclen[NetID];
}
buf[len++] = addr->SSN;
switch ( addr->GTI )
{
case 0: //no global title included
break;
case 1: //global title includes nature of address indicator only
buf[len++] = addr->NAI;
memcpy ( buf + len, addr->GTAI, ( addr->len + 1 ) / 2 );
len += ( addr->len + 1 ) / 2;
break;
case 2: //global title includes translation type only
buf[len++] = addr->TT;
memcpy ( buf + len, addr->GTAI, ( addr->len + 1 ) / 2 );
len += ( addr->len + 1 ) / 2;
break;
case 3: //global title includes translation type, NP, EC
buf[len++] = addr->TT;
cp_len = ( addr->len + 1 ) / 2;
if( addr->len & 1 ) //odd number of address signals
{
addr->ES = 1;
addr->GTAI[cp_len - 1] = addr->GTAI[cp_len - 1] & 0x0F;
}
else
addr->ES = 2;
buf[len++] = addr->NP * 16 + addr->ES;
addr->GTAI[len] = 0;
memcpy ( buf + len, addr->GTAI, cp_len );
len += cp_len;
break;
case 4: //global title includes translation type, NP, EC, NAI
buf[len++] = addr->TT;
addr->len %= 18;
cp_len = ( addr->len + 1 ) / 2;
if( addr->len & 1 ) //odd number of address signals
{
addr->ES = 1;
addr->GTAI[cp_len - 1] = addr->GTAI[cp_len - 1] & 0x0F;
}
else
addr->ES = 2;
buf[len++] = addr->NP * 16 + addr->ES;
buf[len++] = addr->NAI;
memcpy ( buf + len, addr->GTAI, cp_len );
len += cp_len;
break;
}
buf[0] = len - 1;
return len;
}
int decode_addr ( BYTE * buf, SCCP_ADDR * addr, BYTE NetID )
{
BYTE len, pos, nbyte;
BYTE RI_MASK = 0x40, SSN_MASK = 0x02, DPC_MASK = 0x01, GT_MASK = 0x3C;
BYTE DPCI;
len = buf[0] + 1;
addr->RI = ( buf[1] & RI_MASK ) >> 6;
addr->GTI = ( buf[1] & GT_MASK ) >> 2;
DPCI = ( buf[1] & DPC_MASK );
addr->SSN = ( buf[1] & SSN_MASK ) >> 1;
pos = 2;
if( DPCI )
{
memcpy ( ( BYTE * ) & addr->DPC, buf + pos, SCCP_Param.spclen[NetID] );
pos += SCCP_Param.spclen[NetID];
}
if( addr->SSN )
addr->SSN = buf[pos++];
switch ( addr->GTI )
{
case 0: //no global title included
break;
case 1: //global title includes nature of address indicator only
addr->NAI = buf[pos++] & 0x7F;
nbyte = len - pos;
addr->len = 2 * nbyte;
if( ( buf[pos - 1] & 0x80 ) == 0x80 ) //odd number of address signals
addr->len--;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
case 2: //global title includes translation type only
addr->TT = buf[pos++];
nbyte = len - pos;
addr->len = 2 * nbyte;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
case 3: //global title includes translation type, NP, EC
addr->TT = buf[pos++];
addr->NP = buf[pos] / 16;
addr->ES = buf[pos++] % 16;
nbyte = len - pos;
addr->len = 2 * nbyte;
if( addr->ES == 1 )
addr->len--;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
case 4: //global title includes translation type, NP, EC, NAI
addr->TT = buf[pos++];
addr->NP = buf[pos] / 16;
addr->ES = buf[pos++] % 16;
addr->NAI = buf[pos++] & 0x7F;
nbyte = len - pos;
addr->len = 2 * nbyte;
if( addr->ES == 1 )
addr->len--;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
}
return len;
}
//----->ansi
int encode_addr_Ansi ( BYTE * buf, SCCP_ADDR * addr )
{
BYTE len = 0, cp_len;
BYTE NAT_MASK = 0x80, RI_MASK = 0x40, DPC_MASK = 0x02, SSN_MASK = 0x01, GT_MASK = 0x04;
BYTE spclen = 3; //ansi is always 24 bit,3 bytes
/*GTI*/ len = 2;
//if(addr->RI == RI_SSN && addr->SSN > 0)
// addr->GTI = 0;
switch ( addr->GTI )
{
case 4:
addr->GTI = 2;
break;
default:
break;
}
buf[1] = NAT_MASK | ( RI_MASK * addr->RI ) | ( SSN_MASK ) | ( DPC_MASK & ( ( addr->DPC > 0 ? 1 : 0 ) * 2 ) & ( ( addr->AI & 1 ) * 2 ) ) | ( GT_MASK * addr->GTI );
buf[len++] = addr->SSN;
if( addr->DPC > 0 && ( addr->AI & 1 ) )
{
/* memcpy(buf + len, (BYTE *)&addr->DPC, SCCP_Param.spclen[NetID]);
len += SCCP_Param.spclen[NetID]; */
memcpy ( buf + len, ( BYTE * ) & addr->DPC, spclen );
len += spclen;
}
switch ( addr->GTI )
{
case 0: //no global title included
break;
case 1: //global title includes translation type, NP, EC
buf[len++] = addr->TT;
cp_len = ( addr->len + 1 ) / 2;
if( addr->len & 1 ) //odd number of address signals
{
addr->ES = 1;
addr->GTAI[cp_len - 1] = addr->GTAI[cp_len - 1] & 0x0F;
}
else
addr->ES = 2;
buf[len++] = addr->NP * 16 + addr->ES;
addr->GTAI[len] = 0;
memcpy ( buf + len, addr->GTAI, cp_len );
len += cp_len;
break;
case 2: //global title includes translation type only
buf[len++] = addr->TT;
/* added by Pierre, 2006-09-30 for the filler */
cp_len = ( addr->len + 1 ) / 2;
if( addr->len & 1 ) //odd number of address signals
{
addr->GTAI[cp_len - 1] = addr->GTAI[cp_len - 1] & 0x0F;
}
/* above lines added by Pierre */
memcpy ( buf + len, addr->GTAI, ( addr->len + 1 ) / 2 );
len += ( addr->len + 1 ) / 2;
break;
default:
break;
}
buf[0] = len - 1;
return len;
}
int decode_addr_Ansi ( BYTE * buf, SCCP_ADDR * addr )
{
BYTE len, pos, nbyte;
BYTE RI_MASK = 0x40, DPC_MASK = 0x02, SSN_MASK = 0x01, GT_MASK = 0x3C;
BYTE DPCI;
BYTE spclen = 3; //ansi is always 24 bit,3 bytes
len = buf[0] + 1;
addr->RI = ( buf[1] & RI_MASK ) >> 6;
addr->GTI = ( buf[1] & GT_MASK ) >> 2;
DPCI = ( buf[1] & DPC_MASK ) >> 1;
addr->SSN = ( buf[1] & SSN_MASK );
pos = 2;
if( addr->SSN )
addr->SSN = buf[pos++];
if( DPCI )
{
/* memcpy((BYTE *)&addr->DPC, buf + pos, SCCP_Param.spclen[NetID]);
pos += SCCP_Param.spclen[NetID]; */
memcpy ( ( BYTE * ) & addr->DPC, buf + pos, spclen );
pos += spclen;
}
switch ( addr->GTI )
{
case 0: //no global title included
break;
case 1: //global title includes translation type, NP, EC
addr->TT = buf[pos++];
addr->NP = buf[pos] / 16;
addr->ES = buf[pos++] % 16;
nbyte = len - pos;
addr->len = 2 * nbyte;
if( addr->ES == 1 )
addr->len--;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
case 2: //global title includes translation type only
addr->TT = buf[pos++];
nbyte = len - pos;
addr->len = 2 * nbyte;
memcpy ( addr->GTAI, buf + pos, nbyte % ( MAX_DIGITS + 1 ) );
break;
default:
break;
}
return len;
}

705
plat/sccp/src/sccp_param.c Normal file
View File

@@ -0,0 +1,705 @@
/**************************************************/
/*Title: sccpparam.c */
/*Descr: sccp parameter management */
/*Author: Liang Hanxi */
/*Create: 2002-5-7 */
/**************************************************/
#include "./include/sccp.h"
/*===========export================*/
int sccp_loadparam ( );
void sccp_saveparam ( );
int sccp_setparam ( DWORD * oid, BYTE * pdata, WORD datalen );
int sccp_getparam ( DWORD * oid, BYTE * pdata, BYTE * vartype );
/*===========import================*/
extern int Str2Digits ( BYTE * pDigits, char *pStr, int DigitsLen );
extern int Str2Bcd ( BYTE * pBcd, char *pStr, int maxLen );
extern int Str2Array ( BYTE * pArray, char *str, int ArrayLen );
extern int Bcd2Digits ( BYTE * pDigits, BYTE * pBcd, int maxLen );
extern int BcdLen ( BYTE * pBcd, int maxLen );
extern int ParseLine ( char *str, char ( *row )[128], int maxrow );
extern void spLogDebug ( DWORD mask, const char *fmt, ... );
/*===========private================*/
static int SccpGetLocalIP ( );
int ParseLocalNode ( char *str );
static void ParseRouteInfo ( char *str );
static void ParseRLSSN ( char *str );
static void ParseGTTAttributeOMC ( char *str );
/* by simon at 23/9/26 */
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern LOCAL_SSN LocalSSN[256];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
extern int RelatedSPCNum;
extern RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
extern GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern SCCP_Capture_Buf SCCPCapBuf;
int GetMSISDNOfSSN ( BYTE ssn, BYTE * msisdn )
{
int len;
len = Bcd2Digits ( msisdn, LocalSSN[ssn].msisdn, MAX_DIGITS ) % ( MAX_DIGITS + 1 );
// memset ( msisdn + len, 0xFF, MAX_DIGITS - len );
memset ( msisdn + len, 0xFF, 8 - len );
return len;
}
int sccp_GetSSNType ( BYTE ssn )
{
return mtp3_ansiFlag ( LocalSSN[ssn].NetID );
}
int sccp_loadparam ( )
{
FILE *fp;
int i, j;
char str[200] = "\0", *pChr, *pKey;
BYTE state = 0;
SccpGetLocalIP ( );
for ( i = 0; i < 256; i++ )
{
LocalSSN[i].status[0] = LocalSSN[i].status[1] = 0;
LocalSSN[i].ip[0] = LocalSSN[i].ip[1] = 0xFFFFFFFF;
LocalSSN[i].local = 0;
LocalSSN[i].NetID = 0;
memset ( LocalSSN[i].msisdn, 0xFF, MAX_DIGITS );
}
for ( i = 0; i < SCCP_ROUTE_NUM; i++)
{
memset ( &RouteList[i], 0, sizeof ( SCCP_ROUTE ) );
memset ( RouteList[i].StartDigits, 0xFF, MAX_DIGITS * 2 );
memset ( RouteList[i].ReplaceDigits, 0xFF, MAX_DIGITS );
memset ( RouteList[i].acn_ver, 0x02, 48 );
}
RelatedSSNNum = 0;
fp = fopen ( SCCP_CONF_FILE, "r" );
if( fp == NULL )
{
printf ( "GTT Initializing: Config File %s not found\n", SCCP_CONF_FILE );
return -1;
}
while ( fgets ( str, 200, fp ) != NULL )
{
if( ( pChr = strchr ( str, '#' ) ) != NULL )
pChr[0] = '\0';
if( ( pKey = strstr ( str, "[" ) ) != NULL )
{
if( ( pKey = strstr ( str, "[Local Node]" ) ) != NULL )
state = 1;
else if( ( pKey = strstr ( str, "[GTT_Table]" ) ) != NULL )
state = 2;
else if( ( pKey = strstr ( str, "[RL_SSN]" ) ) != NULL )
state = 3;
else if( ( pKey = strstr ( str, "[GTT_ATTRIBUTE]" ) ) != NULL )
state = 4;
continue;
}
switch ( state )
{
case 0:
continue;
case 1:
if( strlen ( str ) < 8 )
continue;
ParseLocalNode ( str );
break;
case 2:
if( strlen ( str ) < 15 )
continue;
ParseRouteInfo ( str );
break;
case 3:
if( strlen ( str ) < 3 )
continue;
ParseRLSSN ( str );
break;
case 4:
ParseGTTAttributeOMC ( str );
break;
}
}
fclose ( fp );
//Load Related SPC===========>
RelatedSPCNum = 0;
for ( i = 0; i < RelatedSSNNum; i++ )
{
for ( j = 0; j < RelatedSPCNum && j < SCCP_RLSPC_NUM; j++ )
{
if( RelatedSPC[j].DPC == RelatedSSN[i].DPC && RelatedSPC[j].NetID == RelatedSSN[i].NetID )
continue;
RelatedSPC[RelatedSPCNum].DPC = RelatedSSN[i].DPC;
RelatedSPC[RelatedSPCNum].NetID = RelatedSSN[i].NetID;
RelatedSPC[RelatedSPCNum].status = 1;
RelatedSPCNum++;
}
}
return 1;
}
void sccp_saveparam ( )
{
struct in_addr addr;
SCCP_ROUTE *pRoute;
FILE *fp;
int i;
char str1[128], str2[64], host0[24], host1[24], *pCh = NULL;
char cNP[8], cTT[8];
if( ( fp = fopen ( SCCP_CONF_FILE, "w" ) ) == NULL )
return;
fprintf ( fp, "#SCCP Config file (R%dV%d_%02d)\r\n\r\n", SCCP_Param.version[0], SCCP_Param.version[1], SCCP_Param.version[2] );
fprintf ( fp, "[Local Node]\r\n\
#ssn NetID msisdn ip0 ip1\r\n" );
for ( i = 2; i < 256; i++ )
{
if( LocalSSN[i].status[0] == 0 && LocalSSN[i].status[1] == 0 )
continue;
if( LocalSSN[i].ip[0] > 0 && LocalSSN[i].ip[0] != 0xFFFFFFFF )
{
/* if (LocalSSN[i].ip[0] == SCCP_Param.ip)
{
sprintf(host0,"localhost");
}
else */
{
addr.s_addr = LocalSSN[i].ip[0];
strcpy ( host0, inet_ntoa ( addr ) );
}
}
else
strcpy ( host0, "-" );
if( LocalSSN[i].ip[1] > 0 && LocalSSN[i].ip[1] != 0xFFFFFFFF )
{
/* if (LocalSSN[i].ip[1] == SCCP_Param.ip)
{
sprintf(host1,"localhost");
}
else */
{
addr.s_addr = LocalSSN[i].ip[1];
strcpy ( host1, inet_ntoa ( addr ) );
}
}
else
strcpy ( host1, "-" );
Bcd2Str ( str1, LocalSSN[i].msisdn, LocalSSN[i].msisdn_len % MAX_DIGITS );
if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
*pCh = 0;
if( strlen ( str1 ) == 0 )
strcpy ( str1, "-" );
fprintf ( fp, "%-4d %-5d %-15s %-15s %-15s\r\n", i, LocalSSN[i].NetID, str1, host0, host1 );
}
fprintf ( fp, "[GTT_Table]\r\n" "#No EN NP TT StartDigits EndDigits NI SPC SSN RI AI S E N Rep\r\n" );
for ( i = 0; i < SCCP_ROUTE_NUM; i++ )
{
//Commented by Roy Jiang for the disabled GTT entries
// if( RouteList[i].avail == 0 )
// continue;
pRoute = &RouteList[i];
if( pRoute->len > 0 )
{
Bcd2Str ( str1, pRoute->StartDigits, pRoute->len % MAX_DIGITS );
if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
*pCh = 0;
Bcd2Str ( str2, pRoute->EndDigits, pRoute->len % MAX_DIGITS );
if( ( pCh = strchr ( str2, 'F' ) ) != NULL )
*pCh = 0;
}
else
{
strcpy ( str1, "-" );
strcpy ( str2, "-" );
}
if( pRoute->NP == 0 )
sprintf ( cNP, "-" );
else
sprintf ( cNP, "%d", pRoute->NP );
if( pRoute->TT == 0 )
sprintf ( cTT, "-" );
else
sprintf ( cTT, "%d", pRoute->TT );
fprintf ( fp, "%-3d %d %s %s %-15s %-15s %d %02X%02X%02X %d %d %d ", i, RouteList[i].avail, cNP, cTT, str1, str2, pRoute->NetID, pRoute->DPC[0], pRoute->DPC[1], pRoute->DPC[2], pRoute->SSN, pRoute->RI,
pRoute->AI );
if( pRoute->convert )
{
Bcd2Str ( str1, pRoute->ReplaceDigits, pRoute->replace_len % MAX_DIGITS );
if( ( pCh = strchr ( str1, 'F' ) ) != NULL )
*pCh = 0;
fprintf ( fp, "%-1d% -1d %-1d %-15s\r\n", pRoute->ReplaceStart, pRoute->ReplaceEnd, pRoute->OutNP, str1 );
}
else
fprintf ( fp, "\r\n" );
}
fprintf ( fp, "\r\n[RL_SSN]\r\n#NetID DPC SSN\r\n " );
for ( i = 0; i < RelatedSSNNum; i++ )
{
if( RelatedSSN[i].status == 0 )
continue;
fprintf ( fp, "%-5d 0x%-6X %-d\r\n", RelatedSSN[i].NetID, RelatedSSN[i].DPC, RelatedSSN[i].SSN );
}
fprintf ( fp, "\r\n[GTT_ATTRIBUTE]\r\nIdx\r\n " );
for ( i = 0; i < 256; i++ )
{
if( RouteList[i].avail == 0 )
continue;
Bcd2Str ( str1, GTTAttribute[i].attribute, SCCP_MAX_GTT_ATTRIBUTE * 2 );
fprintf ( fp, "%-3d %s\r\n", i, str1 );
}
fclose ( fp );
}
int sccp_setparam ( DWORD * oid, BYTE * pdata, WORD datalen )
{
SCCP_ROUTE *pRoute;
RL_SSN *pRLSSN;
LOCAL_SSN *pLocalSSN;
LOCAL_SSN OldLocalSSN;
u_short instance, i;
instance = oid[1];
switch ( oid[0] )
{
case 1:
spLogDebug ( SCCPDB_SNMP, "Set Local Node. ssn = %d", instance );
if( instance >= 256 )
return -1;
pLocalSSN = &LocalSSN[instance];
/* copy the old important parameter */
OldLocalSSN.NetID = pLocalSSN->NetID;
OldLocalSSN.ip[0] = pLocalSSN->ip[0];
OldLocalSSN.ip[1] = pLocalSSN->ip[1];
/* copy the old important parameter */
pLocalSSN->NetID = pdata[0];
memcpy ( &pLocalSSN->msisdn, pdata + 1, MAX_DIGITS );
memcpy ( &pLocalSSN->ip[0], pdata + MAX_DIGITS + 1, 8 );
LocalSSN[instance].msisdn_len = ( BcdLen ( LocalSSN[instance].msisdn, MAX_DIGITS ) + 1 ) / 2;
/* if old and new important parameter are same then return */
if( OldLocalSSN.NetID == pLocalSSN->NetID && OldLocalSSN.ip[0] == pLocalSSN->ip[0] && OldLocalSSN.ip[1] == pLocalSSN->ip[1] )
return 19;
/* if old and new important parameter are same then return */
LocalSSN[instance].local = 0;
LocalSSN[instance].status[0] = LocalSSN[instance].status[1] = 0;
if( LocalSSN[instance].ip[0] > 0 && LocalSSN[instance].ip[0] != 0xFFFFFFFF )
{
if( LocalSSN[instance].ip[0] == SCCP_Param.ip )
{
LocalSSN[instance].status[0] = 1;
LocalSSN[instance].local = 1;
}
else
{
LocalSSN[instance].status[0] = 3;
LocalSSN[instance].timeout[0] = T_hbrecv;
}
}
if( LocalSSN[instance].ip[1] > 0 && LocalSSN[instance].ip[1] != 0xFFFFFFFF )
{
if( LocalSSN[instance].ip[1] == SCCP_Param.ip )
{
LocalSSN[instance].status[1] = 1;
LocalSSN[instance].local = 2;
}
else
{
LocalSSN[instance].status[1] = 3;
LocalSSN[instance].timeout[1] = T_hbrecv;
}
}
SCCP_Param.T_reset = 100;
return 19;
case 2: //GTT Table
spLogDebug ( SCCPDB_SNMP, "Set GTT Table.instance=%d", instance );
if( instance >= SCCP_ROUTE_NUM )
return -1;
SCCP_Param.T_reset = 100; //2s
pRoute = &RouteList[instance];
memcpy ( pRoute, pdata, 43 );
pRoute->len = ( BcdLen ( pRoute->StartDigits, MAX_DIGITS ) + 1 ) / 2;
pRoute->replace_len = ( BcdLen ( pRoute->ReplaceDigits, MAX_DIGITS ) + 1 ) / 2;
if( pRoute->ReplaceStart >= 1 && pRoute->ReplaceStart <= pRoute->ReplaceEnd )
pRoute->convert = 1;
else
pRoute->convert = 0;
SCCP_Param.T_reset = 100;
return 43;
case 3:
spLogDebug ( SCCPDB_SNMP, "Set related subsystem.instance=%d", instance );
if( instance >= SCCP_RLSSN_NUM )
return -1;
pRLSSN = &RelatedSSN[instance];
if( pdata[0] > 0 )
{
pRLSSN->status = 1;
pRLSSN->NetID = pdata[1];
pRLSSN->DPC = pdata[2] * 0x10000 + pdata[3] * 0x100 + pdata[4];
pRLSSN->SSN = pdata[5];
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( RelatedSPC[i].DPC == pRLSSN->DPC && RelatedSPC[i].NetID == pRLSSN->NetID )
continue;
RelatedSPC[RelatedSPCNum].DPC = pRLSSN->DPC;
RelatedSPC[RelatedSPCNum].NetID = pRLSSN->NetID;
RelatedSPC[RelatedSPCNum].status = 1;
RelatedSPCNum++;
}
if( instance + 1 > RelatedSSNNum )
RelatedSSNNum = instance + 1;
}
else
{
pRLSSN->status = 0;
if( instance == RelatedSSNNum - 1 )
while ( RelatedSSN[RelatedSSNNum - 1].status == 0 && RelatedSSNNum > 0 )
RelatedSSNNum--;
}
return 6;
case 4: //GTT Attribute for omc
if( instance >= SCCP_ROUTE_NUM )
return -1;
memcpy ( &GTTAttribute[instance], pdata, SCCP_MAX_GTT_ATTRIBUTE );
return SCCP_MAX_GTT_ATTRIBUTE;
default:
break;
}
return -1;
}
int sccp_getparam ( DWORD * oid, BYTE * pdata, BYTE * vartype )
{
SCCP_ROUTE *pRoute;
RL_SSN *pRLSSN;
LOCAL_SSN *pLocalSSN;
int instance;
instance = oid[1];
switch ( oid[0] )
{
case 1:
spLogDebug ( SCCPDB_SNMP, "get Local Node.ssn=%ld\n", instance );
if( instance >= 256 )
return -1;
pLocalSSN = &LocalSSN[instance];
pdata[0] = pLocalSSN->NetID;
memcpy ( pdata + 1, &pLocalSSN->msisdn, MAX_DIGITS );
memcpy ( pdata + MAX_DIGITS + 1, &pLocalSSN->ip[0], 8 );
*vartype = 4;
return 19;
case 2: //GTT Table
spLogDebug ( SCCPDB_SNMP, "get gtt table.instance=%ld\n", instance );
if( instance >= SCCP_ROUTE_NUM )
return -1;
*vartype = 4;
pRoute = &RouteList[instance];
memcpy ( pdata, pRoute, 43 );
return 43;
case 3:
spLogDebug ( SCCPDB_SNMP, "Get related subsystem.instance=%d", instance );
if( instance > RelatedSSNNum )
return -1;
pRLSSN = &RelatedSSN[instance];
*vartype = 4;
if( pRLSSN->status == 0 )
return -1;
pdata[0] = 1;
pdata[1] = pRLSSN->NetID;
pdata[2] = ( pRLSSN->DPC >> 16 ) & 0xFF;
pdata[3] = ( pRLSSN->DPC >> 8 ) & 0xFF;
pdata[4] = pRLSSN->DPC & 0xFF;
pdata[5] = pRLSSN->SSN;
return 6;
case 4: //GTT Attribute
spLogDebug ( SCCPDB_SNMP, "get gtt attribute table.instance=%ld\n", instance );
if( instance >= SCCP_ROUTE_NUM )
return -1;
*vartype = 4;
memcpy ( pdata, &GTTAttribute[instance], SCCP_MAX_GTT_ATTRIBUTE );
return SCCP_MAX_GTT_ATTRIBUTE;
default:
break;
}
return -1;
}
/*+++++++++++++++++++++++++++++++++++++++ */
//Private function========================>
/*+++++++++++++++++++++++++++++++++++++++ */
int SccpGetLocalIP ( )
{
struct hostent *hptr;
struct in_addr *inaddr;
char hostname[40] = "\0";
if( ( gethostname ( hostname, -1 ) ) != 0 )
return -1;
if( ( hptr = gethostbyname ( hostname ) ) == NULL )
return -1;
if( hptr->h_addr_list[0] != NULL )
{
inaddr = ( struct in_addr * ) hptr->h_addr_list[0];
SCCP_Param.ip = inaddr->s_addr;
}
return 1;
}
int ParseLocalNode ( char *str )
{
char info[5][128];
int rtn;
BYTE ssn;
rtn = ParseLine ( str, info, 5 );
if( rtn < 3 )
{
spLogDebug ( SCCPDB_ERR, "<001>Invalid line in Local_Node Table, field count = %d", rtn );
return 0;
}
ssn = atoi ( info[0] );
LocalSSN[ssn].NetID = atoi ( info[1] ) % 4;
LocalSSN[ssn].msisdn_len = Str2Bcd ( LocalSSN[ssn].msisdn, info[2], MAX_DIGITS );
if( rtn < 4 || strstr ( info[3], "-" ) != NULL )
LocalSSN[ssn].ip[0] = 0xFFFFFFFF;
/* else if (strstr(info[3],"localhost") != NULL)
LocalSSN[ssn].ip[0] = SCCP_Param.ip; */
else
LocalSSN[ssn].ip[0] = inet_addr ( info[3] );
if( rtn < 5 || strstr ( info[4], "-" ) != NULL )
LocalSSN[ssn].ip[1] = 0xFFFFFFFF;
/* else if (strstr(info[4],"localhost") != NULL)
LocalSSN[ssn].ip[1] = SCCP_Param.ip; */
else
LocalSSN[ssn].ip[1] = inet_addr ( info[4] );
/* if (rtn >= 5)
LocalSSN[ssn].ANSIFlag = atoi(info[5]); */
LocalSSN[ssn].local = 0;
LocalSSN[ssn].status[0] = LocalSSN[ssn].status[1] = 0;
if( LocalSSN[ssn].ip[0] > 0 && LocalSSN[ssn].ip[0] != 0xFFFFFFFF )
{
if( LocalSSN[ssn].ip[0] == SCCP_Param.ip )
{
LocalSSN[ssn].status[0] = 1;
LocalSSN[ssn].local = 1;
}
else
{
LocalSSN[ssn].status[0] = 3;
LocalSSN[ssn].timeout[0] = T_hbrecv;
}
}
if( LocalSSN[ssn].ip[1] > 0 && LocalSSN[ssn].ip[1] != 0xFFFFFFFF )
{
if( LocalSSN[ssn].ip[1] == SCCP_Param.ip )
{
LocalSSN[ssn].status[1] = 1;
LocalSSN[ssn].local = 2;
}
else
{
LocalSSN[ssn].status[1] = 3;
LocalSSN[ssn].timeout[1] = T_hbrecv;
}
}
else
{
LocalSSN[ssn].status[1] = 0;
}
return 1;
}
void ParseRouteInfo ( char *str )
{
int spc;
char info[15][128];
u_short index, rtn;
BYTE offset = 0;
BYTE ConfVer; //configure file version
SCCP_ROUTE *pRoute;
rtn = ParseLine ( str, info, 15 );
if( rtn < 8 )
{
spLogDebug ( SCCPDB_ERR, "<002>Invalid line in GTT Table, field count = %d", rtn );
return;
}
if ( (rtn == 11 ) || ( rtn == 15 ) )
ConfVer = 3; //has EN
else if( ( rtn == 10 ) || ( rtn == 14 ) )
ConfVer = 2; //has TT and AI
else if( ( rtn == 9 ) || ( rtn == 13 ) )
ConfVer = 1; //has AI
else
ConfVer = 0; //without TT and AI
index = atoi ( info[offset++] ); //0
if( index >= SCCP_ROUTE_NUM )
{
spLogDebug ( SCCPDB_ERR, "<003>invalid index in GTT Table, index = %d", index );
return;
}
pRoute = &RouteList[index];
if ( ConfVer == 3 )
pRoute->avail = atoi ( info[offset++] ); //1
else
pRoute->avail = 1;
if( strstr ( info[offset], "-" ) != NULL ) //2
pRoute->NP = 0;
else
pRoute->NP = atoi ( info[offset] ); //2
offset++;
if( ConfVer >= 2 )
{
if( strstr ( info[offset], "-" ) != NULL ) //3
pRoute->TT = 0;
else
pRoute->TT = atoi ( info[offset] ); //3
offset++;
}
else
pRoute->TT = 0;
memset ( pRoute->StartDigits, 0xFF, MAX_DIGITS * 2 );
Str2Bcd ( pRoute->StartDigits, info[offset++], MAX_DIGITS ); //4
pRoute->len = Str2Bcd ( pRoute->EndDigits, info[offset++], MAX_DIGITS ); //5
pRoute->NetID = atoi ( info[offset++] ) % 4; //6
spc = strtol ( info[offset++], NULL, 16 ); //7
pRoute->DPC[0] = spc >> 16;
pRoute->DPC[1] = spc >> 8;
pRoute->DPC[2] = spc;
pRoute->SSN = atoi ( info[offset++] ); //8
pRoute->RI = atoi ( info[offset++] ); //9
/* daniel */
if( ConfVer > 0 )
pRoute->AI = atoi ( info[offset++] ) & 7; //10
else
pRoute->AI = 7;
if( rtn < 13 )
{
pRoute->convert = 0;
return;
}
/* daniel */
pRoute->ReplaceStart = atoi ( info[offset++] ); //11
pRoute->ReplaceEnd = atoi ( info[offset++] ); //12
pRoute->OutNP = atoi ( info[offset++] ); //13
if( pRoute->ReplaceStart < 1 || pRoute->ReplaceStart > pRoute->ReplaceEnd )
pRoute->convert = 0;
else
{
memset ( pRoute->ReplaceDigits, 0xFF, MAX_DIGITS );
pRoute->replace_len = Str2Bcd ( pRoute->ReplaceDigits, info[offset++], MAX_DIGITS ); //14
pRoute->convert = 1;
}
return;
}
void ParseRLSSN ( char *str )
{
RL_SSN *pRLSSN = NULL;
char info[3][128];
int rtn;
BYTE NetID;
int spc;
rtn = ParseLine ( str, info, 3 );
if( rtn < 3 )
{
spLogDebug ( SCCPDB_ERR, "<004>Invalid line in RL_SSN Table, field count = %d", rtn );
return;
}
pRLSSN = &RelatedSSN[RelatedSSNNum];
pRLSSN->status = 0;
NetID = pRLSSN->NetID = atoi ( info[0] ) % 4;
spc = pRLSSN->DPC = strtol ( info[1], NULL, 16 );
pRLSSN->SSN = atoi ( info[2] );
pRLSSN->SST = 1;
pRLSSN->timeout = T_sst;
if( SCCP_Param.spc[NetID] == spc )
return;
pRLSSN->status = ST_Disable;
RelatedSSNNum = ( RelatedSSNNum + 1 ) % SCCP_RLSSN_NUM;
}
static void ParseGTTAttributeOMC ( char *str )
{
GTTATT_OMC *pGTTAtt = NULL;
char info[3][128];
int rtn;
BYTE index;
rtn = ParseLine ( str, info, 3 );
if( rtn < 2 )
{
spLogDebug ( SCCPDB_ERR, "<004>Invalid line in GTT Attribute Table, field count = %d", rtn );
return;
}
index = atoi ( info[0] );
pGTTAtt = &GTTAttribute[index];
Str2Bcd ( pGTTAtt->attribute, info[1], SCCP_MAX_GTT_ATTRIBUTE * 2 );
}

615
plat/sccp/src/sclc.c Normal file
View File

@@ -0,0 +1,615 @@
/*******************************************/
/*Title: sclc.c */
/*Descr: SCCP Connectionless Control */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*******************************************/
#include "./include/sccp.h"
/*===========export================*/
int scrc2sclc ( Intra_Msg * pIntraMsg );
int sclc_rf ( Intra_Msg * pIntraMsg );
/* by simon at 23/9/26 */
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern LOCAL_SSN LocalSSN[256];
SCCP_SegMsgBuf sccp_segmsgbuf[MAX_SEGMSG_BUF];
extern struct sccp_msg_statistic
{
DWORD msg_mtp_scoc;
DWORD msg_scoc_up;
DWORD mnp_send;
DWORD mnp_route;
} sccpmsg_st;
extern SCCP_Capture_Buf SCCPCapBuf;
extern LOCAL_SSN LocalSSN[256];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern SCOC_BUF ScocBuf;
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern SCCP_OPT SCCP_Param;
extern u8 MNP_Flag[2];
/*===========import================*/
extern int sclc2scmg ( Intra_Msg * intramsg ); //scmg.c
extern int scrc_route ( Intra_Msg * pIntraMsg, BOOL ForceAnsi ); //scrc.c
extern int scrc_mnp_route ( Intra_Msg * pIntraMsg, BOOL ForceAnsi ); //scrc.c
extern int send_msg ( Intra_Msg * pIntraMsg ); //scrc.c
extern void spLogDebug ( DWORD mask, const char *fmt, ... );
extern void spShowBCD(DWORD mask, BYTE *buf, int len);
extern void spShowMsg(DWORD mask, const char *pDesc, Intra_Msg *pIntraMsg);
extern void spLog ( char *info );
static SCLC_BUF SCLC_OutBuf;
static SCLC_BUF SCLC_InBuf[MAX_SCLC_BUF];
/* buffer changed from 3 to 4, Pierre , 11-07 */
int RecvXUDTMsg ( Intra_Msg * pIntraMsg, BYTE nbuf );
int CheckSegUnID ( Intra_Msg * pIntraMsg );
int RsmRegMsg ( SCLC_MSG * pmsg, SCCP_SegMsgBuf * pSegMsgbuf, Intra_Msg * pIntraMsg );
extern void spLogSeg ( SCCP_SegMsgBuf * pSegMsgbuf );
int scrc2sclc ( Intra_Msg * pIntraMsg )
{
SCLC_MSG *pmsg;
short writesub, readsub;
BYTE nbuf;
SccpCsta[SccpCstaInd].utilization[4 - 3]++;
if( pIntraMsg->msgMNP )
{
nbuf = 1;
sccpmsg_st.mnp_route++;
if(pIntraMsg->msgsource == FROM_MTP)
{
pIntraMsg->SLS = LocalSSN[pIntraMsg->CDA.SSN].local+1;
}
} /* added by pierre for MNP , 2005-11-07 */
else
{
nbuf = LocalSSN[pIntraMsg->CDA.SSN].nbuf % 4;
}
switch ( pIntraMsg->msgtype )
{
case UDT_MSG:
break;
case XUDT_MSG:
switch ( RecvXUDTMsg ( pIntraMsg, nbuf ) )
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
return 0;
case LUDT_MSG:
spLogDebug ( SCCPDB_UDT | SCCPDB_ERR, "<005>LUDT/XUDT message is not supported" );
return 0;
case UDTS_MSG:
break;
case XUDTS_MSG:
case LUDTS_MSG:
spLogDebug ( SCCPDB_UDT | SCCPDB_ERR, "<005>LUDTS/XUDTS message is not supported" );
return 0;
}
if( pIntraMsg->CDA.SSN == SSN_SCMG )
return sclc2scmg ( pIntraMsg );
else
{
writesub = SCLC_InBuf[nbuf].writesub;
readsub = SCLC_InBuf[nbuf].readsub;
pmsg = &SCLC_InBuf[nbuf].msglist[writesub];
pmsg->msglen = pIntraMsg->msglen % SCCP_MSG_MAXLEN;
memcpy ( pmsg->msg, pIntraMsg->data, pmsg->msglen );
memcpy ( &( pmsg->src_addr ), &( pIntraMsg->CGA ), sizeof ( SCCP_ADDR ) );
memcpy ( &( pmsg->dst_addr ), &( pIntraMsg->CDA ), sizeof ( SCCP_ADDR ) );
pmsg->sls = pIntraMsg->SLS;
if( ( SCLC_InBuf[nbuf].writesub + 1 ) == SCLC_InBuf[nbuf].readsub )
spShowMsg ( SCCPDB_UDT, "USER <== SCCP: buf overflow!!!!!!!", pIntraMsg );
SCLC_InBuf[nbuf].writesub = ( writesub + 1 ) % SS_MSG_NUM;
if( SCLC_InBuf[nbuf].writesub == readsub )
SCLC_InBuf[nbuf].readsub = ( readsub + 1 ) % SS_MSG_NUM;
if (pIntraMsg->msgtype == UDTS_MSG)
{
pmsg->primitive = N_NOTICE_IND;
spShowMsg ( SCCPDB_UDT, "USER <== SCCP: N-NOTICE", pIntraMsg );
}
else
{
pmsg->primitive = N_UNITDATA_IND;
spShowMsg ( SCCPDB_UDT, "USER <== SCCP: UDT Message", pIntraMsg );
}
}
return 1;
}
int sclc_rf ( Intra_Msg * pIntraMsg )
{
SCCP_ADDR swapaddr;
spShowMsg ( SCCPDB_UDT | SCCPDB_ERR, "<006>Route Failure", pIntraMsg );
switch ( pIntraMsg->msgtype )
{
case UDT_MSG:
if( pIntraMsg->msgsource == FROM_MTP || pIntraMsg->msgsource == FROM_SCLC )
{
memcpy ( &swapaddr, &( pIntraMsg->CDA ), sizeof ( SCCP_ADDR ) );
memcpy ( &( pIntraMsg->CDA ), &( pIntraMsg->CGA ), sizeof ( SCCP_ADDR ) );
memcpy ( &( pIntraMsg->CGA ), &swapaddr, sizeof ( SCCP_ADDR ) );
pIntraMsg->CDA.ip = 0xFFFFFFFF;
if( pIntraMsg->CDA.RI == RI_SSN )
{
if( pIntraMsg->CDA.DPC == 0 )
pIntraMsg->CDA.DPC = pIntraMsg->CGA.DPC;
}
pIntraMsg->msgsource = FROM_SCLC;
pIntraMsg->msgtype = UDTS_MSG;
return scrc_route ( pIntraMsg, 0 );
}
break;
case XUDT_MSG:
case LUDT_MSG:
//unsupported now
break;
case UDTS_MSG:
break;
case XUDTS_MSG:
case LUDTS_MSG:
//unsupported now
break;
}
return -1;
}
int scmg2sclc ( Intra_Msg * pIntraMsg )
{
return scrc_route ( pIntraMsg, 0 );
}
/******************************************************************/
/*================== User Interface-----> ================*/
/******************************************************************/
int sclc_send ( SCLC_MSG * pmsg )
{
if( pmsg->msglen > 256 )
{
spLogDebug ( SCCPDB_ERR | SCCPDB_UDT, "<007>User ==> SCCP: Message's Length exceed 256" );
spShowBCD ( SCCPDB_ERR, pmsg->msg, pmsg->msglen % 256 );
return 0;
}
SccpCsta[SccpCstaInd].utilization[0]++;
memcpy ( &SCLC_OutBuf.msglist[SCLC_OutBuf.writesub], pmsg, sizeof ( SCLC_MSG ) );
SCLC_OutBuf.writesub = ( SCLC_OutBuf.writesub + 1 ) % SS_MSG_NUM;
if( SCLC_OutBuf.writesub == SCLC_OutBuf.readsub )
{
spLogDebug ( SCCPDB_ERR | SCCPDB_UDT, "<008>SCLC Out Buffer Overflow" );
SCLC_OutBuf.readsub = ( SCLC_OutBuf.readsub + 1 ) % SS_MSG_NUM;
}
return 1;
}
int sclc_receive ( SCLC_MSG * pmsg, BYTE usertype )
{
short readsub;
usertype %= MAX_SCLC_BUF; /* revised by pierre */
readsub = SCLC_InBuf[usertype].readsub % SS_MSG_NUM;
if( SCLC_InBuf[usertype].writesub == readsub )
return 0;
memcpy ( pmsg, &SCLC_InBuf[usertype].msglist[readsub], sizeof ( SCLC_MSG ) );
SCLC_InBuf[usertype].readsub = ( readsub + 1 ) % SS_MSG_NUM;
return 1;
}
void sclc_timer ( )
{
Intra_Msg outmsg;
SCLC_MSG *pmsg;
int loop = 128;
short readsub;
int SegMsgIndex;
for ( SegMsgIndex = 0; SegMsgIndex < MAX_SEGMSG_BUF; SegMsgIndex++ )
{
if( sccp_segmsgbuf[SegMsgIndex].SegMsgTimer && sccp_segmsgbuf[SegMsgIndex].SegMsgTimer++ > MAX_SEGMSG_TIMER )
{
spLogDebug ( SCCPDB_ERR, "SCCP XUDT Msg Timer Out. " );
spLogSeg ( &sccp_segmsgbuf[SegMsgIndex] );
memset ( &sccp_segmsgbuf[SegMsgIndex], 0, sizeof ( SCCP_SegMsgBuf ) );
}
}
while ( loop-- > 0 )
{
if( SCLC_OutBuf.readsub == SCLC_OutBuf.writesub )
return;
readsub = SCLC_OutBuf.readsub % SS_MSG_NUM;
pmsg = &SCLC_OutBuf.msglist[readsub];
SCLC_OutBuf.readsub = ( readsub + 1 ) % SS_MSG_NUM;
outmsg.msgsource = FROM_SCLC;
outmsg.msgtype = UDT_MSG;
outmsg.msgclass = 0;
outmsg.SLS = pmsg->sls;
outmsg.sequenceFlag = pmsg->sequence_control;
memcpy ( &( outmsg.CDA ), &pmsg->dst_addr, sizeof ( SCCP_ADDR ) );
memcpy ( &( outmsg.CGA ), &pmsg->src_addr, sizeof ( SCCP_ADDR ) );
outmsg.NetID = outmsg.CGA.NetID = outmsg.CDA.NetID;
// outmsg.CDA.TT = 0;
outmsg.CDA.ip = 0xFFFFFFFF;
outmsg.msglen = pmsg->msglen % 256;
memcpy ( outmsg.data, pmsg->msg, pmsg->msglen % 256 );
if( MNP_Flag[0] != 0 && outmsg.CDA.NP == 1 && outmsg.CDA.SSN == 6 && pmsg->msg[0] == 0x62 )
{
/* MNP supported */
if( MNP_Flag[1] != 2 ) /* Direct routing */
{
if( MNP_Flag[0] == 1 && outmsg.CDA.TT != 0 )
{
/* IN_based call related message */
spLogDebug ( SCCPDB_UDT, "User ==> SCCP: IN_based MNP and Call_related message, routed to HLR" );
//spShowMsg(SCCPDB_USER, "User ==> SCCP: UDT Message", &outmsg);
//scrc_route(&outmsg);
}
else if( outmsg.CGA.SSN != 10 )
{
spShowMsg ( SCCPDB_USER, "User ==> SCCP ==> MNP_SRF : UDT Message", &outmsg );
outmsg.msgMNP = 1;
scrc2sclc ( &outmsg );
continue;
}
}
}
spShowMsg ( SCCPDB_USER, "User ==> SCCP: UDT Message", &outmsg );
scrc_route ( &outmsg, 0 );
}
return;
}
/* added by Pierre for MNP, 2005-11-07 */
int sclc_mnp_send ( SCLC_MSG * pmsg )
{
Intra_Msg outmsg;
if( pmsg->msglen > 256 )
{
spLogDebug ( SCCPDB_ERR | SCCPDB_UDT, "<007>User ==> SCCP: Message's Length exceed 256" );
spShowBCD ( SCCPDB_ERR, pmsg->msg, pmsg->msglen % 256 );
return 0;
}
SccpCsta[SccpCstaInd].utilization[0]++;
sccpmsg_st.mnp_send++;
outmsg.msgsource = FROM_SCLC;
outmsg.msgtype = UDT_MSG;
outmsg.msgclass = 0;
outmsg.SLS = pmsg->sls;
memcpy ( &( outmsg.CDA ), &pmsg->dst_addr, sizeof ( SCCP_ADDR ) );
memcpy ( &( outmsg.CGA ), &pmsg->src_addr, sizeof ( SCCP_ADDR ) );
outmsg.NetID = outmsg.CGA.NetID = outmsg.CDA.NetID;
//outmsg.CDA.TT = 0;
outmsg.CDA.ip = 0xFFFFFFFF;
outmsg.msglen = pmsg->msglen % 256;
memcpy ( outmsg.data, pmsg->msg, pmsg->msglen % 256 );
spShowMsg ( SCCPDB_USER, "User ==> SCCP: UDT Message", &outmsg );
return scrc_mnp_route ( &outmsg, 0 );
}
//add for UDT SegmentingMsg to XUDT --lw 2007/03/20
int SegmentingMsg ( Intra_Msg * pIntraMsg )
{
Intra_Msg pIntraMsgSeg1, pIntraMsgSeg2;
int ret1, ret2;
BYTE sSegLR[4];
ret1 = ret2 = 0;
memcpy ( &pIntraMsgSeg1, pIntraMsg, sizeof ( Intra_Msg ) );
memcpy ( &pIntraMsgSeg2, pIntraMsg, sizeof ( Intra_Msg ) );
pIntraMsgSeg1.msglen = pIntraMsg->msglen / 2;
pIntraMsgSeg2.msglen = pIntraMsg->msglen - pIntraMsgSeg1.msglen;
memset ( &pIntraMsgSeg1.data[pIntraMsgSeg1.msglen], 0, SCCP_MSG_MAXLEN - pIntraMsgSeg1.msglen );
memcpy ( &pIntraMsgSeg2.data[0], &pIntraMsg->data[pIntraMsgSeg1.msglen], pIntraMsgSeg2.msglen );
memset ( &pIntraMsgSeg2.data[pIntraMsgSeg2.msglen], 0, SCCP_MSG_MAXLEN - pIntraMsgSeg2.msglen );
pIntraMsgSeg1.msgtype = pIntraMsgSeg2.msgtype = XUDT_MSG;
pIntraMsgSeg1.SegPresent = pIntraMsgSeg2.SegPresent = 1;
pIntraMsgSeg1.Segmnt.CBit = pIntraMsgSeg2.Segmnt.CBit = 1; //sequence
pIntraMsgSeg1.Segmnt.FBit = 1;
pIntraMsgSeg2.Segmnt.FBit = 0;
pIntraMsgSeg1.Segmnt.RSBits = 1;
pIntraMsgSeg2.Segmnt.RSBits = 0;
pIntraMsgSeg1.Hop = pIntraMsgSeg1.Hop = 0;
sSegLR[0] = ( SCCP_Param.ip >> 16 ) & 0x0001; //plant number
sSegLR[1] = pIntraMsg->SLS;
sSegLR[2] = SCCPCapBuf.watch_dog[128]++;
memcpy ( pIntraMsgSeg1.Segmnt.SegLR, sSegLR, SEG_RS_LEN );
memcpy ( pIntraMsgSeg2.Segmnt.SegLR, sSegLR, SEG_RS_LEN );
spLogDebug ( SCCPDB_UDT, "SCCP =>SCCP_RegProc=> SCCP : Length [%d Bytes] [%d Bytes]\r\n", pIntraMsgSeg1.msglen, pIntraMsgSeg2.msglen );
ret1 = send_msg ( &pIntraMsgSeg1 );
ret2 = send_msg ( &pIntraMsgSeg2 );
return ( ret1 > 0 && ret2 > 0 );
}
int RecvXUDTMsg ( Intra_Msg * pIntraMsg, BYTE nbuf )
{
SCLC_MSG *pmsg;
short writesub, readsub;
int SegMsgIndex;
if( !pIntraMsg->SegPresent ) //Not Include Segmentation Paramenters
{
return -1;
}
if( pIntraMsg->Segmnt.FBit == 1 && pIntraMsg->Segmnt.RSBits == 0 ) //Single Segmetaion
{
return -1;
}
SegMsgIndex = CheckSegUnID ( pIntraMsg );
if( SegMsgIndex == MAX_SEGMSG_BUF + 1 ) //check CGA SLR MTP3 routing lable is idle
{
return 0;
}
else if( SegMsgIndex == MAX_SEGMSG_BUF ) //first Segmentation
{
if( pIntraMsg->Segmnt.FBit != 1 )
{
spLogDebug ( SCCPDB_ERR, "SCCP Recv new XUDT Msg but the Fbit is not 1." );
return 0;
}
for ( SegMsgIndex = 0; SegMsgIndex < MAX_SEGMSG_BUF; SegMsgIndex++ )
{
if( sccp_segmsgbuf[SegMsgIndex].MsgState == SEGSTREAM_IDLE )
{
int SegBlockIndex;
SCCP_SegStream *pSegStream;
SCCP_SegMsgBuf *pSegMsgbuf = &sccp_segmsgbuf[SegMsgIndex];
pSegMsgbuf->MsgClass = pIntraMsg->Segmnt.CBit;
pSegMsgbuf->MsgTotal = pIntraMsg->Segmnt.RSBits + 1;
pSegMsgbuf->RSE = pIntraMsg->Segmnt.RSBits - 1;
pSegMsgbuf->SegID.DPC = pIntraMsg->DPC;
pSegMsgbuf->SegID.OPC = pIntraMsg->OPC;
pSegMsgbuf->SegID.SLS = pIntraMsg->SLS;
memcpy ( &pSegMsgbuf->SegID.CGA, &pIntraMsg->CGA, sizeof ( SCCP_ADDR ) );
memcpy ( &pSegMsgbuf->SegID.SegLR, &pIntraMsg->Segmnt.SegLR, SEG_RS_LEN );
SegBlockIndex = pSegMsgbuf->MsgTotal - ( pIntraMsg->Segmnt.RSBits + 1 );
pSegStream = &pSegMsgbuf->SegStream[SegBlockIndex];
pSegStream->SegDataLen = pIntraMsg->msglen;
memcpy ( &pSegStream->SegDataBlock, &pIntraMsg->data, pIntraMsg->msglen );
pSegMsgbuf->SegMsgTimer = 1;
pSegMsgbuf->MsgState = SEGSTREAM_BUSY;
return 1;
}
}
if( SegMsgIndex == MAX_SEGMSG_BUF )
{
spLogDebug ( SCCPDB_ERR, "SCCP Recv new XUDT but SCCP SegMsg buf is not enough" );
return 0;
}
}
else //not first Segmentation
{
int SegBlockIndex;
int i, j, linemax;
char info[2560 * 3 + 512], temp_str[128];
SCCP_SegStream *pSegStream;
SCCP_SegMsgBuf *pSegMsgbuf = &sccp_segmsgbuf[SegMsgIndex];
if( pIntraMsg->Segmnt.RSBits != pSegMsgbuf->RSE )
{
spLogDebug ( SCCPDB_ERR, "SCCP Recv unexpect RS XUDT Msg , discard it" );
return 0;
}
if( pIntraMsg->Segmnt.FBit == 1 )
{
spLogDebug ( SCCPDB_ERR, "SCCP Recv XUDT Msg dupulicate first segment. discard it" );
return 0;
}
SegBlockIndex = pSegMsgbuf->MsgTotal - ( pIntraMsg->Segmnt.RSBits + 1 );
pSegStream = &pSegMsgbuf->SegStream[SegBlockIndex];
if( pSegStream->SegDataLen )
{
spLogDebug ( SCCPDB_ERR, "SCCP Recv XUDT Msg dupulicate segment, discard it[RS :%d]", pIntraMsg->Segmnt.RSBits );
return 0;
}
pSegStream->SegDataLen = pIntraMsg->msglen;
memcpy ( &pSegStream->SegDataBlock, &pIntraMsg->data, pIntraMsg->msglen );
if( pSegMsgbuf->RSE )
{
pSegMsgbuf->RSE--;
return 1;
}
//last segment
pSegMsgbuf->SegMsgTimer = 0;
writesub = SCLC_InBuf[nbuf].writesub;
readsub = SCLC_InBuf[nbuf].readsub;
pmsg = &SCLC_InBuf[nbuf].msglist[writesub];
if( !RsmRegMsg ( pmsg, pSegMsgbuf, pIntraMsg ) )
{
return 0;
}
if( ( SCLC_InBuf[nbuf].writesub + 1 ) == SCLC_InBuf[nbuf].readsub )
spShowMsg ( SCCPDB_UDT, "USER <== SCCP: buf overflow!!!!!!!", pIntraMsg );
SCLC_InBuf[nbuf].writesub = ( writesub + 1 ) % SS_MSG_NUM;
if( SCLC_InBuf[nbuf].writesub == readsub )
SCLC_InBuf[nbuf].readsub = ( readsub + 1 ) % SS_MSG_NUM;
spLog ( "\r\n\r\nUser <== SCCP_RegProc. XUDT Message" );
spLogSeg ( pSegMsgbuf );
info[0] = '\0';
sprintf ( temp_str, "Segmentaion Length info: \r\n" );
strcat ( info, temp_str );
for ( i = 0; i < pSegMsgbuf->MsgTotal; i++ )
{
sprintf ( temp_str, "[%02d]:%d ", i, pSegMsgbuf->SegStream[i].SegDataLen );
strcat ( info, temp_str );
if( i == 7 )
{
strcat ( info, "\r\n" );
}
}
spLog ( info );
memset ( info, 0, 2560 * 3 + 512 );
i = j = linemax = 0;
while ( i * 16 < pmsg->msglen )
{
if( ( linemax = pmsg->msglen - 16 * i ) > 16 )
linemax = 16;
for ( j = 0; j < linemax; j++ )
{
sprintf ( info + 3 * j + ( j > 7 ? 1 : 0 ), "%02X ", pmsg->msg[16 * i + j] );
if( j == 7 )
{
sprintf ( info + 3 * 8, " " );
}
}
spLog ( info );
i++;
}
memset ( pSegMsgbuf, 0, sizeof ( SCCP_SegMsgBuf ) );
return 1;
}
return 0;
}
int CheckSegUnID ( Intra_Msg * pIntraMsg )
{
int SegMsgIndex, nCheckFlag;
SCCP_SegUnID *pSegId;
nCheckFlag = 0;
for ( SegMsgIndex = 0; SegMsgIndex < MAX_SEGMSG_BUF; SegMsgIndex++ )
{
pSegId = &sccp_segmsgbuf[SegMsgIndex].SegID;
if( memcmp ( &pSegId->SegLR, &pIntraMsg->Segmnt.SegLR, SEG_RS_LEN ) )
{
continue;
}
if( pSegId->DPC != pIntraMsg->DPC ) //have routed , equal of course
{
spLogDebug ( SCCPDB_ERR, "SCCP XUDT Msg check MTP3 routing lable fail , DPC is not matched!" );
nCheckFlag = 1;;
}
if( pSegId->OPC != pIntraMsg->OPC )
{
spLogDebug ( SCCPDB_ERR, "SCCP XUDT Msg check MTP3 routing lable fail , OPC is not matched!" );
nCheckFlag = 1;
}
if( pSegId->SLS != pIntraMsg->SLS )
{
spLogDebug ( SCCPDB_ERR, "SCCP XUDT Msg check MTP3 routing lable fail , SLS is not matched!" );
nCheckFlag = 1;
}
if( memcmp ( &pSegId->CGA, &pIntraMsg->CGA, sizeof ( SCCP_ADDR ) ) )
{
spLogDebug ( SCCPDB_ERR, "SCCP XUDT Msg check MTP3 routing lable fail , CGA is not matched!" );
nCheckFlag = 1;
}
if( nCheckFlag ) //act as a new segmention start
{
if( pIntraMsg->Segmnt.FBit == 1 && pIntraMsg->Segmnt.RSBits != 0 )
{
return MAX_SEGMSG_BUF;
}
return MAX_SEGMSG_BUF + 1;
}
return SegMsgIndex;
}
return SegMsgIndex;
}
int RsmRegMsg ( SCLC_MSG * pmsg, SCCP_SegMsgBuf * pSegMsgbuf, Intra_Msg * pIntraMsg )
{
int SegBlockIndex, XUDTMsgLen;
SCCP_SegStream *pSegStream;
XUDTMsgLen = 0;
for ( SegBlockIndex = 0; SegBlockIndex < pSegMsgbuf->MsgTotal; SegBlockIndex++ )
{
pSegStream = &pSegMsgbuf->SegStream[SegBlockIndex];
XUDTMsgLen += pSegStream->SegDataLen;
}
if( XUDTMsgLen > MAX_SCLCMSG_LEN )
{
spLogDebug ( SCCPDB_ERR, "SCCP Reassemble XUDT Msg is too long ,discard it" );
return 0;
}
XUDTMsgLen = 0;
for ( SegBlockIndex = 0; SegBlockIndex < pSegMsgbuf->MsgTotal; SegBlockIndex++ )
{
pSegStream = &pSegMsgbuf->SegStream[SegBlockIndex];
memcpy ( pmsg->msg + XUDTMsgLen, pSegStream->SegDataBlock, pSegStream->SegDataLen );
XUDTMsgLen += pSegStream->SegDataLen;
}
pmsg->msglen = XUDTMsgLen;
memcpy ( &( pmsg->src_addr ), &( pIntraMsg->CGA ), sizeof ( SCCP_ADDR ) );
memcpy ( &( pmsg->dst_addr ), &( pIntraMsg->CDA ), sizeof ( SCCP_ADDR ) );
return 1;
}

560
plat/sccp/src/scmg.c Normal file
View File

@@ -0,0 +1,560 @@
/************************************************************/
/*Title: scmg.c */
/*Descr: SCCP Management */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2002-5-7 */
/************************************************************/
#include "./include/sccp.h"
/*===========export================*/
void localssn_timer ( );
void sst_timer ( );
int sclc2scmg ( Intra_Msg * intramsg );
BOOL CheckAvail ( SCCP_ADDR * addr );
/*===========import================*/
extern int scrc_route ( Intra_Msg * pIntraMsg, BOOL ForceAnsi );
extern int send_msg ( Intra_Msg * pIntraMsg, BYTE ansi_flag );
extern void sccp_sethb ( );
extern int CollectLocalInfo ( );
extern int AddToIpList ( DWORD ip, BYTE ssn );
extern void snmpLogInfo ( char *logInfo );
extern void spLogDebug ( DWORD mask, const char *fmt, ... );
/*===========private================*/
static BYTE ssn_status ( int spc, BYTE ssn, BYTE NetID );
void spac ( int spc, BYTE NetID );
void sppc ( int spc, BYTE NetID );
void spcc ( int spc, BYTE NetID );
static void ssac ( int spc, BYTE ssn, BYTE NetID, BOOL relay );
static void sscc ( int spc, BYTE ssn, BYTE NetID );
static void sspc ( int spc, BYTE ssn, BYTE NetID, BOOL relay );
static void lcst ( int spc, BYTE ssn, BYTE ntype, BYTE NetID );
static void bcst ( BYTE ssn, BYTE ntype );
static void bcst_relay ( int spc, BYTE ssn, BYTE ntype, BYTE NetID );
static int build_scmgmsg ( BYTE * intramsg, BYTE type, int spc, BYTE ssn, BYTE NetID );
static int parse_scmgmsg ( BYTE * data, BYTE * type, int *spc, BYTE * ssn, BYTE NetID );
/* by simon at 23/9/25 */
extern DWORD ExistIP[64];
extern DWORD ExistIPNum;
extern SCOC_BUF ScocBuf;
extern LOCAL_SSN LocalSSN[256];
extern u8 ExistSSN[64];
extern u8 ExistSSNNum;
extern struct _dpc2sls
{
int dpc;
u8 sls;
} dpc2sls[256]; // used for sequence control, add by Roy Jiang, 2007-09-17
extern SCCP_OPT SCCP_Param;
extern u8 MNP_Flag[2];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern int RelatedSPCNum;
extern RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
extern GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern SCCP_Capture_Buf SCCPCapBuf;
void localssn_timer ( ) //called per 1s
{
int i;
LOCAL_SSN *pSSN;
for ( i = 0; i < ExistSSNNum; i++ )
{
pSSN = &LocalSSN[ExistSSN[i]];
if( pSSN->status[0] == ST_Enable && pSSN->local != 1 && pSSN->timeout[0]-- <= 0 )
pSSN->status[0] = ST_Disable;
if( pSSN->status[1] == ST_Enable && pSSN->local != 2 && pSSN->timeout[1]-- <= 0 )
pSSN->status[1] = ST_Disable;
}
}
int sclc2scmg ( Intra_Msg * intramsg )
{
BYTE *pmsg;
BYTE ntype, ssn;
int spc;
BOOL relay = 0;
intramsg->msgsource = FROM_SCMG;
pmsg = intramsg->data;
parse_scmgmsg ( intramsg->data, &ntype, &spc, &ssn, intramsg->NetID );
snmpLogInfo ( "sclc2scmg (): start..." );
spLogDebug ( SCCPDB_SCMG, "Receive %s Message.ssn=%d,src_spc=%X", ntype == SSA_MSG ? "SSA" : ( ntype == SSP_MSG ? "SSP" : ( ntype == SST_MSG ? "SST" : "SCMG" ) ), ssn, spc );
switch ( ntype )
{
case SSA_MSG:
//to enable subsystem
SccpCsta[SccpCstaInd].avail[11]++;
if( intramsg->OPC != SCCP_Param.spc[intramsg->NetID] && intramsg->CGA.DPC != SCCP_Param.spc[intramsg->NetID] )
{
lcst ( spc, ssn, SSA_MSG, intramsg->NetID );
if( spc == intramsg->CGA.DPC )
relay = 1;
}
ssac ( spc, ssn, intramsg->NetID, relay );
break;
case SSC_MSG:
SccpCsta[SccpCstaInd].avail[7]++;
sscc ( spc, ssn, intramsg->NetID );
break;
case SSP_MSG:
SccpCsta[SccpCstaInd].avail[10]++;
if( intramsg->OPC != SCCP_Param.spc[intramsg->NetID] && intramsg->CGA.DPC != SCCP_Param.spc[intramsg->NetID] )
{
lcst ( spc, ssn, SSP_MSG, intramsg->NetID );
if( spc == intramsg->CGA.DPC )
relay = 1;
}
sspc ( spc, ssn, intramsg->NetID, relay );
break;
case SST_MSG:
if( LocalSSN[ssn].status[0] == ST_Enable || LocalSSN[ssn].status[1] == ST_Enable )
pmsg[0] = SSA_MSG;
else
return 1;
memcpy ( &intramsg->CDA, &intramsg->CGA, sizeof ( SCCP_ADDR ) );
intramsg->CGA.DPC = SCCP_Param.spc[intramsg->NetID];
intramsg->CGA.GTI = 0;
intramsg->CGA.SSN = 1;
intramsg->CGA.RI = RI_SSN;
intramsg->CGA.len = 0;
spLogDebug ( SCCPDB_SCMG, "Send %s Message.ssn=%d,dst_spc=%X", ( pmsg[0] == SSA_MSG ) ? "SSA" : ( ( pmsg[0] == SSP_MSG ) ? "SSP" : "SSC" ), ssn, intramsg->CDA.DPC );
send_msg ( intramsg, mtp3_ansiFlag ( intramsg->NetID ) );
break;
case SOR_MSG:
//to send SOG
pmsg[0] = SOG_MSG; //to send SOG
memcpy ( &intramsg->CDA, &intramsg->CGA, sizeof ( SCCP_ADDR ) );
scrc_route ( intramsg, 0 );
break;
case SOG_MSG:
//to disable local subsystem
break;
}
snmpLogInfo ( "sclc2scmg (): end..." );
return 1;
}
BOOL CheckAvail ( SCCP_ADDR * addr )
{
BYTE status;
status = ssn_status ( addr->DPC, addr->SSN, addr->NetID );
if( status == ST_Disable )
{
spLogDebug ( SCCPDB_ERR, "<009>Subsystem Failure.NetID=%d,SPC=%x,SSN=%d", addr->NetID, addr->DPC, addr->SSN );
SccpCsta[SccpCstaInd].error[4]++;
return 0;
}
else if( status == ST_Congest )
{
spLogDebug ( SCCPDB_ERR, "<010>Subsystem Congest.NetID=%d,SPC=%x,SSN=%d", addr->NetID, addr->DPC, addr->SSN );
SccpCsta[SccpCstaInd].error[5]++;
return 0;
}
//else if(sccp_status(addr->DPC,addr->NetID)==ST_Disable)
// return 0;
else
return 1;
}
BYTE ssn_status ( int spc, BYTE ssn, BYTE NetID )
//related subsystem
{
int i;
for ( i = 0; i < RelatedSSNNum; i++ )
{
if( RelatedSSN[i].status == 0 )
continue;
if( RelatedSSN[i].DPC != spc || RelatedSSN[i].SSN != ssn || RelatedSSN[i].NetID != NetID )
continue;
return RelatedSSN[i].status;
}
return ST_Enable;
}
/////////////////////////
/*SPAC Module----------> */
/////////////////////////
void spac ( int spc, BYTE NetID )
{
int i, j;
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( spc == RelatedSPC[i].DPC && NetID == RelatedSPC[i].NetID )
{
RelatedSPC[i].status = ST_Enable;
for ( j = 0; j < RelatedSSNNum; j++ )
{
if( RelatedSSN[j].status == 0 )
continue;
if( spc == RelatedSSN[j].DPC && NetID == RelatedSSN[j].NetID )
{
if( RelatedSPC[i].status == ST_Disable )
RelatedSSN[j].SST = 1;
RelatedSSN[j].status = ST_Enable;
}
}
}
}
}
/////////////////////////
/*SPPC Module----------> */
/////////////////////////
void sppc ( int spc, BYTE NetID )
{
int i, j;
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( spc == RelatedSPC[i].DPC && NetID == RelatedSPC[i].NetID )
{
RelatedSPC[i].status = ST_Disable;
for ( j = 0; j < RelatedSSNNum; j++ )
{
if( RelatedSSN[j].status == 0 )
continue;
if( spc == RelatedSSN[j].DPC && NetID == RelatedSSN[j].NetID )
{
RelatedSSN[j].SST = 0;
RelatedSSN[j].status = ST_Disable;
}
}
}
}
}
/////////////////////////
/*SPCC Module----------> */
/////////////////////////
void spcc ( int spc, BYTE NetID )
{
int i;
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( spc == RelatedSSN[i].DPC && NetID == RelatedSSN[i].NetID )
RelatedSSN[i].status = ST_Congest;
}
}
/////////////////////////
/*SSAC Module----------> */
/////////////////////////
int register_ssn ( BYTE ssn, BYTE usertype ) //enable local subsystem
{
BYTE localindex = LocalSSN[ssn].local % 3;
LocalSSN[ssn].RegFlag = 1;
if( localindex > 0 )
{
CollectLocalInfo ( );
LocalSSN[ssn].status[localindex - 1] = ST_Enable;
}
else
{
printf ( "Subsystem %d not equiped.check your GTT Table.\n", ssn );
return 0;
}
if( usertype == 3 )
SCCP_Param.CO_SSN = ssn;
SccpCsta[SccpCstaInd].avail[8]++;
LocalSSN[ssn].nbuf = usertype % 4;
if( LocalSSN[ssn].nbuf == 3 )
SCCP_Param.CO_SSN = ssn;
bcst ( ssn, SSA_MSG );
return 1;
}
void ssac ( int spc, BYTE ssn, BYTE NetID, BOOL relay ) //enable remote subsystem
{
int i;
for ( i = 0; i < RelatedSSNNum; i++ )
{
if( RelatedSSN[i].status == 0 )
continue;
if( RelatedSSN[i].DPC != spc || RelatedSSN[i].SSN != ssn || RelatedSSN[i].NetID != NetID )
continue;
if( RelatedSSN[i].status == ST_Disable && relay ) //Disable->Enable
bcst_relay ( spc, ssn, SSA_MSG, NetID );
RelatedSSN[i].SST = 0;
RelatedSSN[i].status = ST_Enable;
}
}
void sscc ( int spc, BYTE ssn, BYTE NetID ) //enable remote subsystem
{
int i;
for ( i = 0; i < RelatedSSNNum; i++ )
{
if( RelatedSSN[i].status == 0 )
continue;
if( RelatedSSN[i].DPC != spc || RelatedSSN[i].SSN != ssn || RelatedSSN[i].NetID != NetID )
continue;
RelatedSSN[i].status = ST_Congest;
}
}
/////////////////////////
/*SSPC Module----------> */
/////////////////////////
int stop_ssn ( BYTE ssn ) //disable local subsystem
{
BYTE localindex = LocalSSN[ssn].local % 3;
int i;
LocalSSN[ssn].RegFlag = 0;
spLogDebug ( SCCPDB_SCMG, "Disable local subsystem. ssn=%d", ssn );
if( localindex > 0 )
{
CollectLocalInfo ( );
/* add by daniel on 2005-9-15 */
for ( i = 0; i <= 1; i++ )
{
if( SCCP_Param.OMCIP[i] > 0 )
AddToIpList ( SCCP_Param.OMCIP[i], ssn );
}
/* add by daniel on 2005-9-15 */
LocalSSN[ssn].status[localindex - 1] = ST_Disable;
}
else
return -1;
sccp_sethb ( );
SccpCsta[SccpCstaInd].avail[9]++;
bcst ( ssn, SSP_MSG );
return 1;
}
void sspc ( int spc, BYTE ssn, BYTE NetID, BOOL relay ) //disable remote subsystem
{
int i;
for ( i = 0; i < RelatedSSNNum; i++ )
{
if( RelatedSSN[i].status == 0 )
continue;
if( RelatedSSN[i].DPC != spc || RelatedSSN[i].SSN != ssn || RelatedSSN[i].NetID != NetID )
continue;
if( RelatedSSN[i].status == ST_Enable ) //Enable->Disable
{
RelatedSSN[i].timeout = T_sst;
RelatedSSN[i].SST = 1;
if( relay )
bcst_relay ( spc, ssn, SSP_MSG, NetID );
}
RelatedSSN[i].status = ST_Disable;
}
}
/////////////////////////
/*SSTC Module----------> */
/////////////////////////
void sst_timer ( )
{
Intra_Msg outmsg;
RL_SSN *pSSN;
int i;
for ( i = 0; i < RelatedSSNNum; i++ )
{
pSSN = &RelatedSSN[i];
if( !pSSN->SST )
continue;
if( pSSN->timeout-- > 0 )
continue;
if( pSSN->DPC == SCCP_Param.spc[pSSN->NetID] )
continue;
outmsg.msgtype = UDT_MSG;
outmsg.msgsource = FROM_SCMG;
outmsg.CGA.DPC = SCCP_Param.spc[pSSN->NetID];
outmsg.CGA.SSN = 1;
outmsg.CGA.GTI = 0;
outmsg.CGA.RI = RI_SSN;
outmsg.CGA.len = 0;
outmsg.CDA.DPC = pSSN->DPC;
outmsg.CDA.SSN = 1; //SCMG
outmsg.CDA.GTI = 0; //No GT
outmsg.CDA.RI = 1;
outmsg.CDA.len = 0;
outmsg.NetID = pSSN->NetID;
outmsg.CDA.ip = INADDR_NONE;
outmsg.msglen = build_scmgmsg ( outmsg.data, SST_MSG, pSSN->DPC, pSSN->SSN, pSSN->NetID );
spLogDebug ( SCCPDB_SCMG, "SST spc=%X,ssn=%d", pSSN->DPC, pSSN->SSN );
send_msg ( &outmsg, mtp3_ansiFlag ( pSSN->NetID ) );
pSSN->timeout = T_sst;
}
}
/////////////////////////
/*LCST Module----------> */
/////////////////////////
void lcst ( int spc, BYTE ssn, BYTE ntype, BYTE NetID )
{
Intra_Msg outmsg;
int i;
spLogDebug ( SCCPDB_SCMG, "Start Local Broatcast.spc=%X,ssn=%d,ntype=%d", spc, ssn, ntype );
outmsg.msgtype = UDT_MSG;
outmsg.msgsource = FROM_SCMG;
outmsg.CGA.SSN = 1;
outmsg.CGA.GTI = 0;
outmsg.CGA.len = 0;
outmsg.CGA.RI = 1;
outmsg.CGA.DPC = SCCP_Param.spc[NetID];
outmsg.CDA.GTI = 0;
outmsg.NetID = outmsg.CDA.NetID = outmsg.CGA.NetID = NetID;
outmsg.CDA.DPC = SCCP_Param.spc[NetID];
outmsg.CDA.SSN = 1;
outmsg.CDA.RI = 1;
outmsg.CDA.len = 0;
outmsg.msglen = build_scmgmsg ( outmsg.data, ntype, spc, ssn, NetID );
for ( i = 2; i < 256; i++ )
{
if( LocalSSN[i].status[0] > 0 && LocalSSN[i].local != 1 )
{
outmsg.CDA.ip = LocalSSN[i].ip[0];
send_msg ( &outmsg, mtp3_ansiFlag ( NetID ) );
}
if( LocalSSN[i].status[1] > 0 && LocalSSN[i].local != 2 )
{
outmsg.CDA.ip = LocalSSN[i].ip[1];
send_msg ( &outmsg, mtp3_ansiFlag ( NetID ) );
}
}
}
/////////////////////////
/*BCST Module----------> */
/////////////////////////
void bcst ( BYTE ssn, BYTE ntype )
{
Intra_Msg outmsg;
int i;
spLogDebug ( SCCPDB_SCMG, "Start Remote Broadcase ssn=%d,ntype=%d", ssn, ntype );
outmsg.msgtype = UDT_MSG;
outmsg.msgsource = FROM_SCMG;
outmsg.CDA.GTI = 0;
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( RelatedSPC[i].status != ST_Enable )
continue;
outmsg.CGA.SSN = 1;
outmsg.CGA.GTI = 0;
outmsg.CGA.len = 0;
outmsg.CGA.RI = 1;
outmsg.CGA.DPC = SCCP_Param.spc[RelatedSPC[i].NetID];
outmsg.CDA.ip = INADDR_NONE;
outmsg.CDA.DPC = RelatedSPC[i].DPC;
outmsg.CDA.SSN = 1;
outmsg.CDA.RI = 1;
outmsg.CDA.len = 0;
outmsg.NetID = outmsg.CDA.NetID = outmsg.CGA.NetID = RelatedSPC[i].NetID;
outmsg.msglen = build_scmgmsg ( outmsg.data, ntype, SCCP_Param.spc[outmsg.NetID], ssn, outmsg.NetID );
send_msg ( &outmsg, mtp3_ansiFlag ( outmsg.NetID ) );
}
}
void bcst_relay ( int spc, BYTE ssn, BYTE ntype, BYTE NetID )
{
Intra_Msg outmsg;
int i;
spLogDebug ( SCCPDB_SCMG, "relay Broadcase spc:%X,ssn%d,ntype:%d", spc, ssn, ntype );
outmsg.msgtype = UDT_MSG;
outmsg.msgsource = FROM_SCMG;
outmsg.CDA.GTI = 0;
outmsg.CGA.SSN = 1;
outmsg.CGA.GTI = 0;
outmsg.CGA.len = 0;
outmsg.CGA.RI = 1;
outmsg.NetID = outmsg.CGA.NetID = outmsg.CDA.NetID = NetID;
for ( i = 0; i < RelatedSPCNum; i++ )
{
if( NetID != RelatedSPC[i].NetID )
return;
if( RelatedSPC[i].status == ST_Disable || spc == RelatedSPC[i].DPC )
continue;
outmsg.CGA.DPC = SCCP_Param.spc[RelatedSPC[i].NetID];
outmsg.CDA.ip = INADDR_NONE;
outmsg.CDA.DPC = RelatedSPC[i].DPC;
outmsg.CDA.SSN = 1;
outmsg.CDA.RI = 1;
outmsg.CDA.len = 0;
outmsg.msglen = build_scmgmsg ( outmsg.data, ntype, spc, ssn, NetID );
send_msg ( &outmsg, mtp3_ansiFlag ( NetID ) );
}
}
int build_scmgmsg ( BYTE * data, BYTE type, int spc, BYTE ssn, BYTE NetID )
{
int pos = 0;
data[pos++] = type;
data[pos++] = ssn;
memcpy ( data + pos, ( BYTE * ) & spc, SCCP_Param.spclen[NetID] );
pos += SCCP_Param.spclen[NetID];
data[pos++] = 0;
if( type == SSC_MSG )
data[pos++] = 0;
return pos;
}
int parse_scmgmsg ( BYTE * data, BYTE * type, int *spc, BYTE * ssn, BYTE NetID )
{
int pos = 0;
*type = data[pos++];
*ssn = data[pos++];
*spc = 0;
memcpy ( ( BYTE * ) spc, data + pos, SCCP_Param.spclen[NetID] );
pos += SCCP_Param.spclen[NetID];
return 1;
}

126
plat/sccp/src/scoc.c Normal file
View File

@@ -0,0 +1,126 @@
/********************************************************************/
/*Title: scoc.c */
/*Descr: SCCP Connection-Oriented Control */
/*Author: Liang Hanxi */
/*Create: 2002-2-19 */
/*Modify: 2003-5-9 */
/********************************************************************/
#include "./include/sccp.h"
/*===========import================*/
extern int scrc_route ( Intra_Msg * pIntraMsg, BOOL ForceAnsi );
extern int build_msg ( BYTE * buf, Intra_Msg * intramsg, BYTE NetID, BYTE ansi_flag ); //sccpmsg.c
extern int parse_msg ( BYTE * buf, Intra_Msg * intramsg, int len, BYTE NetID, BYTE ansi_flag ); //sccpmsg.c
/*===========export================*/
int scrc2scoc ( Intra_Msg * intramsg, BYTE AnsiFlag );
int scoc_store ( up_message * sccpmsg );
/*
int scrc2scoc ( Intra_Msg * intramsg, BYTE AnsiFlag )
{
up_message mtp3msg;
mtp3msg.len = build_msg ( mtp3msg.msgList, intramsg, intramsg->NetID, AnsiFlag );
mtp3msg.dest_ip = intramsg->CDA.ip;
mtp3msg.dpc = intramsg->DPC;
mtp3msg.opc = intramsg->OPC;
mtp3msg.sio = intramsg->NetID * 0x40 + 3;
mtp3msg.cic[0] = intramsg->SLS;
mtp3msg.link = intramsg->link;
scoc_store ( &mtp3msg );
return 1;
}
*/
/*
int scoc_store ( up_message * sccpmsg )
{
up_message *pmsg;
SccpCsta[SccpCstaInd].utilization[4 - 3]++;
spLogDebug ( SCCPDB_AIF, "MSC <== SCCP: CO Message. opc=%x,sio=%02x", sccpmsg->opc, sccpmsg->sio );
spShowBCD ( SCCPDB_AIF, ( BYTE * ) sccpmsg, ( sccpmsg->len + 17 ) % 256 );
pmsg = &ScocBuf.msgin[ScocBuf.rcvsub[0]];
memcpy ( pmsg, sccpmsg, sizeof ( up_message ) );
ScocBuf.rcvsub[0] = ( ScocBuf.rcvsub[0] + 1 ) % SS_MSG_NUM;
if( ScocBuf.rcvsub[0] == ScocBuf.rcvsub[1] )
ScocBuf.rcvsub[1] = ( ScocBuf.rcvsub[1] + 1 ) % SS_MSG_NUM;
sccpmsg_st.msg_mtp_scoc++;
return 1;
}
*/
/******************************************************************/
/*================== User Interface-----> ================*/
/******************************************************************/
/*
int scoc_send ( up_message * pmsg )
{
BYTE ntype;
BOOL ForceAnsi = 0;
ntype = pmsg->msgList[0];
spLogDebug ( SCCPDB_AIF, "MSC ==> SCCP: CO/UDT Message. opc=%x,sio=%02x,type=%d", pmsg->opc, pmsg->sio, ntype );
spShowBCD ( SCCPDB_AIF, ( BYTE * ) pmsg, ( pmsg->len + 17 ) % 256 );
SccpCsta[SccpCstaInd].utilization[0]++;
switch ( ntype )
{
case CR_MSG:
SccpCsta[SccpCstaInd].quality[4]++;
break;
case CC_MSG:
break;
case DT1_MSG:
SccpCsta[SccpCstaInd].utilization[10 - 3]++;
break;
case DT2_MSG:
SccpCsta[SccpCstaInd].utilization[12 - 3]++;
break;
}
if( ntype == CR_MSG || ntype == UDT_MSG )
{
Intra_Msg outmsg;
BYTE NetID = pmsg->sio / 0x40;
memset ( &outmsg, 0, sizeof ( Intra_Msg ) );
ForceAnsi = ( pmsg->sio >> 4 ) & 1;
parse_msg ( pmsg->msgList, &outmsg, pmsg->len, NetID, ForceAnsi );
outmsg.CDA.ip = INADDR_NONE;
outmsg.OPC = pmsg->opc;
outmsg.DPC = pmsg->dpc;
outmsg.SLS = pmsg->cic[0];
outmsg.NetID = outmsg.CGA.NetID = outmsg.CDA.NetID = NetID;
return scrc_route ( &outmsg, ForceAnsi );
}
else
{
return sccp_to_mtp3 ( pmsg );
}
}
int scoc_receive ( up_message * sccpmsg )
{
up_message *pmsg;
if( ScocBuf.rcvsub[0] == ScocBuf.rcvsub[1] )
return 0;
pmsg = &ScocBuf.msgin[ScocBuf.rcvsub[1]];
memcpy ( sccpmsg, pmsg, sizeof ( up_message ) );
ScocBuf.rcvsub[1] = ( ScocBuf.rcvsub[1] + 1 ) % SS_MSG_NUM;
sccpmsg_st.msg_scoc_up++;
return 1;
}
*/

1068
plat/sccp/src/scoc_fsm.c Normal file

File diff suppressed because it is too large Load Diff

931
plat/sccp/src/scoc_func.c Normal file
View File

@@ -0,0 +1,931 @@
//////////////////////////////////////////////////
//Title : scoc_if.c
//Auhtor : Liu Wei
//Desc : SCOC interface implementation
//Created : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/sccp_pub.h"
#include "./include/scoc_if.h"
#include "./include/sccp_func.h"
/* by simon at 23/9/25 */
extern DWORD ExistIP[64];
extern DWORD ExistIPNum;
extern SCOC_BUF ScocBuf;
extern LOCAL_SSN LocalSSN[256];
extern u8 ExistSSN[64];
extern u8 ExistSSNNum;
extern struct _dpc2sls
{
int dpc;
u8 sls;
} dpc2sls[256]; // used for sequence control, add by Roy Jiang, 2007-09-17
extern SCCP_OPT SCCP_Param;
extern u8 MNP_Flag[2];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern int RelatedSPCNum;
extern RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
extern GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern SCCP_Capture_Buf SCCPCapBuf;
/* by simon at 23/9/26 */
SP_Entity tSpEntity;
SP_Entity *pSp;
void spWatchDogStatic ( u8 uDebugStaticMask );
void coInit ( u32 sysID, u32 localIP, u32 alterIP )
{
pSp = &tSpEntity;
memset ( pSp, 0, sizeof ( SP_Entity ) );
spPoolInit ( );
pSp->dLocalIP = localIP;
pSp->dAlterIP = alterIP;
pSp->dSysID = sysID + 1;
}
void cr2coFailHandle ( Intra_Msg * pIntraMsg, u8 uAnsiFlag, u8 uMsgtype )
{
Intra_Msg tCo2CrMsg;
memset ( &tCo2CrMsg, 0, sizeof ( Intra_Msg ) );
switch ( uMsgtype )
{
case SP_MSG_RLSD:
pIntraMsg->cause = REA_PCREF_IS;
case SP_MSG_RLC:
memcpy ( &tCo2CrMsg.aDLR, &pIntraMsg->aSLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aSLR, &pIntraMsg->aDLR, SP_REF_LEN );
break;
case SP_MSG_ERR:
tCo2CrMsg.cause = REA_PDISC_IS;
break;
case SP_MSG_CREF:
tCo2CrMsg.cause = REA_PCREF_LE;
break;
default:
WxcAssert ( 0, "cr2coFailHandle internal error" );
break;
}
tCo2CrMsg.msgsource = FROM_SCOC;
tCo2CrMsg.msgtype = uMsgtype;
tCo2CrMsg.msgclass = pIntraMsg->msgclass;
tCo2CrMsg.NetID = pIntraMsg->CDA.NetID;
tCo2CrMsg.OPC = SCCP_Param.spc[tCo2CrMsg.NetID];
//scrc_route ( &tCo2CrMsg, uAnsiFlag );
tCo2CrMsg.CDA.DPC = tCo2CrMsg.DPC = pIntraMsg->OPC;
tCo2CrMsg.SLS = pIntraMsg->SLS;
tCo2CrMsg.CDA.ip = 0xffffffff;
send_msg ( &tCo2CrMsg, uAnsiFlag);
spWatchDogStatic ( CO_TO_CR );
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int cr2co ( Intra_Msg * pIntraMsg, u8 uAnsiFlag )
{
int nRet;
char *pStr;
SP_PriPoolEle pPri;
spWatchDogStatic ( CR_TO_CO_APT );
WxcAssert ( pIntraMsg->msgtype < SP_MSG_MAX, "SCCP cr2co unexpected msgtype" );
spGetMsgStr ( pIntraMsg->msgtype, pStr );
switch ( pIntraMsg->msgtype )
{
case SP_MSG_CR:
// if( ( coGetConnId ( pIntraMsg->aSLR ) >= 0 ) || ( ( nRet = coNewConnId ( R_CR ) ) < 0 ) )
if( (nRet = coNewConnId ( R_CR )) < 0 )
{
spLogDebug ( SCCPDB_ERR, "[cr2co]No resourece for %s", pStr );
cr2coFailHandle ( pIntraMsg, uAnsiFlag, SP_MSG_CREF );
return 0 ;
}
break;
case SP_MSG_RLSD:
nRet = coGetConnId ( pIntraMsg->aDLR );
if( nRet < 0 )
{
spLogDebug ( SCCPDB_ERR, "[sr2co]recv %s msg in init state, cr2co return error ", pStr );
cr2coFailHandle ( pIntraMsg, uAnsiFlag, SP_MSG_RLC );
return 0 ;
}
break;
case SP_MSG_RF:
nRet = coGetConnId ( pIntraMsg->aDLR );
if( nRet < 0 )
{
spLogDebug ( SCCPDB_ERR, "[sr2co]recv RF msg in init state, co2cr return cref ", pStr );
cr2coFailHandle ( pIntraMsg, uAnsiFlag, SP_MSG_CREF );
return 0 ;
}
break;
case SP_MSG_IT:
nRet = coGetConnId ( pIntraMsg->aDLR );
if( nRet < 0 )
{
spLogDebug ( SCCPDB_ERR, "[sr2co]recv IT msg in init state,discard " );
cr2coFailHandle ( pIntraMsg, uAnsiFlag, SP_MSG_RLSD );
return 0 ;
}
break;
case SP_MSG_RLC:
nRet = coGetConnId ( pIntraMsg->aDLR );
if( nRet < 0 )
return 0 ;
break;
default:
nRet = coGetConnId ( pIntraMsg->aDLR );
if( nRet < 0 )
{
spLogDebug ( SCCPDB_ERR, "[sr2co]recv %s msg in init state", pStr );
if( memcmp ( pIntraMsg->aSLR, "/0/0/0", SP_REF_LEN ) )
{
spLogDebug ( SCCPDB_ERR, "[sr2co]recv %s msg in init state, co2cr return error ", pStr );
// cr2coFailHandle ( pIntraMsg, uAnsiFlag, SP_MSG_RLSD );
}
return 0 ;
}
break;
}
pPri.tCrPri.wConnId = nRet;
pPri.tCrPri.uUiPri = pIntraMsg->msgtype + SPUI_PRI_MAX;
pPri.tCrPri.uAnsiFlag = uAnsiFlag;
memcpy ( &pPri.tCrPri.tIntraMsg, pIntraMsg, sizeof ( Intra_Msg ) );
spPoolPut ( &pPri, pInCoPool );
spWatchDogStatic ( CR_TO_CO );
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void co2cr ( u16 wConnId, u8 uMsgType )
{
CO_ConnSection *pCS;
Intra_Msg tCo2CrMsg;
spWatchDogStatic ( CO_TO_CR_APT );
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP co2cr unexpected connection id" );
WxcAssert ( uMsgType < SP_MSG_MAX, "SCCP cr2co unexpected msgtype" );
pCS = &pSp->tCo.tCSInst[wConnId];
memset ( &tCo2CrMsg, 0, sizeof ( Intra_Msg ) );
tCo2CrMsg.msgsource = FROM_SCOC;
tCo2CrMsg.msgtype = uMsgType;
tCo2CrMsg.msgclass = pCS->uClass;
tCo2CrMsg.NetID = pCS->uNetId;
switch ( uMsgType )
{
case SP_MSG_CR:
tCo2CrMsg.msglen = 0;
if( pCS->tUD.uDataLen )
{
tCo2CrMsg.msglen = pCS->tUD.uDataLen % 256;
memcpy ( &tCo2CrMsg.data, pCS->tUD.aUserData, tCo2CrMsg.msglen );
}
memcpy( &tCo2CrMsg.CDA , &pCS->tCDA , sizeof(SCCP_ADDR) );
tCo2CrMsg.CGA.NetID = tCo2CrMsg.CDA.NetID = tCo2CrMsg.NetID ;
WxcAssert ( tCo2CrMsg.NetID <= 3, "co2cr: NetID is error " );
tCo2CrMsg.OPC = SCCP_Param.spc[tCo2CrMsg.NetID];
tCo2CrMsg.CDA.DPC = tCo2CrMsg.DPC = pCS->nDPC;
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
tCo2CrMsg.SLS = pCS->uSLS;
scrc_route ( &tCo2CrMsg, pCS->uAnsiFlag );
spWatchDogStatic ( CO_TO_CR );
return;
case SP_MSG_CC:
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
break;
case SP_MSG_CREF:
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
tCo2CrMsg.cause = pCS->eREA;
break;
case SP_MSG_RLSD:
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
tCo2CrMsg.cause = pCS->eREA;
break;
case SP_MSG_RLC:
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
break;
case SP_MSG_DT1:
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
tCo2CrMsg.EOD = 0;
tCo2CrMsg.msglen = 0;
if( pCS->tUD.uDataLen )
{
tCo2CrMsg.msglen = pCS->tUD.uDataLen % 256;
memcpy ( &tCo2CrMsg.data, pCS->tUD.aUserData, tCo2CrMsg.msglen );
}
break;
case SP_MSG_IT:
memcpy ( &tCo2CrMsg.aSLR, &pCS->aSLR, SP_REF_LEN );
memcpy ( &tCo2CrMsg.aDLR, &pCS->aDLR, SP_REF_LEN );
break;
case SP_MSG_ERR:
spLogDebug ( SCCPDB_ERR, "Need to supported SP_MSG_ERR now!" );
break;
case SP_MSG_DT2:
case SP_MSG_AK:
case SP_MSG_ED:
case SP_MSG_EA:
case SP_MSG_RSR:
case SP_MSG_RSC:
spLogDebug ( SCCPDB_ERR, "do not supported now!" );
break;
}
tCo2CrMsg.CGA.NetID = tCo2CrMsg.CDA.NetID = tCo2CrMsg.NetID ;
tCo2CrMsg.OPC = SCCP_Param.spc[tCo2CrMsg.NetID];
if( pCS->uSide == CO_INST_SIDE_ORG )
tCo2CrMsg.CDA.DPC = tCo2CrMsg.DPC = pCS->nDPC;
else if( pCS->uSide == CO_INST_SIDE_DST )
tCo2CrMsg.CDA.DPC = tCo2CrMsg.DPC = pCS->nOPC;
tCo2CrMsg.SLS = pCS->uSLS;
WxcAssert ( tCo2CrMsg.NetID <= 3, "co2cr: NetID is error " );
tCo2CrMsg.OPC = SCCP_Param.spc[tCo2CrMsg.NetID];
tCo2CrMsg.CDA.ip = 0xffffffff;
send_msg ( &tCo2CrMsg, pCS->uAnsiFlag);
spWatchDogStatic ( CO_TO_CR );
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void co2ul ( u16 wConnId, u8 uPri )
{
char *pStr;
CO_ConnSection *pCS;
SP_UiPriUnion *pUnPri;
SP_PriPoolEle tPoolEle, *pPri;
spWatchDogStatic ( CO_SUBMIT_UL_APT );
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP co2cr unexpected connection id" );
pPri = &tPoolEle;
pUnPri = ( SP_UiPriUnion * ) & pPri->tUiPri.tPriUnion;
pCS = &pSp->tCo.tCSInst[wConnId];
pPri->tUiPri.uUiPri = uPri;
pPri->tUiPri.uAnsiFlag = pCS->uAnsiFlag;
pPri->tUiPri.wConnId = wConnId;
spGetUlPrimitiveStr ( uPri, pStr );
switch ( uPri )
{
case N_UNITDATA_IND:
case N_NOTICE_IND:
spLogDebug ( SCCPDB_ERR, "SP=>UL: Unsupported UDT primitive now :%s", pStr );
break;
case N_CONNECT_IND:
pUnPri->tPriNConnInd.tUD.uDataLen = 0;
if( pCS->tUD.uDataLen )
{
pUnPri->tPriNConnInd.uOptFlag = 0x04;
memcpy ( &pUnPri->tPriNConnInd.tUD, &pCS->tUD, sizeof ( SP_UD ) );
}
else
pUnPri->tPriNConnInd.uOptFlag = 0;
memcpy ( &pUnPri->tPriNConnInd.tCDA, &pCS->tCDA, sizeof ( SCCP_ADDR ) );
memcpy ( &pUnPri->tPriNConnInd.aSLR, &pCS->aDLR, SP_REF_LEN );
pUnPri->tPriNConnInd.uSLS = pCS->uSLS;
pUnPri->tPriNConnInd.OPC = pCS->nOPC;
pUnPri->tPriNConnInd.NetID = pCS->uNetId;
break;
case N_CONNECT_CFM:
pUnPri->tPriNConnCfm.tUD.uDataLen = 0;
if( pCS->tUD.uDataLen )
{
pUnPri->tPriNConnCfm.uOptFlag = 0x04;
memcpy ( &pUnPri->tPriNConnCfm.tUD, &pCS->tUD, sizeof ( SP_UD ) );
}
else
pUnPri->tPriNConnCfm.uOptFlag = 0;
break;
case N_DISCONNECT_IND:
pUnPri->tPriNDisconnInd.tUD.uDataLen = 0;
if( pCS->tUD.uDataLen )
{
pUnPri->tPriNDisconnInd.uOptFlag = 0x04;
memcpy ( &pUnPri->tPriNDisconnInd.tUD, &pCS->tUD, sizeof ( SP_UD ) );
}
else
pUnPri->tPriNDisconnInd.uOptFlag = 0;
pUnPri->tPriNDisconnInd.eOR = pCS->eOR;
pUnPri->tPriNDisconnInd.eREA = pCS->eREA;
break;
case N_DATA_IND:
memcpy ( &pUnPri->tPriNDataInd.tUD, &pCS->tUD, sizeof ( SP_UD ) );
break;
case N_DATAAK_IND:
case N_EDATA_IND:
case N_RESET_IND:
case N_RESET_CFM:
case N_INFORM_IND:
case RELAY:
spLogDebug ( SCCPDB_ERR, "SP=>UL: Unsupported the primitive now :%s", pStr );
break;
default:
spLogDebug ( SCCPDB_ERR, "SP=>UL: Unknow primtive :%s", pStr );
break;
}
spShowPrimitive ( &pPri->tUiPri, 0 );
spWatchDogStatic ( WDS_RECV_PRI );
spPoolPut ( &tPoolEle, pOutCoPool );
spWatchDogStatic ( CO_SUBMIT_UL );
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void co2scmg ( )
{
}
void co2co ( u16 wConnId, u8 uPri )
{
SP_PriPoolEle pPri;
memset ( &pPri, 0, sizeof ( SP_PriPoolEle ) );
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP coTimerOut unexpected connection id" );
WxcAssert ( ( uPri > SPCR_PRI_MAX && uPri < SPTM_PRI_MAX ), "SCCP coTimerOut unexpected msgtype" );
pPri.tUiPri.uUiPri = uPri;
pPri.tUiPri.wConnId = wConnId;
spPoolPut ( &pPri, pInCoPool );
}
int spCheckAudit ( )
{
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coAssignSLS ( u8 wConnId )
{
return ( wConnId & 0x0F );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void coAssignLR ( u16 wConnId, u8 * pLR )
{
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP coNewCS unexpected connection id" );
*( pLR ) = pSp->dSysID;
*( pLR + 1 ) = wConnId >> 8;
*( pLR + 2 ) = wConnId & 0xFF;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coAssignClass ( u8 wConnId )
{
//do not support class 3 now
return 2;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coAssignCredit ( u8 wConnId )
{
//credit not supported now
return 0;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coNewCS ( u16 wConnId, SCCP_ADDR * pAddr )
{
CO_ConnSection *pCS;
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP coNewCS unexpected connection id" );
pCS = &pSp->tCo.tCSInst[wConnId];
pCS->uSLS = coAssignSLS ( wConnId );
coAssignLR ( wConnId, pCS->aSLR );
memcpy ( &pCS->tCDA, pAddr, sizeof ( SCCP_ADDR ) );
pCS->uClass = coAssignClass ( wConnId );
pCS->uCredit = coAssignCredit ( wConnId );
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void coFreeCS ( u16 wConnId )
{
CO_DataBlock *pCo;
CO_ConnSection *pCS = &pSp->tCo.tCSInst[wConnId];
pCo = &pSp->tCo;
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP coNewCS un expected connection id" );
memset ( pCS, 0, sizeof ( CO_ConnSection ) );
pCo->wConnIdCount--;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void coFillCS ( SP_PriPoolEle * pPri )
{
SP_CrPriPara *pCrPri;
CO_ConnSection *pCS;
pCrPri = ( SP_CrPriPara * ) & pPri->tCrPri;
WxcAssert ( ( pCrPri->wConnId < CO_CS_MPORT ), "SCCP coFillCS unexpect connection id" );
WxcAssert ( ( pCrPri->uUiPri < SPTM_PRI_MAX ), "SCCP coFillCS unexpect primitive" );
pCS = &pSp->tCo.tCSInst[pCrPri->wConnId];
pCS->uPri = pCrPri->uUiPri;
pCS->uAnsiFlag = pCrPri->uAnsiFlag;
if( pCS->uPri > SPCR_PRI_MAX ) //Internal primitive
{
return;
}
else if( pCS->uPri > SPUI_PRI_MAX ) //CR/SCMG message primitive
{
Intra_Msg *pMsg;
pMsg = &pCrPri->tIntraMsg;
if( pMsg->msglen )
{
WxcAssert ( pMsg->msglen < 255, "coFillCS Message length overflow" );
pCS->tUD.uDataLen = pMsg->msglen % 256;
memcpy ( &pCS->tUD.aUserData, &pMsg->data, pCS->tUD.uDataLen );
}
else
pCS->tUD.uDataLen = 0;
switch ( pCS->uPri )
{
case R_CR: /* connection request */
memcpy ( &pCS->tCDA, &pMsg->CDA, sizeof ( SCCP_ADDR ) );
//memcpy ( &pCS->tCGA, &pMsg->CGA, sizeof ( SCCP_ADDR ) );
pCS->nDPC = pMsg->DPC;
pCS->nOPC = pMsg->OPC;
pCS->uNetId = pMsg->NetID;
pCS->uSLS = pMsg->SLS;
memcpy ( &pCS->aDLR, &pMsg->aSLR, SP_REF_LEN );
break;
case R_CR2: /* connection request type 2 */
break;
case R_CC: /* connection confirm */
pCS->uClass = pMsg->msgclass;
memcpy ( &pCS->aDLR, &pMsg->aSLR, SP_REF_LEN );
break;
case R_CREF: /* connection refused */
pCS->eREA = pMsg->cause;
break;
case R_RLSD: /* release request */
pCS->eREA = pMsg->cause;
break;
case R_RLC: /* release confirm */
break;
case R_DT1: /* Data Form 1 */
break;
case R_DT2: /* Data Form 2 */
break;
case R_AK: /* Data acknowledge */
break;
case R_ED: /* Expedited data */
break;
case R_EA: /* Expedited data acknowledge */
break;
case R_RSR: /* Reset request */
break;
case R_RSC: /* Reset confirm */
break;
case R_ERR: /* PDU error */
break;
case R_IT: /* Inactivity test */
break;
case R_RF: /* Routing Fail */
break;
case R_RLS_ERR: /* Release err */
break;
default:
break;
}
}
else //upper layer primitive
{
SP_UiPriUnion *pUnPri;
pUnPri = ( SP_UiPriUnion * ) & pPri->tUiPri.tPriUnion;
switch ( pCS->uPri )
{
case N_CONNECT_REQ:
memcpy ( &pCS->tCDA, &pUnPri->tPriNConnReq.tCDA, sizeof ( SCCP_ADDR ) );
if( pUnPri->tPriNConnReq.uOptFlag & 0x08 )
{
memcpy ( &pCS->tUD, &pUnPri->tPriNConnReq.tUD, sizeof ( SP_UD ) );
}
pCS->nDPC = pCS->tCDA.DPC;
pCS->uNetId = pUnPri->tPriNConnReq.tCDA.NetID;
break;
case N_CONNECT_RSP:
break;
case N_DISCONNECT_REQ:
pCS->eREA = pUnPri->tPriNDisconnReq.eREA;
pCS->eOR = NSU;
break;
case N_DATA_REQ:
memcpy ( &pCS->tUD, &pUnPri->tPriNDataReq.tUD, sizeof ( SP_UD ) );
break;
case N_DATAAK_REQ:
case N_EDATA_REQ:
case N_RESET_REQ:
case N_RESET_RSP:
case N_INFORM_REQ:
break;
default:
break;
}
}
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coCheckCS ( u16 wConnId, u8 uCState, u8 uSide )
{
#ifdef DEBUG
WxcAssert ( ( uCState < CO_STATUS_MAX ), "SCCP coFsm unexpect connection section state" );
WxcAssert ( ( uSide < CO_INST_SIDE_MAX ), "SCCP coFsm unexpect connection section state" );
#else
if( uCState >= CO_STATUS_MAX )
{
spLogStateError ( wConnId, ERR_FSM_DISCARD );
//spCoRecover ( wConnId, CO_FATAL_STATE );
return 0;
}
if( uSide >= CO_INST_SIDE_MAX )
{
spLogStateError ( wConnId, ERR_FSM_UNEXPECT_SIDE );
//spCoRecover ( wConnId, CO_FATAL_SIDE );
return 0;
}
#endif
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void coTimerOut ( u16 wConnId, u8 uPri )
{
SP_PriPoolEle pPri;
WxcAssert ( wConnId < CO_CS_MPORT, "SCCP coTimerOut unexpected connection id" );
WxcAssert ( ( uPri > SPCR_PRI_MAX && uPri < SPTM_PRI_MAX ), "SCCP coTimerOut unexpected msgtype" );
spLogTimerOut( wConnId , uPri );
memset ( &pPri, 0, sizeof ( SP_PriPoolEle ) );
pPri.tUiPri.uUiPri = uPri;
pPri.tUiPri.wConnId = wConnId;
spPoolPut ( &pPri, pInCoPool );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void coTimerMng ( )
{
u16 wConnId;
CO_ConnSection *pCS;
CO_Timer *pTmSet;
// u8 uPri;
for ( wConnId = 0; wConnId < CO_CS_MPORT; wConnId++ )
{
pCS = &pSp->tCo.tCSInst[wConnId];
if( CO_STATUS_INIT == pCS->uCState )
{
continue;
}
pTmSet = &pCS->tmSCOC;
if( pTmSet->tmConnEst && ++pTmSet->tmConnEst > T_CONNEST_MAX )
{
pTmSet->tmConnEst = 0;
coTimerOut ( wConnId, T_CONNEST_OUT );
}
if( pTmSet->tmIas && ++pTmSet->tmIas > T_IAS_MAX )
{
pTmSet->tmIas = 0;
coTimerOut ( wConnId, T_IAS_OUT );
}
if( pTmSet->tmIar && ++pTmSet->tmIar > T_IAR_MAX )
{
pTmSet->tmIar = 0;
coTimerOut ( wConnId, T_IAR_OUT );
}
if( pTmSet->tmRepeatRel && ++pTmSet->tmRepeatRel > T_REPEATE_RLS_MAX )
{
pTmSet->tmRepeatRel = 0;
coTimerOut ( wConnId, T_REPEATE_RLS_OUT );
}
if( pTmSet->tmRel && ++pTmSet->tmRel > T_RLS_MAX )
{
pTmSet->tmRel = 0;
coTimerOut ( wConnId, T_RLS_OUT );
}
if( pTmSet->tmReset && ++pTmSet->tmReset > T_RESET_MAX )
{
pTmSet->tmReset = 0;
coTimerOut ( wConnId, T_RESET_OUT );
}
if( pTmSet->tmGuard && ++pTmSet->tmGuard > T_GUARD_MAX )
{
pTmSet->tmGuard = 0;
coTimerOut ( wConnId, T_GUARD_OUT );
}
if( pTmSet->tmInternal && ++pTmSet->tmInternal > T_INTERNAL_MAX )
{
pTmSet->tmInternal = 0;
coTimerOut ( wConnId, T_INTERNAL_OUT );
}
}
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coNewConnId ( u8 uPri )
{
static u16 wConnId = 0;
CO_DataBlock *pCo;
CO_ConnSection *pCS;
u16 tmpConnId = wConnId;
pCo = &pSp->tCo;
if( pCo->wConnIdCount >= CO_CS_MPORT )
{
spLogDebug ( SCCPDB_ERR, "No resource for new connection" );
return -1;
}
WxcAssert ( ( uPri == N_CONNECT_REQ || uPri == R_CR ), "Unexpect primitive while allocating new connection" );
// for ( wConnId = 0; wConnId < CO_CS_MPORT; wConnId++ )
while (++wConnId != tmpConnId)
{
if (wConnId >= CO_CS_MPORT)
wConnId = 0;
pCS = &pSp->tCo.tCSInst[wConnId];
if( CO_STATUS_INIT == pCS->uCState )
{
memset ( pCS, 0, sizeof ( CO_ConnSection ) );
pCS->uCState = CO_STATUS_IDLE;
if( R_CR == uPri )
{
pCS->uSide = CO_INST_SIDE_DST;
}
else if( N_CONNECT_REQ == uPri )
{
pCS->uSide = CO_INST_SIDE_ORG;
}
pCo->wConnIdCount++;
return wConnId;
}
}
spLogDebug ( SCCPDB_ERR, "No resource for new connection" );
return -1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
int coGetConnId ( u8 *pSLR )
{
u16 wConnId;
CO_ConnSection *pCS;
for ( wConnId = 0; wConnId < CO_CS_MPORT; wConnId++ )
{
pCS = &pSp->tCo.tCSInst[wConnId];
if( memcmp ( pSLR, "\0\0\0", SP_REF_LEN ) && !memcmp ( &pCS->aSLR, pSLR, SP_REF_LEN ) )
{
return wConnId;
}
}
return -1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
inline int coCheckConnId ( SP_UiPriPara * pUiPriParam )
{
WxcAssert ( ( pUiPriParam->wConnId < CO_CS_MPORT ), "SCCP coCheckConnId unexpect connection id" );
if( pSp->tCo.tCSInst[pUiPriParam->wConnId].uCState > 0 )
{
return 1;
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
// Name : coCheckResource ///
// Function : Check Resouce for a coming connection ///
// Return : Have been check in cr2co function, so always return 1 ///
///////////////////////////////////////////////////////////////////////////
inline int coCheckResource ( )
{
//Have been check in cr2co function, so always return 1
return 1;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spWatchDogStatic ( u8 uDebugStaticMask )
{
CO_DebugStatic *pDs = &pSp->tCo.tCoDebugStatic;
switch ( uDebugStaticMask )
{
case GET_IN_POOL:
pDs->dGetInPool++;
break;
case PUT_IN_POOL:
pDs->dPutInPool++;
break;
case READ_IN_POOL:
pDs->dReadInPool++;
break;
case WRITE_IN_POOL:
pDs->dWriteInPool++;
break;
case GET_OUT_POOL:
pDs->dGetOutPool++;
break;
case PUT_OUT_POOL:
pDs->dPutOutPool++;
break;
case PUT_ELE_APT:
pDs->dPutEleApt++;
break;
case PUT_ELE_SUC:
pDs->dPutEleSuc++;
break;
case UL_POST_CO_APT:
pDs->dUlPostCoApt++;
break;
case UL_POST_CO:
pDs->dUlPostCo++;
break;
case CO_SUBMIT_UL_APT:
pDs->dCoSubmitUlApt++;
break;
case CO_SUBMIT_UL:
pDs->dCoSubmitUl++;
break;
case CO_TO_CR_APT:
pDs->dCo2CrApt++;
break;
case CO_TO_CR:
pDs->dCo2Cr++;
break;
case CR_TO_CO_APT:
pDs->dCr2CoApt++;
break;
case CR_TO_CO:
pDs->dCr2Co++;
break;
case SP_TIMER_OUT:
pDs->dTimerOut++;
break;
default:
break;
}
}
//add by Roy for dual server message redirect
void coRedirect(SP_UiPriPara * pUiPriParam)
{
Intra_Msg tmpMsg;
memset (&tmpMsg, 0, sizeof(Intra_Msg));
tmpMsg.msglen = 0;
if (pUiPriParam->uUiPri == N_UNITDATA_IND)
{
if( pUiPriParam->tPriUnion.tPriNUDataInd.tUD.uDataLen )
{
tmpMsg.msglen = pUiPriParam->tPriUnion.tPriNUDataInd.tUD.uDataLen % 256;
memcpy ( &tmpMsg.data, pUiPriParam->tPriUnion.tPriNUDataInd.tUD.aUserData, tmpMsg.msglen );
}
memcpy( &tmpMsg.CDA , &pUiPriParam->tPriUnion.tPriNUDataInd.tCDA , sizeof(SCCP_ADDR) );
memcpy( &tmpMsg.CGA , &pUiPriParam->tPriUnion.tPriNUDataInd.tCGA , sizeof(SCCP_ADDR) );
WxcAssert ( tmpMsg.NetID <= 3, "co2cr: NetID is error " );
tmpMsg.OPC = pUiPriParam->tPriUnion.tPriNUDataInd.tCGA.DPC;
tmpMsg.SLS = pUiPriParam->tPriUnion.tPriNUDataInd.uSLS;
tmpMsg.msgtype = UDT_MSG;
}
else{
if( pUiPriParam->tPriUnion.tPriNConnInd.tUD.uDataLen )
{
tmpMsg.msglen = pUiPriParam->tPriUnion.tPriNConnInd.tUD.uDataLen % 256;
memcpy ( &tmpMsg.data, pUiPriParam->tPriUnion.tPriNConnInd.tUD.aUserData, tmpMsg.msglen );
}
memcpy( &tmpMsg.CDA , &pUiPriParam->tPriUnion.tPriNConnInd.tCDA , sizeof(SCCP_ADDR) );
memcpy ( &tmpMsg.aSLR, &pUiPriParam->tPriUnion.tPriNConnInd.aSLR, SP_REF_LEN );
WxcAssert ( tmpMsg.NetID <= 3, "co2cr: NetID is error " );
tmpMsg.OPC = pUiPriParam->tPriUnion.tPriNConnInd.OPC;
tmpMsg.SLS = pUiPriParam->tPriUnion.tPriNConnInd.uSLS;
tmpMsg.msgtype = CR_MSG;
//remove the connection
memset(&pSp->tCo.tCSInst[pUiPriParam->wConnId], 0, sizeof(CO_ConnSection));
pSp->tCo.wConnIdCount--;
}
tmpMsg.NetID = tmpMsg.CDA.NetID;
tmpMsg.CDA.ip = pSp->dAlterIP;
tmpMsg.msgsource = FROM_MTP;
tmpMsg.redirectFlag = 1;
spLogDebug ( SCCPDB_TIME, "AIF ==> SCCP : Message redirect request" );
send_msg ( &tmpMsg, pUiPriParam->uAnsiFlag);
}

307
plat/sccp/src/scoc_if.c Normal file
View File

@@ -0,0 +1,307 @@
//////////////////////////////////////////////////
//Title : scoc_if.c
//Auhtor : Liu Wei
//Desc : SCOC interface implementation
//Created : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/sccp_pub.h"
#ifdef LOOSE_COUPLING_MODE //Loose coupling mode
extern inline int coCheckConnId ( SP_UiPriPara * pUiPriParam );
extern void coRedirect(SP_UiPriPara * pUiPriParam);
/* by simon at 23/9/25 */
extern DWORD ExistIP[64];
extern DWORD ExistIPNum;
extern SCOC_BUF ScocBuf;
extern LOCAL_SSN LocalSSN[256];
extern u8 ExistSSN[64];
extern u8 ExistSSNNum;
extern struct _dpc2sls
{
int dpc;
u8 sls;
} dpc2sls[256]; // used for sequence control, add by Roy Jiang, 2007-09-17
extern SCCP_OPT SCCP_Param;
extern u8 MNP_Flag[2];
extern SCCP_ROUTE RouteList[SCCP_ROUTE_NUM];
extern int RelatedSSNNum;
extern RL_SSN RelatedSSN[SCCP_RLSSN_NUM];
extern int RelatedSPCNum;
extern RL_SPC RelatedSPC[SCCP_RLSPC_NUM];
extern GTTATT_OMC GTTAttribute[SCCP_ROUTE_NUM];
extern SCCP_CSTA SccpCsta[96];
extern DWORD SccpCstaInd;
extern SCCP_Capture_Buf SCCPCapBuf;
///////////////////////////////////////////////////////////////////////////
//
// Name : PostSp
// Function : Upper layer post request/response primitive to sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
// Note : Sccp Connid is implicit returned in "pUiPriParam" buffer
// : while N-Connect requesing
// Return : 0 Post Fail 1 Post Successful
//
///////////////////////////////////////////////////////////////////////////
int PostSp ( SP_UiPriPara * pUiPriParam )
{
int nRet;
u8 *pPriStr;
spShowPrimitive ( pUiPriParam, 1 );
spWatchDogStatic ( UL_POST_CO_APT );
switch ( pUiPriParam->uUiPri )
{
case N_UNITDATA_REQ:
{
SCLC_MSG tClMsg;
tClMsg.msglen = pUiPriParam->tPriUnion.tPriNUDataReq.tUD.uDataLen;
memcpy ( &tClMsg.msg, &pUiPriParam->tPriUnion.tPriNUDataReq.tUD.aUserData, tClMsg.msglen );
memcpy ( &tClMsg.src_addr, &pUiPriParam->tPriUnion.tPriNUDataReq.tCGA, sizeof ( SCCP_ADDR ) );
memcpy ( &tClMsg.dst_addr, &pUiPriParam->tPriUnion.tPriNUDataReq.tCDA, sizeof ( SCCP_ADDR ) );
tClMsg.src_addr.DPC = SCCP_Param.spc[tClMsg.src_addr.NetID];
tClMsg.sequence_control = 0;
sclc_send ( &tClMsg );
spWatchDogStatic ( UL_POST_CO );
return 1;
}
//break;
case N_UNITDATA_IND:
case N_CONNECT_IND:
//redirect to alternative server, add by Roy
coRedirect(pUiPriParam);
spWatchDogStatic ( UL_POST_CO );
return 1;
break;
case N_CONNECT_REQ:
nRet = coNewConnId ( N_CONNECT_REQ );
if( nRet < 0 )
{
spLogDebug ( SCCPDB_ERR, "No resouces available !\n" );
return 0;
}
pUiPriParam->wConnId = nRet;
break;
case N_CONNECT_RSP:
case N_DISCONNECT_REQ:
case N_DATA_REQ:
if( !coCheckConnId ( pUiPriParam ) )
{
spLogDebug ( SCCPDB_ERR, "Invalid SCCP connection ID : %d", pUiPriParam->wConnId );
return 0;
}
break;
case N_DATAAK_REQ:
case N_EDATA_REQ:
case N_RESET_REQ:
case N_RESET_RSP:
case N_INFORM_REQ:
spGetUlPrimitiveStr ( pUiPriParam->uUiPri, pPriStr );
spLogDebug ( SCCPDB_ERR, "Unsupported the primitive now :%s", pPriStr );
return 0;
default:
spGetUlPrimitiveStr ( pUiPriParam->uUiPri, pPriStr );
spLogDebug ( SCCPDB_ERR, "Invalid primivtive recieved :%s ", pPriStr );
return 0;
}
spWatchDogStatic ( UL_POST_CO );
{
SP_PriPoolEle tPoolEle;
memset ( &tPoolEle, 0, sizeof ( SP_PriPoolEle ) );
memcpy ( &tPoolEle.tUiPri, pUiPriParam, sizeof ( SP_UiPriPara ) );
spPoolPut ( &tPoolEle, pInCoPool );
}
return 1;
}
///////////////////////////////////////////////////////////////////////////
//
// Name : SpSubmit
// Function : Upper layer fetch indicate/confirm primitive submited form sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
// uUlSapId [upper layer sap id [0 tcap 1 pps 2 smsc 3 aif ] ]
// Return : 0 Fetch Fail 1 Fetch Successful
//
///////////////////////////////////////////////////////////////////////////
int SpSubmit ( SP_UiPriPara * pUiPriParam, u8 uUlSapId )
{
int nRet = 0;
SCLC_MSG tClMsg;
nRet = sclc_receive ( &tClMsg, uUlSapId );
if( nRet )
{
pUiPriParam->tPriUnion.tPriNUDataInd.uSLS = tClMsg.sls;
pUiPriParam->wConnId = 0xFFFF;
pUiPriParam->uUiPri = N_UNITDATA_IND;
pUiPriParam->tPriUnion.tPriNUDataInd.tUD.uDataLen = tClMsg.msglen;
memcpy ( &pUiPriParam->tPriUnion.tPriNUDataInd.tUD.aUserData, &tClMsg.msg, tClMsg.msglen );
memcpy ( &pUiPriParam->tPriUnion.tPriNUDataInd.tCGA, &tClMsg.src_addr, sizeof ( SCCP_ADDR ) );
memcpy ( &pUiPriParam->tPriUnion.tPriNUDataInd.tCDA, &tClMsg.dst_addr, sizeof ( SCCP_ADDR ) );
return nRet;
}
if( 3 == uUlSapId )
{
SP_PriPoolEle tPoolEle;
nRet = spPoolGet ( &tPoolEle, pOutCoPool );
memcpy ( pUiPriParam, &tPoolEle.tUiPri, sizeof ( SP_UiPriPara ) );
return nRet;
}
return nRet;
}
#else
/////////////////////Below is reserved, do not need to read/////////////////////
#ifdef TIGHT_COUPING_MODE //Tight coupling mode
#error "Do not support Tight coupling mode ,please use \"LOOSE_COUPLING_MODE\" flag \n"
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void Ul_Post_Sp ( SP_UiPriPara * pUiPriParam )
{
SP_UiPriUnion *pPriUn;
pPriUn = &pUlPri->tPriUnion;
switch ( pUiPriParam->uUi_Pri )
{
case N_UNITDATA_REQ: //reserved for sclc
spUi_N_UnitDataReq ( &pPriUn->tPriNUDataReq.tCDA, &pPriUn->tPriNUDataReq.tCGA, &pPriUn->tPriNUDataReq.tSEQ, &pPriUn->tPriNUDataReq.tRO, &pPriUn->tPriNUDataReq.tUD );
break;
case N_CONNECT_REQ:
spUi_N_ConnectReq ( &pPriUn->tPriNConnReq.tCDA, &pPriUn->tPriNConnReq.tCGA, &pPriUn->tPriNConnReq.tRCS, &pPriUn->tPriNConnReq.tEDS );
break;
case N_CONNECT_RSP:
spUi_N_ConnectRsp ( &pPriUn->tPriNConnRsp.tRA, &pPriUn->tPriNConnRsp.tRCS, &pPriUn->tPriNConnRsp.tEDS );
break;
case N_DISCONNECT_REQ:
spUi_N_DisconnectReq ( &pPriUn->tPriNDisconnReq.tRA, &pPriUn->tPriNDisconnReq.tREA, &pPriUn->tPriNDisconnReq.tUC, pPriUn->tPriNDisconnReq.tCI );
break;
case N_DATA_REQ:
spUi_N_DataReq ( &pPriUn->tPriNDataReq.tCR, &pPriUn->tPriNDataReq.tUD, pPriUn->tPriNDataReq.tCI );
break;
case N_DATAAK_REQ:
spUi_N_DataAkReq ( pPriUn->tPriNDataAkReq.tCI );
break;
case N_EDATA_REQ:
spUi_N_EDataReq ( pPriUn->tPriNEDataReq.tCI, &pPriUn->tPriNEDataReq.tUD );
break;
case N_RESET_REQ:
spUi_N_ResetReq ( &pPriUn->tPriNResetReq.tREA, pPriUn->tPriNResetReq.tCI );
break;
case N_RESET_RSP:
spUi_N_ResetRsp ( pPriUn->tPriNResetRsp.tCI );
break;
case N_INFORM_REQ:
spUi_N_InformReq ( &pPriUn->tPriNInformReq.tREA, &pPriUn->tPriNInformReq.tQOS, pPriUn->tPriNInformReq.tCI );
break;
default:
spShowMsg ( SCCPDB_ERR, "SCCP <== AIF. UnKnow Primitive %s", GetUiPriStr ( pPriUn->uUi_Pri ) );
return;
break;
}
spShowMsg ( SCCPDB_AIF, "SCCP <== AIF. Primitive %s", GetUiPriStr ( pPriUn->uUi_Pri ) );
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void Sp_Submit_Ul ( SP_UiPriPara * pUiPriParam )
{
switch ( Ui_Pri )
{
case N_UNITDATA_IND: //reserved for sclc
break;
case N_NOTICE_IND:
break;
case N_CONNECT_IND:
break;
case N_CONNECT_CFM:
break;
case N_DISCONNECT_IND:
break;
case N_DATA_IND:
break;
case N_DATAAK_IND:
break;
case N_EDATA_IND:
break;
case N_RESET_IND:
break;
case N_RESET_CFM:
break;
case N_INFORM_IND:
break;
default:
break;
}
return 0;
}
#endif
/////////////////////Above is reserved, do not need to read/////////////////////
#endif

227
plat/sccp/src/scoc_pool.c Normal file
View File

@@ -0,0 +1,227 @@
//////////////////////////////////////////////////
//Title : pool.c
//Auhtor : Liu Wei
//Desc : List and Pool Queue struct implement
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/sccp_pub.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// Reserved for Pool Test -- Start
///////////////////////////////////////////////////////////////////////////
/*
#include "stdio.h"
#include "string.h"
#include "malloc.h"
typedef struct SP_PriPoolEle
{
char ch;
}
SP_PriPoolEle;
*/
///////////////////////////////////////////////////////////////////////////
// Reserved for Pool Test -- End
///////////////////////////////////////////////////////////////////////////
#define SP_MAX_ELEMENT 512
CO_Pool tInCoPool;
CO_Pool *pInCoPool;
CO_Pool tOutCoPool;
CO_Pool *pOutCoPool;
//add by roy jiang for a replacement of dynamic memory allocation
CO_PoolEle SpEleBuf[SP_MAX_ELEMENT];
void spPoolInit ( )
{
pInCoPool = &tInCoPool;
pOutCoPool = &tOutCoPool;
memset ( pInCoPool, 0, sizeof ( CO_Pool ) );
memset ( pOutCoPool, 0, sizeof ( CO_Pool ) );
memset ( SpEleBuf, 0, sizeof ( CO_PoolEle ) * SP_MAX_ELEMENT );
POOL_INIT ( &pInCoPool->tPoolHead );
POOL_INIT ( &pOutCoPool->tPoolHead );
pInCoPool->pPoolHead = &pInCoPool->tPoolHead;
pOutCoPool->pPoolHead = &pOutCoPool->tPoolHead;
pOutCoPool->uMaxPoolSize = MAX_OUT_POOL;
pInCoPool->uMaxPoolSize = MAX_IN_POOL;
}
static int busyCount = 0;
CO_PoolEle *spMallocEle()
{
static int i = 0;
int j = i;
if (busyCount >= SP_MAX_ELEMENT)
return NULL;
while (++i != j)
{
if (i >= SP_MAX_ELEMENT)
i = 0;
if (SpEleBuf[i].flag == 0)
{
busyCount++;
SpEleBuf[i].flag = 1;
pSp->tCo.tCoDebugStatic.dbusyElem = busyCount;
return &SpEleBuf[i];
}
}
return NULL;
}
void spFreeEle(CO_PoolEle *elem)
{
if (elem->flag != 0)
{
busyCount--;
pSp->tCo.tCoDebugStatic.dbusyElem = busyCount;
memset ( elem, 0, sizeof ( CO_PoolEle ) );
}
return;
}
int spPoolGet ( SP_PriPoolEle *pPri, CO_Pool *pCoPool )
{
CO_PoolEle *pPoolEle;
spWatchDogStatic ( CO_GET_POOL );
if( pCoPool->uPoolCount <= 0 || ( POOL_EMPTY ( pCoPool->pPoolHead ) ) )
{
//spLogDebug ( SCCPDB_ERR ,"SCCP get primitive pool fail ,empty" );
return 0;
}
memcpy ( pPri, &pCoPool->pPoolHead->pPoolFirst->tPri, sizeof ( SP_PriPoolEle ) );
pPoolEle = pCoPool->pPoolHead->pPoolFirst;
POOL_REMOVE ( pCoPool->pPoolHead, pPoolEle, tPointer );
pCoPool->uPoolCount--;
// free ( pPoolEle );
spFreeEle (pPoolEle);
spWatchDogStatic ( CO_READ_POOL );
return 1;
}
int spPoolPut ( SP_PriPoolEle * pPri, CO_Pool * pCoPool )
{
CO_PoolEle *pPoolEle;
spWatchDogStatic ( PUT_ELE_APT );
if( pCoPool->uPoolCount > pCoPool->uMaxPoolSize )
{
spLogDebug ( SCCPDB_ERR, "SCCP put Primitive Pool fail , pool full" );
return 0;
}
//commentted by roy jiang to disable dynamic memory allocation, 07-11-16
// pPoolEle = ( CO_PoolEle * ) malloc ( sizeof ( CO_PoolEle ) );
pPoolEle = spMallocEle();
if( NULL == pPoolEle )
{
spLogDebug ( SCCPDB_ERR, "SCCP put Primitive Pool fail ,allocate memery fail" );
return 0;
}
memcpy ( &pPoolEle->tPri, pPri, sizeof ( SP_PriPoolEle ) );
POOL_INSERT_TAIL ( pCoPool->pPoolHead, pPoolEle, tPointer );
pCoPool->uPoolCount++;
spWatchDogStatic ( PUT_ELE_SUC );
return 1;
}
///////////////////////////////////////////////////////////////////////////
// Reserved for Pool Test -- Start
///////////////////////////////////////////////////////////////////////////
/*
FILE *fp;
int main()
{
int nCh;
CO_PoolEle pOutGetPri;
CO_PoolEle pInGetPri;
CO_PoolEle pOutPutPri;
CO_PoolEle pInPutPri;
CO_PoolEle *pPri;
fp = fopen("log.txt" ,"w+");
if( NULL ==fp )
{
return 0;
}
spPoolInit();
pOutGetPri.tPri.ch = pInGetPri.tPri.ch = '0';
for( nCh = 0 ; nCh < 32 ; nCh ++ )
{
memset(&pOutGetPri , 0 , sizeof(CO_PoolEle));
memset(&pInGetPri , 0 , sizeof(CO_PoolEle));
memset(&pOutPutPri , 0 , sizeof(CO_PoolEle));
memset(&pInPutPri , 0 , sizeof(CO_PoolEle));
pOutPutPri.tPri.ch = 'A' + nCh;
spPoolPut( &pOutPutPri.tPri , pOutCoPool);
pInPutPri.tPri.ch = 'Z' - nCh;
spPoolPut( &pInPutPri.tPri , pInCoPool);
if( nCh && (nCh % 4 == 0) )
{
spPoolGet( &pOutGetPri.tPri , pOutCoPool);
}
if( nCh && (nCh % 6 == 0 ) )
{
spPoolGet( &pInGetPri.tPri , pInCoPool);
}
fprintf( fp ,"\npOutPoolHead: [%d]\n" , pOutCoPool->uPoolCount);
fprintf( fp ," Out Put : %c\n" , pOutPutPri.tPri.ch);
fprintf( fp ," Out Get : %c\n" , pOutGetPri.tPri.ch);
fprintf( fp ," List :");
POOL_FOREACH( pPri , pOutCoPool->pPoolHead , tPointer )
{
fprintf( fp ,"%c " ,pPri->tPri.ch );
}
fprintf( fp ,"\n");
fprintf( fp ,"\npInPoolHead: [%d]\n" , pInCoPool->uPoolCount);
fprintf( fp ," Put : %c\n" , pInPutPri.tPri.ch);
fprintf( fp ," Get : %c\n" , pInGetPri.tPri.ch);
fprintf( fp ," List :");
POOL_FOREACH( pPri , pInCoPool->pPoolHead , tPointer )
{
fprintf( fp ,"%c " ,pPri->tPri.ch );
}
fprintf( fp ,"\n\n\n");
}
fclose(fp);
getchar();
return 1;
}
*/
///////////////////////////////////////////////////////////////////////////
// Reserved for Pool Test -- End
///////////////////////////////////////////////////////////////////////////
/*@end@*/

283
plat/sccp/src/scoc_pri.c Normal file
View File

@@ -0,0 +1,283 @@
//////////////////////////////////////////////////
//Title : scoc_pri.c
//Auhtor : Liu Wei
//Desc : SCOC Primitive implemetation
//Created : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Note: The file is reserved , discard in Loose coupling mode now
///////////////////////////////////////////////////////////////////////////
#include "./include/sccp_pub.h"
#ifdef LOOSE_COUPLING_MODE //Loose coupling mode
#else
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_UnitDataReq ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_SEQ * pSEQ, SP_RO * pRO, SP_UD * pUD )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_UnitDataInd ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_UD * pUD )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_NoticeInd ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_RR * pRR, SP_UD * pUD )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ConnectReq ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_RCS * pRCS, SP_EDS * pEDS )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ConnectInd ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ConnectRsp ( SP_RA * pRA, SP_RCS * pRCS, SP_EDS * pEDS )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ConnectCfm ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DisconnectReq ( SP_RA * pRA, SP_REA * pREA, SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DisconnectInd ( SP_OR * pOR, SP_RA * pRA, SP_REA * pREA, SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DataReq ( CR SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DataInd ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DataAkReq ( u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_DataAkInd ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_EDataReq ( SP_UD * pUD, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_EDataInd ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ResetReq ( SP_REA * pREA, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ResetInd ( SP_OR * pOR, SP_REA * pREA, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ResetRsp ( u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_ResetCfm ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_InformReq ( SP_REA * pREA, SP_QOS * pQOS, u8 uCI )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_N_InformInd ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLi_MTP_TransferReq ( sccpmsg )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLi_MTP_TransferInd ( sccpmsg )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLi_MTP_ResumeInd ( PC )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLi_MTP_StatusInd ( PC )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spLi_MTP_UPUInd ( PC )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_ISUP_ReqType1 ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_ISUP_ReqType2 ( )
{
return;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
void spUi_ISUP_Relay ( )
{
return;
}
#endif

1007
plat/sccp/src/scrc.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
##----------------------------------------------------------##
## ##
## Universal Makefile for module Version : V1.4 ##
## ##
## Created : Wei Liu 07/04/11 ##
## Revision: [Last]Wei Liu 07/06/18 ##
## ##
##----------------------------------------------------------##
##---------------------------------------------------------------------##
##--------------------------------------
##
## 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 = sccptest
TYPE = app
DBUG_FLAGS_ADD =
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = exef
CFG = debug
PLT_LIB = sccp mtp3 m2ua \
snmp iptrans debug sccp public
APP_LIB =
LIB_ADD =
SRC_PATH = .
INC_PATH = .
PLT_PATH = ../../../../plat
APP_PATH = ../../../../app
OBJ_ADD =
TEST_OBJ_PATH =
##---------------------------------------------------------------------##
##--------------------------------------
##
## 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 = on
COVER_NEED =
COVER_REPORT_PATH = ./ut/ut_doc/output
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include $(MAKE_INCLUDE)/Makefile.rules

Binary file not shown.

View File

@@ -0,0 +1,8 @@
#application context name configure file for CAP
total data length=4
#application context name data
No.1:50 00 // gsmSSF to gsmSCF
No.2:51 02 // assist handoff gsmSSF to gsmSCF
No.3:52 02 // gsmSRF to gsmSCF
No.4:128 02 // gsmSRF to gsmSCF

View File

@@ -0,0 +1,36 @@
# operation code configure file for CAP
total data length=32
#operation code
No.1:00 04 5 // initial DP
No.2:16 02 5 // assist request instructions
No.3:17 02 20 // establish temporary connection
No.4:18 04 5 // disconnect forward connection
No.5:19 04 5 // connect to resource
No.6:20 04 5 // connect
No.7:22 04 5 // release call
No.8:23 04 5 // request report BCSM event
No.9:24 04 5 // event report BCSM
No.10:31 04 5 // continue
No.11:33 04 5 // reset timer
No.12:34 04 5 // furnish charging information
No.13:35 04 5 // apply charging
No.14:36 04 5 // apply charging report
No.15:44 04 5 // call information report
No.16:45 04 5 // call information request
No.17:46 04 5 // send charging information
No.18:47 04 60 // play announcement
No.19:48 01 60 // prompt and collect user information
No.20:49 04 5 // specialized resource report
No.21:53 04 5 // cancel
No.22:55 04 5 // activity test
No.23:60 04 5 // initial DPSMS
No.24:61 04 5 // Furnishing charging info.SMS
No.25:62 04 5 // connect DPSMS
No.26:63 04 5 // request SMS event
No.27:64 04 5 // event report SMS
No.28:65 04 5 // continue SMS
No.29:66 04 5 // release DPSMS
No.30:67 04 5 // reset timer DPSMS
No.31:176 04 5 // VPS to PPS
No.32:177 04 5 // PPS to VPS

View File

@@ -0,0 +1,215 @@
# Country code table configure file
#List the country code
0086; // China
0001; // Canada & USA
0007; // Kazakhstan & Kirighzia & Kyrgyzstan & Russia & Sakhalin & Tajikistan & Uzbekistan
0020; // Egypt
0027; // South Africa
0030; // Greece
0031; // Netherlands
0036; // Hungary
0039; // Italy
0040; // Bomania
0041; // Switzerland
0042; // Czech Republic & Slovakia
0043; // Austria
0044; // United Kingdom
0045; // Denmark
0046; // Sweden
0047; // Norway
0048; // Poland
0049; // Germany
0051; // Peru
0052; // South Korea
0053; // Cuba
0054; // Argentina
0055; // Brazil
0056; // Chile
0057; // Colombia
0058; // Venezuela
0060; // Malaysia
0061; // Australia
0062; // Indonesia
0063; // Philippines
0064; // New Zealand
0065; // Singapore
0066; // Thailand
0081; // Japan
0084; // Vietnam
0090; // Turkey
0091; // India
0092; // Pakistan
0093; // Afghanistan
0094; // Sri Lanka
0095; // Myanmar (Burma)
0098; // Iran
0212; // Morocco
0213; // Algeria
0216; // Tunisia
0218; // Libya
0220; // Gambia
0221; // Senegal Republic
0222; // Mauritania
0223; // Mali Republic
0224; // Guinea
0225; // Ivory Coast
0226; // Burkina Faso
0227; // Niger
0228; // Togo
0229; // Benin
0230; // Mauritius
0231; // Liberia
0232; // Sierra Leone
0233; // Ghana
0234; // Nigeria
0235; // Chad Republic
0236; // Central Africa Republic
0237; // Cameroon
0239; // Sao Tome
0240; // Equatorial Guinea
0241; // Gabon
0242; // Congo
0243; // Zaire
0244; // Angola
0245; // Guinea Bissau
0246; // Diego Garcia
0247; // Ascension Islands
0248; // Seychelles
0249; // Sudan
0250; // Rwanda
0251; // Ethiopia
0252; // Somalia
0253; // Djibouti
0254; // Kenya
0255; // Tanzania
0256; // Uganda
0257; // Burundi
0258; // Mozambigue
0259; // Zanzibar
0260; // Zambia
0261; // Madagascar
0262; // Reunion Island
0263; // Zimbabwe
0264; // Namibia
0265; // Malawi
0266; // Lesotho
0267; // Botswana
0268; // Swaziland
0269; // Comoros
0290; // St.Helena
0291; // Eritrea
0297; // Aruba
0298; // Faeroe Islands
0299; // Greenland
#2696 // Mayotte Island
0321; // Belgium
0331; // France
0339; // Monaco
0349; // Spain
0350; // Gibraltar
0351; // Portugal
0352; // Luxembourg
0353; // Ireland
0354; // Iceland
0355; // Albania
0356; // Malta
0357; // Cyprus
0358; // Finland
0359; // Bulgaria
0370; // Lithuania
0371; // Latvia
0372; // Estonia
0373; // Moldova
0374; // Armenia
0375; // Belarus
0376; // Andorra
0380; // Ukraine
0381; // Yugoslavia
0385; // Croatia
0386; // Slovenia
0387; // Bosnia Herzegovina
0389; // Macedonia
0395; // San Marino
0396; // Vatican City
0417; // Liechtenstein
0500; // Falkland Islands
0501; // Belize
0502; // Guatemala
0503; // EI Salvador
0504; // Honduras
0505; // Nicaragua
0506; // Costa Rica
0507; // Panama
0508; // St.Pierre
0509; // Haiti
0521; // Mexico Band 1
0522; // Mexico Band 2
0523; // Mexico Band 3
0524; // Mexico Band 4
0525; // Mexico Band 5
0526; // Mexico Band 6
0527; // Mexico Band 7
0528; // Mexico Band 8
0590; // Guadeloupe
0591; // Bolivia
0592; // Ecuador & Guyana
0594; // French Guiana
0595; // Paraguay
0596; // French Antilles
0597; // Suriname
0598; // Uruguay
0599; // Netherlands Antilles
#5399 // Guantanamo Bay
0670; // Saipan
0671; // Guam
0672; // Antarctica(Casey) & Antarctica(Scott) & Christmas/Cocos
0673; // Brunei
0674; // Nauru
0675; // Papau New Guinea
0676; // Tonga
0677; // Solomon Islands
0678; // Vanuatu
0679; // Fiji Islands
0680; // Palau
0681; // Wallis/Futuna
0682; // Cook Island
0683; // Niue Island
0684; // American Samoa
0685; // West Samoa
0686; // Kiribati
0687; // New Caledonia
0688; // Tuvalu Islands
0689; // French Polynesia
0691; // Micronesia
0692; // Marshall Islands
#6723 // Norfolk Island
0787; // Puerto Rico
0809; // Anguilla & Antigua & Bahamas & Barbados & Bermuda......
0850; // North Korea
0852; // Hong Kong
0853; // Macao
0855; // Cambodia
0856; // Laos
0868; // Trinidad/Tobago
0880; // Bangladesh
0886; // Taiwan
0960; // Maldives
0961; // Lebanon
0962; // Jordan
0963; // Syria
0964; // Iraq
0965; // Kuwait
0966; // Saudi Arabia
0967; // Yemen Arab Rep.
0968; // Oman
0971; // United Arab Emirates
0972; // Israel
0973; // Bahrain
0974; // Qatar
0975; // Bhutan
0976; // Mongolia
0977; // Nepal
0994; // Azerbaijan
0995; // Georgia

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#HLR/AUC/EIR system configure file
#IP info of SMSC
hlr-0=172.18.234.1;
#hlr-1=172.18.133.1;
hlr-1=172.54.240.147;

View File

@@ -0,0 +1,20 @@
******************
* HELP PAGE *
******************
Welcome to DEBUG MONITOR.
Press 's' or 'S' to enter "SUB MODULE SELECTION PAGE".
In "SUB MODULE SELECTION PAGE",
Press 'x' or 'X' to return "HELP PAGE",
Press 'a-p' or 'A-P' to select sub module.
In each sub module, Press '0-9' and 'a-f' to select pages.
There are two methods to use Debug,
1. Serial Port, use PC-to-PC serial line.
2. Telnet, use "telnet dst_host_ip 4965".
$

Binary file not shown.

View File

@@ -0,0 +1,25 @@
#ipconfig for pps
4950=UDP,6,DIRECT
4951=UDP,0,BUFFER
4952=UDP,0,BUFFER
4953=UDP,0,BUFFER
4954=UDP,0,BUFFER
4955=UDP,3,BUFFER
4956=UDP,3,BUFFER
4957=UDP,4,BUFFER
4958=UDP,0,BUFFER
4959=UDP,0,BUFFER
4960=UDP,4,BUFFER
4961=UDP,0,BUFFER
4962=UDP,0,BUFFER
4963=UDP,0,BUFFER
4964=UDP,0,BUFFER
4965=TCP,6,BUFFER
4966=UDP,2,DIRECT
4967=UDP,4,DIRECT
4968=UDP,0,BUFFER
4969=UDP,0,BUFFER
4970=UDP,0,BUFFER
4971=UDP,0,BUFFER
4972=UDP,0,BUFFER
4973=UDP,0,BUFFER

View File

@@ -0,0 +1,42 @@
#application context name configure file
total data length=36
#application context name data
No.1:01 03 // network location update
No.2:02 03 // location cancel
No.3:03 03 // roaming number enquiry
No.4:05 03 // location info retrieval
No.5:10 02 // reset context
No.6:11 02 // handover control
No.7:13 02 // equipment management
No.8:14 02 // info retrieval
No.9:15 02 // inter VLR info retrieval
No.10:16 03 // subscriber data management
No.11:17 03 // tracing
No.12:18 02 // network functional SS
No.13:19 02 // network unstructured SS
No.14:20 03 // short message gateway
No.15:21 03 // short message MO relay
No.16:23 02 // short message alert
No.17:24 03 // short message waiting data management
No.18:25 03 // mobile terminating short message relay
No.19:26 02 // imsi retrieval
No.20:27 03 // MS purging
No.21:28 03 // subscriber info enquiry
No.22:29 03 // any time info enquiry
No.23:06 03 // call control transfer
No.24:36 03 // invocation notification
No.25:12 03 // sIWFS allocation
No.26:31 03 // group call control
No.27:32 03 // GPRS location update
No.28:33 03 // GPRS location info retrieval
No.29:34 03 // failure report
No.30:35 03 // GPRS notify
No.31:07 03 // reporting
No.32:08 03 // call completion
No.33:200 02 // security triplets (MAP-H defined by Meng Xiaozhen)
No.34:201 02 // subscriber interrogate (MAP-H defined by Meng Xiaozhen)
No.35:202 02 // HLR subscriber management (MAP-H defined by Meng Xiaozhen)
No.36:203 02 // HLR ping AUC (MAP-H defined by Meng Xiaozhen reserved)
NO.37:09 01 // Send parameter

View File

@@ -0,0 +1,76 @@
# operation code configure file
total data length=72
#operation code
No.1:02 01 20 // update location
No.2:03 01 10 // cancel location
No.3:67 01 20 // purge mobile station
No.4:55 01 05 // send identification
No.5:68 01 20 // prepare handover
No.6:29 03 108000 // send end signal
No.7:33 04 05 // process access signalling
No.8:34 04 05 // forward access signalling
No.9:69 01 20 // prepare subsequent handover
No.10:56 01 20 // send authentication info
No.11:43 01 20 // check IMEI
No.12:07 01 20 // insert subscriber data
No.13:08 01 20 // delete subscriber data
No.14:37 04 20 // reset
No.15:38 04 20 // forward check ss indication
No.16:57 01 20 // restore data
No.17:50 01 20 // active trace mode
No.18:51 01 20 // deactive trace mode
No.19:58 01 20 // send imsi
No.20:22 01 20 // send routing info
No.21:04 01 20 // provide roaming number
No.22:06 01 20 // resume call handling
No.23:31 01 20 // provide SIWFS number
No.24:32 01 20 // SIWFS signalling modify
No.25:73 01 20 // set report state
No.26:74 01 20 // status report
No.27:75 01 60 // remote user free
No.28:10 01 20 // register ss
No.29:11 01 20 // erase ss
No.30:12 01 20 // activate ss
No.31:13 01 20 // deactivate ss
No.32:14 01 20 // interrogate ss
No.33:59 01 600 // process unstructure ss request
No.34:60 01 60 // unstructure ss request
No.35:61 01 60 // unstructure ss notify
No.36:17 01 60 // register password
No.37:18 03 20 // get password
No.38:76 01 20 // register cc entry
No.39:77 01 20 // erase cc entry
No.40:45 01 20 // send routing info for sm
No.41:46 01 60 // mo forward sm
No.42:44 01 60 // mt forward sm
No.43:47 01 05 // report sm delivery status
No.44:63 04 05 // inform service centre
No.45:64 01 05 // alert service center
No.46:66 01 05 // ready for sm
No.47:70 01 20 // provider subscriber info
No.48:71 01 20 // any time interrogation
No.49:72 01 20 // ss invocatin notification
No.50:39 01 20 // prepare group call
No.51:40 03 108000 // send group call end signal
No.52:41 04 05 // process group call signalling
No.53:42 04 05 // forward group call signalling
No.54:23 01 20 // update GPRS location
No.55:24 01 20 // send routing info for GPRS
No.56:25 01 20 // failure report
No.57:26 01 20 // note ms present for GPRS
No.58:200 01 05 // security triplets (MAP-H defined by Meng Xiaozhen)
No.59:201 01 05 // interrogate subscriber (MAP-H defined by Meng Xiaozhen)
No.60:202 01 05 // hlr create subscriber (MAP-H defined by Meng Xiaozhen)
No.61:203 01 05 // hlr delete subscriber (MAP-H defined by Meng Xiaozhen)
No.62:204 01 05 // hlr ping auc (MAP-H defined by Meng Xiaozhen reserved)
No.63:09 01 20 // send parameters
No.64:48 01 20 // not subscriber present
No.65:19 01 20 // process unstructure SS data
No.66:54 01 20 // beging subscriber activity
No.67:28 01 20 // perform handover
No.68:30 01 20 // perform subsequence handvoer
No.69:35 01 20 // note internal handover
No.70:54 01 20 // beging subscriber activity
No.71:49 01 20 // alert service center without result
No.72:52 01 20 // trace subscriber activity

View File

@@ -0,0 +1,17 @@
*******************
* MENU PAGE *
*******************
a -- IPTR m -- MNP
b -- MTP3 n -- DEBUG
c -- SCCP o -- AUC
d -- TCAP p -- SMPP
e -- XAPP r -- M2UA
f -- MSC s -- BICC
g -- VLR t -- SIP
h -- EIR u -- ISUP
i -- HLR v -- Reserved
j -- SMSC w -- SCTP
k -- PPS y -- ISDN
l -- SNMP z -- Reserved

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -0,0 +1,37 @@
# /etc/profile
# System wide environment and startup programs
# Functions and aliases go in /etc/bashrc
PATH=".:$PATH:/sbin:/usr/sbin:/usr/X11R6/bin:/etc/rc.d/init.d:/usr/local/wxc2/bin"
PATH=/usr/java/jdk1.3/bin:$PATH
ulimit -c 80000
if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
umask 002
else
umask 022
fi
USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
JAVA_COMPILER=javacomp ; export JAVA_COMPILER
LD_LIBRARY_PATH=/usr/local/mysql/lib ; export LD_LIBRARY_PATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done
unset i
PATH=/usr/local/wxc2/bin:$PATH

View File

@@ -0,0 +1,26 @@
#SCCP Config file (R8V0_03)
[Local Node]
#ssn NetID msisdn ip0 ip1
4 2 - 172.18.128.1 172.18.129.1
6 2 8675557122002 172.18.199.1 -
7 2 8675557122001 172.18.198.1 -
8 2 8675599999999 172.18.234.3 172.18.99.1
9 2 86755920005 172.18.132.1 172.18.99.1
10 2 86755920004 172.18.132.1 172.18.99.1
11 2 86755920006 172.18.132.1 172.18.99.1
19 2 86755920007 172.18.132.1 172.18.99.1
20 2 86755920008 172.18.132.1 172.18.99.1
21 2 86755920009 172.18.132.1 172.18.99.1
22 2 867559000213 172.18.132.1 -
146 2 86755920011 172.18.132.1 172.18.99.1
147 2 86755920010 172.18.132.1 172.18.99.1
254 2 - 172.18.132.1 172.18.99.1
[GTT_Table]
#No NP StartDigits EndDigits NI SPC SSN RI AI S E N Rep
0 6 460020000000000 460029999999999 2 000028 6 0 7
#1 1 8675590000000 8675599999998 2 000028 6 0 7
[RL_SSN]
#NetID DPC SSN

View File

@@ -0,0 +1,2 @@
172.18.199.1
2000

View File

@@ -0,0 +1,21 @@
# This file defines the SMSC CSTA row
# The max number of row is 20
# Attention: When you want to define the Entity name, the name of "MS" "All" and "Other" is reserved
# define the entity who send short message to SMSC
Receive from:
MS
PPS
VMS
#VMS+PPS
Other
#All
# define the entity who receive short message from SMSC
Send to:
MS
PPS
VMS
#VMS+PPS
Other
#All

Binary file not shown.

View File

@@ -0,0 +1,5 @@
#SMSC system configure file
#IP info of SMSC
wxc2-0=172.18.98.1;
wxc2-1=172.18.99.1;

Binary file not shown.

View File

@@ -0,0 +1 @@
pps-1=172.18.98.1;

View File

@@ -0,0 +1,4 @@
WXC2 procedure exit log
Time: Fri Nov 5 05:27:51 2004
Now module: MSC

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,192 @@
#include "../../src/include/sccp.h"
#include "signal.h"
#include <unistd.h>
#ifdef _WXC_FSM_TEST
#define spLogFsm printf
#else
#define spLogFsm
#endif
static struct itimerval itimer, old_itimer;
u8 sccp_timer_flag;
void mtp3_timer ( );
void send_data ( );
void showbuf ( BYTE * buf, int len )
{
int i;
for ( i = 0; i < len; i++ )
printf ( "%X", buf[i] );
printf ( "\n" );
}
void showbuf2 ( BYTE * buf, int len )
{
int i;
for ( i = 0; i < len; i++ )
printf ( "%02X", buf[i] );
printf ( "\n" );
}
void on_data ( )
{
SCLC_MSG clmsg;
SCCP_ADDR addr;
int len, len2;
if( ( len = sclc_receive ( &clmsg, 0 ) ) > 0 )
{
showbuf2 ( clmsg.msg, clmsg.msglen );
memcpy ( &addr, &clmsg.src_addr, sizeof ( SCCP_ADDR ) );
memcpy ( &clmsg.src_addr, &clmsg.dst_addr, sizeof ( SCCP_ADDR ) );
memcpy ( &clmsg.dst_addr, &addr, sizeof ( SCCP_ADDR ) );
len2 = sclc_send ( &clmsg );
if( len2 == -1 )
printf ( "fail to send message" );
}
}
u8 sccp_20ms_flag = 0;
void On_Timer ( )
{
//on_data ( );
sccp_20ms_flag++;
sccp_timer_flag++;
spLogFsm("pos plat iprtans start \r\n");
iptrans_timer ( );
spLogFsm("pos plat mpt3 start \r\n");
mtp3_proc ( );
spLogFsm("pos plat sccp start \r\n");
spWxcBackTrace();
sccp_timer ( );
spLogFsm("pos plat sccp over \r\n");
spWxcBackTrace();
if( sccp_20ms_flag >= 2 )
{
spWxcBackTrace();
sccp_20ms_flag = 0;
spLogFsm("pos plat debug start \r\n");
debug_rt ( );
spLogFsm("pos plat snmp start \r\n");
snmp_timer ( );
spLogFsm("pos plat heartbeat start \r\n");
heartbeat_timer ( );
spLogFsm("pos plat end start \r\n");
spWxcBackTrace();
}
}
void SetTimer ( )
{
struct sigaction act;
act.sa_handler = On_Timer;
sigemptyset ( &act.sa_mask );
act.sa_flags = 0;
if( sigaction ( SIGALRM, &act, NULL ) < 0 )
{
perror ( "Produce Sigaction" );
exit ( 1 );
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 10 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 10 * 1000;
if( setitimer ( ITIMER_REAL, &itimer, &old_itimer ) != 0 )
{
printf ( "Setting Timer error! \n" );
exit ( 1 );
}
}
void spUserInit( )
{
}
void spUserFsm( )
{
}
u8 delay = 5;
u8 main_state = 0;
void system_init ( )
{
sleep ( 3 );
debug_init ( );
iptrMainInit ( );
snmp_init ( 4957 );
heartbeat_init ( 0x0188 );
mtp_shm_init ( );
sccp_init ( );
sccp_20ms_flag = 0;
sccp_timer_flag = 0;
}
int main ( )
{
system_init();
SetTimer ( );
while ( 1 )
{
usleep ( 1 );
if( sccp_timer_flag >= delay )
{
sccp_timer_flag = 0;
switch ( main_state )
{
case 0:
ulInit( );
main_state = 1;
break;
case 1:
spLogFsm("sccp_test.c: main->ulsapfsm in \n");
ulSapFsm( );
spLogFsm("sccp_test.c: main->ulsapfsm out \n");
break;
}
}
}
return 1;
}
void send_data ( )
{
SCLC_MSG clmsg;
BYTE value[100] = { 1, 2, 3, 4, 5, 6 };
BYTE number[20] = { 0x68, 0x57, 0x55, 0x17, 0x32, 0x00, 0xF3 };
clmsg.msglen = 6;
memcpy ( clmsg.msg, value, clmsg.msglen );
clmsg.src_addr.DPC = 0x111111;
clmsg.src_addr.SSN = 8;
clmsg.src_addr.GTI = 0;
clmsg.dst_addr.DPC = 0;
clmsg.dst_addr.SSN = 8;
clmsg.dst_addr.GTI = 4;
clmsg.dst_addr.NP = 1;
clmsg.dst_addr.NAI = 4;
clmsg.dst_addr.len = 13;
clmsg.dst_addr.NetID = 0;
memcpy ( clmsg.dst_addr.GTAI, number, 7 );
if( sclc_send ( &clmsg ) == -1 )
printf ( "fail to send message\n" );
}

View File

@@ -0,0 +1,616 @@
//////////////////////////////////////////////////
//Title : fsm_test.c
//Auhtor : Liu Wei
//Desc : sccp fsm testing
//Created : 2007-05-25
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "../../src/include/sccp.h"
#include "../../src/include/sccp_pub.h"
#include "../../src/include/scoc_if.h"
extern unsigned long spLogDebug_mask ;
extern BYTE sccpFilterIndex ;
extern BYTE mtp_asciin_buf[80];
#ifdef _WXC_FSM_TEST
#define spLogFsm printf
#else
#define spLogFsm
#endif
typedef enum UL_ORG_STATE
{
ORG_IDLE = 1,
ORG_CR, //CM LU
ORG_CC, //CC
ORG_LUR, //lu reject
ORG_CLCD, //clean command
ORG_CLCE, //clean complete
ORG_DISCONN,
ORG_SEND_UDT, //PRN
ORG_RECV_UDT, //PRN ack
}
UL_OrgState;
typedef enum UL_DST_STATE
{
DST_IDLE = 1,
DST_CR, //CM LU
DST_CC, //CC
DST_LUR, //lu reject
DST_CLCD, //clean command
DST_CLCE, //clean complete
DST_DISCONN,
DST_RECV_UDT, //PRN
DST_SEND_UDT, //PRN ack
}
UL_DstState;
typedef struct SCCP_UL
{
u8 uUlSide;
u8 uUlState;
u32 uUlTestStartTimer;
u32 uUlStateInterval;
u32 uWaitTimer;
u32 wConnId;
int nPort;
int nRemoteIP;
int nSock;
}
SP_UL;
SP_UL tUl;
#define aifprn_udt_msg_len 0x52
static u8 aifprn_udt_msg[] = {
0x51, 0x62, 0x4f,
0x48, 0x04, 0x01, 0x62, 0x00, 0x35, 0x6b, 0x1e,
0x28, 0x1c, 0x06, 0x07, 0x00, 0x11, 0x86, 0x05,
0x01, 0x01, 0x01, 0xa0, 0x11, 0x60, 0x0f, 0x80,
0x02, 0x07, 0x80, 0xa1, 0x09, 0x06, 0x07, 0x04,
0x00, 0x00, 0x01, 0x00, 0x03, 0x02, 0x6c, 0x27,
0xa1, 0x25, 0x02, 0x01, 0x80, 0x02, 0x01, 0x04,
0x30, 0x1d, 0x80, 0x08, 0x64, 0x00, 0x92, 0x00,
0x00, 0x00, 0x83, 0xf4, 0x81, 0x08, 0x91, 0x44,
0x57, 0x55, 0x06, 0x00, 0x00, 0xf0, 0x82, 0x07,
0x91, 0x68, 0x57, 0x95, 0x00, 0x83, 0xf4,
};
#define aifprnak_udt_msg_len 0x4b
static u8 aifprnak_udt_msg[] = {
0x4a, 0x64, 0x48,
0x49, 0x04, 0x01, 0x62, 0x00, 0x35, 0x6b, 0x2a,
0x28, 0x28, 0x06, 0x07, 0x00, 0x11, 0x86, 0x05,
0x01, 0x01, 0x01, 0xa0, 0x1d, 0x61, 0x1b, 0x80,
0x02, 0x07, 0x80, 0xa1, 0x09, 0x06, 0x07, 0x04,
0x00, 0x00, 0x01, 0x00, 0x03, 0x02, 0xa2, 0x03,
0x02, 0x01, 0x00, 0xa3, 0x05, 0xa1, 0x03, 0x02,
0x01, 0x00, 0x6c, 0x14, 0xa2, 0x12, 0x02, 0x01,
0x80, 0x30, 0x0d, 0x02, 0x01, 0x04, 0x04, 0x08,
0x91, 0x44, 0x57, 0x25, 0x31, 0x06, 0x00, 0xf6
};
#define aiflu_cr_msg_len 0x25
static u8 aiflu_cr_msg[] = {
0x0f, 0x23, 0x00, 0x21, 0x57,
0x05, 0x08, 0x00, 0x57, 0xf0, 0x10, 0x0b, 0xb9,
0x0a, 0xfb, 0x17, 0x12, 0x05, 0x08, 0x70, 0x45,
0xf0, 0x10, 0x00, 0x01, 0x30, 0x08, 0x59, 0x04,
0x10, 0x25, 0x00, 0x20, 0x30, 0x62, 0x21, 0x01,
};
#define aifcc_dt1_msg_len 0x00
static u8 aifcc_dt1_msg[] = {
};
#define aiflurj_dt1_msg_len 0x07
static u8 aiflurj_dt1_msg[] = {
0x06, 0x01, 0x00 , 0x03, 0x05, 0x04, 0x0b
};
#define aifclcd_dt1_msg_len 0x07
static u8 aifclcd_dt1_msg[] = {
0x06, 0x00, 0x04 , 0x20, 0x04, 0x01, 0x09
};
#define aifclce_dt1_msg_len 0x05
static u8 aifclce_dt1_msg[] = {
0x03, 0x00, 0x01 , 0x21, 0x00
};
#define aiflu_rlsd_msg_len 0x00
static u8 aiflu_rlsd_msg[] = {
};
#define aiflu_rlc_msg_len 0x00
static u8 aiflu_rlc_msg[] = {
};
int get_socket(u_int32_t ip, int port)
{
int sock;
int on = 1;
DWORD cmdarg = 1;
struct sockaddr_in sin_addr;
sin_addr.sin_family = AF_INET;
sin_addr.sin_port = htons(port);
sin_addr.sin_addr.s_addr = htonl(INADDR_ANY);
if(!(sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
perror("Get socket");
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if(bind(sock, (struct sockaddr *)&sin_addr, sizeof(struct sockaddr_in)) != 0)
{
perror("bind");
return 0;
}
ioctl(sock, FIONBIO, &cmdarg);
return (sock);
}
int ulRecv( u8 *pBuff )
{
struct sockaddr_in sin_addr;
int addr_len;
return recvfrom(tUl.nSock, (char *)pBuff, 256, 0, (struct sockaddr *)&sin_addr, &addr_len);
}
void ulSend( u8 *pBuff , u8 uLen )
{
struct sockaddr_in sin_addr;
WxcAssert( uLen < 255 , "ulSend too long msg");
sin_addr.sin_family = AF_INET;
sin_addr.sin_port = htons(tUl.nPort);
sin_addr.sin_addr.s_addr = tUl.nRemoteIP;
sendto(tUl.nSock, (char *)pBuff, 256, 0, (struct sockaddr *)&sin_addr, sizeof(struct sockaddr));
}
int ulSpecPeer()
{
char msg[256];
memset(msg, 0, 256);
ulRecv(msg);
if( msg[0] )
{
printf("Recv test msg: %s\r\n", msg);
if( !strcmp(msg, "SCCP_TEST") )
{
tUl.uUlSide = 0;
printf("slave mode\r\n");
ulSend("SCCP_OK" , 7);
tUl.uUlStateInterval=0;
return 1;
}
else if( !strcmp(msg, "SCCP_OK") )
{
tUl.uUlSide = 1;
printf("master mode\r\n");
tUl.uUlStateInterval=0;
return 1;
}
}
if( tUl.uUlStateInterval++ % 200 )
{
ulSend("SCCP_TEST" , 9);
}
return 0;
}
void ulInit()
{
int ip;
struct in_addr sin_addr;
sin_addr.s_addr = tUl.nRemoteIP;
memset(&tUl, 0, sizeof(SP_UL));
tUl.uUlSide = 1;
tUl.nPort = 6999;
ip = GetLocalIP();
tUl.nRemoteIP = ( ip ^ 0x00010000 );
tUl.uWaitTimer = 20;
memcpy( &sin_addr , &tUl.nRemoteIP , 4);
printf("Remote ip : %s Start timer :%d \n" , inet_ntoa(sin_addr) ,tUl.uWaitTimer );
tUl.nSock = get_socket(tUl.nRemoteIP, tUl.nPort);
printf("get sock :%d \r\n",tUl.nSock);
register_ssn ( 0xfe, 3 );
mtp_asciin_buf[0] = 1;
strcpy( &mtp_asciin_buf[1] , "log all" );
printf("sizeof[sizeof(CO_ConnSection)* 4096]=%d\n", sizeof(CO_ConnSection)* 4096);
}
void ulLogMsg ( SP_UiPriPara * pSpPri, u8 uDirection , SP_UD *pUD )
{
char *pStr;
spGetUlPrimitiveStr ( pSpPri->uUiPri, pStr );
if( uDirection )
{
spLogDebug ( SCCPDB_AIF , "UL=>SP : %s ", pStr );
}
else
{
spLogDebug ( SCCPDB_AIF , "UL<=SP : %s ", pStr );
}
if( NULL != pUD )
{
spShowBCD ( 1, pUD->aUserData, pUD->uDataLen );
}
}
extern void spLog ( char *info );
void ulLogState ( u8 uSide , u8 *pStr )
{
char aStr[256];
if( uSide )
sprintf(aStr ,"]Org Node[: %s state \n" , pStr);
else
sprintf(aStr ,"]Dst Node[: %s state \n" , pStr);
spLog(aStr);
}
void ul_sccp_addr( SCCP_ADDR *pAddr )
{
memset( pAddr , 0 , sizeof(SCCP_ADDR) );
pAddr->ip = tUl.nRemoteIP;
pAddr->DPC = 40;
pAddr->NetID = 2;
pAddr->SSN = 254;
pAddr->RI = RI_SSN;
pAddr->GTI = 0;
pAddr->AI = 3;
return;
}
void ulSapFsm ( )
{
SP_UiPriPara tSpPri;
SP_UiPriUnion *pUPri;
pUPri = &tSpPri.tPriUnion;
if( !tUl.uUlState )
{
if( ulSpecPeer() )
{
printf("----------------------OK------------------\r\n");
tUl.uUlState++;
}else
{
return;
}
}
sccpFilterIndex = 0;
spLogDebug_mask = 0xFFFFFFFF;
//printf("Side : %d state : %d \n",tUl.uUlSide ,tUl.uUlState );
if( tUl.uUlSide )
{
switch ( tUl.uUlState )
{
case ORG_IDLE:
break;
case ORG_SEND_UDT: //PRN
tSpPri.uUiPri = N_UNITDATA_REQ;
ul_sccp_addr ( &pUPri->tPriNUDataReq.tCDA );
ul_sccp_addr ( &pUPri->tPriNUDataReq.tCGA );
pUPri->tPriNUDataReq.tRO.uRO = 1;
pUPri->tPriNUDataReq.tUD.uDataLen = aifprn_udt_msg_len;
memcpy ( &pUPri->tPriNUDataReq.tUD.aUserData, aifprn_udt_msg, pUPri->tPriNUDataReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNUDataReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while ORG_SEND_UDT state" );
ulLogState( tUl.uUlSide ,"ORG_SEND_UDT" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
return;
case ORG_RECV_UDT: //PRN ack
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_UNITDATA_IND, "ul recv pri error while ORG_RECV_UDT state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNUDataInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_RECV_UDT" );
return ;
}
break;
case ORG_CR: //CM LU
tSpPri.uUiPri = N_CONNECT_REQ;
ul_sccp_addr ( &pUPri->tPriNConnReq.tCDA );
pUPri->tPriNConnReq.uOptFlag = 0x08;
pUPri->tPriNConnReq.tUD.uDataLen = aiflu_cr_msg_len;
memcpy ( &pUPri->tPriNConnReq.tUD.aUserData, aiflu_cr_msg, pUPri->tPriNConnReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNConnReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while ORG_CR state" );
tUl.wConnId = tSpPri.wConnId;
WxcAssert ( tUl.wConnId < CO_CS_MPORT, "wConnId error " );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_CR" );
return;
case ORG_CC: //CC
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_CONNECT_CFM, "ul recv pri error while ORG_CC state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNConnCfm.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_CC" );
return ;
}
break;
case ORG_LUR: //lu reject
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_DATA_IND, "ul recv pri error while ORG_LUR state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNDataInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_LUR" );
return ;
}
break;
case ORG_CLCD: //clean command
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_DATA_IND, "ul recv pri error while ORG_CLCD state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNDataInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_CLCD" );
return ;
}
break;
case ORG_CLCE: //clean complete
tSpPri.uUiPri = N_DATA_REQ;
pUPri->tPriNDataReq.tUD.uDataLen = aifclce_dt1_msg_len;
memcpy ( &pUPri->tPriNDataReq.tUD.aUserData, aifclce_dt1_msg, pUPri->tPriNDataReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNDataReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while ORG_CLCE state" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_CLCE" );
return;
case ORG_DISCONN:
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_DISCONNECT_IND, "ul recv pri error while ORG_RLSD state" );
ulLogMsg ( &tSpPri, 0 , NULL );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"ORG_CLCE" );
return ;
}
break;
default:
printf ( "\n\n\n======================SP Org Test End=================\n\n\n" );
exit(1);
break;
}
if( ORG_IDLE == tUl.uUlState )
{
if( tUl.uUlTestStartTimer++ >= tUl.uWaitTimer )
{
printf ( "\n\n\n======================SP Org Test Start=================\n\n\n" );
tUl.uUlState++;
}
}
else
{
if( tUl.uUlStateInterval++ >= 200 )
{
//WxcAssert ( tUl.uUlState != ORG_RECV_UDT, "ORG_RECV_UDT state timer out" );
//WxcAssert ( tUl.uUlState != ORG_CC, "ORG_CC state timer out" );
//WxcAssert ( tUl.uUlState != ORG_LUR, "ORG_LUR state timer out" );
//WxcAssert ( tUl.uUlState != ORG_CLCD, "ORG_CLCD state timer out" );
//WxcAssert ( tUl.uUlState != ORG_DISCONN, "ORG_DISCONN state timer out" );
tUl.uUlStateInterval = 0;
}
}
}
else
{
switch ( tUl.uUlState )
{
case DST_IDLE:
break;
case DST_RECV_UDT: //PRN
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_UNITDATA_IND, "ul recv pri error while DST_RECV_UDT state" );
ulLogMsg ( &tSpPri, 0 ,&pUPri->tPriNUDataInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_RECV_UDT" );
return ;
}
break;
case DST_SEND_UDT: //PRN ack
tSpPri.uUiPri = N_UNITDATA_REQ;
ul_sccp_addr ( &pUPri->tPriNUDataReq.tCDA );
ul_sccp_addr ( &pUPri->tPriNUDataReq.tCGA );
pUPri->tPriNUDataReq.tRO.uRO = 1;
pUPri->tPriNUDataReq.tUD.uDataLen = aifprnak_udt_msg_len;
memcpy ( &pUPri->tPriNUDataReq.tUD.aUserData, aifprnak_udt_msg, pUPri->tPriNUDataReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNUDataReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while DST_SEND_UDT state" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_SEND_UDT" );
return;
case DST_CR: //CM LU
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( (tSpPri.uUiPri == N_CONNECT_IND), "ul recv pri error while DST_CR state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNConnInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_CR" );
return ;
}
break;
case DST_CC: //CC
tSpPri.uUiPri = N_CONNECT_RSP;
tSpPri.wConnId = tUl.wConnId;
pUPri->tPriNConnRsp.tUD.uDataLen = aifcc_dt1_msg_len;
pUPri->tPriNConnRsp.uOptFlag = 0x00;
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNConnRsp.tUD );
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while DST_CC state" );
WxcAssert ( tUl.wConnId < CO_CS_MPORT, "wConnId error " );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_CC" );
return;
case DST_LUR: //lu reject
tSpPri.uUiPri = N_DATA_REQ;
tSpPri.wConnId = tUl.wConnId;
pUPri->tPriNDataReq.tUD.uDataLen = aiflurj_dt1_msg_len;
memcpy ( &pUPri->tPriNDataReq.tUD.aUserData, aiflurj_dt1_msg, pUPri->tPriNDataReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 , &pUPri->tPriNDataReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while DST_LUR state" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_LUR" );
return;
case DST_CLCD: //clean command
tSpPri.uUiPri = N_DATA_REQ;
tSpPri.wConnId = tUl.wConnId;
pUPri->tPriNDataReq.tUD.uDataLen = aifclcd_dt1_msg_len;
memcpy ( &pUPri->tPriNDataReq.tUD.aUserData, aifclcd_dt1_msg, pUPri->tPriNDataReq.tUD.uDataLen );
ulLogMsg ( &tSpPri, 1 ,&pUPri->tPriNDataReq.tUD);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while DST_CLCD state" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_CLCD" );
return;
case DST_CLCE: //clean complete
if( SpSubmit ( &tSpPri , 3) )
{
WxcAssert ( tSpPri.uUiPri == N_DATA_IND, "ul recv pri error while DST_CLCE state" );
ulLogMsg ( &tSpPri, 0 , &pUPri->tPriNDataInd.tUD);
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_CLCE" );
return ;
}
break;
case DST_DISCONN:
tSpPri.uUiPri = N_DISCONNECT_REQ;
tSpPri.wConnId = tUl.wConnId;
pUPri->tPriNDisconnReq.eREA = REA_UDISC_EUF;
pUPri->tPriNDisconnReq.tUD.uDataLen = aiflu_rlsd_msg_len;
pUPri->tPriNDisconnReq.uOptFlag = 0x00;
ulLogMsg ( &tSpPri, 1 , NULL);
WxcAssert ( PostSp ( &tSpPri ), "ul post pri error while DST_DISCONN state" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
ulLogState( tUl.uUlSide ,"DST_DISCONN" );
return;
default:
printf ( "\n\n\n======================SP Dst Test End=================\n\n\n" );
exit(1);
break;
}
if( DST_IDLE == tUl.uUlState )
{
if( tUl.uUlTestStartTimer++ >= tUl.uWaitTimer )
{
printf ( "\n\n\n======================SP Dst Test Start=================\n\n\n" );
tUl.uUlState++;
tUl.uUlStateInterval = 0;
}
}
else
{
if( tUl.uUlStateInterval++ >= 200 )
{
//WxcAssert ( tUl.uUlState != DST_RECV_UDT, "DST_RECV_UDT state timer out" );
//WxcAssert ( tUl.uUlState != DST_CR, "DST_CR state timer out" );
//WxcAssert ( tUl.uUlState != DST_CLCE, "DST_CLCE state timer out" );
tUl.uUlStateInterval = 0;
}
}
}
}
void ll_cr ( )
{
}
void ll_cc ( )
{
}
void ll_cref ( )
{
}
void ll_rlsd ( )
{
}
void ll_rlc ( )
{
}
void ll_udt ( )
{
}
void ll_dt1 ( )
{
}
void ll_sap ( )
{
}