[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/zte_comm/nvserver/file.c b/ap/app/zte_comm/nvserver/file.c
new file mode 100755
index 0000000..1583747
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/file.c
@@ -0,0 +1,134 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#define FAST_FUNC
+
+ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count)
+{
+ ssize_t n;
+
+ for (;;) {
+ n = read(fd, buf, count);
+ if (n >= 0 || errno != EINTR)
+ break;
+ /* Some callers set errno=0, are upset when they see EINTR.
+ * Returning EINTR is wrong since we retry read(),
+ * the "error" was transient.
+ */
+ errno = 0;
+ /* repeat the read() */
+ }
+
+ return n;
+}
+
+/*
+ * Read all of the supplied buffer from a file.
+ * This does multiple reads as necessary.
+ * Returns the amount read, or -1 on an error.
+ * A short read is returned on an end of file.
+ */
+ssize_t FAST_FUNC full_read(int fd, void *buf, size_t len)
+{
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while (len) {
+ cc = safe_read(fd, buf, len);
+
+ if (cc < 0) {
+ if (total) {
+ /* we already have some! */
+ /* user can do another read to know the error code */
+ return total;
+ }
+ return cc; /* read() returns -1 on failure. */
+ }
+ if (cc == 0)
+ break;
+ buf = ((char *)buf) + cc;
+ total += cc;
+ len -= cc;
+ }
+
+ return total;
+}
+
+ssize_t FAST_FUNC read_close(int fd, void *buf, size_t size)
+{
+ /*int e;*/
+ size = full_read(fd, buf, size);
+ /*e = errno;*/
+ close(fd);
+ /*errno = e;*/
+ return size;
+}
+
+ssize_t FAST_FUNC open_read_close(const char *filename, void *buf, size_t size)
+{
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return fd;
+ return read_close(fd, buf, size);
+}
+
+ssize_t FAST_FUNC safe_write(int fd, const void *buf, size_t count)
+{
+ ssize_t n;
+
+ for (;;) {
+ n = write(fd, buf, count);
+ if (n >= 0 || errno != EINTR)
+ break;
+ /* Some callers set errno=0, are upset when they see EINTR.
+ * Returning EINTR is wrong since we retry write(),
+ * the "error" was transient.
+ */
+ errno = 0;
+ /* repeat the write() */
+ }
+
+ return n;
+}
+
+ssize_t FAST_FUNC full_write(int fd, const void *buf, size_t len)
+{
+ ssize_t cc;
+ ssize_t total;
+
+ total = 0;
+
+ while (len) {
+ cc = safe_write(fd, buf, len);
+
+ if (cc < 0) {
+ if (total) {
+ /* we already wrote some! */
+ /* user can do another write to know the error code */
+ return total;
+ }
+ return cc; /* write() returns -1 on failure. */
+ }
+
+ total += cc;
+ buf = ((const char *)buf) + cc;
+ len -= cc;
+ }
+
+ return total;
+}
diff --git a/ap/app/zte_comm/nvserver/nvserver.c b/ap/app/zte_comm/nvserver/nvserver.c
new file mode 100755
index 0000000..6e1f654
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/nvserver.c
@@ -0,0 +1,286 @@
+
+#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>
+#ifdef FOTA_AB
+#include "zxic_fota_ab_upgrade.h"
+#endif
+#ifdef __cplusplus
+extern"C"{
+#endif
+static void nvConfig();static void nvInit();static int nvDirInit();static void
+analyMsg(T_NV_MSG_INFO*msgrecv,T_NV_MSG_RESULT*msgsnd);static bool checkNvFs(
+char*file);static bool isCfgConfiged(char*configFile);static bool isNvConfiged(
+char*configFile);static uint getSum(const char*s,int len);static int
+loadFactroyParam(T_NV_NODE*list);static int restoreNvFs(char*dstFile,char*
+srcFile);static int loadNvFs(char*file);static int addConfigFile(char*nvFile,
+char*configFile);static int saveNvFs(char*nvName,char*nvFile);static int nvset(
+char*file,const char*key,const char*value,int saveFlag);static int nvget(char*
+file,char*key,char*value);static int nvunset(char*file,char*key);static int
+nvclear(char*file);static int nvreset(char*file);static int nvcommit(char*file);
+T_NV_NODE*nv_list;int nvserver_main(int argc,char*argv[]){int msgId=
+(0xaea+4144-0x1b1a);T_NV_MSG_INFO rcvBuf;T_NV_MSG_RESULT sndBuf;struct msqid_ds
+msgInfo;prctl(PR_SET_NAME,"\x6e\x76\x73\x65\x72\x76\x65\x72",
+(0x1611+1505-0x1bf2),(0x1c14+191-0x1cd3),(0x153+9135-0x2502));memset(&rcvBuf,
+(0x1f8+7402-0x1ee2),sizeof(rcvBuf));memset(&sndBuf,(0x96a+6783-0x23e9),sizeof(
+sndBuf));memset(&msgInfo,(0x27+2084-0x84b),sizeof(msgInfo));msgId=msgget(
+MODULE_ID_NV,IPC_CREAT|(0x1298+4145-0x2149));if(-(0x1c87+666-0x1f20)==msgId){
+printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x6d\x73\x67\x67\x65\x74\x20\x6d\x73\x67\x49\x64\x20\x66\x61\x69\x6c\x2c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,errno);return-(0x84a+2941-0x13c6);}if(-(0x135+7698-0x1f46)!=msgctl(msgId,
+IPC_STAT,&msgInfo)){msgInfo.msg_qbytes=262144;if(-(0x18fd+2884-0x2440)==msgctl(
+msgId,IPC_SET,&msgInfo))printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x6d\x73\x67\x63\x74\x6c\x20\x6d\x73\x67\x49\x64\x20\x66\x61\x69\x6c\x2c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,errno);}if(nvDirInit()!=(0x209f+1040-0x24af)){printf(
+"\x6e\x76\x44\x69\x72\x49\x6e\x69\x74\x20\x66\x61\x69\x6c\x65\x21" "\n");return-
+(0x5e2+1420-0xb6d);}nvConfig();nvInit();while((0xa10+526-0xc1d)){if(-
+(0x17ea+2632-0x2231)==msgrcv(msgId,&rcvBuf,sizeof(T_NV_MSG_INFO)-sizeof(long),
+MSG_TYPE_NV,(0x1790+1510-0x1d76))){printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6d\x73\x67\x72\x63\x76\x20\x66\x61\x69\x6c\x2c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64\x21" "\n"
+,errno);continue;}analyMsg(&rcvBuf,&sndBuf);if(-(0x481+1369-0x9d9)==msgsnd(msgId
+,&sndBuf,sizeof(T_NV_MSG_RESULT)-sizeof(long),(0xa0d+5724-0x2069))){printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6d\x73\x67\x73\x6e\x64\x20\x66\x61\x69\x6c\x2c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64\x21" "\n"
+,errno);continue;}}return((0x12e7+4257-0x2388));}static void configdir(char*dir)
+{DIR*dp;int ret;struct dirent*entry;struct stat statbuf;if((dp=opendir(dir))==
+NULL){fprintf(stderr,
+"\x63\x61\x6e\x6e\x6f\x74\x20\x6f\x70\x65\x6e\x20\x64\x69\x72\x65\x63\x74\x6f\x72\x79\x3a\x20\x25\x73" "\n"
+,dir);return;}chdir(dir);while((entry=readdir(dp))!=NULL){ret=lstat(entry->
+d_name,&statbuf);if(ret<(0x1c2+3334-0xec8)){fprintf(stderr,
+"\x6c\x73\x74\x61\x74\x20\x65\x72\x72\x6f\x72\x3a\x20\x25\x73" "\n",strerror(
+errno));chdir("\x2e\x2e");closedir(dp);return;}if(!S_ISDIR(statbuf.st_mode)){if(
+strcmp("\x2e",entry->d_name)==(0x1d74+1056-0x2194)||strcmp("\x2e\x2e",entry->
+d_name)==(0xd8a+532-0xf9e))continue;if(!isNvConfiged(entry->d_name)){if(
+addConfigFile(entry->d_name,NULL)!=RESULT_SUCCESS)printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x63\x6f\x6e\x66\x69\x67\x20\x25\x73\x20\x65\x72\x72\x6f\x72\x21" "\n"
+,entry->d_name);}}}chdir("\x2e\x2e");closedir(dp);}static void nvConfig(){char*
+val=NULL;FILE*fp=NULL;char buf[NV_MAX_CONFIG_LEN]={(0x70c+4185-0x1765)};fp=fopen
+(NV_CONFIG_FILE,"\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"
+,NV_CONFIG_FILE,errno);return;}while(fgets(buf,NV_MAX_CONFIG_LEN,fp)){if(buf[
+(0x894+93-0x8f1)]=='\n'||buf[(0x18ab+891-0x1c26)]==((char)(0x312+4389-0x1414)))
+continue;val=strchr(buf,((char)(0x5e0+3374-0x12d1)));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\x20\x73\x74\x72\x20\x3d\x20\x25\x73\x21" "\n"
+,NV_CONFIG_FILE,buf);continue;}buf[strlen(buf)-(0xcec+6363-0x25c6)]='\0';*val++=
+'\0';if(!isCfgConfiged(buf)){if(addConfigFile(val,buf)!=RESULT_SUCCESS)printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x63\x6f\x6e\x66\x69\x67\x20\x25\x73\x20\x65\x72\x72\x6f\x72\x21" "\n"
+,buf);}}fclose(fp);configdir(NV_FS_MAIN_PATH);}static int nvDirInit(){if(access(
+NV_FS_PATH,F_OK)!=(0x2fd+1808-0xa0d)){if(mkdir(NV_FS_PATH,(0x2df+3050-0xcdc))!=
+(0x7a7+3590-0x15ad)){printf(
+"\x6e\x65\x72\x76\x65\x72\x20\x6d\x6b\x64\x69\x72\x20\x25\x73\x20\x66\x61\x6c\x69\x2c\x65\x72\x72\x6e\x6f\x3d\x25\x64" "\n"
+,NV_FS_PATH,errno);return-(0x532+691-0x7e4);}if(mkdir(NV_FS_MAIN_PATH,
+(0x459+3006-0xe2a))!=(0x217+5370-0x1711)){printf(
+"\x6e\x65\x72\x76\x65\x72\x20\x6d\x6b\x64\x69\x72\x20\x25\x73\x20\x66\x61\x6c\x69\x2c\x65\x72\x72\x6e\x6f\x3d\x25\x64" "\n"
+,NV_FS_MAIN_PATH,errno);return-(0x1463+3947-0x23cd);}if(mkdir(NV_FS_BACKUP_PATH,
+(0x4a5+5946-0x19f2))!=(0x12f2+2574-0x1d00)){printf(
+"\x6e\x65\x72\x76\x65\x72\x20\x6d\x6b\x64\x69\x72\x20\x25\x73\x20\x66\x61\x6c\x69\x2c\x65\x72\x72\x6e\x6f\x3d\x25\x64" "\n"
+,NV_FS_BACKUP_PATH,errno);return-(0x223+1253-0x707);}}else{if(access(
+NV_FS_MAIN_PATH,F_OK)!=(0xa5f+5243-0x1eda)){if(mkdir(NV_FS_MAIN_PATH,
+(0x259+217-0x145))!=(0xeea+4988-0x2266)){printf(
+"\x6e\x65\x72\x76\x65\x72\x20\x6d\x6b\x64\x69\x72\x20\x25\x73\x20\x66\x61\x6c\x69\x2c\x65\x72\x72\x6e\x6f\x3d\x25\x64" "\n"
+,NV_FS_MAIN_PATH,errno);return-(0x1567+686-0x1814);}}if(access(NV_FS_BACKUP_PATH
+,F_OK)!=(0xcb3+249-0xdac)){if(mkdir(NV_FS_BACKUP_PATH,(0x1825+114-0x16aa))!=
+(0x1574+4254-0x2612)){printf(
+"\x6e\x65\x72\x76\x65\x72\x20\x6d\x6b\x64\x69\x72\x20\x25\x73\x20\x66\x61\x6c\x69\x2c\x65\x72\x72\x6e\x6f\x3d\x25\x64" "\n"
+,NV_FS_BACKUP_PATH,errno);return-(0x1a5a+656-0x1ce9);}}}return(0x29+4739-0x12ac)
+;}static void nvInit(){T_NV_NODE*list=NULL;char nvMainFile[NV_PATH_LEN]={
+(0x1a5+93-0x202)};char nvBackupFile[NV_PATH_LEN]={(0x1139+761-0x1432)};for(list=
+nv_list;list;list=list->next){snprintf(nvMainFile,NV_PATH_LEN,
+"\x25\x73\x2f\x25\x73",NV_FS_MAIN_PATH,list->nvFile);snprintf(nvBackupFile,
+NV_PATH_LEN,"\x25\x73\x2f\x25\x73",NV_FS_BACKUP_PATH,list->nvFile);if(checkNvFs(
+nvMainFile)){if(!checkNvFs(nvBackupFile))restoreNvFs(nvBackupFile,nvMainFile);}
+else if(checkNvFs(nvBackupFile)){restoreNvFs(nvMainFile,nvBackupFile);}else{
+loadFactroyParam(list);nvcommit(list->nvFile);continue;}loadNvFs(list->nvFile);
+if(!strcmp(list->nvFile,NV_CFG)&&get_update_status()==(0x1124+2190-0x19b0)){
+reloadFactroyParam(list);delete_not_needed(list);nvcommit(list->nvFile);
+#ifdef FOTA_AB
+dual_AB_set_fota_status_for_nv((0x16fc+1753-0x1dd5));
+#endif
+}}}uint hash(const char*s){uint hash=(0x749+6614-0x211f);while(*s){hash=
+NV_HASH_MUL*hash+*s++;}return hash;}static int loadFactroyParam(T_NV_NODE*list){
+char*val=NULL;FILE*fp=NULL;T_NV_CONFIG*config=NULL;char buf[NV_MAX_ITEM_LEN]={
+(0x7a6+3997-0x1743)};for(config=list->fileList;config;config=config->next){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[(0x1ff+8264-0x2247)]=='\n'||buf[(0xbf7+2145-0x1458)]
+==((char)(0x1715+230-0x17d8)))continue;val=strchr(buf,
+((char)(0x1936+837-0x1c3e)));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;}if(buf[strlen(buf)-(0x1338+3956-0x22ab)]==
+'\n')buf[strlen(buf)-(0x484+6087-0x1c4a)]='\0';*val++='\0';nvset(list->nvFile,
+buf,val,(0x2b2+687-0x560));}printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x6c\x6f\x61\x64\x46\x61\x63\x74\x72\x6f\x79\x50\x61\x72\x61\x6d\x20\x25\x73\x21" "\n"
+,config->configFile);fclose(fp);}return RESULT_SUCCESS;}static bool checkNvFs(
+char*file){int len=(0xec0+1923-0x1643);int cnt=(0x5a3+4403-0x16d6);FILE*fp=NULL;
+char*buf=NULL;struct stat statbuff={(0x113d+2028-0x1929)};if(stat(file,&statbuff
+)<(0x410+8528-0x2560))return false;len=statbuff.st_size;if(len<NV_CHECK_SIZE)
+return false;fp=fopen(file,"\x72\x6f");if(!fp)return false;buf=(char*)malloc(len
+);if(!buf){fclose(fp);return false;}cnt=(0x99b+51-0x9ce);while(cnt<len){cnt=cnt+
+fread(buf+cnt,(0x51c+7608-0x22d3),len-cnt,fp);if(ferror(fp)){clearerr(fp);free(
+buf);fclose(fp);return false;}}if(len!=cnt){free(buf);fclose(fp);return false;}
+if(getSum(buf,len-NV_CHECK_SIZE)+NV_FILE_FLAG!=*(uint*)(buf+len-NV_CHECK_SIZE)){
+free(buf);fclose(fp);return false;}free(buf);fclose(fp);return true;}static int
+copyfile(const char*from,const char*to){int fd_to;int fd_from;char buf[
+(0x13d7+8497-0x2508)];ssize_t nread;int ret=-(0x16f0+2761-0x21b8);fd_from=open(
+from,O_RDONLY);if(fd_from<(0x2db+799-0x5fa))return-(0x253c+264-0x2642);fd_to=
+open(to,O_RDWR|O_CREAT|O_TRUNC|O_SYNC,(0x500+6714-0x1d9a));if(fd_to<
+(0x37d+6679-0x1d94)){ret=-(0x24a+2472-0xbef);goto out_error;}while(
+(0x13a6+1524-0x1999)){char*out_ptr;ssize_t nwritten;nread=read(fd_from,buf,
+sizeof(buf));if(nread==(0x37d+9025-0x26be)){break;}else{if(nread<
+(0x360+5930-0x1a8a)){if(errno==EINTR||errno==EAGAIN){continue;}else{ret=-
+(0x905+2791-0x13e8);goto out_error;}}}out_ptr=buf;do{nwritten=write(fd_to,
+out_ptr,nread);if(nwritten>(0x5c9+1236-0xa9d)){nread-=nwritten;out_ptr+=nwritten
+;}else{if(nwritten<(0xc04+2808-0x16fc)){if(errno==EINTR||errno==EAGAIN){continue
+;}else{ret=-(0x2cd+6917-0x1dcd);goto out_error;}}}}while(nread>
+(0x25a+7315-0x1eed));}ret=fsync(fd_to);if(ret<(0x11d3+1192-0x167b)){printf(
+"\x53\x79\x6e\x63\x20\x46\x61\x69\x6c\x65\x64\x3a\x25\x73\x2c\x20\x66\x69\x6c\x65\x20\x70\x61\x74\x68\x3a\x25\x73"
+,strerror(errno),to);goto out_error;}if(close(fd_to)<(0xf1c+2978-0x1abe)){fd_to=
+-(0x505+5923-0x1c27);ret=-(0xbd5+787-0xee2);goto out_error;}close(fd_from);
+return(0x1946+229-0x1a2b);out_error:printf(
+"\x63\x6f\x70\x79\x66\x69\x6c\x65\x20\x25\x73\x20\x74\x6f\x20\x25\x73\x20\x65\x72\x72\x6f\x72\x3a\x25\x64" "\n"
+,from,to,ret);close(fd_from);if(fd_to>=(0x394+464-0x564))close(fd_to);return ret
+;}static int restoreNvFs(char*dstFile,char*srcFile){if(copyfile(srcFile,dstFile)
+!=(0x13d8+4786-0x268a))return RESULT_FAIL;return RESULT_SUCCESS;}static int
+loadNvFs(char*file){int len=(0xf5b+4836-0x223f);int cnt=(0x5d9+2332-0xef5);FILE*
+fp=NULL;char*buf=NULL;char*name=NULL;char*value=NULL;char*eq=NULL;struct stat
+statbuff={(0x509+5632-0x1b09)};char nvFile[NV_PATH_LEN]={(0x287+7854-0x2135)};
+sprintf(nvFile,"\x25\x73\x2f\x25\x73",NV_FS_MAIN_PATH,file);if(stat(nvFile,&
+statbuff)<(0x9e4+2048-0x11e4))return RESULT_FAIL;len=statbuff.st_size;if(
+NV_CHECK_SIZE>len)return RESULT_FAIL;fp=fopen(nvFile,"\x72\x6f");if(!fp)return
+RESULT_FILE_OPEN_FAIL;len=len-NV_CHECK_SIZE;buf=(char*)malloc(len+
+(0xf9f+833-0x12df));if(!buf){fclose(fp);return RESULT_MALLOC_FAIL;}memset(buf,
+(0x1184+1122-0x15e6),len+(0x1a68+1095-0x1eae));cnt=(0x5b7+1247-0xa96);while(cnt<
+len){cnt=cnt+fread(buf+cnt,(0x52c+2229-0xde0),len-cnt,fp);if(ferror(fp)){
+clearerr(fp);fclose(fp);free(buf);return RESULT_FILE_READ_FAIL;}}if(cnt!=len){
+fclose(fp);free(buf);return RESULT_FILE_READ_FAIL;}buf[len]='\0';name=buf;while(
+*name){if(!(eq=strchr(name,((char)(0x11ea+1499-0x1788))))){break;}*eq='\0';value
+=eq+(0x1099+5334-0x256e);nvset(file,name,value,(0x1889+956-0x1c44));*eq=
+((char)(0x257a+412-0x26d9));name=value+strlen(value)+(0x13c9+1473-0x1989);}free(
+buf);fclose(fp);return RESULT_SUCCESS;}static void analyMsg(T_NV_MSG_INFO*
+msgrecv,T_NV_MSG_RESULT*msgsnd){switch(msgrecv->nvType){case MSG_GET:msgsnd->
+result=nvget(msgrecv->file,msgrecv->key,msgsnd->value);break;case MSG_SET:msgsnd
+->result=nvset(msgrecv->file,msgrecv->key,msgrecv->value,msgrecv->saveflag);
+break;case MSG_UNSET:msgsnd->result=nvunset(msgrecv->file,msgrecv->key);break;
+case MSG_CLEAR:msgsnd->result=nvclear(msgrecv->file);break;case MSG_RESET:msgsnd
+->result=nvreset(msgrecv->file);break;case MSG_SHOW:msgsnd->result=saveNvFs(
+msgrecv->file,NV_FS_SHOW);;break;case MSG_COMMIT:msgsnd->result=nvcommit(msgrecv
+->file);break;default:break;}msgsnd->msgType=msgrecv->pid;msgsnd->msgIndex=
+msgrecv->msgIndex;}static int addConfigFile(char*nvFile,char*configFile){
+T_NV_NODE*list=NULL;T_NV_NODE*newList=NULL;T_NV_CONFIG*newConfig=NULL;if(!nvFile
+){printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x70\x61\x72\x61\x6d\x20\x69\x6c\x6c\x65\x67\x61\x6c\x21" "\n"
+);return RESULT_INVAL;}if(configFile){newConfig=(T_NV_CONFIG*)malloc(sizeof(
+T_NV_CONFIG));if(!newConfig)return RESULT_MALLOC_FAIL;strncpy(newConfig->
+configFile,configFile,NV_PATH_LEN-(0x3a5+8399-0x2473));newConfig->configFile[
+NV_PATH_LEN-(0x9a6+2041-0x119e)]='\0';newConfig->next=NULL;}for(list=nv_list;
+list;list=list->next){if(strcmp(list->nvFile,nvFile)==(0xf0+778-0x3fa))break;}if
+(!list){newList=(T_NV_NODE*)malloc(sizeof(T_NV_NODE));if(!newList){if(newConfig)
+free(newConfig);return RESULT_MALLOC_FAIL;}newList->next=NULL;strncpy(newList->
+nvFile,nvFile,NV_PATH_LEN-(0x21fc+960-0x25bb));newList->nvFile[NV_PATH_LEN-
+(0xc26+1512-0x120d)]='\0';memset(newList->nvTable,(0xaf8+2366-0x1436),
+NV_HASH_LEN*(0x404+3503-0x11af));newList->fileList=newConfig;if(!nv_list)nv_list
+=newList;else{newList->next=nv_list->next;nv_list->next=newList;}}else if(!list
+->fileList)list->fileList=newConfig;else{if(newConfig==NULL)return RESULT_FAIL;
+newConfig->next=list->fileList->next;list->fileList->next=newConfig;}return
+RESULT_SUCCESS;}static bool isCfgConfiged(char*configFile){T_NV_NODE*list=NULL;
+T_NV_CONFIG*config=NULL;for(list=nv_list;list;list=list->next){for(config=list->
+fileList;config;config=config->next){if(!strcmp(config->configFile,configFile))
+return true;}}return false;}static bool isNvConfiged(char*nvFile){T_NV_NODE*list
+=NULL;for(list=nv_list;list;list=list->next){if(!strcmp(list->nvFile,nvFile))
+return true;}return false;}static uint getSum(const char*s,int len){uint sum=
+(0x1469+1721-0x1b22);char*data=(char*)s;while(len-- >(0xd0c+5271-0x21a3)){sum+=(
+*data++);}return sum;}static int saveNvFs(char*nvName,char*nvFile){int i=
+(0xae6+4407-0x1c1d);int sum=(0x6a7+4794-0x1961);int bufSize=(0xd4a+2813-0x1847);
+int itemSize=(0xe7c+205-0xf49);int ret=(0x8fa+2426-0x1274);int fp=
+(0x246+334-0x394);char*buf=NULL;T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL;for(list
+=nv_list;list;list=list->next){if(strcmp(list->nvFile,nvName))continue;fp=open(
+nvFile,O_SYNC|O_RDWR|O_CREAT|O_TRUNC,(0x270+6353-0x19a1));if(fp==-
+(0x11ed+4255-0x228b)){printf(
+"\x6f\x70\x65\x6e\x20\x25\x73\x20\x66\x61\x69\x6c\x2c\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,nvFile,errno);return RESULT_FILE_OPEN_FAIL;}buf=(char*)malloc(NV_BLOCK_SIZE);if
+(!buf){close(fp);return RESULT_MALLOC_FAIL;}for(i=(0x3c2+5458-0x1914);i<
+NV_HASH_LEN;i++){for(item=list->nvTable[i];item;item=item->next){if(strcmp(
+nvFile,NV_FS_SHOW)&&!item->saveFlag)continue;itemSize=strlen(item->key)+strlen(
+item->value)+(0x1a95+1451-0x203e);if(bufSize+itemSize>NV_BLOCK_SIZE){if(write(fp
+,buf,bufSize)<(0x100c+2506-0x19d6)){printf(
+"\x65\x72\x72\x6f\x72\x20\x25\x73\x20\x25\x64\x3a\x20\x77\x72\x69\x74\x65\x20\x66\x61\x69\x6c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,__FILE__,__LINE__,errno);close(fp);free(buf);return RESULT_FILE_WRITE_FAIL;}sum
++=getSum(buf,bufSize);bufSize=(0xeb0+2591-0x18cf);}sprintf(buf+bufSize,
+"\x25\x73\x3d\x25\x73",item->key,item->value);bufSize+=itemSize;}}if(bufSize!=
+(0x1e77+809-0x21a0)){if(write(fp,buf,bufSize)<(0xfc7+1731-0x168a)){printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x77\x72\x69\x74\x65\x20\x66\x61\x69\x6c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,errno);close(fp);free(buf);return RESULT_FILE_WRITE_FAIL;}sum+=getSum(buf,
+bufSize);}sum+=NV_FILE_FLAG;if(write(fp,&sum,NV_CHECK_SIZE)<(0x82f+452-0x9f3)){
+printf(
+"\x6e\x76\x73\x65\x72\x76\x65\x72\x20\x65\x72\x72\x6f\x72\x3a\x20\x77\x72\x69\x74\x65\x20\x66\x61\x69\x6c\x20\x65\x72\x72\x6e\x6f\x20\x3d\x20\x25\x64" "\n"
+,errno);close(fp);free(buf);return RESULT_FILE_WRITE_FAIL;}ret=fsync(fp);free(
+buf);close(fp);if(ret<(0xf7a+1288-0x1482)){printf(
+"\x53\x79\x6e\x63\x20\x46\x61\x69\x6c\x65\x64\x3a\x25\x73\x2c\x20\x66\x69\x6c\x65\x20\x70\x61\x74\x68\x3a\x25\x73"
+,strerror(errno),nvFile);return ret;}return RESULT_SUCCESS;}return
+RESULT_NO_FILE;}static int nvget(char*file,char*key,char*value){int index=
+(0xb29+4408-0x1c61);T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL;for(list=nv_list;
+list;list=list->next){if(strcmp(list->nvFile,file))continue;index=hash(key)%
+NV_HASH_LEN;for(item=list->nvTable[index];item;item=item->next){if(strcmp(item->
+key,key))continue;strncpy(value,item->value,NV_MAX_VAL_LEN-(0xe37+2952-0x19be));
+value[NV_MAX_VAL_LEN-(0xac0+4480-0x1c3f)]='\0';return RESULT_SUCCESS;}}return
+RESULT_NO_ITEM;}static int nvset(char*file,const char*key,const char*value,int
+saveFlag){int index=(0x17cb+641-0x1a4c);int ret=(0x131c+320-0x145c);int
+key_buf_len=(0x1afa+2437-0x247f);int value_buf_len=(0x162d+2323-0x1f40);
+T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL;T_NV_ITEM*newItem=NULL;if(NULL==key||
+NULL==value)return RESULT_FAIL;key_buf_len=strlen(key)+(0xe3+879-0x451);
+value_buf_len=strlen(value)+(0xa48+4827-0x1d22);for(list=nv_list;list;list=list
+->next){if(strcmp(list->nvFile,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))
+return RESULT_SUCCESS;free(item->value);item->value=(char*)malloc(value_buf_len)
+;if(!item->value)return RESULT_MALLOC_FAIL;strncpy(item->value,value,
+value_buf_len-(0x114f+4319-0x222d));item->value[value_buf_len-
+(0x6d9+5401-0x1bf1)]='\0';return RESULT_SUCCESS;}newItem=(T_NV_ITEM*)malloc(
+sizeof(T_NV_ITEM));if(!newItem)return RESULT_MALLOC_FAIL;newItem->key=(char*)
+malloc(key_buf_len);if(!newItem->key){free(newItem);return RESULT_MALLOC_FAIL;}
+newItem->value=(char*)malloc(value_buf_len);if(!newItem->value){free(newItem->
+key);free(newItem);return RESULT_MALLOC_FAIL;}strncpy(newItem->key,key,
+key_buf_len-(0x418+7161-0x2010));newItem->key[key_buf_len-(0x1218+5049-0x25d0)]=
+'\0';strncpy(newItem->value,value,value_buf_len-(0xa36+512-0xc35));newItem->
+value[value_buf_len-(0x711+2882-0x1252)]='\0';newItem->next=NULL;newItem->
+saveFlag=saveFlag;newItem->update_flag=(0x1320+3434-0x208a);if(!list->nvTable[
+index])list->nvTable[index]=newItem;else{newItem->next=list->nvTable[index]->
+next;list->nvTable[index]->next=newItem;}return RESULT_SUCCESS;}ret=
+addConfigFile(file,NULL);if(ret==RESULT_SUCCESS)return nvset(file,key,value,
+saveFlag);else return ret;}static int nvunset(char*file,char*key){int index=
+(0x2f2+6797-0x1d7f);T_NV_NODE*list=NULL;T_NV_ITEM*item=NULL;T_NV_ITEM*prev=NULL;
+for(list=nv_list;list;list=list->next){if(strcmp(list->nvFile,file))continue;
+index=hash(key)%NV_HASH_LEN;for(item=list->nvTable[index];item;prev=item,item=
+item->next){if(strcmp(item->key,key))continue;if(!prev)list->nvTable[index]=item
+->next;else prev->next=item->next;free(item->key);free(item->value);free(item);
+return RESULT_SUCCESS;}}return RESULT_NO_ITEM;}static int nvreset(char*file){int
+ ret=(0x120a+3246-0x1eb8);T_NV_NODE*list=NULL;for(list=nv_list;list;list=list->
+next){if(strcmp(list->nvFile,file))continue;ret=nvclear(file);if(ret!=
+RESULT_SUCCESS)return ret;if(loadFactroyParam(list)!=RESULT_SUCCESS)return
+RESULT_FAIL;return nvcommit(file);}return RESULT_NO_FILE;}static int nvclear(
+char*file){int i=(0x15e8+2409-0x1f51);T_NV_NODE*list=NULL;T_NV_ITEM*cur=NULL;
+T_NV_ITEM*item=NULL;for(list=nv_list;list;list=list->next){if(strcmp(list->
+nvFile,file))continue;for(i=(0xebc+2335-0x17db);i<NV_HASH_LEN;i++){for(item=list
+->nvTable[i];item;){cur=item;item=item->next;free(cur->key);free(cur->value);
+free(cur);}list->nvTable[i]=NULL;}return RESULT_SUCCESS;}return RESULT_NO_FILE;}
+static int nvcommit(char*file){int ret=(0xca8+173-0xd55);char nvMainFile[
+NV_PATH_LEN]={(0x705+1086-0xb43)};char nvBackupFile[NV_PATH_LEN]={
+(0x1256+3203-0x1ed9)};sprintf(nvMainFile,"\x25\x73\x2f\x25\x73",NV_FS_MAIN_PATH,
+file);sprintf(nvBackupFile,"\x25\x73\x2f\x25\x73",NV_FS_BACKUP_PATH,file);ret=
+saveNvFs(file,nvMainFile);if(ret!=RESULT_SUCCESS)return ret;return restoreNvFs(
+nvBackupFile,nvMainFile);}
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/ap/app/zte_comm/nvserver/nvserver.h b/ap/app/zte_comm/nvserver/nvserver.h
new file mode 100755
index 0000000..f9ae388
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/nvserver.h
@@ -0,0 +1,84 @@
+/*******************************************************************************
+* °æÈ¨ËùÓÐ (C)2016, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+*
+* ÎļþÃû³Æ: nvserver.h
+* Îļþ±êʶ: nvserver.h
+* ÄÚÈÝÕªÒª: nvºǫ́ӦÓÃÍ·Îļþ
+* ʹÓ÷½·¨: #include <nvserver.h>
+*
+* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+* ------------------------------------------------------------------------------
+* 2016/09/20 V1.0 Create ÍõÇæ ´´½¨
+*
+*******************************************************************************/
+#ifndef _NVSERVER_H
+#define _NVSERVER_H
+
+/*******************************************************************************
+* Í·Îļþ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ºê¶¨Òå *
+*******************************************************************************/
+#define NV_PATH_LEN 256
+#define NV_HASH_LEN 512
+#define NV_HASH_MUL 31
+#define NV_MAX_CONFIG_LEN 512
+
+#define NV_CONFIG_FILE "/etc_ro/nvconfig"
+#define NV_FS_PATH "/etc_rw/nv"
+#define NV_FS_MAIN_PATH "/etc_rw/nv/main"
+#define NV_FS_BACKUP_PATH "/etc_rw/nv/backup"
+
+#define NV_BLOCK_SIZE 4096
+#define NV_FILE_FLAG 0x123
+
+#define NV_CFG "cfg"
+#define NV_RO "ro"
+#define NV_RTDEV "rtdev"
+#define NV_CERT "cert"
+#define NV_WAPI "wapi"
+/*******************************************************************************
+* Êý¾ÝÀàÐͶ¨Òå *
+*******************************************************************************/
+typedef enum { false, true } bool;
+
+typedef struct nv_item
+{
+ char *key;
+ char *value;
+ int saveFlag;
+ int update_flag;
+ struct nv_item *next;
+} T_NV_ITEM;
+
+typedef struct nv_config
+{
+ char configFile[NV_PATH_LEN];
+ struct nv_config *next;
+} T_NV_CONFIG;
+
+typedef struct nv_node
+{
+ char nvFile[NV_PATH_LEN];
+ T_NV_CONFIG *fileList;
+ T_NV_ITEM *nvTable[NV_HASH_LEN];
+ struct nv_node *next;
+}T_NV_NODE ;
+
+/*******************************************************************************
+* È«¾Ö±äÁ¿ÉùÃ÷ *
+*******************************************************************************/
+
+/*******************************************************************************
+* È«¾Öº¯ÊýÉùÃ÷ *
+*******************************************************************************/
+int nvupdate(char *nv_file, char *config_file, const char *key, const char *value, int saveFlag);
+int reloadFactroyParam(T_NV_NODE *list);
+int delete_not_needed(T_NV_NODE *list);
+uint hash(const char *s);
+int get_update_status (void);
+
+#endif
+
diff --git a/ap/app/zte_comm/nvserver/nvserver_rpc.c b/ap/app/zte_comm/nvserver/nvserver_rpc.c
new file mode 100755
index 0000000..1ac51e6
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/nvserver_rpc.c
@@ -0,0 +1,166 @@
+/*******************************************************************************
+* °æÈ¨ËùÓÐ (C)2023, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+*
+* ÎļþÃû³Æ: nvserver_rpc.c
+* Îļþ±êʶ: nvserver_rpc.c
+* ÄÚÈÝÕªÒª: nvserverת½ÓcapµÄnvserver
+*
+* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+* ------------------------------------------------------------------------------
+* 2016/06/13 V1.0 Create ÁõÑÇÄÏ ´´½¨
+*
+*******************************************************************************/
+
+/*******************************************************************************
+* Í·Îļþ *
+*******************************************************************************/
+#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 "sc_rpc.h"
+
+#ifdef FOTA_AB
+#include "zxic_fota_ab_upgrade.h"
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*******************************************************************************
+* ³£Á¿¶¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* ºê¶¨Òå *
+*******************************************************************************/
+#define RPC_RPMSG_DEV "/dev/rpmsg8"
+
+/*******************************************************************************
+* Êý¾ÝÀàÐͶ¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¾Ö²¿º¯ÊýÉùÃ÷ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¾Ö²¿¾²Ì¬±äÁ¿¶¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* È«¾Ö±äÁ¿¶¨Òå *
+*******************************************************************************/
+static int g_rpc_fd = -1;
+
+/*******************************************************************************
+* ¾Ö²¿º¯ÊýʵÏÖ *
+*******************************************************************************/
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: analyMsg
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) msgrecv:½ÓÊÕÏûÏ¢
+* (´«³ö²ÎÊý) msgsnd:·¢ËÍÏûÏ¢
+* ·µ »Ø Öµ: 0±íʾ³É¹¦
+* ÆäËü˵Ã÷: void
+*******************************************************************************/
+static void analyMsg(T_NV_MSG_INFO *msgrecv, T_NV_MSG_RESULT *msgsnd)
+{
+ T_sc_rpc_header rpc_data = {0};
+
+ rpc_data.msg_type = RPC_MSG_TYPE_REQUEST;
+ rpc_data.func_id = RPC_FUNC_ID_NV;
+ rpc_data.data_len = sizeof(T_NV_MSG_INFO);
+ memcpy(rpc_data.data, msgrecv, sizeof(T_NV_MSG_INFO));
+
+ sc_rpc_send(g_rpc_fd, &rpc_data, 0);
+
+ while (0 != sc_rpc_recv(g_rpc_fd, &rpc_data, 0)) // µÈ´ýCAPºË´´½¨Í¨µÀ
+ {
+ sleep(1);
+ continue;
+ }
+
+ memcpy(msgsnd, rpc_data.data, sizeof(T_NV_MSG_RESULT));
+}
+
+/*******************************************************************************
+* È«¾Öº¯ÊýʵÏÖ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: main
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: void
+*******************************************************************************/
+int nvserver_main(int argc, char *argv[])
+{
+ int msgId = 0;
+ T_NV_MSG_INFO rcvBuf;
+ T_NV_MSG_RESULT sndBuf;
+ struct msqid_ds msgInfo;
+
+ prctl(PR_SET_NAME, "nvserver", 0, 0, 0);
+
+ memset(&msgInfo, 0, sizeof(msgInfo));
+
+ g_rpc_fd = sc_rpc_open(RPC_RPMSG_DEV);
+
+ msgId = msgget(MODULE_ID_NV, IPC_CREAT | 0600);
+ if (-1 == msgId)
+ {
+ printf("nvserver error: msgget msgId fail, errno = %d\n", errno);
+ return -1;
+ }
+
+ if (-1 != msgctl(msgId, IPC_STAT, &msgInfo))
+ {
+ msgInfo.msg_qbytes = 262144; // 256k
+ if (-1 == msgctl(msgId, IPC_SET, &msgInfo))
+ {
+ printf("nvserver error: msgctl msgId fail, errno = %d\n", errno);
+ }
+ }
+
+ // ÏûÏ¢½»»¥
+ while (1)
+ {
+ memset(&rcvBuf, 0, sizeof(rcvBuf));
+ memset(&sndBuf, 0, sizeof(sndBuf));
+ if (-1 == msgrcv(msgId, &rcvBuf, sizeof(T_NV_MSG_INFO) - sizeof(long), MSG_TYPE_NV, 0))
+ {
+ printf("nvserver error: nvserver msgrcv fail, errno = %d!\n", errno);
+ continue;
+ }
+
+ analyMsg(&rcvBuf, &sndBuf);
+
+ if (-1 == msgsnd(msgId, &sndBuf, sizeof(T_NV_MSG_RESULT) - sizeof(long), 0))
+ {
+ printf("nvserver error: nvserver msgsnd fail, errno = %d!\n", errno);
+ continue;
+ }
+ }
+
+ return (0);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/ap/app/zte_comm/nvserver/nvupdate.c b/ap/app/zte_comm/nvserver/nvupdate.c
new file mode 100755
index 0000000..b7e2041
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/nvupdate.c
@@ -0,0 +1,122 @@
+
+#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 "zxic_fota_ab_upgrade.h"
+#endif
+#ifdef __cplusplus
+extern"C"{
+#endif
+extern T_NV_NODE*nv_list;
+#ifdef FOTA_AB
+int get_update_status(void){int ret=dual_AB_get_fota_status_for_nv();if(ret==
+(0xb96+3288-0x186d))return(0x1184+1640-0x17ea);else return(0xf4b+4962-0x22ad);}
+#else
+int get_update_status(void){int update_status;FILE*fd=(0x764+3978-0x16ee);int
+ret;char*filename=NULL;if(access(FOTA_UPDATE_STATUS_FILE_OLD,R_OK)==
+(0xd92+851-0x10e5)){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<(0x1170+3583-0x1f6f)){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-
+(0x11b4+2670-0x1c21);}
+#endif
+int nvupdate(char*nv_file,char*config_file,const char*key,const char*value,int
+saveFlag){int index=(0xef3+3673-0x1d4c);int key_buf_len=(0x5d5+7730-0x2407);int
+value_buf_len=(0xe7b+382-0xff9);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)+(0x5af+3320-0x12a6);value_buf_len=
+strlen(value)+(0xe8b+891-0x1205);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=(0xb2+1752-0x789);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((0xa39+6476-0x2384)==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=
+(0xca9+4172-0x1cf4);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-(0xca2+2563-0x16a4));item->value[value_buf_len-
+(0x15e6+3203-0x2268)]='\0';item->update_flag=(0x1d1c+1516-0x2307);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)+
+(0x689+6508-0x1ff4));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-
+(0xc3+5582-0x1690));newItem->key[key_buf_len-(0x13a7+3162-0x2000)]='\0';strncpy(
+newItem->value,value,value_buf_len-(0x5e0+7088-0x218f));newItem->value[
+value_buf_len-(0x4f5+1876-0xc48)]='\0';newItem->next=NULL;newItem->saveFlag=
+saveFlag;newItem->update_flag=(0x332+6840-0x1de9);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]={(0x1d6b+785-0x207c)};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[(0x439+7208-0x2061)]=='\n'||buf[(0x10bf+2386-0x1a11)
+]==((char)(0x156d+1747-0x1c1d)))continue;val=strchr(buf,
+((char)(0x1172+2678-0x1bab)));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)-(0xfff+1902-0x176c)]='\0';*
+val++='\0';nvupdate(list->nvFile,config->configFile,buf,val,(0x1970+1137-0x1de0)
+);}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=(0xa86+1817-0x119f);T_NV_ITEM*item=NULL;T_NV_ITEM head={
+(0x104d+1119-0x14ac)};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=(0x3ea+5464-0x1942);index<NV_HASH_LEN;index++){head.next=list->
+nvTable[index];prev=&head;for(item=prev->next;item;){if((0x849+6882-0x232a)==
+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
+
diff --git a/ap/app/zte_comm/nvserver/rpmsg_zx29.h b/ap/app/zte_comm/nvserver/rpmsg_zx29.h
new file mode 100755
index 0000000..596cfc0
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/rpmsg_zx29.h
@@ -0,0 +1,44 @@
+/*******************************************************************************
+* Copyright (C) 2013, ZTE Corporation.
+*
+* File Name: rpmsg_zx29.h
+* File Mark:
+* Description:
+* Others:
+* Version: V0.1
+* Author: ShiDeYou
+* Date: 2013-09-23
+* History 1:
+* Date:
+* Version:
+* Author:
+* Modification:
+*******************************************************************************/
+
+/*******************************************************************************
+* Include files *
+*******************************************************************************/
+
+/*******************************************************************************
+* Types *
+*******************************************************************************/
+#ifndef RPMSG_ZX29_H
+#define RPMSG_ZX29_H
+
+#include <linux/ioctl.h>
+
+#define RPMSG_IOC_MAGIC 'R'
+
+/*ioctl cmd usd by device*/
+#define RPMSG_CREATE_CHANNEL _IOW(RPMSG_IOC_MAGIC, 1, char *)
+#define RPMSG_GET_DATASIZE _IOWR(RPMSG_IOC_MAGIC, 2, char *)
+#define RPMSG_SET_INT _IOW(RPMSG_IOC_MAGIC, 3, char *)
+#define RPMSG_SET_INT_FLAG _IOW(RPMSG_IOC_MAGIC, 4, char *)
+#define RPMSG_CLEAR_INT_FLAG _IOW(RPMSG_IOC_MAGIC, 5, char *)
+#define RPMSG_SET_POLL_FLAG _IOW(RPMSG_IOC_MAGIC, 6, char *)
+#define RPMSG_CLEAR_POLL_FLAG _IOW(RPMSG_IOC_MAGIC, 7, char *)
+
+#define AT_DEV armps_rpmsgch9
+#define FOTA_DEV "/dev/armps_rpmsgch12"
+
+#endif
diff --git a/ap/app/zte_comm/nvserver/sc_rpc.c b/ap/app/zte_comm/nvserver/sc_rpc.c
new file mode 100755
index 0000000..eddf7b5
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/sc_rpc.c
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * 版权所有 (C)2023, 中兴通讯股份有限公司。
+ *
+ * 文件名称: nvserver_rpc.c
+ * 文件标识: nvserver_rpc.c
+ * 内容摘要: nvserver转接cap的nvserver
+ *
+ * 修改日期 版本号 修改标记 修改人 修改内容
+ * ------------------------------------------------------------------------------
+ * 2016/06/13 V1.0 Create 刘亚南 创建
+ *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 头文件 *
+ *******************************************************************************/
+#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 <sys/ioctl.h>
+#include <unistd.h>
+#include "sc_rpc.h"
+#include "zxicbasic_api.h"
+#include "rpmsg_zx29.h"
+
+/*******************************************************************************
+ * 常量定义 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 宏定义 *
+ *******************************************************************************/
+#define RPC_CHN_MAX_BUF_LEN 8192
+
+/*******************************************************************************
+ * 数据类型定义 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 局部函数声明 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 局部静态变量定义 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 全局变量定义 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 局部函数实现 *
+ *******************************************************************************/
+
+/*******************************************************************************
+ * 全局函数实现 *
+ *******************************************************************************/
+
+int sc_rpc_open(const char *rpmsg_dev)
+{
+ int fd;
+ fd = open(rpmsg_dev, O_RDWR);
+
+ if (fd < 0)
+ {
+ perror("[rpc] open device fail\n");
+ return -1;
+ }
+
+ if (ioctl(fd, RPMSG_CREATE_CHANNEL, RPC_CHN_MAX_BUF_LEN) < 0)
+ {
+ perror("[rpc] RPMSG_CREATE_CHANNEL error\n");
+ return -1;
+ }
+
+ // 发送消息时,触发中断
+ if (ioctl(fd, RPMSG_SET_INT_FLAG, NULL) < 0)
+ {
+ perror("[rpc] RPMSG_SET_INT_FLAG error\n");
+ return -1;
+ }
+
+ // 阻塞的方式读
+ if (ioctl(fd, RPMSG_CLEAR_POLL_FLAG, NULL) < 0)
+ {
+ perror("[rpc] RPMSG_CLEAR_POLL_FLAG error\n");
+ return -1;
+ }
+
+ return fd;
+}
+
+int sc_rpc_clear(int fd)
+{
+ char tmp_buf[1024];
+ int ret = -1;
+
+ if (ioctl(fd, RPMSG_SET_POLL_FLAG, NULL) < 0)
+ {
+ perror("[rpc] RPMSG_SET_POLL_FLAG error\n");
+ return -1;
+ }
+
+ while (1)
+ {
+ ret = safe_read(fd, tmp_buf, sizeof(tmp_buf));
+ if (ret == 0)
+ {
+ break; /* channel clear */
+ }
+ else
+ {
+ printf("[rpc] UNBLOCK read len = %d!\n", ret);
+ }
+ }
+ if (ioctl(fd, RPMSG_CLEAR_POLL_FLAG, NULL) < 0)
+ {
+ perror("[rpc] RPMSG_CLEAR_POLL_FLAG error\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int sc_rpc_send(int fd, T_sc_rpc_header *data, unsigned int flag)
+{
+ ssize_t ret;
+
+ ret = full_write(fd, data, sizeof(T_sc_rpc_header));
+ if (ret != sizeof(T_sc_rpc_header))
+ {
+ printf("[rpc] write error, len=%d != %d!\n", ret, (int)sizeof(T_sc_rpc_header));
+ return -1;
+ }
+
+ return 0;
+}
+
+int sc_rpc_recv(int fd, T_sc_rpc_header *data, unsigned int flag)
+{
+ ssize_t ret;
+
+ ret = full_read(fd, data, sizeof(T_sc_rpc_header));
+ if (ret != sizeof(T_sc_rpc_header))
+ {
+ printf("[rpc] read error, len=%d != %d!\n", ret, (int)sizeof(T_sc_rpc_header));
+ return -1;
+ }
+
+ return 0;
+}
+
+int sc_rpc_close(int fd)
+{
+ return close(fd);
+}
diff --git a/ap/app/zte_comm/nvserver/sc_rpc.h b/ap/app/zte_comm/nvserver/sc_rpc.h
new file mode 100755
index 0000000..904991e
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/sc_rpc.h
@@ -0,0 +1,46 @@
+/*******************************************************************************
+* 版权所有 (C)2023, 中兴通讯股份有限公司。
+*
+* 文件名称: sc_rpc.h
+* 文件标识: sc_rpc.h
+* 内容摘要: rpc头文件
+* 使用方法: #include <sc_rpc.h>
+*
+* 修改日期 版本号 修改标记 修改人 修改内容
+* ------------------------------------------------------------------------------
+* 2023/03/23 V1.0 Create 周国坡 创建
+*
+*******************************************************************************/
+#ifndef _SC_RPC_H
+#define _SC_RPC_H
+
+enum
+{
+ RPC_MSG_TYPE_REQUEST = 0xAA,
+ RPC_MSG_TYPE_REPLY = 0xBB
+};
+
+enum
+{
+ RPC_FUNC_ID_NV = 10
+};
+
+typedef struct
+{
+ unsigned int msg_type;
+ unsigned int func_id;
+ unsigned int data_len;
+ char data[4096];
+} T_sc_rpc_header;
+
+int sc_rpc_open(const char *rpmsg_dev);
+
+int sc_rpc_clear(int fd);
+
+int sc_rpc_send(int fd, T_sc_rpc_header *data, unsigned int flag);
+
+int sc_rpc_recv(int fd, T_sc_rpc_header *data, unsigned int flag);
+
+int sc_rpc_close(int fd);
+
+#endif
diff --git a/ap/app/zte_comm/nvserver/zxicbasic_api.h b/ap/app/zte_comm/nvserver/zxicbasic_api.h
new file mode 100755
index 0000000..1640ba3
--- /dev/null
+++ b/ap/app/zte_comm/nvserver/zxicbasic_api.h
@@ -0,0 +1,12 @@
+
+#ifndef __ZXICBASIC_API_H
+#define __ZXICBASIC_API_H
+
+extern ssize_t safe_read(int fd, void *buf, size_t count);
+extern ssize_t full_read(int fd, void *buf, size_t len);
+extern ssize_t read_close(int fd, void *buf, size_t size);
+extern ssize_t open_read_close(const char *filename, void *buf, size_t size);
+extern ssize_t safe_write(int fd, const void *buf, size_t count);
+extern ssize_t full_write(int fd, const void *buf, size_t len);
+
+#endif
\ No newline at end of file