blob: 7b59cd8b16f1b5b45eeeaa6d5d59b21a2a6a9be1 [file] [log] [blame]
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "nvserver.h"
#include "nv_typedef.h"
#include <message.h>
#include <fota_common.h>
#ifdef FOTA_AB
#include "pub_flags.h"
#include "flags_api.h"
#endif
#ifdef __cplusplus
extern"C"{
#endif
extern T_NV_NODE*nv_list;
#ifdef FOTA_AB
int get_update_status(void){T_FLAGS_INFO flags_info={(0x102f+2359-0x1966)};
unsigned int status=(0xbc2+2223-0x1471);int ret=(0x7d8+6796-0x2264);ret=
flags_get(&flags_info);status=flags_info.boot_fota_flag.fota_status;if(status==
(0x12b8+515-0x14ba))return(0xd94+2553-0x178b);else return(0x4e2+7536-0x2252);}
#else
int get_update_status(void){int update_status;FILE*fd=(0x6bf+3121-0x12f0);int
ret;char*filename=NULL;if(access(FOTA_UPDATE_STATUS_FILE_OLD,R_OK)==
(0xf6b+1319-0x1492)){filename=FOTA_UPDATE_STATUS_FILE_OLD;}else{filename=
FOTA_UPDATE_STATUS_FILE;}printf(
"get_update_status, read_update_status from %s\n",filename);fd=fopen(filename,
"\x72\x62\x2b");if(fd==NULL){printf(
"\x5b\x6e\x76\x73\x65\x72\x76\x65\x72\x5d\x75\x70\x64\x61\x74\x65\x5f\x73\x74\x61\x74\x75\x73\x20\x6f\x70\x65\x6e\x20\x20\x65\x72\x72\x6f\x72\x3a\x25\x73" "\n"
,strerror(errno));goto error0;}ret=fscanf(fd,"\x25\x64",(int*)&update_status);if
(ret<(0x857+52-0x88b)){printf(
"\x67\x65\x74\x20\x69\x6e\x66\x6f\x20\x66\x72\x6f\x6d\x20\x66\x69\x6c\x65\x20\x65\x72\x72\x6f\x72\x3a\x25\x73" "\n"
,strerror(errno));fclose(fd);goto error0;}printf(
"\x75\x70\x64\x61\x74\x65\x5f\x73\x74\x61\x74\x75\x73\x3d\x25\x64" "\n",
update_status);fclose(fd);return update_status;error0:return-(0x77b+5798-0x1e20)
;}
#endif
int nvupdate(char*nv_file,char*config_file,const char*key,const char*value,int
saveFlag){int index=(0xe06+2388-0x175a);int key_buf_len=(0x41+2998-0xbf7);int
value_buf_len=(0x2316+827-0x2651);T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL;
T_NV_ITEM*newItem=NULL;if(NULL==key||NULL==value)return RESULT_FAIL;printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6e\x76\x75\x70\x64\x61\x74\x65\x20\x6e\x76\x5f\x66\x69\x6c\x65\x3a\x25\x73\x20\x6b\x65\x79\x3a\x25\x73\x20\x76\x61\x6c\x75\x65\x3a\x25\x73" "\n"
,nv_file,key,value);key_buf_len=strlen(key)+(0x9b6+4534-0x1b6b);value_buf_len=
strlen(value)+(0x1ac9+2440-0x2450);for(list=nv_list;list;list=list->next){if(
strcmp(list->nvFile,nv_file))continue;index=hash(key)%NV_HASH_LEN;for(item=list
->nvTable[index];item;item=item->next){if(strcmp(item->key,key))continue;if(
saveFlag)item->saveFlag=saveFlag;if(!strcmp(item->value,value)){item->
update_flag=(0x375+119-0x3eb);printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6e\x76\x75\x70\x64\x61\x74\x65\x20\x73\x61\x6d\x65\x73\x6b\x69\x70\x3a\x69\x74\x65\x6d\x2d\x3e\x6b\x65\x79\x3a\x25\x73\x20\x69\x74\x65\x6d\x2d\x3e\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x63\x6f\x6e\x66\x69\x67\x5f\x66\x69\x6c\x65\x3a\x25\x73" "\n"
,item->key,item->value,value,config_file);return RESULT_SUCCESS;}if(strstr(
config_file,"\x75\x73\x65\x72")){if((0x125c+47-0x128a)==item->update_flag){
printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6e\x76\x75\x70\x64\x61\x74\x65\x20\x73\x65\x63\x6f\x6e\x64\x20\x63\x68\x61\x6e\x67\x65\x3a\x69\x74\x65\x6d\x2d\x3e\x6b\x65\x79\x3a\x25\x73\x20\x69\x74\x65\x6d\x2d\x3e\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x63\x6f\x6e\x66\x69\x67\x5f\x66\x69\x6c\x65\x3a\x25\x73" "\n"
,item->key,item->value,value,config_file);}else{item->update_flag=
(0x1499+2326-0x1dae);printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6e\x76\x75\x70\x64\x61\x74\x65\x20\x75\x73\x65\x72\x73\x6b\x69\x70\x3a\x69\x74\x65\x6d\x2d\x3e\x6b\x65\x79\x3a\x25\x73\x20\x69\x74\x65\x6d\x2d\x3e\x76\x61\x6c\x75\x65\x31\x3a\x25\x73\x20\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x63\x6f\x6e\x66\x69\x67\x5f\x66\x69\x6c\x65\x3a\x25\x73" "\n"
,item->key,item->value,value,config_file);return RESULT_SUCCESS;}}printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6b\x65\x79\x3d\x25\x73\x20\x63\x68\x61\x6e\x67\x65\x20\x76\x61\x6c\x75\x65\x3a\x25\x73\x20\x74\x6f\x20\x76\x61\x6c\x75\x65\x3d\x25\x73\x20" "\n"
,item->key,item->value,value);free(item->value);item->value=(char*)malloc(
value_buf_len);if(!item->value)return RESULT_MALLOC_FAIL;strncpy(item->value,
value,value_buf_len-(0x1ecb+1238-0x23a0));item->value[value_buf_len-
(0x1df9+326-0x1f3e)]='\0';item->update_flag=(0x4ec+8581-0x2670);return
RESULT_SUCCESS;}newItem=(T_NV_ITEM*)malloc(sizeof(T_NV_ITEM));if(!newItem){
printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x52\x45\x53\x55\x4c\x54\x5f\x4d\x41\x4c\x4c\x4f\x43\x5f\x46\x41\x49\x4c\x31\x20" "\n"
);return RESULT_MALLOC_FAIL;}newItem->key=(char*)malloc(strlen(key)+
(0x894+5890-0x1f95));if(!newItem->key){free(newItem);printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x52\x45\x53\x55\x4c\x54\x5f\x4d\x41\x4c\x4c\x4f\x43\x5f\x46\x41\x49\x4c\x32" "\n"
);return RESULT_MALLOC_FAIL;}newItem->value=(char*)malloc(value_buf_len);if(!
newItem->value){free(newItem->key);free(newItem);printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x52\x45\x53\x55\x4c\x54\x5f\x4d\x41\x4c\x4c\x4f\x43\x5f\x46\x41\x49\x4c\x33\x20" "\n"
);return RESULT_MALLOC_FAIL;}strncpy(newItem->key,key,key_buf_len-
(0xc99+2485-0x164d));newItem->key[key_buf_len-(0x114+7411-0x1e06)]='\0';strncpy(
newItem->value,value,value_buf_len-(0x1698+3150-0x22e5));newItem->value[
value_buf_len-(0x1090+1126-0x14f5)]='\0';newItem->next=NULL;newItem->saveFlag=
saveFlag;newItem->update_flag=(0x19a7+979-0x1d79);printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x61\x64\x64\x20\x6b\x65\x79\x3d\x25\x73\x2c\x20\x76\x61\x6c\x75\x65\x3d\x25\x73\x20" "\n"
,newItem->key,newItem->value);if(!list->nvTable[index])list->nvTable[index]=
newItem;else{newItem->next=list->nvTable[index]->next;list->nvTable[index]->next
=newItem;}return RESULT_SUCCESS;}return RESULT_FAIL;}int reloadFactroyParam(
T_NV_NODE*list){char*val=NULL;FILE*fp=NULL;T_NV_CONFIG*config=NULL;char buf[
NV_MAX_ITEM_LEN]={(0x332+6202-0x1b6c)};printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x72\x65\x6c\x6f\x61\x64\x46\x61\x63\x74\x72\x6f\x79\x50\x61\x72\x61\x6d\x20\x6e\x76\x46\x69\x6c\x65\x3a\x25\x73" "\n"
,list->nvFile);for(config=list->fileList;config;config=config->next){printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x72\x65\x6c\x6f\x61\x64\x46\x61\x63\x74\x72\x6f\x79\x50\x61\x72\x61\x6d\x20\x63\x6f\x6e\x66\x69\x67\x46\x69\x6c\x65\x20\x73\x74\x61\x72\x74\x3a\x25\x73\x21" "\n"
,config->configFile);fp=fopen(config->configFile,"\x72\x6f");if(!fp){printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x6f\x70\x65\x6e\x20\x25\x73\x20\x66\x69\x6c\x65\x20\x66\x61\x69\x6c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64\x21" "\n"
,config->configFile,errno);return RESULT_FILE_OPEN_FAIL;}while(fgets(buf,
NV_MAX_ITEM_LEN,fp)){if(buf[(0x4d+1358-0x59b)]=='\n'||buf[(0x2e0+7741-0x211d)]==
((char)(0x1c57+1033-0x203d)))continue;val=strchr(buf,((char)(0xc42+3951-0x1b74))
);if(!val){printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x25\x73\x20\x66\x69\x6c\x65\x20\x66\x6f\x72\x6d\x61\x74\x20\x65\x72\x72\x6f\x72\x3a\x73\x74\x72\x69\x6e\x67\x20\x3d\x20\x25\x73" "\n"
,config->configFile,buf);continue;}buf[strlen(buf)-(0x2324+127-0x23a2)]='\0';*
val++='\0';nvupdate(list->nvFile,config->configFile,buf,val,(0xce3+3333-0x19e7))
;}printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x72\x65\x6c\x6f\x61\x64\x46\x61\x63\x74\x72\x6f\x79\x50\x61\x72\x61\x6d\x20\x63\x6f\x6e\x66\x69\x67\x46\x69\x6c\x65\x20\x65\x6e\x64\x3a\x25\x73\x21" "\n"
,config->configFile);fclose(fp);}return RESULT_SUCCESS;}void dump_list(T_NV_ITEM
*list){if(list==NULL){printf(
"\x6c\x69\x73\x74\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n");return;}T_NV_ITEM*p=
list->next;while(p!=NULL){printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x64\x75\x6d\x70\x20\x6b\x65\x79\x3d\x25\x73\x2c\x20\x76\x61\x6c\x75\x65\x3d\x25\x73\x2c\x20\x70\x3d\x30\x78\x25\x78" "\n"
,p->key,p->value,((unsigned int)p));p=p->next;}}int delete_not_needed(T_NV_NODE*
list){int index=(0x1d27+2512-0x26f7);T_NV_ITEM*item=NULL;T_NV_ITEM head={
(0xa87+5859-0x216a)};T_NV_ITEM*prev=&head;printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x64\x65\x6c\x65\x74\x65\x5f\x6e\x6f\x74\x5f\x6e\x65\x65\x64\x65\x64\x20\x65\x6e\x74\x65\x72\x20\x2a\x2a\x2a" "\n"
);for(index=(0x1185+2652-0x1be1);index<NV_HASH_LEN;index++){head.next=list->
nvTable[index];prev=&head;for(item=prev->next;item;){if((0x11ac+1175-0x1642)==
item->update_flag){prev=item;item=item->next;}else{printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x64\x65\x6c\x65\x74\x65\x20\x6b\x65\x79\x3d\x25\x73\x2c\x20\x76\x61\x6c\x75\x65\x3d\x25\x73\x20" "\n"
,item->key,item->value);prev->next=item->next;free(item->key);free(item->value);
free(item);item=prev->next;}}list->nvTable[index]=head.next;}printf(
"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x64\x65\x6c\x65\x74\x65\x5f\x6e\x6f\x74\x5f\x6e\x65\x65\x64\x65\x64\x20\x65\x6e\x64\x20\x2a\x2a\x2a" "\n"
);return RESULT_SUCCESS;}
#ifdef __cplusplus
}
#endif