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/public_bak/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 = public
TYPE = plat
DBUG_FLAGS_ADD =
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = lib
CFG = debug
PLT_LIB = -DDEBUG
APP_LIB =
LIB_ADD =
SRC_PATH = ./src
INC_PATH = ./src/include
PLT_PATH = ../../plat
APP_PATH = ../../mss
OBJ_ADD =
TEST_OBJ_PATH =
PREPROC_CMD =
POSTPROC_CMD =
##---------------------------------------------------------------------##
##--------------------------------------
##
## Make configuration(Customer define)
##
##--------------------------------------
## CCFLAG_SWITCH = on/off => gcc flag show on/off
## COVER_NEED = yes/no => PTF cover report needed
## COVER_REPORT_PATH = [path ] => PTF cover report path
CCFLAG_SWITCH = off
COVER_NEED = no
COVER_REPORT_PATH = ./output
MAKE_INCLUDE = $(HOME)/ems.git/include
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include $(MAKE_INCLUDE)/Makefile.rules

941
plat/public_bak/src/asn1.c Normal file
View File

@@ -0,0 +1,941 @@
/********************************************************************/
/*Title: asn1.c */
/*Descr: ASN.1 Encoding/Decoding Module */
/*Author: Liang Hanxi */
/*Create: 2002-1-15 */
/*Version: */
/*Modify: 2002-10-22 */
/********************************************************************/
#include "./include/asn1.h"
#include <string.h>
#include <ctype.h>
#include <stdio.h>
/*@ignore@*/
void AsnEncode(u_char *msg_buf,u_int maxlen,ASN_BUF *asnbuf)
{
asnbuf->msgbuf=msg_buf;
memset(msg_buf,0,2);
asnbuf->msglen=0;
asnbuf->maxlen=maxlen;
}
void asn_encode(u_char *msg_buf,ASN_BUF *asnbuf)
{
AsnEncode(msg_buf,256,asnbuf);
}
void asn_encode_v3(u_char *msg_buf,u_int maxlen,ASN_BUF *asnbuf)
{
AsnEncode(msg_buf,maxlen,asnbuf);
}
int add_tlv(const char *tag_seq,u_int length,u_char *pvalue,u_char tlv_type,ASN_BUF *asnbuf)
{
return AddTLV(tag_seq,length,pvalue,tlv_type,asnbuf);
}
int AddTLV(const char *tag_seq,u_int length,u_char *pvalue,u_char tlv_type,ASN_BUF *asnbuf)
{
u_short tags[50][2];
int level;
int rest,swaplen=0,oldlen=0;
int ntag,nlen;
int addval,temp,i,rtn; //temp variable
u_char flag; //temp variable
u_char *ptlv,*pt,*ptr[50],asn_swap[1024];
if(asnbuf->msglen+length+5>asnbuf->maxlen)
{
printf("No room for new tlv.maxlen=%d,msglen=%d,addlen=%d\n",asnbuf->maxlen,asnbuf->msglen,length);
return -1;
}
/*search position for new data--->*/
level = parse_tags(tag_seq,tags);
pt = asnbuf->msgbuf; //start pointer
rest = asnbuf->msglen % 1024; //remain length
for(i = 1; i < level; i++)
{
if(tags[i][1] == 0) //according to tagcode
rtn = findtlv(pt, tags[i][0], &ptlv, rest);
else //according to order
rtn = findtlv2(pt, tags[i][1], &ptlv, rest);
if(rtn == -1) //length check error
return -1;
else if(rtn == 1) //not found,create it
{
swaplen = asnbuf->msglen - (ptlv - asnbuf->msgbuf);
if(swaplen > 0)
memcpy(asn_swap, ptlv, swaplen);
pt = ptlv;
while(i < level)
{
//printf("create level=%d\n",i);
ntag = addtagcode(pt, tags[i][0], 0xA0);
nlen = addlength(pt + ntag, 0);
ptr[i] = pt + ntag;
addval = modifylength(ptr, i - 1, ntag + nlen);
pt += addval;
asnbuf->msglen += addval;
i ++;
}
rest = 0;
}
else //found,continue
{
if((rtn & 0x20) == 0)
return -1;
ntag=gettagcode(ptlv,&temp,&flag);
nlen=getlength(ptlv+ntag,&rest);
ptr[i]=ptlv+ntag;
pt=ptlv+ntag+nlen;
}
}
//insert new data
if(tags[level][1]==0)
{
rtn=findtlv(pt,tags[level][0],&ptlv,rest);
if(rtn<0)
return -1;
else if(rtn!=1)
{
oldlen=0;
oldlen=gettagcode(ptlv,&temp,&flag);
oldlen+=getlength(ptlv+oldlen,&temp);
oldlen+=temp;
}
if(swaplen==0)
{
swaplen=asnbuf->msglen-(ptlv+oldlen-asnbuf->msgbuf);
if(swaplen>0)
memcpy(asn_swap,ptlv+oldlen,swaplen);
}
ntag=addtagcode(ptlv,tags[level][0],tlv_type);
nlen=addlength(ptlv+ntag,length);
memcpy(ptlv+ntag+nlen,pvalue,length);
//modify parent's length
addval=modifylength(ptr,level-1,ntag+nlen+length);
asnbuf->msglen+=addval;
ptlv+=addval;
}
else
{
rtn=findtlv2(pt,tags[level][1],&ptlv,rest);
if(rtn<0)
return -1;
if(swaplen==0)
{
swaplen=asnbuf->msglen-(ptlv-asnbuf->msgbuf);
if(swaplen>0)
memcpy(asn_swap,ptlv,swaplen);
}
ntag=addtagcode(ptlv,tags[level][0],tlv_type);
nlen=addlength(ptlv+ntag,length);
memcpy(ptlv+ntag+nlen,pvalue,length);
//modify parent's length
addval=modifylength(ptr,level-1,ntag+nlen+length);
asnbuf->msglen+=addval;
ptlv+=addval;
}
if(swaplen>0)
memcpy(ptlv,asn_swap,swaplen);
return asnbuf->msglen;
}
int asn_decode(u_char *msg_buf,int ntlv,ASN_BUF *asnbuf)
{
return AsnDecode(msg_buf,256,ntlv,NULL,asnbuf);
}
int asn_decode_v2(u_char *msg_buf,int ntlv,int *errpos,ASN_BUF *asnbuf)
{
return AsnDecode(msg_buf,256,ntlv,errpos,asnbuf);
}
int asn_decode_v3(u_char *msg_buf,int msglen,int *errpos,ASN_BUF *asnbuf)
{
return AsnDecode(msg_buf,msglen,100,errpos,asnbuf);
}
int AsnDecode(u_char *msg_buf,int msglen,int maxtlv,int *errpos,ASN_BUF *asnbuf)
{
ASN_TLV *p1=NULL,*p2;
int ntlv=0,retval,sublen=0;
asnbuf->msgbuf = msg_buf;
asnbuf->tlvcount=0;
asnbuf->pos = 0;
asnbuf->msglen = msglen;
asnbuf->errmsg[0]='\0';
while(asnbuf->pos < msglen && ntlv<maxtlv)
{
if(errpos!=NULL)
*errpos = asnbuf->pos;
retval=parse_tlv(&p2,asnbuf);
if(retval<0)
{
return -1;
}
else if(retval==0)
{
return sublen;
}
else
{
if(p1!=NULL)
p1->pnext = p2;
p1 = p2;
sublen+=retval;
}
ntlv++;
}
if(errpos!=NULL)
*errpos = asnbuf->pos;
return sublen;
}
int get_tlv(const char *tag_seq,u_char *pvalue,ASN_BUF *asnbuf)
{
return get_tlv_v2(tag_seq,pvalue,NULL,asnbuf);
}
int get_tlv_v2(const char *tag_seq,u_char *pvalue,u_char *flag,ASN_BUF *asnbuf)
{
u_short tags[30][2];
int depth=1,order=1;
ASN_TLV *p1=&asnbuf->heap[0];
parse_tags(tag_seq,tags);
if(asnbuf->tlvcount < 1)
return -1;
while(depth<tags[0][0]+1 && (order<=tags[depth][1] || tags[depth][1]==0))
{
//printf("depth=%d/%d,order=%d,tagcode=%d/%d\n",depth,tags[0][0],order,p1->tagcode,tags[depth][0]);
if((p1->tagcode == tags[depth][0] || tags[depth][0]==0xFFFF) && (tags[depth][1]==0 || order==tags[depth][1]))
{
if(depth==tags[0][0])
{
if(flag!=NULL)
*flag=p1->tagtype;
if(p1->length < 0)
return -1;
else if(p1->length <= 256)
{
memcpy(pvalue,p1->pvalue,p1->length);
return p1->length;
}
else
{
memcpy(pvalue,p1->pvalue,256);
return 256;
}
}
else
{
if(p1->psub==NULL)
return -1;
p1=p1->psub;
depth++;
order=1;
}
}
else
{
if(p1->pnext == NULL)
return -1;
p1=p1->pnext;
order++;
}
}
return -1;
}
int GetTLV(const char *tag_seq,int maxlen,u_char *pvalue,u_char flag,ASN_BUF *asnbuf)
{
u_short tags[30][2];
int depth=1,order=1;
ASN_TLV *p1=&asnbuf->heap[0];
parse_tags(tag_seq,tags);
if(asnbuf->tlvcount < 1)
return -1;
while(depth<tags[0][0]+1 && (order<=tags[depth][1] || tags[depth][1]==0))
{
//printf("depth=%d/%d,order=%d,tagcode=%d/%d\n",depth,tags[0][0],order,p1->tagcode,tags[depth][0]);
//printf("flag:%02X/%02X\n",p1->tagtype,flag);
if((p1->tagcode == tags[depth][0] || tags[depth][0]==0xFFFF) && (depth<tags[0][0] || p1->tagtype == flag) && (tags[depth][1]==0 || order==tags[depth][1]))
{
if(depth==tags[0][0])
{
if(p1->length < 0)
return -1;
else if(p1->length <= maxlen)
{
memcpy(pvalue,p1->pvalue,p1->length);
return p1->length;
}
else
{
memcpy(pvalue,p1->pvalue,maxlen);
return maxlen;
}
}
else
{
if(p1->psub==NULL)
return -1;
p1=p1->psub;
depth++;
order=1;
}
}
else
{
if(p1->pnext == NULL)
return -1;
p1=p1->pnext;
order++;
}
}
return -1;
}
int GetAnyTLV(const char *tag_seq,int maxlen,u_char *pvalue,u_char *pflag,u_short *ptagcode,ASN_BUF *asnbuf)
{
u_short tags[30][2];
int depth=1,order=1;
ASN_TLV *p1=&asnbuf->heap[0];
parse_tags(tag_seq,tags);
if(asnbuf->tlvcount < 1)
return -1;
while(depth<tags[0][0]+1 && (order<=tags[depth][1] || tags[depth][1]==0))
{
//printf("depth=%d/%d,order=%d,tagcode=%d/%d\n",depth,tags[0][0],order,p1->tagcode,tags[depth][0]);
//printf("flag:%02X/%02X\n",p1->tagtype,flag);
if((p1->tagcode == tags[depth][0] || tags[depth][0]==0xFFFF) && (tags[depth][1]==0 || order==tags[depth][1]))
{
if(depth==tags[0][0])
{
if(pflag!=NULL)
*pflag = p1->tagtype;
if(ptagcode != NULL)
*ptagcode = p1->tagcode;
if(p1->length < 0)
return -1;
else if(p1->length <= maxlen)
{
memcpy(pvalue,p1->pvalue,p1->length);
return p1->length;
}
else
{
memcpy(pvalue,p1->pvalue,maxlen);
return maxlen;
}
}
else
{
if(p1->psub==NULL)
return -1;
p1=p1->psub;
depth++;
order=1;
}
}
else
{
if(p1->pnext == NULL)
return -1;
p1=p1->pnext;
order++;
}
}
return -1;
}
int parse_tlv(ASN_TLV **pnode,ASN_BUF *asnbuf)
//idefinite length
{
int ntag,nlen,length,sublen=0,retval;
u_int tagcode;
u_char tagtype;
u_char *msgbuf=asnbuf->msgbuf;
ASN_TLV *ptlv,*p1=NULL,*p2;
if(asnbuf->pos == asnbuf->msglen)
{
*pnode=NULL;
return 0;
}
if(asnbuf->pos+2 > asnbuf->msglen || asnbuf->tlvcount >=256)
{
sprintf(asnbuf->errmsg,"Length check error(rest=%d)/exceed limit(tlvcount=%d)\n",asnbuf->msglen-asnbuf->pos,asnbuf->tlvcount);
return -1;
}
//printf("tlvcount=%d\n",asnbuf->tlvcount);
*pnode = ptlv = &asnbuf->heap[asnbuf->tlvcount++];
ptlv->psub = ptlv->pnext = NULL;
ptlv->length = -1;
if((ntag=gettagcode(msgbuf+asnbuf->pos,&tagcode,&tagtype))<1)
{
sprintf(asnbuf->errmsg,"Wrong encoding of tag(pos=%d:%02X %02X %02X)\n",asnbuf->pos,msgbuf[asnbuf->pos],msgbuf[asnbuf->pos+1],msgbuf[asnbuf->pos+2]);
return -1;
}
else
asnbuf->pos+=ntag;
if((nlen=getlength(msgbuf+asnbuf->pos,&length))<1)
{
sprintf(asnbuf->errmsg,"Wrong encoding of Length(pos=%d:%02X %02X %02X)\n",asnbuf->pos,msgbuf[asnbuf->pos],msgbuf[asnbuf->pos+1],msgbuf[asnbuf->pos+2]);
return -1;
}
else
asnbuf->pos+=nlen;
if(asnbuf->pos + length >asnbuf->msglen)
{
sprintf(asnbuf->errmsg,"Length Check error.length=%d,rest=%d(pos=%d:%02X %02X %02X)\n",length,asnbuf->msglen-asnbuf->pos,asnbuf->pos,msgbuf[asnbuf->pos],msgbuf[asnbuf->pos+1],msgbuf[asnbuf->pos+2]);
return -1;
}
ptlv->tagtype=tagtype;
ptlv->tagcode=tagcode;
ptlv->pvalue=msgbuf+asnbuf->pos;
if((tagtype & 0x20)==0) //primitive
{
if(length==-1)
{
sprintf(asnbuf->errmsg,"Wrong Encoding of Length:primitive form with indefinite length\n(pos=%d)",asnbuf->pos);
return -1;
}
else
{
ptlv->length = length;
asnbuf->pos += length;
return length+ntag+nlen;
}
}
else //constructor
{
if(length >=0) //short/long definite length
{
ptlv->length = length;
while(sublen<length)
{
retval=parse_tlv(&p2,asnbuf);
if(retval<0)
return -1;
else if(retval==0)
{
sprintf(asnbuf->errmsg,"Length Check error.length=%d,sublen=%d(pos=%d:%02X %02X %02X)\n",length,sublen,asnbuf->pos,msgbuf[asnbuf->pos],msgbuf[asnbuf->pos+1],msgbuf[asnbuf->pos+2]);
return -1;
}
else
{
if(p1==NULL)
p1=ptlv->psub = p2;
else
{
p1->pnext = p2;
p1 = p2;
}
sublen+=retval;
}
}
if(sublen>length)
{
sprintf(asnbuf->errmsg,"Length Check error.length=%d,sublen=%d(pos=%d:%02X %02X %02X)\n",length,sublen,asnbuf->pos,msgbuf[asnbuf->pos],msgbuf[asnbuf->pos+1],msgbuf[asnbuf->pos+2]);
return -1;
}
ptlv->length = sublen;
return sublen+ntag+nlen;
}
else //indefinite length
{
while(msgbuf[asnbuf->pos]!=0 || msgbuf[asnbuf->pos+1]!=0)
{
retval=parse_tlv(&p2,asnbuf);
if(retval<0)
{
return -1;
}
else if(retval==0)
{
ptlv->length = sublen;
return sublen+ntag+nlen;
}
else
{
if(p1==NULL)
p1=ptlv->psub = p2;
else
{
p1->pnext = p2;
p1 = p2;
}
sublen+=retval;
}
}
asnbuf->pos += 2;
ptlv->length = sublen;
return sublen+ntag+nlen+2;
}
}
}
int findtlv(u_char *pasn,u_int tagcode,u_char **pnext,int rest)
//according to tagcode
{
int ntag,nlen,nvalue,pos=0;
u_int curtag;
u_char type;
//printf("findtlv rest=%d\n",rest);
if(rest==0)
{
*pnext=pasn;
return 1;
}
else if(rest<0)
return -1;
ntag=gettagcode(pasn,&curtag,&type);
if((nlen=getlength(pasn+ntag,&nvalue)) < 0 || nvalue < 0)
return -1;
//printf("ntag=%d,nlen=%d,nvalue=%d\n",ntag,nlen,nvalue);
if(curtag<tagcode)
{
if((pos = ntag + nlen + nvalue) <= 0)
return -1;
return findtlv(pasn+pos,tagcode,pnext,rest-pos);
}
else if(curtag==tagcode)
{
*pnext=pasn;
return type;
}
else
{
*pnext=pasn;
return 1;
}
}
int findtlv2(u_char *pasn,int index,u_char **pnext,int rest)
//according to position
{
u_int curtag,ntag,nlen,nvalue;
u_char type;
(*pnext)=pasn;
while(--index>0 && rest>0)
{
ntag=gettagcode((*pnext),&curtag,&type);
nlen=getlength((*pnext)+ntag,&nvalue);
(*pnext)+=(ntag+nlen+nvalue);
rest-=(ntag+nlen+nvalue);
}
if(index==0 && rest>0) //found
{
ntag=gettagcode((*pnext),&curtag,&type);
return type;
}
else if(rest==0) //seek to end(not found)
return 1;
else
return -1;
}
int gettagcode(u_char *asnbuf,u_int *tagcode,u_char *type)
{
u_int pos=0;
*type=asnbuf[pos] & 0xE0;
*tagcode=asnbuf[pos] & 0x1F;
pos++;
if(*tagcode==0x1F)
{
*tagcode=0;
while((asnbuf[pos] & 0x80)==0x80 && pos<3)
{
*tagcode=(*tagcode) * 0x80 + (asnbuf[pos++] & 0x7F);
}
*tagcode=(*tagcode) * 0x80 + (asnbuf[pos++] & 0x7F);
}
return pos;
}
int getlength(u_char *asnbuf,int *len)
{
u_int pos=0,lenbyte;
if((asnbuf[pos] & 0x80)==0)
*len=asnbuf[pos++] & 0x7F;
else
{
*len=0;
lenbyte=asnbuf[pos++] & 0x7F;
if(lenbyte>3 || lenbyte<0)
return -1;
if(lenbyte==0)
{
*len=-1;
return 1;
}
else
{
while(lenbyte-->0)
*len=(*len)*0x100 + asnbuf[pos++];
}
}
return pos;
}
int addtagcode(u_char *msg_buf,u_int tagcode,u_char type)
{
u_int tagbyte=0,pos=0;
int i=3;
u_char buf[4];
msg_buf[pos]=type & 0xE0;
if(tagcode<31)
msg_buf[pos++]+=tagcode;
else
{
msg_buf[pos++]+=0x1F;
while(i>=0 && tagcode>0)
{
buf[i]=tagcode & 0x7F;
buf[i]|=0x80;
tagcode=tagcode >> 7;
i--;
}
buf[3]&=0x7F;
tagbyte=3-i;
memcpy(msg_buf+pos,buf+i+1,tagbyte);
pos+=tagbyte;
}
return pos;
}
int addlength(u_char *msg_buf,u_int len)
{
u_int lenbyte=0,pos=0;
int i=3;
u_char buf[4];
if(len>=0 && len<=127)
msg_buf[pos++]=len;
else if(len>0)
{
while(i>=0 && len>0)
{
buf[i]=len & 0xFF;
len=len>>8;
i--;
}
lenbyte=3-i;
msg_buf[pos++]=lenbyte | 0x80;
memcpy(msg_buf+pos,buf+i+1,lenbyte);
pos+=lenbyte;
}
return pos;
}
int parse_tags(const char *tag_seq,u_short (*tags)[2])
{
u_short i,j=0,level=1,len;
len=strlen(tag_seq);
tags[1][0]=0xFFFF;
tags[1][1]=0;
for(i=0;i<len;i++)
{
if(isdigit(tag_seq[i]))
{
if(tags[level][j]==0xFFFF)
tags[level][j]=0;
tags[level][j]=tags[level][j]*10+tag_seq[i]-'0';
}
else if(tag_seq[i]=='-')
j=1;
else if(tag_seq[i]=='.')
{
j=0;
level++;
tags[level][0]=0xFFFF;
tags[level][1]=0;
}
else if(isspace(tag_seq[i])==0)
return -1;
}
tags[0][0]=level;
return level;
}
int modifylength(u_char *ptr[],int level,int addval)
{
int lenbyte1,lenbyte2,len;
u_char swapbuf[1024];
if(level<1)
return addval;
lenbyte1=getlength(ptr[level],&len);
memcpy(swapbuf,ptr[level]+lenbyte1,2);
lenbyte2=addlength(ptr[level],len+addval);
if(lenbyte2>lenbyte1)
{
memcpy(swapbuf+2,ptr[level]+lenbyte1+2,len+addval-2);
memcpy(ptr[level]+lenbyte2,swapbuf,len+addval);
}
return modifylength(ptr,level-1,addval+lenbyte2-lenbyte1);
}
void showbuf(u_char *buf,int len)
{
int i;
for(i=0;i<len;i++)
printf("%02X ",buf[i]);
printf("\n");
}
/////////////////////////////////////////////////
/*Functions for add/get special data types --->*/
/////////////////////////////////////////////////
int add_bool(const char *tag_seq,u_char value,u_char tlv_type,ASN_BUF *asnbuf)
{
return add_tlv(tag_seq,1,&value,tlv_type,asnbuf);
}
u_char get_bool(const char *tag_seq,ASN_BUF *asnbuf)
{
u_char pvalue[10];
get_tlv(tag_seq,pvalue,asnbuf);
return pvalue[0];
}
int add_int(const char *tag_seq,int value,u_char tlv_type,ASN_BUF *asnbuf)
{
return AddInteger(tag_seq,value,tlv_type,asnbuf);
}
int AddInteger(const char *tag_seq,int value,u_char tlv_type,ASN_BUF *asnbuf)
{
u_char buf[4];
u_int *p_uint=(u_int *)buf;
int i;
*p_uint=htonl(value);
if(value<0)
{
for(i=0;i<4;i++)
{
if(buf[i]!=0xFF)
{
if((buf[i] & 0x80)==0)
i--;
break;
}
}
}
else
{
for(i=0;i<4;i++)
{
if(buf[i]!=0)
{
if((buf[i] & 0x80)==0x80)
i--;
break;
}
}
}
if(i>=4)
i=3;
return add_tlv(tag_seq,4-i,buf+i,tlv_type,asnbuf);
}
int GetInteger(const char *tag_seq,int *rtn,u_char flag,ASN_BUF *asnbuf)
{
u_char pvalue[10];
int length,i;
length=GetTLV(tag_seq,5,pvalue,flag,asnbuf);
if(length==-1)
return -1;
if((pvalue[0] & 0x80)==0x80)
*rtn=-1;
else
*rtn=0;
for(i=0;i<length;i++)
*rtn=((*rtn)<<8)|(pvalue[i]);
return length;
}
int get_int(const char *tag_seq,ASN_BUF *asnbuf)
{
u_char pvalue[10];
int length,i,value;
length=get_tlv(tag_seq,pvalue,asnbuf);
if(length==-1)
return -1;
if((pvalue[0] & 0x80)==0x80)
value=-1;
else
value=0;
for(i=0;i<length;i++)
value=(value<<8)|(pvalue[i]);
return value;
}
int get_int_v2(const char *tag_seq,int *rtn,ASN_BUF *asnbuf)
{
u_char pvalue[10];
int length,i;
length=get_tlv(tag_seq,pvalue,asnbuf);
if(length==-1)
return -1;
if((pvalue[0] & 0x80)==0x80)
*rtn=-1;
else
*rtn=0;
for(i=0;i<length;i++)
*rtn=((*rtn)<<8)|(pvalue[i]);
return length;
}
int add_null(const char *tag_seq,u_char tlv_type,ASN_BUF *asnbuf)
{
u_char pvalue[2];
return add_tlv(tag_seq,0,pvalue,tlv_type,asnbuf);
}
int get_null(const char *tag_seq,ASN_BUF *asnbuf)
{
u_char pvalue[50];
if(get_tlv(tag_seq,pvalue,asnbuf)>=0)
return 1;
else
return -1;
}
int add_oid(const char *tag_seq,const char *oidstr,u_char tlv_type,ASN_BUF *asnbuf)
{
u_char pvalue[50],buf[4];
int oid[20],len,i,j,level=0,pos=0;
len=strlen(oidstr);
memset(oid,0,sizeof(oid));
for(i=0;i<len;i++)
{
if(isdigit(oidstr[i]))
oid[level]=oid[level]*10+oidstr[i]-'0';
else if(oidstr[i]=='.')
level++;
}
oid[1]=oid[0]*40 + oid[1];
for(i=1;i<=level;i++)
{
j=3;
do
{
buf[j]=oid[i] & 0x7F;
buf[j]|=0x80;
oid[i]=oid[i]>>7;
j--;
}while(oid[i]>0 && j>=0);
buf[3]&=0x7F;
len=3-j;
memcpy(pvalue+pos,buf+j+1,len);
pos+=len;
}
return add_tlv(tag_seq,pos,pvalue,tlv_type,asnbuf);
}
int get_oid(const char *tag_seq,char *oid,ASN_BUF *asnbuf)
{
u_char pvalue[50];
char tempstr[50],firstoctet=1;
int length,i,temp=0;
length=get_tlv(tag_seq,pvalue,asnbuf);
if(length<=0)
return -1;
for(i=0;i<length;i++)
{
temp=temp * 0x80 +(pvalue[i] & 0x7F);
if((pvalue[i] & 0x80)==0x00)
{
if(firstoctet==1)
{
if(temp<40)
sprintf(tempstr,"0.%d",temp);
else if(temp<80)
sprintf(tempstr,"1.%d",temp-40);
else
sprintf(tempstr,"2.%d",temp-80);
firstoctet=0;
}
else
sprintf(tempstr+strlen(tempstr),".%d",temp);
temp=0;
}
}
strcpy(oid,tempstr);
return 1;
}
int DecodeInteger(u_char *buf, u_char len)
{
int ret;
u_char i, pad = 0, *ptr = (u_char *)&ret;
if(buf[0] & 0x80)
pad = 0xFF;
for(i = 0; i < 4; i++)
{
if(len > 0)
{
len--;
ptr[i] = buf[len];
}
else
ptr[i] = pad;
}
return ret;
}
/*@end@*/

View File

@@ -0,0 +1,199 @@
/******************************************/
/*Title : bisearch.h */
/*Descr : BiSearch arithmetic implement */
/*Author : Liu Wei */
/*Create : 2006-12-13 */
/*Version : R1V00_01 */
/*Modify : 2006-12-13 */
/******************************************/
#include "memory.h"
#include "malloc.h"
#include "stdlib.h"
#include "./include/bisearch.h"
/*@ignore@*/
int BISearchReg ( BiSearchArray *pBSA, int nTotalSize , void *GetIdleNodeFunc )
{
if( pBSA == NULL )
exit(0);
memset( pBSA , 0 , sizeof(BiSearchArray) );
pBSA->nArrayCount = 0;
pBSA->nArrayTotalLen = nTotalSize;
pBSA->pBiArray = malloc( sizeof(BiSearch)*nTotalSize );
memset ( pBSA->pBiArray, 0, BS_SIZE * nTotalSize );
pBSA->GetIdleNodeFunc = (int (*)(int *))GetIdleNodeFunc;
return 1;
}
int BISearchUnReg ( BiSearchArray * pBSA)
{
if( pBSA !=NULL && pBSA->pBiArray != NULL )
{
free(pBSA->pBiArray);
return 1;
}
return 0;
}
int BSearch ( BiSearchArray * pBSA, int nStart, int nEnd, LL llKey, int * nPosResult )
{
BiSearch *pArray ;
int nPos = -1;
if( pBSA == NULL )
return 0;
if( nStart < 0 || nEnd < 0 || nStart > nEnd || pBSA->nArrayCount < nStart )
{
return 0;
}
pArray = pBSA->pBiArray;
if( !pBSA->nArrayCount )
return (*nPosResult = 0);
if( nEnd > pBSA->nArrayCount-1 )
nEnd = pBSA->nArrayCount-1;
for ( nPos = nStart; nStart <= nEnd; nPos = ( nStart + nEnd ) / 2 )
{
if( pArray[nPos].llKey == llKey )
{
*nPosResult = nPos;
return 1;
}
if( pArray[nPos].llKey > llKey )
{
nEnd = nPos - 1;
}
if( pArray[nPos].llKey < llKey )
{
nStart = nPos + 1;
}
}
if( nPos != -1 && pArray[nPos].llKey < llKey )
nPos++;
*nPosResult = nPos;
return 0;
}
int BSearchArray ( BiSearchArray * pBSA, LL llKey, int *nPosResult )
{
if( pBSA == NULL )
return 0;
return BSearch ( pBSA, 0, (pBSA->nArrayCount > 0 ? pBSA->nArrayCount-1 : 0), llKey, nPosResult );
}
int BISInsert ( BiSearchArray * pBSA, LL llKey, int nDUPosIndex )
{
int nPos = -1;
if( pBSA == NULL )
return 0;
//memery protect: Data Unit Index exceed Data Unit Array Length
if( nDUPosIndex > pBSA->nArrayTotalLen || nDUPosIndex < 0)
return 0;
if( pBSA->nArrayCount >= pBSA->nArrayTotalLen ) //Array Full
return 0;
if( !BSearchArray ( pBSA , llKey, &nPos ) && nPos != -1 )
{
BiSearch *pBS = pBSA->pBiArray + nPos ;
memmove ( pBS + 1, pBS , BS_SIZE * ( pBSA->nArrayCount - nPos ) );
pBS->llKey = llKey;
pBS->nDUPosIndex = nDUPosIndex;
pBSA->nArrayCount++;
return 1;
}
//The Key is existed, insert fail.
return 0;
}
int BISDelete ( BiSearchArray * pBSA, LL llKey )
{
int nPos = -1;
if( pBSA == NULL )
return 0;
if( pBSA->nArrayCount <= 0 )
return 0;
if( BSearchArray ( pBSA ,llKey, &nPos ) )
{
BiSearch *pBS = pBSA->pBiArray + nPos;
memmove ( pBS, pBS + 1, BS_SIZE * ( pBSA->nArrayCount - nPos ) );
memset ( pBSA->pBiArray + pBSA->nArrayCount, 0, BS_SIZE );
pBSA->nArrayCount--;
return 1;
}
return 0;
}
int BISSearch ( BiSearchArray * pBSA, LL llKey , int* nDUPosIndex)
{
int nPos = -1;
if( pBSA == NULL )
return 0;
if( BSearchArray ( pBSA ,llKey, &nPos ) )
{
*nDUPosIndex = pBSA->pBiArray[nPos].nDUPosIndex;
if( *nDUPosIndex > pBSA->nArrayTotalLen )
return 0;
return 1;
}
return 0;
}
int GetBISearchCount ( BiSearchArray * pBSA)
{
if( pBSA == NULL )
return 0;
return pBSA->nArrayCount;
}
int GetDUIndex ( BiSearchArray * pBSA, int nBIIndex)
{
if( pBSA == NULL )
return 0;
if( nBIIndex >= pBSA->nArrayCount )
return -1;
else
return pBSA->pBiArray[nBIIndex].nDUPosIndex;
}
int BISSearchMng( BiSearchArray * pBSA, BIS_OP mng_type,LL llkey, int* nDUIndex )
{
switch( mng_type )
{
case BIS_INIT:
return BISInsert( pBSA , llkey , *nDUIndex );
case BIS_SEARCH:
return BISSearch( pBSA , llkey , nDUIndex );
case BIS_INSERT:
if( pBSA->GetIdleNodeFunc != NULL && pBSA->GetIdleNodeFunc( nDUIndex ) )
return BISInsert( pBSA , llkey , *nDUIndex );
break;
case BIS_DELETE:
return BISDelete( pBSA, llkey);
break;
default:
return 0;
}
return 1;
}
/*@end@*/

493
plat/public_bak/src/crypt.c Normal file
View File

@@ -0,0 +1,493 @@
/*
** PACS-WLL 2000 project, Prepaid System.
**
** The module Copyright (C) 2000-2001 interWAVE Inc.
** Written completely by Zhang Shuzhong at iCRD February, 2001
**
** file name: crypt.c
** CVS $Id: crypt.c,v 1.1 2001/06/28 07:21:15 zhangsz Exp $
**
** Crypt functions
**
*/
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*@ignore@*/
#define DES_KEY "N2r3T5B0"
static unsigned char T1[] =
{
57,49,41,33,25,17, 9, 1,
59,51,43,35,27,19,11, 3,
61,53,45,37,29,21,13, 5,
63,55,47,39,31,23,15, 7,
56,48,40,32,24,16, 8, 0,
58,50,42,34,26,18,10, 2,
60,52,44,36,28,20,12, 4,
62,54,46,38,30,22,14, 6
};
static unsigned char T2[] =
{
39, 7,47,15,55,23,63,31,
38, 6,46,14,54,22,62,30,
37, 5,45,13,53,21,61,29,
36, 4,44,12,52,20,60,28,
35, 3,43,11,51,19,59,27,
34, 2,42,10,50,18,58,26,
33, 1,41, 9,49,17,57,25,
32, 0,40, 8,48,16,56,24
};
static unsigned char T3[] =
{
31, 0, 1, 2, 3, 4,
3, 4, 5, 6, 7, 8,
7, 8, 9,10,11,12,
11,12,13,14,15,16,
15,16,17,18,19,20,
19,20,21,22,23,24,
23,24,25,26,27,28,
27,28,29,30,31, 0
};
static unsigned char T5[] =
{
15, 6,19,20,
28,11,27,16,
0,14,22,25,
4,17,30, 9,
1, 7,23,13,
31,26, 2, 8,
18,12,29, 5,
21,10, 3,24
};
static unsigned char T7_1_2[] =
{
56,48,40,32,24,16, 8,
0,57,49,41,33,25,17,
9, 1,58,50,42,34,26,
18,10, 2,59,51,43,35,
62,54,46,38,30,22,14,
6,61,53,45,37,29,21,
13, 5,60,52,44,36,28,
20,12, 4,27,19,11, 3
};
static unsigned char T8[] =
{
0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0
};
static unsigned char T9[] =
{
13,16,10,23, 0, 4,
2,27,14, 5,20, 9,
22,18,11, 3,25, 7,
15, 6,26,19,12, 1,
40,51,30,36,46,54,
29,39,50,44,32,47,
43,48,38,55,33,52,
45,41,49,35,28,31
};
static unsigned char T6[][64] =
{
{/* S1 */
14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13
},
{/* S2 */
15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9
},
{/* S3 */
10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12
},
{/* S4 */
7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14
},
{/* S5 */
2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3
},
{/* S6 */
12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13
},
{/* S7 */
4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12
},
{/* S8 */
13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11
}
};
unsigned char TE[][4] =
{
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1},
{1,0,1,0},
{1,0,1,1},
{1,1,0,0},
{1,1,0,1},
{1,1,1,0},
{1,1,1,1}
};
void Ks (unsigned char *Key, unsigned char Kn[16][48])
{
unsigned char cd[56];
unsigned char zt[60];
int n, i;
unsigned char tmp11, tmp12, tmp21, tmp22;
unsigned char *Knn;
/* choix 1 */
for (i = 0; i < 56; i++)
{
cd[i] = Key[T7_1_2[i]];
}
for (n = 0; n < 16; n++)
{
if (T8[n] == 0)
{
tmp11 = cd[0];
tmp21 = cd[28];
memcpy( zt , &cd[1] , 55 );
memcpy( cd , zt , 55 );
cd[27] = tmp11;
cd[55] = tmp21;
}
else
{
tmp11 = cd[0];
tmp12 = cd[1];
tmp21= cd[28];
tmp22 = cd[29];
memcpy( zt , &cd[2] , 54 );
memcpy( cd , zt , 54 );
cd[26] = tmp11;
cd[27] = tmp12;
cd[54] = tmp21;
cd[55] = tmp22;
}
Knn = Kn[n];
for (i = 0; i < 48; i++)
{
Knn[i] = cd[T9[i]];
}
}
}
void fonction(unsigned char *Knn, unsigned char *r, unsigned char *s)
{
unsigned char x[32];
unsigned long *px;
int i, l;
unsigned char c;
unsigned char t;
for (i = 0, l = 0, px = (unsigned long *) x; i < 8;)
{
c = 32 * (r[T3[l]] ^ Knn[l]);
l++;
c += 8 * (r[T3[l]] ^ Knn[l]);
l++;
c += 4 * (r[T3[l]] ^ Knn[l]);
l++;
c += 2 * (r[T3[l]] ^ Knn[l]);
l++;
c += 1 * (r[T3[l]] ^ Knn[l]);
l++;
c += 16 * (r[T3[l]] ^ Knn[l]);
l++;
t = T6[i][c];
i++;
*px = *(long *)TE[t];
px++;
}
for (i = 0; i < 32; i++)
{
s[i] = x[T5[i]];
}
}
void permutation(unsigned char *org, unsigned char *tab)
{
unsigned char tmp[64];
int i;
memcpy(tmp, org, 64);
for (i = 0; i < 64; i++)
{
org[i] = tmp[tab[i]];
}
}
void chiffrement(unsigned char *xi, unsigned char *xo, unsigned char Kn[16][48])
{
unsigned char r[32], l[32];
unsigned char rp[32], lp[32];
int i;
int n;
memcpy(l, &xi[0], 32);
memcpy(r, &xi[32], 32);
for (n = 0; n < 16; n++)
{
memcpy(lp, r, 32);
fonction(Kn[n], r, rp);
for (i = 0; i < 32; i++)
{
r[i] =( ( l[i]) ^ (rp[i] ) ) ;
}
memcpy(l, lp, 32);
}
memcpy(&xo[0], r, 32);
memcpy(&xo[32], l, 32);
}
void dechiffrement(unsigned char *xi, unsigned char *xo, unsigned char Kn[16][48])
{
unsigned char r[32], l[32], rp[32], lp[32];
int i;
int n;
memcpy(l, &xi[0], 32);
memcpy(r, &xi[32], 32);
for (n = 0; n < 16; n++)
{
memcpy(lp, r, 32);
fonction(Kn[15 - n], r, rp);
for (i = 0; i < 32; i++)
{
r[i] =( ( l[i] ) ^ ( rp[i] )) ;
}
memcpy(l, lp, 32);
}
memcpy(&xo[0], r, 32);
memcpy(&xo[32], l, 32);
}
void eclater(const unsigned char *buf_bit, unsigned char *byte)
{
int i;
unsigned char m;
for (i = 0; i < 8; i++)
{
for (m = 0x80; m != 0; )
{
if ((buf_bit[i] & m) != 0)
*byte = 1;
else
*byte = 0;
byte++;
m=m/2 ;
}
}
}
void compacter(unsigned char *byte, unsigned char *buf_bit)
{
int i;
unsigned char m, n;
for (i = 0; i < 8; i++)
{
n = 0;
for (m = 0x80; m != 0; )
{
if (*byte++)
n = n | m;
m=m/2 ;
}
buf_bit[i] = n;
}
}
// direction 0/1=Encryption/Decryption
// binput,boutput,bkey = 8bytes
// direction: 0/1=Encryt/Decrypt
void des(unsigned char *boutput, const unsigned char *binput, const unsigned char *bkey, int direction)
{
unsigned char input[64]; /* data input */
unsigned char output[64]; /* data output */
unsigned char Key[64];
unsigned char Kn[16][48];
eclater(binput, input);
eclater(bkey, Key);
Ks(Key, Kn);
permutation(input, T1);
if (direction) dechiffrement(input, output, Kn);
else chiffrement(input, output, Kn);
permutation(output, T2);
compacter(output, boutput);
}
void atob (unsigned char *bcd_buf, const char *ascii_buf, int len)
{
int i;
char ch;
for (i=0; i<len; i++)
{
ch = ascii_buf[i];
if (ch>='a') ch -= 'a' - 10;
else if (ch>='A') ch -= 'A' - 10;
else ch -= '0';
if (i & 1) *(bcd_buf++) |= ch & 0x0f;
else *bcd_buf = ch << 4;
}
}
void btoa (char *ascii_buf, const unsigned char *bcd_buf, int len)
{
int i;
char ch;
for (i=0; i<len; i++)
{
if (i & 1) ch = *(bcd_buf++) & 0x0f;
else ch = *bcd_buf >> 4;
ascii_buf[i] = ch + ((ch > 9)? 'A'-10 : '0');
}
ascii_buf[i] = '\0';
}
void EncryptPIN (unsigned char cipher[], const char plain[], const char pan[], const unsigned char pin_key[])
{
char pin[20];
unsigned char buf1[8], buf2[8];
int i;
i = strlen(plain);
buf1[0] = i;
strcpy(pin, plain);
for (; i<14; ++i) pin[i] = 'F';
atob(buf1+1, pin, 14);
buf2[0] = buf2[1] = 0x00;
atob(buf2+2, pan+strlen(pan)-13, 12);
for (i=0; i<8; ++i) buf1[i] ^= buf2[i];
des(cipher, buf1, pin_key, 0);
}
/* length of pan more than 13, and length of pin key more than 8 */
void DecryptPIN (char plain[], const unsigned char cipher[], const char pan[], const unsigned char pin_key[])
{
unsigned char buf1[8], buf2[8];
int i;
des(buf1, cipher, pin_key, 1);
buf2[0] = buf2[1] = 0x00;
atob(buf2+2, pan+strlen(pan)-13, 12);
for (i=0; i<8; i++) buf1[i] ^= buf2[i];
i = buf1[0];
if (i <= 14) btoa(plain, buf1+1, i);
else plain[0] = '\0';
}
void CalcMAC (char mac[], const char data[], const unsigned char mac_key[])
{
int i;
unsigned char m[8];
memset(m, 0, 8);
for (i=0; data[i];)
{
m[i&7] ^= data[i];
++i;
if (!((i&7) && data[i])) des(m, m, mac_key, 0);
}
btoa(mac, m, 8);
}
void CalcMAC1 (unsigned char mac[], const unsigned char data[], int len, const unsigned char mac_key[])
{
int i;
memset(mac, 0, 8);
for (i=0; i<len; ++i) mac[i&7] ^= data[i];
des(mac, mac, mac_key, 0);
}
static unsigned char kkey[] =
{0x35, 0x01, 0x27, 0x73, 0x11, 0x08, 0x43, 0x1F};
void EncryptKey (char cipher[], const unsigned char plain[])
{
unsigned char buf[8];
des(buf, plain, kkey, 0);
btoa(cipher, buf, 16);
}
void DecryptKey (unsigned char plain[], const char cipher[])
{
unsigned char buf[8];
atob(buf, cipher, 16);
des(plain, buf, kkey, 1);
}
void DesCrypt(unsigned char *Output,unsigned char *Input,unsigned char *DesKey,unsigned char DesMode){
if (NULL == DesKey){
des(Output,Input,DES_KEY,DesMode);
}
else{
des(Output,Input,DesKey,DesMode);
}
}
/*@end@*/

View File

@@ -0,0 +1,76 @@
/********************************************************************/
/*Title: asn1.h */
/*Descr: ASN.1 Encoding/Decoding Module(Head file) */
/*Author: Liang Hanxi */
/*Create: 2002-1-15 */
/*Version: R3V03_01 */
/*Modify: 2002-10-22 */
/********************************************************************/
#ifndef _ASN_1_HEAD
#define _ASN_1_HEAD
#include <sys/types.h>
#include <netinet/in.h>
typedef struct ASN_TLV
{
u_char tagtype;
u_short tagcode;
int length;
u_char *pvalue;
struct ASN_TLV *pnext;
struct ASN_TLV *psub;
}ASN_TLV;
typedef struct _ASN_BUFFER
{
u_char *msgbuf; //store pointer of buffer
int maxlen;
int msglen; //totallength of message
int pos;
ASN_TLV heap[256];
char errmsg[1024];
short tlvcount;
}ASN_BUF;
//interface======>
void AsnEncode(u_char *msg_buf,u_int maxlen,ASN_BUF *asnbuf);
int AsnDecode(u_char *msg_buf,int msglen,int maxtlv,int *errpos,ASN_BUF *asnbuf);
int GetTLV(const char *tag_seq,int maxlen,u_char *pvalue,u_char flag,ASN_BUF *asnbuf);
int GetAnyTLV(const char *tag_seq,int maxlen,u_char *pvalue,u_char *pflag,u_short *ptagcode,ASN_BUF *asnbuf);
int AddTLV(const char *tag_seq,u_int length,u_char *pvalue,u_char tlv_type,ASN_BUF *asnbuf);
int GetInteger(const char *tag_seq,int *rtn,u_char flag,ASN_BUF *asnbuf);
int AddInteger(const char *tag_seq,int value,u_char tlv_type,ASN_BUF *asnbuf);
void asn_encode(u_char *asn_buf,ASN_BUF *asnbuf);
void asn_encode_v3(u_char *msg_buf,u_int maxlen,ASN_BUF *asnbuf);
int add_tlv(const char *tag_seq,u_int length,u_char *pvalue,u_char tlv_type,ASN_BUF *asnbuf);
int asn_decode(u_char *asn_buf,int ntlv,ASN_BUF *asnbuf);
int asn_decode_v2(u_char *msg_buf,int ntlv,int *plen,ASN_BUF *asnbuf);
int asn_decode_v3(u_char *msg_buf,int msglen,int *errpos,ASN_BUF *asnbuf);
int get_tlv(const char *tag_seq,u_char *pvalue,ASN_BUF *asnbuf);
int get_tlv_v2(const char *tag_seq,u_char *pvalue,u_char *flag,ASN_BUF *asnbuf);
int parse_tlv(ASN_TLV **pnode,ASN_BUF *asnbuf);
//int parse_tlv2(u_char *asn_buf,int rest,u_short (*tags)[2],int order,ASN_BUF *asnbuf);
int findtlv(u_char *pasn,u_int tagcode,u_char **pnext,int rest);
int findtlv2(u_char *pasn,int index,u_char **pnext,int rest);
int gettagcode(u_char *asnbuf,u_int *tagcode,u_char *type);
int getlength(u_char *asnbuf,int *len);
int addtagcode(u_char *asn_buf,u_int tagcode,u_char type);
int addlength(u_char *asn_buf,u_int len);
int parse_tags(const char *tag_seq,u_short (*tags)[2]);
int modifylength(u_char *ptr[],int level,int addval);
void showbuf(u_char *buf,int len);
int add_bool(const char *tag_seq,u_char value,u_char tlv_type,ASN_BUF *asnbuf);
u_char get_bool(const char *tag_seq,ASN_BUF *asnbuf);
int add_int(const char *tag_seq,int value,u_char tlv_type,ASN_BUF *asnbuf);
int get_int(const char *tag_seq,ASN_BUF *asnbuf);
int get_int_v2(const char *tag_seq,int *rtn,ASN_BUF *asnbuf);
int add_oid(const char *tag_seq,const char *oidstr,u_char tlv_type,ASN_BUF *asnbuf);
int get_oid(const char *tag_seq,char *oid,ASN_BUF *asnbuf);
int add_null(const char *tag_seq,u_char tlv_type,ASN_BUF *asnbuf);
int get_null(const char *tag_seq,ASN_BUF *asnbuf);
int DecodeInteger(u_char *buf, u_char len);
#endif

View File

@@ -0,0 +1,123 @@
/******************************************/
/*Title : bisearch.h */
/*Descr : BiSearch arithmetic Structure */
/*Author : Liu Wei */
/*Create : 2006-12-13 */
/*Version : R1V00_01 */
/*Modify : 2006-12-13 */
/******************************************/
#ifndef _BISEARCH_H_
#define _BISEARCH_H_
#define LL long long
#define u8 unsigned char
typedef struct BiSearch
{
LL llKey; //BiSearch Array Node Key
int nDUPosIndex; //Data Unit array Position Index
}
BiSearch;
#define BS_SIZE sizeof(BiSearch)
typedef struct BiSearchArray
{
int nArrayCount;
int nArrayTotalLen;
BiSearch *pBiArray; //SearchArray pointer
int (*GetIdleNodeFunc)(int* nDUIndex);
}
BiSearchArray;
/*********************************************************************/
/*BiSearchReg : Init BiSearch Struct, Alloc BiSearch Memery */
/*Return : [0]:BiSearchReg fail [1] :BiSearchReg Success */
/*********************************************************************/
extern int BISearchReg ( BiSearchArray * pBSA, int nTotalSize ,void *GetIdleNodeFunc );
/*********************************************************************/
/*BiSearchUnReg : Release BiSearch Memery */
/*Return : [0]:BiSearchUnReg fail [1] :BiSearchUnReg Success */
/*********************************************************************/
int BISearchUnReg ( BiSearchArray * pBSA);
/*********************************************************************/
/*BSearch : BiSearch from nStart to nEnd with the llKey */
/* Search Result save in the val "nPosResult" */
/*Return : [0]:BSearch fail [1] :BSearch Success */
/*********************************************************************/
int BSearch ( BiSearchArray * pBSA, int nStart, int nEnd, LL llKey, int *nPosResult );
/*********************************************************************/
/*BSearchArray : BiSearch from 0 to ArrayEndIndex with the llKey */
/* Search nPos Result save in the val "nPosResult" */
/*Return : [0]:BSearchArray fail [1] :BSearchArray Success */
/*********************************************************************/
int BSearchArray ( BiSearchArray * pBSA, LL llKey, int *nPosResult );
/*********************************************************************/
/*BISInsert : Insert a BiSearch Array Element with the llKey */
/* return Data Unit Array Index Get by GetIdleNodeFunc*/
/*Return : [0]:BISInsert fail [1]:BISInsert Success */
/*********************************************************************/
int BISInsert ( BiSearchArray * pBSA, LL llKey, int nDUPosIndex );
/*********************************************************************/
/*BISDelete : Delete a BiSearch Array Element with the llKey */
/*Return : [0]:BISDelete fail [1]:BISDelete Success */
/*********************************************************************/
int BISDelete ( BiSearchArray * pBSA, LL llKey );
/*********************************************************************/
/*BISSearch : BiSearch from 0 to ArrayEndIndex with the llKey */
/* Search DUIndex Result save in the val "nDUPosIndex"*/
/*Return : [0]:BISSearch fail [1]:BISSearch Success */
/*********************************************************************/
int BISSearch ( BiSearchArray * pBSA, LL llKey , int* nDUPosIndex);
/*********************************************************************/
/*GetBISearchCount : Get The BiSearch struct counter */
/*Return : return The BiSearch struct counter */
/*********************************************************************/
int GetBISearchCount ( BiSearchArray * pBSA);
/*********************************************************************/
/*GetDUIndex : Get The Data Unit Index by bisearch struct index */
/*Return : return the BiSearch struct dataunit index */
/*********************************************************************/
int GetDUIndex ( BiSearchArray * pBSA, int nBIIndex);
//BiSearch ManageMent Operation
typedef enum _BIS_OP
{
BIS_INIT = 0,
BIS_SEARCH,
BIS_INSERT,
BIS_DELETE,
}BIS_OP;
/*********************************************************************/
/*BISSearchMng : BiSearch Management Opertion fuction */
/* Init : use BIS_OP [BIS_INIT] Insert the elment */
/* with the key_str and nDUIndex */
/* Search : use BIS_OP [BIS_SEARCH] search the elemnt */
/* with the key_str ,return nDUIndex */
/* Insert : se BIS_OP [BIS_Insert] Insert a BiSearch */
/* Array Element with the llKey ,return Data */
/* Unit Array Index Get by GetIdleNodeFunc() */
/* by GetIdleNodeFunc() */
/* Delete : use BIS_OP [BIS_DELETE] Delete the elment */
/* with the key_str */
/*Return : [0] fail [1] success */
/*********************************************************************/
int BISSearchMng( BiSearchArray * pBSA, BIS_OP mng_type,LL llkey, int* nDUIndex );
#endif

View File

@@ -0,0 +1,28 @@
/*
* crypt.h ---- Key management and data encryption/decryption.
*/
#ifndef CRYPT__H
#define CRYPT__H
void des(unsigned char *output, const unsigned char *input, const unsigned char *key, int direction);
void atob (unsigned char *bcd_buf, const char *ascii_buf, int len);
void btoa (char *ascii_buf, const unsigned char *bcd_buf, int len);
void EncryptPIN (unsigned char cipher[], const char plain[], const char pan[], const unsigned char pin_key[]);
void DecryptPIN (char plain[], const unsigned char cipher[], const char pan[], const unsigned char pin_key[]);
void CalcMAC (char mac[], const char data[], const unsigned char mac_key[]);
void CalcMAC1 (unsigned char mac[], const unsigned char data[], int len, const unsigned char mac_key[]);
void EncryptKey (char cipher[], const unsigned char plain[]);
void DecryptKey (unsigned char plain[], const char cipher[]);
typedef enum _des_crypt_mode{
_DES_ENCRYPT_ = 0,
_DES_DECRYPT_
}_DesMode;
void DesCrypt(
unsigned char *Output /*8 bytes*/,
unsigned char *Input /*8 bytes*/,
unsigned char *DesKey/*default=NULL.While using for user licenses control,can keep the default value*/,
unsigned char DesMode/*encrpt or decrypt,refer to enum _DesMode*/);
#endif

View File

@@ -0,0 +1,47 @@
/* public include head file */
/* written by Liu Zhiguo 2002-03-26 */
/* Version 1.0 */
/* -------------------------------- */
#ifndef _PUBLIC_INCLUDES_H_
#define _PUBLIC_INCLUDES_H_
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <termio.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/io.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#endif

View File

@@ -0,0 +1,31 @@
#ifndef _LICENCE_ID__H
#define _LICENCE_ID__H
typedef enum _WXC2_LICENSE_ID
{
LIC_MSC_TRUNK,
LIC_HLR_USERS,
LIC_VLR_USERS,
LIC_AUC_USERS,
LIC_EIR_USERS,
LIC_PPS_USERS,
LIC_SMSC_USERS,
LIC_MNP_USERS,
LIC_GPRS,
LIC_USSD,
LIC_ISUP,
LIC_BICC,
LIC_AIF,
LIC_MGC,
LIC_CAP,
LIC_OPPS_USERS,
LIC_OPPS_OPR,
LIC_OPPS_IMDM,
}WXC2_LICENSE_ID;
/* functionID: listed above,
if functionID doesn't exist, return -1, else return license value
*/
int wxc2_get_license(int functionID);
#endif

View File

@@ -0,0 +1,707 @@
/*
** MEMWATCH.H
** Nonintrusive ANSI C memory leak / overwrite detection
** Copyright (C) 1992-2002 Johan Lindh
** All rights reserved.
** Version 2.71
**
************************************************************************
**
** PURPOSE:
**
** MEMWATCH has been written to allow guys and gals that like to
** program in C a public-domain memory error control product.
** I hope you'll find it's as advanced as most commercial packages.
** The idea is that you use it during the development phase and
** then remove the MEMWATCH define to produce your final product.
** MEMWATCH is distributed in source code form in order to allow
** you to compile it for your platform with your own compiler.
** It's aim is to be 100% ANSI C, but some compilers are more stingy
** than others. If it doesn't compile without warnings, please mail
** me the configuration of operating system and compiler you are using
** along with a description of how to modify the source, and the version
** number of MEMWATCH that you are using.
**
************************************************************************
This file is part of MEMWATCH.
MEMWATCH is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
MEMWATCH is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MEMWATCH; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
************************************************************************
**
** REVISION HISTORY:
**
** 920810 JLI [1.00]
** 920830 JLI [1.10 double-free detection]
** 920912 JLI [1.15 mwPuts, mwGrab/Drop, mwLimit]
** 921022 JLI [1.20 ASSERT and VERIFY]
** 921105 JLI [1.30 C++ support and TRACE]
** 921116 JLI [1.40 mwSetOutFunc]
** 930215 JLI [1.50 modified ASSERT/VERIFY]
** 930327 JLI [1.51 better auto-init & PC-lint support]
** 930506 JLI [1.55 MemWatch class, improved C++ support]
** 930507 JLI [1.60 mwTest & CHECK()]
** 930809 JLI [1.65 Abort/Retry/Ignore]
** 930820 JLI [1.70 data dump when unfreed]
** 931016 JLI [1.72 modified C++ new/delete handling]
** 931108 JLI [1.77 mwSetAssertAction() & some small changes]
** 940110 JLI [1.80 no-mans-land alloc/checking]
** 940328 JLI [2.00 version 2.0 rewrite]
** Improved NML (no-mans-land) support.
** Improved performance (especially for free()ing!).
** Support for 'read-only' buffers (checksums)
** ^^ NOTE: I never did this... maybe I should?
** FBI (free'd block info) tagged before freed blocks
** Exporting of the mwCounter variable
** mwBreakOut() localizes debugger support
** Allocation statistics (global, per-module, per-line)
** Self-repair ability with relinking
** 950913 JLI [2.10 improved garbage handling]
** 951201 JLI [2.11 improved auto-free in emergencies]
** 960125 JLI [X.01 implemented auto-checking using mwAutoCheck()]
** 960514 JLI [2.12 undefining of existing macros]
** 960515 JLI [2.13 possibility to use default new() & delete()]
** 960516 JLI [2.20 suppression of file flushing on unfreed msgs]
** 960516 JLI [2.21 better support for using MEMWATCH with DLL's]
** 960710 JLI [X.02 multiple logs and mwFlushNow()]
** 960801 JLI [2.22 merged X.01 version with current]
** 960805 JLI [2.30 mwIsXXXXAddr() to avoid unneeded GP's]
** 960805 JLI [2.31 merged X.02 version with current]
** 961002 JLI [2.32 support for realloc() + fixed STDERR bug]
** 961222 JLI [2.40 added mwMark() & mwUnmark()]
** 970101 JLI [2.41 added over/underflow checking after failed ASSERT/VERIFY]
** 970113 JLI [2.42 added support for PC-Lint 7.00g]
** 970207 JLI [2.43 added support for strdup()]
** 970209 JLI [2.44 changed default filename to lowercase]
** 970405 JLI [2.45 fixed bug related with atexit() and some C++ compilers]
** 970723 JLI [2.46 added MW_ARI_NULLREAD flag]
** 970813 JLI [2.47 stabilized marker handling]
** 980317 JLI [2.48 ripped out C++ support; wasn't working good anyway]
** 980318 JLI [2.50 improved self-repair facilities & SIGSEGV support]
** 980417 JLI [2.51 more checks for invalid addresses]
** 980512 JLI [2.52 moved MW_ARI_NULLREAD to occur before aborting]
** 990112 JLI [2.53 added check for empty heap to mwIsOwned]
** 990217 JLI [2.55 improved the emergency repairs diagnostics and NML]
** 990224 JLI [2.56 changed ordering of members in structures]
** 990303 JLI [2.57 first maybe-fixit-for-hpux test]
** 990516 JLI [2.58 added 'static' to the definition of mwAutoInit]
** 990517 JLI [2.59 fixed some high-sensitivity warnings]
** 990610 JLI [2.60 fixed some more high-sensitivity warnings]
** 990715 JLI [2.61 changed TRACE/ASSERT/VERIFY macro names]
** 991001 JLI [2.62 added CHECK_BUFFER() and mwTestBuffer()]
** 991007 JLI [2.63 first shot at a 64-bit compatible version]
** 991009 JLI [2.64 undef's strdup() if defined, mwStrdup made const]
** 000704 JLI [2.65 added some more detection for 64-bits]
** 010502 JLI [2.66 incorporated some user fixes]
** [mwRelink() could print out garbage pointer (thanks mac@phobos.ca)]
** [added array destructor for C++ (thanks rdasilva@connecttel.com)]
** [added mutex support (thanks rdasilva@connecttel.com)]
** 010531 JLI [2.67 fix: mwMutexXXX() was declared even if MW_HAVE_MUTEX was not defined]
** 010619 JLI [2.68 fix: mwRealloc() could leave the mutex locked]
** 020918 JLI [2.69 changed to GPL, added C++ array allocation by Howard Cohen]
** 030212 JLI [2.70 mwMalloc() bug for very large allocations (4GB on 32bits)]
** 030520 JLI [2.71 added ULONG_LONG_MAX as a 64-bit detector (thanks Sami Salonen)]
**
** To use, simply include 'MEMWATCH.H' as a header file,
** and add MEMWATCH.C to your list of files, and define the macro
** 'MEMWATCH'. If this is not defined, MEMWATCH will disable itself.
**
** To call the standard C malloc / realloc / calloc / free; use mwMalloc_(),
** mwCalloc_() and mwFree_(). Note that mwFree_() will correctly
** free both malloc()'d memory as well as mwMalloc()'d.
**
** 980317: C++ support has been disabled.
** The code remains, but is not compiled.
**
** For use with C++, which allows use of inlining in header files
** and class specific new/delete, you must also define 'new' as
** 'mwNew' and 'delete' as 'mwDelete'. Do this *after* you include
** C++ header files from libraries, otherwise you can mess up their
** class definitions. If you don't define these, the C++ allocations
** will not have source file and line number information. Also note,
** most C++ class libraries implement their own C++ memory management,
** and don't allow anyone to override them. MFC belongs to this crew.
** In these cases, the only thing to do is to use MEMWATCH_NOCPP.
**
** You can capture output from MEMWATCH using mwSetOutFunc().
** Just give it the adress of a "void myOutFunc(int c)" function,
** and all characters to be output will be redirected there.
**
** A failing ASSERT() or VERIFY() will normally always abort your
** program. This can be changed using mwSetAriFunc(). Give it a
** pointer to a "int myAriFunc(const char *)" function. Your function
** must ask the user whether to Abort, Retry or Ignore the trap.
** Return 2 to Abort, 1 to Retry or 0 to Ignore. Beware retry; it
** causes the expression to be evaluated again! MEMWATCH has a
** default ARI handler. It's disabled by default, but you can enable
** it by calling 'mwDefaultAri()'. Note that this will STILL abort
** your program unless you define MEMWATCH_STDIO to allow MEMWATCH
** to use the standard C I/O streams. Also, setting the ARI function
** will cause MEMWATCH *NOT* to write the ARI error to stderr. The
** error string is passed to the ARI function instead, as the
** 'const char *' parameter.
**
** You can disable MEMWATCH's ASSERT/VERIFY and/or TRACE implementations.
** This can be useful if you're using a debug terminal or smart debugger.
** Disable them by defining MW_NOASSERT, MW_NOVERIFY or MW_NOTRACE.
**
** MEMWATCH fills all allocated memory with the byte 0xFE, so if
** you're looking at erroneous data which are all 0xFE:s, the
** data probably was not initialized by you. The exception is
** calloc(), which will fill with zero's. All freed buffers are
** zapped with 0xFD. If this is what you look at, you're using
** data that has been freed. If this is the case, be aware that
** MEMWATCH places a 'free'd block info' structure immediately
** before the freed data. This block contains info about where
** the block was freed. The information is in readable text,
** in the format "FBI<counter>filename(line)", for example:
** "FBI<267>test.c(12)". Using FBI's slows down free(), so it's
** disabled by default. Use mwFreeBufferInfo(1) to enable it.
**
** To aid in tracking down wild pointer writes, MEMWATCH can perform
** no-mans-land allocations. No-mans-land will contain the byte 0xFC.
** MEMWATCH will, when this is enabled, convert recently free'd memory
** into NML allocations.
**
** MEMWATCH protects it's own data buffers with checksums. If you
** get an internal error, it means you're overwriting wildly,
** or using an uninitialized pointer.
**
************************************************************************
**
** Note when compiling with Microsoft C:
** - MSC ignores fflush() by default. This is overridden, so that
** the disk log will always be current.
**
** This utility has been tested with:
** PC-lint 7.0k, passed as 100% ANSI C compatible
** Microsoft Visual C++ on Win16 and Win32
** Microsoft C on DOS
** SAS C on an Amiga 500
** Gnu C on a PC running Red Hat Linux
** ...and using an (to me) unknown compiler on an Atari machine.
**
************************************************************************
**
** Format of error messages in MEMWATCH.LOG:
** message: <sequence-number> filename(linenumber), information
**
** Errors caught by MemWatch, when they are detected, and any
** actions taken besides writing to the log file MEMWATCH.LOG:
**
** Double-freeing:
** A pointer that was recently freed and has not since been
** reused was freed again. The place where the previous free()
** was executed is displayed.
** Detect: delete or free() using the offending pointer.
** Action: The delete or free() is cancelled, execution continues.
** Underflow:
** You have written just ahead of the allocated memory.
** The size and place of the allocation is displayed.
** Detect: delete or free() of the damaged buffer.
** Action: The buffer is freed, but there may be secondary damage.
** Overflow:
** Like underflow, but you've written after the end of the buffer.
** Detect: see Underflow.
** Action: see Underflow.
** WILD free:
** An unrecognized pointer was passed to delete or free().
** The pointer may have been returned from a library function;
** in that case, use mwFree_() to force free() of it.
** Also, this may be a double-free, but the previous free was
** too long ago, causing MEMWATCH to 'forget' it.
** Detect: delete or free() of the offending pointer.
** Action: The delete or free() is cancelled, execution continues.
** NULL free:
** It's unclear to me whether or not freeing of NULL pointers
** is legal in ANSI C, therefore a warning is written to the log file,
** but the error counter remains the same. This is legal using C++,
** so the warning does not appear with delete.
** Detect: When you free(NULL).
** Action: The free() is cancelled.
** Failed:
** A request to allocate memory failed. If the allocation is
** small, this may be due to memory depletion, but is more likely
** to be memory fragmentation problems. The amount of memory
** allocated so far is displayed also.
** Detect: When you new, malloc(), realloc() or calloc() memory.
** Action: NULL is returned.
** Realloc:
** A request to re-allocate a memory buffer failed for reasons
** other than out-of-memory. The specific reason is shown.
** Detect: When you realloc()
** Action: realloc() is cancelled, NULL is returned
** Limit fail:
** A request to allocate memory failed since it would violate
** the limit set using mwLimit(). mwLimit() is used to stress-test
** your code under simulated low memory conditions.
** Detect: At new, malloc(), realloc() or calloc().
** Action: NULL is returned.
** Assert trap:
** An ASSERT() failed. The ASSERT() macro works like C's assert()
** macro/function, except that it's interactive. See your C manual.
** Detect: On the ASSERT().
** Action: Program ends with an advisory message to stderr, OR
** Program writes the ASSERT to the log and continues, OR
** Program asks Abort/Retry/Ignore? and takes that action.
** Verify trap:
** A VERIFY() failed. The VERIFY() macro works like ASSERT(),
** but if MEMWATCH is not defined, it still evaluates the
** expression, but it does not act upon the result.
** Detect: On the VERIFY().
** Action: Program ends with an advisory message to stderr, OR
** Program writes the VERIFY to the log and continues, OR
** Program asks Abort/Retry/Ignore? and takes that action.
** Wild pointer:
** A no-mans-land buffer has been written into. MEMWATCH can
** allocate and distribute chunks of memory solely for the
** purpose of trying to catch random writes into memory.
** Detect: Always on CHECK(), but can be detected in several places.
** Action: The error is logged, and if an ARI handler is installed,
** it is executed, otherwise, execution continues.
** Unfreed:
** A memory buffer you allocated has not been freed.
** You are informed where it was allocated, and whether any
** over or underflow has occured. MemWatch also displays up to
** 16 bytes of the data, as much as it can, in hex and text.
** Detect: When MemWatch terminates.
** Action: The buffer is freed.
** Check:
** An error was detected during a CHECK() operation.
** The associated pointer is displayed along with
** the file and line where the CHECK() was executed.
** Followed immediately by a normal error message.
** Detect: When you CHECK()
** Action: Depends on the error
** Relink:
** After a MEMWATCH internal control block has been trashed,
** MEMWATCH tries to repair the damage. If successful, program
** execution will continue instead of aborting. Some information
** about the block may be gone permanently, though.
** Detect: N/A
** Action: Relink successful: program continues.
** Relink fails: program aborts.
** Internal:
** An internal error is flagged by MEMWATCH when it's control
** structures have been damaged. You are likely using an uninitialized
** pointer somewhere in your program, or are zapping memory all over.
** The message may give you additional diagnostic information.
** If possible, MEMWATCH will recover and continue execution.
** Detect: Various actions.
** Action: Whatever is needed
** Mark:
** The program terminated without umarking all marked pointers. Marking
** can be used to track resources other than memory. mwMark(pointer,text,...)
** when the resource is allocated, and mwUnmark(pointer) when it's freed.
** The 'text' is displayed for still marked pointers when the program
** ends.
** Detect: When MemWatch terminates.
** Action: The error is logged.
**
**
************************************************************************
**
** The author may be reached by e-mail at the address below. If you
** mail me about source code changes in MEMWATCH, remember to include
** MW's version number.
**
** Johan Lindh
** johan@linkdata.se
**
** The latest version of MEMWATCH may be downloaded from
** http://www.linkdata.se/
*/
#ifndef __MEMWATCH_H
#define __MEMWATCH_H
/* Make sure that malloc(), realloc(), calloc() and free() are declared. */
/*lint -save -e537 */
#include <stdlib.h>
/*lint -restore */
#ifdef __cplusplus
extern "C" {
#endif
/*
** Constants used
** All MEMWATCH constants start with the prefix MW_, followed by
** a short mnemonic which indicates where the constant is used,
** followed by a descriptive text about it.
*/
#define MW_ARI_NULLREAD 0x10 /* Null read (to start debugger) */
#define MW_ARI_ABORT 0x04 /* ARI handler says: abort program! */
#define MW_ARI_RETRY 0x02 /* ARI handler says: retry action! */
#define MW_ARI_IGNORE 0x01 /* ARI handler says: ignore error! */
#define MW_VAL_NEW 0xFE /* value in newly allocated memory */
#define MW_VAL_DEL 0xFD /* value in newly deleted memory */
#define MW_VAL_NML 0xFC /* value in no-mans-land */
#define MW_VAL_GRB 0xFB /* value in grabbed memory */
#define MW_TEST_ALL 0xFFFF /* perform all tests */
#define MW_TEST_CHAIN 0x0001 /* walk the heap chain */
#define MW_TEST_ALLOC 0x0002 /* test allocations & NML guards */
#define MW_TEST_NML 0x0004 /* test all-NML areas for modifications */
#define MW_NML_NONE 0 /* no NML */
#define MW_NML_FREE 1 /* turn FREE'd memory into NML */
#define MW_NML_ALL 2 /* all unused memory is NML */
#define MW_NML_DEFAULT 0 /* the default NML setting */
#define MW_STAT_GLOBAL 0 /* only global statistics collected */
#define MW_STAT_MODULE 1 /* collect statistics on a module basis */
#define MW_STAT_LINE 2 /* collect statistics on a line basis */
#define MW_STAT_DEFAULT 0 /* the default statistics setting */
/*
** MemWatch internal constants
** You may change these and recompile MemWatch to change the limits
** of some parameters. Respect the recommended minimums!
*/
#define MW_TRACE_BUFFER 2048 /* (min 160) size of TRACE()'s output buffer */
#define MW_FREE_LIST 64 /* (min 4) number of free()'s to track */
/*
** Exported variables
** In case you have to remove the 'const' keyword because your compiler
** doesn't support it, be aware that changing the values may cause
** unpredictable behaviour.
** - mwCounter contains the current action count. You can use this to
** place breakpoints using a debugger, if you want.
*/
#ifndef __MEMWATCH_C
extern const unsigned long mwCounter;
#endif
/*
** System functions
** Normally, it is not nessecary to call any of these. MEMWATCH will
** automatically initialize itself on the first MEMWATCH function call,
** and set up a call to mwAbort() using atexit(). Some C++ implementations
** run the atexit() chain before the program has terminated, so you
** may have to use mwInit() or the MemWatch C++ class to get good
** behaviour.
** - mwInit() can be called to disable the atexit() usage. If mwInit()
** is called directly, you must call mwTerm() to end MemWatch, or
** mwAbort().
** - mwTerm() is usually not nessecary to call; but if called, it will
** call mwAbort() if it finds that it is cancelling the 'topmost'
** mwInit() call.
** - mwAbort() cleans up after MEMWATCH, reports unfreed buffers, etc.
*/
void mwInit( void );
void mwTerm( void );
void mwAbort( void );
/*
** Setup functions
** These functions control the operation of MEMWATCH's protective features.
** - mwFlushNow() causes MEMWATCH to flush it's buffers.
** - mwDoFlush() controls whether MEMWATCH flushes the disk buffers after
** writes. The default is smart flushing: MEMWATCH will not flush buffers
** explicitly until memory errors are detected. Then, all writes are
** flushed until program end or mwDoFlush(0) is called.
** - mwLimit() sets the allocation limit, an arbitrary limit on how much
** memory your program may allocate in bytes. Used to stress-test app.
** Also, in virtual-memory or multitasking environs, puts a limit on
** how much MW_NML_ALL can eat up.
** - mwGrab() grabs up X kilobytes of memory. Allocates actual memory,
** can be used to stress test app & OS both.
** - mwDrop() drops X kilobytes of grabbed memory.
** - mwNoMansLand() sets the behaviour of the NML logic. See the
** MW_NML_xxx for more information. The default is MW_NML_DEFAULT.
** - mwStatistics() sets the behaviour of the statistics collector. See
** the MW_STAT_xxx defines for more information. Default MW_STAT_DEFAULT.
** - mwFreeBufferInfo() enables or disables the tagging of free'd buffers
** with freeing information. This information is written in text form,
** using sprintf(), so it's pretty slow. Disabled by default.
** - mwAutoCheck() performs a CHECK() operation whenever a MemWatch function
** is used. Slows down performance, of course.
** - mwCalcCheck() calculates checksums for all data buffers. Slow!
** - mwDumpCheck() logs buffers where stored & calc'd checksums differ. Slow!!
** - mwMark() sets a generic marker. Returns the pointer given.
** - mwUnmark() removes a generic marker. If, at the end of execution, some
** markers are still in existence, these will be reported as leakage.
** returns the pointer given.
*/
void mwFlushNow( void );
void mwDoFlush( int onoff );
void mwLimit( long bytes );
unsigned mwGrab( unsigned kilobytes );
unsigned mwDrop( unsigned kilobytes );
void mwNoMansLand( int mw_nml_level );
void mwStatistics( int level );
void mwFreeBufferInfo( int onoff );
void mwAutoCheck( int onoff );
void mwCalcCheck( void );
void mwDumpCheck( void );
void * mwMark( void *p, const char *description, const char *file, unsigned line );
void * mwUnmark( void *p, const char *file, unsigned line );
/*
** Testing/verification/tracing
** All of these macros except VERIFY() evaluates to a null statement
** if MEMWATCH is not defined during compilation.
** - mwIsReadAddr() checks a memory area for read privilige.
** - mwIsSafeAddr() checks a memory area for both read & write privilige.
** This function and mwIsReadAddr() is highly system-specific and
** may not be implemented. If this is the case, they will default
** to returning nonzero for any non-NULL pointer.
** - CHECK() does a complete memory integrity test. Slow!
** - CHECK_THIS() checks only selected components.
** - CHECK_BUFFER() checks the indicated buffer for errors.
** - mwASSERT() or ASSERT() If the expression evaluates to nonzero, execution continues.
** Otherwise, the ARI handler is called, if present. If not present,
** the default ARI action is taken (set with mwSetAriAction()).
** ASSERT() can be disabled by defining MW_NOASSERT.
** - mwVERIFY() or VERIFY() works just like ASSERT(), but when compiling without
** MEMWATCH the macro evaluates to the expression.
** VERIFY() can be disabled by defining MW_NOVERIFY.
** - mwTRACE() or TRACE() writes some text and data to the log. Use like printf().
** TRACE() can be disabled by defining MW_NOTRACE.
*/
int mwIsReadAddr( const void *p, unsigned len );
int mwIsSafeAddr( void *p, unsigned len );
int mwTest( const char *file, int line, int mw_test_flags );
int mwTestBuffer( const char *file, int line, void *p );
int mwAssert( int, const char*, const char*, int );
int mwVerify( int, const char*, const char*, int );
/*
** User I/O functions
** - mwTrace() works like printf(), but dumps output either to the
** function specified with mwSetOutFunc(), or the log file.
** - mwPuts() works like puts(), dumps output like mwTrace().
** - mwSetOutFunc() allows you to give the adress of a function
** where all user output will go. (exeption: see mwSetAriFunc)
** Specifying NULL will direct output to the log file.
** - mwSetAriFunc() gives MEMWATCH the adress of a function to call
** when an 'Abort, Retry, Ignore' question is called for. The
** actual error message is NOT printed when you've set this adress,
** but instead it is passed as an argument. If you call with NULL
** for an argument, the ARI handler is disabled again. When the
** handler is disabled, MEMWATCH will automatically take the
** action specified by mwSetAriAction().
** - mwSetAriAction() sets the default ARI return value MEMWATCH should
** use if no ARI handler is specified. Defaults to MW_ARI_ABORT.
** - mwAriHandler() is an ANSI ARI handler you can use if you like. It
** dumps output to stderr, and expects input from stdin.
** - mwBreakOut() is called in certain cases when MEMWATCH feels it would
** be nice to break into a debugger. If you feel like MEMWATCH, place
** an execution breakpoint on this function.
*/
void mwTrace( const char* format_string, ... );
void mwPuts( const char* text );
void mwSetOutFunc( void (*func)(int) );
void mwSetAriFunc( int (*func)(const char*) );
void mwSetAriAction( int mw_ari_value );
int mwAriHandler( const char* cause );
void mwBreakOut( const char* cause );
/*
** Allocation/deallocation functions
** These functions are the ones actually to perform allocations
** when running MEMWATCH, for both C and C++ calls.
** - mwMalloc() debugging allocator
** - mwMalloc_() always resolves to a clean call of malloc()
** - mwRealloc() debugging re-allocator
** - mwRealloc_() always resolves to a clean call of realloc()
** - mwCalloc() debugging allocator, fills with zeros
** - mwCalloc_() always resolves to a clean call of calloc()
** - mwFree() debugging free. Can only free memory which has
** been allocated by MEMWATCH.
** - mwFree_() resolves to a) normal free() or b) debugging free.
** Can free memory allocated by MEMWATCH and malloc() both.
** Does not generate any runtime errors.
*/
void* mwMalloc( size_t, const char*, int );
void* mwMalloc_( size_t );
void* mwRealloc( void *, size_t, const char*, int );
void* mwRealloc_( void *, size_t );
void* mwCalloc( size_t, size_t, const char*, int );
void* mwCalloc_( size_t, size_t );
void mwFree( void*, const char*, int );
void mwFree_( void* );
char* mwStrdup( const char *, const char*, int );
/*
** Enable/disable precompiler block
** This block of defines and if(n)defs make sure that references
** to MEMWATCH is completely removed from the code if the MEMWATCH
** manifest constant is not defined.
*/
#ifndef __MEMWATCH_C
#ifdef MEMWATCH
#define mwASSERT(exp) while(mwAssert((int)(exp),#exp,__FILE__,__LINE__))
#ifndef MW_NOASSERT
#ifndef ASSERT
#define ASSERT mwASSERT
#endif /* !ASSERT */
#endif /* !MW_NOASSERT */
#define mwVERIFY(exp) while(mwVerify((int)(exp),#exp,__FILE__,__LINE__))
#ifndef MW_NOVERIFY
#ifndef VERIFY
#define VERIFY mwVERIFY
#endif /* !VERIFY */
#endif /* !MW_NOVERIFY */
#define mwTRACE mwTrace
#ifndef MW_NOTRACE
#ifndef TRACE
#define TRACE mwTRACE
#endif /* !TRACE */
#endif /* !MW_NOTRACE */
/* some compilers use a define and not a function */
/* for strdup(). */
#ifdef strdup
#undef strdup
#endif
#define malloc(n) mwMalloc(n,__FILE__,__LINE__)
#define strdup(p) mwStrdup(p,__FILE__,__LINE__)
#define realloc(p,n) mwRealloc(p,n,__FILE__,__LINE__)
#define calloc(n,m) mwCalloc(n,m,__FILE__,__LINE__)
#define free(p) mwFree(p,__FILE__,__LINE__)
#define CHECK() mwTest(__FILE__,__LINE__,MW_TEST_ALL)
#define CHECK_THIS(n) mwTest(__FILE__,__LINE__,n)
#define CHECK_BUFFER(b) mwTestBuffer(__FILE__,__LINE__,b)
#define MARK(p) mwMark(p,#p,__FILE__,__LINE__)
#define UNMARK(p) mwUnmark(p,__FILE__,__LINE__)
#else /* MEMWATCH */
#define mwASSERT(exp)
#ifndef MW_NOASSERT
#ifndef ASSERT
#define ASSERT mwASSERT
#endif /* !ASSERT */
#endif /* !MW_NOASSERT */
#define mwVERIFY(exp) exp
#ifndef MW_NOVERIFY
#ifndef VERIFY
#define VERIFY mwVERIFY
#endif /* !VERIFY */
#endif /* !MW_NOVERIFY */
/*lint -esym(773,mwTRACE) */
#define mwTRACE /*lint -save -e506 */ 1?(void)0:mwDummyTraceFunction /*lint -restore */
#ifndef MW_NOTRACE
#ifndef TRACE
/*lint -esym(773,TRACE) */
#define TRACE mwTRACE
#endif /* !TRACE */
#endif /* !MW_NOTRACE */
extern void mwDummyTraceFunction(const char *,...);
/*lint -save -e652 */
#define mwDoFlush(n)
#define mwPuts(s)
#define mwInit()
#define mwGrab(n)
#define mwDrop(n)
#define mwLimit(n)
#define mwTest(f,l)
#define mwSetOutFunc(f)
#define mwSetAriFunc(f)
#define mwDefaultAri()
#define mwNomansland()
#define mwStatistics(f)
#define mwMark(p,t,f,n) (p)
#define mwUnmark(p,f,n) (p)
#define mwMalloc(n,f,l) malloc(n)
#define mwStrdup(p,f,l) strdup(p)
#define mwRealloc(p,n,f,l) realloc(p,n)
#define mwCalloc(n,m,f,l) calloc(n,m)
#define mwFree(p) free(p)
#define mwMalloc_(n) malloc(n)
#define mwRealloc_(p,n) realloc(p,n)
#define mwCalloc_(n,m) calloc(n,m)
#define mwFree_(p) free(p)
#define mwAssert(e,es,f,l)
#define mwVerify(e,es,f,l) (e)
#define mwTrace mwDummyTrace
#define mwTestBuffer(f,l,b) (0)
#define CHECK()
#define CHECK_THIS(n)
#define CHECK_BUFFER(b)
#define MARK(p) (p)
#define UNMARK(p) (p)
/*lint -restore */
#endif /* MEMWATCH */
#endif /* !__MEMWATCH_C */
#ifdef __cplusplus
}
#endif
#if 0 /* 980317: disabled C++ */
/*
** C++ support section
** Implements the C++ support. Please note that in order to avoid
** messing up library classes, C++ support is disabled by default.
** You must NOT enable it until AFTER the inclusion of all header
** files belonging to code that are not compiled with MEMWATCH, and
** possibly for some that are! The reason for this is that a C++
** class may implement it's own new() function, and the preprocessor
** would substitute this crucial declaration for MEMWATCH new().
** You can forcibly deny C++ support by defining MEMWATCH_NOCPP.
** To enble C++ support, you must be compiling C++, MEMWATCH must
** be defined, MEMWATCH_NOCPP must not be defined, and finally,
** you must define 'new' to be 'mwNew', and 'delete' to be 'mwDelete'.
** Unlike C, C++ code can begin executing *way* before main(), for
** example if a global variable is created. For this reason, you can
** declare a global variable of the class 'MemWatch'. If this is
** is the first variable created, it will then check ALL C++ allocations
** and deallocations. Unfortunately, this evaluation order is not
** guaranteed by C++, though the compilers I've tried evaluates them
** in the order encountered.
*/
#ifdef __cplusplus
#ifndef __MEMWATCH_C
#ifdef MEMWATCH
#ifndef MEMWATCH_NOCPP
extern int mwNCur;
extern const char *mwNFile;
extern int mwNLine;
class MemWatch {
public:
MemWatch();
~MemWatch();
};
void * operator new(size_t);
void * operator new(size_t,const char *,int);
void * operator new[] (size_t,const char *,int); // hjc 07/16/02
void operator delete(void *);
#define mwNew new(__FILE__,__LINE__)
#define mwDelete (mwNCur=1,mwNFile=__FILE__,mwNLine=__LINE__),delete
#endif /* MEMWATCH_NOCPP */
#endif /* MEMWATCH */
#endif /* !__MEMWATCH_C */
#endif /* __cplusplus */
#endif /* 980317: disabled C++ */
#endif /* __MEMWATCH_H */
/* EOF MEMWATCH.H */

View File

@@ -0,0 +1,643 @@
/************************************************************************/
/* Title: omc_public.h */
/* Desc: Public variables def for PACS OMC Project. */
/* Author: Meng Xiaozhen */
/* CrtDate: 2000-08-16 */
/* AltDate: 2001-06-21 */
/* CVS: $Id: omc_public.h,v 1.1 2000/08/03 01:09:33 mengxz Exp $ */
/************************************************************************/
#ifndef OMC_PUBLIC__H
#define OMC_PUBLIC__H
#ifndef PUBLIC__H
#include "public.h"
#endif
#ifndef IPTRANS__H
#include "iptrans.h"
#endif
#define DEBUG 1
/***************************************************/
/* Macro define for Server's system number */
#define GRP_NUM 32
#define TS_NUM 32
#define TS_SUB 16
#define TS_E1 8
#define PW_NUM 32
#define PW_SUB 3
#define ETH_NUM 32
#define ETH_SUB 16
#define RDEV_NUM 32
#define RDEV_SUB 8
#define RDEV_E1 1
#define BSS_NUM 48
#define BSC_NUM 12
#define BSC_SUB 9
#define BSC_E1 2
#define BTS_NUM 24 //BTS system include 12 BTS subsystem
#define BTSSITE_NUM 48 //BTS site include 6 BTS subsystem
#define BTS_SUB 12
#define BTS_E1 2
#define SVR_NUM 36
#define CONN_NUM 128
#define CLIENT_NUM 50
#define BTN_NUM 66
#define ALARM_NUM 20
#define CACHE_BUF 512
/***************************************************/
/***************************************************/
/* Macro definition of start ID for applet's button used by system device */
#define TS_START_BTN 0
#define RDEV_START_BTN 18
#define SVR_START_BTN 34
#define BSC_START_BTN 54
/***************************************************/
/***************************************************/
/* Macro define for Server's IP Address */
#define OMC_0 "172.18.128.1"
#define OMC_1 "172.18.129.1"
#define HLR_0 "172.18.132.1"
#define HLR_1 "172.18.133.1"
#define PPS_0 "172.18.136.1"
#define PPS_1 "172.18.137.1"
#define CDR_0 "172.18.160.1"
#define CDR_1 "172.18.161.1"
/***************************************************/
/***************************************************/
/* Macro define for Mysql Database */
#define HOST_NAME "localhost"
#define DB_NAME1 "mysql"
#define DB_PORT_NUM 0
#define SOCKET_NAME NULL
#define FLAGS 0
#define USER_NAME "root"
#define PASSWORD "rootaa"
/***************************************************/
/***************************************************/
/* Macro def for (UDP)Communication port used by OMC */
#define PORT_OUT 4951 //for sending message to ts
#define PORT_BASE 4951
#define PORT_REALSTAT 3 /* 4951 + 3 = 4954 */
#define PORT_CSTA 4 /* 4951 + 4 = 4955 */
#define PORT_COMM 5 /* 4951 + 5 = 4956 */
#define PORT_HEARTBEAT 6 /* 4951 + 6 = 4957 */
#define PORT_CLUSTER 27 /* 4951 + 27 =4978 */
#define BROADCAST_IP "172.18.255.255"
#define CLUSTER_IP "239.255.10.1"
#define BROADCAST 0 //if broadcast message
/***************************************************/
/* Macro def for shm key and sem key used by OMC */
#define COMM_FLAG_SHM_KEY 0x6a000000
#define COMM_FLAG_SHM_PERM 0666
#define COMM_FLAG_SEM_KEY 300
#define COMM_FLAG_SEM_PERM 0666
#define COMM_FLAG_SEM_NUM 1
#define COMM_FLAG_SIZE 1024
#define COMM_LIST_SHM_KEY 0x6a100000
#define COMM_LIST_SHM_PERM 0666
#define COMM_LIST_SEM_KEY 310
#define COMM_LIST_SEM_PERM 0666
#define COMM_LIST_SEM_NUM 1
#define STATUS_SHM_KEY 0x6a200000
#define STATUS_SHM_PERM 0666
#define STATUS_SEM_KEY 320
#define STATUS_SEM_PERM 0666
#define STATUS_SEM_NUM 1
#define CACHE_SHM_KEY 0x6a400000
#define CACHE_SHM_PERM 0666
#define CACHE_SEM_KEY 340
#define CACHE_SEM_PERM 0666
#define CACHE_SEM_NUM 1
#define BSS_SHM_KEY 0x6a600000
#define BSS_SHM_PERM 0666
#define BSS_SEM_KEY 360
#define BSS_SEM_PERM 0666
#define BSS_SEM_NUM 1
#define LED_SHM_KEY 0x6a800000
#define LED_SHM_PERM 0666
#define LED_SEM_KEY 380
#define LED_SEM_PERM 0666
#define LED_SEM_NUM 1
#define CLUSTER_SHM_KEY 0x6a900000
#define CLUSTER_SHM_PERM 0666
#define CLUSTER_SEM_KEY 390
#define CLUSTER_SEM_PERM 0666
#define CLUSTER_SEM_NUM 1
/***************************************************/
/*############################################################################
* shm structure
* between heartbeat transceiver and heartbeat processor
* &
* between heartbeat transceiver and svr cluster processor
*###########################################################################*/
typedef struct cache_list{
long msgSrcIP;
u_short msgLength;
BYTE msgContent[CACHE_BUF];
}cache_list;
typedef struct status_cahce{
//int send_flag;
/*this flag is only for server cluster funciton
*0/1/2=ignore cluster FSM influence,directly send heartbeat/cluster permit *to send heartbeat/can't send heartbeat,waiting cluster's info
*/
u_short msgReadSub;
u_short msgWriteSub;
cache_list msgcache[CACHE_BUF];
}status_cache;
/*############################################################################
* shm structure between real status processor and heartbeat processor
*###########################################################################*/
typedef struct clientinfo {
BYTE used_flag; // 0/1=not used/used
BYTE grp_id; // group which is requested by client now
BYTE is_responsed; // 0/1/2=not response/responsing/responsed
long ip;
unsigned int waittime; //if waittime>60seconds,timeout
BYTE updatetime[16]; //last time when client request info
} client_info;
typedef struct conninfo {
BYTE avail_flag; // 0/1=unavailable/available
BYTE disp_name; // 0/1=not display/display
char name[16];
char remark[44];
BYTE lsys_type;// local device system type
BYTE lsys_id; //local device system id
BYTE lsub_id; //local device subsystem id
BYTE rsys_type; //remote device system type
BYTE rsys_id; //remote device system id
BYTE rsub_id; //remote device subsystem id
} conn_info;
typedef struct btninfo {
BYTE used_flag; // 0/1=not use/used
BYTE sys_type; // device system type
BYTE sys_id; // device system id
BYTE sub_id; // device subsystem id
} btn_info;
typedef struct grp_simple_stat {
btn_info btn[BTN_NUM]; // relationship between button and device
unsigned int coord[2]; // X,Y coord for group icon
int critical; // critical counter
int alarm; // alarm counter
BYTE isinstalled; // 0/1=not install/install
BYTE ts_id[2]; // Transit switch id(default=99,no ts)
BYTE disp_name; // 0/1=not display/display
BYTE grp_name[17]; // Group name
BYTE grp_remark[45]; // remark about group
BYTE stat_amount; // number of status for group icon
BYTE stat_direct; // direction of display status (0/1=h/v)
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3= uninstalled
*/
}grpsimple_stat;
typedef struct subts_detail_stat {
BYTE subtype; //subsystem status
BYTE timeout; //if the subsystem is timeout(0/1=timeout/not)
BYTE substat0[8];// simple status of this subsystem
/* substat0[0] -- if subsys is installed(0/1=not/yes)
* substat0[1] -- if subsys is normal(0/1=abnormal/normal)
* substat0[2] -- if subsys send master clock(0/1=not/sending)
* substat0[3] -- locking clock(0-7:2=normal,7=idle,other=abnormal)
*/
BYTE substat1[8]; // performance or status data of subsystem
/* substat1[0-1] -- CPU Load ('00'-'45')
* substat1[2-4] -- Clock frequency('000'-'255')
*/
BYTE e1stat0[TS_E1][8]; //simple status of all E1
/* e1[i][0] -- e1[i] installed/not installed (0/1=not/yes)
* e1[i][1] -- e1[i] layer 2 installed/not installed (0/1=not/yes)
* e1[i][2] -- e1[i] layer 1 connected/disconnected (0/1=not/yes)
* e1[i][3] -- e1[i] layer 2 connected/disconnected (0/1=not/yes)
* e1[i][4] -- e1[i] without/with ECHO CANCELLER (0/1=not/yes)
*/
BYTE e1stat1[TS_E1][8]; // performance or status data of all E1
/* e1[i][0-1] -- e1[i] idle channels('00'/'30')
*/
long lock_alarmtime;
/*last time inserting alarm log into db because of clock locking error
*/
long e1_alarmtime[TS_E1][2];
/*last time inserting alarm log into db because of e1 1,2th error
*/
BYTE version_info[16];
/*version information for the application
*/
BYTE updatetime[16]; //last time refreshing subsystem status
}subtsdetail_stat;
typedef struct subpw_detail_stat {
BYTE timeout; //if the subsystem is timeout(0/1=timeout/not)
BYTE substat[2]; // status of this subsystem(0/1=abnomal/normal)
/* substat[0] -- if subsys is installed(0/1=not/yes)
* substat[1] -- if subsys is normal(0/1=abnormal/normal)
*/
long pcard_alarmtime;
/*last time inserting alarm log into db because of power card error
*/
BYTE updatetime[16]; //last time refreshing subsystem status
}subpwdetail_stat;
typedef struct ts_detail_stat {
BYTE grp_id;
BYTE clock_status;//if master clock is normal(0/1=N/Y)
long clock_alarmtime;//master clock status
/*last time inserting alarm log into db because of master clock error
*/
subtsdetail_stat sub_detail[TS_SUB];
subpwdetail_stat subpw_detail[PW_SUB];
}tsdetail_stat;
typedef struct subts_simple_stat {
BYTE isinstalled;
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
int waittime; // if TS subsystem is timeout
BYTE issent ; // if sending get request to timeout ts subsystem
} subtssimple_stat;
typedef struct ts_simple_stat {
BYTE isinstalled; // 0/1=N/Y
BYTE location; // 0/1=local/remote
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE grp_id;
BYTE disp_name; // 0/1=not display/display
BYTE name[16];
BYTE remark[44];
int coord[2];
BYTE stat_amount; // number of status for ts icon
BYTE stat_direct; // direction of display status (0/1=h/v)
subtssimple_stat sub_simple[TS_SUB];
subtssimple_stat subpw_simple[PW_SUB];
} tssimple_stat;
typedef struct subeth_detail_stat {
BYTE timeout; //if the subsystem is timeout(0/1=timeout/not)
long self_ip; //ip address of LAN Module self
BYTE mac[6]; //physical address of LAN Module
BYTE substat[6];
/* substat[0] -- if LAN Module is installed(0/1)
* substat[1] -- if LAN Module is normal(0/1)
* substat[2] -- if there is unreachable ip(0/1)
* substat[3] -- if LAN Module upload program to csu(0/1)
* substat[4] -- if csu is availabe (0/1)
*/
BYTE cpu_load[2]; //CPU load of LAN module(hex value)
BYTE unreachable_ip[4]; //ip Can't be found by LAN Module (hex value)
long unreach_time;
long alarmtime[2];
/*CSU Upload program status
*alarmtime[0] -- can't reach target ip address
*alarmtime[1] -- uploading program
*/
BYTE version_info[16];
/*version information for the application
*/
char updatetime[16];
}subethdetail_stat;
typedef struct eth_detail_stat {
BYTE grp_id;
subethdetail_stat sub_detail[ETH_SUB];
}ethdetail_stat;
typedef struct subeth_simple_stat {
BYTE isinstalled;
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
int waittime; // if TS subsystem is timeout
BYTE issent ; // if sending get request to timeout ts subsystem
} subethsimple_stat;
typedef struct eth_simple_stat {
BYTE isinstalled; // 0/1=N/Y
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE grp_id;
subethsimple_stat sub_simple[ETH_SUB];
} ethsimple_stat;
typedef struct subrdev_detail_stat {
BYTE subtype; //0-4
BYTE timeout; //if the subsystem is timeout(0/1=timeout/not)
BYTE substat0[6];
/* substat[0] -- if subsys is installed(0/1=N/Y)
* substat[1] -- if subsys is normal(0/1=N/Y)
* sysstat[2] -- if send master clock(0/1=N/Y)
*/
BYTE substat1[6];
/* substat[0-1] -- used CPU(00/30)
*/
BYTE e1stat0[RDEV_E1][8];
/* e1[0] -- e1 installed/not installed (0/1=N/Y)
* e1[1] -- e1 layer 1 connected/disconnected (0/1=N/Y)
* e1[2] -- e1 layer 2 connected/disconnected (0/1=N/Y)
*/
BYTE e1stat1[RDEV_E1][8];
/* e1[i][0-1] -- e1 idle channels('00'--'30')
*/
long e1_alarmtime[RDEV_E1][2];
/* alarmtime[i][0] -- e1[i] layer 1
* alarmtime[i][1] -- e1[i] layer 2
*/
BYTE version_info[16];
/*version information for the application
*/
char updatetime[16];
}subrdevdetail_stat;
typedef struct rdev_detail_stat {
BYTE grp_id;
BYTE systype; //05=VPS;06=PCR
BYTE clock_status;//if master clock is normal(0/1=N/Y)
long clock_alarmtime;//master clock status
/*last time inserting alarm log into db because of master clock error
*/
subrdevdetail_stat sub_detail[RDEV_SUB];
}rdevdetail_stat;
typedef struct subrdev_simple_stat {
BYTE isinstalled;
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
int waittime; // if Rdev subsystem is timeout
BYTE issent ; // if sending get request to timeout ts subsystem
} subrdevsimple_stat;
typedef struct rdev_simple_stat {
BYTE isinstalled; // 0/1=N/Y
BYTE location; // 0/1=local/remote
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE grp_id;
BYTE disp_name; // 0/1=not display/display
BYTE name[16];
BYTE remark[44];
int coord[2];
BYTE stat_amount; // number of status for rdev icon
BYTE stat_direct; // direction of display status (0/1=h/v)
subrdevsimple_stat sub_simple[RDEV_SUB];
} rdevsimple_stat;
typedef struct bts_simple_stat {
BYTE isinstalled; // 0/1=not/installed
BYTE bts_site_id;
BYTE bts_link_id;
BYTE location; // 0/1=local/remote
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE grp_id;
BYTE disp_name; // 0/1=not display/display
BYTE name[16];
BYTE remark[44];
int coord[2];
BYTE stat_amount; // number of status for bts site icon
BYTE stat_direct; // direction of display status (0/1=h/v)
} btssimple_stat;
typedef struct bsc_simple_stat {
BYTE isinstalled; // 0/1=not/installed
BYTE location; // 0/1=local/remote
BYTE timeout; // 0/1=timeout/not timeout
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE grp_id;
BYTE disp_name; // 0/1=not display/display
BYTE name[16];
BYTE remark[44];
int coord[2];
BYTE stat_amount; // number of status for bsc icon
BYTE stat_direct; // direction of display status (0/1=h/v)
} bscsimple_stat;
/* structure for server detail status in heartbeat processor
************************************/
typedef struct svr_detail_stat {
BYTE timeout; //if the subsystem is timeout(0/1=not/timeout)
BYTE grp_id;
BYTE systype;
BYTE sys_id;
int cpuused;
int viravail;
int virfree;
int memavail;
int memfree;
int hdavail;
int hdfree;
BYTE init_progress[3];
BYTE proc_id[16];
BYTE proc_status[16];
BYTE subproc_num[16];
BYTE sysstat[16]; // 0/1=abnormal/normal
/*
* 0=Normal,1=abnormal
*sysstat[0]: system status
* sysstat[1]:cpu status sysstat[2]:swap status
* sysstat[3]:memory status sysstat[4]:disk status
* sysstat[5]:proc_status sysstat[6]:server working status
* sysstat[7]:database status
*/
long alarmtime[6];
BYTE version_info[16];
/*version information for the application
*/
BYTE updatetime[16];
} svrdetail_stat;
typedef struct svr_simple_stat {
BYTE grp_id;
BYTE location;
BYTE isinstalled;
int waittime;
BYTE ischanged;
/* 0/1=N/Y,process will send message to client if status is changed
*/
BYTE status;
/*0=critical ; 1=normal ; 2=alarm ; 3=uninstalled
*/
int critical; // critical counter
int alarm; // alarm counter
BYTE disp_name; // 0/1=not display/display
BYTE name[16];
BYTE remark[44];
int coord[2];
BYTE stat_amount; // number of status for bts site icon
BYTE stat_direct; // direction of display status (0/1=h/v)
} svrsimple_stat;
struct alarm_log {
BYTE systype;
BYTE sys_id;
BYTE sub_id;
BYTE e1no;
BYTE alarmnum;
BYTE occurtime[16];
};
typedef struct ts_alarm_log {
int readSub;
int writeSub;
struct alarm_log alrlist[ALARM_NUM];
} tsalarm_log;
typedef struct ask_alarm_log {
long client_ip; //ip address where the request is sent from
int init_Req_Flag;
int readSub;
int writeSub;
struct alarm_log alrlist[ALARM_NUM];
} askalarm_log;
/*
* shared memory structure
*************************/
typedef struct shm_ts_stat {
BYTE init_flag;
BYTE sys_struct;//0/1=single/double plane system structure
grpsimple_stat grp_simple[GRP_NUM];
tsdetail_stat ts_detail[TS_NUM];
tssimple_stat ts_simple[TS_NUM];
ethdetail_stat eth_detail[ETH_NUM];
ethsimple_stat eth_simple[ETH_NUM];
rdevdetail_stat vps_detail[RDEV_NUM];
rdevsimple_stat vps_simple[RDEV_NUM];
rdevdetail_stat pcr_detail[RDEV_NUM];
rdevsimple_stat pcr_simple[RDEV_NUM];
svrdetail_stat svr_detail[SVR_NUM];
svrsimple_stat svr_simple[SVR_NUM];
/*
sysnum=systype*2+sys_id
svr_simple[0]=OMC-0
svr_simple[1]=OMC-1
svr_simple[2]=HLR-0
svr_simple[3]=HLR-1
svr_simple[4]=PRP-0
svr_simple[5]=PRP-1
svr_simple[6]=CDR-0
svr_simple[7]=CDR-1
*/
bscsimple_stat bsc_simple[BSC_NUM];
BYTE global_status[ETH_NUM];
conn_info connection[CONN_NUM];
client_info client[CLIENT_NUM];
/*global_status[0]= if normal ;global_status[1]= if changed*/
tsalarm_log alarmlog;
} shm_stat;
/*****************************************************************************/
/* Lan Module's global status*/
typedef struct global_status{
BYTE eth_mac[ETH_NUM][ETH_SUB][7];
long update_time[ETH_NUM][ETH_SUB];
long alarm_time[ETH_NUM][ETH_SUB];
}eth_global;
/***************************************************/
/*****************************************************************************/
/* structure for BSS simple status in heartbeat processor
************************************/
typedef struct bss_simple_stat {
BYTE isinstalled[BSS_NUM];
BYTE ischanged[BSS_NUM];
BYTE isnormal[BSS_NUM];
unsigned int waittime[BSS_NUM];
} bsssimple_stat;
/***************************************************/
#endif /*OMC_PUBLIC__H */

View File

@@ -0,0 +1,127 @@
//////////////////////////////////////////////////
//Title : pub_basic.c
//Auhtor : Liu Wei
//Desc : public basic function
//Created : 2007-06-23
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_BASE_H_
#define _PUB_BASE_H_
typedef struct VALUE_STRING
{
u32 dValue;
u8 *pStr;
} StringVal;
#define ALPHA_TABLE_LOWER "abcdefghijklmnopqrstuvwsyz"
#define ALPHA_TABLE_UPPER "ABCDEFGHIJKLMNOPQRSTUVWSYZ"
#define NOTSO(n) ( !(n) )
#define IsNull(n) ( ((n) == NULL) )
#define CNULL '\0'
#define IsChNull(ch) ( ch==CNULL )
#define STR_CHECK_LAST(str,ch) ( str[strlen(str)-1] == ch )
#define STR_CHECK_FIRST(str,ch) ( str[0] == ch )
#define STR_CUT_LAST(str) ( str[strlen(str)-1] = CNULL )
#define BitSet(arg,posn) ((arg) | (1L << (posn)))
#define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
#define BitFlp(arg,posn) ((arg) ^ (1L << (posn)))
#define BitTst(arg,posn) (!(!((arg) & (1L << (posn)))))
#define HexToChar(ch) ( (ch) + ( ((ch) > 9)? 'A'-10 : '0') )
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
#ifndef MAX
#define MAX(a, b) ( (a) > (b) ? (a) : (b) )
#define MIN(a, b) ( (a) < (b) ? (a) : (b) )
#endif
///////////////////////////////////////////////////////////////////////////
//
// Name : GET_U8 GET_U16 GET_U32
// Function : Return the u8 /u16 / u32 value of the pointer memery
// Parameter: x : pointer
//
///////////////////////////////////////////////////////////////////////////
#define GET_U8( x ) ( *( (u8 *) (x) ) )
#define GET_U16( x ) ( *( (u16 *) (x) ) )
#define GET_U32( x ) ( *( (u32 *) (x) ) )
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
#define U16_LOW_BYTE ( x ) ( (u8 )( ((u16) (x) ) & 0xFF ) )
#define U16_HIG_BYTE ( x ) ( (u8 )( ((u16) (x) ) >> 8 ) )
#define LSB_BYTE2WORD( uVal ) ( (((u16) (uVal)[0]) * 256) + (uVal)[1] )
#define MSB_BYTE2WORD( uVal ) ( (((u16) (uVal)[1]) * 256) + (uVal)[0] )
#define LSB_WORD2BYTE( wVal , uVal ) \
(uVal)[0] = ((wVal) / 256); \
(uVal)[1] = ((wVal) & 0xFF )
#define MSB_WORD2BYTE( wVal , uVal ) \
(uVal)[1] = ((wVal) / 256 ); \
(uVal)[0] = ((wVal) & 0xFF)
///////////////////////////////////////////////////////////////////////////
//
// Name : ARR_SIZE
// Function : Return array size of a
// Parameter: a : array
//
///////////////////////////////////////////////////////////////////////////
#define ARR_SIZE( a ) ( sizeof( (a) ) / sizeof( (a[0]) ) )
///////////////////////////////////////////////////////////////////////////
//
// Name : STR
// Function : Convert the s to string
// Parameter: a : a value you want to Convert to string but no need ""
// e.g. : printf(STR(if(NOTSO(a)) return 0));
///////////////////////////////////////////////////////////////////////////
#define STR(s) #s
#define FILL_VALSTR(n) {n,#n}
#define GET_FILE_NAME(fn) \
{ \
static char fn[] = STR(_FILE_); \
}
#define GetValueString(i,p,Maxtrix,IdMax) \
{ \
if( (i) >= (IdMax) ) \
{ \
(p) = Maxtrix[(IdMax)].pStr; \
} \
else \
{ \
(p) = Maxtrix[(i)].pStr; \
} \
}
#define GET_MODULE_VER(x) (x##_VERSION)
#define FPOS( type, field ) \
/*lint -e545 */ ( ( dword ) & ( ( type * ) 0 )->field ) /*lint +e545 */
#define FSIZ( type, field ) sizeof( ((type *) 0)->field )
///////////////////////////////////////////////////////////////////////////
// DivRndUp: Divide and Round Up ///
///////////////////////////////////////////////////////////////////////////
#define DivRndUp(Num,Div) ( ((Num) % (Div))?((Num)/(Div) + 1):((Num)/(Div)) )
#endif

View File

@@ -0,0 +1,43 @@
//////////////////////////////////////////////////
//Title : pub_debug.h
//Auhtor : Liu Wei
//Desc : public debug api header
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_DEBUG_H_
#define _PUB_DEBUG_H_
#include "stdio.h"
#include "assert.h"
#include "string.h"
#include "stdlib.h"
#include <execinfo.h>
#include <signal.h>
extern void WxcDump(int nSigno);
extern void WxcBackTrace();
#ifdef DEBUG
#define WxcAssert(Expression,pStr) \
{ \
int nVal = (Expression); \
if(!nVal) \
{ \
WxcBackTrace(); \
} \
assert( nVal && pStr ); \
}
#else
#define WxcAssert(uVal,pStr)
#endif
#endif

View File

@@ -0,0 +1,22 @@
//////////////////////////////////////////////////
//Title : wxc_file.h
//Auhtor : Liu Wei
//Desc : wxc file handle header
//Created : 2007-06-04
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_FILE_H_
#define _PUB_FILE_H_
#include "./public.h"
#include "./includes.h"
#include "./pub_base.h"
#endif

View File

@@ -0,0 +1,132 @@
//////////////////////////////////////////////////
//Title : pub_convert.h
//Auhtor : Liu Wei
//Desc : public type fomat convert inplementation
//Created : 2007-06-24
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// lCRD software network data type assumpsit
//
// Memery Low <<============[Little Endian]===========>> Memery High
// Type abbr. e.g. Remark
// const value CVal 0x12345678
// Host BCD HBcd/BCd 0x78 0x56 0x34 0x12
// Anti BCD ABcd 0x87 0x65 0x43 0x21
// NetBCD NBcd 0x12 0x34 0x56 0x78
// String Str 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 "12345678"
// U64 U64 0x4E 0x61 0xBC 0x00 0x00 0x00 0x00 0x00 12345678=0xBC614E
// Digit Dig 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08
//
////////////////////////////////////////////////////////////////////////////////
#ifndef _PUB_FMT_H_
#define _PUB_FMT_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_debug.h"
extern inline char HexToCh ( u8 uHex );
extern inline u8 ChToHex ( char ch );
void AsciiToBcd (BYTE *bcd_buf, const char *ascii_buf, int len);
void BcdToAscii (char *ascii_buf, const BYTE *bcd_buf, int len);
///////////////////////////////////////////////////////////////////////////
// ReverseByte : 0010 1010 =>> 0101 0100
//
///////////////////////////////////////////////////////////////////////////
extern u8 ReverseByte(u8 uByteIn );
///////////////////////////////////////////////////////////////////////////
// ReverseBCD : 0x12 0x34 0x56 0x78 =>> 0x21 0x43 0x65 0x87
//
///////////////////////////////////////////////////////////////////////////
extern void ReverseBCD( u8 *pDst , const u8 *pSrc , int nBcdLen );
///////////////////////////////////////////////////////////////////////////
// ReverseArray : 0x12 0x34 0x56 0x78 =>> 0x78 0x56 0x34 0x12
//
///////////////////////////////////////////////////////////////////////////
extern void ReverseArray( u8 *pDst , const u8 *pSrc , int nBcdLen );
///////////////////////////////////////////////////////////////////////////
// BcdToStr : 0x12 0x34 0x56 0x78 =>> "12345678"
//
///////////////////////////////////////////////////////////////////////////
extern void BcdToStr( char *pStr , const u8 *pBcd , int nBcdLen );
///////////////////////////////////////////////////////////////////////////
// BcdToU64 : 0x12 0x34 0x56 0x78 =>> 12345678
//
//////////////////////////////////////////////////////////////////////////
extern u64 BcdToU64( const u8 *pBcd , int nBcdLen );
///////////////////////////////////////////////////////////////////////////
// BcdToDig : 0x12 0x34 0x56 =>>0x01 0x02 0x03 0x04 0x05 0x06
//
///////////////////////////////////////////////////////////////////////////
extern int BcdToDig( u8 *pDig , int nDigBuffLen, u8 *pBcd , int nBcdLen );
///////////////////////////////////////////////////////////////////////////
// StrToBcd : "123456" =>> 0x12 0x34 0x56
//
///////////////////////////////////////////////////////////////////////////
extern int StrToBcd( u8 *pBcd , char *pStr , int nBcdBuffLen );
///////////////////////////////////////////////////////////////////////////
// U64ToBcd : 1234567 => 0x01 0x23 0x45 0x67
//
///////////////////////////////////////////////////////////////////////////
extern int U64ToBcd( u8 *pBcd ,u64 llInput , int nBcdBuffLen );
///////////////////////////////////////////////////////////////////////////
// DigToBcd : 0x01 0x02 0x03 x04 0x05 0x06 0x07 => 0x01 0x23 0x45 0x67
//
///////////////////////////////////////////////////////////////////////////
extern int DigToBcd( u8* pBcd , int nBcdBuffLen , u8 *pDig , int nDigLen );
extern int DigToBcdE( u8* pBcd , int nBcdBuffLen , u8 *pDig , int nDigLen , int nEnd );
int Str2Bcd ( BYTE * pBcd, char *pStr, int maxLen );
int Bcd2Str ( char *pStr, const BYTE * pBcd, int len );
int DigitsLen(BYTE *pDigits, int maxLen);
int BcdLen(BYTE *pBcd, int maxLen);
int Digits2Str(char *pStr, BYTE *pDigits, int DigitsLen);
ull Digits2Ull(BYTE *pDigits, int DigitsLen);
int Ull2Digits(BYTE *pDigits, ull value, int DigitsLen);
int Str2Digits(BYTE *pDigits, char *pStr, int DigitsLen);
int Ull2Digits_Ralign(BYTE *pDigits, ull value, int DigitsLen);
ull Bcd2Ull(BYTE *pBcd, int BcdLen);
int Ull2Bcd(BYTE *pBcd, ull value, int BcdLen);
int Digits2Bcd(BYTE *pBcd, BYTE *pDigits, int maxLen);
int Bcd2Digits(BYTE *pDigits, BYTE *pBcd, int maxLen);
int Bcd2Digits_dLen(BYTE *pDigits, BYTE *pBcd, int maxLen);
int Str2Oid(DWORD *pOid, char *pStr, BYTE maxLen);
int TrimLeft(char *pStr);
int TrimRight(char *pStr);
int Array2Digits(BYTE *pDigits, BYTE *pArray, int ArrayLen);
ull Str2Ull(char *pStr);
int Digits2Array(BYTE *pArray, BYTE *pDigits, int DigitsLen);
int Bcd2Array(BYTE *pArray, BYTE *pBcd, int BcdLen);
int Str2Array(BYTE *pArray, char *str, int ArrayLen);
BYTE EditDigits(BYTE *digits_out, BYTE len_max, BYTE *digits_in, BYTE len_in, BYTE len_del, BYTE *digits_ins, BYTE len_ins, BYTE filler);
BYTE DelDigits(BYTE *in_digit, BYTE in_len, BYTE *out_digit, BYTE count, BYTE filler);
void DWORD2BYTE(BYTE *pdword, BYTE *pbyte, int len);
void u32tobyte(u8 *str, u32 data);
u8 u16tobcd(u8 *bcd_string, u16 data);
u16 bcdtou16(u8 *bcd_string, u8 bcd_len);
u8 u32tobcd(u8 *bcd_string, u32 data);
u32 bcdtou32(u8 *bcd_string, u8 bcd_len);
void AsciiToRbcd(BYTE *bcd_buf, const char *ascii_buf, int len);
#endif

View File

@@ -0,0 +1,39 @@
//////////////////////////////////////////////////
//Title : pub_incudes.h
//Auhtor : Liu Wei
//Desc : public header includes
//Created : 2007-07-13
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_INCLUDE_H_
#define _PUB_INCLUDE_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "asn1.h"
#include "crypt.h"
#include "bisearch.h"
#include "pub_base.h"
#include "pub_debug.h"
#include "pub_log.h"
#include "pub_file.h"
#include "pub_list.h"
#include "pub_malloc.h"
#include "pub_fmt.h"
#include "pub_base.h"
#include "pub_time.h"
#include "pub_timer.h"
#include "pub_sys.h"
#include "pub_str.h"
#include "pub_inet.h"
#include "pub_wnet.h"
#include "pub_netcap.h"
#include "pub_sdp.h"
#endif

View File

@@ -0,0 +1,75 @@
//////////////////////////////////////////////////
//Title : pub_inet.h
//Auhtor : Liu Wei
//Desc : public inet function header
//Created : 2007-06-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_INET_H_
#define _PUB_INET_H_
#include "public.h"
#include "includes.h"
#include "pub_debug.h"
///////////////////////////////////////////////////////////////////////////
// Inet If Address infomation interface
///////////////////////////////////////////////////////////////////////////
#define MAXINTERFACES 16
typedef struct IF_ADDR
{
u8 uIfNum;
struct
{
u32 dIfIP;
u8 uIfState;
}
tIfEntity[MAXINTERFACES];
}
IfAddr;
extern int GetNetIfInfo ( IfAddr * pIfAddr );
extern u32 GetLocalIP();
///////////////////////////////////////////////////////////////////////////
// Ping Interface
///////////////////////////////////////////////////////////////////////////
#define PACKET_SIZE 4096
#define MAX_NO_PACKETS 3
typedef void PingCallBack( int nPingResult );
typedef struct ICMP_SERVICE
{
u8 uSrvState;
u8 uIcmpState;
u8 uPackNo;
u8 uDataLen;
u8 nPackNumSend;
u8 nPackNumRecv;
u8 aSendBuff[PACKET_SIZE];
u8 aRecvBuff[PACKET_SIZE];
u32 wSockfd;
pid_t tPid;
struct sockaddr_in tToAddr;
struct sockaddr_in tFromAddr;
struct protoent *pProtoent;
PingCallBack *fCallBack;
}
IcmpSrv;
extern int PingInit ( IcmpSrv *pIS , int nDataLen );
extern int PingStart( IcmpSrv *pIS , char *sIP , PingCallBack fCallBack );
extern int PingTimer ( IcmpSrv *pIS );
#endif

View File

@@ -0,0 +1,501 @@
//////////////////////////////////////////////////
//Title : pool.c
//Auhtor : Liu Wei
//Desc : List and Pool Queue struct implement
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_LIST_H_
#define _PUB_LIST_H_
//LIFO Queue
#define LIFOQ_HEAD( name , type ) \
struct name \
{ \
struct type *pLqFirst;/*First elment*/ \
}
#define LIFOQ_ENTRY(type) \
struct \
{ \
struct type *pLqNext; \
}
#define LIFOQ_EMPTY(head) \
((head)->pLqFirst == NULL)
#define LIFOQ_FIRST(head) \
((head)->pLqFirst)
#define LIFOQ_FOREACH(var, head, field) \
for((var) = (head)->pLqFirst; (var); (var) = (var)->field.pLqNext)
#define LIFOQ_INIT(head) \
{ \
(head)->pLqFirst = NULL; \
}
#define LIFOQ_INSERT_AFTER(lifoq_elm, elm, field) \
do \
{ \
(elm)->field.pLqNext = (lifoq_elm)->field.pLqNext; \
(lifoq_elm)->field.pLqNext = (elm); \
} while (0)
#define LIFOQ_INSERT_HEAD(head, elm, field) \
do \
{ \
(elm)->field.pLqNext = (head)->pLqFirst; \
(head)->pLqFirst = (elm); \
} while (0)
#define LIFOQ_NEXT(elm, field) ((elm)->field.pLqNext)
#define LIFOQ_REMOVE_HEAD(head, field) \
do \
{ \
(head)->pLqFirst = (head)->pLqFirst->field.pLqNext; \
} while (0)
#define LIFOQ_REMOVE(head, elm, type, field) \
do \
{ \
if ((head)->pLqFirst == (elm)) \
{ \
LIFOQ_REMOVE_HEAD((head), field); \
} \
else \
{ \
struct type *curelm = (head)->pLqFirst; \
\
while( curelm->field.pLqNext != (elm) ) \
{ \
curelm = curelm->field.pLqNext; \
} \
curelm->field.pLqNext = \
curelm->field.pLqNext->field.pLqNext; \
} \
} while (0)
//FIFO Quence
#define FIFOQ_HEAD(name, type) \
struct name \
{ \
struct type *pFqFirst;/* first element */ \
struct type **pFqLast;/* addr of last next element */ \
}
#define FIFOQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).pFqFirst }
#define FIFOQ_ENTRY(type) \
struct \
{ \
struct type *pFqNext; /* next element */ \
}
#define FIFOQ_EMPTY(head) ((head)->pFqFirst == NULL)
#define FIFOQ_INIT(head) \
do \
{ \
(head)->pFqFirst = NULL; \
(head)->spTQLast = &(head)->pFqFirst; \
} while (0)
#define FIFOQ_FIRST(head) ((head)->pFqFirst)
#define FIFOQ_LAST(head, type, field) \
(FIFOQ_EMPTY(head) ? NULL : ((struct type *) \
((char *)((head)->spTQLast) - __offsetof(struct type, field))))
#define FIFOQ_FOREACH(var, head, field) \
for((var) = (head)->pFqFirst; (var); (var) = (var)->field.pFqNext)
#define FIFOQ_INSERT_HEAD(head, elm, field) \
do \
{ \
if (((elm)->field.pFqNext = (head)->pFqFirst) == NULL) \
(head)->spTQLast = &(elm)->field.pFqNext; \
(head)->pFqFirst = (elm); \
} while (0)
#define FIFOQ_INSERT_TAIL(head, elm, field) \
do \
{ \
(elm)->field.pFqNext = NULL; \
*(head)->spTQLast = (elm); \
(head)->spTQLast = &(elm)->field.pFqNext; \
} while (0)
#define FIFOQ_INSERT_AFTER(head, tqelm, elm, field) \
do \
{ \
if (((elm)->field.pFqNext = (tqelm)->field.pFqNext) == NULL)\
(head)->spTQLast = &(elm)->field.pFqNext; \
(tqelm)->field.pFqNext = (elm); \
} while (0)
#define FIFOQ_NEXT(elm, field) ((elm)->field.pFqNext)
#define FIFOQ_REMOVE_HEAD(head, field) \
do \
{ \
if (((head)->pFqFirst = (head)->pFqFirst->field.pFqNext) == NULL) \
(head)->spTQLast = &(head)->pFqFirst; \
} while (0)
#define FIFOQ_REMOVE_HEAD_UNTIL(head, elm, field) \
do \
{ \
if (((head)->pFqFirst = (elm)->field.pFqNext) == NULL) \
(head)->spTQLast = &(head)->pFqFirst; \
} while (0)
#define FIFOQ_REMOVE(head, elm, type, field) \
do \
{ \
if ((head)->pFqFirst == (elm)) \
{ \
FIFOQ_REMOVE_HEAD(head, field); \
} \
else \
{ \
struct type *curelm = (head)->pFqFirst; \
while( curelm->field.pFqNext != (elm) ) \
curelm = curelm->field.pFqNext; \
\
if((curelm->field.pFqNext = \
curelm->field.pFqNext->field.pFqNext) == NULL)\
(head)->spTQLast = &(curelm)->field.pFqNext; \
} \
} while (0)
// List
#define LIST_HEAD(name, type) \
struct name \
{ \
struct type *pListFirst; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct \
{ \
struct type *pListNext; /* next element */ \
struct type **pListPrev; /* address of previous next element */ \
}
/*
* List functions.
*/
#define LIST_EMPTY(head) ((head)->pListFirst == NULL)
#define LIST_FIRST(head) ((head)->pListFirst)
#define LIST_FOREACH(var, head, field) \
for((var) = (head)->pListFirst; (var); (var) = (var)->field.pListNext)
#define LIST_INIT(head) \
do \
{ \
(head)->pListFirst = NULL; \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) \
do \
{ \
if (((elm)->field.pListNext = (listelm)->field.pListNext) != NULL) \
{ \
(listelm)->field.pListNext->field.pListPrev = \
&(elm)->field.pListNext; \
} \
(listelm)->field.pListNext = (elm); \
(elm)->field.pListPrev = &(listelm)->field.pListNext; \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) \
do \
{ \
(elm)->field.pListPrev = (listelm)->field.pListPrev; \
(elm)->field.pListNext = (listelm); \
*(listelm)->field.pListPrev = (elm); \
(listelm)->field.pListPrev = &(elm)->field.pListNext; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) \
do \
{ \
if (((elm)->field.pListNext = (head)->pListFirst) != NULL) \
(head)->pListFirst->field.pListPrev = &(elm)->field.pListNext; \
(head)->pListFirst = (elm); \
(elm)->field.pListPrev = &(head)->pListFirst; \
} while (0)
#define LIST_NEXT(elm, field) ((elm)->field.pListNext)
#define LIST_REMOVE(elm, field) \
do \
{ \
if ((elm)->field.pListNext != NULL) \
(elm)->field.pListNext->field.pListPrev = \
(elm)->field.pListPrev; \
*(elm)->field.pListPrev = (elm)->field.pListNext; \
} while (0)
/*
* Tail queue definitions.
*/
#define TAILQ_HEAD(name, type) \
struct name \
{ \
struct type *pTQFirst; /* first element */ \
struct type **pTQLast; /* addr of last next element */ \
}
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).pTQFirst }
#define TAILQ_ENTRY(type) \
struct \
{ \
struct type *pTQNext; /* next element */ \
struct type **pTQPrev; /* address of previous next element */ \
}
/*
* Tail queue functions.
*/
#define TAILQ_EMPTY(head) ((head)->pTQFirst == NULL)
#define TAILQ_FOREACH(var, head, field) \
for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var); \
(var) = TAILQ_PREV((var), headname, field))
#define TAILQ_FIRST(head) ((head)->pTQFirst)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->pTQLast))->pTQLast))
#define TAILQ_NEXT(elm, field) ((elm)->field.pTQNext)
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.pTQPrev))->pTQLast))
#define TAILQ_INIT(head) \
do \
{ \
(head)->pTQFirst = NULL; \
(head)->pTQLast = &(head)->pTQFirst; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) \
do \
{ \
if (((elm)->field.pTQNext = (head)->pTQFirst) != NULL) \
(head)->pTQFirst->field.pTQPrev = \
&(elm)->field.pTQNext; \
else \
(head)->pTQLast = &(elm)->field.pTQNext; \
(head)->pTQFirst = (elm); \
(elm)->field.pTQPrev = &(head)->pTQFirst; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) \
do \
{ \
(elm)->field.pTQNext = NULL; \
(elm)->field.pTQPrev = (head)->pTQLast; \
*(head)->pTQLast = (elm); \
(head)->pTQLast = &(elm)->field.pTQNext; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) \
do \
{ \
if (((elm)->field.pTQNext = (listelm)->field.pTQNext) != NULL) \
(elm)->field.pTQNext->field.pTQPrev = &(elm)->field.pTQNext; \
else \
(head)->pTQLast = &(elm)->field.pTQNext; \
(listelm)->field.pTQNext = (elm); \
(elm)->field.pTQPrev = &(listelm)->field.pTQNext; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) \
do { \
(elm)->field.pTQPrev = (listelm)->field.pTQPrev; \
(elm)->field.pTQNext = (listelm); \
*(listelm)->field.pTQPrev = (elm); \
(listelm)->field.pTQPrev = &(elm)->field.pTQNext; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) \
do { \
if (((elm)->field.pTQNext) != NULL) \
(elm)->field.pTQNext->field.pTQPrev = (elm)->field.pTQPrev; \
else \
(head)->pTQLast = (elm)->field.pTQPrev; \
*(elm)->field.pTQPrev = (elm)->field.pTQNext; \
} while (0)
/*
* Pool -- Circular queue definitions.
*/
#define POOL_HEAD(name, type) \
struct name \
{ \
struct type *pPoolFirst; /* first element */ \
struct type *pPoolLast; /* last element */ \
}
#define POOL_ENTRY(type) \
struct \
{ \
struct type *pPoolNext; /* next element */ \
struct type *pPoolPrev; /* previous element */ \
}
/*
* Pool -- Circular queue functions.
*/
#define POOL_EMPTY(head) ((head)->pPoolFirst == (void *)(head))
#define POOL_FIRST(head) ((head)->pPoolFirst)
#define POOL_FOREACH(var, head, field) \
for((var) = (head)->pPoolFirst; \
(var) != (void *)(head); \
(var) = (var)->field.pPoolNext)
#define POOL_FOREACH_REVERSE(var, head, field) \
for((var) = (head)->pPoolLast; \
(var) != (void *)(head); \
(var) = (var)->field.pPoolPrev)
#define POOL_INIT(head) \
do \
{ \
(head)->pPoolFirst = (void *)(head); \
(head)->pPoolLast = (void *)(head); \
} while (0)
#define POOL_INSERT_AFTER(head, listelm, elm, field) \
do { \
(elm)->field.pPoolNext = (listelm)->field.pPoolNext; \
(elm)->field.pPoolPrev = (listelm); \
if ((listelm)->field.pPoolNext == (void *)(head)) \
(head)->pPoolLast = (elm); \
else \
(listelm)->field.pPoolNext->field.pPoolPrev = (elm); \
(listelm)->field.pPoolNext = (elm); \
} while (0)
#define POOL_INSERT_BEFORE(head, listelm, elm, field) \
do { \
(elm)->field.pPoolNext = (listelm); \
(elm)->field.pPoolPrev = (listelm)->field.pPoolPrev; \
if ((listelm)->field.pPoolPrev == (void *)(head)) \
(head)->pPoolFirst = (elm); \
else \
(listelm)->field.pPoolPrev->field.pPoolNext = (elm); \
(listelm)->field.pPoolPrev = (elm); \
} while (0)
#define POOL_INSERT_HEAD(head, elm, field) \
do { \
(elm)->field.pPoolNext = (head)->pPoolFirst; \
(elm)->field.pPoolPrev = (void *)(head); \
if ((head)->pPoolLast == (void *)(head)) \
(head)->pPoolLast = (elm); \
else \
(head)->pPoolFirst->field.pPoolPrev = (elm); \
(head)->pPoolFirst = (elm); \
} while (0)
#define POOL_INSERT_TAIL(head, elm, field) \
do { \
(elm)->field.pPoolNext = (void *)(head); \
(elm)->field.pPoolPrev = (head)->pPoolLast; \
if ((head)->pPoolFirst == (void *)(head)) \
(head)->pPoolFirst = (elm); \
else \
(head)->pPoolLast->field.pPoolNext = (elm); \
(head)->pPoolLast = (elm); \
} while (0)
#define POOL_LAST(head) ((head)->pPoolLast)
#define POOL_NEXT(elm,field) ((elm)->field.pPoolNext)
#define POOL_PREV(elm,field) ((elm)->field.pPoolPrev)
#define POOL_REMOVE(head, elm, field) \
do { \
if ((elm)->field.pPoolNext == (void *)(head)) \
(head)->pPoolLast = (elm)->field.pPoolPrev; \
else \
(elm)->field.pPoolNext->field.pPoolPrev = (elm)->field.pPoolPrev; \
\
if ((elm)->field.pPoolPrev == (void *)(head)) \
(head)->pPoolFirst = (elm)->field.pPoolNext; \
else \
(elm)->field.pPoolPrev->field.pPoolNext =(elm)->field.pPoolNext; \
} while (0)
#ifdef _KERNEL
/*
* XXX insque() and remque() are an old way of handling certain queues.
* They bogusly assumes that all queue heads look alike.
*/
struct quehead
{
struct quehead *qh_link;
struct quehead *qh_rlink;
};
#ifdef __GNUC__
static __inline void insque ( void *a, void *b )
{
struct quehead *element = a, *head = b;
element->qh_link = head->qh_link;
element->qh_rlink = head;
head->qh_link = element;
element->qh_link->qh_rlink = element;
}
static __inline void remque ( void *a )
{
struct quehead *element = a;
element->qh_link->qh_rlink = element->qh_rlink;
element->qh_rlink->qh_link = element->qh_link;
element->qh_rlink = 0;
}
#else /* !__GNUC__ */
void insque __P ( ( void *a, void *b ) );
void remque __P ( ( void *a ) );
#endif /* __GNUC__ */
#endif /* _KERNEL */
#endif

View File

@@ -0,0 +1,68 @@
//////////////////////////////////////////////////
//Title : pub_log.h
//Auhtor : Liu Wei
//Desc : public log function header
//Created : 2007-05-21
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_LOG_H_
#define _PUB_LOG_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_debug.h"
#include "pub_fmt.h"
#include <stdarg.h>
#define RESET 0
#define BRIGHT 1
#define DIM 2
#define UNDERLINE 3
#define BLINK 4
#define REVERSE 7
#define HIDDEN 8
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
/////////////////////////////////////////////////////////////////////////
// Public print information
/////////////////////////////////////////////////////////////////////////
#define PIF_INFO 0x01 // Normal Information
#define PIF_WARN 0x02 // Warnings
#define PIF_GERR 0x04 // General errors
#define PIF_CERR 0x10 // Critical errors
#define PIF_DBG 0x20 // Debugging
#define PIF_UNKN 0x40 // Things that are unknown
// Default SIM output
#define PIF_DEFAULT (PIF_INFO|PIF_WARN|PIF_CERR)
// Everything, but DBG
#define PIF_ALL (PIF_INFO|PIF_WARN|PIF_GERR|PIF_CERR|PIF_UNKN)
#define SYSERR strerror(errno)
extern char *ByteBinToStr( char *pDst , const u8 *pSrc , int nByte );
extern char *TxtColor ( int nAttr, int nFg, int nBg, char *pStr );
extern int MsgToFmtLog ( const BYTE * pBcd, int nBcdLen, char *pStr, int nStrBuffSize );
#ifdef DEBUG
#define WxcDebugLog printf
#else
#define WxcDebugLog
#endif
#endif

View File

@@ -0,0 +1,26 @@
//////////////////////////////////////////////////
//Title : pub_malloc.h
//Auhtor : Liu Wei
//Desc : Public heap memery management
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_MALLOC_H_
#define _PUB_MALLOC_H_
#include "public.h"
#include "includes.h"
//#ifdef _USE_SYS_MALLOC_
#define WxcMalloc malloc
#define WxcFree free
//#endif
#endif

View File

@@ -0,0 +1,35 @@
//////////////////////////////////////////////////
//Title : pub_netcap.h
//Auhtor : Liu Wei
//Desc : public netcap header
//Created : 2007-06-05
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_NETCAP_H_
#define _PUB_NETCAP_H_
#include "public.h"
#include "includes.h"
typedef struct NET_CAPTURE
{
u8 uState;
u32 nSock;
u32 nPort;
u32 nDstIp;
}
NetCap;
int NcInit();
int NcStart( u32 wIP , u32 wPort );
int NcStop( );
void NcSetPort( u32 port );
void NcSetIP( u32 ip );
void NcMtp3Send( u8 *pMtp3Msg , u32 wMtp3Len , u8 uAnsiFlag );
int NcSccpSend( u8 *pSccpMsg , u32 wSccpLen , u8 *pIntraMsg , u8 uAnsiFlag );
#endif

View File

@@ -0,0 +1,196 @@
#ifndef _PUB_SDP__H
#define _PUB_SDP__H
#define PUB_SDP_MAX_USER_NAME_LEN 64
#define PUB_SDP_MAX_SESS_ID_LEN 32
#define PUB_SDP_MAX_SESS_VER_LEN 16
#define PUB_SDP_MAX_ADDR_LEN 64
#define PUB_SDP_MAX_SESS_NAME_LEN 64
#define PUB_SDP_MAX_SESS_INFO_LEN 64
#define PUB_SDP_MAX_PAYLOAD_NUM 8
#define PUB_SDP_MAX_MEDIA_NUM 8
#define PUB_SDP_MAX_ATTR_NUM 16
#define PUB_SDP_MAX_ATTR_LEN 32
#define PUB_SDP_FLAG_V 0x00000001
#define PUB_SDP_FLAG_O 0x00000002
#define PUB_SDP_FLAG_S 0x00000004
#define PUB_SDP_FLAG_I 0x00000008
#define PUB_SDP_FLAG_U 0x00000010
#define PUB_SDP_FLAG_E 0x00000020
#define PUB_SDP_FLAG_P 0x00000040
#define PUB_SDP_FLAG_C 0x00000080
#define PUB_SDP_FLAG_B 0x00000100
#define PUB_SDP_FLAG_Z 0x00000200
#define PUB_SDP_FLAG_K 0x00000400
#define PUB_SDP_FLAG_A 0x00000800
#define PUB_SDP_FLAG_T 0x00001000
#define PUB_SDP_FLAG_R 0x00002000
#define PUB_SDP_FLAG_M 0x00004000
#define PUB_MGCP_PARA_FLAG_TFO 0x00000800
#define PUB_SDP_STR_TO_API 1
#define PUB_SDP_API_TO_STR 2
#define PUB_SDP_NET_TYPE_IN 1
#define PUB_SDP_ADDR_TYPE_IPV4 1
#define PUB_SDP_ADDR_TYPE_IPV6 2
#define PUB_SDP_ATTR_TYPE_RTPMAP 1
#define PUB_SDP_ATTR_TYPE_PTIME 2
#define PUB_SDP_ATTR_TYPE_FMTP 3
#define PUB_SDP_ATTR_TYPE_RECVONLY 4
#define PUB_SDP_ATTR_TYPE_SENDONLY 5
#define PUB_SDP_ATTR_TYPE_SENDRECV 6
#define PUB_SDP_MEDIA_TYPE_AUDIO 1
#define PUB_SDP_MEDIA_TYPE_VIDEO 2
#define PUB_SDP_PROTO_TYPE_RTP_AVP 1
typedef struct _PUB_SDP_V
{
BYTE value;
}PUB_SDP_V;
typedef struct _PUB_SDP_O
{
char userName[PUB_SDP_MAX_USER_NAME_LEN];
char sessId[PUB_SDP_MAX_SESS_ID_LEN];
char sessVer[PUB_SDP_MAX_SESS_VER_LEN];
BYTE netType;
BYTE addrType;
char addr[PUB_SDP_MAX_ADDR_LEN];
}PUB_SDP_O;
typedef struct _PUB_SDP_S
{
char sessName[PUB_SDP_MAX_SESS_NAME_LEN];
}PUB_SDP_S;
typedef struct _PUB_SDP_I
{
char info[PUB_SDP_MAX_SESS_INFO_LEN];
}PUB_SDP_I;
typedef struct _PUB_SDP_U
{
}PUB_SDP_U;
typedef struct _PUB_SDP_E
{
}PUB_SDP_E;
typedef struct _PUB_SDP_P
{
}PUB_SDP_P;
typedef struct _PUB_SDP_C
{
BYTE netType;
BYTE addrType;
char addr[PUB_SDP_MAX_ADDR_LEN];
}PUB_SDP_C;
typedef struct _PUB_SDP_B
{
}PUB_SDP_B;
typedef struct _PUB_SDP_Z
{
}PUB_SDP_Z;
typedef struct _PUB_SDP_K
{
}PUB_SDP_K;
typedef struct _PUB_SDP_T
{
DWORD startTime;
DWORD stopTime;
}PUB_SDP_T;
typedef struct _PUB_SDP_R
{
}PUB_SDP_R;
typedef struct _PUB_SDP_M
{
BYTE media;
WORD port;
BYTE portNum;
BYTE proto;
BYTE plNum;
BYTE payloads[PUB_SDP_MAX_PAYLOAD_NUM];
}PUB_SDP_M;
typedef struct _PUB_SDP_A
{
BYTE aType;
char aValue[PUB_SDP_MAX_ATTR_LEN];
}PUB_SDP_A;
typedef struct _PUB_SDP_ATTRS
{
BYTE num;
PUB_SDP_A attrs[PUB_SDP_MAX_ATTR_NUM];
}PUB_SDP_ATTRS;
typedef struct _PUB_SDP_MEDIA
{
DWORD flag;
PUB_SDP_M m;
PUB_SDP_I i;
PUB_SDP_C c;
PUB_SDP_B b;
PUB_SDP_K k;
PUB_SDP_ATTRS attrs;
}PUB_SDP_MEDIA;
typedef struct _PUB_SDP_MEDIAS
{
BYTE num;
PUB_SDP_MEDIA medias[PUB_SDP_MAX_MEDIA_NUM];
}PUB_SDP_MEDIAS;
typedef struct _PUB_SDP_MSG
{
DWORD flag;
PUB_SDP_V v;
PUB_SDP_O o;
PUB_SDP_S s;
PUB_SDP_I i;
PUB_SDP_U u;
PUB_SDP_E e;
PUB_SDP_P p;
PUB_SDP_C c;
PUB_SDP_B b;
PUB_SDP_Z z;
PUB_SDP_K k;
PUB_SDP_A a;
PUB_SDP_T t;
PUB_SDP_R r;
PUB_SDP_MEDIAS medias;
}PUB_SDP_MSG;
void pub_replace_all_lws(char *msg);
char *pub_strncpy(char *dest, const char *src, WORD length);
int pub_set_next_token(char *dest, char *buf, int endSeparator, char **next);
int pub_sdp_msg_init(PUB_SDP_MSG *sdp);
int pub_sdp_parse(PUB_SDP_MSG *sdp, char *buf, char **nextMsg, DWORD flag);
int pub_sdp_encode(PUB_SDP_MSG *sdp, char *dest, WORD flag);
int pub_sdp_net_type_conv(char *str, BYTE *netType, BYTE flag);
int pub_sdp_addr_type_conv(char *str, BYTE *addrType, BYTE flag);
int pub_sdp_attr_type_conv(char *str, BYTE *attrType, BYTE flag);
int pub_sdp_media_type_conv(char *str, BYTE *mediaType, BYTE flag);
int pub_sdp_proto_type_conv(char *str, BYTE *protoType, BYTE flag);
#endif

View File

@@ -0,0 +1,26 @@
//////////////////////////////////////////////////
//Title : pub_str.h
//Auhtor : Liu Wei
//Desc : wxc2 string library
//Created : 2007-06-02
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_STR_H_
#define _PUB_STR_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#endif

View File

@@ -0,0 +1,53 @@
//////////////////////////////////////////////////
//Title : pub_sys.c
//Auhtor : Liu Wei
//Desc : Public Linux system infomation
//Created : 2007-06-02
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_SYS_H_
#define _PUB_SYS_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_time.h"
#include <sys/mount.h>
#include <mntent.h>
#include <sys/sysinfo.h>
#include <sys/utsname.h>
#include <fstab.h>
#include <sys/stat.h>
#include <linux/kernel.h>
//#include <linux/sys.h>
#define SIM_NONL 0x1000 // Don't add newline to output
#define SIM_NOLBL 0x2000 // Don't print "Public: Error:"
#define MHERTZ 1000000 // MegaHertz
#define BYTES ((u32)1) // Bytes
#define KBYTES ((u32)1024) // Kilo bytes
#define MBYTES ((u32)(1024*1024)) // Mega bytes
#define GBYTES ((u32)(1024*1024*1024)) // Giga bytes
#define BytesToGBytes(N) ( (float) N / (float) GBYTES )
#define BytesToMBytes(N) ( (float) N / (float) MBYTES )
#define BytesToKBytes(N) ( (float) (N / (float) KBYTES) )
#define MBytesToBytes(N) ( (float) ( (float) N * (float) MBYTES ) )
#define KBytesToMbytes(N) ( (float) ( (float) N / (float) KBYTES ) )
#define KBytesToGbytes(N) ( (float) ( (float) N / (float) MBYTES ) )
#define MbytesToGbytes(N) ( (float) ( (float) N / (float) KBYTES ) )
#define EQ(a,b) (a && b && strcasecmp(a,b)==0)
#define EQN(a,b,n) (a && b && strncasecmp(a,b,n)==0)
#define eq(a,b) (a && b && strcmp(a,b)==0)
#define eqn(a,b,n) (a && b && strncmp(a,b,n)==0)
#define ARG(s) ((s) ? s : "<null>")
#define PRTS(s) ( ( s && *s ) ? s : "" )
#endif

View File

@@ -0,0 +1,29 @@
//////////////////////////////////////////////////
//Title : pub_time.h
//Auhtor : Liu Wei
//Desc : Linux time function
//Created : 2007-06-02
//Revision :
//
//Revision :
//
/////////////////////////////////////////////////
#ifndef _PUB_TIME_H_
#define _PUB_TIME_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_log.h"
#include <sys/time.h>
/* pub_time.c */
long GetTickCount(void);
int GetCurrentTime(u8 *pNowTime);
char *GetAsciiTime(void);
char *TimeToStr(time_t TimeVal, char *Format);
char *GetTimeHMS(char *pTimeBuf);
#endif

View File

@@ -0,0 +1,96 @@
//////////////////////////////////////////////////
//Title : wxc_timer.h
//Auhtor : Liu Wei
//Desc : WXC2 Public Timer Managemnet
//Created : 2007-04-27
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _PUB_TIMER_H_
#define _PUB_TIMER_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_malloc.h"
///////////////////////////////////////////////////////////////////////////
typedef void ( *TimerCallBack ) ( u16 dSuitId, u16 dData );
#define TM_CLOCK_MAX (24*60*60*100) //one day based on wxc2 base timer 10ms
typedef struct WXC_TIMER
{
u32 dExpires; //dExpires : Timer expired number
u32 dSuitNumber; //dSuitNumber : Timer suit size of member
TimerCallBack pFunc; //pFunc : Timer call back function
u16 dData; //dData : Pointer for parameter of callback
void *pTimerNode; //pTimerNode : Reserved for timer Managemnet
}
WxcTimer;
///////////////////////////////////////////////////////////////////////////
typedef struct WXC_TIMER_NODE
{
u32 *dClockArray; //dClockArray : Timer set member clock array
WxcTimer *pTimer;
struct WXC_TIMER_NODE *pNext;
struct WXC_TIMER_NODE *pPrev;
}
WxcTimerNode;
///////////////////////////////////////////////////////////////////////////
#define MAX_TM_MODE 512
#define TIMER_NODE_SIZE ( sizeof( WxcTimerNode ) + sizeof( WxcTimer ) )
#define CLOCK_SZIE ( sizeof ( u32 ) )
#define TMHEAP_MM_SIZE ( MAX_TM_MODE * TIMER_NODE_SIZE )
#define GET_TNODE_SIZE(n) ( TIMER_NODE_SIZE + ( n ) *( CLOCK_SZIE ))
///////////////////////////////////////////////////////////////////////////
u8 TMHeap[TMHEAP_MM_SIZE];
WxcTimerNode tTimerListHead;
WxcTimerNode *pTLHead;
WxcTimerNode *pTLCur;
///////////////////////////////////////////////////////////////////////////
#ifndef _LINUX_TIMER_H
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
#define time_before(a,b) time_after(b,a)
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
#define time_before_eq(a,b) time_after_eq(b,a)
#endif
///////////////////////////////////////////////////////////////////////////
#define TimerAfter(a,b) time_after(a,b)
#define TimerBefore(a,b) time_before(a,b)
#define TimerAfterEq(a,b) time_after_eq(a,b)
#define TimerBeforeEq(a,b) time_before_eq(a,b)
extern void TimerAdd ( WxcTimer * pTimer );
extern void TimerMod ( WxcTimer * pTimer, u16 dExpires );
extern void TimerDel ( WxcTimer * pTimer );
inline void TimerStart ( WxcTimer * pTimer, u16 dSuitId );
inline void TimerStop ( WxcTimer * pTimer, u16 dSuitId );
inline void TM_Init ( );
#endif

View File

@@ -0,0 +1,41 @@
//////////////////////////////////////////////////
//Title : pub_wnet.h
//Auhtor : Liu Wei
//Desc : wireless network publice function
//Created : 2007-06-05
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#ifndef _WXC_WNET_H_
#define _WXC_WNET_H_
#include "public.h"
#include "includes.h"
#include "pub_base.h"
#include "pub_fmt.h"
#define ISDN_LEN 9
#define IMSI_LEN 8
/* ./src/pub_wnet.c */
u8 GetBcdStr(char *str, u8 *bcd, u8 bcd_len);
void ImsiNtoA(u8 *pAntiImsi, u8 *pNormalImsi);
void ImsiAToN(u8 *pNormalImsi, u8 *pAntiImsi);
void ImsiNToS(u8 *pImsiStr, u8 *pNormalImsi);
void ImsiSToN(u8 *pNormalImsi, u8 *pImsiStr);
void IsdnNToA(u8 *pAntiIsdn, u8 *pNormalIsdn);
void IsdnAToN(u8 *pNormalIsdn, u8 *pAntiIsdn);
void IsdnNToS(u8 *pIsdnStr, u8 *pNormalIsdn);
u8 IsdnSToN(u8 *pNormalIsdn, u8 *pIsdnStr);
void GttToIsdn(u8 *pIsdn, u8 *pGtt);
u8 IsdnToGtai(u8 *pGtai, u8 *pIsdn);
void GtaiToIsdn(u8 *pIsdn, u8 *pGtai, u8 len);
u8 BcdToStrPE(char *str, u8 *bcd, u8 bcd_len);
void AddCcToIsdn(u8 *isdn_str, u8 *cc);
void AddNdcToIsdn(u8 *isdn_str, u8 *ndc);
#endif

View File

@@ -0,0 +1,102 @@
/*
** PACS WLL 2000 project, Prepaid System.
**
** File name: public.h
** Written completely by Zhang Shuzhong at 2000-10-17
** CVS $Id: public.h,v 1.4 2001/01/20 19:58:49 zhangsz Exp $
**
** Public type definitions for PACS-WLL Project.
**
*/
#ifndef PUBLIC__H
#define PUBLIC__H
#include <sys/types.h>
#include "memwatch.h"
#ifndef _T_BYTE
#define _T_BYTE
typedef unsigned char BYTE;
#endif
#ifndef _T_WORD
#define _T_WORD
typedef unsigned short WORD;
#endif
#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif
#ifndef _T_ULL
#define _T_ULL
typedef unsigned long long ull;
#endif
#ifndef _T_U8
#define _T_U8
typedef unsigned char u8;
#endif
#ifndef _T_U16
#define _T_U16
typedef unsigned short u16;
#endif
#ifndef _T_U32
#define _T_U32
typedef unsigned int u32;
#endif
#ifndef _T_U64
#define _T_U64
typedef unsigned long long u64;
#endif
#ifndef _T_BOOL
#define _T_BOOL
typedef int BOOL;
#endif
#ifndef SUCCESS
#define SUCCESS (0)
#endif
#ifndef FAILURE
#define FAILURE (-1)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef YES
#define YES (1)
#endif
#ifndef NO
#define NO (0)
#endif
#ifndef ERROR
#define ERROR (-1)
#endif
#ifndef EMPTY
#define EMPTY (0)
#endif
#define BUFSIZE 8192
#define MAXBUFLEN 8192
#define MAXLINE 8192
//#define MAX(a, b) ((a) > (b) ? (a) : (b))
//#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* PUBLIC__H */

View File

@@ -0,0 +1,100 @@
/*
** PACS-WLL 2000 project, WAVEloop System.
**
** The module Copyright (C) 2000-2001 interWAVE Inc.
** Written completely by Zhang Shuzhong at iCRD Sep, 2001
**
** file name: svrstat.h
** CVS $Id: $
**
** The header file is defination about shared memory
** of server state information.
**
*/
#ifndef SVRSTAT__H
#define SVRSTAT__H
#define SVRSTAT_SHM_KEY 0x00010000
#define SVRSTAT_SHM_PERM 0666
#define SVRSTAT_SEM_KEY 0x00010000
#define SVRSTAT_SEM_PERM 0666
#define SVRSTAT_SEM_NUM 1
enum _server_state_enum {
SS_IDLE,
SS_INITIATE,
SS_NORMAL,
SS_SERVICE_SUSPEND,
SS_SERVICE_HALT,
SS_SHM_REINITIATE,
SS_SERVICE_RESTART,
SS_SYSTEM_RESTART,
SS_SYSTEM_HALT,
};
enum _oper_state_enum {
OS_NO_COMMAND,
OS_SET_COMMAND,
OS_GOT_COMMAND,
OS_FINISHED_COMMAND,
OS_REFUSED_COMMAND,
};
typedef struct {
u_char component_type;
u_char component_id;
u_char alarm_level;
u_char alarm_code;
DWORD timestamp;
} _alarm_log;
typedef struct {
u_short read_sub;
u_short write_sub;
_alarm_log alarm_log[16];
} _alarm_buffer;
typedef struct {
u_char version[3];
DWORD distrib_date;
u_char current_state; // Please view server's state enum.
// The server's current state.
u_char received_state; // State received from OMC.
// Please view server's state enum
// for detail.
u_char oper_state; /* 0: No command.
** 1: Agent set command.
** 2: Function server got the command.
** 3: Function server finished.
** 4: Function server refused.
** refer to enum of _oper_state_enum
*/
u_char net_status; // 0/1=normal/abnormal,
// status of network
u_char rate_progress; // Rate of progress.
DWORD time_updated;
_alarm_buffer alarm_buffer; // Alarm code
} _server_state;
typedef struct {
DWORD time_created; // Heartbeating module set the field
DWORD server_list; /* Bit0-15:
** Server exist if set '1' in bit
** Bit16-31:
** 0/1 = Primary/Secondary server.
** that base server object id.
*/
u_char led_state[16]; /* Led's state:
** 0: Idle/Disable/Suspend/Halt
** 1: Enable/Normal
** 2: Initiating/Activated
*/
u_char port_stat[3];
_server_state server_state[16]; /* Subscript of array
** base on server object ID
*/
} _ss_buffer;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
//////////////////////////////////////////////////
//Title : pub_conf.c
//Auhtor : Liu Wei
//Desc : public conf file handle inplementation
//Created : 2007-06-04
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////

View File

@@ -0,0 +1,52 @@
//////////////////////////////////////////////////
//Title : wxc_debug.c
//Auhtor : Liu Wei
//Desc : wxc debug api implemetation
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_debug.h"
/*@ignore@*/
void WxcDump( int nSigno )
{
char buf[1024];
char cmd[1024];
FILE *fh;
snprintf ( buf, sizeof ( buf ), "/proc/%d/cmdline", getpid ( ) );
fh = fopen ( buf, "r" );
if ( fh == NULL )
exit ( 0 );
if ( NULL == (fgets ( buf, sizeof ( buf ), fh ) ))
exit ( 0 );
fclose ( fh );
if ( buf[strlen ( buf ) - 1] == '\n' )
buf[strlen ( buf ) - 1] = '\0';
snprintf ( cmd, sizeof ( cmd ), "gdb %s %d", buf, getpid ( ) );
system ( cmd );
exit ( 0 );
}
void WxcBackTrace( )
{
int i;
void *array[25];
int nSize = backtrace ( array, 25 );
char **symbols = backtrace_symbols ( array, nSize );
for ( i = 0; i < nSize; i++ )
{
printf ( "%s \n", symbols[i] );
}
free ( symbols );
}
/*@end@*/

View File

@@ -0,0 +1,44 @@
//////////////////////////////////////////////////
//Title : wxc_file.c
//Auhtor : Liu Wei
//Desc : wxc file handle inplementation
//Created : 2007-06-04
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_file.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// GetOneLine: Read one line of a file
///////////////////////////////////////////////////////////////////////////
extern char *GetOneLine ( char *pFileName )
{
FILE *pFile;
static char sBuff[1024];
char *pCh;
pFile = fopen ( pFileName, "r" );
if ( pFile != NULL )
{
if ( fgets ( sBuff, sizeof ( sBuff ), pFile ) != NULL )
{
if ( NULL != (pCh = strchr ( sBuff, '\n' )) )
{
*pCh = CNULL;
}
return sBuff;
}
( void ) fclose ( pFile );
}
return ( char * ) NULL;
}
/*@end@*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,342 @@
//////////////////////////////////////////////////
//Title : pub_inet.c
//Auhtor : Liu Wei
//Desc : public inet function implementation
//Created : 2007-06-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_inet.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// Inet If Address infomation interface
///////////////////////////////////////////////////////////////////////////
extern int GetNetIfInfo ( IfAddr * pIfAddr )
{
int fd;
struct ifreq buf[MAXINTERFACES];
struct arpreq arp;
struct ifconf ifc;
pIfAddr->uIfNum = 0;
if ( ( fd = socket ( AF_INET, SOCK_DGRAM, 0 ) ) >= 0 )
{
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = ( caddr_t ) buf;
if ( !ioctl ( fd, SIOCGIFCONF, ( char * ) &ifc ) )
{
int i;
pIfAddr->uIfNum = ifc.ifc_len / sizeof ( struct ifreq );
pIfAddr->uIfNum = pIfAddr->uIfNum % MAXINTERFACES;
for ( i = 0; i < pIfAddr->uIfNum; i++ )
{
ioctl ( fd, SIOCGIFFLAGS, ( char * ) &buf[i] );
pIfAddr->tIfEntity[i].uIfState = buf[i].ifr_flags & IFF_UP;
if ( !( ioctl ( fd, SIOCGIFADDR, ( char * ) &buf[i] ) ) )
{
pIfAddr->tIfEntity[i].dIfIP = ( ( struct sockaddr_in * )
( &buf[i].ifr_addr ) )->
sin_addr.s_addr;
}
}
}
}
close ( fd );
return pIfAddr->uIfNum;
}
u32 GetLocalIP ( )
{
struct hostent *host;
struct in_addr *hostip_addr;
char name[100];
gethostname ( name, 24 );
host = gethostbyname ( name );
WxcAssert ( NULL != host, "Get Local IP failed" );
hostip_addr = ( struct in_addr * ) ( *host->h_addr_list );
return hostip_addr->s_addr;
}
///////////////////////////////////////////////////////////////////////////
// Inet If Address infomation interface
///////////////////////////////////////////////////////////////////////////
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD>
static u16 IcmpCheckSum ( u16 * addr, int len )
{
int nleft = len;
int sum = 0;
u16 *w = addr;
u16 answer = 0;
//<2F><>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD>
while ( nleft > 1 )
{
sum += *w++;
nleft -= 2;
}
//<2F><>ICMP<4D><50>ͷΪ<CDB7><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֽڡ<D6BD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ϊһ<CEAA><D2BB>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĸ<DDB5><C4B8>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĵ<DDB5><C4B5>ֽ<EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
if ( nleft == 1 )
{
*( unsigned char * ) ( &answer ) = *( unsigned char * ) w;
sum += answer;
}
sum = ( sum >> 16 ) + ( sum & 0xffff );
sum += ( sum >> 16 );
answer = ~sum;
return answer;
}
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
static int IcmpPacking ( IcmpSrv * pIS )
{
int i, packsize;
struct icmp *icmp;
struct timeval *tval;
icmp = ( struct icmp * ) pIS->aSendBuff;
icmp->icmp_type = ICMP_ECHO;
icmp->icmp_code = 0;
icmp->icmp_cksum = 0;
icmp->icmp_seq = pIS->nPackNumSend;
icmp->icmp_id = pIS->tPid;
packsize = 8 + pIS->uDataLen;
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
tval = ( struct timeval * ) icmp->icmp_data;
gettimeofday ( tval, NULL );
icmp->icmp_cksum = IcmpCheckSum ( ( u16 * ) icmp, packsize );
return packsize;
}
//<2F><>ȥICMP<4D><50>ͷ
static int IcmpUnPack ( u8 * buf, int len, IcmpSrv * pIS )
{
int i, nIpHdrLen;
struct ip *pIP;
struct icmp *icmp;
struct timeval *tvSend;
struct timeval tvRecv;
double rtt;
gettimeofday ( &tvRecv, NULL );
pIP = ( struct ip * ) buf;
//<2F><>ip<69><70>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>,<2C><>ip<69><70>ͷ<EFBFBD>ij<EFBFBD><C4B3>ȱ<EFBFBD>־<EFBFBD><D6BE>4
nIpHdrLen = pIP->ip_hl << 2;
//Խ<><D4BD>ip<69><70>ͷ,ָ<><D6B8>ICMP<4D><50>ͷ
icmp = ( struct icmp * ) ( buf + nIpHdrLen );
//ICMP<4D><50>ͷ<EFBFBD><CDB7>ICMP<4D><50><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
len -= nIpHdrLen;
if ( len < 8 )
//С<><D0A1>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>򲻺<EFBFBD><F2B2BBBA><EFBFBD>
{
printf ( "ICMP packets's length is less than 8 " );
return 0;
}
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ICMP<4D>Ļ<EFBFBD>Ӧ
if ( ( icmp->icmp_type == ICMP_ECHOREPLY )
&& ( icmp->icmp_id == pIS->tPid ) )
{
tvSend = ( struct timeval * ) icmp->icmp_data;
rtt = ( tvRecv.tv_sec * 1000 + tvRecv.tv_usec / 1000 ) -
( tvSend->tv_sec * 1000 + tvSend->tv_usec / 1000 );
printf ( "%d byte from %s: icmp_seq=%u ttl=%d rtt=%.3f ms \n", len,
inet_ntoa ( pIS->tFromAddr.sin_addr ), icmp->icmp_seq,
pIP->ip_ttl, rtt );
return 1;
}
return 0;
}
static void IcmpStatis ( IcmpSrv * pIS )
{
int nSend, nRecv;
nSend = pIS->nPackNumSend;
nRecv = pIS->nPackNumRecv;
printf ( " --------------------PING statistics------------------- \n" );
printf ( "%d packets transmitted, %d received , %%%d lost \n\n", nSend,
nRecv, ( nSend - nRecv ) / nSend * 100 );
close ( pIS->wSockfd );
pIS->uSrvState = 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
static int IcmpSend ( IcmpSrv * pIS )
{
int nSize;
if ( pIS->nPackNumSend < MAX_NO_PACKETS )
{
pIS->nPackNumSend++;
nSize = IcmpPacking ( pIS );
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
if ( sendto ( pIS->wSockfd, pIS->aSendBuff, nSize, 0,
( struct sockaddr * ) &pIS->tToAddr,
sizeof ( pIS->tToAddr ) ) < 0 )
{
perror ( "sendto error" );
return 0;
}
printf ( "[IcmpSend] : Send icmp Pack %d \n", pIS->nPackNumSend );
return 1;
}
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
static void IcmpRecv ( IcmpSrv * pIS )
{
int n, fromlen;
extern int errno;
fromlen = sizeof ( pIS->tFromAddr );
while ( pIS->nPackNumRecv < pIS->nPackNumSend )
{
if ( ( n =
recvfrom ( pIS->wSockfd, pIS->aRecvBuff,
sizeof ( pIS->aRecvBuff ), 0,
( struct sockaddr * ) &pIS->tFromAddr,
&fromlen ) ) < 0 )
{
if ( errno == EINTR )
continue;
perror ( "recvfrom error" );
continue;
}
if ( IcmpUnPack ( pIS->aRecvBuff, n, pIS ) == -1 )
continue;
pIS->nPackNumRecv++;
}
}
extern int PingInit ( IcmpSrv * pIS, int nDataLen )
{
memset ( pIS, 0, sizeof ( IcmpSrv ) );
pIS->uSrvState = 0;
pIS->uDataLen = 56;
if ( ( pIS->pProtoent = getprotobyname ( "icmp" ) ) == NULL )
{
perror ( "getprotobyname" );
exit ( 1 );
}
// <20><><EFBFBD><EFBFBD>rootȨ<74><C8A8>,<2C><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>û<EFBFBD>Ȩ<EFBFBD><C8A8>
setuid ( getuid ( ) );
//<2F><>ȡmain<69>Ľ<EFBFBD><C4BD><EFBFBD>id,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D>ı<EFBFBD>־<EFBFBD><D6BE>
pIS->tPid = getpid ( );
}
extern int PingStart ( IcmpSrv * pIS, char *sIP, PingCallBack fCallBack )
{
int nSize;
struct hostent *pHost;
//struct in_addr *pInAddr;
u32 nInetAddr;
if ( pIS->uSrvState )
{
return 0;
}
pIS->fCallBack = fCallBack;
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ICMP<4D><50>ԭʼ<D4AD>׽<EFBFBD><D7BD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD><EFBFBD>ֻ<EFBFBD><D6BB>root<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ( ( pIS->wSockfd =
socket ( AF_INET, SOCK_RAW, pIS->pProtoent->p_proto ) ) < 0 )
{
perror ( "socket error" );
exit ( 1 );
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD>ֽ<EFBFBD><D6BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>50K<30><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪΪ<D2AA>˼<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ping<6E><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>
setsockopt ( pIS->wSockfd, SOL_SOCKET, SO_RCVBUF, &nSize,
sizeof ( nSize ) );
bzero ( &pIS->tToAddr, sizeof ( pIS->tToAddr ) );
pIS->tToAddr.sin_family = AF_INET;
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip<69><70>ַ
nInetAddr = inet_addr ( sIP );
if ( nInetAddr == INADDR_NONE )
{
if ( ( pHost = gethostbyname ( sIP ) ) == NULL ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
perror ( "gethostbyname error" );
exit ( 1 );
}
memcpy ( ( char * ) &pIS->tToAddr.sin_addr, pHost->h_addr,
pHost->h_length );
}
else //<2F><>ip<69><70>ַ
{
pIS->tToAddr.sin_addr.s_addr = nInetAddr;
//memcpy( (char *)&pIS->tToAddr,(char *)&nInetAddr,host->h_length);
}
printf ( "PING %s(%s): %d bytes data in ICMP packets. \n", sIP,
inet_ntoa ( pIS->tToAddr.sin_addr ), pIS->uDataLen );
pIS->uSrvState = 1;
pIS->uIcmpState = 1;
}
extern int PingTimer ( IcmpSrv * pIS )
{
if ( pIS->uSrvState )
{
IcmpRecv ( pIS );
switch ( pIS->uIcmpState )
{
case 1:
case 2:
case 3:
IcmpSend ( pIS );
pIS->uIcmpState++;
break;
default:
if ( pIS->nPackNumRecv >= 3 )
{
IcmpStatis ( pIS );
pIS->fCallBack ( 1 );
}
if ( pIS->uIcmpState++ > 200 )
{
IcmpStatis ( pIS );
pIS->fCallBack ( 0 );
}
break;
}
}
}
/*@end@*/

View File

@@ -0,0 +1,135 @@
//////////////////////////////////////////////////
//Title : pub_log.c
//Auhtor : Liu Wei
//Desc : public output log implementation
//Created : 2007-05-21
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_log.h"
void FLogMsg( u8 LogMask , const char *pFmt, ...)
{
va_list ap;
va_start(ap, pFmt);
switch( LogMask )
{
case PIF_INFO:
break;
case PIF_WARN:
break;
case PIF_GERR:
break;
case PIF_CERR:
break;
case PIF_DBG:
break;
case PIF_UNKN:
break;
case PIF_DEFAULT:
break;
case PIF_ALL:
break;
default:
break;
}
printf(pFmt, ap);
va_end(ap);
return;
}
char *ByteBinToStr( char *pDst , const u8 *pSrc , int nByte )
{
register int i , j , k = 0;
for( i =0 ; i < nByte ; i++ )
{
for( j = 7 ; j >= 0 ; j --)
{
pDst[k++] = (pSrc[i] >>j & 0x01) + '0';
}
}
pDst[k++] = CNULL;
return pDst;
}
inline char *TxtColor ( int nAttr, int nFg, int nBg, char *pStr )
{
register int nPos ;
int nLen = strlen(pStr);
char *p = strdup (pStr);
nPos = 0;
pStr[nPos++] = 27;
pStr[nPos++] = '[';
pStr[nPos++] = nAttr + '0';
pStr[nPos++] = ';';
pStr[nPos++] = 3 + '0';
pStr[nPos++] = nFg + '0';
pStr[nPos++] = ';';
pStr[nPos++] = 4 + '0';
pStr[nPos++] = nBg + '0';
pStr[nPos++] = 'm';
strcpy( pStr + nPos , p);
nPos += nLen;
pStr[nPos++] = 27;
pStr[nPos++] = '[';
pStr[nPos++] = RESET + '0';
pStr[nPos++] = ';';
pStr[nPos++] = 3 + '0';
pStr[nPos++] = WHITE + '0';
pStr[nPos++] = ';';
pStr[nPos++] = 4 + '0';
pStr[nPos++] = BLACK + '0';
pStr[nPos++] = 'm';
pStr[nPos] = CNULL;
free(p);
return pStr;
}
inline int MsgToFmtLog ( const BYTE * pBcd, int nBcdLen, char *pStr, int nStrBuffSize )
{
register int i, len = 0;
int nChar;
nChar = ( nBcdLen / 16 ) * 49;
if( (nBcdLen %16) > 8 )
{
nChar+=8*3 +1;
}
nChar += (nBcdLen %8)*3 +1 + 2 ; //add "\r\n" at end
WxcAssert ( ( nChar < nStrBuffSize ), "sprint bcd string buffer flow" );
for ( i = 0; i <= nBcdLen-1; i++ )
{
pStr[len++] = HexToCh(pBcd[i] >> 4 );
pStr[len++] = HexToCh(pBcd[i] & 0x0F);
pStr[len++] = ' ';
if ( 0 == ( (i+1) % 16 ) && i)
{
pStr[len++] = '\n';
}
else if ( 0 == ( (i+1) % 8 ) )
{
pStr[len++] = ' ';
}
}
if ( 0 != ( len % 49 ) )
{
pStr[len++] = ' ';
}
pStr[len++] = '\r';
pStr[len++] = '\n';
pStr[len++] = CNULL;
return len;
}

View File

@@ -0,0 +1,23 @@
//////////////////////////////////////////////////
//Title : wxc_malloc.c
//Auhtor : Liu Wei
//Desc : WXC2 Public heap memery management
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_malloc.h"
/*
void *WxcMalloc ( )
{
return (void*)NULL;
}
void WxcFree ( )
{
}
*/

View File

@@ -0,0 +1,370 @@
//////////////////////////////////////////////////
//Title : wxc_netcap.c
//Auhtor : Liu Wei
//Desc : wxc2 netcap implementation
//Created : 2007-06-05
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_netcap.h"
/*@ignore@*/
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif
static NetCap tNC;
#define BASE 65521
static u32 NcAd32 ( u32 ad, u8 * buf, int len )
{
u32 s1 = ad & 0xffff;
u32 s2 = ( ad >> 16 ) & 0xffff;
int n;
for ( n = 0; n < len; n++, buf++ )
{
s1 = ( s1 + *buf );
if ( s1 >= BASE )
s1 -= BASE;
s2 = ( s2 + s1 );
if ( s2 >= BASE )
{
s2 -= BASE;
}
}
return ( s2 << 16 ) + s1;
}
#define HEADER_LEN 12
static u32 NcCS ( u8 * ptr, u16 count )
{
u32 ad = 1L;
u32 zero = 0L;
ad = NcAd32 ( ad, ptr, sizeof ( HEADER_LEN - sizeof ( u32 ) ) );
ad = NcAd32 ( ad, ( u8 * ) & zero, sizeof ( u32 ) );
ptr += HEADER_LEN;
count -= HEADER_LEN;
ad = NcAd32 ( ad, ptr, count );
return ad;
}
static int NcGetSocket ( u32 port )
{
int nSock;
int nOn = 1;
unsigned long 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 ( ( nSock = socket ( AF_INET, SOCK_RAW, IPPROTO_SCTP ) ) < 0 )
{
perror ( "Get SCTP socket error " );
return -1;
}
setsockopt ( nSock, SOL_SOCKET, SO_REUSEADDR, &nOn, sizeof ( nOn ) );
ioctl ( nSock, FIONBIO, &cmdarg );
return ( nSock );
}
extern void NcSetPort ( u32 port )
{
tNC.nPort = port;
}
extern void NcSetIP ( u32 ip )
{
tNC.nDstIp = ip;
}
extern int NcInit ( )
{
memset ( &tNC, 0, sizeof ( NetCap ) );
tNC.nPort = 8000;
tNC.nDstIp = inet_addr ( "172.54.240.3" );
return 1;
}
extern int NcStart ( u32 wIP, u32 wPort )
{
if ( tNC.uState )
return 0;
tNC.nDstIp = wIP ? wIP : tNC.nDstIp;
tNC.nPort = wPort ? wPort : tNC.nPort;
tNC.nSock = NcGetSocket ( tNC.nPort );
tNC.uState = 1;
return 1;
}
extern int NcStop ( )
{
shutdown ( tNC.nSock, 2 );
tNC.uState = 0;
return 1;
}
#define SCTP_HEADER_LEN 0x1C
#define SCCTP_CS_POS 0x08
#define SCTP_CHUNKLEN_POS 15
static u8 SCTP_HEADER[] = {
0x13, 0x56, 0x13, 0x56, 0x00, 0x00, 0x2d, 0xd1,
0x05, 0x67, 0x59, 0x7a, 0x00, 0x00, 0x00, 0x3c,
0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11,
0x00, 0x00, 0x00, 0x02
};
static int NcStuffSCTP ( u8 * pIPBuff )
{
memcpy ( pIPBuff, SCTP_HEADER, SCTP_HEADER_LEN );
pIPBuff[0] = 4950 >> 8;
pIPBuff[1] = 4950 & 0xFF;
pIPBuff[2] = tNC.nPort >> 8;
pIPBuff[3] = tNC.nPort & 0xFF;
return SCTP_HEADER_LEN;
}
#define M2UA_HEADER_LEN 0x14
#define M2UA_MSGLEN_POS 0x07
#define M2UA_PARALEN_POS 0x13
static inline int NcGetM2uaParaLen ( u32 wMtp3Len )
{
return ( wMtp3Len + 4 );
}
static inline int NcGetM2uaMsgLen ( u32 wMtp3Len )
{
return ( NcGetM2uaParaLen ( wMtp3Len ) + 16 );
}
static u8 M2UA_HEADER[] = {
0x01, 0x00, 0x06, 0x01, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x1c
};
int NcStuffM2UA ( u8 * pIPBuff, u32 wMtp3Len )
{
memcpy ( pIPBuff, M2UA_HEADER, M2UA_HEADER_LEN );
*( pIPBuff + M2UA_PARALEN_POS ) = NcGetM2uaParaLen ( wMtp3Len );
*( pIPBuff + M2UA_MSGLEN_POS ) = NcGetM2uaMsgLen ( wMtp3Len );
return M2UA_HEADER_LEN;
}
#define MTP3_HAEDER_ANSI_LEN 0x08
static u8 MTP3_HEADER_ANSI[] = {
0x83, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00
};
#define MTP3_HAEDER_ITU_LEN 0x05
static u8 MTP3_HEADER_ITU[] = {
0x83, 0x20, 0x00, 0x08, 0x00
};
static int NcStuffMtp3 ( u8 * pIPBuff, u32 wDPC, u32 wOPC, u8 uSLS,
u8 uAnsiFlag )
{
u32 MTP3_HAEDER_LEN;
u8 *MTP3_HEADER;
//printf ( "stuff mtp3 : dpc :%ld opc :%ld sls: %d , ansi :%d \n", wDPC, wOPC,
// uSLS, uAnsiFlag );
if ( uAnsiFlag )
{
MTP3_HEADER_ANSI[1] = wDPC ? MTP3_HEADER_ANSI[1] : wDPC;
MTP3_HEADER_ANSI[4] = wOPC ? MTP3_HEADER_ANSI[4] : wOPC;
MTP3_HEADER_ANSI[7] = uSLS ? MTP3_HEADER_ANSI[7] : uSLS;
}
else
{
if ( wDPC )
{
MTP3_HEADER_ITU[1] = wDPC & 0xFF;
MTP3_HEADER_ITU[2] &= 0xC0;
MTP3_HEADER_ITU[2] |= ( wDPC >> 8 ) & 0x3F;
}
if ( wOPC )
{
MTP3_HEADER_ITU[2] &= 0x3F;
MTP3_HEADER_ITU[2] |= ( wDPC & 0x03 ) << 6;
MTP3_HEADER_ITU[3] = wDPC >> 2;
MTP3_HEADER_ITU[4] &= 0xF0;
MTP3_HEADER_ITU[4] |= wOPC >> 10;
}
MTP3_HEADER_ITU[4] &= 0x0F;
MTP3_HEADER_ITU[4] |= uSLS << 4;
}
MTP3_HEADER = uAnsiFlag ? MTP3_HEADER_ANSI : MTP3_HEADER_ITU;
MTP3_HAEDER_LEN = uAnsiFlag ? MTP3_HAEDER_ANSI_LEN : MTP3_HAEDER_ITU_LEN;
memcpy ( pIPBuff, MTP3_HEADER, MTP3_HAEDER_LEN );
return MTP3_HAEDER_LEN;
}
extern void NcMtp3Send ( u8 * pMtp3Msg, u32 wMtp3Len, u8 uAnsiFlag )
{
u8 IPBuff[512];
u32 wPackLen = 0;
u32 wM2uaLen = 0;
u32 ad = 0;
u32 MTP3_HAEDER_LEN;
u8 uPad = 0;
struct sockaddr_in sin_addr;
memset ( IPBuff, 0, 512 * sizeof ( u8 ) );
wPackLen += NcStuffSCTP ( IPBuff + wPackLen );
MTP3_HAEDER_LEN = uAnsiFlag ? MTP3_HAEDER_ANSI_LEN : MTP3_HAEDER_ITU_LEN;
wM2uaLen = NcStuffM2UA ( IPBuff + wPackLen, wMtp3Len );
wPackLen += wM2uaLen;
memcpy ( IPBuff + wPackLen, pMtp3Msg, wMtp3Len );
wPackLen += wMtp3Len;
uPad = ( IPBuff[SCTP_HEADER_LEN + 7] ) % 4;
uPad = uPad ? ( 4 - uPad ) : 0;
for ( ; uPad > 0; uPad-- )
{
IPBuff[SCTP_HEADER_LEN + 7]++; //m2ua msg len
IPBuff[wPackLen++] = 0x00;
}
IPBuff[SCTP_CHUNKLEN_POS] = 0x10 + IPBuff[SCTP_HEADER_LEN + 7];
ad = NcCS ( IPBuff, wPackLen );
IPBuff[SCCTP_CS_POS] = ad & 0xFF;
IPBuff[SCCTP_CS_POS + 1] = ad / ( 256 );
IPBuff[SCCTP_CS_POS + 2] = ad / ( 256 * 256 );
IPBuff[SCCTP_CS_POS + 3] = ad / ( 256 * 256 * 256 );
sin_addr.sin_family = AF_INET;
sin_addr.sin_port = htons ( tNC.nPort );
sin_addr.sin_addr.s_addr = tNC.nDstIp;
sendto ( tNC.nSock, ( char * ) IPBuff, wPackLen, 0,
( struct sockaddr * ) &sin_addr, sizeof ( struct sockaddr ) );
//printf ( "\nMTP3 Send Net cap message!\n " );
}
typedef struct WXC_NETCAP_SCCP_INTRA_MESSAGE
{
u8 msgsource;
u8 msgtype;
u8 msgclass;
u8 msgMNP;
int OPC;
int DPC;
u8 SLS;
}
Wxc_NCSccpIntra;
extern int NcSccpSend ( u8 * pSccpMsg, u32 wSccpLen, u8 * pIntraMsg,
BYTE uAnsiFlag )
{
u8 IPBuff[512];
u32 wPackLen = 0;
u32 wM2uaLen = 0;
u32 ad = 0;
u8 uPad = 0;
u32 MTP3_HAEDER_LEN;
struct sockaddr_in sin_addr;
Wxc_NCSccpIntra *pIntra = ( Wxc_NCSccpIntra * ) pIntraMsg;
memset ( IPBuff, 0, 512 * sizeof ( u8 ) );
wPackLen += NcStuffSCTP ( IPBuff + wPackLen );
MTP3_HAEDER_LEN = uAnsiFlag ? MTP3_HAEDER_ANSI_LEN : MTP3_HAEDER_ITU_LEN;
wM2uaLen = NcStuffM2UA ( IPBuff + wPackLen, wSccpLen + MTP3_HAEDER_LEN );
wPackLen += wM2uaLen;
wPackLen +=
NcStuffMtp3 ( IPBuff + wPackLen, pIntra->DPC, pIntra->DPC, pIntra->SLS,
uAnsiFlag );
memcpy ( IPBuff + wPackLen, pSccpMsg, wSccpLen );
wPackLen += wSccpLen;
uPad = ( IPBuff[SCTP_HEADER_LEN + 7] ) % 4;
uPad = uPad ? ( 4 - uPad ) : 0;
for ( ; uPad > 0; uPad-- )
{
IPBuff[SCTP_HEADER_LEN + 7]++; //m2ua msg len
IPBuff[wPackLen++] = 0x00;
}
IPBuff[SCTP_CHUNKLEN_POS] = 0x10 + IPBuff[SCTP_HEADER_LEN + 7];
ad = NcCS ( IPBuff, wPackLen );
IPBuff[SCCTP_CS_POS] = ad & 0xFF;
IPBuff[SCCTP_CS_POS + 1] = ad / ( 256 );
IPBuff[SCCTP_CS_POS + 2] = ad / ( 256 * 256 );
IPBuff[SCCTP_CS_POS + 3] = ad / ( 256 * 256 * 256 );
sin_addr.sin_family = AF_INET;
sin_addr.sin_port = htons ( tNC.nPort );
sin_addr.sin_addr.s_addr = tNC.nDstIp;
if ( sendto
( tNC.nSock, ( char * ) IPBuff, wPackLen, 0,
( struct sockaddr * ) &sin_addr, sizeof ( struct sockaddr ) ) < 0 )
{
perror ( "SCCP send tNC error!\n" );
return 0;
}
//printf ( "\nSCCP Send Net cap message!\n " );
//write(nSock, IPBuff, wPackLen);
return 1;
}
/*
#define SCCP_RLSE_LEN 0x0a
static u8 SCCP_RLSD[ ] =
{
0x04, 0x01, 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x01,
0x00
};
void main()
{
int i;
NcInit();
NcStart(inet_addr("10.167.144.35") , 8000 );
for( i = 0 ; i < 5000 ; i ++ )
{
sleep(1);
NcSccpSend( SCCP_RLSD , SCCP_RLSE_LEN );
}
NcStop();
return ;
}
*/
/*@end@*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,977 @@
//////////////////////////////////////////////////
//Title : wxc_str.c
//Auhtor : Liu Wei
//Desc : wxc2 string library
//Created : 2007-06-20
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_str.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// Name : StrInc
// Function : test string is included in string "pStr"or not
//////////////////////////////////////////////////////////////////////////
inline char *StrInc ( char *pIncStr, char *pStr )
{
int m;
register char *pCh;
register int n;
m = strlen ( pIncStr );
n = strlen ( pStr );
for ( pCh = pStr; !IsChNull(*pCh) && ( n >= m ); pCh++, n-- )
{
if ( !strncmp ( pIncStr, pCh, m ) )
{
return ( pCh );
}
}
return ( NULL );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrIns
// Function : Insert string "pStrIns" to string "pSrc" , at the position of
// nPos, the nBufLen of string "pSrc" , is not enought , rerurn
// NULL, nor return pSrc
///////////////////////////////////////////////////////////////////////////
inline char *StrIns ( int nPos, const char *pStrIns, char *pSrc, int nBufLen )
{
register int i;
int nLen;
nLen = strlen ( pStrIns );
if ( nBufLen < nLen + strlen ( pSrc ) )
{
return NULL;
}
*(pSrc+nLen+strlen ( pSrc )) = CNULL;
for ( i = strlen ( pSrc ); i >= nPos; i-- )
{
*( pSrc + nLen + i ) = *( pSrc + i );
}
for ( i = 0; i < nLen; i++ )
{
*( pSrc + nPos + i ) = *( pStrIns + i );
}
return ( pSrc );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrDel
// Function : Delete string "pStrDel" in string "pStr" , If pStrDel is not
// exist, rerurn NULL, nor return pSrc
///////////////////////////////////////////////////////////////////////////
inline char *StrDel ( char *pStrDel, char *pStr )
{
char *pCh, *pPos;
pCh = strstr ( pStr, pStrDel );
if ( !pCh )
{
return ( NULL );
}
pPos = pCh + strlen ( pStrDel );
strcpy ( pCh, pPos );
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrRepCh
// Function : Replace char cSrc in the string pStr with cDst
// Return : return the replace counter
///////////////////////////////////////////////////////////////////////////
inline int StrRepCh ( char *pStr, char cSrc, char cDst )
{
int nReplaced = 0;
register char *pCh;
for ( pCh = pStr; !IsChNull ( *pCh ); pCh++ )
{
if ( cSrc == *pCh )
{
*pCh = cDst;
nReplaced++;
}
}
return ( nReplaced );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrRepStr
// Function : Replace the first string "pSrc" in string "pStr" with "pDst" ,
// If pSrc is not exist or the nBuffLen of pStr is not enought
// to insert pDst , rerurn NULL, nor return new pSrc
///////////////////////////////////////////////////////////////////////////
inline char *StrRepStr ( char *pStr, char *pSrc, char *pDst, int nBuffLen )
{
char *pCh = NULL;
int nPos;
pCh = strstr ( pSrc, pStr);
if ( !IsNull(pCh) )
{
StrDel ( pSrc, pStr );
nPos = pCh - pStr;
if (NULL == StrIns ( nPos, pDst, pStr, nBuffLen ))
pCh = NULL;
else
pCh = pStr;
}
return ( pCh );
}
/*
inline char *StrRepStr ( char *pStr, char *pSrc, char *pDst, int nBuffLen )
{
char *pCh = NULL;
int nPos;
int SrcLen;
int DstLen;
SrcLen = strlen(pSrc);
DstLen = strlen(pDst);
pCh = strstr ( pStr, pSrc);
if ( (!IsNull(pCh)) && (nBuffLen >DstLen + strlen ( pStr ) - SrcLen))
{
StrDel ( pSrc, pStr );
nPos = pCh - pStr;
if (NULL == StrIns ( nPos, pDst, pStr, nBuffLen ))
pCh =NULL;
else
pCh = pStr;
}
else
pCh =NULL;
return ( pCh );
}
*/
///////////////////////////////////////////////////////////////////////////
// Name : StrChg
// Function : Replace all the string "pSrc" in string "pStr" with "pDst" ,
// If pSrc is not exist or the nBuffLen of pStr is not enought
// to insert pDst , rerurn NULL, nor return new pSrc
///////////////////////////////////////////////////////////////////////////
/*
inline char *StrChg ( char *pStr, char *pSrc, char *pDst , int nBuffLen )
{
int n = 0;
char *pCh = pStr;
int i;
i = strlen ( pDst );
for ( ;; )
{
if ( IsNull( StrRepStr ( pCh, pSrc, pDst, nBuffLen ) ) )
{
break;
}
pCh += i;
n++;
}
return ( n ? pStr : NULL );
}
*/
/*
inline char *StrChg ( char *pStr, char *pSrc, char *pDst , int nBuffLen )
{
int n = 0;
char *pCh = pStr;
char *pCounter = pStr;
int DstLen;
int SrcLen;
int counter = 0;
SrcLen = strlen(pSrc);
DstLen = strlen(pDst);
pCounter = strstr(pCounter, pSrc);
while (NULL != pCounter)
{
counter++;
pCounter = strstr(pCounter+SrcLen, pSrc);
}
if ((0 != counter) && (nBuffLen > strlen(pStr)+DstLen*counter-SrcLen*counter))
{
for ( ;; )
{
if ( IsNull( StrRepStr ( pCh, pSrc, pDst, nBuffLen ) ) )
{
break;
}
nBuffLen = nBuffLen - DstLen;
pCh += DstLen;
n++;
}
}
return ( n ? pStr : NULL );
}
*/
///////////////////////////////////////////////////////////////////////////
// Name : StriInc
// Function : test string is included in string "pStr"or not
// Note : No matter Upper or Lower
///////////////////////////////////////////////////////////////////////////
inline char *StriInc ( char *pIncStr, char *pStr )
{
int m;
register char *pCh;
register int n;
m = strlen ( pIncStr );
n = strlen ( pStr );
for ( pCh = pStr; !IsChNull(*pCh) && ( n >= m ); pCh++, n-- )
{
if ( !strncasecmp ( pIncStr, pCh, m ) )
{
return ( pCh );
}
}
return ( NULL );
}
///////////////////////////////////////////////////////////////////////////
// Name : StriDel
// Function : Delete string "pStrDel" in string "pStr" , If pStrDel is not
// exist, rerurn NULL, nor return pSrc
// Note : No matter Upper or Lower
//////////////////////////////////////////////////////////////////////////
inline char *StriDel ( char *pStrDel, char *pStr )
{
char *pCh, *pPos;
pCh = StriInc ( pStrDel, pStr );
if ( !pCh )
{
return ( NULL );
}
pPos = pCh + strlen ( pStrDel );
strcpy ( pCh, pPos );
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrRepCh
// Function : Replace char cSrc in the string pStr with cDst
// Return : return the replace counter
///////////////////////////////////////////////////////////////////////////
inline int StriRepCh ( char *pStr, char cSrc, char cDst )
{
int nReplaced = 0;
register char *pCh;
cSrc = toupper ( cSrc );
for ( pCh = pStr; !IsChNull( *pCh ); pCh++ )
{
if ( cSrc == toupper ( *pCh ) )
{
*pCh = cDst;
nReplaced++;
}
}
return ( nReplaced );
}
///////////////////////////////////////////////////////////////////////////
// Name : StriRepStr
// Function : Replace the first string "pSrc" in string "pStr" with "pDst" ,
// If pSrc is not exist or the nBuffLen of pStr is not enought
// to insert pDst , rerurn NULL, nor return new pSrc
///////////////////////////////////////////////////////////////////////////
inline char *StriRepStr ( char *pStr, char *pSrc, char *pDst, int nBuffLen )
{
char *pCh = NULL;
int nPos;
pCh = StriInc ( pSrc, pStr);
if ( !IsNull(pCh) )
{
StriDel ( pSrc, pStr );
nPos = pCh - pStr;
if (NULL == StrIns ( nPos, pDst, pStr, nBuffLen ))
pCh = NULL;
else
pCh = pStr;
}
return ( pCh );
}
/*
inline char *StriRepStr ( char *pStr, char *pSrc, char *pDst, int nBuffLen )
{
char *pCh = NULL;
int nPos;
int SrcLen;
int DstLen;
SrcLen = strlen(pSrc);
DstLen = strlen(pDst);
pCh = StriInc ( pSrc, pStr);
if (( !IsNull(pCh) ) && (nBuffLen >DstLen + strlen ( pStr ) - SrcLen))
{
StriDel ( pSrc, pStr );
nPos = pCh - pStr;
if (NULL == StrIns ( nPos, pDst, pStr, nBuffLen ))
pCh = NULL;
else
pCh = pStr;
}
else
pCh = NULL;
return ( pCh );
}
*/
///////////////////////////////////////////////////////////////////////////
// Name : StrChg
// Function : Replace all the string "pSrc" in string "pStr" with "pDst" ,
// If pSrc is not exist or the nBuffLen of pStr is not enought
// to insert pDst , rerurn NULL, nor return new pSrc
// Note : No matter Upper or Lower
///////////////////////////////////////////////////////////////////////////
/*
inline char *StriChg ( char *pStr, char *pSrc, char *pDst , int nBuffLen )
{
int n = 0;
char *pCh = pStr;
int i;
int nSrc , nDst ;
i = strlen ( pDst );
for ( ;; )
{
if ( IsNull( StriRepStr ( pCh, pSrc, pDst, nBuffLen ) ) )
{
break;
}
pCh += i;
n++;
}
return ( n ? pStr : NULL );
}
*/
/*
inline char *StriChg ( char *pStr, char *pSrc, char *pDst , int nBuffLen )
{
int n = 0;
char *pCh = pStr;
char *pCounter = pStr;
int DstLen;
int SrcLen;
int counter = 0;
SrcLen = strlen(pSrc);
DstLen = strlen(pDst);
pCounter = StriInc(pSrc, pCounter);
while (NULL != pCounter)
{
counter++;
pCounter = StriInc(pSrc, pCounter + SrcLen);
}
if ((0 != counter) && (nBuffLen > strlen(pStr)+DstLen*counter-SrcLen*counter))
{
for ( ;; )
{
if ( IsNull( StriRepStr ( pCh, pSrc, pDst, nBuffLen ) ) )
{
break;
}
nBuffLen = nBuffLen - DstLen;
pCh += DstLen;
n++;
}
}
return ( n ? pStr : NULL );
}
*/
///////////////////////////////////////////////////////////////////////////
// Name : StrCode
// Function : Xor the pStr with pSecCode , used in security coding
///////////////////////////////////////////////////////////////////////////
inline char *StrCode ( char *pStr, char *pSecCode )
{
char *q = pSecCode;
register char *pCh;
for ( pCh = pStr; !IsChNull(*pCh); pCh++ )
{
if ( *pCh != *q )
{
*pCh = *pCh ^ *q;
}
q++;
if ( IsChNull(*q) )
{
q = pSecCode;
}
}
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrFinis
// Function : cut the string with '\0', if nPos > the len of pStr , fill
// the string end with ' ' and set the pStr end positon at nPos
///////////////////////////////////////////////////////////////////////////
inline char *StrFinis ( char *pStr, int nPos )
{
int i;
int nLen;
nLen = strlen ( pStr );
if ( nPos < nLen )
{
*( pStr + nPos ) = CNULL;
}
else
{
for ( i = nLen; i < nPos; i++ )
{
*( pStr + i ) = ' ';
}
*( pStr + i ) = CNULL;
}
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrEnding
// Function : set the string end with the pEnd string till nPos position
//////////////////////////////////////////////////////////////////////////
inline char *StrEnding( char *pDst, char *pEnd , int nPos )
{
register int nLen = strlen(pDst);
int nEndLen = strlen(pEnd);
if( nPos < nLen + nEndLen )
{
return NULL;
}
for( ; nPos > nLen + nEndLen ; nLen += nEndLen )
{
strcat( pDst , pEnd);
}
}
///////////////////////////////////////////////////////////////////////////
// StrSuff: checks whether suffix is a suffix of src. If it is not,
// the result is NULL. If it is, the result is a pointer
// to the character of src.
///////////////////////////////////////////////////////////////////////////
inline char *StrSuff(const char *pSrc, const char *pSuffix )
{
register int nLen;
for ( nLen = 0; *pSuffix++; nLen++ )
if(!*pSrc++) return NULL;
while (*pSrc++);
for ( --pSrc, --pSuffix; --nLen >= 0; )
if ( *--pSrc != *--pSuffix ) return NULL;
return (char*)pSrc;
}
/* Fill string 'c' into last area of 'str'. */
void StringCat(char *str, char *c, int slen)
{
if (strlen(str) >= slen)
return;
while (strlen(str) < slen)
strcat(str, c);
str[slen] = 0;
}
///////////////////////////////////////////////////////////////////////////
// Name : StrLeftShit
// Function : String left shit , delete first n chars
///////////////////////////////////////////////////////////////////////////
inline char *StrLeftShit ( char *pStr, int n )
{
int i;
int len;
len = strlen(pStr);
if( n > len )
{
return StrFinis(pStr , 0);
}
len -= n;
for ( i = 0; i < len; i++ )
{
*( pStr + i ) = *( pStr + n + i );
}
StrFinis( pStr , len );
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrRLeftShit
// Function : String round left shit
///////////////////////////////////////////////////////////////////////////
inline char *StrRLeftShit ( char *pStr, int n )
{
int i, j;
char t;
if ( !IsChNull(*pStr) )
{
for ( j = 0; j < n; j++ )
{
t = *( pStr );
for ( i = 0; *( pStr + i ); i++ )
{
*( pStr + i ) = *( pStr + i + 1 );
}
*( pStr + i - 1 ) = t;
}
}
return ( pStr );
}
///////////////////////////////////////////////////////////////////////////
// StrToLower: String all lower case.
///////////////////////////////////////////////////////////////////////////
inline char *StrToLower ( char *pStr )
{
register char *pCh;
for ( pCh = pStr; pCh && *pCh; ++pCh )
{
if ( isupper ( *pCh ) )
{
*pCh = tolower ( *pCh );
}
}
return pStr;
}
///////////////////////////////////////////////////////////////////////////
// StrToUpper: String all upper case.
///////////////////////////////////////////////////////////////////////////
inline char *StrToUpper ( char *pStr )
{
register char *pCh;
for ( pCh = pStr; pCh && *pCh; ++pCh )
{
if ( islower ( *pCh ) )
{
*pCh = toupper ( *pCh );
}
}
return pStr;
}
///////////////////////////////////////////////////////////////////////////
// StrDupLower: Return an all lower case version of String
// you can free the return pointer
///////////////////////////////////////////////////////////////////////////
inline char *StrDupLower ( char *pStr )
{
static char *pBuffer = NULL;
register char *pCh;
if ( pBuffer )
{
free ( pBuffer );
}
pBuffer = strdup ( pStr );
for ( pCh = pBuffer; pCh && *pCh; ++pCh )
{
if ( isupper ( *pCh ) )
{
*pCh = tolower ( *pCh );
}
}
return ( pBuffer );
}
///////////////////////////////////////////////////////////////////////////
// StrDupUpper: Return an all upper case version of String // you can free the return pointer
///////////////////////////////////////////////////////////////////////////
inline char *StrDupUpper ( char *pStr )
{
static char *pBuffer = NULL;
register char *pCh;
if ( pBuffer )
{
free ( pBuffer );
}
pBuffer = strdup ( pStr );
for ( pCh = pBuffer; pCh && *pCh; ++pCh )
{
if ( islower ( *pCh ) )
{
*pCh = toupper ( *pCh );
}
}
return ( pBuffer );
}
///////////////////////////////////////////////////////////////////////////
// IsExistCh : Is the char exist in the string
///////////////////////////////////////////////////////////////////////////
inline int IsExistCh ( char ch, char *pStr )
{
register char *pCh;
for ( pCh = pStr; !IsChNull(*pCh); ++pCh )
{
if ( ch == *pCh )
{
return ( 1 );
}
}
return ( 0 );
}
///////////////////////////////////////////////////////////////////////////
// FindSep: Find the first char in char set in String
///////////////////////////////////////////////////////////////////////////
inline char *StrChSet ( char *pChSet, char *pStr )
{
register char *pCh;
for ( pCh = pChSet; !IsChNull(*pCh); ++pCh )
{
if ( IsExistCh ( *pCh, pStr ) )
{
return ( pCh );
}
}
return ( ( char * ) NULL );
}
///////////////////////////////////////////////////////////////////////////
// Name : StrChNum
// Function : return the char number in the string
///////////////////////////////////////////////////////////////////////////
inline int StrChNum ( char *pStr, char ch )
{
int n = 0;
char *pCh = pStr;
for( ; !IsChNull(*pCh); pCh++ )
{
if (ch == *pCh)
n++;
}
return ( n );
}
/*
inline int StrChNum ( char *pStr, char ch )
{
int n = 0;
char *pCh = pStr;
for( ; !IsChNull(*pCh) && (ch == *pCh) ; pCh++ )
n++;
return ( n );
}
*/
///////////////////////////////////////////////////////////////////////////
// StrTrimCh: trim the char in the string
///////////////////////////////////////////////////////////////////////////
inline char *StrTrimCh ( char *pSrc , char cTrim )
{
register char *pCh;
char *p,*q;
q = pSrc;
p = pCh = strdup(pSrc);
if (NULL == pCh)
{
return NULL;
}
for( ; !IsChNull(*pCh) ; pCh++ )
{
if(*pCh != cTrim)
{
*pSrc++ = *(pCh);
}
}
*pSrc = '\0';
free(p);
return q;
}
///////////////////////////////////////////////////////////////////////////
// StrTrimCh: trim the char of the set in the string
///////////////////////////////////////////////////////////////////////////
inline char *StrTrimChSet ( char *pSrc , char *pTrimSet )
{
register char *pCh;
char *p , *q , *m;
p = pSrc;
m = pCh = strdup(pSrc);
if (NULL == pCh)
{
return NULL;
}
for( ; !IsChNull(*pCh) ; pCh++ )
{
for( q = pTrimSet; *q && *pCh != *q ; q++ )
{
;
}
if( IsChNull(*q) )
{
*pSrc++ = *(pCh);
}
}
*pSrc = CNULL;
pSrc = p;
free(m);
return pSrc;
}
///////////////////////////////////////////////////////////////////////////
// StrTrimLeftSpace: trim left space of string
///////////////////////////////////////////////////////////////////////////
inline char *StrTrimLeftSpace( const char *pStr )
{
const char *p = pStr;
for ( ; !IsChNull(*p) && isspace(*p) ; )
{
p++;
}
return (char*) p;
}
///////////////////////////////////////////////////////////////////////////
// StrTrimMoreSpace: trim more than one space
///////////////////////////////////////////////////////////////////////////
inline char *StrTrimMoreSpace ( char *pSrc )
{
char *pCh , *q;
register char *p;
pCh = p = strdup(pSrc);
q = pSrc;
for ( ; *p; p++ )
{
if ( !( isspace ( *p ) && isspace ( *(p+1) ) ) )
{
*pSrc++ = *p;
}
}
*pSrc = CNULL;
free(pCh);
return pSrc;
}
///////////////////////////////////////////////////////////////////////////
// StrPickWord: pick a word from the string
///////////////////////////////////////////////////////////////////////////
inline char *StrPickWord ( const char *pSrc, char *pDst )
{
char *pCh , *q = pDst;
pCh = StrTrimLeftSpace(pSrc);
for( ; !isspace(*pCh) && !IsChNull(*pCh) ; pCh++)
{
*q++ = *pCh;
}
return (char *)pDst;
}
///////////////////////////////////////////////////////////////////////////
// Name : StrEqTok
// Function: Parse the string and return the expression name and value
// Return : NULL, parse over or string expression error , nor while to call
// StrEqTok at odd times , return the name ; and return the value
// while even times
// Note : use it like strtok
// e.g. :
// {
// char *p = NULL;
// u8 uFlag = 0;
//
// p = StrEqTok(tmpStr);
// printf( "Name: %-20s " , p);
// for( ; p = StrEqTok(NULL); )
// {
// uFlag = uFlag ? 0 : 1;
// if( uFlag )
// {
// printf( "Valu: %-20s \n" , p);
// }
// else
// {
// printf( "Name: %-20s " , p);
// }
// }
// }
//////////////////////////////////////////////////////////////////////////
static char *pStrEqTok = NULL;
static u8 uStrEqState = 0;
char *StrEqTok ( char *pStr )
{
char *p, *q, *pCh;
char *pDel = " ";
pCh = pStr;
if ( pCh == NULL )
{ //last position
pCh = pStrEqTok;
}
else
{
StrTrimLeftSpace ( pCh );
StrTrimMoreSpace ( pCh );
}
if ( pCh == NULL )
{
return NULL;
}
uStrEqState = uStrEqState > 2 ? 0 : uStrEqState;
q = strpbrk ( pCh, pDel );
if ( q == NULL )
{ //over , one word
pStrEqTok = NULL;
q = pCh;
}
else
{ //save position
pStrEqTok = q + 1;
*q = CNULL;
}
p = strchr ( pCh, '=' ); //parse word
if ( p == NULL )
{ //simple word exclude '='
if ( pStrEqTok == NULL || uStrEqState == 1 )
{ //miss '='
goto STREQTOK_CLEAN_UP;
}
if ( uStrEqState == 0 || uStrEqState == 2 )
{ //wating expres left or right, recieved
uStrEqState++;
return pCh;
}
}
else
{
if ( uStrEqState == 0 && STR_CHECK_LAST( pCh, '=' ) )
{ //wating expres left , revied left and '='
uStrEqState += 2;
STR_CUT_LAST( pCh );
return pCh;
}
else if ( uStrEqState == 1 && STR_CHECK_FIRST( pCh,'=') )
{ //wating '=' , revied
if ( pCh[1] == CNULL )
{ //just '='
if ( pStrEqTok == NULL )
{
goto STREQTOK_CLEAN_UP;
}
pCh = pStrEqTok;
p = strpbrk ( pCh, pDel );
if ( p == NULL )
{
pStrEqTok = NULL;
p = pCh;
}
else
{
pStrEqTok = p + 1;
*p = CNULL;
}
uStrEqState = 3;
return pCh;
}
else
{ //expres '=' and right
uStrEqState = 3; //all meet
return ++pCh;
}
}
else if ( uStrEqState == 0 )
{ //expres left and '=' and right
if ( pStrEqTok != NULL )
{
*( pStrEqTok - 1 ) = ' ';
}
pStrEqTok = p + 1;
*p = CNULL;
uStrEqState = 2;
return pCh;
}
else
{
goto STREQTOK_CLEAN_UP;
}
}
STREQTOK_CLEAN_UP:
pStrEqTok = NULL;
uStrEqState = 0;
return NULL;
}
/*@end@*/

View File

@@ -0,0 +1,553 @@
//////////////////////////////////////////////////
//Title : linux_sys.c
//Auhtor : Liu Wei
//Desc : Linux system infomation
//Created : 2007-06-02
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_sys.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// InitParalPort:Init parallel port data .
///////////////////////////////////////////////////////////////////////////
extern void InitParalPort(void)
{
ioperm(0x37a,3,1);
ioperm(0x378,3,1);
ioperm(0x379,3,1);
outb(0,0x37a);
outb(0,0x378);
}
///////////////////////////////////////////////////////////////////////////
// Name : WriteParalPort
// Function : Write parallel port data
// Node : Parallel port address:
// : flag=0,address=0x37a B1;flag=1,address=0x37a B2
// : flag=2--9,address=0x378 B0--B7
///////////////////////////////////////////////////////////////////////////
extern void WriteParalPort(u8 uFlag,u8 uData)
{
u8 ii,jj;
if (uFlag > 9)
return;
if (uData != 0 && uData != 1)
return;
if (uFlag == 0 || uFlag == 1) // read or write 0x37a
{
ii = inb(0x37a);
jj = 1 << (uFlag + 1);
ii = ii & (~jj);
if (uFlag == 0)
jj = (~uData & 0x01) << (uFlag + 1);
else
jj = uData << (uFlag + 1);
ii = ii | jj;
outb(ii,0x37a);
}
else
{
ii = inb(0x378);
jj = 1 << (uFlag - 2);
ii = ii & (~jj);
jj = uData << (uFlag - 2);
ii = ii | jj;
outb(ii,0x378);
}
}
///////////////////////////////////////////////////////////////////////////
// GetMemoryStr: Get memery string
//////////////////////////////////////////////////////////////////////////
extern char *GetMemoryStr(u32 Amount)
{
static char Buff[64];
if (Amount > 0) {
(void) snprintf(Buff, sizeof(Buff), "%d", Amount/MBYTES);
return(Buff);
}
return((char *) NULL);
}
///////////////////////////////////////////////////////////////////////////
// GetBootTimeProc: Get System Model using the /proc/cpuinfo file.
///////////////////////////////////////////////////////////////////////////
#define PROC_FILE_UPTIME "/proc/uptime"
extern char *GetBootTimeProc ( )
{
FILE *pFile;
static char sBuff[64];
char *pCh;
char *DateStr;
time_t tmUptime;
time_t tmBootTime;
pFile = fopen ( PROC_FILE_UPTIME, "r" );
if ( !pFile )
{
FLogMsg ( PIF_GERR, "%s: open readonly failed: %s", PROC_FILE_UPTIME,
SYSERR );
return ( ( char * ) NULL );
}
if ( !fgets ( sBuff, sizeof ( sBuff ), pFile ) )
{
FLogMsg ( PIF_GERR, "%s: Read uptime failed: %s", PROC_FILE_UPTIME,
SYSERR );
( void ) fclose ( pFile );
return ( ( char * ) NULL );
}
if ( pCh = strchr ( sBuff, ' ' ) )
{
*pCh = CNULL;
}
tmUptime = ( time_t ) strtol ( sBuff, NULL, 0 );
if ( tmUptime <= 0 )
{
FLogMsg ( PIF_GERR, "Convert `%s' to long failed", sBuff );
( void ) fclose ( pFile );
return ( ( char * ) NULL );
}
tmBootTime = time ( NULL );
tmBootTime -= tmUptime;
DateStr = TimeToStr ( tmBootTime, NULL );
( void ) fclose ( pFile );
return ( DateStr );
}
///////////////////////////////////////////////////////////////////////////
// Get System Model using the /proc/cpuinfo file.
///////////////////////////////////////////////////////////////////////////
#define PROC_FILE_CPUINFO "/proc/cpuinfo"
/*
extern char *GetModelProc ( )
{
FILE *pFile;
static char sBuff[256];
char *Cpu = NULL;
char *Vendor = NULL;
char *Model = NULL;
char Speed[64];
float sp = 0;
char **Argv;
int Argc;
int Cleanup;
if ( sBuff[0] )
{
return ( sBuff );
}
pFile = fopen ( PROC_FILE_CPUINFO, "r" );
if ( !pFile )
{
FLogMsg ( PIF_GERR, "%s: open readonly failed: %s", PROC_FILE_CPUINFO,
SYSERR );
return ( ( char * ) NULL );
}
Speed[0] = CNULL;
while ( fgets ( sBuff, sizeof ( sBuff ), pFile ) )
{
Cleanup = TRUE;
Argc = StrToArgv ( sBuff, ":", &Argv, NULL, 0 );
if ( Argc < 2 )
{
continue;
}
if ( EQ ( Argv[0], "cpu" ) )
{
Cpu = Argv[1];
}
else if ( EQ ( Argv[0], "vendor_id" ) )
{
Vendor = Argv[1];
}
else if ( EQ ( Argv[0], "model name" ) )
{
Model = Argv[1];
}
else if ( EQ ( Argv[0], "cpu MHz" ) )
{
// This value is not always perfectly accurate as Linux estimates
// the actual Mhz by doing a loop test at boot.
if ( sscanf ( Argv[1], "%f", &sp ) )
{
( void ) sprintf ( Speed, "%.0f Mhz", rint ( ( double ) sp ) );
}
}
else
{
DestroyArgv ( &Argv, Argc );
Cleanup = FALSE;
}
if ( Cleanup )
{
( void ) free ( Argv[0] );
}
}
sBuff[0] = CNULL;
if ( Vendor )
{
( void ) strcpy ( sBuff, Vendor );
( void ) free ( Vendor );
}
if ( Speed[0] )
{
if ( sBuff[0] )
{
( void ) strcat ( sBuff, " " );
}
( void ) strcat ( sBuff, Speed );
}
if ( Model )
{
if ( sBuff[0] )
{
strcat ( sBuff, " " );
}
strcat ( sBuff, Model );
( void ) free ( Model );
}
if ( Cpu )
{
if ( sBuff[0] )
{
strcat ( sBuff, " " );
}
strcat ( sBuff, Cpu );
( void ) free ( Cpu );
}
( void ) fclose ( pFile );
return ( sBuff );
}
*/
///////////////////////////////////////////////////////////////////////////
// GetMBytesStr: Get the string of Mbytes
///////////////////////////////////////////////////////////////////////////
extern char *GetMBytesStr ( u32 wAmount )
{
static char sBuff[64];
if ( !wAmount )
{
return ( ( char * ) NULL );
}
if ( wAmount > KBYTES )
{
( void ) snprintf ( sBuff, sizeof ( sBuff ), "%.1f GB",
( float ) MbytesToGbytes ( wAmount ) );
}
else
{
( void ) snprintf ( sBuff, sizeof ( sBuff ), "%.0f MB",
( float ) wAmount );
}
}
///////////////////////////////////////////////////////////////////////////
// GetMemoryKcore: Get System Memory using size of /proc/kcore
///////////////////////////////////////////////////////////////////////////
#define PROC_FILE_KCORE "/proc/kcore"
extern char *GetMemoryKcore ( )
{
static char *pMemStr = NULL;
u32 wMemBytes = 0;
u32 wAmount = 0;
struct stat tStatBuf;
if ( pMemStr )
{
return ( pMemStr );
}
if ( stat ( PROC_FILE_KCORE, &tStatBuf ) != 0 )
{
FLogMsg ( PIF_GERR, "%s: stat failed: %s", PROC_FILE_KCORE, SYSERR );
return ( ( char * ) NULL );
}
wMemBytes = ( u32 ) ( tStatBuf.st_size - 4096 );
wAmount = DivRndUp( wMemBytes, ( u32 ) MBYTES );
pMemStr = GetMBytesStr ( wAmount );
return ( pMemStr );
}
///////////////////////////////////////////////////////////////////////////
// GetMemorySysinfo: Get System Memory using sysinfo() system call
///////////////////////////////////////////////////////////////////////////
extern char *GetMemorySysinfo ( )
{
struct sysinfo tSysInfo;
static char *pMemStr = NULL;
u32 wMemBytes = 0;
u32 wAmount = 0;
if ( pMemStr )
{
return ( pMemStr );
}
if ( sysinfo ( &tSysInfo ) != 0 )
{
FLogMsg ( PIF_GERR, "sysinfo() system call failed: %s", SYSERR );
return ( ( char * ) NULL );
}
// sysinfo.totalram represents total USABLE physical memory. Memory
// reserved by the kernel is not included. So this is as close as we
// can get for now.
wMemBytes = ( u32 ) tSysInfo.totalram;
wAmount = DivRndUp( wMemBytes, ( u32 ) MBYTES );
pMemStr = GetMemoryStr ( wAmount );
return ( pMemStr );
}
///////////////////////////////////////////////////////////////////////////
// GetVirtMemLinux:Get Virtual Memory using sysinfo() system call
///////////////////////////////////////////////////////////////////////////
extern char *GetVirtMemLinux ( )
{
struct sysinfo tSysInfo;
static char *pMemStr = NULL;
u32 wMemBytes = 0;
u32 wAmount = 0;
if ( pMemStr )
{
return ( pMemStr );
}
if ( sysinfo ( &tSysInfo ) != 0 )
{
FLogMsg ( PIF_GERR, "sysinfo() system call failed: %s", SYSERR );
return ( ( char * ) NULL );
}
wMemBytes = ( u32 ) ( tSysInfo.totalram + tSysInfo.totalswap );
wAmount = DivRndUp( wMemBytes, ( u32 ) MBYTES );
pMemStr = GetMemoryStr ( wAmount );
return ( pMemStr );
}
///////////////////////////////////////////////////////////////////////////
// GetCpuTypeProc:Get CPU Type from /proc/cpuinfo
///////////////////////////////////////////////////////////////////////////
#define PROC_FILE_CPUINFO "/proc/cpuinfo"
/*
extern char *GetCpuTypeProc ( )
{
FILE *pFile;
static char sBuff[256];
static char *Cpu = NULL;
char **Argv;
char *pCh;
int Argc;
if ( Cpu )
{
return ( Cpu );
}
pFile = fopen ( PROC_FILE_CPUINFO, "r" );
if ( !pFile )
{
FLogMsg ( PIF_GERR, "%s: open readonly failed: %s", PROC_FILE_CPUINFO,
SYSERR );
return ( ( char * ) NULL );
}
while ( fgets ( sBuff, sizeof ( sBuff ), pFile ) )
{
Argc = StrToArgv ( sBuff, ":", &Argv, NULL, 0 );
if ( Argc < 2 )
{
continue;
}
if ( EQ ( Argv[0], "cpu" ) )
{
// Linux 2.0
Cpu = Argv[1];
break;
}
else if ( EQ ( Argv[0], "model name" ) )
{
// Linux 2.2
Cpu = Argv[1];
if ( pCh = strchr ( Cpu, ' ' ) )
{
*pCh = CNULL;
}
break;
}
}
( void ) fclose ( pFile );
return ( Cpu );
}
*/
///////////////////////////////////////////////////////////////////////////
// GetKernVerProc: Get Kernel Version string using /proc/version
///////////////////////////////////////////////////////////////////////////
#define PROC_FILE_VERSION "/proc/version"
extern char *GetKernVerProc ( )
{
FILE *pFile;
static char sBuff[512];
if ( sBuff[0] )
{
return ( sBuff );
}
pFile = fopen ( PROC_FILE_VERSION, "r" );
if ( !pFile )
{
FLogMsg ( PIF_GERR, "%s: open readonly failed: %s", PROC_FILE_VERSION,
SYSERR );
return ( ( char * ) NULL );
}
if ( !fgets ( sBuff, sizeof ( sBuff ), pFile ) )
{
FLogMsg ( PIF_GERR, "%s: read failed: %s", PROC_FILE_VERSION, SYSERR );
return ( ( char * ) NULL );
}
( void ) fclose ( pFile );
return ( sBuff );
}
///////////////////////////////////////////////////////////////////////////
// GetKernVerLinux: Get Kernel Version string using uname()
///////////////////////////////////////////////////////////////////////////
extern char *GetKernVerLinux ( )
{
static struct utsname tName;
static char *pVerStr = NULL;
if ( uname ( &tName ) != 0 )
{
FLogMsg ( PIF_GERR, "uname() system call failed: %s", SYSERR );
return ( ( char * ) NULL );
}
pVerStr = tName.version;
return ( pVerStr );
}
///////////////////////////////////////////////////////////////////////////
// GetOSDistLinux: Get linux distribution (vendor)
///////////////////////////////////////////////////////////////////////////
/*
extern char *GetOSDistLinux ( )
{
static char sBuff[256];
register char *pCh;
register char *End;
char IssueFile[] = "/etc/issue";
char Welcome[] = "Welcome to ";
FILE *pFile;
int Found = FALSE;
if ( !( pFile = fopen ( IssueFile, "r" ) ) )
{
FLogMsg ( PIF_GERR, "%s: Cannot open to get OS Dist: %s", IssueFile,
SYSERR );
return ( ( char * ) NULL );
}
while ( fgets ( sBuff, sizeof ( sBuff ), pFile ) )
{
// Some distributions have VGA control chars in them
if ( !isalpha ( sBuff[0] ) )
{
continue;
}
for ( pCh = sBuff; pCh && *pCh && *pCh != '\n' && !isalpha ( *pCh );
++pCh )
;
if ( *pCh == '\n' || !strlen ( pCh ) )
{
continue;
}
// Found first nonblank line
Found = TRUE;
break;
}
( void ) fclose ( pFile );
if ( !Found )
{
return ( ( char * ) NULL );
}
if ( EQN ( pCh, Welcome, sizeof ( Welcome ) - 1 ) )
{
pCh += sizeof ( Welcome ) - 1;
}
else if ( EQN ( pCh, "Linux ", 6 ) )
{
pCh += 6;
}
if ( End = strchr ( pCh, '-' ) )
{
--End;
while ( *End && isspace ( *End ) )
{
--End;
}
*++End = CNULL;
}
return ( pCh );
}
/*@end@*/

View File

@@ -0,0 +1,130 @@
//////////////////////////////////////////////////
//Title : pub_time.c
//Auhtor : Liu Wei
//Desc : Linux time function
//Created : 2007-06-02
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_time.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// Name : GetTickCount
// Function: return the ms value of the time
// Note :
///////////////////////////////////////////////////////////////////////////
extern long GetTickCount()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
///////////////////////////////////////////////////////////////////////////
// Name : GetCurrentTime
// Function: get current system time(BcdFormate)
// Note : now_time's length is 6: year,month,day,hour,minute,second
// Return : 1 successful 0 fail
///////////////////////////////////////////////////////////////////////////
extern int GetCurrentTime( u8 *pNowTime )
{
struct tm *pTMNowTime;
time_t tTemptime;
tTemptime = time(NULL);
pTMNowTime = localtime(&tTemptime);
if( pTMNowTime == NULL )
return 0;
pNowTime[0] = pTMNowTime->tm_year-100;
pNowTime[1] = pTMNowTime->tm_mon+1;
pNowTime[2] = pTMNowTime->tm_mday;
pNowTime[3] = pTMNowTime->tm_hour;
pNowTime[4] = pTMNowTime->tm_min;
pNowTime[5] = pTMNowTime->tm_sec;
return 1;
}
///////////////////////////////////////////////////////////////////////////
// Name : GetCurrentTime
// Function: get current system time in ASCII format
// Note :
///////////////////////////////////////////////////////////////////////////
extern char *GetAsciiTime()
{
char *pAscTime;
time_t tCurTime;
tCurTime = time(NULL);
pAscTime = ctime(&tCurTime);
return (char *)pAscTime;
}
char *TimeToStr ( time_t TimeVal, char *Format )
{
struct tm *tm;
static char sBuff[128];
char *String;
char *pCh;
char *Fmt;
if ( Format != NULL)
{
Fmt = Format;
}
else
{
//Use %H instead of %k as %H is more portable
Fmt = "%a %b %e %H:%M:%S %Y %Z";
}
tm = localtime ( &TimeVal );
if ( NULL != tm )
{
String = asctime ( tm );
if ( NULL != String )
{
pCh = strchr ( String, '\n' );
if ( NULL != pCh )
{
*pCh = CNULL;
}
return String;
}
}
FLogMsg ( PIF_DBG, "TimeToStr() failed - No conversion func defined?" );
return ( char * ) NULL;
}
///////////////////////////////////////////////////////////////////////////
// Name : GetTimeHMS
// Function: get current system time string of hour mininute and second
// Note :
///////////////////////////////////////////////////////////////////////////
extern char *GetTimeHMS(char *pTimeBuf)
{
struct tm *pTM,tTM;
long lCurTime;
pTM = &tTM;
lCurTime = time((long *)0);
pTM = localtime(&lCurTime);
sprintf(pTimeBuf,"%02d:%02d:%02d",pTM->tm_hour,pTM->tm_min,pTM->tm_sec);
pTimeBuf[8] = CNULL;
return pTimeBuf;
}
/*@end@*/

View File

@@ -0,0 +1,176 @@
//////////////////////////////////////////////////
//Title : wxc_timer.c
//Auhtor : Liu Wei
//Desc : WXC2 Public Timer Managemnet
//Created : 2007-04-27
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_timer.h"
/*@ignore@*/
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
extern void TimerAdd ( WxcTimer * pTimer )
{
WxcTimerNode *pTNode;
assert ( NULL != pTimer && NULL != pTimer->pFunc );
assert ( pTimer->dExpires && pTimer->dSuitNumber < TM_CLOCK_MAX );
//pTimer->dSuitNumber = ? : 1;
pTNode =
( WxcTimerNode * ) WxcMalloc ( GET_TNODE_SIZE ( pTimer->dSuitNumber ) );
if( NULL == pTNode )
{
return ;
}
pTNode->pNext = NULL;
pTNode->pPrev = pTLCur;
pTNode->pTimer = ( WxcTimer * ) ( pTNode + 4 * sizeof ( void * ) );
pTimer->pTimerNode = ( void * ) pTNode;
memcpy ( pTNode->pTimer, pTimer, sizeof ( WxcTimer ) );
pTNode->dClockArray = ( u32 * ) ( pTNode->pTimer + sizeof ( WxcTimer ) );
pTLCur = pTNode;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
inline void TimerStart ( WxcTimer * pTimer, u16 dSuitId )
{
assert ( pTimer && pTimer->pTimerNode );
assert ( dSuitId < pTimer->dSuitNumber );
( ( WxcTimerNode * ) pTimer->pTimerNode )->dClockArray[dSuitId] = 1;
}
extern void TimerMod ( WxcTimer * pTimer, u16 dExpires )
{
int i;
assert ( NULL != pTimer && dExpires );
pTimer->dExpires = dExpires;
for ( i = 0; i < pTimer->dSuitNumber; i++ )
{
TimerStart ( pTimer, i );
}
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
extern void TimerDel ( WxcTimer * pTimer )
{
assert ( pTimer && pTimer->pTimerNode );
WxcFree ( pTimer->pTimerNode );
pTimer->pTimerNode = NULL;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
extern inline void TimerStop ( WxcTimer * pTimer, u16 dSuitId )
{
assert ( NULL != pTimer && dSuitId < pTimer->dSuitNumber );
( ( WxcTimerNode * ) pTimer->pTimerNode )->dClockArray[dSuitId] = 0;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
#define TimerRestart(pTimer) TimerStart(pTimer)
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
static void *TM_Alloc ( u16 dSize )
{
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
static void TM_Free ( void *p )
{
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
static inline int TM_Pending ( WxcTimerNode * pTNode, u16 dSuitId )
{
return ( pTNode->dClockArray[dSuitId] ? 1 : 0 );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
static inline int TM_Expiring ( WxcTimerNode * pTNode, u16 dSuitId )
{
return ( TimerAfter
( pTNode->dClockArray[dSuitId], pTNode->pTimer->dExpires ) );
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
extern inline void TM_Init ( )
{
pTLCur = pTLHead = &tTimerListHead;
}
///////////////////////////////////////////////////////////////////////////
// ///
///////////////////////////////////////////////////////////////////////////
extern void TM_RT ( )
{
u16 sid;
WxcTimer *pTimer;
WxcTimerNode *pTNode;
pTNode = pTLHead;
for ( ; NULL != pTNode; pTNode = pTNode->pNext )
{
pTimer = pTNode->pTimer;
for ( sid = 0; sid <= pTimer->dSuitNumber; sid++ )
{
if ( !TM_Pending ( pTNode, sid ) )
{
pTNode->dClockArray[sid]++;
if ( TM_Expiring ( pTNode, sid ) )
{
pTimer->pFunc ( pTimer->dData, sid );
}
}
}
}
}
/*@end@*/

View File

@@ -0,0 +1,425 @@
//////////////////////////////////////////////////
//Title : wxc_netfunc.c
//Auhtor : Liu Wei
//Desc : wxc2 network convert function
//Created : 2007-06-20
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "./include/pub_wnet.h"
u8 GetBcdStr ( char *str, u8 * bcd, u8 bcd_len )
{
u8 ii = 0;
Bcd2Str ( str, bcd, bcd_len * 2 );
for ( ii = 0; ii < bcd_len * 2; ii++ )
{
if( str[ii] == 'e' || str[ii] == 'E' )
break;
}
str[ii] = '\0';
return ii;
}
///////////////////////////////////////////////////////////////////////////
// Name : ImsiNToA
// Function: transfer IMSI format from normal to anti sequence
// Note : 0460022157127001 --> 64002251177200f1
//////////////////////////////////////////////////////////////////////////
void ImsiNtoA( u8 *pAntiImsi , u8 *pNormalImsi )
{
u8 ii;
u8 aa, bb = 0;
for ( ii = 1; ii <= IMSI_LEN * 2; ii++ )
{
if ( ( ii % 2 ) == 1 )
{
bb = pNormalImsi[ii / 2] & 0x0f;
}
else
{
aa = (ii == IMSI_LEN * 2) ? 0x0f0 : (pNormalImsi[ii / 2] & 0x0f0);
pAntiImsi[ii / 2 - 1] = aa | bb;
}
}
}
///////////////////////////////////////////////////////////////////////////
// Name : ImsiAToN
// Function: transfer IMSI format from anti to normal sequence
// Note : 64002251177200f1 --> 0460022157127001
//////////////////////////////////////////////////////////////////////////
void ImsiAToN ( u8 * pNormalImsi, u8 * pAntiImsi )
{ // the IMSI must 15 digits
u8 ii;
u8 aa, bb = 0;
pNormalImsi[0] = 0;
for ( ii = 0; ii < IMSI_LEN * 2; ii++ )
{
if ( ( ii % 2 ) == 1 )
{
aa = pAntiImsi[ii / 2] & 0x0f;
pNormalImsi[ii / 2] |= aa;
}
else
{
if ( ii / 2 != IMSI_LEN - 1 )
{
bb = pAntiImsi[ii / 2] & 0x0f0;
pNormalImsi[ii / 2 + 1] = bb;
}
}
}
}
///////////////////////////////////////////////////////////////////////////
// Name : ImsiNToS
// Function: transfer IMSI format from normal to ascii string
// Note : 0460022157127001 --> "460022157127001"
///////////////////////////////////////////////////////////////////////////
void ImsiNToS ( u8 * pImsiStr, u8 * pNormalImsi )
{
u8 len;
u8 ii, jj;
pImsiStr[0] = ( pNormalImsi[0] & 0x0f ) + '0';
len = 1;
for ( ii = 1; ii < IMSI_LEN; ii++ )
{
jj = ( pNormalImsi[ii] >> 4 ) & 0x0f;
pImsiStr[len++] = jj + '0';
jj = pNormalImsi[ii] & 0x0f;
pImsiStr[len++] = jj + '0';
}
pImsiStr[len] = '\0';
}
///////////////////////////////////////////////////////////////////////////
// Name : ImsiSToN
// Function: transfer IMSI format from ascii string to normal
// Note : "460022157127001" --> 0460022157127001
///////////////////////////////////////////////////////////////////////////
void ImsiSToN ( u8 * pNormalImsi, u8 * pImsiStr )
{
if ( strlen ( pImsiStr ) != IMSI_LEN * 2 - 1 )
return;
pNormalImsi[0] = pImsiStr[0] - '0';
Str2Bcd ( pNormalImsi + 1, pImsiStr + 1, IMSI_LEN * 2 - 2 );
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnNToA
// Function: transfer ISDN format from normal to anti sequence
// Note : 918675557127001EEE --> 08916857551700E1
///////////////////////////////////////////////////////////////////////////
void IsdnNToA ( u8 * pAntiIsdn, u8 * pNormalIsdn )
{
u8 ii;
u8 aa = 0, bb = 0;
u8 len;
// nature of address and numbering plan indicator
pAntiIsdn[1] = pNormalIsdn[0];
len = 1;
for ( ii = 1; ii < ISDN_LEN; ii++ )
{
if ( pNormalIsdn[ii] == 0xee )
{
break;
}
else
{
aa = ( pNormalIsdn[ii] & 0x0f0 ) >> 4;
bb = pNormalIsdn[ii] & 0x0f;
if ( bb > 0x0c )
{
bb = 0x0f;
}
pAntiIsdn[ii + 1] = ( bb << 4 ) + aa;
len++;
}
}
pAntiIsdn[0] = len;
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnAToN
// Function: transfer ISDN format from anti to normal sequence
// Note : 08916857551700E1 --> 918675557127001EEE
///////////////////////////////////////////////////////////////////////////
void IsdnAToN ( u8 * pNormalIsdn, u8 * pAntiIsdn )
{
u8 ii;
u8 aa = 0, bb = 0;
u8 uIsdnLen;
uIsdnLen = pAntiIsdn[0];
if ( uIsdnLen > ISDN_LEN )
uIsdnLen = ISDN_LEN;
pNormalIsdn[0] = pAntiIsdn[1];
for ( ii = 1; ii < uIsdnLen; ii++ )
{
if ( ( pAntiIsdn[ii + 1] & 0x0f ) >= 0x0e )
break;
aa = ( pAntiIsdn[ii + 1] & 0x0f0 ) >> 4;
if ( aa > 0x0c )
aa = 0x0e;
bb = pAntiIsdn[ii + 1] & 0x0f;
pNormalIsdn[ii] = ( bb << 4 ) + aa;
}
for ( ; ii < ISDN_LEN; ii++ )
pNormalIsdn[ii] = 0x0ee;
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnNToS
// Function: transfer ISDN format from normal to ascii string
// Note : 918675557127001EEE --> "8675557127001"
///////////////////////////////////////////////////////////////////////////
void IsdnNToS ( u8 * pIsdnStr, u8 * pNormalIsdn )
{
u8 len = 0;
u8 ii, jj;
for ( ii = 1; ii < ISDN_LEN; ii++ )
{
jj = ( pNormalIsdn[ii] >> 4 ) & 0x0f;
if ( jj > 0x0c )
break;
pIsdnStr[len++] = jj + '0';
jj = pNormalIsdn[ii] & 0x0f;
if ( jj > 0x0c )
break;
pIsdnStr[len++] = jj + '0';
}
pIsdnStr[len] = '\0';
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnAToS
// Function: transfer ISDN format from anti to ascii string
// Note : 08916857551700E1 --> "8675557127001"
///////////////////////////////////////////////////////////////////////////
void IsdnAToS ( u8 * pAntiIsdn, u8 * pIsdnStr )
{
u8 ii;
u8 aa = 0, bb = 0;
u8 len = 0;
u8 uIsdnLen;
uIsdnLen = pAntiIsdn[0];
if ( uIsdnLen > ISDN_LEN )
uIsdnLen = ISDN_LEN;
for ( ii = 1; ii < uIsdnLen; ii++ )
{
if ((bb = ( pAntiIsdn[ii + 1] & 0x0f )) >= 0x0c)
break;
pIsdnStr[len++] = bb + '0';
if ((aa = ( pAntiIsdn[ii + 1] & 0x0f0 ) >> 4) >= 0x0c)
break;
pIsdnStr[len++] = aa + '0';
}
pIsdnStr[len] = '\0';
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnSToN
// Function: transfer ISDN format from ascii string to normal
// Note : "8675557127001" --> 918675557127001EEE
// Return : 0--string has error; 1--success
///////////////////////////////////////////////////////////////////////////
u8 IsdnSToN ( u8 * pNormalIsdn, u8 * pIsdnStr )
{
u8 ii;
u8 len;
len = strlen ( pIsdnStr );
if ( len > ISDN_LEN * 2 - 2 )
return 0;
if ( ( len % 2 ) == 1 ) // odd number
{
Str2Bcd ( pNormalIsdn + 1, pIsdnStr, len - 1 );
ii = len / 2 + 1;
pNormalIsdn[ii] = ( pIsdnStr[len - 1] - '0' ) << 4;
pNormalIsdn[ii] |= 0x0E;
}
else
{
Str2Bcd ( pNormalIsdn + 1, pIsdnStr, len );
ii = len / 2;
}
memset ( pNormalIsdn + ii + 1, 0xEE, ISDN_LEN - ii - 1 );
pNormalIsdn[0] = 0x91; // default value
return 1;
}
///////////////////////////////////////////////////////////////////////////
// Name : GttToIsdn
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
void GttToIsdn ( u8 *pIsdn, u8 *pGtt )
{
u8 ii, jj;
pIsdn[0] = 0x91;
for ( ii = 1; ii < ISDN_LEN; ii++ )
{
jj = pGtt[ii - 1] & 0x0f;
if ( jj > 0x0c )
break;
pIsdn[ii] = jj << 4;
jj = ( pGtt[ii - 1] & 0xf0 ) >> 4;
if ( jj > 0x0c )
jj = 0x0e;
pIsdn[ii] |= jj;
if ( jj == 0x0e )
{
ii++;
break;
}
}
for ( ; ii < ISDN_LEN; ii++ )
pIsdn[ii] = 0xee;
}
///////////////////////////////////////////////////////////////////////////
// Name : IsdnToGtai
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
u8 IsdnToGtai ( u8 * pGtai, u8 * pIsdn )
{
u8 tmpBuf[32];
u8 ii;
u8 len;
IsdnNToA ( tmpBuf, pIsdn );
ii = tmpBuf[0];
memcpy ( pGtai, tmpBuf + 2, ii - 1 );
if ( ( tmpBuf[ii] & 0x0f0 ) == 0x0f0 )
len = ii * 2 - 3;
else
len = ii * 2 - 2;
return len;
}
///////////////////////////////////////////////////////////////////////////
// Name : GtaiToIsdn
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
void GtaiToIsdn ( u8 * pIsdn, u8 * pGtai, u8 len )
{
u8 tmpBuf[32];
tmpBuf[0] = ( len + 1 ) / 2;
tmpBuf[1] = 0x91;
memcpy ( tmpBuf + 2, pGtai, tmpBuf[0]++ );
IsdnAToN ( pIsdn, tmpBuf );
}
///////////////////////////////////////////////////////////////////////////
// Name : BcdToStrPE
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
u8 BcdToStrPE ( char *str, u8 * bcd, u8 bcd_len )
{
u8 ii = 0;
Bcd2Str ( str, bcd, bcd_len * 2 );
for ( ii = 0; ii < bcd_len * 2; ii++ )
{
if ( str[ii] == 'e' || str[ii] == 'E' )
break;
}
str[ii] = '\0';
return ii;
}
///////////////////////////////////////////////////////////////////////////
// Name : AddCcToIsdn
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
void AddCcToIsdn ( u8 * isdn_str, u8 * cc )
{
char str1[32], str2[32];
u8 len, len1, len2;
len1 = BcdToStrPE ( str1, isdn_str + 1, ISDN_LEN - 1 );
len2 = BcdToStrPE ( str2, cc, 2 );
memcpy ( str2 + len2, str1, len1 );
len = len1 + len2;
if ( ( len % 2 ) != 0 )
str2[len++] = 'E';
str2[len] = '\0';
Str2Bcd ( isdn_str + 1, str2, len );
isdn_str[0] = 0x91;
}
///////////////////////////////////////////////////////////////////////////
// Name : AddNdcToIsdn
// Function:
// Note :
///////////////////////////////////////////////////////////////////////////
void AddNdcToIsdn ( u8 * isdn_str, u8 * ndc )
{
char str1[32], str2[32];
u8 len, len1, len2;
len1 = GetBcdStr ( str1, isdn_str + 1, ISDN_LEN - 1 );
len2 = GetBcdStr ( str2, ndc, 3 ); //6 digit ndc
memcpy ( str2 + len2, str1, len1 );
len = len1 + len2;
if ( ( len % 2 ) != 0 )
str2[len++] = 'E';
Str2Bcd ( isdn_str + 1, str2, len );
isdn_str[0] = 0xa1;
}
void BcdToAsciiR(char *ascii_buf, const unsigned char *bcd_buf, int len)
{
char ch;
int i;
for(i=0;i<len;i++)
{
sprintf(&ascii_buf[i*2],"%02X",bcd_buf[i]);
ch = ascii_buf[i*2];
ascii_buf[i*2] = ascii_buf[i*2+1];
ascii_buf[i*2+1] = ch;
}
}

View File

@@ -0,0 +1,362 @@
/*
* public/uwav/number.c
*
* Copyright (C) 2008 ADC, Inc
* Written by: Xinyu Yan <xinyu.yan@adc.com>
*
*/
#include "./number.h"
/*
ITU:
0-spare
1-subscriber
2-unknown
3-NDD
4-IDD
GSM 09.02:
-- bits 765: nature of address indicator
-- 000 unknown
-- 001 international number
-- 010 national significant number
-- 011 network specific number
-- 100 subscriber number
-- 101 reserved
-- 110 abbreviated number
-- 111 reserved for extension
*/
static const u8 NAI_GSM2ITU[8] = {0x02, 0x04, 0x03, 0x03, 0x01, 0x02, 0x02, 0x02};
static const u8 NAI_ITU2GSM[8] = {0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00};
u8 nai_gsm_to_itu(u8 nai)
{
return NAI_GSM2ITU[nai & 0x07];
}
u8 nai_itu_to_gsm(u8 nai)
{
return NAI_ITU2GSM[nai & 0x07];
}
u8 *msc_isdn_to_bcd(u8 *bcd, const isdn_t *isdn)
{
int i;
const num32_t *num = &isdn->num;
u8 *bcdptr;
bcd[0] = (num->num_of_digit+1)/2 + 1;
bcd[1] = 0x81 | (nai_itu_to_gsm(isdn->nai) << 4);
bcdptr = bcd + 2;
for(i = 0; ((i < 32) && (i < num->num_of_digit)); i++)
{
if((i & 1) == 0)
*bcdptr = (num->digit[i] << 4) | 0x0f;
else
{
*bcdptr = (*bcdptr & 0xf0) + num->digit[i];
bcdptr++;
}
}
return bcd;
}
isdn_t *netbcd_to_isdn(isdn_t *isdn, const u8 *bcd)
{
u8 bcd_digits;
u8 digit;
num32_t *num = &isdn->num;
if(bcd[0] < 1)
{
num->num_of_digit = 0;
return isdn;
}
bcd_digits = (bcd[0]-1) * 2;
isdn->nai = nai_gsm_to_itu((bcd[1] >> 4) & 0x07);
bcd += 2;
for(num->num_of_digit = 0; (num->num_of_digit<32)&&(num->num_of_digit<bcd_digits); num->num_of_digit++)
{
if((num->num_of_digit & 1) == 0)
digit = *bcd & 0x0f;
else
digit = *(bcd++) >> 4;
if(is_dail_digit(digit))
num->digit[num->num_of_digit] = digit;
else
break;
}
return isdn;
}
u8 *isdn_to_netbcd(u8 *bcd, const isdn_t *isdn)
{
int i;
const num32_t *num = &isdn->num;
u8 *bcdptr;
bcd[0] = (num->num_of_digit+1)/2 + 1;
bcd[1] = 0x81 | (nai_itu_to_gsm(isdn->nai) << 4);
bcdptr = bcd + 2;
for(i = 0; ((i < 32) && (i < num->num_of_digit)); i++)
{
if((i & 1) == 0)
*bcdptr = 0xf0 + (num->digit[i] & 0x0f);
else
{
*bcdptr = (num->digit[i] << 4) | (*bcdptr & 0x0f);
bcdptr++;
}
}
return bcd;
}
/* TBCD: Telephony Binary Coded Decimal (GSM 09.02) */
int tbcd_to_string(char *str, const u8 *tbcd, u8 tbcd_len)
{
int i;
u8 max_digits;
u8 digit;
max_digits = tbcd_len * 2;
for(i = 0; i < max_digits; i++)
{
if((i & 1) == 0)
digit = *tbcd & 0x0f;
else
digit = *(tbcd++) >> 4;
if(is_dail_digit(digit))
digit_to_char(str[i], digit);
else
break;
}
str[i] = 0;
return i;
}
isdn_t *tpaddr_to_isdn(isdn_t *isdn, const u8 *tpaddr)
{
u8 bcd_digits;
u8 digit;
num32_t *num = &isdn->num;
bcd_digits = tpaddr[0];
isdn->nai = nai_gsm_to_itu((tpaddr[1] >> 4) & 0x07);
tpaddr += 2;
for(num->num_of_digit = 0; (num->num_of_digit<32)&&(num->num_of_digit<bcd_digits); num->num_of_digit++)
{
if((num->num_of_digit & 1) == 0)
digit = *tpaddr & 0x0f;
else
digit = *(tpaddr++) >> 4;
if(is_dail_digit(digit))
num->digit[num->num_of_digit] = digit;
else
break;
}
return isdn;
}
int string_to_num32(num32_t *num, const char *str)
{
u8 digit;
for(num->num_of_digit = 0; num->num_of_digit < 32; num->num_of_digit++, str++)
{
if((*str >= '0') && (*str <= '9'))
digit = *str - '0';
else if(*str == '*')
digit = 0x0b;
else if(*str == '#')
digit = 0x0c;
else
break;
num->digit[num->num_of_digit] = digit;
}
return num->num_of_digit;
}
int num32_to_string(char *str, const num32_t *num)
{
int i;
for(i = 0; ((i < 32) && (i < num->num_of_digit)); i++)
{
if(num->digit[i] <= 9)
str[i] = num->digit[i] + '0';
else if(num->digit[i] == 0x0b)
str[i] = '*';
else if(num->digit[i] == 0x0c)
str[i] = '#';
}
str[i] = 0;
return i;
}
int string_to_num16(num16_t *num, const char *str)
{
u8 digit;
for(num->num_of_digit = 0; num->num_of_digit < 16; num->num_of_digit++, str++)
{
if((*str >= '0') && (*str <= '9'))
digit = *str - '0';
else if(*str == '*')
digit = 0x0b;
else if(*str == '#')
digit = 0x0c;
else
break;
num->digit[num->num_of_digit] = digit;
}
return num->num_of_digit;
}
int num16_to_string(char *str, const num16_t *num)
{
int i;
for(i = 0; ((i < 16) && (i < num->num_of_digit)); i++)
{
if(num->digit[i] <= 9)
str[i] = num->digit[i] + '0';
else if(num->digit[i] == 0x0b)
str[i] = '*';
else if(num->digit[i] == 0x0c)
str[i] = '#';
}
str[i] = 0;
return i;
}
int string_to_num8(num8_t *num, const char *str)
{
u8 digit;
for(num->num_of_digit = 0; num->num_of_digit < 8; num->num_of_digit++, str++)
{
if((*str >= '0') && (*str <= '9'))
digit = *str - '0';
else if(*str == '*')
digit = 0x0b;
else if(*str == '#')
digit = 0x0c;
else
break;
num->digit[num->num_of_digit] = digit;
}
return num->num_of_digit;
}
int num8_to_string(char *str, const num8_t *num)
{
int i;
for(i = 0; ((i < 8) && (i < num->num_of_digit)); i++)
{
if(num->digit[i] <= 9)
str[i] = num->digit[i] + '0';
else if(num->digit[i] == 0x0b)
str[i] = '*';
else if(num->digit[i] == 0x0c)
str[i] = '#';
}
str[i] = 0;
return i;
}
int digit_to_netbcd(u8 *netbcd, u8 *digit, u8 max_digit)
{
int i;
for(i = 0; i < max_digit; i++)
{
if((i & 1) == 0)
*netbcd = 0xf0 + (digit[i] & 0x0f);
else
{
*netbcd = (digit[i] << 4) | (*netbcd & 0x0f);
netbcd++;
}
}
return (max_digit+1)/2;
}
int netbcd_to_digit(u8 *digit, u8 *netbcd, u8 max_digit)
{
int i;
u8 d;
for(i = 0; i < max_digit; i++)
{
if((i & 1) == 0)
d = *netbcd & 0x0f;
else
d = *(netbcd++) >> 4;
if(d != 0x0f)
digit[i] = d;
else
break;
}
return i;
}
void msc_save_lai(u8 *lai, u8 *mcc, u8 *mnc, int lac)
{
lai[0] = (mcc[1] << 4) + (mcc[0] & 0x0f);
lai[1] = (mnc[2] << 4) | mcc[2];
lai[2] = (mnc[1] << 4) + (mnc[0] & 0x0f);
lai[3] = lac >> 8;
lai[4] = lac;
}
void msc_load_lai(u8 *mcc, u8 *mnc, int *lac, u8 *lai)
{
mcc[0] = lai[0] & 0x0f;
mcc[1] = lai[0] >> 4;
mcc[2] = lai[1] & 0x0f;
mnc[0] = lai[2] & 0x0f;
mnc[1] = lai[2] >> 4;
mnc[2] = lai[1] >> 4;
*lac = (lai[3] << 8) + lai[4];
}
#if 0
/* return the digit counts of number */
static int bcd_to_num16(num16_t *num, const u8 *bcd)
{
u8 digit;
for(num->num_of_digit = 0; num->num_of_digit < 16; num->num_of_digit++)
{
if((num->num_of_digit & 1) == 0)
digit = *bcd >> 4;
else
digit = *(bcd++) & 0x0f;
if(is_dail_digit(digit))
num->digit[num->num_of_digit] = digit;
else
break;
}
return num->num_of_digit ;
}
/* return the length of bcd */
static int num16_to_bcd(u8 *bcd, const num16_t *num)
{
int i;
for(i = 0; ((i < 16) && (i < num->num_of_digit)); i++)
{
if((i & 1) == 0)
*bcd = (num->digit[i] << 4) | 0x0f;
else
*(bcd++) = (*bcd & 0xf0) + num->digit[i];
}
return (i+1)/2;
}
#endif

View File

@@ -0,0 +1,79 @@
#ifndef _UWAV_NUMBER_H
#define _UWAV_NUMBER_H
#include "../include/public.h"
/*
* Number type definition:
* 32 digits number is used for party number handling
* 16 digits number is used for prefix parameter
* 8 digits number is used for short number parameter, i.e. cc, ndc
*/
typedef struct number32 {
u8 num_of_digit;
u8 digit[32];
} num32_t;
typedef struct number16 {
u8 num_of_digit;
u8 digit[16];
} num16_t;
typedef struct number8 {
u8 num_of_digit;
u8 digit[8];
} num8_t;
typedef struct isdn_num {
u8 nai; /* Nature of Address Indicator */
// u8 npi; /* Number Plan Indicator */
u8 pi;
num32_t num;
} isdn_t;
struct number_change {
u8 nai;
u8 del_count;
num16_t insert;
};
#define is_dail_digit(digit) (digit < 0x0e)
#define char_to_digit(digit, ch) do { \
if((ch >= '0') && (ch <= '9')) \
digit = ch - '0'; \
else if(ch == '*') \
digit = 0x0b; \
else if(ch == '#') \
digit = 0x0c; \
else \
break; \
} while(0)
#define digit_to_char(ch, digit) do { \
if(digit <= 9) \
ch = digit + '0'; \
else if(digit == 0x0b) \
ch = '*'; \
else if(digit == 0x0c) \
ch = '#'; \
} while(0)
extern u8 nai_gsm_to_itu(u8 nai);
extern u8 nai_itu_to_gsm(u8 nai);
extern u8 *msc_isdn_to_bcd(u8 *bcd, const isdn_t *isdn);
extern isdn_t *netbcd_to_isdn(isdn_t *isdn, const u8 *bcd);
extern u8 *isdn_to_netbcd(u8 *bcd, const isdn_t *isdn);
extern int tbcd_to_string(char *str, const u8 *tbcd, u8 tbcd_len);
extern isdn_t *tpaddr_to_isdn(isdn_t *isdn, const u8 *tpaddr);
extern int string_to_num32(num32_t *num, const char *str);
extern int num32_to_string(char *str, const num32_t *num);
extern int string_to_num16(num16_t *num, const char *str);
extern int num16_to_string(char *str, const num16_t *num);
extern int string_to_num8(num8_t *num, const char *str);
extern int num8_to_string(char *str, const num8_t *num);
extern int digit_to_netbcd(u8 *netbcd, u8 *digit, u8 max_digit);
extern int netbcd_to_digit(u8 *digit, u8 *netbcd, u8 max_digit);
extern void msc_save_lai(u8 *lai, u8 *mcc, u8 *mnc, int lac);
extern void msc_load_lai(u8 *mcc, u8 *mnc, int *lac, u8 *lai);
#endif

View File

@@ -0,0 +1,176 @@
/*
* public/uwav/numgrp.c
*
* Copyright (C) 2008 ADC, Inc
* Written by: Xinyu Yan <xinyu.yan@adc.com>
*
* Description: number group lookup algorithm
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "numgrp.h"
static struct numgrp_table group_table[MAX_NUMBER_GROUP_TABLE];
struct numgrp_table *assign_numgrp_table(char *name, int size)
{
int i;
assert(size <= MAX_NUMBER_GROUP_TABLE_SIZE);
for(i = 0; i < MAX_NUMBER_GROUP_TABLE; i++)
{
if(group_table[i].size == 0)
{
strncpy(group_table[i].name, name, 32);
group_table[i].size = size;
group_table[i].len = 0;
group_table[i].item = malloc(sizeof(struct number_group) * size);
return &group_table[i];
}
}
return NULL;
}
int delete_numgrp_table(struct numgrp_table *table)
{
int i;
for(i = 0; i < MAX_NUMBER_GROUP_TABLE; i++)
{
if(&group_table[i] == table)
{
free(group_table[i].item);
memset(&group_table[i], 0, sizeof(struct numgrp_table));
return 1;
}
}
return 0;
}
/*Return an integer greater than, equal to, or less than 0, if the number pointed to
by n1 is greater than, equal to, or less than the number pointed to by n2, respectively*/
static int numcmp(const num16_t *n1, const num16_t *n2)
{
int i;
if(n1->num_of_digit > n2->num_of_digit)
return 1;
else if(n1->num_of_digit < n2->num_of_digit)
return -1;
for(i = 0; i < n1->num_of_digit; i++)
{
if(n1->digit[i] > n2->digit[i])
return 1;
else if(n1->digit[i] < n2->digit[i])
return -1;
}
return 0;
}
/*Return an integer greater than, equal to, or less than 0, if the number pointed to
by n is greater than, equal to, or less than the group pointed to by start and end, respectively*/
static int numgrpcmp(const num16_t *start, const num16_t *end, const num16_t *n)
{
int ret1, ret2;
ret1 = numcmp(n, start);
ret2 = numcmp(n, end);
if((ret1 >= 0) && (ret2 <= 0))
return 0;
else if(ret2 > 0)
return 1;
else
return -1;
}
/* n: max items of table
* num: number being searched
* m: the position of value which is found or will be inserted
* ret: return 1 if found, otherwise 0
*/
static int bisearch(struct number_group *item, int n, num16_t *num, int *m)
{
int i = 0;
int j = n - 1;
int ret;
*m = 0;
while(i <= j)
{
*m = (i+j) / 2;
ret = numgrpcmp(&item[*m].start, &item[*m].end, num);
if(ret == 0)
return 1;
else if(ret > 0)
i = *m + 1;
else
j = *m - 1;
}
*m = i;
return 0;
}
int numgrp_search(int *index, struct numgrp_table *table, num16_t *num)
{
int m;
if(table == NULL)
return 0;
if(bisearch(table->item, table->len, num, &m))
{
*index = table->item[m].index;
return 1;
}
return 0;
}
int numgrp_insert(struct numgrp_table *table, num16_t *start, num16_t *end, int index)
{
int m, m2;
if(numcmp(start, end) > 0)
{
printf("Start number > end number\n");
return 0;
}
if(bisearch(table->item, table->len, start, &m))
{
printf("Start number in exist group\n");
return 0;
}
if(bisearch(table->item, table->len, end, &m2))
{
printf("End number in exist group\n");
return 0;
}
if(m != m2)
{
printf("Start-end contains other group\n");
return 0;
}
memmove(&table->item[m+1], &table->item[m], sizeof(struct number_group)*(table->len-m));
memcpy(&table->item[m].start, start, sizeof(num16_t));
memcpy(&table->item[m].end, end, sizeof(num16_t));
table->item[m].index = index;
table->len++;
return 1;
}
int numgrp_delete(struct numgrp_table *table, num16_t *num)
{
int m;
if(bisearch(table->item, table->len, num, &m))
{
memmove(&table->item[m], &table->item[m+1], sizeof(struct number_group)*(table->len-m-1));
memset(&table->item[table->len-1], 0, sizeof(struct number_group));
table->len--;
return 1;
}
return 0;
}

View File

@@ -0,0 +1,29 @@
#ifndef _UWAV_NUMGRP_H_
#define _UWAV_NUMGRP_H_
#include "number.h"
#define MAX_NUMBER_GROUP_TABLE 32
#define MAX_NUMBER_GROUP_TABLE_SIZE 1024
struct number_group {
num16_t start;
num16_t end;
int index;
};
struct numgrp_table {
char name[32];
int size;
int len;
struct number_group *item;
};
extern struct numgrp_table *assign_numgrp_table(char *name, int size);/* size: capability of table in unit of records */
extern int delete_numgrp_table(struct numgrp_table *table);
extern int numgrp_search(int *index, struct numgrp_table *table, num16_t *num);
extern int numgrp_insert(struct numgrp_table *table, num16_t *start, num16_t *end, int index);
extern int numgrp_delete(struct numgrp_table *table, num16_t *num);
#endif

View File

@@ -0,0 +1,429 @@
#include "./include/asn1.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int test1();
int test2();
int test3();
int test4();
int test5();
int test6();
int test7();
int test8();
int test9();
int test10();
int test11();
int test12();
int showtlv(const char *tag_seq,ASN_BUF *asnbuf);
int main(int argc,char *argv[])
{
if(argc==2)
{
switch(atoi(argv[1]))
{
case 1:
test1();
break;
case 2:
test2();
break;
case 3:
test3();
break;
case 4:
test4();
break;
case 5:
test5();
break;
case 6:
test6();
break;
case 7:
test7();
break;
case 8:
test8();
break;
case 9:
test9();
break;
case 10:
test10();
break;
case 11:
test11();
break;
case 12:
test12();
break;
default:
printf("Out of range!\n");
}
}
else
printf("Usage:asntest number\n");
return 0;
}
int test1() //Tag encoding/decoding test
{
u_char msg_buf[50];
int len;
ASN_BUF asnbuf;
asn_encode(msg_buf,&asnbuf);
len=add_null("2",0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
if(get_null("2",&asnbuf)==1)
printf("decoding correctly\n");
asn_encode(msg_buf,&asnbuf);
len=add_null("32",0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
if(get_null("32",&asnbuf)==1)
printf("decoding correctly\n");
asn_encode(msg_buf,&asnbuf);
len=add_null("129",0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
if(get_null("129",&asnbuf)==1)
printf("decoding correctly\n");
asn_encode(msg_buf,&asnbuf);
len=add_null("2",0x80,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
if(get_null("2",&asnbuf)==1)
printf("decoding correctly\n");
asn_encode(msg_buf,&asnbuf);
len=add_null("32",0xC0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
if(get_null("32",&asnbuf)==1)
printf("decoding correctly\n");
return 1;
}
int test2()
{
u_char msg_buf[1024],pvalue[1024];
ASN_BUF asnbuf;
memset(pvalue,0xFF,1024);
asn_encode(msg_buf,&asnbuf);
add_tlv("1",0,pvalue,0,&asnbuf);
showbuf(msg_buf,5);
asn_decode(msg_buf,1,&asnbuf);
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
asn_encode(msg_buf,&asnbuf);
add_tlv("1",2,pvalue,0,&asnbuf);
showbuf(msg_buf,5);
asn_decode(msg_buf,1,&asnbuf);
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
asn_encode(msg_buf,&asnbuf);
add_tlv("1",128,pvalue,0,&asnbuf);
showbuf(msg_buf,5);
asn_decode(msg_buf,1,&asnbuf);
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
asn_encode(msg_buf,&asnbuf);
add_tlv("1",129,pvalue,0,&asnbuf);
showbuf(msg_buf,5);
asn_decode(msg_buf,1,&asnbuf);
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
asn_encode(msg_buf,&asnbuf);
add_tlv("1",257,pvalue,0,&asnbuf);
showbuf(msg_buf,5);
asn_decode(msg_buf,1,&asnbuf);
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
return 1;
}
int test3()
{
u_char msg_buf[256];
ASN_BUF asnbuf;
char oid[20];
int len;
//Boolean----->
asn_encode(msg_buf,&asnbuf);
len=add_bool("1",0,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_bool("1",&asnbuf));
asn_encode(msg_buf,&asnbuf);
len=add_bool("1",1,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_bool("1",&asnbuf));
//Integer----->
asn_encode(msg_buf,&asnbuf);
len=add_int("1",2,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_int("1",&asnbuf));
asn_encode(msg_buf,&asnbuf);
len=add_int("1",257,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_int("1",&asnbuf));
asn_encode(msg_buf,&asnbuf);
len=add_int("1",-2,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_int("1",&asnbuf));
asn_encode(msg_buf,&asnbuf);
len=add_int("1",-259,0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
printf("decoded value:%d\n",get_int("1",&asnbuf));
//Object Identifier----->
asn_encode(msg_buf,&asnbuf);
len=add_oid("1","2.100.6",0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
get_oid("1",oid,&asnbuf);
printf("decoded value:%s\n",oid);
asn_encode(msg_buf,&asnbuf);
len=add_oid("1","0.39.6",0,&asnbuf);
showbuf(msg_buf,len);
asn_decode(msg_buf,1,&asnbuf);
get_oid("1",oid,&asnbuf);
printf("decoded value:%s\n",oid);
return 1;
}
int test4() //encoding test
{
u_char msg_buf[256];
int c1=0,c2=1;
u_char d1[2]={0x22,0x22};
u_char d2[2]={0x33,0x33};
u_char b3[2]={0x44,0x44};
u_char a2[2]={0x55,0x55};
u_char a3[2]={0x66,0x66};
int len;
ASN_BUF asnbuf;
asn_encode_v3(msg_buf,128,&asnbuf);
len=add_int("1.0.2-1",c1,0,&asnbuf);
len=add_int("1.0.2-2",c2,0,&asnbuf);
len=add_tlv("1.0.1-3.0",2,d1,0x80,&asnbuf);
len=add_tlv("1.0.1-3.1",2,d2,0x80,&asnbuf);
len=add_tlv("1.1",2,b3,0x80,&asnbuf);
len=add_tlv("2",2,a2,0x80,&asnbuf);
len=add_tlv("3",2,a3,0x80,&asnbuf);
showbuf(msg_buf,len);
printf("decode......\n");
asn_decode(msg_buf,3,&asnbuf);
showtlv("1.0.2-1",&asnbuf);
showtlv("1.0.2-2",&asnbuf);
showtlv("1.0.1-3.0",&asnbuf);
showtlv("1.0.1-3.1",&asnbuf);
showtlv("1.1",&asnbuf);
showtlv("2",&asnbuf);
showtlv("3",&asnbuf);
return 1;
}
int test5() //decoding test(long length)
{
u_char msg_buf[256]={0xA5,0x80,
0x82,0x80,
0x83,0x02,0x00,0x00,
0x00,0x00,
0x00,0x00,
0xA6,0x80,0x82,0x02,0x11,0x11,0x00,0x00};
ASN_BUF asnbuf;
asn_decode(msg_buf,2,&asnbuf);
showtlv("5.2.3",&asnbuf);
showtlv("6.2",&asnbuf);
showtlv("5.2",&asnbuf);
showtlv("6",&asnbuf);
return 1;
}
int test6() //decoding test(indefinite length)
{
u_char msg_buf[256]={0xA5,0x80,
0xA2,0x81,0x82,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
0xA3,0x02,0x01,0x01,
0x00,0x00,
0xA6,0x80,0x82,0x02,0x11,0x11,0x00,0x00};
ASN_BUF asnbuf;
int temp;
asn_decode_v3(msg_buf,256,&temp,&asnbuf);
showtlv("5.2",&asnbuf);
showtlv("5.3",&asnbuf);
showtlv("5",&asnbuf);
showtlv("6.2",&asnbuf);
return 1;
}
int showtlv(const char *tag_seq,ASN_BUF *asnbuf)
{
u_char tlvbuf[256];
int len;
len=get_tlv(tag_seq,tlvbuf,asnbuf);
showbuf(tlvbuf,len);
return 1;
}
int test7() //decoding test(long length)
{
u_char msg_buf[256]={0x60,0x80,
0x80,0x02,0x07,0x80,
0xa1,0x80,
0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x01,0x02,
0x00,0x00,
0x00,0x00};
ASN_BUF asnbuf;
asn_decode(msg_buf,1,&asnbuf);
showtlv("0",&asnbuf);
showtlv("0.0",&asnbuf);
showtlv("0.1",&asnbuf);
showtlv("0.1.6",&asnbuf);
return 1;
}
int test8() //decoding test(long length)
{
u_char msg_buf[256]={0x10,0x03,0xaa,0xbb,0xcc};
ASN_BUF asnbuf;
asn_decode(msg_buf,1,&asnbuf);
printf("tlvcount=%d\n",asnbuf.tlvcount);
showtlv("16",&asnbuf);
return 1;
}
int test9()
{
u_char msg_buf[256]={0x02,0x01,0xaa,
0x04,0x02,0xbb,0xbb,
0x04,0x02,0xcc,0xcc,
0x04,0x02,0xdd,0xdd,
0x02,0x01,0xaa,
0x05,0x02,0x55,0xbb,
0x05,0x02,0x55,0xcc,
0x05,0x02,0x55,0xdd};
// u_char mybuf[64];
// int len;
int temp;
ASN_BUF asnbuf;
asn_decode_v3(msg_buf,30,&temp,&asnbuf);
showtlv("2",&asnbuf);
showtlv("4-2",&asnbuf);
showtlv("4-3",&asnbuf);
showtlv("4-4",&asnbuf);
return 1;
}
int test10()
{
u_char msg_buf[256]={0xA0,0x80,
0x04,0x01,0x21,
0x30,0x80,
0x30,0x80,
0x83,0x01,0x11,
0x84,0x01,0x07,
0x85,0x05,0x81,0x21,0x84,0x00,0x94,
0x86,0x01,0x00,
0x00,0x00,
0x00,0x00,
0x00,0x00};
u_char mybuf[64];
int len;
ASN_BUF asnbuf;
if(asn_decode(msg_buf,1,&asnbuf)==-1)
printf("decode error\n");
len=get_tlv("0",mybuf,&asnbuf);
printf("0:");
showbuf(mybuf,len);
len=get_tlv("0.4",mybuf,&asnbuf);
printf("0.4:");
showbuf(mybuf,len);
len=get_tlv("0.16",mybuf,&asnbuf);
printf("0.16:");
showbuf(mybuf,len);
len=get_tlv("0.16.16.5",mybuf,&asnbuf);
printf("0.16.5:");
showbuf(mybuf,len);
return 1;
}
int test11()
{
u_char msg_buf[256]={0x64,0x6A,0x49
,0x04,0x01,0x62,0x00,0x60,0x6B,0x80,0x28,0x80,0x06,0x07,0x00,0x11
,0x86,0x05,0x01,0x01,0x01,0xA0,0x80,0x61,0x80,0x80,0x02,0x07,0x80
,0xA1,0x80,0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x05,0x02,0x00,0x00
,0xA2,0x80,0x02,0x01,0x00,0x00,0x00,0xA3,0x80,0xA1,0x80,0x02,0x01
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x6C,0x26,0xA2,0x80,0x02,0x01,0x00,0x30,0x80,0x02,0x01,0x16,0x30
,0x80,0x04,0x08,0x64,0x00,0x92,0x00,0x00,0x00,0x00,0xF1,0x04,0x08
,0x91,0x44,0x57,0x25,0x31,0x06,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00
};
// u_char mybuf[64];
// int len;
ASN_BUF asnbuf;
if(asn_decode(msg_buf,1,&asnbuf)==-1)
printf("decode error\n");
return 1;
}
int test12()
{
u_char msg_buf[256]={0xA1,0x0E,
0x01,0x01,0x01,
0x02,0x80,0x02,0x01,0x01,0x00,0x00,
0x02,0x02,0x01,0x02
};
// u_char mybuf[64];
// int len;
ASN_BUF asnbuf;
if(asn_decode(msg_buf,1,&asnbuf)==-1)
printf("decode error\n");
return 1;
}

View File

@@ -0,0 +1,149 @@
/******************************************/
/*Title : bisearch.h */
/*Descr : BiSearch arithmetic Tester */
/*Author : Liu Wei */
/*Create : 2006-12-13 */
/*Version : R1V00_01 */
/*Modify : 2006-12-13 */
/******************************************/
#include "../../iptrans/src/include/iptrans.h"
#include "./include/bisearch.h"
FILE *fp = NULL;
BiSearchArray bsearch_array;
int GetIdleNode(int *nDUIndex)
{
if( bsearch_array.nArrayCount >= bsearch_array.nArrayTotalLen )
return 0;
*nDUIndex = (rand()*19)%bsearch_array.nArrayTotalLen;
return 1;
}
void logarray ( BiSearchArray * pBiArray, char *op )
{
BiSearch *pBS;
LL lastkey = 0;
int nPos = -1;
char buf[4096];
char tmp_str[512];
int i;
buf[0] = '\0';
sprintf ( buf, "Array Contents:[total :%d]\n" , pBiArray->nArrayCount);
for ( i = 0; i < pBiArray->nArrayTotalLen; i++ )
{
pBS = pBiArray->pBiArray + i;
sprintf ( tmp_str, "{%-3u,(%-3llu,%-3u)} ", i, pBS->llKey, pBS->nDUPosIndex );
strcat ( buf, tmp_str );
if( i % 6 == 5 )
{
strcat ( buf, "\n" );
}
if( lastkey > pBS->llKey && i < pBiArray->nArrayCount )
nPos = i;
lastkey = pBS->llKey;
}
//if( nPos != -1 )
{
sprintf ( tmp_str, "\nERR Pos: %d\n\n", nPos );
strcat ( buf, tmp_str );
fprintf ( fp, buf );
}
}
#define log() logarray( &bsearch_array , op)
int main ( int argc, char *argv[] )
{
char op[32];
char buff[64];
int i;
srand((int)time(0));
if( ( fp = fopen ( "./log.txt", "w" ) ) == NULL )
{
printf ( "Open File Fail\n" );
return 0;
}
fprintf ( fp, "======================\n" );
fprintf ( fp, "|| BiSearch Test ||\n" );
fprintf ( fp, "======================\n\n\n" );
for ( i = 0; i < 32; i++ )
{
op[i] = 'A' + ( i * 3 + 11 ) % 26;
buff[i] = op[i] + ( i * 7 + 19 ) % 26;
}
BISearchReg ( &bsearch_array, 64 ,GetIdleNode );
for ( i = 0; i < 30; i++ )
{
int key = ( ( i * 11 ) % 5 ) * ( i % 5 ) - 3 * ( i % 11 ) + 39;
int value = (3 * i + 1)%bsearch_array.nArrayTotalLen;
fprintf ( fp, "Insert(%-3d, %-3d)\n", key, value );
BISInsert ( &bsearch_array, key, value );
log();
}
log();
for ( i = 0; i < 128; i++ )
{
int k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
k = k % 999;
fprintf ( fp, "=====>>Insert(%d, %d)\n", k, 2 * i );
BISInsert ( &bsearch_array, k, (2 * i+rand() % 13 * 19 + i*19)%bsearch_array.nArrayTotalLen);
fprintf ( fp, "\n" );
log();
k = ( ( 20 - i ) % 3 ) * 9 - ( 3 * ( 20 - i ) ) + 9*128;
k = k % 999;
fprintf ( fp, "search index: %d" , k );
if( -1 != GetDUIndex( &bsearch_array ,k ) )
{
fprintf ( fp, "<<=====Delete Key %d\n", k );
BISDelete ( &bsearch_array , k );
}
else
fprintf ( fp, "<<=====Delete Fail , not found [%d]", k );
fprintf ( fp, "\n" );
log();
}
for( i = 0 ; i < 128 ; i++ )
{
int nDUIndex = 0;
int k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
k = k % 999;
BISSearchMng( &bsearch_array , BIS_INSERT , k , &nDUIndex );
fprintf ( fp, "=====>>Insert(%d, %d)\n", k, nDUIndex );
fprintf ( fp, "\n" );
log();
k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
k = k % 999;
fprintf ( fp, "search index: %d" , k );
if( -1 != GetDUIndex( &bsearch_array ,k ) )
{
fprintf ( fp, "<<=====Delete Key %d\n", k );
BISSearchMng( &bsearch_array , BIS_DELETE , k ,&nDUIndex);
}
else
fprintf ( fp, "<<=====Delete Fail , not found [%d]", k );
fprintf ( fp, "\n" );
log();
}
//fclose ( fp );
BISearchUnReg ( &bsearch_array);
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1,125 @@
//////////////////////////////////////////////////
//Title : wxc_debug.c
//Auhtor : Liu Wei
//Desc : wxc debug api implemetation
//Created : 2007-05-01
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "stdio.h"
#include "assert.h"
#include "string.h"
#include "stdlib.h"
#include <execinfo.h>
#include <signal.h>
void dump(int signo)
{
char buf[1024];
char cmd[1024];
FILE *fh;
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", getpid());
if(!(fh = fopen(buf, "r")))
exit(0);
if(!fgets(buf, sizeof(buf), fh))
exit(0);
fclose(fh);
if(buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
snprintf(cmd, sizeof(cmd), "gdb %s %d", buf, getpid());
system(cmd);
exit(0);
}
void WxcBackTrace()
{
int i;
void * array[25];
int nSize = backtrace(array, 25);
char ** symbols = backtrace_symbols(array, nSize);
for (i = 0; i < nSize; i++)
{
printf("%s \n" , symbols[i]);
}
free(symbols);
}
typedef unsigned char BYTE;
#define WxcAssert(uVal,pStr) \
if(!(uVal)) \
{ \
WxcBackTrace(); \
} \
assert( uVal && pStr ); \
void sprintf_bcd( const BYTE *pBcdBuff , int nBcdLen , char *pStrBuff , int nStrBuffSize )
{
int i ,len = 0;
int nChar;
nChar = ( nBcdLen % 8 )* 3 + ( nBcdLen / 8 ) * 25 + 1 ;
WxcAssert((nChar < nStrBuffSize),"sprint bcd string buffer flow");
for( i = 1 ; i <= nBcdLen; i ++ )
{
sprintf ( pStrBuff + len , "%02X ", pBcdBuff[i-1] );
len += 3;
if( 0 == (i % 16) )
{
strcat ( pStrBuff , "\n");
len++;
}
else if( 0 == (i % 8) )
{
strcat ( pStrBuff , " ");
len++;
}
}
if( 0 != (len % 50) )
{
strcat ( pStrBuff , "\n");
}
}
void testdump(char *p)
{
*p =0;
}
void main()
{
BYTE aBCDBuff[128];
char temp[256] ;
int i , j;
char *p ;
p = NULL;
signal(SIGSEGV, &dump);
for( i = 0 ; i < 128 ; i ++ )
{
if( i < 80 )
aBCDBuff[i] = (BYTE)(1 + i) ;
else
aBCDBuff[i] = (BYTE)(256 - i*2) ;
}
for( j = 30 ; j < 100 ; j+=7 )
{
sprintf_bcd(aBCDBuff , j , temp , 256 );
printf("BCD:\r\n%s\r\n", temp);
}
testdump(p);
getchar();
}

View File

@@ -0,0 +1,87 @@
/* public function c file */
/* written by Liu Zhiguo 2002-03-26 */
/* version 1.0 */
/* -------------------------------- */
#include "./include/includes.h"
#include "./include/public.h"
#include "./include/pub_debug.h"
# ifndef S_SPLINT_S
/*@ignore@*/
/* ++++++++++++++++++++++++++++++++++++++ */
/* transfer ascii code to bcd code */
/* ++++++++++++++++++++++++++++++++++++++ */
/*
void AsciiToBcd (BYTE *bcd_buf, const char *ascii_buf, int len)
{
int i;
char ch;
char flag=0;
if (ascii_buf == NULL)
{
for (i=0;i<len/2;i++)
bcd_buf[i] = 0;
bcd_buf[len/2] = '\0';
return;
}
if (len & 1)
{
bcd_buf[0] = 0;
flag = 1;
}
for (i=0; i<len; i++)
{
ch = ascii_buf[i];
if (ch>='a')
ch -= 'a' - 10;
else if (ch>='A')
ch -= 'A' - 10;
else
ch -= '0';
if (flag)
{
if (i & 1)
*bcd_buf = ch << 4;
else
*(bcd_buf++) |= ch & 0x0f;
}
else
{
if (i & 1)
*(bcd_buf++) |= ch & 0x0f;
else
*bcd_buf = ch << 4;
}
}
}
*/
/* ++++++++++++++++++++++++++++++++++++++ */
/* transfer bcd code to ascii code */
/* ++++++++++++++++++++++++++++++++++++++ */
/*
void BcdToAscii (char *ascii_buf, const BYTE *bcd_buf, int len)
{
int i;
char ch;
if (bcd_buf == NULL)
{
for (i=0;i<len;i++)
ascii_buf[i] = '0';
ascii_buf[len] = '\0';
return;
}
for (i=0; i<len; i++)
{
if (i & 1) ch = *(bcd_buf++) & 0x0f;
else ch = *bcd_buf >> 4;
ascii_buf[i] = ch + ((ch > 9)? 'A'-10 : '0');
}
ascii_buf[i] = '\0';
}
*/
/*@end@*/
#endif

View File

@@ -0,0 +1,646 @@
//////////////////////////////////////////////////
//Title : pub_inet_test.c
//Auhtor : Liu Wei
//Desc : public ipnet function test
//Created : 2007-06-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include <stdio.h>
#include <signal.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netdb.h>
#include <setjmp.h>
#include <errno.h>
#include <string.h>
typedef unsigned char u8;
typedef unsigned int u32;
typedef unsigned short u16;
#define MAXINTERFACES 16
typedef struct EIF
{
u32 dIfIP;
u8 uIfState;
}
EIF;
typedef struct IF_ADDR
{
EIF tIfEntity[MAXINTERFACES];
u8 uIfNum;
}
IfAddr;
int GetNetIfInfo ( IfAddr * pIfAddr )
{
int fd;
struct ifreq buf[MAXINTERFACES];
struct arpreq arp;
struct ifconf ifc;
pIfAddr->uIfNum = 0;
if( ( fd = socket ( AF_INET, SOCK_DGRAM, 0 ) ) >= 0 )
{
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = ( caddr_t ) buf;
if( !ioctl ( fd, SIOCGIFCONF, ( char * ) &ifc ) )
{
int i;
pIfAddr->uIfNum = ifc.ifc_len / sizeof ( struct ifreq );
pIfAddr->uIfNum = pIfAddr->uIfNum % MAXINTERFACES;
for ( i = 0; i < pIfAddr->uIfNum; i++ )
{
ioctl ( fd, SIOCGIFFLAGS, ( char * ) &buf[i] );
pIfAddr->tIfEntity[i].uIfState = buf[i].ifr_flags & IFF_UP;
if( !( ioctl ( fd, SIOCGIFADDR, ( char * ) &buf[i] ) ) )
{
pIfAddr->tIfEntity[i].dIfIP = ( ( struct sockaddr_in * )
( &buf[i].ifr_addr ) )->sin_addr.s_addr;
}
}
}
}
close ( fd );
return pIfAddr->uIfNum;
}
#define PACKET_SIZE 4096
#define MAX_NO_PACKETS 3
struct sockaddr_in dest_addr;
struct sockaddr_in from;
struct timeval tvrecv;
typedef void PingCallBack( int nPingResult );
typedef struct ICMP_SERVICE
{
u8 uSrvState;
u8 uPingResult;
u8 uIcmpState;
u8 uPackNo;
u8 uDataLen;
u8 nPackNumSend;
u8 nPackNumRecv;
u8 aSendBuff[PACKET_SIZE];
u8 aRecvBuff[PACKET_SIZE];
u32 wSockfd;
pid_t tPid;
struct protoent *pProtoent;
PingCallBack *fCallBack;
}
IcmpSrv;
IcmpSrv tIcmpSrvEntity;
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD>
u16 IcmpCheckSum ( u16 *addr, int len )
{
int nleft = len;
int sum = 0;
u16 *w = addr;
u16 answer = 0;
//<2F><>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD>
while ( nleft > 1 )
{
sum += *w++;
nleft -= 2;
}
//<2F><>ICMP<4D><50>ͷΪ<CDB7><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֽڡ<D6BD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ϊһ<CEAA><D2BB>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĸ<DDB5><C4B8>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĵ<DDB5><C4B5>ֽ<EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
if( nleft == 1 )
{
*( unsigned char * ) ( &answer ) = *( unsigned char * ) w;
sum += answer;
}
sum = ( sum >> 16 ) + ( sum & 0xffff );
sum += ( sum >> 16 );
answer = ~sum;
return answer;
}
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
int IcmpPacking ( IcmpSrv *pIS )
{
int i, packsize;
struct icmp *icmp;
struct timeval *tval;
icmp = ( struct icmp * ) pIS->aSendBuff;
icmp->icmp_type = ICMP_ECHO;
icmp->icmp_code = 0;
icmp->icmp_cksum = 0;
icmp->icmp_seq = pIS->nPackNumSend;
icmp->icmp_id = pIS->tPid;
packsize = 8 + pIS->uDataLen;
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
tval = ( struct timeval * ) icmp->icmp_data;
gettimeofday ( tval, NULL );
icmp->icmp_cksum = IcmpCheckSum ( (u16 *)icmp, packsize );
return packsize;
}
//<2F><>ȥICMP<4D><50>ͷ
int IcmpUnPack ( u8 *buf, int len , IcmpSrv *pIS )
{
int i, nIpHdrLen;
struct ip *pIP;
struct icmp *icmp;
struct timeval *tvSend;
struct timeval tvRecv;
double rtt;
gettimeofday ( &tvRecv, NULL );
pIP = ( struct ip * ) buf;
//<2F><>ip<69><70>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>,<2C><>ip<69><70>ͷ<EFBFBD>ij<EFBFBD><C4B3>ȱ<EFBFBD>־<EFBFBD><D6BE>4
nIpHdrLen = pIP->ip_hl << 2;
//Խ<><D4BD>ip<69><70>ͷ,ָ<><D6B8>ICMP<4D><50>ͷ
icmp = ( struct icmp * ) ( buf + nIpHdrLen );
//ICMP<4D><50>ͷ<EFBFBD><CDB7>ICMP<4D><50><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
len -= nIpHdrLen;
if( len < 8 )
//С<><D0A1>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>򲻺<EFBFBD><F2B2BBBA><EFBFBD>
{
printf ( "ICMP packets's length is less than 8 " );
return 0;
}
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ICMP<4D>Ļ<EFBFBD>Ӧ
if( ( icmp->icmp_type == ICMP_ECHOREPLY ) && ( icmp->icmp_id == pIS->tPid ) )
{
tvSend = ( struct timeval * ) icmp->icmp_data;
rtt = ( tvRecv.tv_sec * 1000 + tvRecv.tv_usec / 1000 ) -
( tvSend->tv_sec * 1000 + tvSend->tv_usec / 1000 );
printf ( "%d byte from %s: icmp_seq=%u ttl=%d rtt=%.3f ms \n"
, len, inet_ntoa ( from.sin_addr )
, icmp->icmp_seq, pIP->ip_ttl, rtt
);
return 1;
}
return 0;
}
void IcmpStatis ( IcmpSrv *pIS )
{
int nSend , nRecv ;
nSend = pIS->nPackNumSend;
nRecv = pIS->nPackNumRecv;
printf ( " --------------------PING statistics------------------- \n" );
printf ( "%d packets transmitted, %d received , %%%d lost \n\n"
, nSend, nRecv, ( nSend - nRecv ) / nSend * 100 );
close ( pIS->wSockfd );
pIS->uSrvState = 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
int IcmpSend ( IcmpSrv *pIS )
{
int nSize;
if ( pIS->nPackNumSend < MAX_NO_PACKETS )
{
pIS->nPackNumSend++;
nSize = IcmpPacking ( pIS );
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
if( sendto ( pIS->wSockfd, pIS->aSendBuff, nSize, 0,
( struct sockaddr * ) &dest_addr, sizeof ( dest_addr ) ) < 0 )
{
perror ( "sendto error" );
return 0;
}
printf("[IcmpSend] : Send icmp Pack %d \n" , pIS->nPackNumSend);
return 1;
}
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
void IcmpRecv ( IcmpSrv *pIS )
{
int n, fromlen;
extern int errno;
fromlen = sizeof ( from );
while ( pIS->nPackNumRecv < pIS->nPackNumSend )
{
if( ( n = recvfrom ( pIS->wSockfd, pIS->aRecvBuff, sizeof ( pIS->aRecvBuff ),
0, ( struct sockaddr * ) &from, &fromlen ) ) < 0 )
{
if( errno == EINTR )
continue;
perror ( "recvfrom error" );
continue;
}
if( IcmpUnPack ( pIS->aRecvBuff, n , pIS ) == -1 )
continue;
pIS->nPackNumRecv++;
}
}
int PingInit ( IcmpSrv *pIS , int nDataLen )
{
memset( pIS , 0 , sizeof(IcmpSrv) );
pIS->uSrvState = 0;
pIS->uDataLen = 56;
if( ( pIS->pProtoent = getprotobyname ( "icmp" ) ) == NULL )
{
perror ( "getprotobyname" );
exit ( 1 );
}
// <20><><EFBFBD><EFBFBD>rootȨ<74><C8A8>,<2C><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>û<EFBFBD>Ȩ<EFBFBD><C8A8>
setuid ( getuid ( ) );
//<2F><>ȡmain<69>Ľ<EFBFBD><C4BD><EFBFBD>id,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D>ı<EFBFBD>־<EFBFBD><D6BE>
pIS->tPid = getpid ( );
}
int PingTimer ( IcmpSrv *pIS )
{
if( pIS->uSrvState )
{
IcmpRecv( pIS );
switch( pIS->uIcmpState )
{
case 1:
case 2:
case 3:
IcmpSend( pIS );
pIS->uIcmpState++;
break;
default:
if( pIS->nPackNumRecv >= 3 )
{
IcmpStatis( pIS );
pIS->fCallBack( 1 );
}
if( pIS->uIcmpState++ > 200 )
{
IcmpStatis( pIS );
pIS->fCallBack( 0 );
}
break;
}
}
}
int PingStart( IcmpSrv *pIS , char *sIP , PingCallBack fCallBack )
{
int nSize;
struct hostent *pHost;
//struct in_addr *pInAddr;
u32 nInetAddr;
if( pIS->uSrvState )
{
return 0;
}
pIS->fCallBack = fCallBack;
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ICMP<4D><50>ԭʼ<D4AD>׽<EFBFBD><D7BD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD><EFBFBD>ֻ<EFBFBD><D6BB>root<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( ( pIS->wSockfd = socket ( AF_INET, SOCK_RAW, pIS->pProtoent->p_proto ) ) < 0 )
{
perror ( "socket error" );
exit ( 1 );
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD>ֽ<EFBFBD><D6BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>50K<30><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪΪ<D2AA>˼<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ping<6E><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>
setsockopt ( pIS->wSockfd, SOL_SOCKET, SO_RCVBUF, &nSize, sizeof ( nSize ) );
bzero ( &dest_addr, sizeof ( dest_addr ) );
dest_addr.sin_family = AF_INET;
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip<69><70>ַ
nInetAddr = inet_addr ( sIP ) ;
if( nInetAddr == INADDR_NONE )
{
if( ( pHost = gethostbyname ( sIP ) ) == NULL ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
perror ( "gethostbyname error" );
exit ( 1 );
}
memcpy ( ( char * ) &dest_addr.sin_addr, pHost->h_addr, pHost->h_length );
}
else //<2F><>ip<69><70>ַ
{
dest_addr.sin_addr.s_addr = nInetAddr;
//memcpy( (char *)&dest_addr,(char *)&nInetAddr,host->h_length);
}
printf ( "PING %s(%s): %d bytes data in ICMP packets. \n", sIP
, inet_ntoa ( dest_addr.sin_addr ) , pIS->uDataLen );
pIS->uSrvState = 1 ;
pIS->uIcmpState = 1;
}
//<2F><>ӡip<69><70><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>Ϣ
void printIP ( char *packet, int len )
{
struct sockaddr_in addr_src, addr_dst;
struct ip *pip = ( struct ip * ) packet;
printf ( "ip head len:%d ", pip->ip_hl << 2 );
printf ( "ip len:%d ", ntohs ( pip->ip_len ) );
printf ( "ip pro id:%d ", pip->ip_p );
printf ( "ip ttl:%d ", pip->ip_ttl );
printf ( "ip offset:%d ", ntohs ( pip->ip_off ) & IP_OFFMASK );
memset ( &addr_src, 0, sizeof ( struct sockaddr_in ) );
memset ( &addr_dst, 0, sizeof ( struct sockaddr_in ) );
memcpy ( &addr_src, &pip->ip_src, sizeof ( struct sockaddr_in ) );
memcpy ( &addr_dst, &pip->ip_dst, sizeof ( struct sockaddr_in ) );
printf ( "src ip:%x ", addr_src.sin_addr );
printf ( "dst ip:%x ", addr_dst.sin_addr );
}
void NetCapPing( int nRet )
{
if( nRet )
{
printf("Host is rearchable\n");
}
else
{
printf("Host is not rearchable\n");
}
}
static char *pStrEqTok = NULL;
static u8 uStrEqState = 0;
#define CNULL '\0'
#define STR_CHECK_END(str,ch) ( str[strlen(str)-1] == ch )
#define STR_CUT_LAST(str) ( str[strlen(str)-1] = CNULL )
void StrTrimMoreSpace(char *pStr )
{
char *pSrc , *pDst , *pCh;
pDst = pStr;
pCh = pSrc = strdup( pStr );
for( ; *pSrc ; pSrc++ )
{
if( !( isspace(*pSrc) && isspace( *(pSrc+1) ) ) )
{
*pDst++ = *pSrc;
}
}
*pDst = CNULL;
}
char *StrEqTok( char *pStr )
{
char *p, *pCh;
char *pDel = " ";
pCh = NULL;
if( pStr == NULL )
{
pStr = pStrEqTok;
}
else
{
pStr += strspn (pStr, pDel);
if (*pStr == '\0')
{
pStrEqTok = NULL;
return NULL;
}
StrTrimMoreSpace( pStr );
}
if( pStr == NULL )
{
return NULL;
}
uStrEqState = uStrEqState > 2 ? 0 : uStrEqState;
pCh = strpbrk (pStr, pDel );
if( pCh == NULL )
{
pStrEqTok = NULL;
pCh = pStr;
}
else
{
pStrEqTok = pCh + 1;
*pCh = CNULL;
pCh = pStr;
}
p = strchr( pCh , '=');
if( p == NULL )
{
if( pStrEqTok == NULL )
{
goto STREQTOK_CLEAN_UP;
}
if( uStrEqState == 0 || uStrEqState == 2 )
{ //expres left and right
uStrEqState++;
return pCh;
}
else
{ //Miss '='
goto STREQTOK_CLEAN_UP;
}
}
else
{
if( uStrEqState == 0 && STR_CHECK_END( pCh , '=') )
{ //expres left and '='
uStrEqState+=2;
STR_CUT_LAST(pCh);
return pCh;
}
else if( uStrEqState == 1 && pCh[0] == '=')
{ //'=' meet
if( pCh[1] == CNULL )
{
if( pStrEqTok == NULL )
{
goto STREQTOK_CLEAN_UP;
}
pStr = pStrEqTok;
pCh = strpbrk (pStr, pDel);
if( pCh == NULL )
{
pStrEqTok = NULL;
pCh = pStr;
}
else
{
pStrEqTok = pCh + 1;
*pCh = CNULL;
pCh = pStr;
}
uStrEqState = 3;
return pCh;
}
else
{ //expres '=' and right
uStrEqState = 3; //all meet
return ++pCh;
}
}
else if( uStrEqState == 0 )
{ //expres left and '=' and right
if( pStrEqTok != NULL )
{
*(pStrEqTok -1) = ' ';
}
pStrEqTok = p + 1;
*p = CNULL;
uStrEqState = 2;
return pCh;
}
else
{
goto STREQTOK_CLEAN_UP;
}
}
STREQTOK_CLEAN_UP:
pStrEqTok = NULL;
uStrEqState = 0;
return NULL;
}
int main ( )
{
int i, ret = 0;
IfAddr tIfAddr;
IcmpSrv tIcmpSrv;
char tmpStr[80];
ret = GetNetIfInfo ( &tIfAddr );
printf ( "Interface num :%d \n\n", ret );
for ( i = 0; i < ret; i++ )
{
printf ( "If %d : state : %d ip : %s \n\n"
, i, tIfAddr.tIfEntity[i].uIfState
, inet_ntoa ( *((struct in_addr* )&tIfAddr.tIfEntity[i].dIfIP ))
);
}
#define STR(s) #s
printf(STR(if(NOTSO(a)) return 0\n));
#define FPOS( type, field ) /*lint -e545 */ ( (u32) &(( type *) 0)-> field ) /*lint +e545 */
#define FSIZ( type, field ) sizeof( ((type *) 0)->field )
printf("Pos : %ld \n" , FPOS(IfAddr ,uIfNum ) );
printf("Size : %ld \n" , FSIZ(IfAddr ,uIfNum ) );
printf("Pos : %ld \n" , FPOS(IfAddr ,tIfEntity ) );
printf("Size : %ld \n" , FSIZ(IfAddr ,tIfEntity ) );
printf("Pos : %ld \n" , FPOS(EIF ,dIfIP ) );
printf("Size : %ld \n" , FSIZ(EIF ,dIfIP ) );
printf("Pos : %ld \n" , FPOS(EIF ,uIfState ) );
printf("Size : %ld \n" , FSIZ(EIF ,uIfState ) );
printf("Pos : %ld \n" , FPOS(IcmpSrv ,nPackNumSend ) );
printf("Size : %ld \n" , FSIZ(IcmpSrv ,nPackNumSend ) );
printf("Pos : %ld \n" , FPOS(IcmpSrv ,aSendBuff ) );
printf("Size : %ld \n" , FSIZ(IcmpSrv ,aSendBuff ) );
printf("Please input ip and port : ");
fgets( tmpStr, 80 ,stdin );
printf("%s\n", tmpStr);
if( STR_CHECK_END(tmpStr , '\n' ) )
{
STR_CUT_LAST(tmpStr );
}
//StrTrimMoreSpace(tmpStr);
//printf("trim space : \n%s\n" ,tmpStr );
{
char *p = NULL;
u8 uFlag = 0;
p = StrEqTok(tmpStr);
printf( "Name: %-20s " , p);
for( ; p = StrEqTok(NULL); )
{
uFlag = uFlag ? 0 : 1;
if( uFlag )
{
printf( "Valu: %-20s \n" , p);
}
else
{
printf( "Name: %-20s " , p);
}
}
}
printf("\n\n");
PingInit( &tIcmpSrv , 56 );
ret = PingStart( &tIcmpSrv , "172.18.99.1" , NetCapPing );
if( !ret )
{
printf("ping is processing\n");
}
while(1)
{
PingTimer( &tIcmpSrv );
sleep ( 1 );
//ÿ<><C3BF>һ<EFBFBD><EFBFBD><EBB7A2>һ<EFBFBD><D2BB>ICMP<4D><50><EFBFBD><EFBFBD>
}
return 1;
}

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 = publictest
TYPE = plat
DBUG_FLAGS_ADD =
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = exef
CFG = debug
PLT_LIB = public
APP_LIB =
LIB_ADD =
SRC_PATH = ./src
INC_PATH = ./src/include
PLT_PATH = ../../../../plat
APP_PATH = ../../../../mss
OBJ_ADD =
TEST_OBJ_PATH = ../../obj
##---------------------------------------------------------------------##
##--------------------------------------
##
## 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

View File

@@ -0,0 +1,19 @@
//////////////////////////////////////////////////
//Title : main.c
//Auhtor : Liu Wei
//Desc : public function test
//Created : 2007-06-24
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////
#include "../../src/include/includes.h"
#include "../../src/include/public.h"
#include "../../src/include/function.h"
int main()
{
return 1;
}

View File

@@ -0,0 +1,15 @@
/* public test c file */
/* Written by Liu Zhiguo 2002-03-26 */
/* Version 1.0 */
/* -------------------------------- */
#include "./include/includes.h"
#include "./include/public.h"
#include "./include/function.h"
int main()
{
return 1;
}

View File

@@ -0,0 +1,72 @@
##----------------------------------------------------------##
## ##
## Universal Makefile for wxc2 module ##
## --By Wei Liu 2007/04/11 ##
## ##
##----------------------------------------------------------##
##--------------------------------------
##
## Project correlation(Customer define)
##
##--------------------------------------
##Module Name
MODULE = tmtest
#BUILD = lib/exef
BUILD = exef
#CFG = debug / release
CFG = debug
#Source file path
SRC_PATH= ./
#include file path
INC_PATH= ./
#extend wxc2plat module lib need
WXC2_PLT_LIB= public
#extend wxc2plat module lib need
WXC2_APP_LIB=
#extend wxc2plat path default to ./wxc2plat
WXC2_PLT_PATH = ../../../../wxc2plat
#extend wxc2plat path default to ./wxc2app
WXC2_APP_PATH =
#extend obj needed
CFG_OBJ =
##--------------------------------------
##
## Make configuration(Customer define)
##
##--------------------------------------
#gcc flag show on/off
CCFLAG_SWITCH = on
#customer debug version flag add for compile
DEBUG_CFLAGS_ADD = -D_MSCR83 -D_DEVELOPER
#customer release version flag add for compile
RELEASE_CFLAGS_ADD = -D_MSCR83
#need cover fucntion of PTF for test = YES/NO
COVER_NEED =
#cover fucntion output path of PTF for test
COVER_REPORT_PATH = ./ut/ut_doc/output
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include $(MAKE_INCLUDE)/Makefile.rules

View File

@@ -0,0 +1,155 @@
#include "assert.h"
#include "../../src/include/includes.h"
#include "../../src/include/public.h"
#include "../../src/include/wxc_timer.h"
u32 hlr_timer_flag;
u32 hlr_20ms_flag;
void system_init ( void )
{
sleep ( 3 );
hlr_timer_flag = 0;
hlr_20ms_flag = 0;
}
void timer_callback ( )
{
hlr_20ms_flag++;
hlr_timer_flag++;
printf("10 ms call back : %d\n" , hlr_timer_flag);
}
void set_timer ( )
{
struct sigaction act;
struct itimerval value;
struct itimerval old_value;
value.it_interval.tv_sec = 0;
value.it_interval.tv_usec = 10000; // 10 ms
value.it_value.tv_sec = 0;
value.it_value.tv_usec = 10000; // 10 ms
act.sa_handler = timer_callback;
sigemptyset ( &act.sa_mask );
act.sa_flags = 0;
if( sigaction ( SIGALRM, &act, NULL ) == -1 )
{
printf ( "Timer error\n" );
exit ( 0 );
}
setitimer ( ITIMER_REAL, &value, &old_value );
iopl ( 3 );
}
void tm_app_callback_10ms ( u16 dSuitId, u16 dData )
{
printf("10 ms call back\n");
}
void tm_app_callback_1s ( u16 dSuitId, u16 dData )
{
printf("10 ms call back\n");
}
void tm_app_callback_50s ( u16 dSuitId, u16 dData )
{
printf("10 ms call back\n");
}
void tm_app_callback_5000s ( u16 dSuitId, u16 dData )
{
printf("10 ms call back\n");
}
void tm_app_init ( )
{
}
int app_state;
WxcTimer tTimer10ms;
WxcTimer tTimer1s;
WxcTimer tTimer50s;
WxcTimer tTimer5000s;
typedef enum TMTEST_STATE
{
APP_REGSITER,
APP_START,
APP_TIMEROUT,
APP_STOP,
}
TM_STATE;
void tm_app_test ( )
{
switch ( app_state )
{
case APP_REGSITER:
tTimer10ms.dExpires = 1;
tTimer10ms.dSuitNumber = 1;
tTimer10ms.pFunc = &tm_app_callback_10ms;
tTimer10ms.dData = 0;
TimerAdd ( &tTimer10ms );
tTimer1s.dExpires = 100;
tTimer1s.dSuitNumber = 10;
tTimer1s.pFunc = &tm_app_callback_1s;
tTimer1s.dData = 0;
TimerAdd ( &tTimer1s );
tTimer50s.dExpires = 5000;
tTimer50s.dSuitNumber = 100;
tTimer50s.pFunc = &tm_app_callback_50s;
tTimer50s.dData = 0;
TimerAdd ( &tTimer50s );
tTimer5000s.dExpires = 5000000;
tTimer5000s.dSuitNumber = 10;
tTimer5000s.pFunc = &tm_app_callback_5000s;
tTimer5000s.dData = 0;
TimerAdd ( &tTimer5000s );
app_state++;
break;
case APP_START:
app_state++;
break;
case APP_TIMEROUT:
TimerAdd ( &tTimer50s );
app_state++;
break;
case APP_STOP:
TimerAdd ( &tTimer50s );
app_state++;
break;
default:
break;
}
}
int main ( int argc, char *argv[] )
{
system_init ( );
set_timer ( );
while ( 1 )
{
usleep ( 1 );
tm_app_test ( );
}
return 1;
}