[Feature][ZXW50][systime] add liblynq-systime

Only Configure:No
Affected branch:master
Affected module:systime
Is it affected on both ZXIC and MTK:Yes
Self-test: Yes
Doc Update:Need

Change-Id: I4d75d22b5e9ecb1afcd105798d0554d3a40acdde
diff --git a/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c b/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
index 2d4c6b1..03d43eb 100755
--- a/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
+++ b/ap/app/zte_comm/at_ctl/src/atconfig/ps_normal.c
@@ -115,6 +115,14 @@
 	void *p[5] = {&timeinfo.time_zone,&timeinfo.sav_time,temp1,temp2,timeinfo.univer_time};

 	int time_zone = 0;

 	

+	//>>>sj.zhang add @2023-08-10 for systime NITZ sync enable/disenable.

+	if(0 != system("uci get lynq_uci.lynq_sync_time.lynq_modem_sync_time_enable | grep -E \'^1$\'"))

+	{

+		at_print(AT_ERR,"zmmi_auto_act: nitz disenabled. \n");

+		return AT_END;

+	}

+	//>>>sj.zhang add @2023-08-10 end.

+

     sc_cfg_get("sntp_time_set_mode", mode, sizeof(mode));

 	if(strcmp(mode, "manual") == 0)

 	{

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
index 5de1db2..ec00506 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
@@ -163,6 +163,7 @@
         liblynq-qser-network \
         liblynq-qser-gnss \
         liblynq-qser-fota \
+        liblynq-systime \
 	"
 
 zxic_lib += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'libril libreference-ril', 'libtelsvr', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index 4201487..c12bcad 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -192,6 +192,7 @@
         liblynq-qser-gnss \
         liblynq-qser-fota \
         libpoweralarm \
+        liblynq-systime \
 	"
 
 zxic_lib += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'libril', 'libtelsvr', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-systime/liblynq-systime.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-systime/liblynq-systime.bb
new file mode 100644
index 0000000..0b417ec
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-systime/liblynq-systime.bb
@@ -0,0 +1,64 @@
+#inherit externalsrc package
+
+DESCRIPTION = "liblynq-systime"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=b1e07e8d88e26263e71d3a9e2aa9a2ff"
+DEPENDS += "${@bb.utils.contains('TARGET_PLATFORM', 'T106', "liblynq-uci libsctel", '', d)} "
+#inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/lib/liblynq-systime/"
+FILESEXTRAPATHS_prepend :="${TOPDIR}/../src/lynq/lib/:"
+SRC_URI = " \
+          file://liblynq-systime \
+          "
+
+SRC-DIR = "${S}/../liblynq-systime"
+
+TARGET_CC_ARCH += "${LDFLAGS}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST} -Wl,--hash-style=gnu"
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'TARGET_PLATFORM = ${TARGET_PLATFORM}'"
+
+FILES_${PN} = "${base_libdir}/*.so \
+               ${base_bindir}\
+               ${base_sbindir} \
+               /etc/dbus-1/system.d/"
+FILES_${PN}-dev = "/test \
+                   ${includedir}"
+
+FILES_${PN}-doc = "/doc"
+
+FILES_${PN}-dbg ="${base_bindir}/.debug \
+                  ${base_libdir}/.debug \
+                  ${base_sbindir}/.debug"
+
+INSANE_SKIP_${PN} += "already-stripped"
+INSANE_SKIP_${PN} += "installed-vs-shipped"
+
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+	if [ "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" ]; then
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu"
+	elif [ "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4" ]; then
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu"
+	elif [ "${PACKAGE_ARCH}" = "cortexa53hf-neon-fp-armv8" ]; then
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu -mhard-float -mfpu=neon-fp-armv8 -mfloat-abi=hard -mcpu=cortex-a53 -mtune=cortex-a53"
+	else
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -Wl,--hash-style=gnu"
+	fi
+}
+
+do_install () {
+    oe_runmake install -C ${SRC-DIR} ROOT=${D}
+	
+    if [ -d "${WORKONSRC}" ] ; then
+        install -d ${D}${includedir}/
+        cp -af ${SRC-DIR}/include/ ${D}${includedir}/
+    fi 
+}
+
+addtask bachclean
+do_bachclean () {
+    oe_runmake clean
+}
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/LICENSE b/cap/zx297520v3/src/lynq/lib/liblynq-systime/LICENSE
new file mode 100755
index 0000000..605b7ea
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MobileTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MobileTek Inc. and/or its licensors. Without
+the prior written permission of MobileTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MobileTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MobileTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MobileTek SOFTWARE")
+RECEIVED FROM MobileTek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MobileTek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MobileTek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MobileTek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MobileTek
+SOFTWARE. MobileTek SHALL ALSO NOT BE RESPONSIBLE FOR ANY MobileTek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MobileTek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MobileTek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MobileTek'S OPTION, TO REVISE OR REPLACE THE
+MobileTek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MobileTek FOR SUCH MobileTek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/include/lynq_systime.h b/cap/zx297520v3/src/lynq/lib/liblynq-systime/include/lynq_systime.h
new file mode 100755
index 0000000..001edda
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/include/lynq_systime.h
@@ -0,0 +1,123 @@
+/**@file lynq-systime.h

+ *

+ * @brief Sync systime form each time source.

+ *

+ * @author sj.zhang

+ *

+ * @date 2023-08-14

+ *

+ * @version V1.0

+ *

+ * @copyright Copyright (c) MobileTek

+ */

+#include <stdio.h>

+#include <string.h>

+#include <stdlib.h>

+#include <time.h>

+#include <include/lynq_uci.h>

+

+#ifndef _LYNQ_SYSTIME_H_

+#define _LYNQ_SYSTIME_H_

+

+#ifdef __cplusplus

+extern "C"

+{

+#endif

+

+typedef struct time_source_status

+{

+    int ntp;

+    int nitz;

+    int gnss;

+}time_src_status_s;

+

+#ifdef MOBILETEK_TARGET_PLATFORM_T106

+

+    /**@brief Set the rtc time to the system time.

+     *

+     * @param void

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int lynq_sync_time_from_rtc(void);

+

+    /**@brief Set the system time to the rtc time.

+     *

+     * @param void

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int lynq_set_rtc_time(void);

+

+    /**@brief Query the rtc time.

+     *

+     * @param [OUT] ulsec: rtc time, secconds from 1900.1.1 00:00

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int lynq_get_rtc_time(unsigned long *ulsec);

+#endif

+

+    /**@brief Query the time source status now.

+     *

+     * @param [OUT] ntp, nitz, gnss:

+     *        0: disable

+     *        1: enable

+     *

+     * @return

+     *      0 : success

+     *      other:failure

+     */

+    int lynq_get_time_src_status(time_src_status_s *time_src);

+

+    /**@brief Turn sntp on/off

+     *

+     * @param enable [IN] : 0  disenable; 1 enable;

+     *

+     * @return

+     *    0 set success

+     *    1 SNTP_DISENABLE

+     *    2 SNTP_ALREADY_ENABLE

+     */

+    int ntp_sync_time(int enable);

+

+    /**@brief Enable/Disenable sync time from NITZ.

+     *

+     * @param enable [IN] : 0  disenable; 1 enable;

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int modem_time_enable(int enable);

+

+    /**@brief Enable/Disenable sync time from GNSS.

+     *

+     * @param enable [IN] : 0  disenable; 1 enable;

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int gnss_time_enable(int enable);

+

+    /**@brief User set systime manually.

+     *

+     * @param enable [IN] : 0  disenable; 1 enable;

+     *

+     * @return

+     *      0:success

+     *      other:failure

+     */

+    int user_set_time(char *date, char *time);

+

+#ifdef __cplusplus

+}

+#endif

+#endif

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
new file mode 100755
index 0000000..6b7351b
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
@@ -0,0 +1,382 @@
+/**@file lynq-systime.cpp

+ *

+ * @brief Sync systime form different time source.

+ *

+ * @author sj.zhang

+ *

+ * @date 2023-08-15

+ *

+ * @version V1.0

+ *

+ * @copyright Copyright (c) MobileTek

+ */

+#include <stdio.h>

+#include <string.h>

+#include <stdlib.h>

+#include <time.h>

+#include <unistd.h>

+#include <include/lynq_uci.h>

+#include "liblog/lynq_deflog.h"

+#include "lynq_systime.h"

+

+#ifdef __cplusplus

+extern "C"

+{

+#endif

+

+#define USER_LOG_TAG "LYNQ_SYSTIME"

+#define LOG_LEVEL 4

+

+#define LYNQ_SYNC_TIME_SECTION "lynq_sync_time"

+#define LYNQ_MODEM_TIME_KEY "lynq_modem_sync_time_enable"

+#define LYNQ_GNSS_TIME_KEY "lynq_gnss_sync_time_enable"

+#define BUF_LEN 258

+#define TIME_BUF 100

+#define SYNC_TIME_SUCCESS 0

+#define NTP_ALREADY_ENABLE 1

+#define NTP_ALREADY_DISABLE 2

+

+#define OPEN_ERROR 7

+#define ERROR_PARA 8

+

+#ifdef MOBILETEK_TARGET_PLATFORM_T106

+#define NTP_RESTART_BUF "/etc/init.d/sntp restart"

+#define NTP_STOP_BUF "/etc/init.d/sntp stop"

+#define NTP_START_BUF "/etc/init.d/sntp start"

+#define PGREP_NTP_DARMON "pgrep -x /usr/bin/sntp"

+#define SET_RTC() lynq_set_rtc_time()

+#else

+#define NTP_RESTART_BUF "systemctl restart ntpd"

+#define NTP_STOP_BUF "systemctl stop ntpd"

+#define NTP_START_BUF "systemctl start ntpd"

+#define PGREP_NTP_DARMON "pgrep ntpd"

+#define SET_RTC() system("hwclock -w -f /dev/rtc0")

+#endif

+

+#ifdef MOBILETEK_TARGET_PLATFORM_T106

+    typedef int (*sc_rtc_time_get_cb)(unsigned int src_id, unsigned long ulsec);

+extern int sc_rtc_timer_init(void);

+extern int sc_rtc_timer_uninit(void);

+extern int sc_rtc_time_set(int srcid);

+extern int sc_rtc_time_get(int srcid, sc_rtc_time_get_cb rtc_notify);

+

+char sync_from_rtc_cb_flag = 1;

+char rtc_time_get_cb_flag = 1;

+static unsigned long s_rtc_sec = 0;

+

+static int sync_from_rtc_cb(unsigned int src_id, unsigned long ulsec)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    sync_from_rtc_cb_flag = 1;

+    struct tm rtc_time = {0};

+    time_t tmp = 0;

+    char command[100] = "";

+    tmp = (time_t)ulsec;

+    rtc_time = *localtime(&tmp);

+

+    LYINFLOG("RTC time now is: %d-%d-%d,%d:%d:%d\n",

+             rtc_time.tm_year + 1900, rtc_time.tm_mon + 1, rtc_time.tm_mday, rtc_time.tm_hour, rtc_time.tm_min, rtc_time.tm_sec);

+    snprintf(command, sizeof(command), "date --set=\'@%lu\' ", ulsec);

+    system(command);

+    sync_from_rtc_cb_flag = 0;

+    return 0;

+}

+

+static int rtc_time_get_cb(unsigned int src_id, unsigned long ulsec)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    rtc_time_get_cb_flag = 1;

+    s_rtc_sec = ulsec;

+    struct tm rtc_time = {0};

+    time_t tmp = 0;

+    tmp = (time_t)ulsec;

+    rtc_time = *localtime(&tmp);

+    LYINFLOG("RTC time now is: %d-%d-%d,%d:%d:%d\n",

+             rtc_time.tm_year + 1900, rtc_time.tm_mon + 1, rtc_time.tm_mday, rtc_time.tm_hour, rtc_time.tm_min, rtc_time.tm_sec);

+    rtc_time_get_cb_flag = 0;

+    return 0;

+}

+

+int lynq_sync_time_from_rtc(void)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    int ret = -1;

+    int srcid = -1;

+    int i = 0;

+    if ((srcid = sc_rtc_timer_init()) <= 0)

+    {

+        LYERRLOG("rtc_timer_demo:rtc_timer_init fail!\n");

+        return -1;

+    }

+    ret = sc_rtc_time_get(srcid, sync_from_rtc_cb);

+    if (ret != 0)

+    {

+        LYERRLOG("sc_rtc_time_get failed !\n");

+        sc_rtc_timer_uninit();

+        return -1;

+    }

+

+    // Wait for the callback function to finish executing. But 5 seconds tops.

+    for (i = 25; i > 0; i--)

+    {

+        if (sync_from_rtc_cb_flag == 0)

+            break;

+        usleep(200000);

+    }

+

+    if (sync_from_rtc_cb_flag != 0)

+    {

+        LYERRLOG("rtc_get_time_cb failed\n");

+        sc_rtc_timer_uninit();

+        return -1;

+    }

+    LYINFLOG("sync from rtc success\n");

+    ret = sc_rtc_timer_uninit();

+    if (0 != ret)

+    {

+        LYERRLOG("uninit failed \n");

+        return -1;

+    }

+    return 0;

+}

+

+int lynq_set_rtc_time(void)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    int ret = -1;

+    int srcid = -1;

+    if ((srcid = sc_rtc_timer_init()) <= 0)

+    {

+        LYERRLOG("rtc_timer_demo:rtc_timer_init fail!\n");

+        return -1;

+    }

+    ret = sc_rtc_time_set(srcid);

+    if (ret != 0)

+    {

+        LYERRLOG("sc_rtc_time_set failed !\n");

+        return -1;

+    }

+    ret = sc_rtc_timer_uninit();

+    if (0 != ret)

+    {

+        LYERRLOG("uninit failed \n");

+        return -1;

+    }

+    return 0;

+}

+

+int lynq_get_rtc_time(unsigned long *ulsec)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    int ret = -1;

+    int srcid = -1;

+    int i = 0;

+    if (NULL == ulsec)

+    {

+        LYERRLOG("NULL parameter!\n");

+        return ERROR_PARA;

+    }

+    if ((srcid = sc_rtc_timer_init()) <= 0)

+    {

+        LYERRLOG("rtc_timer_demo:rtc_timer_init fail!\n");

+        return -1;

+    }

+    ret = sc_rtc_time_get(srcid, rtc_time_get_cb);

+    if (ret != 0)

+    {

+        LYERRLOG("sc_rtc_time_get failed !\n");

+        sc_rtc_timer_uninit();

+        return -1;

+    }

+

+    // Wait for the callback function to finish executing. But 5 seconds tops.

+    for (i = 25; i > 0; i--)

+    {

+        if (rtc_time_get_cb_flag == 0)

+            break;

+        usleep(200000);

+    }

+    if (rtc_time_get_cb_flag != 0)

+    {

+        LYERRLOG("rtc_get_time_cb failed\n");

+        sc_rtc_timer_uninit();

+        return -1;

+    }

+    *ulsec = s_rtc_sec;

+    ret = sc_rtc_timer_uninit();

+    if (0 != ret)

+    {

+        LYERRLOG("uninit failed \n");

+        return -1;

+    }

+    return 0;

+}

+#endif

+

+int lynq_get_time_src_status(time_src_status_s *time_src)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    char nitz_enable[8] = "";

+    char gnss_enable[8] = "";

+    char buf[BUF_LEN] = "";

+    if (NULL == time_src)

+    {

+        LYERRLOG("NULL parameter!\n");

+        return ERROR_PARA;

+    }

+    // get ntp status.

+    int ret = system(PGREP_NTP_DARMON);

+    if (0 == ret)

+    {

+        time_src->ntp = 1;

+    }

+    else

+    {

+        time_src->ntp = 0;

+    }

+

+    // get nitz status

+    sprintf(buf, "%s.%s.%s", LYNQ_UCI_FILE, LYNQ_SYNC_TIME_SECTION, LYNQ_MODEM_TIME_KEY);

+    lynq_uci_get(buf, nitz_enable);

+    time_src->nitz = atoi(nitz_enable);

+

+    // get gnss status

+    sprintf(buf, "%s.%s.%s", LYNQ_UCI_FILE, LYNQ_SYNC_TIME_SECTION, LYNQ_GNSS_TIME_KEY);

+    lynq_uci_get(buf, gnss_enable);

+    time_src->gnss = atoi(gnss_enable);

+

+    return 0;

+}

+

+const char *lynq_read_version()

+{

+    return "SYSTIME_V1.0";

+}

+

+int user_set_time(char *date, char *time)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    char cmd_buf[TIME_BUF] = "";

+    if (NULL == date || NULL == time)

+    {

+        LYERRLOG("NULL parameter!\n");

+        return ERROR_PARA;

+    }

+

+    // set systime

+    snprintf(cmd_buf, sizeof(cmd_buf), "date -s %s+%s", date, time);

+    system(cmd_buf);

+

+    // set RTC by macrofunction

+    SET_RTC();

+    return 0;

+}

+

+int ntp_sync_time(int enable)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    if (enable != 0 && enable != 1)

+    {

+        LYERRLOG("Parameter error! Only 0/1 allowed.\n");

+        return ERROR_PARA;

+    }

+    int ret = system(PGREP_NTP_DARMON);

+    if (0 == ret)

+    {

+        if (enable)

+        {

+            system(NTP_RESTART_BUF);

+            return NTP_ALREADY_ENABLE;

+        }

+        else

+        {

+            system(NTP_STOP_BUF);

+            return SYNC_TIME_SUCCESS;

+        }

+    }

+    else

+    {

+        if (enable)

+        {

+            // Only one time source is allowed to run simultaneously.

+            modem_time_enable(0);

+            gnss_time_enable(0);

+            system(NTP_START_BUF);

+            return SYNC_TIME_SUCCESS;

+        }

+        else

+        {

+            return NTP_ALREADY_DISABLE;

+        }

+    }

+}

+

+int modem_time_enable(int enable)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    char buf[BUF_LEN] = "";

+    int ret = 0;

+    if (enable != 0 && enable != 1)

+    {

+        LYERRLOG("Parameter error! Only 0/1 allowed.\n");

+        return ERROR_PARA;

+    }

+    if (enable)

+    {

+        // Only one time source is allowed to run simultaneously.

+        ntp_sync_time(0);

+        gnss_time_enable(0);

+    }

+    sprintf(buf, "%s.%s.%s=%d", LYNQ_UCI_FILE, LYNQ_SYNC_TIME_SECTION, LYNQ_MODEM_TIME_KEY, enable);

+    ret = lynq_uci_set(buf);

+    if (ret == 4)

+        ret = 0;

+    return ret;

+}

+

+int gnss_time_enable(int enable)

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

+    char buf[BUF_LEN] = "";

+    int ret = 0;

+    if (enable != 0 && enable != 1)

+    {

+        LYERRLOG("Parameter error! Only 0/1 allowed.\n");

+        return ERROR_PARA;

+    }

+    if (enable)

+    {

+        // Only one time source is allowed to run simultaneously.

+        ntp_sync_time(0);

+        modem_time_enable(0);

+    }

+    sprintf(buf, "%s.%s.%s=%d", LYNQ_UCI_FILE, LYNQ_SYNC_TIME_SECTION, LYNQ_GNSS_TIME_KEY, enable);

+    ret = lynq_uci_set(buf);

+    if (ret == 4)

+        ret = 0;

+    return ret;

+}

+

+#ifdef __cplusplus

+}

+#endif

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile
new file mode 100755
index 0000000..57c68c9
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile
@@ -0,0 +1,74 @@
+SHELL = /bin/sh

+RM = rm -f

+

+LOCAL_CFLAGS := -Wall \

+                -std=gnu++14 \

+                -g -Os \

+                -flto \

+                -fPIC \

+                -fpermissive \

+

+ifeq ($(strip $(TARGET_PLATFORM)), T106)

+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0 

+endif

+

+ifeq ($(strip $(TARGET_PLATFORM)), T106)

+LOCAL_CFLAGS += -DMOBILETEK_TARGET_PLATFORM_T106

+endif

+

+LOCAL_CFLAGS += $(CFLAGS)

+$(warning ################# rock ROOT: $(ROOT),includedir:$(includedir),)

+

+LOCAL_PATH   = .

+

+LOCAL_C_INCLUDES = \

+  -I. \

+  -I$(LOCAL_PATH)/include \

+  -I$(ROOT)$(includedir)/logger \

+  -I$(ROOT)$(includedir)/liblog \

+  -I$(ROOT)$(includedir) \

+

+

+LOCAL_LIBS := \

+    -L. \

+    -ldl \

+    -lstdc++ \

+    -lpthread \

+    -lsctel \

+    -llynq-uci \

+

+

+SOURCES = $(wildcard *.cpp)

+

+EXECUTABLE = liblynq-systime.so

+

+OBJECTS=$(SOURCES:.cpp=.o)

+

+.PHONY: build clean install pack_rootfs 

+

+all: build

+$(EXECUTABLE): $(OBJECTS)

+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@

+

+%.o : %.cpp

+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $< 

+

+build:  $(EXECUTABLE)

+	$(warning ########## build $(EXECUTABLE)  ##########)

+

+install:

+	mkdir -p $(ROOT)$(base_libdir)/

+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/

+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk

+

+pack_rootfs:

+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)

+	mkdir -p $(PACK_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)

+.PHONY: clean

+clean:

+	$(RM) $(OBJECTS) $(EXECUTABLE)

+

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config b/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
index 3ac501d..f77fd37 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
@@ -9,7 +9,8 @@
         option gateway '192.168.11.1'

 

 config  lynq_sync_time_rw  'lynq_sync_time'

-

+        option lynq_modem_sync_time_enable '0'

+        option lynq_gnss_sync_time_enable '0'

 config  lynq_autosuspend  'lynq_autosuspend'

         option auto_enable '0'

         option debug '1'

diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/at_ctl/src/atconfig/ps_normal.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/at_ctl/src/atconfig/ps_normal.c
index f7becaa..caac23e 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/at_ctl/src/atconfig/ps_normal.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/at_ctl/src/atconfig/ps_normal.c
@@ -115,6 +115,14 @@
 	void *p[5] = {&timeinfo.time_zone,&timeinfo.sav_time,temp1,temp2,timeinfo.univer_time};

 	int time_zone = 0;

 	

+	//>>>sj.zhang add @2023-08-10 for systime NITZ sync enable/disenable.

+	if(0 != system("uci get lynq_uci.lynq_sync_time.lynq_modem_sync_time_enable | grep -E \'^1$\'"))

+	{

+		at_print(AT_ERR,"zmmi_auto_act: nitz disenabled. \n");

+		return AT_END;

+	}

+	//>>>sj.zhang add @2023-08-10 end.

+

     sc_cfg_get("sntp_time_set_mode", mode, sizeof(mode));

 	if(strcmp(mode, "manual") == 0)

 	{