#include "includes.h" #define AUTH_FILE "m5700_info" #define ID_VALID_BYTE 12 char *modemImei=NULL; char id_imei[ID_VALID_BYTE+1]={0}; void saveAuthEncode(char *writebuf,int length){ int fd; MSG_INFO(1,"%s save start",AUTH_FILE); fd=LSAPI_FS_Open(AUTH_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT |LSAPI_FS_O_TRUNC,0); if(fd<0){ MSG_ERR(1,"%s open failed",AUTH_FILE); return; } //保存 LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET); LSAPI_FS_Write(fd, writebuf, length); //nwy_sdk_fsync(fd); LSAPI_FS_Close(fd); MSG_INFO(1,"%s save done", AUTH_FILE); } bool readAuthEncode(char *readbuf,int length){ int fd; fd=LSAPI_FS_Open(AUTH_FILE, LSAPI_FS_O_RDWR,0x0); if(fd<0){ MSG_ERR(1,"%s open read failed", AUTH_FILE); return false; } LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET); LSAPI_FS_Read(fd, readbuf,length); LSAPI_FS_Close(fd); return true; } /* DecodeImeiBytes Ȩ */ void DecodeImeiBytes(unsigned char *imei){ unsigned char i,j,seeds='w'; j='j'; for(i=0;iID_VALID_BYTE){ w=(len-ID_VALID_BYTE)*2; for(i=0;i>8; //4-5 sendbuf[i++]=liushui; for(k=0;k=10){ if(handshake==false) authSendCmd(PRO_AUTH_RESPONS,0,0); cnt=0; } LSAPI_OSI_ThreadSleep(100); } if(showFlag) guiShowMessageBox("Ȩͨ"); #endif sutApp.authReady=1; } #define FACTORY_NAME "YT" //#define FACTORY_NAME "RTL" void EncodeKeyWithFactorAndMode(unsigned char *code) { int i,j; char *FN=FACTORY_NAME; char *MN=OHPOC_APP_NAME; j=strlen(FACTORY_NAME); for(i=0;iSlaveNum=*dataPtr; //write new auth authInfo->authCode=codeData; //make lier data for(i=0;inoUseStart);i++){ authInfo->noUseStart[i]=*dataPtr++^data[6]; if(dataPtr>=&data[len]) dataPtr=data; } for(i=0;inoUseEnd);i++){ authInfo->noUseEnd[i]=*dataPtr++^data[4]; if(dataPtr>=&data[len]) dataPtr=data; } #endif if(codeData == encodeWithImei(id_imei, ID_VALID_BYTE)){ saveAuth(modemImei); sutApp.authReady=1; return 0; }else return 4; } char authRecvPro(const char *data, unsigned int length){ unsigned char senddata[ID_VALID_BYTE+16+16]; char ret=authDataPro(data, length); switch(ret){ case 0: authSendCmd(PRO_AUTH_OK,id_imei,ID_VALID_BYTE); break; case 4://鉴权吗不正确 authSendCmd(PRO_AUTH_FAI, id_imei, ID_VALID_BYTE); break; case 5://握手成功 handshake=true; break; case 6://请求基本数据 memset(senddata, 0, sizeof(senddata)); memcpy(senddata, id_imei, ID_VALID_BYTE); strcpy(senddata+ID_VALID_BYTE, FACTORY_NAME); strcpy(senddata+ID_VALID_BYTE+16, OHPOC_APP_NAME); authSendCmd(PRO_AUTH_REQ,senddata,ID_VALID_BYTE+16+16); break; } return ret; }