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 |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 18 | #include "pub_flags.h" |
| 19 | #include "flags_api.h" |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 20 | #endif |
| 21 | #ifdef __cplusplus |
| 22 | extern"C"{ |
| 23 | #endif |
| 24 | extern T_NV_NODE*nv_list; |
| 25 | #ifdef FOTA_AB |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 26 | int get_update_status(void){T_FLAGS_INFO flags_info={(0x872+6138-0x206c)}; |
| 27 | unsigned int status=(0xab1+4701-0x1d0e);int ret=(0xbe7+3997-0x1b84);ret= |
rita | 7189f7e | 2023-11-03 10:46:32 +0800 | [diff] [blame] | 28 | flags_get(&flags_info);status=flags_info.boot_fota_flag.fota_status;if(status== |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 29 | (0x77+16-0x86))return(0xf92+977-0x1361);else return(0xcb3+5679-0x22e2);} |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 30 | #else |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 31 | int get_update_status(void){int update_status;FILE*fd=(0x131a+4105-0x2323);int |
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 32 | ret;char*filename=NULL;if(access(FOTA_UPDATE_STATUS_FILE_OLD,R_OK)== |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 33 | (0x5c8+593-0x819)){filename=FOTA_UPDATE_STATUS_FILE_OLD;}else{filename= |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 34 | FOTA_UPDATE_STATUS_FILE;}printf( |
| 35 | "get_update_status, read_update_status from %s\n",filename);fd=fopen(filename, |
| 36 | "\x72\x62\x2b");if(fd==NULL){printf( |
| 37 | "\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" |
| 38 | ,strerror(errno));goto error0;}ret=fscanf(fd,"\x25\x64",(int*)&update_status);if |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 39 | (ret<(0x1814+608-0x1a74)){printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 40 | "\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" |
| 41 | ,strerror(errno));fclose(fd);goto error0;}printf( |
| 42 | "\x75\x70\x64\x61\x74\x65\x5f\x73\x74\x61\x74\x75\x73\x3d\x25\x64" "\n", |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 43 | update_status);fclose(fd);return update_status;error0:return-(0x6a7+2923-0x1211) |
rita | 7189f7e | 2023-11-03 10:46:32 +0800 | [diff] [blame] | 44 | ;} |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 45 | #endif |
| 46 | int nvupdate(char*nv_file,char*config_file,const char*key,const char*value,int |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 47 | saveFlag){int index=(0x1f12+1265-0x2403);int key_buf_len=(0x10ca+5671-0x26f1); |
| 48 | int value_buf_len=(0x10e1+3265-0x1da2);T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL; |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 49 | T_NV_ITEM*newItem=NULL;if(NULL==key||NULL==value)return RESULT_FAIL;printf( |
| 50 | "\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" |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 51 | ,nv_file,key,value);key_buf_len=strlen(key)+(0x1078+5412-0x259b);value_buf_len= |
| 52 | strlen(value)+(0x98b+5218-0x1dec);for(list=nv_list;list;list=list->next){if( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 53 | strcmp(list->nvFile,nv_file))continue;index=hash(key)%NV_HASH_LEN;for(item=list |
| 54 | ->nvTable[index];item;item=item->next){if(strcmp(item->key,key))continue;if( |
| 55 | saveFlag)item->saveFlag=saveFlag;if(!strcmp(item->value,value)){item-> |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 56 | update_flag=(0xf16+3257-0x1bce);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 57 | "\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" |
| 58 | ,item->key,item->value,value,config_file);return RESULT_SUCCESS;}if(strstr( |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 59 | config_file,"\x75\x73\x65\x72")){if((0xfcb+1301-0x14df)==item->update_flag){ |
rita | 7189f7e | 2023-11-03 10:46:32 +0800 | [diff] [blame] | 60 | 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\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" |
| 62 | ,item->key,item->value,value,config_file);}else{item->update_flag= |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 63 | (0xcc5+3362-0x19e6);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 64 | "\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" |
| 65 | ,item->key,item->value,value,config_file);return RESULT_SUCCESS;}}printf( |
| 66 | "\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" |
| 67 | ,item->key,item->value,value);free(item->value);item->value=(char*)malloc( |
| 68 | value_buf_len);if(!item->value)return RESULT_MALLOC_FAIL;strncpy(item->value, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 69 | value,value_buf_len-(0x1061+4302-0x212e));item->value[value_buf_len- |
| 70 | (0x1bcf+1454-0x217c)]='\0';item->update_flag=(0x2673+18-0x2684);return |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 71 | RESULT_SUCCESS;}newItem=(T_NV_ITEM*)malloc(sizeof(T_NV_ITEM));if(!newItem){ |
| 72 | printf( |
| 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\x31\x20" "\n" |
| 74 | );return RESULT_MALLOC_FAIL;}newItem->key=(char*)malloc(strlen(key)+ |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 75 | (0x18ad+1366-0x1e02));if(!newItem->key){free(newItem);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 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\x32" "\n" |
| 77 | );return RESULT_MALLOC_FAIL;}newItem->value=(char*)malloc(value_buf_len);if(! |
| 78 | newItem->value){free(newItem->key);free(newItem);printf( |
| 79 | "\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" |
| 80 | );return RESULT_MALLOC_FAIL;}strncpy(newItem->key,key,key_buf_len- |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 81 | (0x1c2c+1971-0x23de));newItem->key[key_buf_len-(0x5cc+6410-0x1ed5)]='\0';strncpy |
| 82 | (newItem->value,value,value_buf_len-(0x11d7+834-0x1518));newItem->value[ |
| 83 | value_buf_len-(0x8d9+7699-0x26eb)]='\0';newItem->next=NULL;newItem->saveFlag= |
| 84 | saveFlag;newItem->update_flag=(0xd7a+1778-0x146b);printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 85 | "\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" |
| 86 | ,newItem->key,newItem->value);if(!list->nvTable[index])list->nvTable[index]= |
| 87 | newItem;else{newItem->next=list->nvTable[index]->next;list->nvTable[index]->next |
| 88 | =newItem;}return RESULT_SUCCESS;}return RESULT_FAIL;}int reloadFactroyParam( |
| 89 | T_NV_NODE*list){char*val=NULL;FILE*fp=NULL;T_NV_CONFIG*config=NULL;char buf[ |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 90 | NV_MAX_ITEM_LEN]={(0xa1b+3303-0x1702)};printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 91 | "\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" |
| 92 | ,list->nvFile);for(config=list->fileList;config;config=config->next){printf( |
| 93 | "\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" |
| 94 | ,config->configFile);fp=fopen(config->configFile,"\x72\x6f");if(!fp){printf( |
| 95 | "\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" |
| 96 | ,config->configFile,errno);return RESULT_FILE_OPEN_FAIL;}while(fgets(buf, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 97 | NV_MAX_ITEM_LEN,fp)){if(buf[(0xfaa+123-0x1025)]=='\n'||buf[(0x109c+5580-0x2668)] |
| 98 | ==((char)(0x10c4+5080-0x2479)))continue;val=strchr(buf, |
| 99 | ((char)(0xb5d+1165-0xfad)));if(!val){printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 100 | "\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" |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 101 | ,config->configFile,buf);continue;}buf[strlen(buf)-(0x2103+323-0x2245)]='\0';* |
| 102 | val++='\0';nvupdate(list->nvFile,config->configFile,buf,val,(0xa01+4475-0x1b7b)) |
rita | 7189f7e | 2023-11-03 10:46:32 +0800 | [diff] [blame] | 103 | ;}printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 104 | "\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" |
| 105 | ,config->configFile);fclose(fp);}return RESULT_SUCCESS;}void dump_list(T_NV_ITEM |
| 106 | *list){if(list==NULL){printf( |
| 107 | "\x6c\x69\x73\x74\x20\x69\x73\x20\x6e\x75\x6c\x6c" "\n");return;}T_NV_ITEM*p= |
| 108 | list->next;while(p!=NULL){printf( |
| 109 | "\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" |
| 110 | ,p->key,p->value,((unsigned int)p));p=p->next;}}int delete_not_needed(T_NV_NODE* |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 111 | list){int index=(0x12ab+2750-0x1d69);T_NV_ITEM*item=NULL;T_NV_ITEM head={ |
| 112 | (0x10b+3216-0xd9b)};T_NV_ITEM*prev=&head;printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 113 | "\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" |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 114 | );for(index=(0x28f+7457-0x1fb0);index<NV_HASH_LEN;index++){head.next=list-> |
| 115 | nvTable[index];prev=&head;for(item=prev->next;item;){if((0x1843+126-0x18c0)== |
| 116 | item->update_flag){prev=item;item=item->next;}else{printf( |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 117 | "\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" |
| 118 | ,item->key,item->value);prev->next=item->next;free(item->key);free(item->value); |
| 119 | free(item);item=prev->next;}}list->nvTable[index]=head.next;}printf( |
| 120 | "\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" |
| 121 | );return RESULT_SUCCESS;} |
| 122 | #ifdef __cplusplus |
| 123 | } |
| 124 | #endif |
| 125 | |