#include "includes.h" /*文件描述 1、本文件主要处理终端向服务器授权的功能,DTU作为中间的网络桥梁 2、主要通讯链路包括两部分:终端<-->DTU, DTU<-->服务器 3、终端到DTU之间的通讯是自定义协议,带加密 4、DTU到服务器之间使用部标协议,自定义消息ID 5、支持多串口通道授权操作,每个串口要独立配置好外设 */ CHANNEL_DEF channel[CHANNEL_NUM]; void authSendCmd(unsigned char cmd, unsigned char *data, unsigned char len); unsigned char authSocketStatus; //授权初始化 void authNewInit(void) { unsigned char i; for(i=0;ichannel[scanChannel].waitTime){ //两秒超时终端没响应,则清掉本结构体 memset((unsigned char *)&channel[scanChannel], 0, sizeof(CHANNEL_DEF)); channel[scanChannel].result=SER_AUTH_IDLE; } break; case SER_AUTH_FAILED:break;//鉴权失败,可以显示状态,但不清除结构体 case SER_AUTH_DEV_OK_DLY://防止由于鉴权太快了,灯看不到灭的瞬间而作出的一小会灭延时 if(os_time_get()>channel[scanChannel].waitTime){ channel[scanChannel].result=SER_AUTH_DEV_OK; } break; } } } } void ModemTryAuthNow(unsigned char *id); //应用发起向服务器请求授权的入口 void ModemSendAuthReqHandle(void) { static CHANNEL_TYPEENUM scanChannel=CHL_UART1; static unsigned int tick=0; unsigned char reReqNum; AuthIndicator(); if(sutModemStatus.PDPStatus != OPENED) return; if(authSocketStatus==0) return; if(os_time_get()= reReqNum) channel[scanChannel].reqTime=0; } } if(++scanChannel >= CHL_TOTAL) scanChannel=CHL_UART1; } void testMakeReqAck(unsigned char *id); //模块通过部标向服务器请示某终端鉴权请求接口 void ModemTryAuthNow(unsigned char *id) {//打包并通过UDP发送数据 unsigned char sendbuf[128]; unsigned short i,j; unsigned char *ptr=sendbuf; unsigned char th,tl,sum=0; char temp[20]; static unsigned short liushui=0; j=0; //header //sms type 2bytes ptr[j++]=AUTH_REQ_ID>>8; ptr[j++]=AUTH_REQ_ID&0xff; //sms property 2bytes i=45;//only low 10bits are define as sms length ptr[j++]=i>>8;//no sub packets,no encrypt ptr[j++]=i;//sms length //device SN 6bytes snprintf(temp, sizeof(temp),"%012d",sutProductPara.PSN); for(i=0;i<6;i++){ th=temp[2*i]; tl=temp[2*i+1]; th <<= 4;th &= 0xF0; tl &= 0x0F; ptr[j++]=th | tl; } //serial nuber 2bytes ptr[j++]=(liushui>>8)&0xFF; ptr[j++]=liushui&0xFF; liushui++; //sms info //生厂产家标识 i=sizeof(sutProductPara.proName); memset(&ptr[j], 0, i); memcpy(&ptr[j], sutProductPara.proName, i); j += i; //产品型号 i=sizeof(sutProductPara.devName); memset(&ptr[j], 0, i); memcpy(&ptr[j], sutProductPara.devName, i); j += i; //id len ptr[j++]=UNIQUE_ID_BYTES; //id data memcpy(ptr+j, id, UNIQUE_ID_BYTES); j += UNIQUE_ID_BYTES; //verify code for(i=0;i>8; sendbuf[i++]=liushui; for(k=0;k>8; ptr[j++]=AUTH_ACK_ID&0xff; //sms property 2bytes i=39;//授权成功长度 36 授权失败长度 ptr[j++]=i>>8;//no sub packets,no encrypt ptr[j++]=i;//sms length //device SN 6bytes snprintf(temp, sizeof(temp),"%012d",sutProductPara.PSN); for(i=0;i<6;i++){ th=temp[2*i]; tl=temp[2*i+1]; th <<= 4;th &= 0xF0; tl &= 0x0F; ptr[j++]=th | tl; } //serial nuber 2bytes ptr[j++]=(liushui>>8)&0xFF; ptr[j++]=liushui&0xFF; liushui++; //sms info memset(ptr+j, 0, 32); memcpy(ptr+j, id, UNIQUE_ID_BYTES); j += 32; ptr[j++]=0; ptr[j++]=ENCODE_VALUE; ptr[j++]=4; ptr[j++]=0x78^ENCODE_VALUE; ptr[j++]=0x2a^ENCODE_VALUE; ptr[j++]=0xc8^ENCODE_VALUE; ptr[j++]=0x0f^ENCODE_VALUE; //verify code for(i=0;i