authFota.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. authFota.c
  3. 应用授权和FOTA升级功能
  4. 应用授权:请求服务器授权情况,授权则应用功能正常,否则应用不启动对讲功能
  5. FOTA升级:请求服务器是否有新对讲版本可以更新,如果有且用户确认升级,则执行升级(需要module支持/或者通过tcp自定义协议完成)
  6. */
  7. #include "includes.h"
  8. #include "http.h"
  9. #define BUF_SIZE 100
  10. #define AUTH_FOTA_PORT 9138
  11. #ifdef ENABLE_OPENHPOC
  12. #define FOTA_AUTH_VERSION OHPOC_VERSION
  13. #define FOTA_AUTH_MODLE OHPOC_MODLE
  14. #define FOTA_AUTH_CT OHPOC_CUST
  15. #else
  16. #define FOTA_AUTH_VERSION HPOC_VERSION
  17. #define FOTA_AUTH_MODLE HPOC_MODULE_TYPE
  18. #define FOTA_AUTH_CT CUST_STR
  19. #endif
  20. typedef enum{
  21. AF_IDLE,
  22. AF_WAIT_READY,
  23. AF_READY,
  24. AF_TCP,
  25. AF_TCP_WAIT,
  26. AF_SEND_WAIT_ACK,
  27. AF_WAIT_USER_CONFIRM,
  28. AF_ACK_UPDATE_POC,
  29. AF_STOP,
  30. AF_END
  31. }AF_ENUM;
  32. T_INT16 serverAck=0;
  33. T_INT8 rightFlag=0;//0,unknow result, 1, have right, else no right
  34. T_INT8 wgetPath[64];
  35. T_INT32 targetVersion;
  36. static AF_ENUM fotaStatus=AF_IDLE;
  37. static TUPSEND_DEF tupsendPara;
  38. static void saveAuth(T_INT8 *imei,T_INT8 flag);
  39. static void infoPacketAndSend(T_UINT32 psn,T_INT8 *imei, T_UINT32 version,T_INT8 *modemType,T_UINT8 udpvalue2_3,T_UINT8 udpvalue4);
  40. static T_INT8 RecvDataHandle(T_UINT8 *src, T_UINT16 length);
  41. static void tellHgsPocUpdateUdpByQue(T_UINT8 udptime2_3,T_UINT8 udptime4);
  42. void fillTargetVersion(char *filePath, int *targetversion){
  43. //120.77.66.129/higos/fotaFiles/N58_POC_ZT_2000.bin
  44. //-->120.77.66.129/higos/fotaFiles/N58_POC_ZT_2000.bin
  45. int i;
  46. char findDot=0;
  47. char info[30];
  48. for(i=strlen(filePath)-1;i>=0;i--){
  49. if(findDot==0){
  50. if(filePath[i]=='.') findDot=1;
  51. }else if(filePath[i]=='_'){
  52. *targetversion=atoi(filePath+i+1);
  53. //if(targetversion>HPOC_VERSION){
  54. // filePath[i+1]=0;
  55. // snprintf(info, sizeof(info), "%d%d.pack",HPOC_VERSION,*targetversion);
  56. // strcat(filePath,info);
  57. //}
  58. return;
  59. }
  60. }
  61. }
  62. T_UINT8 tudptime2_3,tudptime4;
  63. /*
  64. authFotaRecv_cb
  65. PLATFORM_MS5700平台udp接收回调操作入口
  66. */
  67. void authFotaRecv_cb(void *param){
  68. unsigned char *pdata;
  69. int len_ret;
  70. //T_UINT8 buffer[BUF_SIZE];
  71. nwy_osiEvent_t *pEvent = (nwy_osiEvent_t *)param;
  72. TUPSEND_DEF *para=(TUPSEND_DEF *)pEvent->param3;
  73. T_BOOL needExitThread=FALSE;
  74. static T_UINT8 handleDataOk=FALSE;
  75. showTupEventInfo("authFota",pEvent->id,para,0);
  76. switch(pEvent->id){
  77. case TUP_EVENT_SOCK_LINK_OK:
  78. if(AF_TCP_WAIT==fotaStatus) fotaStatus=AF_SEND_WAIT_ACK;
  79. break;
  80. // case LSAPI_SOCK_TCPIP_SOCKET_SEND_RSP:break;
  81. // case LSAPI_SOCK_TCPIP_SOCKET_CLOSE_RSP:
  82. // wlog_warn("authfota client close");
  83. // serverAck=-1;
  84. // needExitThread=TRUE;
  85. // break;
  86. case TUP_EVENT_SOCK_LINK_RECV:
  87. pdata=(unsigned char *)pEvent->param1;
  88. len_ret=pEvent->param2;
  89. if(FALSE==handleDataOk){
  90. len_ret=RecvDataHandle(pdata, len_ret);
  91. wlog_info("RecvDataHandle return %d", len_ret);
  92. if(len_ret==0) handleDataOk=TRUE;//成功处理一包后不再处理了
  93. }
  94. break;
  95. case TUP_EVENT_SOCK_LINK_SERVER_SHUT:break;
  96. default: break;
  97. }
  98. // LSAPI_OSI_Free(pEvent);
  99. // if(TRUE==needExitThread) threadPostEvent(nwy_get_current_thread(),USER_EVENT_EXIT);
  100. }
  101. void isAutoFotaIdle(void){
  102. if(fotaStatus==AF_END || fotaStatus==AF_WAIT_USER_CONFIRM) ticketVote(TICKET_PT_AUTH);
  103. else ticketDeVote(TICKET_PT_AUTH);
  104. }
  105. /*
  106. ptAuthFotaTask
  107. 负责授权、FOTA升级任务操作
  108. */
  109. PT_THREAD (ptAuthFotaTask(pt_timer_t *ptPool, struct pt *pt)){
  110. static pt_timer_t ptTimer;
  111. static T_UINT8 index,i;
  112. static T_INT16 timeout;
  113. static T_INT8 ipAddr[20];
  114. T_UINT8 ret;
  115. static T_INT8 *fAddr;
  116. PT_BEGIN(pt);
  117. while(1){
  118. //if(TCP_LOGIN_SUCC==talking.tcpLoginStatus)
  119. //goto PTHREAD_END;
  120. if(AF_IDLE==fotaStatus){
  121. fAddr=paras.fotaServer;
  122. if(talking.netWork.pdp==0 || fAddr==NULL || talking.getImeiFlag==FALSE){
  123. wlog_warn("pdp:%d,imei:%d,fAddr:%s, wait", talking.netWork.pdp,talking.getImeiFlag,fAddr);
  124. fotaStatus=AF_WAIT_READY;
  125. }else fotaStatus=AF_READY;
  126. }else if(AF_WAIT_READY==fotaStatus){
  127. if(talking.netWork.pdp==1 && fAddr != NULL && talking.getImeiFlag==TRUE){
  128. fotaStatus=AF_READY;
  129. wlog_info("authFota:ready");
  130. }
  131. }else if(AF_READY==fotaStatus){
  132. if(FALSE==setDomainForIp(fAddr, &index)){
  133. wlog_warn("authFota domain fun busy, retry later");
  134. PTTimerStart(ptPool, &ptTimer,300);//3 seconds later retry
  135. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  136. }else{
  137. i=0;
  138. while(1){
  139. ret=getDomainForIp(index, ipAddr, sizeof(ipAddr));
  140. if(ret==DOMAIN_ERR){
  141. wlog_error("authFota domain fail , quit");
  142. fotaStatus=AF_END;break;
  143. }else if(DOMAIN_OK==ret){
  144. wlog_info("authFota domain done:%s", ipAddr);
  145. tupParaSet(&tupsendPara, AUTH_FOTA_PORT, authFotaRecv_cb,AUTH_UDP_THREAD_STACK);
  146. fotaStatus=AF_TCP;
  147. break;
  148. }else{
  149. PTTimerStart(ptPool, &ptTimer,50);//wait 0.5 per time
  150. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  151. if(++i>=20){//当AUTH与POC同时处理时,有可能AUTH会比较迟才处理域名结果
  152. wlog_error("authFota domain timeout, quit");
  153. fotaStatus=AF_END;break;
  154. }
  155. }
  156. }
  157. }
  158. }else if(AF_TCP==fotaStatus){
  159. //do tcp connect
  160. if(1==talking.netWork.pdp){
  161. switch(tryConnectTup(ipAddr,TUP_UDP,&tupsendPara)){
  162. case TUP_STATUS_TRUE:
  163. wlog_info("authFota connect server ok");
  164. fotaStatus=AF_SEND_WAIT_ACK;
  165. break;
  166. case TUP_STATUS_FALSE:
  167. wlog_warn("authFota connect server failed, retry after 3 seconds");
  168. PTTimerStart(ptPool, &ptTimer,300);//3 seconds later retry
  169. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  170. break;
  171. case TUP_STATUS_WAIT:
  172. fotaStatus=AF_TCP_WAIT;
  173. break;
  174. }
  175. }
  176. }else if(AF_SEND_WAIT_ACK==fotaStatus){
  177. //send request and wait ack
  178. timeout=5;
  179. do{
  180. if(1==talking.netWork.pdp){
  181. infoPacketAndSend(paras.psn,talking.imei,FOTA_AUTH_VERSION,FOTA_AUTH_MODLE,paras.udpHeartTick_none_4G,paras.udpHeartTick_4G);
  182. timeout--;
  183. }else wlog_warn("pdp of , wait");
  184. PTTimerStart(ptPool, &ptTimer,200);//2 seconds later retry
  185. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  186. }while(timeout && serverAck==0);
  187. saveAuth(talking.imei,rightFlag);
  188. userCloseSocket(&tupsendPara.fd);
  189. if(timeout==0 || serverAck==-1 ||serverAck==0){
  190. msgToOutter("+CSERVER:DENY\r\n");
  191. wlog_warn("udp server no ack, exit");
  192. fotaStatus=AF_END;
  193. goto PTHREAD_END;
  194. }
  195. if(1==serverAck){
  196. wlog_info("get server ack");
  197. tellHgsPocUpdateUdpByQue(tudptime2_3,tudptime4);
  198. }else if(2==serverAck){
  199. wlog_info("no extend info, exit");
  200. fotaStatus=AF_END;
  201. goto PTHREAD_END;
  202. }else{
  203. wlog_info("ack data not fit, exit");
  204. fotaStatus=AF_END;
  205. goto PTHREAD_END;
  206. }
  207. if(FOTA_AUTH_VERSION>=targetVersion){
  208. wlog_info("No new version, exit");
  209. fotaStatus=AF_END;
  210. goto PTHREAD_END;
  211. }
  212. talking.fota_version=targetVersion;
  213. wlog_info("fota is available:%d,%d",FOTA_AUTH_VERSION,targetVersion);
  214. fotaStatus=AF_WAIT_USER_CONFIRM;
  215. }else if(AF_WAIT_USER_CONFIRM==fotaStatus){
  216. if(talking.userFotaConfirm==TRUE){
  217. fotaStatus=AF_ACK_UPDATE_POC;
  218. talking.userFotaConfirm=FALSE;
  219. msgToOutter("+FOTA:1\r\n");
  220. wlog_info("start to update poc");
  221. }
  222. }else if(AF_ACK_UPDATE_POC==fotaStatus){
  223. //try to update poc
  224. tryUpdateLte(wgetPath);
  225. do{
  226. ret=getLteUpdateStatus();
  227. if(ret==LTE_UPDATE_FAILED) fotaStatus=AF_WAIT_USER_CONFIRM;
  228. else if(ret==LTE_UPDATE_DONE) fotaStatus=AF_END;
  229. PTTimerStart(ptPool, &ptTimer,10);//should be fast
  230. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  231. }while(LTE_UPDATE_BUSY==ret);
  232. }else if(AF_TCP_WAIT==fotaStatus){
  233. if(tupsendPara.tupStatus==CNNT_TOUT) fotaStatus=AF_END;
  234. }
  235. PTHREAD_END:
  236. isAutoFotaIdle();
  237. PTTimerStart(ptPool, &ptTimer,100);//should be fast
  238. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  239. }
  240. PT_END(pt);
  241. }
  242. /*
  243. translateBeforeSend
  244. 部标协议数据发送前转义接口
  245. */
  246. static T_UINT16 translateBeforeSend(T_UINT8 *src, T_UINT16 length){
  247. //0x7E-->0X7D,0X02
  248. //0X7D-->0X7D,0X01
  249. T_UINT8 temp[BUF_SIZE*2];
  250. T_UINT16 i,retlen;
  251. retlen=0;
  252. for(i=0;i<length;i++){
  253. if(src[i]==0x7E){
  254. temp[retlen++]=0x7D;
  255. temp[retlen++]=0x02;
  256. }else if(src[i]==0x7D){
  257. temp[retlen++]=0x7D;
  258. temp[retlen++]=0x01;
  259. }else{
  260. temp[retlen++]=src[i];
  261. }
  262. }
  263. memcpy(src, temp, retlen);
  264. return retlen;
  265. }
  266. /*
  267. infoPacketAndSend
  268. 部标协议打包数据并发送
  269. */
  270. static void infoPacketAndSend(
  271. T_UINT32 psn,
  272. T_INT8 *imei,
  273. T_UINT32 version,
  274. T_INT8 *modemType,
  275. T_UINT8 udpvalue2_3,
  276. T_UINT8 udpvalue4){
  277. T_UINT8 sendbuf[BUF_SIZE];
  278. T_UINT8 *ptr=sendbuf;
  279. T_UINT8 *startPtr=sendbuf+1;
  280. T_UINT8 sum=0,*imeiPtr,th,tl;
  281. T_UINT16 i,len;
  282. T_INT8 temp[20];
  283. T_INT32 ret;
  284. static T_UINT16 liushui=0;
  285. len=0;
  286. //make login info
  287. //start indicator
  288. ptr[len++]=0x7E;
  289. //header
  290. //sms type 2bytes
  291. ptr[len++]=0x09;
  292. ptr[len++]=0x29;
  293. //sms property 2bytes
  294. i=59;//only low 10bits are define as sms length
  295. ptr[len++]=i>>8;//no sub packets,no encrypt
  296. ptr[len++]=i;//sms length
  297. //device SN 6bytes
  298. snprintf(temp, sizeof(temp),"%012d",psn);
  299. for(i=0;i<6;i++){
  300. th=temp[2*i];
  301. tl=temp[2*i+1];
  302. th <<= 4;th &= 0xF0;
  303. tl &= 0x0F;
  304. ptr[len++]=th | tl;
  305. }
  306. //serial nuber 2bytes
  307. ptr[len++]=(liushui>>8)&0xFF;
  308. ptr[len++]=liushui&0xFF;
  309. liushui++;
  310. //sms info
  311. //poc modle:EC20TGA_POC 16bytes
  312. memset(&ptr[len], 0, 16);
  313. snprintf(temp, sizeof(temp), "%s_%s",FOTA_AUTH_MODLE,FOTA_AUTH_CT);
  314. memcpy(&ptr[len],temp,16);
  315. len += 16;
  316. //poc version 4bytes
  317. ptr[len++]=version>>24;
  318. ptr[len++]=version>>16;
  319. ptr[len++]=version>>8;
  320. ptr[len++]=version;
  321. //mcu modle 16bytes
  322. memset(&ptr[len], 0, 16);
  323. len += 16;
  324. //mcu version 4bytes
  325. memset(&ptr[len], 0, 4);
  326. len += 4;
  327. //NET CODE:IMEI 16:fill 15bytes
  328. memset(&ptr[len], 0, 16);
  329. memcpy(&ptr[len], imei, 15);
  330. len += 16;
  331. //current udp2_3 heart time 1byte
  332. ptr[len++]=udpvalue2_3;
  333. //current udp4 heart time 1byte
  334. ptr[len++]=udpvalue4;
  335. //current gps upload time 1byte
  336. ptr[len++]=0;
  337. //verify code
  338. for(i=1;i<len;i++) sum ^= sendbuf[i];
  339. ptr[len++]=sum;
  340. //translate
  341. len=translateBeforeSend(sendbuf+1,len-1)+1;
  342. sendbuf[len++]=0x7E;
  343. //printf("Len:%d\r\n",len);
  344. //for(i=0;i<len;i++) printf("%02x",sendbuf[i]);
  345. //printf("\r\n");
  346. //send now
  347. //wlog_info("udp send data len %d\n", len)
  348. trySendTup(sendbuf,len,TUP_UDP,&tupsendPara);
  349. }
  350. /*
  351. translateAfterRecv
  352. 部标协议数据接受后转义接口
  353. */
  354. static T_UINT16 translateAfterRecv(T_UINT8 *src, T_UINT8 *in_src,T_UINT16 length){
  355. T_UINT16 i,retlen=0;
  356. T_UINT8 lastByte=0xff;
  357. T_UINT8 *savePtr=src;
  358. for(i=1;i<length-2;i++){
  359. if(lastByte==0x7D){
  360. if(in_src[i]==0x01){
  361. *savePtr++=0x7D;
  362. retlen++;
  363. }else if(in_src[i]==0x02){
  364. *savePtr++=0x7E;
  365. retlen++;
  366. }else{
  367. *savePtr++=in_src[i];
  368. retlen++;
  369. }
  370. }else{
  371. *savePtr++=in_src[i];
  372. retlen++;
  373. }
  374. lastByte=in_src[i];
  375. }
  376. return retlen;
  377. }
  378. /*
  379. findTargetVersion
  380. 从字符串口获取应用的最新版本号
  381. */
  382. static T_INT32 findTargetVersion(T_INT8 *src){
  383. int i,ver=0;;
  384. char findDot=0;
  385. //M5700_POC_ZT_2006.pack
  386. //M5700_POC_SFE_2006.pack
  387. //M5700_POC_COM_2006.pack
  388. for(i=strlen(src)-1;i>=0;i--){
  389. if(findDot==0){
  390. if(src[i]=='.') findDot=1;
  391. }else if(src[i]=='_'){
  392. return atoi(src+i+1);
  393. }
  394. }
  395. return 0;
  396. }
  397. /*
  398. updateLocalTime
  399. 更新系统时间接口
  400. */
  401. static void updateLocalTime(char *bcdtime){
  402. //19-06-12 11:57:12
  403. MY_CLOCK clock;
  404. clock.year=bcdToDec(bcdtime[0])+2000;
  405. clock.month=bcdToDec(bcdtime[1]);
  406. clock.day=bcdToDec(bcdtime[2]);
  407. clock.hour=bcdToDec(bcdtime[3]);
  408. clock.min=bcdToDec(bcdtime[4]);
  409. clock.sec=bcdToDec(bcdtime[5]);
  410. setMyClock(clock);
  411. wlog_info("UpdateDate:%d-%02d-%02d %02d:%02d:%02d",clock.year,clock.month,clock.day,clock.hour,clock.min,clock.sec);
  412. }
  413. /*
  414. tellHgsPocUpdateUdpByQue
  415. 授权时从服务器发下的应用udp心跳维持时间的更新
  416. */
  417. static void tellHgsPocUpdateUdpByQue(T_UINT8 udptime2_3,T_UINT8 udptime4){
  418. T_INT8 info[30];
  419. snprintf(info, sizeof(info), "+UDP=%d,%d\r\n",udptime2_3,udptime4);
  420. msgFromInner(info, strlen(info));
  421. wlog_warn("Tell info:%s", info);
  422. }
  423. void showtestinfo(char type){
  424. wlog_info("showtest info:%d",type);
  425. nwy_sleep(10);
  426. }
  427. /*
  428. RecvDataHandle
  429. 解析授权响应数据
  430. */
  431. static T_INT8 RecvDataHandle(T_UINT8 *src, T_UINT16 length){
  432. T_UINT16 i,j;
  433. T_INT32 k;
  434. T_UINT8 num_7E=0,sum=0,reallen;
  435. T_UINT16 takenotelen=0,temp;
  436. T_UINT8 temBuf[BUF_SIZE*2];
  437. T_UINT8 *realPtr;
  438. T_UINT8 filePath[80];
  439. T_UINT8 gpsTime;
  440. for(i=0;i<length;i++){
  441. takenotelen++;
  442. if(src[i]==0x7E){
  443. if(++num_7E>=2){
  444. break;
  445. }
  446. }
  447. }
  448. memcpy(temBuf, src,takenotelen);
  449. if(num_7E != 2 || takenotelen<=2) return 1;
  450. j=translateAfterRecv(temBuf,src,takenotelen);
  451. if(j<12) return 2;//header len err
  452. if(temBuf[0] != 0x89 || temBuf[1] != 0x29) return 3;//ID not fit
  453. temp = temBuf[2];temp <<= 8;temp &= 0xFF00;
  454. temp |= temBuf[3];
  455. if(((temp >> 10)&0xF) != 0) return 4;//no support sub packet or encrypt
  456. temp &= 0x3FF;//sms length
  457. if((12+temp) != j) return 5;//packet length err
  458. for(i=0;i<j-0;i++) sum ^= temBuf[i];
  459. if(sum != temBuf[j+1]) return 6;//sum err
  460. realPtr = temBuf + 12+6;
  461. //handle ack info
  462. if(realPtr[0]==1){
  463. rightFlag=1;//have right
  464. updateLocalTime(realPtr-6);
  465. }
  466. else rightFlag=0;//no right
  467. //这里调用tellHgsPocUpdateUdpByQue(realPtr[1],realPtr[2]);好像是不够堆栈,放在外层处理吧
  468. tudptime2_3=realPtr[1];
  469. tudptime4=realPtr[2];
  470. gpsTime=realPtr[3];
  471. realPtr += 4;//point to extend info
  472. temp -= 9;//extend info length
  473. k=temp;
  474. while(k>0){
  475. if(realPtr[0]==1){
  476. //take type 1 info, for poc update
  477. i=realPtr[1];//take length
  478. //decrypt
  479. realPtr += 2;
  480. for(j=0;j<i;j++){
  481. if(j % 2 !=0) filePath[j]=realPtr[j] ^ 0xB8;
  482. else filePath[j]=realPtr[j] ^ 0x56;
  483. }
  484. filePath[j]=0;
  485. wlog_info("Get file path:%s",filePath);
  486. //backup file path
  487. strcpy(wgetPath,filePath);
  488. fillTargetVersion(wgetPath,&targetVersion);
  489. wlog_info("target:%d,%s",targetVersion,wgetPath);
  490. serverAck=1;
  491. return 0;
  492. }else k -= (1+1+realPtr[1]);
  493. }
  494. serverAck=2;
  495. return 7;
  496. }
  497. /*
  498. DecodeImeiBytes
  499. 授权码加密
  500. */
  501. void DecodeImeiBytes(T_INT8 *imei){
  502. T_UINT8 i,j,seeds='w';
  503. j='j';
  504. for(i=0;i<IMEI_SIZE;i++){
  505. imei[i] ^= seeds;
  506. seeds += j;
  507. j += 'l';
  508. }
  509. }
  510. /*
  511. saveAuth
  512. 保存授权码
  513. */
  514. static void saveAuth(T_INT8 *imei,T_INT8 flag){
  515. T_UINT8 writebuf[64],tmp[10];
  516. T_UINT16 length,i;
  517. T_INT8 tempImei[IMEI_SIZE];
  518. memcpy(tempImei, imei,IMEI_SIZE );
  519. switch(flag){
  520. case 0:wlog_warn("auth no save authfile"); return;
  521. case 1:wlog_warn("auth have right");
  522. DecodeImeiBytes(tempImei);break;
  523. case 2:wlog_warn("auth have no right");
  524. default:memset(tempImei,0x55,IMEI_SIZE);
  525. break;
  526. }
  527. length=0;
  528. for(i=0;i<IMEI_SIZE;i++){
  529. snprintf(tmp,sizeof(tmp),"%02x",tempImei[i]);
  530. writebuf[length++]=tmp[0];
  531. writebuf[length++]=tmp[1];
  532. }
  533. //save code bellow
  534. saveAuthEncode(writebuf,length);
  535. }