[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/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