⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svcriter.cpp

📁 七号信令解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:

#include "stdafx.h"


#define u8 unsigned char
#define u16 unsigned short
#define u32 unsigned long
#define NOPASS 0
#define PASS 0xff

#define BYTEOFPVAR 3
#define BYTEOFACUIN 0
#define BYTEOFAPIN 0


u8 BUFSETMEM[3*30];

u8 compare(u8 *code,u8 *crit,u8 floh)
{ u8 logsign,numofbyte;
  u8 c;
  u8 stat=PASS;

	logsign=*crit++;
	numofbyte=*crit++;

	switch(logsign)
	 {
	  case 0xf1://=
		stat=PASS;
		for (c=0;c<numofbyte;c++)
		 { if (*(code+c)!=*(crit+c)) {stat=NOPASS;break;}}
		break;

	  case 0xf2://!=
		stat=PASS;
		for (c=0;c<numofbyte;c++)
		 { if (*(code+c)==*(crit+c)) {stat=NOPASS;break;}}
		break;

	  case 0xf5://IN
		stat=PASS;
		if (floh==0xff) //store from L to H
		{c=numofbyte;
		 while (c!=0) //update by 1999\08\10
		 {if (*(code+c-1)<*(crit+c-1)) {stat=NOPASS; break;}
		  else if (*(code+c-1)>*(crit+c-1)) break;
		  c--;
		 }//while
		 if (stat==PASS)
		 {crit += numofbyte;
		  c=numofbyte;
		  while (c!=0) //update by 1999\08\10
		  {if (*(code+c-1)>*(crit+c-1)) {stat=NOPASS; break;}
		   c--;
		  }//while
		 }//if (stat==PASS)
		}//if (floh==0xff)
		else //store from H to L
		 {
		  for (c=0;c<numofbyte;c++)
			{if (*(code+c)<*(crit+c)) {stat=NOPASS;break;}
			 else if (*(code+c)>*(crit+c)) break;
			}
		  if ((stat==PASS)&&(c!=numofbyte-1))
			{crit += numofbyte;
			 for (c=0;c<numofbyte;c++)
			  {if (*(code+c)>*(crit+c)){stat=NOPASS;break;}}
			}
		 }
		break;

	  default:stat=NOPASS;break;
	 }//switch(logsign)
	return stat;
}

u8 compareaddr(u8 *msg,u8 *crit)
{u8 startbit,bitlen,c,temp;
 u8 code[10];

 startbit=*crit++;
 bitlen=*crit++;		//crit-->logic sign

 msg += startbit/8;
 startbit %=8;
 if(startbit!=0) //startbit=0
  {
	for (c=0;c<bitlen/8;c++)
	 {temp=*msg; temp&= 0xf0; code[c]=temp>>4;
	  temp=*msg++; temp&=0x0f; code[c] |=temp<<4;
	 }
	if((bitlen%8)!=0)
	 {temp=*msg; temp &= 0xf0; code[c]=temp;}
  } //startbit=0
 else  //startbit=4
  {
	for (c=0;c<bitlen/8;c++)
	 {temp=*msg; temp &= 0xf0; code[c]=temp>>4;
	  temp=(*msg++)&0x0f; code[c] |=temp<<4;
	 }
	if((bitlen%8)!=0)
	 {temp=*msg++; temp &= 0x0f; code[c]=temp<<4;}
  }//startbit=4

 return (compare(&code[0],crit,0));
}

u8 comparespcode(u8 *msg,u8 *crit)
{ u8 spcode[3];

  crit +=2;

  spcode[0]=*msg;
  spcode[1]=*(msg+1);
  spcode[2]=*(msg+2);

  return (compare(&spcode[0],crit,0));
}

u8 compareDPC14(u8 *msg,u8 *crit)
{ u8 spcode[2];

  crit +=2;

  spcode[0]=*msg;
  spcode[1]=*(msg+1)&0x3f;

  return (compare(&spcode[0],crit,0));
}

u8 compareOPC14(u8 *msg,u8 *crit)
{ u8 spcode[2];

  crit +=2;

  spcode[0]=(*msg)>>6|*(msg+1)<<2;
  spcode[1]=*(msg+1)>>6|*(msg+2)<<2;
  spcode[1]&=0x3fff;

  return (compare(&spcode[0],crit,0));
}


u8 comparel4bitscode(u8 *msg,u8 *crit)
{ u8 code;

  code=(*msg)&0x0f;
  return (compare(&code,crit+2,0));
}

u8 compare8bitscode(u8 *msg,u8 *crit)
{ u8 code;
  u8 startbit,bitlen,c;
  u8 mask[]={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,};
  u8 mask2[]={0,1,3,7,0x0f,0x1f,0x3f,0x7f,0xff,};

  startbit=*crit++;
  bitlen=*crit++;

  code=(*msg)&mask[startbit];
  if (startbit!=0) for (c=0;c<startbit;c++) code >>1;
  code &= mask2[bitlen];

  return (compare(&code,crit,0));
}

u8 compare12bitscode(u8 *msg,u8 *crit)
{ u8 code[2];
  u8 startbit,bitlen,c;
  u16 mask[]={0xffff,0xfffe,0xfffc,0xfff8,0xfff0,0xffe0,0xffc0,0xff80,
				  0xff00,0xfe00,0xfc00,0xf800,0xf000,0xe000,0xc000,0x8000,
				 };
  u16 mask2[]={0,1,3,7,0x0f,0x1f,0x3f,0x7f,0xff,0x1ff,0x3ff,0x7ff,0xfff,
					0x1fff,0x3fff,0x7fff,0xffff,};
  u16 scode;

  startbit=*crit++;
  bitlen=*crit++;

  scode=(*(u16 *)msg)&mask[startbit];
  if (startbit!=0) for (c=0;c<startbit;c++) scode >>1;
  scode &= mask2[bitlen];
  code[0]=LOBYTE(scode);
  code[1]=HIBYTE(scode);

  return (compare(&code[0],crit,0xff));
}

u8 DUPmesscri14(u8 *msg,u8 *crit)
{
  return 1;
}
u8 DUPmesscri(u8 *msg,u8 *crit)
{
  return 1;
}
extern u8 ISUPmesscri14(u8 *msg,u8 *crit);
extern u8 ISUPmesscri(u8 *msg,u8 *crit);
extern u8 SCCPmesscri14(u8 *msg,u8 *crit);
extern u8 SCCPmesscri(u8 *msg,u8 *crit);

u8 TUPmesscri14(u8 *bmsg,u8 *crit)
{
  u8 selecth1h0=0;
  u8 fldno,numofbyte,varno;
  u8 c,stat,head,code[3];
  u8 *msg;
  u16 temp;

  do{
	fldno = *crit++;
	numofbyte=*(crit+3);
	switch (fldno)
	  {
		 case 7://DPC
		  if (numofbyte==0)//compare with var
			{varno = (*(crit+4))*BYTEOFPVAR;stat=PASS;
			 if ((BUFSETMEM[varno]!=*bmsg)
				||(BUFSETMEM[varno+1]!=(*(bmsg+1)&0x3f)))
				stat=NOPASS;
			 crit +=5;  //crit-->OR(F7)/AND(F8)/CC
			}
		  else //compare with criteria
			{stat=compareDPC14(bmsg,crit);
			 if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
			}
		  break;

		 case 8://OPC
		  msg=bmsg+1;         //msg-->OPC
		  if (numofbyte==0)//compare with var
			{varno = (*(crit+4))*BYTEOFPVAR;stat=PASS;
			 if ((BUFSETMEM[varno]!=(*msg&0xc0))
				||(BUFSETMEM[varno+1]!=*(msg+1))
				||(BUFSETMEM[varno+2]!=*(msg+2))) stat=NOPASS;
			 crit +=5;     //crit-->OR/AND/0xaa
			}
		  else //compare with criteria
			{stat=compareOPC14(msg,crit);
			 if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
			}
		  break;

		 case 9://CIC
		  stat=NOPASS;
		  msg=bmsg+3;          //msg-->slc
		  if (numofbyte==0)//compare with var
			{varno = (*(crit+4))*BYTEOFPVAR;stat=PASS;
			 if ((BUFSETMEM[varno]!=(*msg&0xf0))
				||(BUFSETMEM[varno+1]!= *(msg+1)) )
			  stat=NOPASS;
			 crit +=5;     //crit-->OR/AND/0xaa
			}
		  else //compare with criteria
			{temp=(*(u16 *)msg)>>4;
			 code[0]=LOBYTE(temp); code[1]=HIBYTE(temp);
			 stat=compare(&code[0],crit+2,0);
			 if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			 crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
			}
		  break;

		 case 10: //H1H0
		  selecth1h0=0xff;
		  msg=bmsg+5;          //msg-->H1H0
		  head=*msg;       //get h1h0
		  stat=compare8bitscode(msg,crit);
			 if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
		  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
		  break;

		 case 11:
		  stat=NOPASS;
		  if (selecth1h0!=0xff)  //have select H1H0
		  { msg=bmsg+6;
		    if(head==0x41)//SAO
			 { code[0]=*msg&0x0f;   //ADDR:D3-D0,IN SAO
				stat=compare(&code[0],crit+2,0);
			 }//SAO
		    else if (head==0x14)//ACM
			 { code[0]=*msg;        //MIN:8BITS,IN ACM
				stat=compare(&code[0],crit+2,0);
			 }//ACM
          }//have select H1H0
		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
		  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

		 case 12:
		  stat=NOPASS;
		  if (selecth1h0==0xff)//have select H1H0
		  {if((head==0x31)&&((*bmsg+6)&0xf0))//SAM and BNOA!=0
			 stat=compareaddr(bmsg+7,crit); //BADDR in SAM
			else if (head==0xf5)
			 stat=comparespcode(bmsg+7,crit);//SPCODE in EUM
		  }//have select H1H0

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
		  break;

//BADDR in IAM\IAI
		 case 14:
		  stat=NOPASS;
		  if ((selecth1h0==0xff) &&       //have select H1H0
				((head==0x11)||(head==0x21)) ) //IAM or IAI
			 {msg=bmsg+8;				//msg-->BNOA
			  if((*msg&0xf0)!=0) stat=compareaddr(msg+1,crit);//BNOA!=0
			 }//have select H1H0,and IAM\IAI

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
		  break;

//AADDR in GSM
		 case 15:
		  stat=NOPASS;
		  if ((selecth1h0==0xff)&&(head==0x12))//have select H1H0,GSM
			 {msg=bmsg+6;  //msg-->ATIN
			  if (*msg&0x02) //exist AADDR
				{msg++;   //msg-->ANOR or CLGPC
				 if(*msg&0x01) msg++; //exist CLGPC
				 if (*msg&0xf0) stat=compareaddr(msg+1,crit);//ANOA!=0
				}//exist AADDR
			 }//have select H1H0,GSM

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

//TXID in GSM
		 case 18:
		  stat=NOPASS;
		  if ((selecth1h0==0xff)&&(head==0x12))//have select H1H0,GSM
			 {msg=bmsg+6;  //msg-->ATIN
			  c=*msg;      //get ATIN
			  if (c&0x04) //exist TXID
				{msg++;   //msg-->ANOR or CLGPC
				 if(c&0x01) msg++; //exist CLGPC,msg-->ANOA
				 if(c&0x02) {c=*msg++; msg +=(c&0xf0+0x10)/0x20;}
				 c=*msg++;      //get EXLIN
				 if ((c&0xf0)==0) stat=comparespcode(msg,crit);
				 else stat=compareaddr(msg+1,crit);
				}//exist TXID
			 }//have select H1H0,GSM

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

//AADDR in IAI
		 case 22:
		  stat=NOPASS;
		  if ((selecth1h0==0xff)&&(head==0x21))//have select H1H0,IAI
			{msg=bmsg+8;   //msg-->BNOA
			 c=*msg++; msg +=(c&0xf0+0x10)/0x20; //si-->IN1
			 c=*msg++;  //get IN1
			 if (c&0x10)  //exist AADDR
			  {if(c&0x01) msg++;
				if(c&0x02) msg +=5; //exist CUGIN
				if(c&0x04) msg +=BYTEOFACUIN;//exist ACUIN
				if(c&0x08) msg +=BYTEOFAPIN;
				c=*msg++;  //get ANOA
				if(c*0xf0) stat=compareaddr(msg,crit);//ANOA!=0
			  }//exist AADDR
			}//have select H1H0,IAI

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

//OADDR in GSM
		 case 23:
		  stat=NOPASS;
		  if ((selecth1h0==0xff)&&(head==0x12))//have select H1H0,GSM
			 {msg=bmsg+6;  //msg-->ATIN
			  c=*msg;      //get ATIN
			  if ((c&0x08)==0x08) //exist OADDR
				{msg++;   //msg-->ANOR or CLGPC
				 if(c&0x01) msg++; //exist CLGPC,msg-->ANOA
				 if(c&0x02) {c=*msg++; msg +=(c&0xf0+0x10)/0x20;}
				 if(c&0x04) //exist TXID
				  {c=*msg++;      //get EXLIN
					if ((c&0x0f)==0) msg+=3;
					else {c=*msg++; msg +=(c&0xf0+0x10)/0x20;}
				  }//exist TXID
				 c=*msg++;  //get FLIN
				 msg += c/0x10;  //msg-->ONOA
				 c=*msg++;   //get ONOA
				 if ((c&0xf0)==0) stat=comparespcode(msg,crit);
				}//exist OADDR
			 }//have select H1H0,GSM

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

//OADDR in IAI
		 case 25:
		  stat=NOPASS;
		  if ((selecth1h0==0xff)&&(head==0x21))//have select H1H0,IAI
			{msg=bmsg+8;   //msg-->BNOA
			 c=*msg++; msg +=(c&0xf0+0x10)/0x20; //si-->IN1
			 c=*msg++;  //get IN1
			 if (c&0x20)  //exist OADDR
			  {if(c&0x01) msg++;
				if(c&0x02) msg +=5; //exist CUGIN
				if(c&0x04) msg +=BYTEOFACUIN;//exist ACUIN
				if(c&0x08) msg +=BYTEOFAPIN;
				if(c&0x10) //exist AADDR
				 {c=*msg++; msg += (c&0xf0+0x10)/0x20; }//get ANOA
				c=*msg++;  //get ONOA
				if(c*0xf0) stat=compareaddr(msg,crit);//ANOA!=0
			  }//exist OADDR
			}//have select H1H0,IAI

		  if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC

		  break;

		 default:stat=NOPASS; break;
	  }//switch

	 crit++;        //crit-->F7/F8/AA

	 if((stat!=PASS && *crit==0xf8)//the condition isn't pass & and
	  ||(stat==PASS && *crit==0xf7))//the condition is pass & or
		  break;
	 else if ((stat==PASS && *crit==0xf8)//condition is pass & OR
			  ||(stat!=PASS && *crit==0xf7))//condition isn't pass & AND
		  crit++;
  } while(*crit!=0xaa);
  return stat;
}

u8 TUPmesscri(u8 *bmsg,u8 *crit)
{
  u8 selecth1h0=0;
  u8 fldno,numofbyte,varno;
  u8 c,stat,head,code;
  u8 *msg;

  do{
	fldno = *crit++;
	numofbyte=*(crit+3);
	switch (fldno)
	  {
		 case 7://DPC
		  if (numofbyte==0)//compare with var
			{varno = (*(crit+4))*BYTEOFPVAR;stat=PASS;
			 for (c=0;c<3;c++)
				 if (BUFSETMEM[varno+c]!=*(bmsg+c)) {stat=NOPASS;break;}
			 crit +=5;  //crit-->OR(F7)/AND(F8)/CC
			}
		  else //compare with criteria
			{stat=comparespcode(bmsg,crit);
			 if (*(crit+2)==0xf5) numofbyte *=2;//logical sign
			  crit += 4+numofbyte;//crit-->OR(F7)/AND(F8)/CC
			}
		  break;

		 case 8://OPC
		  msg=bmsg+3;         //msg-->OPC
		  if (numofbyte==0)//compare with var
			{varno = (*(crit+4))*BYTEOFPVAR;stat=PASS;
			 for (c=0;c<3;c++)
				 if (BUFSETMEM[varno+c]!=*(msg+c)) {stat=NOPASS;break;}
			 crit +=5;     //crit-->OR/AND/0xaa
			}
		  else //compare with criteria

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -