[Feature][T800][PL][task-view-613] SDK ready upgrade
Only Configure: No
Affected branch: master
Affected module: PL
Is it affected on both ZXIC and MTK: both
Self-test: yes
Doc Update: yes
Change-Id: Iba56399ff28937b03c7f7a058e9710411887e4d3
diff --git a/IC_meta/mtk/2735/liblynq-sdk-ready/liblynq-sdk-ready.bb b/IC_meta/mtk/2735/liblynq-sdk-ready/liblynq-sdk-ready.bb
new file mode 100755
index 0000000..dc2f062
--- /dev/null
+++ b/IC_meta/mtk/2735/liblynq-sdk-ready/liblynq-sdk-ready.bb
@@ -0,0 +1,34 @@
+inherit externalsrc package workonsrc
+
+DESCRIPTION = "lynq sdk ready"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+DEPENDS += "platform-libs liblynq-sim liblynq-uci liblynq-misc"
+
+WORKONSRC = "${TOPDIR}/../LYNQ_PUBLIC/common_src/lib/liblynq-sdk-ready"
+TARGET_CC_ARCH += "${LDFLAGS}"
+FILES_${PN} = "${base_libdir}/*.so \
+ ${base_bindir}\
+ ${base_sbindir}"
+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"
+do_compile () {
+ if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+ else
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+ fi
+}
+
+do_install() {
+ install -d ${D}${base_libdir}/
+ install -d ${D}${includedir}/
+ install ${S}liblynq-sdk-ready.so ${D}${base_libdir}/
+ install ${S}include/lynq_sdk_ready.h ${D}${includedir}/
+}
diff --git a/common_src/framework/lynq-ril-service/src/ril.cpp b/common_src/framework/lynq-ril-service/src/ril.cpp
index 9b5fcc7..e669a43 100755
--- a/common_src/framework/lynq-ril-service/src/ril.cpp
+++ b/common_src/framework/lynq-ril-service/src/ril.cpp
@@ -170,6 +170,8 @@
#define LYNQ_SERVICE_PORT 8088
#define LYNQ_AT_SERVICE_PORT 8087
#define LYNQ_BRODCAST_PORT 8086
+#define LYNQ_SDK_READY_IP "127.0.0.1"
+#define LYNQ_SDK_READY_PORT 8157
#ifdef GSW_RIL_CFG
/*Interfaces lo net addr 127.0.0.1,mask 255.0.0.0,so lo broadcast addr is 127.255.255.255*/
#define LYNQ_RIL_FWK_BROADCAST_IP "127.255.255.255" /*hong.liu change broadcast addr on 2024.2.18*/
@@ -4190,6 +4192,27 @@
}
}
+int lynq_send_ril_restart()
+{
+ RLOGD("lynq send ril restart");
+ struct sockaddr_in sdk_ready_addr;
+ char BUF[8] = {0};
+ ssize_t sent = 0;
+ memset(&sdk_ready_addr,0,sizeof(sdk_ready_addr));
+ sdk_ready_addr.sin_family = AF_INET; //IPv4
+ sdk_ready_addr.sin_port = htons(LYNQ_SDK_READY_PORT);
+ sdk_ready_addr.sin_addr.s_addr = inet_addr(LYNQ_SDK_READY_IP);
+ sprintf(BUF,"%d",RIL_UNSOL_TELEPHONY_RESTART);
+ BUF[4]='\0';
+ sent = sendto(lynq_urc_socket_fd,BUF,8,0, (struct sockaddr *)&sdk_ready_addr, sizeof(sdk_ready_addr));
+ if( sent < 0 )
+ {
+ RLOGE("LYNQ_RIL_urcBroadcast send datalen fail (sent=%d, sendFD=%d)",sent,lynq_urc_socket_fd);
+ return -1;
+ }
+ return 0;
+}
+
static void lynq_get_sim_state(RIL_CardStatus_v6 *card_status)
{
g_lynq_sim_state = card_status->card_state;
@@ -4971,6 +4994,11 @@
handleRingbackTone(data, datalen, soc_id);
break;
}
+ case RIL_UNSOL_TELEPHONY_RESTART:
+ {
+ lynq_send_ril_restart();
+ break;
+ }
default:
break;
}
diff --git a/common_src/lib/liblynq-sdk-ready/demo_test.cpp b/common_src/lib/liblynq-sdk-ready/demo_test.cpp
new file mode 100755
index 0000000..23716fb
--- /dev/null
+++ b/common_src/lib/liblynq-sdk-ready/demo_test.cpp
@@ -0,0 +1,106 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include "lynq_sdk_ready.h"
+
+int (*sdk_ready_register)(const int uToken,const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb);
+int (*get_sdk_ready_status)(int *status);
+
+
+int demo_sdk_status_cb(const lynq_sdk_ready_t *sdk_ready, void *reserve)
+{
+ printf("sdk_ready_status:%d,ref_action:%d\n",sdk_ready->sdk_ready_status,sdk_ready->ref_action);
+ return 0;
+}
+
+void help()
+{
+ printf("help:\n\
+ argv[1]:isvalid(0/1)\n\
+ argv[2]:boot\n\
+ argv[3]:GNSS-MIN:60\n\
+ argv[4]:MD-MIN:30\n\
+ argv[5]:PTN-MIN:120\n\
+ argv[6]:RIL-MIN:10\n\
+ argv[7]:SYS-MIN:120\n\
+ argv[8]:INTR\n\
+ argv[9]:LOAD_AVG\n");
+ return;
+}
+void print_binary(int num) {
+ int i;
+ for (i = sizeof(num) * 8 - 1; i >= 0; i--) {
+ printf("%d", (num >> i) & 1);
+ }
+ printf("\n");
+}
+int main(int argc, char **argv)
+{
+ printf("lynq-sdk-ready begin");
+ lynq_sdk_check_param_t param;
+ void *dlHandle;
+ int bit_sdk_ready_status = 0;
+ memset(¶m,0,sizeof(lynq_sdk_check_param_t));
+ const char *lynqLibPath = "/lib64/liblynq-sdk-ready.so";
+ dlHandle = dlopen(lynqLibPath, RTLD_NOW);
+ if (dlHandle == NULL)
+ {
+ printf("dlopen dlHandle_call failed: %s", dlerror());
+ exit(EXIT_FAILURE);
+ }
+ sdk_ready_register = (int(*)(const int uToken,const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb))dlsym(dlHandle, "lynq_sdk_ready_register");
+ if (sdk_ready_register == NULL) {
+ printf("lynq_init_call not defined or exported in %s", lynqLibPath);
+ exit(EXIT_FAILURE);
+ }
+ get_sdk_ready_status = (int(*)(int *status))dlsym(dlHandle, "lynq_get_sdk_ready_status");
+ if (get_sdk_ready_status == NULL) {
+ printf("lynq_init_call not defined or exported in %s", lynqLibPath);
+ exit(EXIT_FAILURE);
+ }
+ help();
+ if(argc >= 2)
+ {
+ if(atoi(argv[1])==1 && argc >=10)
+ {
+ param.isvalid = atoi(argv[1]);
+ param.period.BOOT = atoi(argv[2]);
+ param.period.GNSS = atoi(argv[3]);
+ param.period.MD = atoi(argv[4]);
+ param.period.PTN = atoi(argv[5]);
+ param.period.RIL = atoi(argv[6]);
+ param.period.SYS = atoi(argv[7]);
+ param.threshold.interrupts = atoi(argv[8]);
+ param.threshold.load_average = atoi(argv[9]);
+ }
+ }
+ printf("You input param:\n\
+ param.isvalid:%d\n\
+ param.period.BOOT:%d\n\
+ param.period.GNSS:%d\n\
+ param.period.MD:%d\n\
+ param.period.PTN:%d\n\
+ param.period.RIL:%d\n\
+ param.period.SYS:%d\n\
+ param.threshold.interrupts:%llu\n\
+ param.threshold.load_average:%d\n",param.isvalid,
+ param.period.BOOT,
+ param.period.GNSS,
+ param.period.MD,
+ param.period.PTN,
+ param.period.RIL,
+ param.period.SYS,
+ param.threshold.interrupts,
+ param.threshold.load_average);
+ sdk_ready_register(1024,¶m,demo_sdk_status_cb);
+ while (1)
+ {
+ sleep(30);
+ get_sdk_ready_status(&bit_sdk_ready_status);//需要的时候调用,不是必选项
+ print_binary(bit_sdk_ready_status);
+ }
+ return 0;
+}
diff --git a/common_src/lib/liblynq-sdk-ready/include/lynq_sdk_ready.h b/common_src/lib/liblynq-sdk-ready/include/lynq_sdk_ready.h
new file mode 100755
index 0000000..7ec43fd
--- /dev/null
+++ b/common_src/lib/liblynq-sdk-ready/include/lynq_sdk_ready.h
@@ -0,0 +1,103 @@
+/**@file lynq_sdk_ready.h
+* @brief Define sdk ready.
+* @details SDK ready defines the exception type, configuration parameters, and corresponding exception handling methods.
+* @author hong.liu@mobiletek.cn
+* @date 2024-10-26
+* @version V1.0
+* @copyright Copyright (c) MobileTek
+*/
+
+#ifndef __LYNQ_SDK_READY__
+#define __LYNQ_SDK_READY__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef enum{
+ LYNQ_E_CONFLICT=9000,
+ LYNQ_E_NULL_ANONALY=9001,
+ LYNQ_E_NORMAL=9010,
+}LYNQ_E;
+
+typedef enum {
+ LYNQ_SDK_READY=0, //ready status
+ LYNQ_SDK_MD_EXCPT=1, //modem crash exception
+ LYNQ_SDK_MD_REBOOT_EXCPT=2, //modem reboot exception
+ LYNQ_SDK_RIL_EXCPT=3, //RIL channel exception
+ LYNQ_SDK_PARTITION_EXCPT=4, //user data partition full
+ LYNQ_SDK_MIN_FREE_EXCPT=5, //Memory is critically low
+ LYNQ_SDK_INTR_EXCPT=6, //Interrupt exception reporting
+ LYNQ_SDK_LOAD_AVG_EXCPT=7, //5-minute average load exception
+ LYNQ_SDK_NET_CHANNEL_EXCPT=8, //systeme NET(data call) channel exception
+ LYNQ_SDK_GNSS_EXCPT=9, //GNSS service exception
+} lynq_sdk_status_t; //5,6,7 Generally used to evaluate whether the system may be in a busy state
+
+typedef enum {
+ LYNQ_ACTION_NOTHING=0, //do nothing
+ LYNQ_ACTION_REBOOT=1, //reboot
+ LYNQ_ACTION_RESET_MD=2, //reset modem
+ LYNQ_ACTION_RETRY_DATA_CALL=3, //retry data call
+ LYNQ_ACTION_PTN_CLEAN=4, //clean user data partition
+ LYNQ_ACTION_SYS_WARNING=5, //system resource shortage warning, restart recommended
+} lynq_sdk_ref_action_t;
+
+typedef struct {
+ lynq_sdk_status_t sdk_ready_status;
+ lynq_sdk_ref_action_t ref_action;
+} lynq_sdk_ready_t;
+
+typedef struct {
+ int MD; //default 60s,modem check period
+ int RIL; //default 30s,RIL channel check period
+ int GNSS; //default 300s,GNSS channel check period
+ int PTN; //default 120s,partition used check period
+ int SYS; //default 120s,system resource check period
+ int BOOT; //default 60s,Boot preparation time. No exceptions will be reported during this time. Only the LYNQ_SDK_READY status will be reported.
+} lynq_sdk_check_period_t;
+
+typedef struct {
+ unsigned long long interrupts; //The number of interrupts added within lynq_sdk_check_period_t.SYS, confirmed based on actual hardware,default=(sys/30)*5000*(cpu core)
+ int load_average; //Average load in lynq_sdk_check_period_t.SYS (actually read the average load for 5 minutes), more confirmed by actual hardware,default=(cpu core)*2。
+} lynq_sdk_check_threshold_t;
+
+typedef struct {
+ int isvalid; //Whether to use the following configuration, 0: not use, 1: use
+ lynq_sdk_check_period_t period;
+ lynq_sdk_check_threshold_t threshold;
+} lynq_sdk_check_param_t;
+
+/**@brief SDK ready callback function
+* @param lynq_sdk_ready_t *sdk_ready [OUT] <sdk_ready>: Exception type and handling information carried after the callback is triggered.
+* @param void *reserve [OUT] <reserve>: reserve param,Don't pay attention for now.
+* @warning Do not perform any blocking operations or locks in the callback function..
+* @return Return value: 0 if successful, other values if failed
+*/
+typedef int (*lynq_sdk_status_cb)(const lynq_sdk_ready_t *sdk_ready, void *reserve);
+
+/**@brief Register callback function
+* @param uToken [IN] <uToken>: user identifier. If multiple processes call this library, uToken must be different for each process.
+* @param lynq_sdk_check_param_t* param [IN] <param>: SDK check related period and threshold
+* @param lynq_sdk_status_cb* sdk_status_cb [OUT] <sdk_status_cb>: Callback function, triggered when an exception event occurs.
+* @warning If the registration fails, the program will exit directly
+* @return Return value: 0 if successful, other values if failed
+*/
+int lynq_sdk_ready_register(const int uToken, const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb);
+
+/**@brief get sdk ready status
+* @param int *status [OUT] <status>: sdk ready status Bitwise AND, 0 no exception, 1 exception
+* bit0:RIL
+* bit1:MD
+* bit2:GNSS
+* bit3:PTN
+* bit4:SYS
+* @return Return value: 0 if successful, other values if failed
+*/
+int lynq_get_sdk_ready_status(int *status);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/common_src/lib/liblynq-sdk-ready/lynq_sdk_ready.cpp b/common_src/lib/liblynq-sdk-ready/lynq_sdk_ready.cpp
new file mode 100755
index 0000000..aa57ed3
--- /dev/null
+++ b/common_src/lib/liblynq-sdk-ready/lynq_sdk_ready.cpp
@@ -0,0 +1,1150 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <string.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <include/lynq_uci.h>
+#include <lynq_misc/lynq_misc.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <assert.h>
+#include "lynq_sdk_ready.h"
+
+#define LOG_TAG "LYNQ_SDK_READY"
+#define DEST_PORT 8088
+#define LYNQ_BRODCAST_PORT 8086
+
+#define SDK_READY_PORT 8157
+#define DSET_IP_ADDRESS "127.0.0.1"
+#define RIL_REQUEST_DEVICE_IDENTITY 98
+#define MAX_LEN 1024
+#define TIMER 30
+#define LOG_UCI_FILE "lynq_uci"
+#define LOG_UCI_MODULE "debug_mode"
+#define update_ril_digit 0x7 //The last three digits are reserved for RIL service,0x111
+#define update_userdata_digit 1<<3
+#define update_gnss_digit 1<<4
+
+#define DEFAULT_PERIOD_RIL 30
+#define DEFAULT_PERIOD_GNSS 300
+#define DEFAULT_PERIOD_MD 60
+#define DEFAULT_PERIOD_PTN 120
+#define DEFAULT_PERIOD_SYS 120
+#define DEFAULT_PERIOD_BOOT 60
+
+#define MIN_PERIOD_RIL 10
+#define MIN_PERIOD_GNSS 60
+#define MIN_PERIOD_MD 30
+#define MIN_PERIOD_PTN 120
+#define MIN_PERIOD_SYS 120
+#define RIL_UNSOL_TELEPHONY_RESTART 3113
+
+#define GET_CPU_NUM "cat /proc/cpuinfo | grep processor | wc -l"
+#define GET_LOAD_AVG_INFO "/proc/loadavg"
+#define GET_INTR_INFO "/proc/stat"
+#define GET_MEM_INFO "/proc/meminfo"
+#define GET_MIN_FREE "/proc/sys/vm/min_free_kbytes"
+
+#define BIT_EXCPT_RIL 1
+#define BIT_EXCPT_MD 1 << 1
+#define BIT_EXCPT_GNSS 1 << 2
+#define BIT_EXCPT_PTN 1 << 3
+#define BIT_EXCPT_SYS 1 << 4
+
+using ::android::Parcel;
+
+static pthread_mutex_t g_lynq_sim_sendto_mutex;
+static pthread_mutex_t lock;
+static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
+
+// 全局变量
+static lynq_sdk_check_param_t *global_param = NULL;
+static lynq_sdk_status_cb global_sdk_status_cb = NULL;
+static lynq_sdk_ready_t global_sdk_status;
+static int utoken = 0;
+static int global_sdk_ready_status = 1;
+static int s_ril_started = 0;
+static int s_sys_started = 0;
+static int s_ptn_started = 0;
+static int s_gnss_started = 0;
+static int boot_ril_check_timer[8] = {2,2,4,4,8,8,16,16};
+enum in_ril_excpt {
+ RIL_REQUEST_SUCCESS=0,
+ RIL_MODEM_BOOT_EXCPT=1,
+ RIL_RESP_ERROR_FAIL=2,
+ RIL_SOCKET_CREATE_FAIL=3,
+ RIL_SOCKET_SEND_REC_FAIL=4,
+};
+
+typedef struct{
+ int uToken;
+ int request;
+ int paramLen;
+ char param[MAX_LEN];
+}lynq_client_t;
+
+
+void unlock_with_s_start(int *s_start)
+{
+ pthread_mutex_lock(&s_startupMutex);
+ *s_start = 1;
+ pthread_cond_broadcast(&s_startupCond);
+ pthread_mutex_unlock(&s_startupMutex);
+}
+long get_uptime()
+{
+ struct timespec start_time;
+ clock_gettime(CLOCK_MONOTONIC, &start_time);
+ return start_time.tv_sec;
+}
+const char * sdk_status_excpt_to_string(lynq_sdk_status_t excpt)
+{
+ switch(excpt)
+ {
+ case LYNQ_SDK_READY: return "LYNQ_SDK_READY";
+ case LYNQ_SDK_MD_EXCPT: return "LYNQ_SDK_MD_EXCPT";
+ case LYNQ_SDK_MD_REBOOT_EXCPT: return "LYNQ_SDK_MD_REBOOT_EXCPT";
+ case LYNQ_SDK_RIL_EXCPT: return "LYNQ_SDK_RIL_EXCPT";
+ case LYNQ_SDK_PARTITION_EXCPT: return "LYNQ_SDK_PARTITION_EXCPT";
+ case LYNQ_SDK_MIN_FREE_EXCPT: return "LYNQ_SDK_MIN_FREE_EXCPT";
+ case LYNQ_SDK_INTR_EXCPT: return "LYNQ_ACTION_INTR_EXCPT";
+ case LYNQ_SDK_LOAD_AVG_EXCPT: return "LYNQ_SDK_LOAD_AVG_EXCPT";
+ case LYNQ_SDK_NET_CHANNEL_EXCPT: return "LYNQ_SDK_NET_CHANNEL_EXCPT";
+ case LYNQ_SDK_GNSS_EXCPT: return "LYNQ_SDK_GNSS_EXCPT";
+ default: return "<unknown excpt>";
+ }
+}
+const char * sdk_status_action_to_string(lynq_sdk_ref_action_t action)
+{
+ switch(action)
+ {
+ case LYNQ_ACTION_NOTHING: return "LYNQ_ACTION_NOTHING";
+ case LYNQ_ACTION_REBOOT: return "LYNQ_ACTION_REBOOT";
+ case LYNQ_ACTION_RESET_MD: return "LYNQ_ACTION_RESET_MD";
+ case LYNQ_ACTION_RETRY_DATA_CALL: return "LYNQ_ACTION_RETRY_DATA_CALL";
+ case LYNQ_ACTION_PTN_CLEAN: return "LYNQ_ACTION_PTN_CLEAN";
+ case LYNQ_ACTION_SYS_WARNING: return "LYNQ_ACTION_SYS_WARNING";
+ default: return "<unknown action>";
+ }
+}
+void reset_sdk_ready_status()
+{
+ global_sdk_status.sdk_ready_status = LYNQ_SDK_READY;
+ global_sdk_status.ref_action = LYNQ_ACTION_NOTHING;
+}
+void trigger_sdk_ready_cb(lynq_sdk_status_t excpt, lynq_sdk_ref_action_t action)
+{
+ pthread_mutex_lock(&lock);
+ RLOGI("trigger sdk ready cb excpt:%s,action:%s",sdk_status_excpt_to_string(excpt),sdk_status_action_to_string(action));
+ long uptime = get_uptime();
+ if((excpt != LYNQ_SDK_READY) && (uptime < global_param->period.BOOT))
+ {
+ goto end;
+ }
+ //if((global_sdk_status.sdk_ready_status == excpt) && (global_sdk_status.ref_action == action))
+ //{
+ // goto end;
+ //}
+ global_sdk_status.sdk_ready_status = excpt;
+ global_sdk_status.ref_action = action;
+ global_sdk_status_cb(&global_sdk_status,NULL);
+end:
+ pthread_mutex_unlock(&lock);
+ return;
+}
+//maybe uci,or other
+void set_sdk_ready_nv(int value)
+{
+ char cmd[64] = {0};
+ RLOGI("set_sdk_ready_nv:%d",value);
+ sprintf(cmd,"uci set lynq_uci.sdk_ready=%d",value);//set uci
+ system(cmd);
+ return;
+}
+void set_sdk_ready_status_bit(int bit,int status)
+{
+ pthread_mutex_lock(&lock);
+ int old = 1;
+ if((global_sdk_ready_status & bit) == 0)
+ {
+ old = 0;
+ }
+ if(old == status)
+ {
+ goto end;
+ }
+ if(status == 1)
+ {
+ global_sdk_ready_status |= bit;
+ }
+ else
+ {
+ global_sdk_ready_status &= ~bit;
+ }
+ set_sdk_ready_nv(global_sdk_ready_status);
+end:
+ pthread_mutex_unlock(&lock);
+ return;
+}
+static int get_md_sta(void)
+{
+ FILE *fp;
+ char buffer[64]={};
+ fp = popen("cat /sys/kernel/ccci/boot","r");
+ if(fp == NULL)
+ {
+ RLOGD("function %s fp is null\n", __FUNCTION__);
+ return 0;
+ }
+ fgets(buffer,sizeof(buffer),fp);
+ if(!strlen(buffer))
+ {
+ RLOGD("function %s line %d\n", __FUNCTION__, __LINE__);
+ pclose(fp);
+ return 0;
+ }
+ if(buffer[4] == '4')
+ {
+ pclose(fp);
+ return 1;
+ }
+ RLOGD("function %s line %d\n", __FUNCTION__, __LINE__);
+ pclose(fp);
+ return 0;
+}
+
+static int check_service(const char *service)
+{
+ FILE *fp = NULL;
+ char buffer[1024]={};
+ if(!strcmp(service, "/usr/sbin/mtkfusionrild"))
+ {
+ fp = popen("ps -ef|grep rild","r");
+ }
+ else if(!strcmp(service, "lynq-ril-service"))
+ {
+ fp = popen("ps -ef|grep ril-service","r");
+ }
+ if(fp == NULL)
+ {
+ RLOGD("function %s fp is null\n", __FUNCTION__);
+ return 0;
+ }
+ while(NULL != fgets(buffer,sizeof(buffer),fp))
+ {
+ if(strstr(buffer,service))
+ {
+ pclose(fp);
+ RLOGD("check_service 1\n");
+ return 1;
+ }
+ }
+ RLOGD("check_service 0\n");
+ pclose(fp);
+ return 0;
+}
+
+/**
+ * @brief find partition zhengshu for exzample 5.7M,get value 5
+ *
+ * @param arg
+ * @return
+ */
+static void removeSpaces(char* str)
+{
+ char* dest = str;
+ while (*str) {
+ if (*str != ' ') {
+ *dest++ = *str;
+ }
+ str++;
+ }
+ *dest = '\0';
+ return ;
+}
+void check_ril_sleep(int count)
+{
+ if((count < sizeof(boot_ril_check_timer)/sizeof(int)) && ((global_sdk_ready_status & 1) == 1))// total 60s
+ {
+ sleep(boot_ril_check_timer[count]);
+ }
+ else
+ {
+ sleep(global_param->period.RIL);
+ }
+ return;
+}
+void update_ril_value(int value)
+{
+ switch (value)
+ {
+ case RIL_REQUEST_SUCCESS:
+ {
+ trigger_sdk_ready_cb(LYNQ_SDK_READY, LYNQ_ACTION_NOTHING);
+ set_sdk_ready_status_bit(BIT_EXCPT_RIL,0);
+ break;
+ }
+ case RIL_MODEM_BOOT_EXCPT:
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_RIL,1);
+ trigger_sdk_ready_cb(LYNQ_SDK_MD_EXCPT,LYNQ_ACTION_REBOOT);
+ break;
+ }
+ case RIL_RESP_ERROR_FAIL:
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_RIL,1);
+ trigger_sdk_ready_cb(LYNQ_SDK_RIL_EXCPT,LYNQ_ACTION_NOTHING);
+ break;
+ }
+ case RIL_SOCKET_CREATE_FAIL:
+ case RIL_SOCKET_SEND_REC_FAIL:
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_RIL,1);
+ trigger_sdk_ready_cb(LYNQ_SDK_RIL_EXCPT,LYNQ_ACTION_REBOOT);
+ break;
+ }
+ default:
+ RLOGE("Not this case:%d",value);
+ }
+ return;
+}
+
+void update_userdata_value()
+{
+ pthread_mutex_lock(&lock);
+ trigger_sdk_ready_cb(LYNQ_SDK_PARTITION_EXCPT, LYNQ_ACTION_REBOOT);
+ set_sdk_ready_status_bit(BIT_EXCPT_PTN,1);
+ pthread_mutex_unlock(&lock);
+ return;
+}
+
+void update_gnss_value()
+{
+ pthread_mutex_lock(&lock);
+ trigger_sdk_ready_cb(LYNQ_SDK_GNSS_EXCPT, LYNQ_ACTION_REBOOT);
+ set_sdk_ready_status_bit(BIT_EXCPT_GNSS,1);
+ pthread_mutex_unlock(&lock);
+ return;
+}
+/**
+ * @brief send request imei
+ *
+ * @param arg
+ * 线程run起来后前两个60s 不做异常上报,这段时间是模组就绪时间因此只报ready 状态,60s 以后如果还是检测到异常,说明是真异常
+ * @return void*
+ */
+void * timer_request_imei(void * arg)
+{
+ unlock_with_s_start(&s_ril_started);
+ int send_num = -1;
+ int recv_num = -1;
+ int resp_type = -1;
+ int request = -1;
+ int slot_id = -1;
+ int token = -1;
+ int res_error = -1;
+ int count = 0;
+ Parcel p;
+ struct sockaddr_in addr_serv;
+ struct sockaddr_in liblynq_sdk_ready_socket;
+ memset(&liblynq_sdk_ready_socket, 0,sizeof(liblynq_sdk_ready_socket));
+ memset(&addr_serv, 0, sizeof(addr_serv));
+ addr_serv.sin_family = AF_INET;
+ addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
+ addr_serv.sin_port = htons(DEST_PORT);
+ liblynq_sdk_ready_socket.sin_family = AF_INET;
+ liblynq_sdk_ready_socket.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
+ int len_addr_serv = sizeof(addr_serv);
+
+ lynq_client_t client_t;
+ char res_data[MAX_LEN] = {0};
+ client_t.request = RIL_REQUEST_DEVICE_IDENTITY;
+ client_t.paramLen = 0;
+ client_t.uToken = utoken;
+ memset(client_t.param, 0, sizeof(client_t.param));
+
+ struct timeval timeOut;
+ timeOut.tv_sec = 3;//timeout time 3s
+ timeOut.tv_usec = 0;
+
+ int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (-1 == sock_fd)
+ {
+ RLOGD("__FUNCTION__ %s create sock_fd failed %s\n", __FUNCTION__, strerror(errno));
+ exit(EXIT_FAILURE);
+ return NULL;
+ }
+ int ret = bind(sock_fd, (struct sockaddr *)&liblynq_sdk_ready_socket, sizeof(liblynq_sdk_ready_socket));
+ if (-1 == ret)
+ {
+ RLOGE("liblynq_data_socket bind fail,errno:%d",errno);
+ return NULL;
+ }
+
+ if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
+ {
+ RLOGD("__FUNCTION__ %s time out setting failed %s\n", __FUNCTION__, strerror(errno));
+ exit(EXIT_FAILURE);
+ return NULL;
+ }
+ while (1)
+ {
+ bzero(res_data, MAX_LEN);
+ pthread_mutex_lock(&g_lynq_sim_sendto_mutex);
+ send_num = sendto(sock_fd, &client_t, sizeof(client_t), 0, (struct sockaddr *)&addr_serv, len_addr_serv);
+ RLOGD("send_num %d\n", send_num);
+ if(send_num == 0)
+ {
+ RLOGD("__FUNCTION__ %s Close to end %s\n", __FUNCTION__, strerror(errno));
+ //unknow
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+ continue;
+ }
+ if(send_num < 0)
+ {
+ RLOGD("__FUNCTION__ %s sendto error %s\n", __FUNCTION__, strerror(errno));
+ //unknow
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+ continue;
+ }
+ //get data msg
+ recv_num = recvfrom(sock_fd,res_data,sizeof(char)*MAX_LEN,0,(struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
+ RLOGD("recv_num %d\n", recv_num);
+ if(recv_num == -1 && errno == EAGAIN)
+ {
+ RLOGD("__FUNCTION__ %srecvfrom fail because timeout\n", __FUNCTION__);
+ /*set uci*/
+ if(!get_md_sta())
+ {
+ update_ril_value(RIL_MODEM_BOOT_EXCPT);
+ }
+ else
+ {
+ if(check_service("/usr/sbin/mtkfusionrild"))//rild work
+ {
+ if(!check_service("lynq-ril-service"))//not find,must be socket error
+ {
+ update_ril_value(RIL_SOCKET_CREATE_FAIL);
+ }
+ else
+ {
+ //unknow error
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ }
+ }
+ else//rild no work
+ {
+ //unknow
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ }
+ }
+ pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+ check_ril_sleep(count);
+ count++;
+ continue;
+ }
+ if(recv_num <= 0)
+ {
+ RLOGD("__FUNCTION__ %s recvfrom fail %s\n", __FUNCTION__, strerror(errno));
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+ check_ril_sleep(count);
+ count++;
+ continue;
+ }
+ p.setData((uint8_t *)res_data,sizeof(char)*recv_num);
+ p.setDataPosition(0);
+ if(p.dataAvail() > 0)
+ {
+ p.readInt32(&resp_type);
+ p.readInt32(&token);
+ p.readInt32(&request);
+ p.readInt32(&slot_id);
+ p.readInt32(&res_error);
+ }
+ /*judge the res_error*/
+ if(!res_error)
+ {
+ update_ril_value(RIL_REQUEST_SUCCESS);
+ }
+ else
+ {
+ update_ril_value(RIL_RESP_ERROR_FAIL);
+ }
+ count = 0;
+ RLOGD("__FUNCTION__ %s res_error %d\n", __FUNCTION__, res_error);
+ /*judge the res_error*/
+ pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+ check_ril_sleep(sizeof(boot_ril_check_timer)/sizeof(int));
+ }
+ return NULL;
+}
+
+void * wait_ril_event(void * arg)
+{
+ unlock_with_s_start(&s_ril_started);
+ int REC_BUFF_LEN = 64;
+ int recv_num = 0;
+ char rec_data[REC_BUFF_LEN] = {0};
+ int count = 0;
+ struct sockaddr_in wait_ril_event_socket;
+ struct sockaddr_in addr_client;
+ memset(&wait_ril_event_socket, 0,sizeof(wait_ril_event_socket));
+ memset(&addr_client, 0, sizeof(addr_client));
+ wait_ril_event_socket.sin_family = AF_INET;
+ wait_ril_event_socket.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
+ wait_ril_event_socket.sin_port = htons(SDK_READY_PORT);
+ int len_addr_serv = sizeof(addr_client);
+
+ int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (-1 == sock_fd)
+ {
+ RLOGD("__FUNCTION__ %s create sock_fd failed %s\n", __FUNCTION__, strerror(errno));
+ exit(EXIT_FAILURE);
+ return NULL;
+ }
+ int ret = bind(sock_fd, (struct sockaddr *)&wait_ril_event_socket, sizeof(wait_ril_event_socket));
+ if (-1 == ret)
+ {
+ RLOGE("liblynq_data_socket bind fail,errno:%d",errno);
+ exit(EXIT_FAILURE);
+ return NULL;
+ }
+ while(1)
+ {
+ memset(rec_data,0,REC_BUFF_LEN);
+ recv_num = recvfrom(sock_fd,rec_data,sizeof(char)*REC_BUFF_LEN,0,(struct sockaddr *)&addr_client,(socklen_t*)&len_addr_serv);
+ if(recv_num <= 0)
+ {
+ RLOGD("__FUNCTION__ %s Close to end\n", __FUNCTION__);
+ update_ril_value(RIL_SOCKET_SEND_REC_FAIL);
+ continue;
+ }
+ rec_data[recv_num] = '\0';
+ if((atoi(rec_data) == RIL_UNSOL_TELEPHONY_RESTART) && (count%2 == 0))//this urc will be reported twice in a row
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_MD, 1);
+ trigger_sdk_ready_cb(LYNQ_SDK_MD_REBOOT_EXCPT,LYNQ_ACTION_RETRY_DATA_CALL);
+ count = 0;
+ }
+ count ++;
+ }
+ close(sock_fd);
+}
+
+
+void delete_enter(char data[])
+{
+ char *find = strchr(data, '\n');
+ if(find)
+ *find = '\0';
+ return ;
+}
+
+unsigned long long get_interrupts(int fd,char *buffer,int size)
+{
+ char *line = NULL;
+ unsigned long long intr_value = 0;
+ memset(buffer,0,size);
+ lseek(fd, 0, SEEK_SET);
+ ssize_t bytes_intr_read = read(fd,buffer, size - 1);
+ buffer[bytes_intr_read] = '\0';
+ line = strstr(buffer, "intr");
+ if (line == NULL)
+ {
+ RLOGE("get intr fail");
+ }
+ else
+ {
+ line += 5;
+ sscanf(line,"%llu",&intr_value);
+ }
+ return intr_value;
+}
+unsigned long long get_mem_free(int fd,char *buffer,int size)
+{
+ char *line = NULL;
+ unsigned long long mem_value = 0;
+ lseek(fd, 0, SEEK_SET);
+ memset(buffer,0,size);
+ ssize_t bytes_mem_read = read(fd, buffer, size - 1);
+ buffer[bytes_mem_read] = '\0';
+ line = strstr(buffer, "MemFree:");
+ if (line == NULL)
+ {
+ RLOGE("get MemFree fail");
+ }
+ else
+ {
+ line += 9;
+ while (*line == ' ')
+ {
+ line++;
+ }
+ sscanf(line,"%llu",&mem_value);
+ }
+ return mem_value;
+}
+
+void *check_system(void * arg)
+{
+ int fd_mem = 0;
+ int fd_intr = 0;
+ int fd_avg = 0;
+ int fd_free = 0;
+ int BUFFER_SIZE = 512;
+ unsigned long long min_free = 0;
+ unsigned long long mem_value = 0;
+ unsigned long long intr_value_old = 0;
+ unsigned long long intr_value_new = 0;
+ float avg_value = 0;
+ int excpt_flag = 0;
+ char sys_buffer[BUFFER_SIZE];
+ char min_free_buffer[BUFFER_SIZE];
+ unlock_with_s_start(&s_sys_started);
+ fd_mem = open(GET_MEM_INFO,O_RDONLY);
+ fd_free = open(GET_MIN_FREE,O_RDONLY);
+ fd_intr = open(GET_INTR_INFO,O_RDONLY);
+ fd_avg = open(GET_LOAD_AVG_INFO,O_RDONLY);
+ if((fd_mem < 0) || (fd_intr < 0) || (fd_avg < 0) || (fd_free < 0))
+ {
+ RLOGE("check system open fail");
+ exit(EXIT_FAILURE);
+ }
+ memset(min_free_buffer,0,BUFFER_SIZE);
+ ssize_t bytes_min_free_read = read(fd_free, min_free_buffer, BUFFER_SIZE - 1);
+ if(bytes_min_free_read == -1)
+ {
+ RLOGE("get min free fail");
+ exit(EXIT_FAILURE);
+ }
+ min_free = atoi(min_free_buffer);
+ close(fd_free);
+ ssize_t bytes_avg_read = 0;
+ intr_value_old = get_interrupts(fd_intr, sys_buffer, BUFFER_SIZE);
+ while(1)
+ {
+ memset(sys_buffer,0,BUFFER_SIZE);
+ lseek(fd_avg, 0, SEEK_SET);
+ bytes_avg_read = read(fd_avg, sys_buffer, BUFFER_SIZE - 1);
+ sys_buffer[bytes_avg_read] = '\0';
+ sscanf(sys_buffer,"%*f %f",&avg_value);
+
+ mem_value = get_mem_free(fd_mem, sys_buffer, BUFFER_SIZE);
+ intr_value_new = get_interrupts(fd_intr, sys_buffer, BUFFER_SIZE);
+ //pages_min = /proc/sys/vm/min_free_kbytes
+ //pages_low = pages_min*5/4
+ //pages_high = pages_min*3/2
+ if((mem_value >= min_free) && (mem_value < min_free*1.25))//pages_min-pages_low
+ {
+ trigger_sdk_ready_cb(LYNQ_SDK_MIN_FREE_EXCPT,LYNQ_ACTION_SYS_WARNING);
+ excpt_flag = 1;
+ }
+ if(mem_value < min_free)
+ {
+ trigger_sdk_ready_cb(LYNQ_SDK_MIN_FREE_EXCPT,LYNQ_ACTION_REBOOT);
+ excpt_flag = 1;
+ }
+ if(avg_value > global_param->threshold.load_average)
+ {
+ trigger_sdk_ready_cb(LYNQ_SDK_LOAD_AVG_EXCPT,LYNQ_ACTION_SYS_WARNING);
+ excpt_flag = 1;
+ }
+ if((intr_value_new - intr_value_old) > global_param->threshold.interrupts)
+ {
+ trigger_sdk_ready_cb(LYNQ_SDK_INTR_EXCPT,LYNQ_ACTION_SYS_WARNING);
+ excpt_flag = 1;
+ }
+ set_sdk_ready_status_bit(BIT_EXCPT_SYS,excpt_flag);
+ RLOGI("memfree:%llu,intr_old:%llu,intr_new:%llu,intr_delat:%llu,avg:%.2f\n",mem_value,intr_value_old,intr_value_new,(intr_value_new - intr_value_old),avg_value);
+ intr_value_old = intr_value_new;
+ excpt_flag = 0;
+ sleep(global_param->period.SYS);
+ }
+ close(fd_mem);
+ close(fd_intr);
+ close(fd_avg);
+}
+
+/* old code 2024/11/04 close
+void *check(void * arg)
+{
+
+ char pid[200][8];
+ char ffd[200][4];
+ char buf[64];
+ char check_time[4];
+ char timebuf[32];
+ int num = 1;
+ int i=0;
+ int j;
+ FILE *fp,*fp_1;
+ int ret;
+
+ RLOGD("check cpu/pid/interrupts/fd!!!\n");
+ system("mkdir /media/check_file");
+ system("touch /media/check_time");
+ fp_1 = popen("cat /media/check_time","r");
+ if(fgets(check_time, 4, fp_1) != NULL)
+ {
+ num = atoi(check_time);
+ }
+ pclose(fp_1);
+ while(1)
+ {
+ i = 0;
+ system("date >>/media/check_file/cpu_moniter.txt");
+ ret = system("top -b |head -n 25 >>/media/check_file/cpu_moniter.txt");
+ RLOGD("cpu ret %d", ret);
+ system("date >>/media/check_file/inter_moniter.txt");
+ ret = system("cat /proc/interrupts |grep -v \": 0 0\" >>/media/check_file/inter_moniter.txt");
+ RLOGD("interrupts ret %d", ret);
+
+ system("date >>/media/check_file/pid_moniter.txt");
+ ret = system("ps -eo \"%p %a\" | grep -v \"\\[\" >>/media/check_file/pid_moniter.txt");
+ RLOGD("pid ret %d", ret);
+
+ system("date >>/media/check_file/meminfo_moniter.txt");
+ ret = system("cat /proc/meminfo >>/media/check_file/meminfo_moniter.txt");
+ RLOGD("meminfo ret %d", ret);
+
+ system("date >>/media/check_file/buddyinfo_moniter.txt");
+ ret = system("cat /proc/buddyinfo >>/media/check_file/buddyinfo_moniter.txt");
+ RLOGD("buddyinfo ret %d", ret);
+
+ system("date >>/media/check_file/ps_auxw_moniter.txt");
+ ret = system("ps -auxw|grep -v \"0.0 0.0\"|grep -v \"0.1 0.0\"|grep -v \"0.0 0.1\" >>/media/check_file/ps_auxw_moniter.txt");
+ RLOGD("ps_auxw ret %d", ret);
+
+ system("date >>/media/check_file/cur_freq_moniter.txt");
+ ret = system("cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq >>/media/check_file/cur_freq_moniter.txt");
+ RLOGD("cur_freq ret %d", ret);
+
+ system("date >>/media/check_file/available_frequencies_moniter.txt");
+ ret = system("cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies >>/media/check_file/available_frequencies_moniter.txt");
+ RLOGD("available_frequencies ret %d", ret);
+
+ system("date >>/media/check_file/fd_moniter.txt");
+ fp = popen("ps -eo \"%p %a\" | grep -v \"\\[\"|awk '{print $1}'","r");
+ while(fgets(pid[i], 8, fp) != NULL)
+ {
+ delete_enter(pid[i]);
+ i++;
+ }
+ pclose(fp);
+
+ for(j=1;j<i;j++)
+ {
+ sprintf(buf, "ls /proc/%s/fd | wc -l", pid[j]);
+ fp = popen(buf, "r");
+ fgets(ffd[j], 4, fp);
+ sprintf(buf,"echo \"pid: %s, fd_num: %s\" >>/media/check_file/fd_moniter.txt",pid[j], ffd[j]);
+ system(buf);
+ pclose(fp);
+ }
+
+ if(num > 228)
+ {
+ system("cp /media/check_file/cpu_moniter.txt /media/check_file/cpu_moniter_1.txt");
+ system("cp /media/check_file/inter_moniter.txt /media/check_file/inter_moniter_1.txt");
+ system("cp /media/check_file/pid_moniter.txt /media/check_file/pid_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/fd_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/meminfo_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/buddyinfo_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/ps_auxw_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/cur_freq_moniter_1.txt");
+ system("cp /media/check_file/fd_moniter.txt /media/check_file/available_frequencies_moniter_1.txt");
+
+
+ system("rm -rf /media/check_file/cpu_moniter.txt");
+ system("rm -rf /media/check_file/inter_moniter.txt");
+ system("rm -rf /media/check_file/pid_moniter.txt");
+ system("rm -rf /media/check_file/fd_moniter.txt");
+ system("rm -rf /media/check_file/meminfo_moniter.txt");
+ system("rm -rf /media/check_file/buddyinfo_moniter.txt");
+ system("rm -rf /media/check_file/ps_auxw_moniter.txt");
+ system("rm -rf /media/check_file/cur_freq_moniter.txt");
+ system("rm -rf /media/check_file/available_frequencies_moniter.txt");
+
+ num = 0;
+ }
+ num++;
+ sprintf(timebuf, "echo \"%d\" >/media/check_time", num);
+ ret = system(timebuf);
+ sleep(300);
+ }
+ return NULL;
+
+}
+
+int num = 0;
+void *check_uci(void * arg)
+{
+ int ret[6];
+ int result = 0;
+ int flag = 0;
+
+ char uci_0[]="/etc/config/lynq_uci";
+ char uci_1[]="/etc/config/lynq_uci_ro";
+ char uci_2[]="/etc/config/mdlog";
+ char uci_3[]="/etc/config/radio_property";
+ char uci_4[]="/etc/config/service";
+ char uci_5[]="/etc/config/usb";
+ RLOGD("start check uci\n");
+ while(num++ < 4)
+ {
+ RLOGD("@@@@@@@num=%d\n", num);
+ flag = 0;
+ ret[0] = system("uci show | grep \"lynq_uci.lynq_ril\" > /dev/null");
+ if(ret[0] != 0)
+ {
+ RLOGD("lynq_uci unload\n");
+ flag = 1;
+ }
+
+ ret[1] = system("uci show | grep \"^lynq_uci_ro\.\" > /dev/null");
+ if(ret[1] != 0)
+ {
+ RLOGD("lynq_uci_ro unload\n");
+ flag = 1;
+ }
+
+ ret[2] = system("uci show | grep \"^mdlog\.\"");
+ if(ret[2] != 0)
+ {
+ RLOGD("mdlog unload\n");
+ flag = 1;
+ }
+
+ ret[3] = system("uci show | grep \"^radio_property\.\" > /dev/null");
+ if(ret[3] != 0)
+ {
+ RLOGD("radio_property unload\n");
+ flag = 1;
+ }
+
+ ret[4] = system("uci show | grep \"^service\.\" > /dev/null");
+ if(ret[4] != 0)
+ {
+ RLOGD("service unload\n");
+ flag = 1;
+ }
+
+ ret[5] = system("uci show | grep \"^usb\.\" > /dev/null");
+ if(ret[5] != 0)
+ {
+ RLOGD("usb unload\n");
+ flag = 1;
+ }
+
+ RLOGD("flag=%d\n",flag);
+ if(flag != 0)
+ {
+ RLOGD("config reload\n");
+ result = chdir("/data_backup/");
+ result =system("tar -zxvf userdata.tar.gz -C /STATE/ >/dev/null");
+ if(result!= 0)
+ {
+ RLOGD("cp config fail\n");
+ }
+ if(ret[0] != 0)
+ {
+ lynq_load_config(uci_0);
+ RLOGD("reload lynq_uci\n");
+ system("systemctl start autosuspend");
+ }
+ if(ret[1] != 0)
+ {
+ lynq_load_config(uci_1);
+ RLOGD("reload lynq_uci_ro\n");
+ }
+ if(ret[2] != 0)
+ {
+ lynq_load_config(uci_2);
+ RLOGD("reload mdlog\n");
+ }
+ if(ret[3] != 0)
+ {
+ lynq_load_config(uci_3);
+ RLOGD("reload radio_property\n");
+ system("systemctl restart mtkfusionrild");
+ }
+ if(ret[4] != 0)
+ {
+ lynq_load_config(uci_4);
+ RLOGD("reload service\n");
+ }
+ if(ret[5] != 0)
+ {
+ lynq_load_config(uci_5);
+ RLOGD("reload usb\n");
+ }
+ }
+ else
+ {
+ RLOGD("uci check success, exit check!\n");
+ break;
+ }
+ sleep(2);
+ }
+ return NULL;
+}
+old code 2024/11/04 close*/
+
+static void t800_check_partition()
+{
+ char buf[64] = {0};
+ FILE *fp = NULL;
+ int q = 22*1024;
+ int ubisize = 0;
+
+ fp = popen("df -l| grep '/data$' | awk '{print $3}'","r");
+ if(fp == NULL)
+ {
+ RLOGD("Failed to run command\n");
+ return;
+ }
+ fgets(buf, sizeof(buf) - 1, fp);
+ RLOGD("buf is: %s\n",buf);
+ ubisize = atoi(buf);
+ if(ubisize >= q)
+ {
+ RLOGD(">set ready 5,userdata size is %d M\n",ubisize);
+ update_userdata_value();
+ }
+ else
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_PTN, 0);
+ }
+ return;
+}
+void t800_check_mnld()
+{
+ FILE *fp;
+ const char *symble = "NRestarts=";
+ const char *cmd = "systemctl show -p NRestarts mnld.service";
+ char buf[64];
+ int count_old = 0;
+ int count_new = 0;
+ while(1)
+ {
+ fp = popen(cmd,"r");
+ while(fgets(buf, sizeof(buf) - 1, fp) != NULL)
+ {
+ if(strncmp(buf,symble,strlen(symble)) == 0)
+ count_new = atoi(buf+strlen(symble));
+ memset(buf,0,sizeof(buf));
+ }
+ if((count_new - count_old) > 1)
+ {
+ update_gnss_value();//out put mnld severe abnormal state
+ RLOGD("mnld is severe abnormal state = %d\n",count_new - count_old);
+ }
+ else
+ {
+ set_sdk_ready_status_bit(BIT_EXCPT_GNSS,0);
+ }
+ pclose(fp);
+ count_old = count_new;
+ sleep(global_param->period.GNSS);
+ }
+ return;
+}
+void *check_partition(void *arg)
+{
+ unlock_with_s_start(&s_ptn_started);
+ while(1)
+ {
+ t800_check_partition();
+ sleep(global_param->period.PTN);
+ }
+ return NULL;
+}
+
+void *check_gnss(void * arg)
+{
+ unlock_with_s_start(&s_gnss_started);
+ t800_check_mnld();
+ return NULL;
+}
+int get_cpu_info()
+{
+ FILE *CPU_FD = NULL;
+ int cpu_num = 0;
+ char cpu_info[8];
+ CPU_FD = popen(GET_CPU_NUM,"r");
+ if(CPU_FD == NULL)
+ {
+ RLOGD("get cpu info fail:%s",GET_CPU_NUM);
+ return -1;
+ }
+ fgets(cpu_info, sizeof(cpu_info) - 1, CPU_FD);
+ cpu_num = atoi(cpu_info);
+ pclose(CPU_FD);
+ return cpu_num;
+}
+int set_default_sdk_check_param(lynq_sdk_check_param_t *param)
+{
+ int cpu_num = 0;
+ param->period.RIL = DEFAULT_PERIOD_RIL;
+ param->period.GNSS = DEFAULT_PERIOD_GNSS;
+ param->period.MD = DEFAULT_PERIOD_MD;
+ param->period.PTN = DEFAULT_PERIOD_PTN;
+ param->period.SYS = DEFAULT_PERIOD_SYS;
+ param->period.BOOT = DEFAULT_PERIOD_BOOT;
+ cpu_num = get_cpu_info();
+ if(cpu_num <= 0)
+ {
+ RLOGE("set default sdk check param fail");
+ return -1;
+ }
+ param->threshold.interrupts = (DEFAULT_PERIOD_SYS/30)*cpu_num*5000;
+ param->threshold.load_average = cpu_num*2;
+ return 0;
+}
+int create_check_threads(void)
+{
+ pthread_t thid,thid_1,thid_2,thid_3,thid_4;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ int ret;
+ pthread_mutex_lock(&s_startupMutex);
+ ret = pthread_create(&thid, &attr, timer_request_imei, NULL);
+ if(ret != 0)
+ {
+ RLOGE("timer_request_imei error!!!");
+ goto excp;
+ }
+ while (s_ril_started == 0)
+ {
+ pthread_cond_wait(&s_startupCond, &s_startupMutex);
+ }
+ ret = pthread_create(&thid_1, &attr, check_system, NULL);
+ if(ret != 0)
+ {
+ RLOGE("check_system error!!!");
+ goto excp;
+ }
+ while (s_sys_started == 0)
+ {
+ pthread_cond_wait(&s_startupCond, &s_startupMutex);
+ }
+
+ ret = pthread_create(&thid_2, &attr,check_gnss,NULL);
+ if(ret != 0)
+ {
+ RLOGD("check_gnss error!!!");
+ goto excp;
+ }
+ while (s_gnss_started == 0)
+ {
+ pthread_cond_wait(&s_startupCond, &s_startupMutex);
+ }
+ ret = pthread_create(&thid_3, &attr,check_partition,NULL);
+ if(ret != 0)
+ {
+ RLOGD("check_partition error!!!");
+ goto excp;
+ }
+ while (s_ptn_started == 0)
+ {
+ pthread_cond_wait(&s_startupCond, &s_startupMutex);
+ }
+ s_ril_started = 0;
+ ret = pthread_create(&thid_4, &attr,wait_ril_event,NULL);
+ if(ret != 0)
+ {
+ RLOGD("wait_ril_event error!!!");
+ goto excp;
+ }
+ while (s_ril_started == 0)
+ {
+ pthread_cond_wait(&s_startupCond, &s_startupMutex);
+ }
+ pthread_mutex_unlock(&s_startupMutex);
+ return 0;
+excp:
+ pthread_mutex_unlock(&s_startupMutex);
+ return LYNQ_E_NORMAL;
+}
+int lynq_sdk_ready_register(const int uToken,const lynq_sdk_check_param_t* param,lynq_sdk_status_cb sdk_status_cb)
+{
+ int ret = 0;
+ if (param == NULL || sdk_status_cb == NULL)
+ {
+ RLOGE("input null");
+ return LYNQ_E_NULL_ANONALY;
+ }
+ utoken = uToken;
+ global_param = (lynq_sdk_check_param_t *)malloc(sizeof(lynq_sdk_check_param_t));
+ if(global_param == NULL)
+ {
+ RLOGE("malloc global_param fail");
+ goto end;
+ }
+ memset(global_param,0,sizeof(lynq_sdk_check_param_t));
+ if(param->isvalid == 0)
+ {
+ ret = set_default_sdk_check_param(global_param);
+ if (ret < 0)
+ {
+ RLOGE("get default param fail");
+ goto end;
+ }
+ }
+ else
+ {
+ if((param->period.RIL < MIN_PERIOD_RIL) || (param->period.GNSS < MIN_PERIOD_GNSS) || (param->period.MD < MIN_PERIOD_MD)
+ || (param->period.PTN < MIN_PERIOD_PTN) || (param->period.SYS < MIN_PERIOD_SYS))
+ {
+ RLOGE("param excption");
+ goto end;
+ }
+ global_param->period.RIL = param->period.RIL;
+ global_param->period.GNSS = param->period.GNSS;
+ global_param->period.MD = param->period.MD;
+ global_param->period.PTN = param->period.PTN;
+ global_param->period.SYS = param->period.SYS;
+ global_param->period.BOOT = param->period.BOOT;
+ global_param->threshold.interrupts = param->threshold.interrupts;
+ global_param->threshold.load_average = param->threshold.load_average;
+ }
+ RLOGI("period.RIL:%d,period.GNSS:%d,period.MD:%d,period.PTN:%d,period.SYS:%d,threshold.interrupts:%llu,threshold.load_average:%d",
+ global_param->period.RIL,global_param->period.GNSS,global_param->period.MD,global_param->period.PTN,
+ global_param->period.SYS,global_param->threshold.interrupts,global_param->threshold.load_average);
+ global_sdk_status_cb = sdk_status_cb;
+ global_sdk_status.sdk_ready_status = (lynq_sdk_status_t)-1;
+ global_sdk_status.ref_action = (lynq_sdk_ref_action_t)-1;
+ set_sdk_ready_nv(1);//开机默认RIL 异常,第一次检测完成之后更新正确值
+ ret = create_check_threads();
+ if(ret != 0)
+ {
+ goto end;
+ }
+ return ret;
+end:
+ exit(EXIT_FAILURE);
+}
+int lynq_get_sdk_ready_status(int *status)
+{
+ if (status == NULL)
+ {
+ RLOGE("sdk_ready_status is null");
+ return LYNQ_E_NULL_ANONALY;
+ }
+ *status = global_sdk_ready_status;
+ return 0;
+}
diff --git a/common_src/lib/liblynq-sdk-ready/makefile b/common_src/lib/liblynq-sdk-ready/makefile
new file mode 100755
index 0000000..faaf70d
--- /dev/null
+++ b/common_src/lib/liblynq-sdk-ready/makefile
@@ -0,0 +1,56 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+ -g -Os \
+ -std=gnu++14 \
+ -flto \
+ -fPIC \
+ -D__LINUX_OS__ \
+
+
+
+LOCAL_PATH = .
+$(warning ################# LEI ROOT: $(ROOT),includedir:$(includedir),LOCAL_PATH:$(LOCAL_PATH))
+LOCAL_C_INCLUDES = \
+ -I. \
+ -I./include \
+ -I$(LOCAL_PATH)/include \
+ -I$(LOCAL_PATH) \
+ -I$(ROOT)$(includedir)/ \
+ -I$(ROOT)$(includedir)/include \
+
+
+LOCAL_LIBS := \
+ -L. \
+ -ldl \
+ -lstdc++ \
+ -llog \
+ -lcutils \
+ -lutils \
+ -lbinder \
+ -lpthread \
+ -llynq-uci \
+ -llynq-misc \
+
+SOURCES = ./lynq_sdk_ready.cpp
+
+EXECUTABLE = liblynq-sdk-ready.so
+
+OBJECTS=$(SOURCES:.cpp=.o)
+
+
+.PHONY: build clean
+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) ##########)
+
+.PHONY: clean
+clean:
+ $(RM) $(OBJECTS) $(EXECUTABLE)