Squashed 'LYNQ_PUBLIC/' content from commit 79d8f932f
git-subtree-dir: LYNQ_PUBLIC
git-subtree-split: 79d8f932fb4ebc4b5aec6c5ace97634912394272
Change-Id: If2527ba937f56fe989487bf71e996f7cfd9fbe61
diff --git a/common_src/lib/liblynq-uci/LICENSE b/common_src/lib/liblynq-uci/LICENSE
new file mode 100644
index 0000000..77f59ed
--- /dev/null
+++ b/common_src/lib/liblynq-uci/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MediaTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+the prior written permission of MediaTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MediaTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MediaTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MEDIATEK 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 MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK 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 MEDIATEK
+SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
diff --git a/common_src/lib/liblynq-uci/include/lynq_uci.h b/common_src/lib/liblynq-uci/include/lynq_uci.h
new file mode 100755
index 0000000..904ff2b
--- /dev/null
+++ b/common_src/lib/liblynq-uci/include/lynq_uci.h
@@ -0,0 +1,37 @@
+#ifndef _LYNQ_UCI_H_
+#define _LYNQ_UCI_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <uci.h>
+
+#define LYNQ_UCI_MAX_LEN 128
+#define LYNQ_UCI_SUCCESS 0
+#define LYNQ_UCI_ERROR 1
+#define LYNQ_UCI_FILE "lynq_uci"
+#define LYNQ_UCI_RO_FILE "lynq_uci_ro"
+
+//static struct uci_context * ctx = NULL;
+
+int lynq_del(char *option);
+
+static int uci_get_value(struct uci_option *o, char *out_buf);
+
+int lynq_uci_get(const char *arg, char *out_buf);
+
+int lynq_uci_set(const char *arg);
+
+int lynq_add_section(char *section_type, char *section);
+
+int lynq_set_value(char *section, char *key, char *value);
+
+int lynq_get_value(char *file, char *section, char *key, char *tmp);
+
+int lynq_load_config(char *filename);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/common_src/lib/liblynq-uci/lynq_uci.config b/common_src/lib/liblynq-uci/lynq_uci.config
new file mode 100755
index 0000000..501a034
--- /dev/null
+++ b/common_src/lib/liblynq-uci/lynq_uci.config
@@ -0,0 +1,32 @@
+config lynq_ril_rw 'lynq_ril'
+ option serverport '8000'
+
+config lynq_log_rw 'lynq_log'
+ option thhandle_level '0'
+ option function_test_level '0'
+
+config lynq_wifi_rw 'lynq_wifi'
+ option gateway '192.168.11.1'
+
+config lynq_sync_time_rw 'lynq_sync_time'
+
+config lynq_autosuspend 'lynq_autosuspend'
+ option auto_enable '0'
+ option debug '0'
+
+config lynq_fota_rw 'lynq_fota'
+
+config service 'adb'
+
+config adb 'tcp'
+ option port '5555'
+
+config lynq_gnss_log_level 'lynq_gnss_log'
+ option level '4'
+
+config lynq_rndis 'lynq_rndis'
+ option initiate '0'
+
+config debug_mode_status 'debug_mode'
+ option rild_debug_status '0'
+ option sysinfo_debug_status '0'
diff --git a/common_src/lib/liblynq-uci/lynq_uci_ro.config b/common_src/lib/liblynq-uci/lynq_uci_ro.config
new file mode 100644
index 0000000..4aa92ac
--- /dev/null
+++ b/common_src/lib/liblynq-uci/lynq_uci_ro.config
@@ -0,0 +1,4 @@
+config lynq_version_ro 'lynq_version'
+
+config lynq_wifi_ro 'lynq_wifi'
+ option serverport '8000'
\ No newline at end of file
diff --git a/common_src/lib/liblynq-uci/makefile b/common_src/lib/liblynq-uci/makefile
new file mode 100755
index 0000000..e937577
--- /dev/null
+++ b/common_src/lib/liblynq-uci/makefile
@@ -0,0 +1,89 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+ -std=gnu++14 \
+ -g -Os \
+ -flto \
+ -fPIC \
+ -fpermissive \
+
+$(warning ################# C2K support: $(RAT_CONFIG_C2K_SUPPORT))
+ifeq ($(strip $(RAT_CONFIG_C2K_SUPPORT)), yes)
+ LOCAL_CFLAGS += -DC2K_SUPPORT
+
+endif
+
+ifeq ($(strip $(MTK_MULTI_SIM_SUPPORT)), dsds)
+ LOCAL_CFLAGS += -DANDROID_SIM_COUNT_2 \
+ -DANDROID_MULTI_SIM \
+ -DMODE_DSDS
+endif
+
+ifeq ($(strip $(MTK_MULTI_SIM_SUPPORT)), dsss)
+ LOCAL_CFLAGS += -DMODE_DSSS
+endif
+
+$(warning ################# TARGET_PLATFORM: $(TARGET_PLATFORM))
+ifeq ($(strip $(TARGET_PLATFORM)), mt2731)
+#$(warning #################add for debug $(ROOT), $(includedir))
+$(warning ################# TARGET_PLATFORM_MT2731)
+ LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2731 \
+ -DMD_93_SUPPORT
+else ifeq ($(strip $(TARGET_PLATFORM)), mt2635)
+$(warning ################# TARGET_PLATFORM_MT2635)
+ LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2635 \
+ -DMD_90_SUPPORT
+endif
+
+$(warning ################# RITA ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH = .
+
+LOCAL_C_INCLUDES = \
+ -I. \
+ -I$(LOCAL_PATH)/include \
+ -I$(ROOT)$(includedir)/logger \
+
+
+LOCAL_LIBS := \
+ -L. \
+ -ldl \
+ -lpthread \
+ -luci \
+ -llog \
+
+SOURCES = $(wildcard *.c wildcard *.h src/*.c)
+
+EXECUTABLE = liblynq-uci.so
+
+OBJECTS=$(SOURCES:.c=.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 : %.c
+ $(CC) $(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/common_src/lib/liblynq-uci/src/lynq_uci.c b/common_src/lib/liblynq-uci/src/lynq_uci.c
new file mode 100755
index 0000000..2234e71
--- /dev/null
+++ b/common_src/lib/liblynq-uci/src/lynq_uci.c
@@ -0,0 +1,220 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <lynq_uci.h>
+#include <log/log.h>
+
+
+int lynq_del(char *option)
+{
+ int ret;
+ char buf[LYNQ_UCI_MAX_LEN];
+ struct uci_context *ctx = uci_alloc_context();
+ struct uci_ptr ptr;
+
+ sprintf(buf, "%s", option);
+ if(uci_lookup_ptr(ctx, &ptr, buf, true) == UCI_OK)
+ {
+ uci_delete(ctx, &ptr);
+ uci_save(ctx, ptr.p);
+ ret = LYNQ_UCI_SUCCESS;
+ }
+ else
+ ret = LYNQ_UCI_ERROR;
+
+ uci_free_context(ctx);
+ return ret;
+}
+
+static int uci_get_value(struct uci_option *o, char *out_buf)
+{
+ struct uci_element *e;
+ const char *delimiter = " ";
+ int lynq_uci_flag = 0;
+
+ switch(o->type) {
+ case UCI_TYPE_STRING:
+ strcpy(out_buf, o->v.string);
+ break;
+ case UCI_TYPE_LIST:
+ uci_foreach_element(&o->v.list, e)
+ {
+ if(lynq_uci_flag)
+ strcat(out_buf, delimiter);
+
+ strcat(out_buf, e->name);
+ lynq_uci_flag = 1;
+ }
+ break;
+ default:
+ return UCI_ERR_INVAL;
+ break;
+ }
+ return UCI_OK;
+}
+
+int lynq_uci_get(const char *arg, char *out_buf)
+{
+ struct uci_context *ctx;
+ struct uci_element *e;
+ struct uci_ptr ptr;
+
+ int ret = UCI_OK;
+ char *para_name = NULL;
+
+ if(arg == NULL || out_buf == NULL) return UCI_ERR_INVAL;
+
+ para_name = strdup(arg);
+ if(para_name == NULL) return UCI_ERR_INVAL;
+
+ ctx = uci_alloc_context();
+ if (!ctx) {
+ free(para_name);
+ return UCI_ERR_MEM;
+ }
+
+ if (uci_lookup_ptr(ctx, &ptr, para_name, true) != UCI_OK) {
+ uci_free_context(ctx);
+ free(para_name);
+ return UCI_ERR_NOTFOUND;
+ }
+
+ if(UCI_LOOKUP_COMPLETE & ptr.flags)
+ {
+ e = ptr.last;
+ switch(e->type)
+ {
+ case UCI_TYPE_SECTION:
+ ret = UCI_ERR_INVAL;
+ break;
+ case UCI_TYPE_OPTION:
+ ret = uci_get_value(ptr.o, out_buf);
+ break;
+ default:
+ ret = UCI_ERR_NOTFOUND;
+ break;
+ }
+ }
+ else
+ ret = UCI_ERR_NOTFOUND;
+
+ uci_free_context(ctx);
+ free(para_name);
+ return ret;
+}
+
+int lynq_uci_set(const char *arg)
+{
+ struct uci_context *ctx;
+ struct uci_element *e;
+ struct uci_ptr ptr;
+ int ret = UCI_OK;
+ char *name = NULL;
+
+ if(arg == NULL) return UCI_ERR_INVAL;
+
+ name = strdup(arg);
+ if(name == NULL) return UCI_ERR_MEM;
+
+ ctx = uci_alloc_context();
+ if (!ctx) {
+ free(name);
+ return UCI_ERR_MEM;
+ }
+
+ if (uci_lookup_ptr(ctx, &ptr, name, true) != UCI_OK) {
+ uci_free_context(ctx);
+ free(name);
+ return UCI_ERR_NOTFOUND;
+ }
+
+ ret = uci_set(ctx, &ptr);
+ if(ret != UCI_OK)
+ {
+ uci_free_context(ctx);
+ free(name);
+ return ret;
+ }
+
+ ret = uci_save(ctx, ptr.p);
+ if(ret != UCI_OK)
+ {
+ uci_free_context(ctx);
+ free(name);
+ return ret;
+ }
+
+ ret = uci_commit(ctx, &ptr.p, false);
+ if(ret != UCI_OK)
+ {
+ uci_free_context(ctx);
+ free(name);
+ return ret;
+ }
+
+ uci_free_context(ctx);
+ free(name);
+ return ret;
+}
+
+int lynq_add_section(char *section_type, char *section)//rita add @2021.7.30 for adding section
+{
+ char buf[128] = "";
+ sprintf(buf,"lynq_uci.%s=%s", section, section_type);
+ //printf("[%s-%d] buf = %s\n", __FUNCTION__, __LINE__, buf);
+ int ret = lynq_uci_set(buf);
+
+ return ret;
+}
+
+int lynq_set_value(char *section, char *key, char *value)//rita add @2021.7.30 for setting value
+{
+ char buf[LYNQ_UCI_MAX_LEN] = "";
+
+ sprintf(buf,"%s.%s.%s=%s", LYNQ_UCI_FILE, section, key, value);
+ //printf("[%s-%d] buf = %s\n", __FUNCTION__, __LINE__, buf);
+ int ret = lynq_uci_set(buf);
+
+ return ret;
+}
+
+int lynq_get_value(char *file, char *section, char *key, char *tmp)//rita add @2021.7.30 for getting value
+{
+ char buf[LYNQ_UCI_MAX_LEN] = "";
+ int ret = 0;
+
+ if(strcmp(file, LYNQ_UCI_RO_FILE) && strcmp(file, LYNQ_UCI_FILE))
+ {
+ printf("[%s-%d] invalid file %s!!!\n", __FUNCTION__, __LINE__, file);
+ return LYNQ_UCI_ERROR;
+ }
+
+ sprintf(buf,"%s.%s.%s", file, section, key);
+ //printf("[%s-%d] buf = %s\n", __FUNCTION__, __LINE__, buf);
+
+ ret = lynq_uci_get(buf, tmp);
+ return ret;
+}
+
+int lynq_load_config(char *filename)
+{
+ struct uci_context * ctx = NULL;
+ struct uci_element *e;
+ struct uci_package * pkg = NULL;
+ ctx = uci_alloc_context();
+ RLOGD("uci load start \n");
+ if (UCI_OK != uci_load(ctx, filename, &pkg))
+ {
+ RLOGD("uci config fail !!!\n");
+ uci_free_context(ctx);
+ ctx = NULL;
+ return -1;
+ }
+ uci_unload(ctx, pkg);
+ uci_free_context(ctx);
+ RLOGD("uci config success !!!\n");
+ ctx = NULL;
+ return 0;
+}
+
+