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

📄 newfun61xx.c

📁 典型的NOKIA短信猫程序,控制NOKIA615061105110等序列手机收发短信.
💻 C
字号:
#include  <msp430x14x.h>
#include  "modem.h"
uchar g_AckCmd;		
struct SENDSTRUT
  {//两个缓冲在串口发送中顺序执行
      uchar Buf[SENDBUFLEN];
      uchar BufPtr;			//发送指针
      uchar BufLen;			//发送缓冲长度
      uchar Ack[SENDACKLEN];		//ACK应答发送缓冲
      uchar AckPtr;			//ACK发送指针
      uchar CmdSeq;			//发送命令序号
  }
g_Send;
uchar g_RecCmd;//Ack返回的CMD号
uchar g_RecLen;
uchar g_AckSeq;//ACK返回的SEQ号
uchar g_RecBuf[RECBUFLEN];
uchar g_RecPhoneNo[RECPHONELEN];
uchar g_SmgCen[9];
uchar g_SmgCenLen;
uchar g_SmgNoIn;//发送的对方手机号是0x81/0x91
uchar g_CenNoIn;
uchar g_SmgNoLen;
uchar g_RecSmg[RECSMGLEN];
uchar g_RecUSSD[RECSMGLEN];
uchar g_RecSmgLong;
uchar g_RecUSSDLen;
uchar g_DialBuf[30];//
uint g_flag=0;
uint g_flag_2=0;
uchar Sele_Pnum;//定义发送选择的目标号码
unsigned int C_or_E;//定义中英文发送方式
extern void delay_2(void);
extern uchar outnum[20];
extern uchar RXsmg[180];

void Start_SendBuf(uchar len)//发送g_SendBuf数据
  {
	IE1 &= ~URXIE0;  //ES=0;//准备发起发送期间,关中断,置标志
	g_Send.BufLen=len;
	if(g_Send.AckPtr==0)
	  {
		TXBUF0=g_Send.Buf[0];
		g_Send.BufPtr=1;			
	  }	
	IE1 |= URXIE0;  //开串口中断ES=1;
  }

void SendSync(void)//发送同步字符
  {
	uchar i;	
	for(i=0;i<SENDBUFLEN;i++)
	    g_Send.Buf[i]=0x55;
	Start_SendBuf(SENDBUFLEN);
	while(g_Send.BufLen!=0);	//等待发送完成
  }

void Send6110Cmd(uchar len)//len为准备好的g_sendbuf长度,本函数补足seq 及校验值 
  {
	uchar i;	
	if(len&0x1)
	  {
		len=len+3;	//保持len为偶数
		g_Send.Buf[len-3]=g_Send.CmdSeq;					
	  }
	else 
	  {
		len=len+4;	
		g_Send.Buf[len-4]=g_Send.CmdSeq;
		g_Send.Buf[len-3]=0;	
	  }
	g_Send.Buf[len-2]=0;//较验和赋初值
	g_Send.Buf[len-1]=0;
	for(i=0;i<len-2;i++)
	  {		
		if(i&0x01)
		    g_Send.Buf[len-1]^=g_Send.Buf[i];
		else
		    g_Send.Buf[len-2]^=g_Send.Buf[i];
	  }	
	for(i=0;i<3;i++)
	  {//试3次 press
		Start_SendBuf(len);
		while(g_Send.BufLen!=0);	//等待发送完成
		delay_2();
		//等待发送完毕返回ACK
		if(g_flag&RECACK)
		  { 
		        g_flag&=~RECACK;
			if(g_AckCmd==g_Send.Buf[3]&&(g_AckSeq==(g_Send.CmdSeq-0x40)|g_AckSeq==(g_Send.CmdSeq+0x40))) 
			    break;
		  }	
		delay_2();
		//等待发送完毕返回ACK
		if(g_flag&RECACK)
		  { 
		        g_flag&=~RECACK;
			if(g_AckCmd==g_Send.Buf[3]&&(g_AckSeq==(g_Send.CmdSeq-0x40)|g_AckSeq==(g_Send.CmdSeq+0x40))) 
  			    break;
		  }	
		
	  }	
        g_Send.CmdSeq = g_Send.CmdSeq + 1;
        if (g_Send.CmdSeq > 0x47) 
            g_Send.CmdSeq = 0x40;
  }

void DelSmg(uchar smgno)//删除短消息,no为SMG在SIM中的索引值
  {
	uchar i;	
	const uchar buf[]= {0x1e,0x00,0x0c,0x14,0x00,0x08,0x00,0x01,0x00,0x0a,0x02,1,0x01};
	SendSync();
	for(i=0;i<sizeof(buf);i++)
            g_Send.Buf[i]=buf[i];
	g_Send.Buf[sizeof(buf)-2]=smgno;
	Send6110Cmd(sizeof(buf));	
	delay_2();
  }
  
void SendSmg(uchar *buf,uint len)
  {

        char *Find_Pnu;
        unsigned int FPK;
	const uchar SENDSMGBUFB[]={0x1E,0x00,0x0C,0x02,0x00,0x3e,0x00,0x01,0x00,0x01,0x02,0x00
				  ,0x08,0x91,0x68,0x31,0x08,0x20,0x04,0x05,0xF0,0x00,0x00,0x00
			          ,0x11,0x00,0x00,0x00,0x12,0x0B,0x81,0x00,0x00,0x00,0x00,0x00
				  ,0x00,0x00,0x00,0x00,0x00,0xA7,0x00,0x00,0x00,0x00,0x00,0x00};
        uchar scet;
	uchar i,j=0,k=0;
	uchar len_z;
	
        P5OUT |= 0x02;      // 发送短消息
	SendSync();
	FPK=0x00;
	scet=0;
	for(i=0;i<48;i++)
	    g_Send.Buf[i]=SENDSMGBUFB[i];         
        len_z=len;
        g_Send.Buf[28]=len;//短消息长度
	len=len-(len/8);
	g_Send.Buf[48+len]=0x01;
	g_Send.Buf[5]=44+len;
	g_Send.Buf[12]=g_SmgCenLen;
	for(i=0;i<g_SmgCenLen;i++)
	    g_Send.Buf[13+i]=g_SmgCen[i];
	if(C_or_E==0x01)//英文方式发送
	  {
              for(i=0;i<len;i++)
                {
                    g_Send.Buf[i+48]=(((buf[j]>>k)|(buf[j+1]<<(7-k)))&0xff);
                    j++;		
                    k=(k+1)%7;
                    if(k==0)
                       j++;
                                  
                }	
	  }
	if(C_or_E==0x10)//中文方式发送
	  {
              for(i=0;i<len_z;i++)
                   g_Send.Buf[i+48]=buf[i];
              g_Send.Buf[0x1b]=0x08;
              g_Send.Buf[0x1c]=len_z;
              g_Send.Buf[48+len_z]=0x01;
	      g_Send.Buf[5]=44+len_z;
	  }  
        if(Sele_Pnum<0x04)//从存的FLASH内读目标号码 
          {
              for(Find_Pnu=(char*)0x1004;Find_Pnu<=((char *)FSEG_B+80);Find_Pnu++)           
                {
                    if(scet==Sele_Pnum-1)
                      {   
                          if((*Find_Pnu)!=0x11)
                            {           //if not end
                                if( FPK&0x01)
                                    g_Send.Buf[31+ FPK/2]=g_Send.Buf[31+ FPK/2]+((*Find_Pnu)<<4);
                                else
                                    g_Send.Buf[31+ FPK/2]=*Find_Pnu;
                                FPK++;              
                            }     
                          else
                            {//本段结束
                                if( FPK&0x01)
                                     g_Send.Buf[31+ FPK/2]=g_Send.Buf[31+ FPK/2]+0xf0;//奇数则补0xf0
                                g_Send.Buf[29]= FPK;
                                g_Send.Buf[30]= g_CenNoIn;
                                break;
                            }
                          
                      }
                    else 
                      { 
                          if((*Find_Pnu)==0x11)
                              scet++;                //look  for next 0x11
                      }
                }   
          }
        if(Sele_Pnum==0x05)//直接用来号发出 
          {
              g_Send.Buf[30]=g_SmgNoIn;
              g_Send.Buf[29]=outnum[0];
              if(outnum[0]&&0x01)//even
                {
                    for(k=1;k<=outnum[0]/2+1;k++)
                        g_Send.Buf[30+k]=outnum[k];
                }
              else
                {
                    for(k=1;k<=outnum[0]/2;k++)
                        g_Send.Buf[30+k]=outnum[k];
                }
                
          }
        if(Sele_Pnum==0x04)//直接用串口来号发出 
	  {
	      g_Send.Buf[30]=g_CenNoIn;
              g_Send.Buf[29]=RXsmg[1];//注意没改好啊
              if((RXsmg[1]%2)==0x00)//even
                {
                    for(k=1;k<=(RXsmg[1]/2);k++)
                        g_Send.Buf[30+k]=RXsmg[k*2]-0x30+(RXsmg[k*2+1]-0x30)*0x10;
                }
              else
                {
                    for(k=1;k<=(RXsmg[1]/2);k++)
                        g_Send.Buf[30+k]=RXsmg[k*2]-0x30+(RXsmg[k*2+1]-0x30)*0x10;  
                    g_Send.Buf[30+RXsmg[1]/2+1]=(RXsmg[RXsmg[1]+1]-0x30)+0xf0; 
                }
          }	
	if(C_or_E==0x10)
	    Send6110Cmd(49+len_z);
	else
	    Send6110Cmd(49+len);	
  }

void Read6110ID(void)//读6110ID号
  {
	uchar i;
	const uchar RequestIDBuf[]= {0x1e,0x00,0x0c,0x04,0x00,0x06,0x00,0x01,0x00,0x03,0x01};//11
	SendSync();
	for(i=0;i<sizeof(RequestIDBuf);i++)
		g_Send.Buf[i]=RequestIDBuf[i];
	Send6110Cmd(sizeof(RequestIDBuf));
  }

void DialOut(uchar *DialBuf,uchar len)		//一次拔号拔出DialBuf缓冲所存的电放号,长度为len
  {	
	const uchar SENDCALLB[]={0x1e,0x00,0x0c,0x01,0x00,0x17,0x00,0x01,0x00,0x01};//通用头 
	const uchar SENDCALLE[]={0x05,0x01,0x01,0x05,0x81,0x01,0x00,0x00,0x01,0x01};//通用尾
  	uchar i,dat;
	SendSync();
	dat=sizeof(SENDCALLB);
	for(i=0;i<dat;i++)//放头
	    g_Send.Buf[i]=SENDCALLB[i];
	g_Send.Buf[5]=sizeof(SENDCALLB)+sizeof(SENDCALLE)+len-4;//发送包的长度
	g_Send.Buf[i]=len;//号长度	
	i++;
	dat++;
	for(;i<dat+len;i++)//放号
	    g_Send.Buf[i]=DialBuf[i-dat]+0x30;
	dat+=len;	
	for(;i<dat+sizeof(SENDCALLE);i++)//放尾
	    g_Send.Buf[i]=SENDCALLE[i-dat];
	Send6110Cmd(dat+sizeof(SENDCALLE));	
  }

void GetSmgCen(void)//读SIM卡中短信中心号
  {
	uchar i;		 
	const uchar buf[]= {0x1e,0x00,0x0c,0x2,0x00,0x8,0x00,0x01,0x00,0x33,0x64,1,1};
	SendSync();
	for(i=0;i<sizeof(buf);i++)
		g_Send.Buf[i]=buf[i];
	Send6110Cmd(sizeof(buf));	
	delay_2();	
  }

⌨️ 快捷键说明

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