lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | |
| 2 | #include <unistd.h> |
| 3 | #include <errno.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <dirent.h> |
| 7 | #include <string.h> |
| 8 | #include <sys/file.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/ipc.h> |
| 12 | #include <sys/msg.h> |
| 13 | #include "nvserver.h" |
| 14 | #include "nv_typedef.h" |
| 15 | #include <message.h> |
| 16 | #include <fota_common.h> |
| 17 | #ifdef FOTA_AB |
| 18 | #include "zxic_fota_ab_upgrade.h" |
| 19 | #endif |
| 20 | #ifdef __cplusplus |
| 21 | extern"C"{ |
| 22 | #endif |
| 23 | extern T_NV_NODE*nv_list; |
| 24 | #ifdef FOTA_AB |
| 25 | int get_update_status(void){int ret=dual_AB_get_fota_status_for_nv();if(ret== |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 26 | (0x999+318-0xad6))return(0x173+1220-0x635);else return(0x130a+602-0x1564);} |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 27 | #else |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 28 | int get_update_status(void){int update_status;FILE*fd=(0xa38+3938-0x199a);int |
| 29 | ret;char*filename=NULL;if(access(FOTA_UPDATE_STATUS_FILE_OLD,R_OK)== |
| 30 | (0x870+3973-0x17f5)){filename=FOTA_UPDATE_STATUS_FILE_OLD;}else{filename= |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 31 | FOTA_UPDATE_STATUS_FILE;}printf( |
| 32 | "get_update_status, read_update_status from %s\n",filename);fd=fopen(filename, |
| 33 | "\x72\x62\x2b");if(fd==NULL){printf( |
| 34 | "\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" |
| 35 | ,strerror(errno));goto error0;}ret=fscanf(fd,"\x25\x64",(int*)&update_status);if |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 36 | (ret<(0x2a2+201-0x36b)){printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 37 | "\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" |
| 38 | ,strerror(errno));fclose(fd);goto error0;}printf( |
| 39 | "\x75\x70\x64\x61\x74\x65\x5f\x73\x74\x61\x74\x75\x73\x3d\x25\x64" "\n", |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 40 | update_status);fclose(fd);return update_status;error0:return-(0x7ad+7742-0x25ea) |
| 41 | ;} |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 42 | #endif |
| 43 | int nvupdate(char*nv_file,char*config_file,const char*key,const char*value,int |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 44 | saveFlag){int index=(0x431+1502-0xa0f);int key_buf_len=(0xc71+64-0xcb1);int |
| 45 | value_buf_len=(0x553+6951-0x207a);T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 46 | T_NV_ITEM*newItem=NULL;if(NULL==key||NULL==value)return RESULT_FAIL;printf( |
| 47 | "\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" |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 48 | ,nv_file,key,value);key_buf_len=strlen(key)+(0xda+4091-0x10d4);value_buf_len= |
| 49 | strlen(value)+(0x8b+8660-0x225e);for(list=nv_list;list;list=list->next){if( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 50 | strcmp(list->nvFile,nv_file))continue;index=hash(key)%NV_HASH_LEN;for(item=list |
| 51 | ->nvTable[index];item;item=item->next){if(strcmp(item->key,key))continue;if( |
| 52 | saveFlag)item->saveFlag=saveFlag;if(!strcmp(item->value,value)){item-> |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 53 | update_flag=(0x5a4+6662-0x1fa9);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 54 | "\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" |
| 55 | ,item->key,item->value,value,config_file);return RESULT_SUCCESS;}if(strstr( |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 56 | config_file,"\x75\x73\x65\x72")){if((0xd8c+1756-0x1467)==item->update_flag){ |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 57 | printf( |
| 58 | "\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" |
| 59 | ,item->key,item->value,value,config_file);}else{item->update_flag= |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 60 | (0x16fc+89-0x1754);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 61 | "\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" |
| 62 | ,item->key,item->value,value,config_file);return RESULT_SUCCESS;}}printf( |
| 63 | "\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" |
| 64 | ,item->key,item->value,value);free(item->value);item->value=(char*)malloc( |
| 65 | value_buf_len);if(!item->value)return RESULT_MALLOC_FAIL;strncpy(item->value, |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 66 | value,value_buf_len-(0x15e9+2371-0x1f2b));item->value[value_buf_len- |
| 67 | (0x30+6450-0x1961)]='\0';item->update_flag=(0x1047+2801-0x1b37);return |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 68 | RESULT_SUCCESS;}newItem=(T_NV_ITEM*)malloc(sizeof(T_NV_ITEM));if(!newItem){ |
| 69 | printf( |
| 70 | "\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" |
| 71 | );return RESULT_MALLOC_FAIL;}newItem->key=(char*)malloc(strlen(key)+ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 72 | (0x1bf+8770-0x2400));if(!newItem->key){free(newItem);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 73 | "\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" |
| 74 | );return RESULT_MALLOC_FAIL;}newItem->value=(char*)malloc(value_buf_len);if(! |
| 75 | newItem->value){free(newItem->key);free(newItem);printf( |
| 76 | "\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" |
| 77 | );return RESULT_MALLOC_FAIL;}strncpy(newItem->key,key,key_buf_len- |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 78 | (0x1737+3997-0x26d3));newItem->key[key_buf_len-(0x573+2465-0xf13)]='\0';strncpy( |
| 79 | newItem->value,value,value_buf_len-(0x24c3+480-0x26a2));newItem->value[ |
| 80 | value_buf_len-(0xa5d+1659-0x10d7)]='\0';newItem->next=NULL;newItem->saveFlag= |
| 81 | saveFlag;newItem->update_flag=(0x511+7176-0x2118);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 82 | "\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" |
| 83 | ,newItem->key,newItem->value);if(!list->nvTable[index])list->nvTable[index]= |
| 84 | newItem;else{newItem->next=list->nvTable[index]->next;list->nvTable[index]->next |
| 85 | =newItem;}return RESULT_SUCCESS;}return RESULT_FAIL;}int reloadFactroyParam( |
| 86 | T_NV_NODE*list){char*val=NULL;FILE*fp=NULL;T_NV_CONFIG*config=NULL;char buf[ |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 87 | NV_MAX_ITEM_LEN]={(0x9e8+3243-0x1693)};printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 88 | "\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" |
| 89 | ,list->nvFile);for(config=list->fileList;config;config=config->next){printf( |
| 90 | "\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" |
| 91 | ,config->configFile);fp=fopen(config->configFile,"\x72\x6f");if(!fp){printf( |
| 92 | "\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" |
| 93 | ,config->configFile,errno);return RESULT_FILE_OPEN_FAIL;}while(fgets(buf, |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 94 | NV_MAX_ITEM_LEN,fp)){if(buf[(0x579+4079-0x1568)]=='\n'||buf[(0x2b8+3136-0xef8)] |
| 95 | ==((char)(0xf70+3343-0x1c5c)))continue;val=strchr(buf,((char)(0x8a+4197-0x10b2)) |
| 96 | );if(!val){printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 97 | "\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" |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 98 | ,config->configFile,buf);continue;}buf[strlen(buf)-(0x2299+1021-0x2695)]='\0';* |
| 99 | val++='\0';nvupdate(list->nvFile,config->configFile,buf,val,(0x3fb+3242-0x10a4)) |
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 100 | ;}printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 101 | "\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" |
| 102 | ,config->configFile);fclose(fp);}return RESULT_SUCCESS;}void dump_list(T_NV_ITEM |
| 103 | *list){if(list==NULL){printf( |
| 104 | "\x6c\x69\x73\x74\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n");return;}T_NV_ITEM*p= |
| 105 | list->next;while(p!=NULL){printf( |
| 106 | "\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" |
| 107 | ,p->key,p->value,((unsigned int)p));p=p->next;}}int delete_not_needed(T_NV_NODE* |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 108 | list){int index=(0x286+7147-0x1e71);T_NV_ITEM*item=NULL;T_NV_ITEM head={ |
| 109 | (0x92b+3549-0x1708)};T_NV_ITEM*prev=&head;printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 110 | "\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" |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 111 | );for(index=(0x1394+248-0x148c);index<NV_HASH_LEN;index++){head.next=list-> |
| 112 | nvTable[index];prev=&head;for(item=prev->next;item;){if((0xe0+7470-0x1e0d)==item |
| 113 | ->update_flag){prev=item;item=item->next;}else{printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 114 | "\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" |
| 115 | ,item->key,item->value);prev->next=item->next;free(item->key);free(item->value); |
| 116 | free(item);item=prev->next;}}list->nvTable[index]=head.next;}printf( |
| 117 | "\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" |
| 118 | );return RESULT_SUCCESS;} |
| 119 | #ifdef __cplusplus |
| 120 | } |
| 121 | #endif |
| 122 | |