Add basic change for v1453
Change-Id: I9497a61bbc3717f66413794a4e7dee0347c0bc33
diff --git a/mbtk/liblynq_lib_rilv2/Makefile b/mbtk/liblynq_lib_rilv2/Makefile
new file mode 100755
index 0000000..7ceee11
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/Makefile
@@ -0,0 +1,51 @@
+BUILD_ROOT = $(shell pwd)/..
+include $(BUILD_ROOT)/Make.defines
+
+LOCAL_PATH=$(BUILD_ROOT)/liblynq_lib_rilv2
+
+INC_DIR += \
+ -I$(LOCAL_PATH)
+
+LIB_DIR +=
+
+LIBS += -lmbtk_lib -lrilutil -lprop2uci -lmtel -laudio-apu -lcutils -ltinyalsa -lacm -llog -ljson-c -lblobmsg_json
+
+CFLAGS += -shared -Wl,-shared,-Bsymbolic
+
+DEFINE +=
+
+MY_FILES_PATH:=$(LOCAL_PATH)
+#ifeq ($(CONFIG_MBTK_QL_SUPPORT),y)
+#MY_FILES_PATH += $(LOCAL_PATH)/ql
+#endif
+
+#ifeq ($(CONFIG_MBTK_PLATFORM),linux)
+#MY_FILES_PATH += $(LOCAL_PATH)/platform/linux
+#endif
+
+MY_FILES_SUFFIX:=%.c %.cpp
+My_All_Files := $(foreach src_path,$(MY_FILES_PATH), $(shell find "$(src_path)" -type f))
+MY_SRC_LIST := $(filter $(MY_FILES_SUFFIX),$(My_All_Files))
+MY_SRC_LIST := $(MY_SRC_LIST:$(LOCAL_PATH)/%=%)
+LOCAL_SRC_FILES += $(MY_SRC_LIST)
+$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
+OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(LOCAL_SRC_FILES)))
+$(info OBJS = $(OBJS))
+
+dtarget := $(OUT_DIR)/lib/liblynq_lib.so
+
+all: $(dtarget)
+
+$(dtarget): $(OBJS)
+ $(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $(OBJS) -o $@
+ cp $@ $(BUILD_ROOT)/rootfs/lib
+
+%.o:%.c
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+%.o:%.cpp
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+clean:
+ rm -f $(OBJS) $(dtarget)
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_adc.c b/mbtk/liblynq_lib_rilv2/lynq_adc.c
new file mode 100755
index 0000000..3c203e7
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_adc.c
@@ -0,0 +1,32 @@
+#include "lynq-adc.h"
+#include "mbtk_type.h"
+#include "mbtk_adc.h"
+#include "mbtk_log.h"
+
+int qser_adc_show(ADC_CHANNEL_E qadc)
+{
+ UNUSED(qadc);
+
+ mbtk_adc_enum adc = MBTK_ADC0;
+ switch(qadc) {
+ case QADC_NONE:
+ {
+ return 0;
+ }
+ case ADC0:
+ adc = MBTK_ADC0;
+ break;
+ case ADC1:
+ adc = MBTK_ADC1;
+ break;
+ case ADC2:
+ adc = MBTK_ADC2;
+ break;
+ default:
+ LOGE("Unsupport adc : %d", qadc);
+ return -1;
+ }
+
+ return mbtk_adc_get(ADC_DEVICE_AUX, adc);
+}
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_alarm.c b/mbtk/liblynq_lib_rilv2/lynq_alarm.c
new file mode 100755
index 0000000..355279b
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_alarm.c
@@ -0,0 +1,107 @@
+#include <math.h>
+#include <stdlib.h>
+
+#include "mbtk_alarm.h"
+#include "lynq_alarm.h"
+#include "mbtk_str.h"
+#include "lynq-qser-autosuspend.h"
+#include "mbtk_utils.h"
+
+
+
+bool rtc_flag = FALSE;
+int lynq_rtc_service_init(void)
+{
+ int ret = 0;
+ if(!rtc_flag)
+ {
+ rtc_flag = TRUE;
+ ret = 1;
+ }
+ else
+ {
+ ret = -1;
+ }
+ return ret;
+}
+
+int lynq_rtc_service_deinit(void)
+{
+ int ret = 0;
+ if(rtc_flag)
+ {
+ rtc_flag = FALSE;
+ ret = 0;
+ }
+ else{
+ ret = -1;
+ }
+
+ return ret;
+}
+
+void mbtk_info_callback_func1(const void* data, int data_len)
+{
+ mbtk_system("echo 456 > /data/test1.txt");
+ return;
+}
+
+
+int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
+{
+ UNUSED(time_sec);
+ if(time_sec < 1 || time_sec > pow(2, 28)) {
+ return -1;
+ }
+
+ if(!rtc_flag)
+ {
+ return -1;
+ }
+
+ qser_suspend_timer_set(time_sec, mbtk_info_callback_func1);
+
+ return 0;
+
+}
+
+//int lynq_set_poweralarm(unsigned long time_sec)
+int lynq_set_poweralarm(unsigned long time_sec,int src_id)
+{
+ UNUSED(time_sec);
+ if(time_sec < 1 || time_sec > pow(2, 28)) {
+ return -1;
+ }
+ char buf[50] ={0};
+ sprintf(buf, "rtcwake -d rtc0 -s %ld -m on &", time_sec);
+ mbtk_system(buf);
+
+ return 0;
+}
+
+// min:1 max:2^28
+ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
+{
+ UNUSED(buffer);
+ if(str_empty(buffer)) {
+ return -1;
+ }
+ return lynq_set_wakealarm(atol(buffer), src_id, rtc_id, wakealarm_notify);
+}
+
+// min:1 max:2^28
+ssize_t poweralarm(char *buffer,int src_id)
+{
+ UNUSED(buffer);
+ if(str_empty(buffer)) {
+ return -1;
+ }
+ return lynq_set_poweralarm(atol(buffer), 0);
+}
+
+ssize_t cancel_wakealarm(int src_id, int rtc_id)
+{
+ return -1;
+}
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_audio.c b/mbtk/liblynq_lib_rilv2/lynq_audio.c
new file mode 100755
index 0000000..259661e
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_audio.c
@@ -0,0 +1,271 @@
+#include "lynq-qser-audio.h"
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "mbtk_audio2.h"
+
+#define AUDIO_DEV_PLAY "device1"
+#define AUDIO_DEV_RECORDER "device2"
+#define AUDIO_HDL_DEFAULT 0
+
+static _cb_onPlayer play_cb = NULL;
+static int play_hdl = -1;
+
+static _cb_onPlayer recv_cb = NULL;
+static int recv_hdl = -1;
+
+int qser_AudPlayer_Open(char* device, _cb_onPlayer cb_fun)
+{
+ UNUSED(device);
+ UNUSED(cb_fun);
+ if(device == NULL || strcmp(device, AUDIO_DEV_PLAY)) {
+ LOGE("device must be %s for play.", AUDIO_DEV_PLAY);
+ return -1;
+ }
+
+ if(mbtk_audio_wav_init()) {
+ LOGE("mbtk_audio_wav_init() fail.");
+ return -1;
+ }
+
+ play_cb = cb_fun;
+
+ return 0;
+}
+
+int qser_AudPlayer_PlayFrmFile(int hdl, const char *fd, int offset)
+{
+ UNUSED(hdl);
+ UNUSED(fd);
+ UNUSED(offset);
+ if(play_hdl >= 0) {
+ LOGE("Play busy.");
+ if(play_cb) {
+ play_cb(-1);
+ }
+ return -1;
+ }
+
+ if(mbtk_audio_wav_play_start(fd)) {
+ LOGE("mbtk_audio_wav_play_start() fail.");
+ if(play_cb) {
+ play_cb(-2);
+ }
+ return -1;
+ }
+
+ play_hdl = hdl;
+
+ if(play_cb) {
+ play_cb(0);
+ }
+
+ return 0;
+}
+
+int qser_AudPlayer_PlayPcmBuf(const unsigned char *pcm_data, int data_size, int period_size,
+ int period_count, int num_channels, int sample_rate, int ownerid)
+{
+
+ if(play_hdl >= 0) {
+ LOGE("Play busy.");
+ if(play_cb) {
+ play_cb(-1);
+ }
+ return -1;
+ }
+
+ if(mbtk_audio_wav_stream_play_start(pcm_data, data_size, sample_rate, num_channels)) {
+ LOGE("mbtk_audio_wav_stream_play_start() fail.");
+ if(play_cb) {
+ play_cb(-2);
+ }
+ return -1;
+ }
+
+ play_hdl = AUDIO_HDL_DEFAULT;
+ if(play_cb) {
+ play_cb(0);
+ }
+ return 0;
+}
+
+int qser_AudPlayer_Pause(int hdl)
+{
+ UNUSED(hdl);
+ if((play_hdl != AUDIO_HDL_DEFAULT && hdl != play_hdl) || play_hdl < 0) {
+ LOGE("Play busy or hdl error.");
+ return -1;
+ }
+
+ if(mbtk_audio_wav_play_pause()) {
+ LOGE("mbtk_audio_wav_play_pause() fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_AudPlayer_Resume(int hdl)
+{
+ UNUSED(hdl);
+ if((play_hdl != AUDIO_HDL_DEFAULT && hdl != play_hdl) || play_hdl < 0) {
+ LOGE("Play busy or hdl error.");
+ return -1;
+ }
+
+ if(mbtk_audio_wav_play_resume()) {
+ LOGE("mbtk_audio_wav_play_resume() fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+void qser_AudPlayer_Stop(int hdl)
+{
+ UNUSED(hdl);
+ if((play_hdl != AUDIO_HDL_DEFAULT && hdl != play_hdl) || play_hdl < 0) {
+ LOGE("Play busy or hdl error.");
+ return;
+ }
+
+ if(mbtk_audio_wav_play_stop()) {
+ LOGE("mbtk_audio_wav_play_stop() fail.");
+ return;
+ }
+
+ play_hdl = -1;
+}
+
+
+void qser_AudPlayer_Close(int hdl)
+{
+ UNUSED(hdl);
+
+ if(play_hdl >= 0) {
+ qser_AudPlayer_Stop(hdl);
+ }
+
+ if(mbtk_audio_wav_deinit()) {
+ LOGE("mbtk_audio_wav_deinit() fail.");
+ return;
+ }
+
+ play_cb = NULL;
+}
+
+int qser_AudRecorder_Open(char* device, _cb_onPlayer cb_fun)
+{
+ UNUSED(device);
+ UNUSED(cb_fun);
+ if(device == NULL || strcmp(device, AUDIO_DEV_RECORDER)) {
+ LOGE("device must be %s for recv.", AUDIO_DEV_RECORDER);
+ return -1;
+ }
+
+ if(mbtk_audio_wav_init()) {
+ LOGE("mbtk_audio_wav_init() fail.");
+ return -1;
+ }
+
+ recv_cb = cb_fun;
+
+ return 0;
+}
+
+int qser_AudRecorder_StartRecord(int hdl, const char *fd, int offset)
+{
+ UNUSED(hdl);
+ UNUSED(fd);
+ UNUSED(offset);
+ if(recv_hdl >= 0) {
+ LOGE("Recv busy.");
+ if(recv_cb) {
+ recv_cb(-1);
+ }
+ return -1;
+ }
+
+ if(mbtk_audio_wav_recorder_start(fd, MBTK_AUDIO_SAMPLE_RATE_8000)) {
+ LOGE("mbtk_audio_wav_recorder_start() fail.");
+ if(recv_cb) {
+ recv_cb(-2);
+ }
+ return -1;
+ }
+
+ recv_hdl = hdl;
+ if(recv_cb) {
+ recv_cb(0);
+ }
+ return 0;
+}
+
+int qser_AudRecorder_StartRecord_Custom(char *file, int period_size, int period_count,
+ int num_channels, int sample_rate)
+{
+ return qser_AudRecorder_StartRecord(0, file, 0);
+}
+
+int qser_AudRecorder_Pause(void)
+{
+ if(recv_hdl < 0) {
+ LOGE("Recv busy or hdl error.");
+ return -1;
+ }
+
+ if(mbtk_audio_wav_recorder_pause()) {
+ LOGE("mbtk_audio_wav_recorder_pause() fail.");
+ return -1;
+ }
+ return 0;
+}
+
+int qser_AudRecorder_Resume(void)
+{
+ if(recv_hdl < 0) {
+ LOGE("Recv busy or hdl error.");
+ return -1;
+ }
+
+ if(mbtk_audio_wav_recorder_resume()) {
+ LOGE("mbtk_audio_wav_recorder_resume() fail.");
+ return -1;
+ }
+ return 0;
+}
+
+void qser_AudRecorder_Stop(void)
+{
+ if(recv_hdl < 0) {
+ LOGE("Recv busy or hdl error.");
+ return;
+ }
+
+ if(mbtk_audio_wav_recorder_stop()) {
+ LOGE("mbtk_audio_wav_recorder_stop() fail.");
+ return;
+ }
+
+ recv_hdl = -1;
+}
+
+void qser_AudRecorder_Close(void)
+{
+ if(recv_hdl >= 0) {
+ qser_AudRecorder_Stop();
+ }
+
+ if(mbtk_audio_wav_deinit()) {
+ LOGE("mbtk_audio_wav_deinit() fail.");
+ return;
+ }
+
+ recv_cb = NULL;
+}
+
+void qser_Audio_Deinit(void)
+{
+ // Do nothing...
+}
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_chip_id.c b/mbtk/liblynq_lib_rilv2/lynq_chip_id.c
new file mode 100755
index 0000000..34e60c1
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_chip_id.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <time.h>
+#include "mbtk_ril_api.h"
+static mbtk_ril_handle* info_handle = NULL;
+
+int lynq_get_time_sec(char *time_t)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ sprintf(time_t, "%lld", tv.tv_sec);
+ return 0;
+}
+
+int lynq_imet_get(char *imei_t)
+{
+ info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ int err;
+ err = mbtk_imei_get(info_handle, imei_t);
+ if(err) {
+ // printf("Error : %d\n", err);
+ return -1;
+ } else {
+ // printf("IMEI : %s\n", imei_t);
+ }
+ return 0;
+}
+
+
+int lynq_get_chip_id(char *chip_id)
+{
+ char time[50]={0};
+ char imei[50]={0};
+ int ret = 0;
+
+ lynq_get_time_sec(time);
+ ret = lynq_imet_get(imei);
+
+ if(info_handle != NULL)
+ {
+ int ret_ril = mbtk_ril_close(MBTK_AT_PORT_DEF);
+ if (ret_ril == MBTK_RIL_ERR_SUCCESS)
+ LOGI("deinit info_handle is succuess");
+ else
+ LOGE("deinit info_handle is error(%d)",ret_ril);
+ }
+
+ if(!ret)
+ {
+ sprintf(chip_id,"%s%s",imei, time);
+// printf("%s\n",chip_id );
+ }
+ else{
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_data_call.c b/mbtk/liblynq_lib_rilv2/lynq_data_call.c
new file mode 100755
index 0000000..94bf008
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_data_call.c
@@ -0,0 +1,892 @@
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @file lynq_data_call.c
+ @brief data call service API
+*/
+/*-----------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
+ mobiletek Wireless Solution Proprietary and Confidential.
+-------------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ EDIT HISTORY
+ This section contains comments describing changes made to the file.
+ Notice that changes are listed in reverse chronological order.
+ $Header: $
+ when who what, where, why
+ -------- --------- -----------------------------------------------------------------
+ 20241202 yq.wang Created.
+-------------------------------------------------------------------------------------------------*/
+
+#include <pthread.h>
+#include <cutils/properties.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+//#include <sys/scoket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "lynq_qser_data.h"
+#include "mbtk_type.h"
+#include "mbtk_ril_api.h"
+
+/*define*/
+#define QSER_DATA_CALL_FUNC __func__
+
+#define QSER_LOGE LOGE
+#define QSER_LOGD LOGD
+
+#define QSER_DEFAULT_APN_TYPE "iot_default"
+
+/*define*/
+
+/*enum*/
+typedef enum {
+ QSER_RESULT_SUCCESS = 0,
+ QSER_RESULT_FAIL,
+ QSER_RESULT_SERVER_NO_INIT,
+ QSER_RESULT_INVALID_PARAMS,
+}qser_result_e;
+
+/*enum*/
+
+/*struct*/
+typedef struct {
+ mbtk_ril_handle* handle;
+ qser_data_call_evt_cb_t net_status_cb;
+}qser_data_call_handle_s;
+
+/*struct*/
+
+/*----------------------------------------------DATA CALL FUNCTION-------------------------------------*/
+static qser_data_call_handle_s* qser_data_call_handle_get(void)
+{
+ static qser_data_call_handle_s data_call_handle = {0};
+
+ return &data_call_handle;
+}
+
+static int qser_apn_convert_to_qser_s(qser_apn_info_s *qser_apn, mbtk_apn_info_t *mbtk_apn)
+{
+ if(qser_apn == NULL || mbtk_apn == NULL)
+ {
+ QSER_LOGE("[%s] apn param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ int length = 0;
+ memset(qser_apn, 0x0, sizeof(qser_apn_info_s));
+ qser_apn->profile_idx = (unsigned char)(mbtk_apn->cid - 1);
+ //get ip type
+ if(mbtk_apn->ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6
+ {
+ qser_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4V6;
+ }
+ else if(mbtk_apn->ip_type == MBTK_IP_TYPE_IP) // IPV4
+ {
+ qser_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4;
+ }
+ else if(mbtk_apn->ip_type == MBTK_IP_TYPE_IPV6) // IPV6
+ {
+ qser_apn->pdp_type = QSER_APN_PDP_TYPE_IPV6;
+ }
+ else
+ {
+ qser_apn->pdp_type = QSER_APN_PDP_TYPE_PPP;
+ }
+
+ //get apn proto
+ qser_apn->auth_proto = (qser_apn_auth_proto_e)mbtk_apn->auth;
+
+ //get apn name
+ length = strlen((char *)mbtk_apn->apn);
+ if( length <= 0 || length > QSER_APN_NAME_SIZE)
+ {
+ QSER_LOGE("[%s] apn_nmea length fault.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ memcpy(qser_apn->apn_name, mbtk_apn->apn, length);
+ }
+
+ //get apn user
+ length = strlen((char *)mbtk_apn->user);
+ if(length < 0 || length > QSER_APN_USERNAME_SIZE)
+ {
+ QSER_LOGE("[%s] user length fault.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ memcpy(qser_apn->username, mbtk_apn->user, length);
+ }
+
+ //get apn password
+ length = strlen((char *)mbtk_apn->pass);
+ if(length < 0 || length > QSER_APN_PASSWORD_SIZE)
+ {
+ QSER_LOGE("[%s] pass length fault.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ memcpy(qser_apn->password, mbtk_apn->pass, length);
+ }
+
+ //get apn type
+ length = strlen((char *)mbtk_apn->type);
+ if(length < 0 || length > QSER_APN_TYPE_SIZE)
+ {
+ QSER_LOGE("[%s] type length fault.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ memcpy(qser_apn->apn_type, mbtk_apn->type, length);
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+static int qser_apn_convert_to_mbtk_s(mbtk_ril_cid_enum cid, mbtk_apn_info_t *mbtk_apn, qser_apn_info_s *qser_apn)
+{
+ if(mbtk_apn == NULL || qser_apn == NULL)
+ {
+ QSER_LOGE("[%s] apn param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ if(strlen(qser_apn->apn_name) > QSER_APN_NAME_SIZE || strlen(qser_apn->username) > QSER_APN_USERNAME_SIZE
+ || strlen(qser_apn->password) > QSER_APN_PASSWORD_SIZE || strlen(qser_apn->apn_type) > QSER_APN_TYPE_SIZE)
+ {
+ QSER_LOGE("[%s] apn length out of range.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_INVALID_PARAMS;
+ }
+
+ memset(mbtk_apn, 0x0, sizeof(mbtk_apn_info_t));
+ mbtk_apn->cid = cid;
+
+ if(qser_apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
+ {
+ mbtk_apn->ip_type = MBTK_IP_TYPE_IP;
+ }
+ else if(qser_apn->pdp_type == QSER_APN_PDP_TYPE_IPV6)
+ {
+ mbtk_apn->ip_type = MBTK_IP_TYPE_IPV6;
+ }
+ else if(qser_apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6)
+ {
+ mbtk_apn->ip_type = MBTK_IP_TYPE_IPV4V6;
+ }
+ else if(qser_apn->pdp_type == QSER_APN_PDP_TYPE_PPP)
+ {
+ mbtk_apn->ip_type = MBTK_IP_TYPE_PPP;
+ }
+ else
+ {
+ QSER_LOGE("[%s] pdp_type error.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ //no support PAP_CHAP
+ if(qser_apn->auth_proto >= QSER_APN_AUTH_PROTO_DEFAULT && qser_apn->auth_proto < QSER_APN_AUTH_PROTO_PAP_CHAP)
+ {
+ mbtk_apn->auth = (mbtk_apn_auth_type_enum)qser_apn->auth_proto;
+ }
+ else
+ {
+ QSER_LOGE("[%s] auth_proto error.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_apn->auto_save = true;
+ mbtk_apn->auto_boot_call = false;
+
+ if(strlen(qser_apn->apn_type))
+ {
+ if(memcmp(qser_apn->apn_type, QSER_DEFAULT_APN_TYPE, strlen(QSER_DEFAULT_APN_TYPE)) == 0)
+ {
+ mbtk_apn->def_route = true;
+ mbtk_apn->as_dns = true;
+ }
+ memcpy(mbtk_apn->type, qser_apn->apn_type, strlen(qser_apn->apn_type));
+ }
+ else
+ {
+ mbtk_apn->def_route = false;
+ mbtk_apn->as_dns = false;
+ }
+
+ if(strlen(qser_apn->apn_name))
+ {
+ memcpy(mbtk_apn->apn, qser_apn->apn_name, strlen(qser_apn->apn_name));
+ }
+ else
+ {
+ QSER_LOGE("[%s] apn is empty.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ if(strlen(qser_apn->username))
+ {
+ memcpy(mbtk_apn->user, qser_apn->username, strlen(qser_apn->username));
+ }
+ if(strlen(qser_apn->password))
+ {
+ memcpy(mbtk_apn->pass, qser_apn->password, strlen(qser_apn->password));
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+static void qser_netcard_state_init(qser_data_call_state_s *state)
+{
+ if(state != NULL)
+ {
+ state->profile_idx = 0;
+ memset(state->name, 0x0, 16);
+ state->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
+ state->state = QSER_DATA_CALL_DISCONNECTED;
+ state->err = QSER_DATA_CALL_ERROR_NONE;
+ inet_aton("0.0.0.0", &(state->v4.ip));
+ inet_aton("0.0.0.0", &(state->v4.gateway));
+ inet_aton("0.0.0.0", &(state->v4.pri_dns));
+ inet_aton("0.0.0.0", &(state->v4.sec_dns));
+ inet_pton(AF_INET6, "::", &(state->v6.ip));
+ inet_pton(AF_INET6, "::", &(state->v6.gateway));
+ inet_pton(AF_INET6, "::", &(state->v6.pri_dns));
+ inet_pton(AF_INET6, "::", &(state->v6.sec_dns));
+ }
+}
+
+static void qser_pdp_state_change_cb(const void* data, int data_len)
+{
+ if(data == NULL || data_len != sizeof(mbtk_ril_pdp_state_info_t))
+ {
+ QSER_LOGE("[%s] cb data fault.", QSER_DATA_CALL_FUNC);
+ return;
+ }
+
+ mbtk_ril_pdp_state_info_t pdp_data;
+ qser_data_call_state_s state = {0};
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle)
+ {
+ QSER_LOGE("[%s] qser_data_call_handle_get() fail.", QSER_DATA_CALL_FUNC);
+ return;
+ }
+
+
+ memset(&pdp_data, 0x0, sizeof(mbtk_ril_pdp_state_info_t));
+ memcpy(&pdp_data, data, sizeof(mbtk_ril_pdp_state_info_t));
+ QSER_LOGD("[%s] cid - %d, act - %d, auto_change - %d, reason - %d", QSER_DATA_CALL_FUNC, pdp_data.cid, pdp_data.action,
+ pdp_data.auto_change, pdp_data.reason);
+
+ qser_netcard_state_init(&state);
+ state.profile_idx = (char)(pdp_data.cid - 1);
+ snprintf(state.name, 16, "ccinet%d", state.profile_idx);
+ if(pdp_data.action)
+ {
+ state.state = QSER_DATA_CALL_CONNECTED;
+ }
+ else
+ {
+ state.state = QSER_DATA_CALL_DISCONNECTED;
+ }
+
+ if(pdp_data.ip_info_valid)
+ {
+ if(pdp_data.ip_info.ipv4.valid)
+ {
+ state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
+ state.v4.ip.s_addr = pdp_data.ip_info.ipv4.IPAddr;
+ state.v4.pri_dns.s_addr = pdp_data.ip_info.ipv4.PrimaryDNS;
+ state.v4.sec_dns.s_addr = pdp_data.ip_info.ipv4.SecondaryDNS;
+ }
+
+ if(pdp_data.ip_info.ipv6.valid)
+ {
+ state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
+ memcpy(&(state.v6.ip), &(pdp_data.ip_info.ipv6.IPV6Addr), sizeof(pdp_data.ip_info.ipv6.IPV6Addr));
+ memcpy(&(state.v6.pri_dns), &(pdp_data.ip_info.ipv6.PrimaryDNS), sizeof(pdp_data.ip_info.ipv6.PrimaryDNS));
+ memcpy(&(state.v6.sec_dns), &(pdp_data.ip_info.ipv6.SecondaryDNS), sizeof(pdp_data.ip_info.ipv6.SecondaryDNS));
+ }
+
+ if(pdp_data.ip_info.ipv4.valid && pdp_data.ip_info.ipv6.valid)
+ {
+ state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
+ }
+ }
+
+ if(data_call_handle->net_status_cb)
+ {
+ data_call_handle->net_status_cb(&state);
+ }
+}
+
+static void* qser_data_call_async_thread(void* arg)
+{
+ QSER_LOGD("[%s] entry func.", QSER_DATA_CALL_FUNC);
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ qser_data_call_error_e err = QSER_DATA_CALL_ERROR_NONE;
+
+ qser_data_call_state_s state = {0};
+ qser_data_call_s qser_data_backup = {0};
+ qser_data_call_info_s info = {0};
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ qser_netcard_state_init(&state);
+ if(arg != NULL)
+ {
+ memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s));
+ }
+ else
+ {
+ QSER_LOGD("[%s] arg is NULL.", QSER_DATA_CALL_FUNC);
+ state.err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ if(data_call_handle->net_status_cb)
+ {
+ data_call_handle->net_status_cb(&state);
+ }
+ return NULL;
+ }
+
+ state.profile_idx = qser_data_backup.profile_idx;
+ snprintf(state.name, 16, "ccinet%d", qser_data_backup.profile_idx);
+ state.ip_family = qser_data_backup.ip_family;
+
+ ret = qser_data_call_start(&qser_data_backup, &err);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] qser_data_call_start() fail.", QSER_DATA_CALL_FUNC);
+ state.err = err;
+ }
+ else
+ {
+ state.state = QSER_DATA_CALL_CONNECTED;
+ ret = qser_data_call_info_get(qser_data_backup.profile_idx, qser_data_backup.ip_family, &info, &err);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] qser_data_call_info_get() fail.", QSER_DATA_CALL_FUNC);
+ state.err = err;
+ }
+ else
+ {
+ memcpy(&(state.v4), &(info.v4.addr), sizeof(struct v4_address_status));
+ memcpy(&(state.v6), &(info.v6.addr), sizeof(struct v6_address_status));
+ }
+ }
+
+ if(data_call_handle->net_status_cb)
+ {
+ data_call_handle->net_status_cb(&state);
+ }
+ return NULL;
+}
+
+/*----------------------------------------------DATA CALL FUNCTION-------------------------------------*/
+
+/*----------------------------------------------DATA CALL API------------------------------------------*/
+int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
+{
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle)
+ {
+ QSER_LOGE("[%s] qser_data_call_handle_get() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ if(NULL == data_call_handle->handle)
+ {
+ data_call_handle->handle = mbtk_ril_open(MBTK_AT_PORT_DATA);
+ if(NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] mbtk_ril_open() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_pdp_state_change_cb_reg(qser_pdp_state_change_cb);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_pdp_state_change_cb_reg() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ goto error_1;
+ }
+
+ data_call_handle->net_status_cb = evt_cb;
+ }
+
+ QSER_LOGD("[%s] data call init success.", QSER_DATA_CALL_FUNC);
+
+ return QSER_RESULT_SUCCESS;
+error_1:
+ if(data_call_handle->handle)
+ {
+ ret = mbtk_ril_close(MBTK_AT_PORT_DATA);
+ data_call_handle->handle = NULL;
+ }
+
+ return QSER_RESULT_FAIL;
+}
+
+void qser_data_call_destroy(void)
+{
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return;
+ }
+
+ data_call_handle->net_status_cb = NULL;
+
+ ret = mbtk_ril_close(MBTK_AT_PORT_DATA);
+ if(ret != MBTK_RIL_ERR_SUCCESS && ret != MBTK_RIL_ERR_PORT_NOT_CLOSE)
+ {
+ QSER_LOGE("[%s] mbtk_ril_close() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ return;
+ }
+ data_call_handle->handle = NULL;
+}
+
+int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
+{
+ if(data_call == NULL || err == NULL)
+ {
+ QSER_LOGE("[%s] data_call or err is NULL.", QSER_DATA_CALL_FUNC);
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ int retry_interval[] = {5, 10};
+ mbtk_ip_info_t ip_info;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ memset(&ip_info, 0x0, sizeof(mbtk_ip_info_t));
+ ret = mbtk_data_call_start(data_call_handle->handle, (mbtk_ril_cid_enum)(data_call->profile_idx + 1),
+ MBTK_DATA_CALL_ITEM_STATE_NON, MBTK_DATA_CALL_ITEM_STATE_NON, MBTK_DATA_CALL_ITEM_STATE_NON,
+ retry_interval, 2, 0, &ip_info);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_data_call_start() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ *err = QSER_DATA_CALL_ERROR_NONE;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
+{
+ if(data_call == NULL || err == NULL)
+ {
+ QSER_LOGE("[%s] data_call or err is NULL.", QSER_DATA_CALL_FUNC);
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ pthread_attr_t thread_attr;
+ pthread_t data_call_thread_id;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ pthread_attr_init(&thread_attr);
+ if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+ {
+ QSER_LOGE("[%s] pthread_attr_setdetachstate() fail.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pthread_create(&data_call_thread_id, &thread_attr, qser_data_call_async_thread, (void *) data_call))
+ {
+ QSER_LOGE("[%s] pthread_create() fail.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+ pthread_attr_destroy(&thread_attr);
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
+{
+ UNUSED(ip_family);
+
+ if(err == NULL)
+ {
+ QSER_LOGE("[%s] err is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ ret = mbtk_data_call_stop(data_call_handle->handle, (mbtk_ril_cid_enum)(profile_idx + 1), 15);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_data_call_stop() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ *err = QSER_DATA_CALL_ERROR_NONE;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family,
+ qser_data_call_info_s *info, qser_data_call_error_e *err)
+{
+ UNUSED(ip_family);
+
+ if(info == NULL || err == NULL)
+ {
+ QSER_LOGE("[%s] info or err is NULL.", QSER_DATA_CALL_FUNC);
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_ip_info_t ip_info;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+#ifdef QSER_TEST
+ char v4_buff[32] = {0};
+ char v6_buff[128] = {0};
+#endif
+ memset(&ip_info, 0x0, sizeof(mbtk_ip_info_t));
+ memset(info, 0x0, sizeof(qser_data_call_info_s));
+ ret = mbtk_data_call_state_get(data_call_handle->handle, (mbtk_ril_cid_enum)(profile_idx + 1), &ip_info);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_data_call_state_get fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ info->profile_idx = profile_idx;
+ if(ip_info.ipv4.valid)
+ {
+ info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
+ info->v4.state = QSER_DATA_CALL_CONNECTED;
+ sprintf(info->v4.name, "ccinet%d", profile_idx);
+ info->v4.addr.ip.s_addr = ip_info.ipv4.IPAddr;
+ info->v4.addr.pri_dns.s_addr = ip_info.ipv4.PrimaryDNS;
+ info->v4.addr.sec_dns.s_addr = ip_info.ipv4.SecondaryDNS;
+ info->v4.reconnect = true;
+
+#ifdef QSER_TEST
+ //LOGE("[qser_data] IP: %x pri_DNS: %x sec_DNS: %x.", ipv4.IPAddr, ipv4.PrimaryDNS, ipv4.SecondaryDNS);
+ if(inet_ntop(AF_INET, &(info->v4.addr.ip), v4_buff, 32) == NULL) {
+ LOGE("[qser_data] IP error.");
+ } else {
+ LOGE("[qser_data] IP : %s", v4_buff);
+ }
+ if(inet_ntop(AF_INET, &(info->v4.addr.pri_dns), v4_buff, 32) == NULL) {
+ LOGE("[qser_data] PrimaryDNS error.");
+ } else {
+ LOGE("[qser_data] PrimaryDNS : %s", v4_buff);
+ }
+ if(inet_ntop(AF_INET, &(info->v4.addr.sec_dns), v4_buff, 32) == NULL) {
+ LOGE("[qser_data] SecondaryDNS error.");
+ } else {
+ LOGE("[qser_data] SecondaryDNS : %s", v4_buff);
+ }
+#endif
+ }
+
+ if(ip_info.ipv6.valid)
+ {
+ info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
+ info->v6.state = QSER_DATA_CALL_CONNECTED;
+ sprintf(info->v6.name, "ccinet%d", profile_idx);
+ memcpy(&(info->v6.addr.ip), &(ip_info.ipv6.IPV6Addr), sizeof(ip_info.ipv6.IPV6Addr));
+ memcpy(&(info->v6.addr.pri_dns), &(ip_info.ipv6.PrimaryDNS), sizeof(ip_info.ipv6.PrimaryDNS));
+ memcpy(&(info->v6.addr.sec_dns), &(ip_info.ipv6.SecondaryDNS), sizeof(ip_info.ipv6.SecondaryDNS));
+ info->v6.reconnect = true;
+
+#ifdef QSER_TEST
+ if(ipv6_2_str(&(info->v6.addr.ip), v6_buff))
+ {
+ LOGE("[qser_data] IP error.");
+ } else {
+ LOGE("[qser_data] IP : %s", v6_buff);
+ }
+ if(ipv6_2_str(&(info->v6.addr.pri_dns), v6_buff))
+ {
+ LOGE("[qser_data] PrimaryDNS error.");
+ } else {
+ LOGE("[qser_data] PrimaryDNS : %s", v6_buff);
+ }
+ if(ipv6_2_str(&(info->v6.addr.sec_dns), v6_buff))
+ {
+ LOGE("[qser_data] SecondaryDNS error.");
+ } else {
+ LOGE("[qser_data] SecondaryDNS : %s", v6_buff);
+ }
+#endif
+ }
+
+ if(ip_info.ipv4.valid && ip_info.ipv6.valid)
+ {
+ info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
+ }
+ }
+
+ *err = QSER_DATA_CALL_ERROR_NONE;
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_set(qser_apn_info_s *apn)
+{
+ if(apn == NULL)
+ {
+ QSER_LOGE("[%s] apn param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_apn_info_t apninfo;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ if(qser_apn_convert_to_mbtk_s((mbtk_ril_cid_enum)(apn->profile_idx + 1), &apninfo, apn) != QSER_RESULT_SUCCESS)
+ {
+ QSER_LOGE("[%s] qser_apn_convert_to_mbtk_s() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_apn_set(data_call_handle->handle, &apninfo);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_apn_set() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
+{
+ if(apn == NULL)
+ {
+ QSER_LOGE("[%s] apn param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ int i = 0;
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_apn_info_array_t apninfo;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ memset(&apninfo, 0x0, sizeof(mbtk_apn_info_array_t));
+ ret = mbtk_apn_get(data_call_handle->handle, &apninfo);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_apn_get() fail. [%d]", QSER_DATA_CALL_FUNC, ret);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ for(i = 0; i < apninfo.num; i++)
+ {
+ if(apninfo.apns[i].cid == (mbtk_ril_cid_enum)(profile_idx + 1))
+ {
+ QSER_LOGD("[%s] find idx[%d].", QSER_DATA_CALL_FUNC, profile_idx);
+ break;
+ }
+ }
+
+ if(i == apninfo.num)
+ {
+ QSER_LOGE("[%s] not find idx, max num[%d].", QSER_DATA_CALL_FUNC, apninfo.num);
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_apn_convert_to_qser_s(apn, &(apninfo.apns[i])) != QSER_RESULT_SUCCESS)
+ {
+ QSER_LOGE("[%s] qser_apn_convert_to_qser_s() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
+{
+ if(apn == NULL || profile_idx == NULL)
+ {
+ QSER_LOGE("[%s] apn param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_apn_info_t apninfo;
+ qser_apn_info_s qser_info;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ memset(&qser_info, 0x0, sizeof(qser_apn_info_s));
+ qser_info.profile_idx = MBTK_RIL_CID_NUL;
+ qser_info.pdp_type = apn->pdp_type;
+ qser_info.auth_proto = apn->auth_proto;
+ memcpy(qser_info.apn_name, apn->apn_name, QSER_APN_NAME_SIZE);
+ memcpy(qser_info.username, apn->username, QSER_APN_USERNAME_SIZE);
+ memcpy(qser_info.password, apn->password, QSER_APN_PASSWORD_SIZE);
+ memcpy(qser_info.apn_type, apn->apn_type, QSER_APN_TYPE_SIZE);
+ if(qser_apn_convert_to_mbtk_s(MBTK_RIL_CID_NUL, &apninfo, &qser_info) != QSER_RESULT_SUCCESS)
+ {
+ QSER_LOGE("[%s] apn_convert_to_mbtk_s() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_apn_set(data_call_handle->handle, &apninfo);
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_apn_set() fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ return QSER_RESULT_FAIL;
+ }
+
+ *profile_idx = (unsigned char)(apninfo.cid - 1);
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_del(unsigned char profile_idx)
+{
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_apn_info_t apninfo;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ memset(&apninfo, 0x0, sizeof(mbtk_apn_info_t));
+ apninfo.cid = (mbtk_ril_cid_enum)(profile_idx + 1);
+ apninfo.auto_save = true;
+ ret = mbtk_apn_set(data_call_handle->handle, &(apninfo));
+ if(ret != MBTK_RIL_ERR_SUCCESS)
+ {
+ QSER_LOGE("[%s] mbtk_apn_set fail.[%d]", QSER_DATA_CALL_FUNC, ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_get_list(qser_apn_info_list_s *apn_list)
+{
+ if(apn_list == NULL)
+ {
+ QSER_LOGE("[%s] apn_list param is NULL.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+
+ int i = 0;
+ mbtk_ril_err_enum ret = MBTK_RIL_ERR_SUCCESS;
+ mbtk_apn_info_array_t apninfo;
+ qser_data_call_handle_s* data_call_handle = qser_data_call_handle_get();
+ if(NULL == data_call_handle || NULL == data_call_handle->handle)
+ {
+ QSER_LOGE("[%s] server not init.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_SERVER_NO_INIT;
+ }
+
+ memset(&apninfo, 0x0, sizeof(mbtk_apn_info_array_t));
+ ret = mbtk_apn_get(data_call_handle->handle, &apninfo);
+ if(ret != MBTK_RIL_ERR_SUCCESS && ret != MBTK_RIL_ERR_CME)
+ {
+ QSER_LOGE("[%s] mbtk_apn_get() fail. [%d]", QSER_DATA_CALL_FUNC, ret);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(apninfo.num > 0 && apninfo.num <= QSER_APN_MAX_LIST)
+ {
+ apn_list->cnt = 0;
+ for(i = 0; i < apninfo.num; i++)
+ {
+ if(qser_apn_convert_to_qser_s(&apn_list->apn[apn_list->cnt], &(apninfo.apns[i])) != QSER_RESULT_SUCCESS)
+ {
+ QSER_LOGE("[%s] qser_apn_convert_to_qser_s() fail.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ apn_list->cnt++;
+ }
+ }
+ else if(apninfo.num > QSER_APN_MAX_LIST)
+ {
+ QSER_LOGE("[%s] apn_num overlong.", QSER_DATA_CALL_FUNC);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ apn_list->cnt = 0;
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+/*----------------------------------------------DATA CALL API------------------------------------------*/
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_fota.c b/mbtk/liblynq_lib_rilv2/lynq_fota.c
new file mode 100755
index 0000000..9b12656
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_fota.c
@@ -0,0 +1,113 @@
+#include "lynq-qser-fota.h"
+#include "mbtk_type.h"
+#include "mbtk_fota.h"
+#include "mbtk_log.h"
+
+
+char addr_buf[128]={0};
+int segment_size =0;
+
+
+int Process_flag = 0;
+
+
+int fota_cb(int status, int percent)
+{
+ LOGE("%d: percent: %d%%\n", percent/10, percent);
+ Process_flag = percent/10;
+ return 0;
+}
+
+int lynq_read_process(void)
+{
+ return Process_flag;
+}
+
+int lynq_rock_main(int first_run)
+{
+ UNUSED(first_run);
+ LOGE("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ LOGE("addr_buf:%s, segment_size:%d\n", addr_buf, segment_size);
+ ret = mbtk_fota_init(fota_cb);
+ if(strncmp(addr_buf, "http", 4) == 0)
+ {
+
+ ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
+ }
+ else
+ {
+ ret =mbtk_fota_fw_write(addr_buf, segment_size);
+ }
+
+ if(ret)
+ {
+ LOGE("lynq_rock_main fail\n");
+ return -1;
+ }
+
+ mbtk_fota_done1(1);
+
+
+ return 0;
+}
+
+int lynq_fota_set_addr_value(char *value,int size)
+{
+ UNUSED(value);
+ UNUSED(size);
+ LOGE("%s, %d", __FUNCTION__, __LINE__);
+
+ if(value == NULL)
+ {
+ return -1;
+ }
+
+ memset(addr_buf, 0, sizeof(addr_buf));
+ memcpy(addr_buf, value, strlen(value));
+ segment_size = size;
+
+ LOGE("addr_buf:%s, value:%s\n", addr_buf, value);
+ LOGE("segment_size:%d, size:%d\n", segment_size, size);
+
+ return 0;
+}
+
+int lynq_fota_nrestart(void)
+{
+ LOGE("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ LOGE("addr_buf:%s", addr_buf);
+ ret = mbtk_fota_init(fota_cb);
+ if(strncmp(addr_buf, "http", 4) == 0)
+ {
+ ret = mbtk_fota_fw_write_by_url(addr_buf, segment_size,10, 600);
+ }
+ else
+ {
+ ret =mbtk_fota_fw_write(addr_buf, segment_size);
+ }
+
+ if(ret)
+ {
+ LOGE("lynq_fota_nrestart fail\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int lynq_get_upgrade_status(void)
+{
+ LOGE("%s, %d", __FUNCTION__, __LINE__);
+
+ return mbtk_fota_status();
+}
+
+int lynq_get_reboot_upgrade_status(void)
+{
+ return mbtk_fota_get_asr_reboot_cnt_flag();
+}
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_gnss.c b/mbtk/liblynq_lib_rilv2/lynq_gnss.c
new file mode 100755
index 0000000..37b3074
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_gnss.c
@@ -0,0 +1,519 @@
+#include <time.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "lynq_gnss.h"
+
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+#define QSER_GNSS_TIMEOUT 5
+#define QSER_AGNSS_DOWNLOAD_TIMEPUT 60
+#define QSER_AGNSS_INJECT_TIMEOUT 20
+
+/**********************************VARIABLE***********************************/
+static bool inited = FALSE;
+static uint32_t qser_h_gnss = 0x5F6F7F8F;
+gnss_handler_func_t qser_gnss_callback = NULL;
+static time_t qser_gnss_time = 0;
+qser_agps_info qser_agps_info_save = {0};
+gnss_async_func_t qser_gnss_async_callback = NULL;
+
+extern long timezone;
+/**********************************VARIABLE***********************************/
+
+/**********************************FUNC***********************************/
+static void qser_gnss_async_set_cb(gnss_async_func_t cb)
+{
+ qser_gnss_async_callback = cb;
+}
+
+static gnss_async_func_t qser_gnss_async_get_cb(void)
+{
+ return qser_gnss_async_callback;
+}
+
+
+static time_t qser_get_timestamp(char *time)
+{
+ char tmp_char[4] = {0};
+ struct tm* tmp_time = (struct tm*)malloc(sizeof(struct tm));
+
+ memset(tmp_time, 0, sizeof(struct tm));
+ memset(tmp_char, 0, sizeof(tmp_char));
+ memcpy(tmp_char, &time[4], 2);
+ tmp_time->tm_sec = atoi(tmp_char);
+ memcpy(tmp_char, &time[2], 2);
+ tmp_time->tm_min = atoi(tmp_char);
+ memcpy(tmp_char, &time[0], 2);
+ tmp_time->tm_hour = atoi(tmp_char);
+ memcpy(tmp_char, &time[6], 2);
+ tmp_time->tm_mday = atoi(tmp_char);
+ memcpy(tmp_char, &time[8], 2);
+ tmp_time->tm_mon = atoi(tmp_char) - 1;
+ memcpy(tmp_char, &time[10], 2);
+ tmp_time->tm_year = 100 + atoi(tmp_char);
+
+ time_t _t = mktime(tmp_time);//按当地时区解析tmp_time
+ //gnss_log("timestamp: %ld\n",_t);
+ tzset(); // 自动设置本地时区
+ _t = _t - timezone;
+ //gnss_log("timestamp: %ld\n",_t);
+
+ free(tmp_time);
+ return _t;
+}
+
+static time_t qser_get_gnss_time_sec(const void *data, int data_len)
+{
+ int i = 0, num = 0;
+ const char *nmea = (const char *)data;
+ char time[15] = {0};
+ char *check_state = NULL;
+
+ //$GNRMC,024142.000,A,3039.364421,N,10403.417935,E,0.051,0.00,030124,,E,A*00
+ check_state = strstr(nmea, "RMC");
+ if(check_state != NULL)
+ {
+ for(i = 0; i < data_len; i++)
+ {
+ if(check_state[i] == ',')
+ {
+ num++;
+ i++;
+ if(num == 1)//get time
+ {
+ if(check_state[i] >= '0' && check_state[i] <= '9')
+ {
+ memcpy(time, check_state + i, 6);
+ //LOGE("[qser_gnss] %s.", time);
+ }
+ else
+ {
+ qser_gnss_time = 0;
+ return qser_gnss_time;
+ }
+ }
+ else if(num == 9)//get date
+ {
+ if(check_state[i] >= '0' && check_state[i] <= '9')
+ {
+ memcpy(time + 6, check_state + i, 6);
+ //LOGE("[qser_gnss] %s.", time);
+ break;
+ }
+ else
+ {
+ qser_gnss_time = 0;
+ return qser_gnss_time;
+ }
+ }
+ else if(num > 9)
+ {
+ qser_gnss_time = 0;
+ return qser_gnss_time;
+ }
+ }
+ }
+
+ qser_gnss_time = qser_get_timestamp(time);
+ }
+
+ return qser_gnss_time;
+}
+
+static void* gnss_async_thread(void* arg)
+{
+ qser_gnss_error_e state = QSER_GNSS_ERROR_SUCCESS;
+ gnss_async_func_t cb = qser_gnss_async_get_cb();
+ int ret = qser_Gnss_Start(qser_h_gnss);
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_gnss] gnss_async_thread() fail.");
+ state = QSER_GNSS_ERROR_FAIL;
+ }
+
+ if(cb != NULL)
+ {
+ cb(state);
+ }
+ return NULL;
+}
+
+static void gnss_callback(uint32 ind_type, const void* data, uint32 data_len)
+{
+ if(data == NULL || data_len <= 0)
+ {
+ LOGE("[qser_gnss] data is NULL.");
+ return;
+ }
+
+ if(qser_gnss_callback == NULL)
+ {
+ //LOGE("[qser_gnss] qser_gnss_callback is NULL.");
+ return;
+ }
+
+ if(ind_type == MBTK_GNSS_IND_LOCATION) {
+ if(data_len != sizeof(mbtk_gnss_location_info_t))
+ {
+ LOGE("[qser_gnss] data size error");
+ return;
+ }
+ mbtk_gnss_location_info_t *locl_info = (mbtk_gnss_location_info_t *)data;
+ mopen_location_info_t qser_locl_info;
+ memset(&qser_locl_info, 0x0, sizeof(mopen_location_info_t));
+ qser_locl_info.latitude = locl_info->latitude;
+ qser_locl_info.longitude = locl_info->longitude;
+ qser_locl_info.altitude = locl_info->altitude;
+ qser_locl_info.speed = locl_info->speed;
+ qser_locl_info.bearing = locl_info->bearing;
+ qser_locl_info.timestamp = locl_info->timestamp;
+ qser_gnss_callback(NULL, E_MT_LOC_MSG_ID_LOCATION_INFO, (void *)(&qser_locl_info), NULL);
+ } else if(ind_type == MBTK_GNSS_IND_NMEA) {
+ mopen_gnss_nmea_info_t qser_nmea = {0};
+ memset(&qser_nmea, 0x0, sizeof(mopen_gnss_nmea_info_t));
+ qser_nmea.length = data_len;
+ memcpy(qser_nmea.nmea, (char *)data, data_len);
+ qser_nmea.timestamp = qser_get_gnss_time_sec(data, data_len);
+ qser_gnss_callback(NULL, E_MT_LOC_MSG_ID_NMEA_INFO, (void *)(&qser_nmea), NULL);
+ } else {
+ printf("Unknown IND : %d\n", ind_type);
+ }
+}
+
+
+/**********************************FUNC***********************************/
+
+/**********************************API***********************************/
+int qser_Gnss_Init (uint32_t *h_gnss)
+{
+ //UNUSED(h_gnss);
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+
+ if(!inited)
+ {
+ ret = mbtk_gnss_init(gnss_callback);
+ if(ret == GNSS_ERR_OK)
+ {
+ ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_NMEA, QSER_GNSS_TIMEOUT);
+ if(ret == GNSS_ERR_OK)
+ {
+ inited = TRUE;
+ }
+ else
+ {
+ LOGE("[qser_gnss] init mbtk_gnss_ind_set() fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_gnss] mbtk_gnss_init() fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ }
+ *h_gnss = qser_h_gnss;
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Deinit (uint32_t h_gnss)
+{
+ //UNUSED(h_gnss);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+
+ if(inited)
+ {
+ ret = mbtk_gnss_deinit();
+ if(ret == GNSS_ERR_OK)
+ {
+ inited = FALSE;
+ }
+ else
+ {
+ LOGE("[qser_gnss] mbtk_gnss_init() fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_AddRxIndMsgHandler (gnss_handler_func_t handler_ptr,uint32_t h_gnss)
+{
+ //UNUSED(handler_ptr);
+ //UNUSED(h_gnss);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(handler_ptr == NULL)
+ {
+ LOGE("[qser_gnss] handler_ptr is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ qser_gnss_callback = handler_ptr;
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Set_Indications (uint32_t h_gnss,e_msg_id_t type)
+{
+ //UNUSED(h_gnss);
+ //UNUSED(type);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_OK;
+ if(type == E_MT_LOC_MSG_ID_LOCATION_INFO)
+ {
+ ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_LOCATION, QSER_GNSS_TIMEOUT);
+ }
+ else if(type == E_MT_LOC_MSG_ID_NMEA_INFO)
+ {
+ ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_NMEA, QSER_GNSS_TIMEOUT);
+ }
+ else
+ {
+ LOGE("[qser_gnss] type is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_ind_set() fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Set_Async_Callback(gnss_async_func_t cb)
+{
+ qser_gnss_async_set_cb(cb);
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Start (uint32_t h_gnss)
+{
+ //UNUSED(h_gnss);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+
+ ret = mbtk_gnss_open(255, QSER_GNSS_TIMEOUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_open is error.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Start_Async(uint32_t h_gnss)
+{
+ //UNUSED(h_gnss);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ pthread_attr_t thread_attr;
+ pthread_t gnss_thread_id;
+ pthread_attr_init(&thread_attr);
+ if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+ {
+ LOGE("[qser_gnss] pthread_attr_setdetachstate() fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s));
+ if(pthread_create(&gnss_thread_id, &thread_attr, gnss_async_thread, NULL))
+ {
+ LOGE("[qser_gnss] pthread_create() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ pthread_attr_destroy(&thread_attr);
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Stop (uint32_t h_gnss)
+{
+ //UNUSED(h_gnss);
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+ ret = mbtk_gnss_close(QSER_GNSS_TIMEOUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_close is error.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_InjectTime (uint32_t h_gnss,LYNQ_INJECT_TIME_INTO_T *time_info)
+{
+ //UNUSED(h_gnss);
+ UNUSED(time_info);
+
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Delete_Aiding_Data (uint32_t h_gnss,DELETE_AIDING_DATA_TYPE_T flags)
+{
+ //UNUSED(h_gnss);
+ //UNUSED(flags);
+
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Server_Configuration(char *host, char *id, char *password)
+{
+ //UNUSED(host);
+ //UNUSED(id);
+ //UNUSED(password);
+
+ if(!inited)
+ {
+ LOGE("[qser_gnss] api not init.");
+ return QSER_RESULT_FAIL;
+ }
+
+ memset(qser_agps_info_save.host, 0x0, QSER_LEN_MAX);
+ if(host != NULL && strlen(host) > 0 && strlen(host) < QSER_LEN_MAX)
+ {
+ memcpy(qser_agps_info_save.host, host, strlen(host));
+ }
+
+ memset(qser_agps_info_save.id, 0x0, QSER_LEN_MAX);
+ if(id != NULL && strlen(id) > 0 && strlen(id) < QSER_LEN_MAX)
+ {
+ memcpy(qser_agps_info_save.id, id, strlen(id));
+ }
+
+ memset(qser_agps_info_save.passwd, 0x0, QSER_LEN_MAX);
+ if(password != NULL && strlen(password) > 0 && strlen(password) < QSER_LEN_MAX)
+ {
+ memcpy(qser_agps_info_save.passwd, password, strlen(password));
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+ char write_buff[512] = {0};
+// int write_length = 0;
+ snprintf(write_buff, 512, "$AGPSCFG,%s,%s,%s", strlen(qser_agps_info_save.host) > 0 ? qser_agps_info_save.host : "NULL",
+ strlen(qser_agps_info_save.id) > 0 ? qser_agps_info_save.id : "NULL",
+ strlen(qser_agps_info_save.passwd) > 0 ? qser_agps_info_save.passwd : "NULL");
+ ret = mbtk_gnss_setting(write_buff, QSER_GNSS_TIMEOUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_download_tle()
+{
+ if(!inited)
+ {
+ LOGE("[qser_gnss] api not init.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+ ret = mbtk_gnss_eph_download(QSER_AGNSS_DOWNLOAD_TIMEPUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_eph_download fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_injectEphemeris(uint32_t h_gnss)
+{
+ //UNUSED(h_gnss);
+
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+ ret = mbtk_gnss_eph_inject(QSER_AGNSS_INJECT_TIMEOUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_eph_inject fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_Set_Frequency(uint32_t h_gnss, int frequency)
+{
+ //UNUSED(h_gnss);
+ //UNUSED(frequency);
+
+ if(h_gnss != qser_h_gnss)
+ {
+ LOGE("[qser_gnss] h_gnss is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(frequency != 1 && frequency != 2 && frequency != 5)
+ {
+ LOGE("[qser_gnss] frequency out of range.");
+ return QSER_RESULT_FAIL;
+ }
+
+ gnss_err_enum ret = GNSS_ERR_UNKNOWN;
+ char param_buf[32] = {0};
+// int length = 0;
+ snprintf(param_buf, 32, "$FREQCFG,%d", frequency);
+ ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
+ if(ret != GNSS_ERR_OK)
+ {
+ LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+/**********************************API***********************************/
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_gpio.c b/mbtk/liblynq_lib_rilv2/lynq_gpio.c
new file mode 100755
index 0000000..ae6ee19
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_gpio.c
@@ -0,0 +1,337 @@
+#include "mbtk_type.h"
+#include "lynq-gpio.h"
+#include "unistd.h"
+#include "fcntl.h"
+#include "mbtk_log.h"
+
+#include <errno.h>
+static int gpio_export(int gpio)
+{
+// int index=0;
+ int file=-1;
+ int result =-1;
+ char pin_index_buffer[5]= {0};
+
+ char buffer[50];
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ if(access(buffer , F_OK) == 0)
+ {
+ LOGD("%d has export.", gpio);
+ return 0;
+ }
+
+ file = open("/sys/class/gpio/export",O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio export file fail.");
+ return -1;
+ }
+
+ memset(pin_index_buffer,0,5);
+ sprintf(pin_index_buffer,"%d", gpio);
+ result = write(file,pin_index_buffer,strlen(pin_index_buffer));
+ if(result < 0)
+ {
+ LOGE("Gpio[%d] export fail. err = %d", gpio, errno);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+static int gpio_unexport(int gpio)
+{
+// int index=0;
+ int file=-1;
+ int result =-1;
+ char pin_index_buffer[5]= {0};
+ char buffer[50];
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ if(access(buffer , F_OK) == -1)
+ {
+ LOGD("%d not export.", gpio);
+ return 0;
+ }
+
+ file = open("/sys/class/gpio/unexport",O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio unexport file fail.");
+ return -1;
+ }
+
+ memset(pin_index_buffer,0,5);
+ sprintf(pin_index_buffer,"%d", gpio);
+ result=write(file,pin_index_buffer,strlen(pin_index_buffer));
+ if(result < 0)
+ {
+ close(file);
+ LOGE("Gpio[%d] unexport fail.", gpio);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+#if 0
+static int gpio_direct_get(int gpio, char *value, int value_size)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ file = open(buffer, O_RDONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] direct fail.", gpio);
+ return -1;
+ }
+
+ memset(value, 0x0, value_size);
+ result = read(file,value,value_size);
+ if(result <= 0)
+ {
+ LOGE("Get gpio[%d] direct fail.", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+#endif
+
+static int gpio_direct_set(int gpio, char *value)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
+ file = open(buffer, O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] direct fail.", gpio);
+ return -1;
+ }
+
+ result = write(file,value,strlen(value));
+ if(result != strlen(value))
+ {
+ LOGE("Set gpio[%d] direct fail.", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+static int gpio_value_get(int gpio)
+{
+ char buffer[50];
+ int fd =-1;
+
+ memset(buffer, 0, sizeof(buffer));
+ sprintf(buffer, "/sys/class/gpio/gpio%d/value", gpio);
+ fd = open(buffer, O_RDONLY);
+ if(fd == -1)
+ {
+ LOGE("Open gpio[%d] fail.", gpio);
+ return -1;
+ }
+
+ memset(buffer, 0, sizeof(buffer));
+ if(read(fd, buffer, sizeof(buffer)) <= 0)
+ {
+ LOGE("Get gpio[%d] value fail", gpio);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ return atoi(buffer);
+}
+
+static int gpio_value_set(int gpio, int value)
+{
+ char buffer[50]= {0};
+ int file =-1;
+ int result =-1;
+
+ memset(buffer,0,50);
+ sprintf(buffer,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(buffer,O_WRONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] value fail.", gpio);
+ return -1;
+ }
+ if(value == 0) {
+ result = write(file,"0",1);
+ } else {
+ result = write(file,"1",1);
+ }
+ if(result != 1)
+ {
+ LOGE("Set gpio[%d] value fail err =%d.", gpio, errno);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+
+int lynq_gpio_init(int gpio, int direction, int value, int pullsel)
+{
+ //UNUSED(gpio);
+ //UNUSED(direction);
+ //UNUSED(value);
+ UNUSED(pullsel);
+
+ if (direction != 1 && direction != 0)
+ {
+ LOGE("[lynq_gpio_init] direction fail.");
+ return -1;
+ }
+
+ if (value != 1 && value != 0)
+ {
+ LOGE("[lynq_gpio_init] value fail.");
+ return -1;
+ }
+
+ if(gpio_export(gpio))
+ {
+ LOGE("[lynq_gpio_init]gpio_export fail.");
+ return -1;
+ }
+
+ if(gpio_direct_set(gpio, direction == 0 ? "in" : "out"))
+ {
+ LOGE("[lynq_gpio_init]gpio_direct_set fail.");
+ return -1;
+ }
+
+ if(direction == 1 && (gpio_value_set(gpio, value) != 0))
+ {
+ LOGE("[lynq_gpio_init]gpio_value_set fail.");
+ return -1;
+ }
+
+
+ return 0;
+}
+
+int lynq_gpio_deinit(int gpio)
+{
+ UNUSED(gpio);
+
+ if(gpio_unexport(gpio))
+ {
+ LOGE("[lynq_gpio_deinit]gpio_unexport fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int lynq_gpio_direction_set(int gpio, int direction)
+{
+ //UNUSED(gpio);
+ //UNUSED(direction);
+
+ if(gpio_direct_set(gpio, direction == 0 ? "in" : "out"))
+ {
+ LOGE("[lynq_gpio_direction_set]gpio_direct_set fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int lynq_gpio_value_set(int gpio, int value)
+{
+ //UNUSED(gpio);
+ //UNUSED(value);
+
+ if(gpio_value_set(gpio, value))
+ {
+ LOGE("[lynq_gpio_value_set]gpio_value_set fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int lynq_gpio_value_get(int gpio)
+{
+ //UNUSED(gpio);
+ int ret = -1;
+
+ ret = gpio_value_get(gpio);
+ if (ret == -1)
+ {
+ LOGE("[lynq_gpio_value_get]gpio_value_get fail.");
+ return -1;
+ }
+
+ return ret;
+}
+
+int lynq_gpio_pullsel_set(int gpio, int pullsel)
+{
+ //UNUSED(gpio);
+ //UNUSED(pullsel);
+ int ret = -1;
+ int value_t;
+
+ if (pullsel == 1)
+ value_t = 0;
+ else if (pullsel == 2)
+ value_t = 1;
+ else
+ {
+ LOGE("[lynq_gpio_pullsel_set] value_t fail.");
+ return -1;
+ }
+
+ ret = gpio_value_set(gpio, value_t);
+ if(ret == -1)
+ {
+ LOGE("[lynq_gpio_pullsel_set]gpio_value_set() fail.");
+ return -1;
+ }
+
+ return ret;
+}
+
+
+int lynq_gpio_pullsel_get(int gpio)
+{
+ //UNUSED(gpio);
+ int ret = -1;
+
+ ret = gpio_value_get(gpio);
+ if (ret == -1)
+ {
+ LOGE("[lynq_gpio_pullsel_get]gpio_value_get() fail.");
+ return -1;
+ }
+
+ return ret + 1;
+}
+
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_irq.c b/mbtk/liblynq_lib_rilv2/lynq_irq.c
new file mode 100755
index 0000000..4e42e07
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_irq.c
@@ -0,0 +1,475 @@
+#include "lynq-irq.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+#include "mbtk_log.h"
+
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+
+// #define _GNU_SOURCE
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <poll.h>
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+
+struct libirq_info {
+ unsigned int line;
+ unsigned int type;
+ int wake;
+ int fd;
+ irq_handler handler;
+ unsigned int used;
+};
+
+struct libirq_context {
+ unsigned int inited;
+ int fd;
+ pthread_t th;
+ struct libirq_info info[SC_LIBIRQ_MAX];
+};
+static struct libirq_context irq_ctx = {0};
+
+#define irq_init() irq_ctx.inited
+#define line_used(l) irq_ctx.info[l].used
+#define irq_fd(l) irq_ctx.info[l].fd
+#define libirq_fd() irq_ctx.fd
+
+static void *libirq_loop(void *arg)
+{
+ unsigned int int_status = 0;
+ int fd = libirq_fd();
+ int ret = 0;
+ int i;
+
+ while(1) {
+ ret = ioctl(fd, SC_IRQ_GET_STATUS, &int_status);
+ if (ret < 0) {
+ LOGE("libirq_loop get status failed:%d", ret);
+ } else {
+/* printf("libirq_loop get status :0x%x\n", int_status); */
+ }
+
+ for (i=0; i<SC_LIBIRQ_MAX; i++) {
+ if ((int_status & (1<<i)) && line_used(i) && irq_ctx.info[i].handler) {
+ irq_ctx.info[i].handler();
+
+ ret = ioctl(fd, SC_IRQ_CLEAR_STATUS, 0);
+ if (ret < 0) {
+ LOGE("libirq_loop clear status failed:%d", ret);
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
+static int libirq_init_thread(void)
+{
+ int ret = 0;
+ pthread_attr_t attribute;
+
+ pthread_attr_init(&attribute);
+ pthread_attr_setstacksize(&attribute, 32*1024);
+
+ ret = pthread_create(&irq_ctx.th, &attribute, libirq_loop, NULL);
+ if(ret) {
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * Add a handler for an interrupt line.
+ *
+ * line : The interrupt line
+ * handler : Function to be called when the IRQ occurs.
+ * trig_type : rising edge or fallling edge
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_install(unsigned int line, irq_handler handler, int trig_type)
+{
+ int fd;
+ struct libirq_info *info;
+ char *usr_name;
+ int ret = 0;
+
+ if ((line >= SC_LIBIRQ_MAX) || (handler == NULL) || (trig_type >= SC_LIBIRQ_TYPE_MAX))
+ return -EINVAL;
+
+ if (line_used(line))
+ return -EEXIST;
+
+ ret = asprintf(&usr_name, "%s%d", SC_IRQ_DEV, line);
+ if (ret < 0) {
+ return -ENOMEM;
+ }
+
+ fd = open(usr_name, O_RDWR);
+ if(fd < 0) {
+ free(usr_name);
+ return -ENODEV;
+ }
+ irq_fd(line) = fd;
+ free(usr_name);
+ info = &irq_ctx.info[line];
+ info->line = line;
+ info->type = trig_type;
+ info->handler = handler;
+
+ if (ioctl(fd, SC_IRQ_INSTALL, trig_type) < 0) {
+ return -EPERM;
+ }
+
+ line_used(line) = 1;
+
+ if (!irq_init()) {
+ ret = libirq_init_thread();
+ if (ret) {
+ LOGE("libirq_init_thread, err:%d", ret);
+ return ret;
+ }
+
+ libirq_fd() = fd;
+ irq_init() = 1;
+ }
+
+ return 0;
+}
+
+/*
+ * free an interrupt allocated with sc_irq_install.
+ *
+ * line : The interrupt line
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_uninstall(unsigned int line)
+{
+ int fd;
+
+ if (line >= SC_LIBIRQ_MAX)
+ return -EINVAL;
+
+ if (!line_used(line))
+ return -ENODEV;
+
+ if (ioctl(irq_fd(line), SC_IRQ_UNINSTALL, 0) < 0) {
+ return -EPERM;
+ }
+
+ fd = libirq_fd();
+ if (fd)
+ close(fd);
+
+ line_used(line) = 0;
+
+ return 0;
+}
+
+/*
+ * set the irq trigger type for an irq.
+ *
+ * line : The interrupt line
+ * trig_type : edge or level type
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_set_type(unsigned int line, int trig_type)
+{
+ struct libirq_info *info;
+
+ if ((line >= SC_LIBIRQ_MAX) || (trig_type >= SC_LIBIRQ_TYPE_MAX))
+ return -EINVAL;
+
+ if (!line_used(line))
+ return -EEXIST;
+
+ info = &irq_ctx.info[line];
+ //if (info->type != trig_type) {
+ if (ioctl(irq_fd(line), SC_IRQ_SET_TYPE, trig_type) < 0) {
+ return -EPERM;
+ }
+ //}
+
+ info->type = trig_type;
+
+ return 0;
+}
+
+/*
+ * get the irq trigger type for an irq.
+ *
+ * line : The interrupt line
+ * trig_type : edge or level type
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_get_type(unsigned int line, int *trig_type)
+{
+ struct libirq_info *info;
+
+ if ((line >= SC_LIBIRQ_MAX) || !trig_type)
+ return -EINVAL;
+
+ if (!line_used(line))
+ return -EEXIST;
+
+ info = &irq_ctx.info[line];
+ *trig_type = info->type;
+
+ return 0;
+}
+
+/*
+ * control irq power management wakeup.
+ *
+ * line : The interrupt line
+ * en : enable/disable power management wakeup
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_set_wake(unsigned int line, int en)
+{
+ struct libirq_info *info;
+
+ if (line >= SC_LIBIRQ_MAX)
+ return -EINVAL;
+
+ if (!line_used(line))
+ return -EEXIST;
+
+ info = &irq_ctx.info[line];
+ if (info->wake != en) {
+ if (ioctl(irq_fd(line), SC_IRQ_SET_WAKE, en) < 0) {
+ return -EPERM;
+ }
+ }
+
+ info->wake = en;
+
+ return 0;
+}
+
+/*
+ * get the irq awake status for an irq.
+ *
+ * line : The interrupt line
+ * en : enable/disable power management wakeup
+ *
+ * return 0 if succeed, others failed
+ */
+int sc_irq_get_wake(unsigned int line, int *en)
+{
+ struct libirq_info *info;
+ unsigned int wake;
+
+ if (line >= SC_LIBIRQ_MAX)
+ return -EINVAL;
+
+ if (!line_used(line))
+ return -EEXIST;
+
+ if (ioctl(irq_fd(line), SC_IRQ_GET_WAKE, &wake) < 0) {
+ return -EPERM;
+ }
+
+ info = &irq_ctx.info[line];
+ info->wake = wake;
+ *en = wake;
+
+ return 0;
+}
+
+
+
+
+/*****************************************
+* @brief:lynq_irq_install
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+int lynq_irq_install(int line, irq_handler irq_test_handler, trig_type_e trig_type)
+{
+ int ret;
+
+ if (trig_type != 0 && trig_type != 1)
+ {
+ LOGE("lynq_irq_install error trig_type:%d", trig_type);
+ return -1;
+ }
+
+ line = line-117;
+ if (line < 0)
+ {
+ LOGE("lynq_irq_install error line:%d", line);
+ return -1;
+ }
+
+ ret = sc_irq_install(line, irq_test_handler, trig_type);
+ if (ret != 0)
+ {
+ LOGE("do_install_irq failed, ret:%d", ret);
+ return ret;
+ }
+ return 0;
+}
+
+
+/*****************************************
+* @brief:lynq_irq_uninstall
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+
+int lynq_irq_uninstall(int line)
+{
+ int ret;
+
+ line = line-117;
+ ret = sc_irq_uninstall(line);
+ if (ret != 0)
+ {
+ LOGE("unistall failed, ret:%d", ret);
+ return ret;
+ }
+ LOGI("uninstall irq(%d) ok", line);
+ return 0;
+}
+
+
+/*****************************************
+* @brief:lynq_irq_set_type
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+int lynq_irq_set_type(int line, int trig_type)
+{
+ int ret;
+
+ if (trig_type != 0 && trig_type != 1)
+ {
+ LOGE("lynq_irq_set_type error trig_type:%d", trig_type);
+ return -1;
+ }
+
+ line = line-117;
+ ret = sc_irq_set_type(line, trig_type);
+ if (ret != 0)
+ {
+ LOGE("set_type failed, ret:%d", ret);
+ return ret;
+ }
+ return 0;
+
+}
+
+/*****************************************
+* @brief:lynq_irq_get_type
+* @param count [IN]:1
+* @param sum [OUT]:NA
+* @return :success >= 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+int lynq_irq_get_type(int line)
+{
+ int ret;
+ int trig_type;
+
+ line = line-117;
+ ret = sc_irq_get_type(line, &trig_type);
+ if (ret != 0)
+ {
+ LOGE("get_type failed, ret:%d", ret);
+ return ret;
+ }
+ LOGI("get_type readback(%d)", trig_type);
+ return trig_type;
+}
+
+
+/*****************************************
+* @brief:lynq_irq_set_wake
+* @param count [IN]:2
+* @param sum [OUT]:NA
+* @return :success 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+int lynq_irq_set_wake(int line, int en)
+{
+ int ret;
+
+ if((en != 0) && (en != 1))
+ {
+ LOGE("wake_state is not 0 or 1");
+ return -1;
+ }
+
+ line = line-117;
+ ret = sc_irq_set_wake(line, en);
+ if (ret != 0)
+ {
+ LOGE("set_wake failed, ret:%d", ret);
+ return ret;
+ }
+ return 0;
+}
+
+/*****************************************
+* @brief:lynq_irq_get_wake
+* @param count [IN]:1
+* @param sum [OUT]:NA
+* @return :success >= 0, failed other
+* @todo:NA
+* @see:NA
+* @warning:NA
+******************************************/
+int lynq_irq_get_wake(int line)
+{
+ int ret;
+ int en;
+
+ line = line-117;
+ ret = sc_irq_get_wake(line, &en);
+ if (ret != 0)
+ {
+ LOGE("get_wake failed, ret:%d", ret);
+ return ret;
+ }
+ LOGI("get_wake readback(%d)", en);
+ return en;
+}
+
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_log.c b/mbtk/liblynq_lib_rilv2/lynq_log.c
new file mode 100755
index 0000000..b844490
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_log.c
@@ -0,0 +1,640 @@
+#include <stdarg.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include "json-c/json.h"
+#include "lynq_deflog.h"
+#include "mbtk_type.h"
+#include <signal.h>
+#include "mbtk_utils.h"
+
+#define LOG_CONFIG_PATH "/etc/mbtk/mbtk_log.json"
+#define SYSLOG_PATCH "syslog"
+#define SYSLOG_NAME "syslog"
+#define SYSLOG_INDEX 0
+
+#define RADIOLOG_NAME "radio"
+#define RADIO_INDEX 1
+
+void lynq_log_configuration_init(const char *log_name)
+{
+ //UNUSED(log_name);
+ mbtk_log_init(SYSLOG_PATCH, (char*)log_name);
+}
+
+void lynq_log_global_output(log_level_enum Level,const char *format,...)
+{
+ va_list args;
+ va_start(args,format);
+ mbtk_log(Level, format, args);
+ va_end(args);
+}
+
+const char* lynq_read_log_version()
+{
+ return "LOG-V1.0";
+}
+
+int lynq_syslog_set_file_size(int value)
+{
+// UNUSED(value);
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+ int tmp_int;
+ const char* tmp_string = NULL;
+
+ if(value < 1)
+ {
+ value = 1;
+ }
+ else if(value > 100)
+ {
+ value = 100;
+ }
+ value = value*1024;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ mbtk_system("echo Can't open config file > /dev/console");
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("NULL == datajson\n");
+ mbtk_system("echo NULL == datajson > /dev/console");
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("SYSLOG_NAME error, tmp_int != 1\n");
+ mbtk_system("echo SYSLOG_NAME error, tmp_int != 1 > /dev/console");
+ return -1;
+ }
+
+ json_object_object_add(datajson, "rotate_file_size", json_object_new_int(value));
+
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return 0;
+}
+
+int lynq_syslog_get_file_size(void)
+{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+ int tmp_int;
+ const char* tmp_string = NULL;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "rotate_file_size", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ /***释放json对象***/
+ json_object_put(jsonobj);
+
+ return tmp_int/1024;
+// return tmp_int;
+}
+
+int lynq_syslog_set_file_rotate(int value)
+{
+ //UNUSED(value);
+
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+ int tmp_int;
+ const char* tmp_string = NULL;
+
+ if(value < 0)
+ {
+ value = 0;
+ }
+ else if(value > 99)
+ {
+ value = 99;
+ }
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_add(datajson, "rotate_file_count", json_object_new_int(value));
+
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return 0;
+}
+
+int lynq_syslog_get_file_rotate(void)
+{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+ int tmp_int;
+ const char* tmp_string = NULL;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0 || tmp_int != 1)
+ {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "rotate_file_count", &listjson);
+ tmp_int = json_object_get_int(listjson);
+
+ /***释放json对象***/
+ json_object_put(jsonobj);
+
+ return tmp_int;
+}
+
+log_level_enum filter_char_to_pri(char c)
+{
+ switch (c) {
+ case 'v':
+ return LOG_VERBOSE;
+ case 'd':
+ return LOG_DEBUG;
+ case 'i':
+ return LOG_INFO;
+ case 'w':
+ return LOG_WARNING;
+ case 'e':
+ return LOG_ERROR;
+ case '*':
+ default:
+ return LOG_LEVEL_MAX;
+ }
+}
+
+char filter_pri_to_char(log_level_enum level)
+{
+ char char_level;
+ switch (level) {
+ case LOG_VERBOSE:
+ char_level = 'v';
+ break;
+ case LOG_DEBUG:
+ char_level = 'd';
+ break;
+ case LOG_UNSET:
+ case LOG_INFO:
+ char_level = 'i';
+ break;
+ case LOG_WARNING:
+ char_level = 'w';
+ break;
+ case LOG_ERROR:
+ char_level = 'e';
+ break;
+ case LOG_LEVEL_MAX:
+ default:
+ char_level = '*';
+ break;
+ }
+ return char_level;
+}
+
+int lynq_set_log_level(const char * module_name, log_level_enum level)
+{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+ json_object* fileterjson = NULL;
+ json_object* fileter_listjson = NULL;
+ json_object* new_fileter = NULL;
+
+ int n = 0, array_length = 0;
+ char* tmp_string = NULL;
+ char level_string[5] = {'\0'};
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "filter_list", &listjson);
+ if (NULL == listjson) {
+ printf("%s %d: object failure!\n", __FUNCTION__, __LINE__);
+ json_object_put(listjson);
+ return -1;
+ }
+ array_length = json_object_array_length(listjson);
+ for (n = 0; n <= array_length; n++) {
+ fileterjson = json_object_array_get_idx(listjson, n);
+ if (NULL == fileterjson) {
+ new_fileter = json_object_new_object();
+ sprintf(level_string, "%c", filter_pri_to_char(level));
+ json_object_object_add(new_fileter, "priority", json_object_new_string(level_string));
+ json_object_object_add(new_fileter, "tag", json_object_new_string(module_name));
+ json_object_array_add(listjson, new_fileter);
+ break;
+ }
+
+ json_object_object_get_ex(fileterjson, "tag", &fileter_listjson);
+ const char *str = json_object_get_string(fileter_listjson);
+ if (str) {
+ tmp_string = strdup(str);
+ if(strcmp(module_name, tmp_string) == 0)
+ {
+ sprintf(level_string, "%c", filter_pri_to_char(level));
+ json_object_object_add(fileterjson, "priority", json_object_new_string(level_string));
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return 0;
+ }
+ }
+ else
+ {
+ continue;
+ }
+ }
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+
+ return 0;
+}
+
+int lynq_get_log_level(const char * module_name, log_level_enum *level)
+{
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+ json_object* fileterjson = NULL;
+ json_object* fileter_listjson = NULL;
+
+ int n;
+ char* tmp_string = NULL;
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj) {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ return -1;
+ }
+ /***获取data***/
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson) {
+ json_object_put(jsonobj);
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "filter_list", &listjson);
+ if (NULL == listjson) {
+ printf("%s %d: object failure!\n", __FUNCTION__, __LINE__);
+ json_object_put(listjson);
+ return -1;
+ }
+
+ for (n = 0 ; n < 5; n++) {
+ fileterjson = json_object_array_get_idx(listjson, n);
+ if (NULL == fileterjson) {
+ printf("the fileterjson exit\n");
+ break;
+ }
+
+ json_object_object_get_ex(fileterjson, "tag", &fileter_listjson);
+ const char *str = json_object_get_string(fileter_listjson);
+ if (str) {
+ tmp_string = strdup(str);
+ printf("tag is %s\n", tmp_string);
+ if(strcmp(module_name, tmp_string) == 0)
+ {
+ json_object_object_get_ex(fileterjson, "priority", &fileter_listjson);
+ str = json_object_get_string(fileter_listjson);
+ if (str) {
+ *tmp_string = str[0];
+ printf("fileter_listjson: %c\n", *tmp_string);
+ *level = filter_char_to_pri(*tmp_string);
+ //get the log level
+ json_object_put(jsonobj);
+ return 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ continue;
+ }
+ }
+ *level = LOG_UNSET;
+ /***释放json对象***/
+ json_object_put(jsonobj);
+
+ return 0;
+}
+
+int lynq_set_special_log_level(const char * exe_name, const char * module_name, log_level_enum level)
+{
+ UNUSED(exe_name);
+ UNUSED(module_name);
+ UNUSED(level);
+
+
+ return 0;
+}
+
+int lynq_get_special_log_level(const char * exe_name, const char * module_name, log_level_enum *level)
+{
+ UNUSED(exe_name);
+ UNUSED(module_name);
+ UNUSED(level);
+
+
+ return 0;
+}
+
+int lynq_notify_recalc_log_level(pid_t pid)
+{
+ UNUSED(pid);
+ char sendBuff[100]={'\0'};
+ int clientFd,nwrite;
+ struct sockaddr_un serverAddr,clientAddr;
+
+ unlink("/var/log_client.socket"); /* in case it already exists */
+
+ memset(&clientAddr,0,sizeof(clientAddr));
+ memset(&serverAddr,0,sizeof(serverAddr));
+ clientAddr.sun_family = AF_UNIX;
+ sprintf(clientAddr.sun_path,"%s","/var/log_client.socket");
+
+ if ((clientFd = socket(AF_UNIX,SOCK_STREAM,0)) < 0)
+ {
+ printf("err -1\n");
+ return -1;
+ }
+
+ if (bind(clientFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0)
+ {
+ printf("err -2\n");
+ close(clientFd);
+ return -2;
+ }
+
+ serverAddr.sun_family = AF_UNIX;
+ sprintf(serverAddr.sun_path, "/var/log_server.socket");
+ if (connect(clientFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0)
+ {
+ printf("err -3\n");
+ close(clientFd);
+ return -3;
+ }
+
+ sprintf(sendBuff,"%s","update");
+ if ((nwrite = write(clientFd, sendBuff, 100)) < 0)
+ {
+ printf("err -4\n");
+ close(clientFd);
+ return -4;
+ }
+
+ close(clientFd);
+ return 0;
+}
+
+int lynq_write_log_to_file_now()
+{
+ FILE *fp;
+ char command[256];
+ char buffer[256];
+ int pid = -1;
+ const char *process_name = "mbtk_logd";
+
+
+ snprintf(command, sizeof(command), "pgrep %s", process_name);
+ fp = popen(command, "r");
+ if (fp == NULL)
+ {
+ perror("error comman");
+ return -1;
+ }
+
+ if (fgets(buffer, sizeof(buffer), fp) != NULL)
+ {
+ pid = atoi(buffer);
+ }
+ pclose(fp);
+
+ if (pid != -1)
+ {
+ printf("mbtk %s PID: %d\n", process_name, pid);
+ if (kill(pid, SIGTERM) == -1)
+ {
+ perror("send SIGTERM signal failed");
+ return -1;
+ }
+ printf("send %d SIGTERM signal\n", pid);
+ }
+ else
+ {
+ printf("no find %s\n", process_name);
+ }
+
+ //lynq_log_configuration_init("log_end");
+ //lynq_log_global_output(LOG_DEBUG,"mbtk_logd_out");
+ return 0;
+
+}
+
+int lynq_stop_record_log(int value)
+{
+
+ json_object* jsonobj = NULL;
+ json_object* tmpjson = NULL;
+ json_object* datajson = NULL;
+ json_object* listjson = NULL;
+
+// int tmp_int;
+ const char* tmp_string = NULL;
+
+ if(value != 0 && value != 1)
+ {
+ printf("invalid value ");
+ return -1;
+ }
+
+ jsonobj = json_object_from_file(LOG_CONFIG_PATH);
+ if (NULL == jsonobj)
+ {
+ printf("Can't open config file: %s\n", LOG_CONFIG_PATH);
+ mbtk_system("echo Can't open config file > /dev/console");
+ return -1;
+ }
+
+
+ json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson);
+
+ /***获取syslog json data***/
+ datajson = json_object_array_get_idx(tmpjson, SYSLOG_INDEX);
+ if (NULL == datajson)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("NULL == datajson\n");
+ mbtk_system("echo NULL == datajson > /dev/console");
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, SYSLOG_NAME) != 0)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("SYSLOG_NAME error, \n");
+ mbtk_system("echo SYSLOG_NAME error, > /dev/console");
+ return -1;
+ }
+ else
+ {
+ //set 0 to syslog
+ json_object_object_add(datajson, "enable", json_object_new_int(value));
+ }
+
+ /***获取radiolog json data***/
+ datajson = json_object_array_get_idx(tmpjson, RADIO_INDEX);
+ if (NULL == datajson)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("NULL == datajson\n");
+ mbtk_system("echo NULL == datajson > /dev/console");
+ return -1;
+ }
+
+ json_object_object_get_ex(datajson, "name", &listjson);
+ tmp_string = json_object_get_string(listjson);
+
+ json_object_object_get_ex(datajson, "enable", &listjson);
+ json_object_get_int(listjson);
+
+ if(strcmp(tmp_string, RADIOLOG_NAME) != 0)
+ {
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ printf("RADIO_NAME error or \n");
+ mbtk_system("echo RADIO_NAME error, > /dev/console");
+ return -1;
+ }
+ else
+ {
+ //set 0 to radio_log
+ json_object_object_add(datajson, "enable", json_object_new_int(value));
+ }
+
+ /***释放json对象***/
+ json_object_to_file(LOG_CONFIG_PATH, jsonobj);
+ json_object_put(jsonobj);
+ return 0;
+}
\ No newline at end of file
diff --git a/mbtk/liblynq_lib_rilv2/lynq_net_light.c b/mbtk/liblynq_lib_rilv2/lynq_net_light.c
new file mode 100755
index 0000000..4b229c3
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_net_light.c
@@ -0,0 +1,62 @@
+#include "lynq_led.h"
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "mbtk_led_control.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_FAIL -1
+#define QSER_RESULT_SUCCESS 0
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+
+/****************************VARIABLE***************************************/
+
+
+/******************************FUNC*****************************************/
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int lynq_set_netled_on(int led_mode)
+{
+ //UNUSED(led_mode);
+
+ if(led_mode != MBTK_LED_STATUS_CLOSE && led_mode != MBTK_LED_STATUS_OPEN)
+ {
+ LOGE("[qser_led]param is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ led_info_s led_control;
+
+ memset(&led_control, 0x0, sizeof(led_info_s));
+ led_control.led_type = MBTK_LED_NET;
+ led_control.status = led_mode;
+ mbtk_led_set(led_control);
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int lynq_set_statusled_on(int led_mode)
+{
+ //UNUSED(led_mode);
+
+ if(led_mode != MBTK_LED_STATUS_CLOSE && led_mode != MBTK_LED_STATUS_OPEN)
+ {
+ LOGE("[qser_led]param is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ led_info_s led_control;
+
+ memset(&led_control, 0x0, sizeof(led_info_s));
+ led_control.led_type = MBTK_LED_STATUS;
+ led_control.status = led_mode;
+ mbtk_led_set(led_control);
+
+ return QSER_RESULT_SUCCESS;
+}
+/****************************API***************************************/
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_network.c b/mbtk/liblynq_lib_rilv2/lynq_network.c
new file mode 100755
index 0000000..aed8aad
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_network.c
@@ -0,0 +1,1212 @@
+#include "lynq_qser_network.h"
+#include "mbtk_type.h"
+#include "mbtk_ril_api.h"
+#include "mbtk_log.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+
+static mbtk_ril_handle* qser_info_handle;
+static const uint qser_h_nw = 0x5F6F7F8F;
+
+static uint64_t tmp_mode = 0xFF;
+
+typedef struct
+{
+ QSER_NW_RxMsgHandlerFunc_t handlerPtr;
+ void* contextPtr;
+} lynq_cust_cb_func;
+
+static lynq_cust_cb_func lynq_func_cb_handle;
+
+static int roaming_pref = 1; // Open roaming for default.
+
+typedef enum {
+ RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */
+ RADIO_TECH_3GPP2 = 2 /* 3GPP2 Technologies - CDMA */
+} RIL_RadioTechnologyFamily;
+
+
+typedef struct
+{
+ uint8 *lynq_operator_l;
+ uint8 *lynq_operator_s;
+ uint32 lynq_mcc_mnc;
+} lynq_operator_mcc_mnc_t;
+
+static lynq_operator_mcc_mnc_t lynq_operator_mcc_mnc[] =
+{
+ {(uint8*)"China Mobile",(uint8*)"CMCC",46000},
+ {(uint8*)"China Unicom",(uint8*)"CU",46001},
+ {(uint8*)"China Mobile",(uint8*)"CMCC",46002},
+ {(uint8*)"China Telecom",(uint8*)"CT",46003},
+ {(uint8*)"China Mobile",(uint8*)"CMCC",46004},
+ {(uint8*)"China Telecom",(uint8*)"CT",46005},
+ {(uint8*)"China Unicom",(uint8*)"CU",46006},
+ {(uint8*)"China Mobile",(uint8*)"CMCC",46007},
+ {(uint8*)"China Mobile",(uint8*)"CMCC",46008},
+ {(uint8*)"China Unicom",(uint8*)"CU",46009},
+ {(uint8*)"China Telecom",(uint8*)"CT",46011}
+};
+
+#if 0
+//T106的实现
+/*Used to wait for an update signal*/
+int lynq_wait_signalchanges(int *handle)
+{
+ LYDBGLOG("start wait signalchanges info");
+ if(NULL == handle)
+ {
+ LYERRLOG("illegal input");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ wait_urc_signal_changes();
+ LYDBGLOG("get signalchanges");
+ *handle = s_module_wait_urc_id;
+ return RESULT_OK;
+}
+
+bool is_support_urc(int urc_id)
+{
+ switch(urc_id)
+ {
+ case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
+ case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
+ case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
+ case RIL_UNSOL_SIGNAL_STRENGTH:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*Used to get urc info*/
+int lynq_get_urc_info(const int handle,signalStrength_t *solSigStren,int *slot_id)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return -1;
+ }
+ LYDBGLOG("start get urc info");
+ if(is_support_urc(handle)==false)
+ {
+ LYINFLOG("invalid handle!!!");
+ return -1;
+ }
+ if((handle ==RIL_UNSOL_SIGNAL_STRENGTH && NULL == solSigStren) ||
+ (handle !=RIL_UNSOL_SIGNAL_STRENGTH && NULL == slot_id))
+ {
+ LYINFLOG("incoming solSigStren or slot_id is NULL!!!");
+ return -1;
+ }
+ switch(handle)
+ {
+ case RIL_UNSOL_SIGNAL_STRENGTH: //1009
+ {
+ LYDBGLOG("get state update to signal info");
+ solSigStren->gw_sig_valid = s_network_urc_solSigStren.gw_sig_valid;
+ solSigStren->rssi = s_network_urc_solSigStren.rssi;
+ solSigStren->wcdma_signalstrength = s_network_urc_solSigStren.wcdma_signalstrength;
+ solSigStren->wcdma_sig_valid = s_network_urc_solSigStren.wcdma_sig_valid;
+ solSigStren->rscp = s_network_urc_solSigStren.rscp;
+ solSigStren->ecno = s_network_urc_solSigStren.ecno;
+ solSigStren->lte_signalstrength = s_network_urc_solSigStren.lte_signalstrength;
+ solSigStren->lte_sig_valid = s_network_urc_solSigStren.lte_sig_valid;
+ solSigStren->rsrp = s_network_urc_solSigStren.rsrp;
+ solSigStren->rsrq = s_network_urc_solSigStren.rsrq;
+ solSigStren->rssnr = s_network_urc_solSigStren.rssnr;
+ solSigStren->nr_sig_valid = s_network_urc_solSigStren.nr_sig_valid;
+ solSigStren->ssRsrp = s_network_urc_solSigStren.ssRsrp;
+ solSigStren->ssRsrq = s_network_urc_solSigStren.ssRsrq;
+ solSigStren->ssSinr = s_network_urc_solSigStren.ssSinr;
+ solSigStren->csiRsrp = s_network_urc_solSigStren.csiRsrp;
+ solSigStren->csiRsrq = s_network_urc_solSigStren.csiRsrq;
+ solSigStren->csiSinr = s_network_urc_solSigStren.csiSinr;
+ break;
+ }
+ default:
+ {
+ *slot_id = s_module_urc_slot_id;
+ LYINFLOG("slot_id = %d",s_module_urc_slot_id);
+ }
+ }
+ return 0;
+}
+
+
+void urc_msg_process_voice_reg()
+{
+ if(s_handlerPtr != NULL)
+ {
+ s_handlerPtr(g_nw_val,NW_IND_VOICE_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+ }
+}
+
+void urc_msg_process_data_reg()
+{
+ if(s_handlerPtr != NULL)
+ {
+ s_handlerPtr(g_nw_val,NW_IND_DATA_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+ }
+}
+
+void urc_msg_process_ims_reg()
+{
+ if(s_handlerPtr != NULL)
+ {
+ s_handlerPtr(g_nw_val,NW_IND_IMS_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+ }
+}
+
+void *new_network_thread_recv(void *context)
+{
+ int handle = -1;
+ uint32_t ind_flag = 0;
+
+ while (1)
+ {
+ lynq_wait_signalchanges(&handle);
+
+ switch(handle)
+ {
+ case 1002: //RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
+ {
+ urc_msg_process_voice_reg();
+
+ break;
+ }
+ case 3015://RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
+ {
+ urc_msg_process_data_reg();
+ break;
+ }
+ case 1009://RIL_UNSOL_SIGNAL_STRENGTH:
+ {
+ urc_msg_process_signal_strength();
+ break;
+ }
+ case 1037://RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
+ {
+ urc_msg_process_ims_reg();
+ break;
+ }
+ }
+ }
+ return NULL;
+}
+
+void urc_msg_process_signal_strength()
+{
+ signalStrength_t signalstrength;
+ int slot_id;
+
+ int ret = lynq_get_urc_info(1009,&signalstrength,&slot_id);
+ if (ret == 0)
+ {
+ QSER_NW_SINGNAL_EVENT_IND_T msg_buf;
+ msg_buf.gsm_sig_info_valid = signalstrength.gw_sig_valid;
+ msg_buf.gsm_sig_info.rssi = signalstrength.rssi;
+ msg_buf.wcdma_sig_info_valid = signalstrength.wcdma_sig_valid;
+ msg_buf.wcdma_sig_info.rssi = signalstrength.rscp;
+ msg_buf.wcdma_sig_info.ecio = signalstrength.ecno;
+ msg_buf.tdscdma_sig_info_valid = 0;
+ msg_buf.lte_sig_info_valid = signalstrength.lte_sig_valid;
+ msg_buf.lte_sig_info.rssi = -125;
+ msg_buf.lte_sig_info.rsrp = signalstrength.rsrp;
+ msg_buf.lte_sig_info.rsrq = signalstrength.rsrq;
+ msg_buf.lte_sig_info.snr = signalstrength.rssnr;
+ msg_buf.cdma_sig_info_valid = 0;
+ msg_buf.hdr_sig_info_valid = 0;
+ msg_buf.nr_sig_info_valid = signalstrength.nr_sig_valid;
+ msg_buf.nr_sig_info.ssRsrp = signalstrength.ssRsrp;
+ msg_buf.nr_sig_info.ssRsrq = signalstrength.ssRsrq;
+ msg_buf.nr_sig_info.ssSinr = signalstrength.ssSinr;
+ msg_buf.nr_sig_info.csiRsrp = signalstrength.csiRsrp;
+ msg_buf.nr_sig_info.csiRsrq = signalstrength.csiRsrq;
+ msg_buf.nr_sig_info.csiSinr = signalstrength.csiSinr;
+ void *ind_msg_buf= &msg_buf;
+ if(s_handlerPtr!=NULL)
+ {
+ s_handlerPtr(g_nw_val,NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG,ind_msg_buf,sizeof (msg_buf) ,s_contextPtr);
+ }
+ }
+}
+
+#endif
+
+static int8_t rssi_convert_to_dBm(uint8 rssi)
+{
+ if(rssi <= 31)
+ {
+ return rssi * 2 - 113;
+ }
+ else
+ {
+ return -125;
+ }
+}
+
+static int16_t rsrp_convert_to_dBm(uint8 rsrp)
+{
+ if(rsrp <= 96)
+ {
+ return rsrp - 140;
+ }
+ else
+ {
+ return -44;
+ }
+}
+
+static int16_t rsrq_convert_to_dB(uint8 rsrq)
+{
+ if(rsrq >= 1 && rsrq <= 34)
+ {
+ return (rsrq + 1) / 2 - 20;
+ }
+ else
+ {
+ return -20;
+ }
+}
+
+static int16_t ecno_convert_to_dB(uint8 ecno)
+{
+ if(ecno >= 48)
+ {
+ return 0;
+ }
+ else if(ecno == 255)
+ {
+ return 255;
+ }
+ else
+ {
+ return 48 - ecno;
+ }
+}
+
+void qser_signal_state_change_cb(const void* data, int data_len)
+{
+ /*
+ data_signal[0] = signal.type;
+ data_signal[1] = signal.rssi;
+ data_signal[2] = signal.rxlev;
+ data_signal[3] = signal.ber;
+ data_signal[4] = signal.rscp;
+ data_signal[5] = signal.ecno;
+ data_signal[6] = signal.rsrq;
+ data_signal[7] = signal.rsrp;
+ */
+ if(data && data_len == 8)
+ {
+ uint8 *net_data = (uint8*)data;
+ mbtk_radio_technology_enum type = (mbtk_radio_technology_enum)net_data[0];
+
+ QSER_NW_SINGNAL_EVENT_IND_T signal_msg_buf;
+ memset(&signal_msg_buf, 0x0, sizeof(QSER_NW_SINGNAL_EVENT_IND_T));
+
+ signal_msg_buf.gsm_sig_info_valid = FALSE;
+ signal_msg_buf.lte_sig_info_valid = FALSE;
+ signal_msg_buf.wcdma_sig_info_valid = FALSE;
+ signal_msg_buf.tdscdma_sig_info_valid = FALSE;
+ signal_msg_buf.cdma_sig_info_valid = FALSE;
+ signal_msg_buf.hdr_sig_info_valid = FALSE;
+ signal_msg_buf.nr_sig_info_valid = FALSE;
+
+ if(type == MBTK_RADIO_TECH_GSM || type == MBTK_RADIO_TECH_GSM_COMPACT || \
+ type == MBTK_RADIO_TECH_GSM_EGPRS) //GSM
+ {
+ signal_msg_buf.gsm_sig_info_valid = TRUE;
+ signal_msg_buf.gsm_sig_info.rssi = rssi_convert_to_dBm(net_data[1]);
+ }
+ else if(type == MBTK_RADIO_TECH_E_UTRAN) //LTE
+ {
+ signal_msg_buf.lte_sig_info_valid = TRUE;
+ signal_msg_buf.lte_sig_info.rssi = rssi_convert_to_dBm(net_data[1]);
+ signal_msg_buf.lte_sig_info.rsrp = rsrp_convert_to_dBm(net_data[7]);
+ signal_msg_buf.lte_sig_info.rsrq = rsrq_convert_to_dB(net_data[6]);
+ signal_msg_buf.lte_sig_info.snr = 0x7FFF;//(当前mbtk没有该参数)
+ }
+ else if (type == MBTK_RADIO_TECH_UTRAN || type == MBTK_RADIO_TECH_UTRAN_HSDPA || \
+ type == MBTK_RADIO_TECH_UTRAN_HSUPA || type == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA || \
+ type == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
+ {
+ signal_msg_buf.wcdma_sig_info_valid = TRUE;
+ signal_msg_buf.wcdma_sig_info.rssi = rssi_convert_to_dBm(net_data[1]);
+ signal_msg_buf.wcdma_sig_info.ecio = ecno_convert_to_dB(net_data[5]);
+ }
+
+ if(lynq_func_cb_handle.handlerPtr != NULL)
+ {
+ lynq_func_cb_handle.handlerPtr(qser_h_nw, NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG, (void *)&signal_msg_buf, sizeof(QSER_NW_SINGNAL_EVENT_IND_T), lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(qser_h_nw, NW_IND_VOICE_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(qser_h_nw, NW_IND_DATA_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(qser_h_nw, NW_IND_IMS_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ }
+ }
+ else
+ {
+ LOGD("qser_nw_state_change_cb : NULL");
+ }
+
+}
+
+static uint8 lynq_net_pre_change(bool mbtk_2_lynq,int net_mode)
+{
+ uint8 mbtk_net_pre = 0xFF;
+
+#if 0
+ 此参数表在别处使用
+ E_QSER_NW_RADIO_TECH_TD_SCDMA = 1, Y3 1
+ E_QSER_NW_RADIO_TECH_GSM = 2, /**< GSM; only supports voice. */ YL2 0
+ E_QSER_NW_RADIO_TECH_HSPAP = 3, /**< HSPA+. */ 3 1
+ E_QSER_NW_RADIO_TECH_LTE = 4, /**< LTE. */ 4 5
+ E_QSER_NW_RADIO_TECH_EHRPD = 5, /**< EHRPD. */ 3 1
+ E_QSER_NW_RADIO_TECH_EVDO_B = 6, /**< EVDO B. */ D3 1
+ E_QSER_NW_RADIO_TECH_HSPA = 7, /**< HSPA. */ 3 1
+ E_QSER_NW_RADIO_TECH_HSUPA = 8, /**< HSUPA. */ 3.5 1
+ E_QSER_NW_RADIO_TECH_HSDPA = 9, /**< HSDPA. */ 3.5 1
+ E_QSER_NW_RADIO_TECH_EVDO_A = 10, /**< EVDO A. */ D3 1
+ E_QSER_NW_RADIO_TECH_EVDO_0 = 11, /**< EVDO 0. */ D3 1
+ E_QSER_NW_RADIO_TECH_1xRTT = 12, /**< 1xRTT. */ 2 0
+ E_QSER_NW_RADIO_TECH_IS95B = 13, /**< IS95B. */ 3 0
+ E_QSER_NW_RADIO_TECH_IS95A = 14, /**< IS95A. */ 3 0
+ E_QSER_NW_RADIO_TECH_UMTS = 15, /**< UMTS. */ L3 1
+ E_QSER_NW_RADIO_TECH_EDGE = 16, /**< EDGE. */ 2.75 0
+ E_QSER_NW_RADIO_TECH_GPRS = 17, /**< GPRS. */ 2.5 0
+ E_QSER_NW_RADIO_TECH_NONE = 18 /**< No technology selected. */
+#endif
+ /*
+ 0 : GSM only
+ 1 : UMTS only
+ 2 : GSM/UMTS(auto)
+ 3 : GSM/UMTS(GSM preferred)
+ 4 : GSM/UMTS(UMTS preferred)
+ 5 : LTE only
+ 6 : GSM/LTE(auto)
+ 7 : GSM/LTE(GSM preferred)
+ 8 : GSM/LTE(LTE preferred)
+ 9 : UMTS/LTE(auto)
+ 10 : UMTS/LTE(UMTS preferred)
+ 11 : UMTS/LTE(LTE preferred)
+ 12 : GSM/UMTS/LTE(auto)
+ 13 : GSM/UMTS/LTE(GSM preferred)
+ 14 : GSM/UMTS/LTE(UMTS preferred)
+ 15 : GSM/UMTS/LTE(LTE preferred)
+ */
+
+ if(mbtk_2_lynq)
+ {
+ switch(net_mode)
+ {
+ //使用之前set的tmp_mode的值来进行回显get
+ case QSER_NW_MODE_GSM:
+ mbtk_net_pre = QSER_NW_MODE_GSM;
+ break;
+ case QSER_NW_MODE_WCDMA:
+ mbtk_net_pre = QSER_NW_MODE_WCDMA;
+ break;
+ case QSER_NW_MODE_CDMA:
+ mbtk_net_pre = QSER_NW_MODE_CDMA;
+ break;
+ case QSER_NW_MODE_EVDO:
+ mbtk_net_pre = QSER_NW_MODE_EVDO;
+ break;
+ case QSER_NW_MODE_LTE:
+ mbtk_net_pre = QSER_NW_MODE_LTE;
+ break;
+ case QSER_NW_MODE_TDSCDMA:
+ mbtk_net_pre = QSER_NW_MODE_TDSCDMA;
+ break;
+ default:
+ mbtk_net_pre = 0xFF;
+ break;
+ }
+ }
+ else
+ {
+ if(QSER_NW_MODE_GSM == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_GSM_ONLY;
+ }
+ else if(QSER_NW_MODE_WCDMA == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_ONLY;
+ }
+ else if(QSER_NW_MODE_LTE == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_LTE_ONLY;
+ }
+ else if((QSER_NW_MODE_GSM | QSER_NW_MODE_WCDMA) == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+ }
+ else if((QSER_NW_MODE_WCDMA | QSER_NW_MODE_LTE) == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_LTE_LTE_PREF;
+ }
+ else if((QSER_NW_MODE_GSM | QSER_NW_MODE_LTE) == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_GSM_LTE_LTE_PREF;
+ }
+ else if((QSER_NW_MODE_GSM | QSER_NW_MODE_WCDMA | QSER_NW_MODE_LTE) == net_mode)
+ {
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF;
+ }
+ else
+ {
+ mbtk_net_pre = 0xFF;
+ }
+ }
+ return mbtk_net_pre;
+}
+
+int qser_nw_client_init(nw_client_handle_type *ph_nw)
+{
+ //UNUSED(ph_voice);
+ if(ph_nw == NULL)
+ {
+ LOGE("[qser_nw] ph_nw is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(NULL == qser_info_handle)
+ {
+ qser_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+ if(NULL == qser_info_handle)
+ {
+ LOGE("[qser_nw] qser_info_handle get fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_nw] qser_info_handle has init.");
+ *ph_nw = qser_h_nw;
+ return QSER_RESULT_FAIL;
+ }
+ *ph_nw = qser_h_nw;
+
+ LOGE("[qser_nw] qser_info_handle get success.");
+
+
+ return QSER_RESULT_SUCCESS;
+
+}
+
+
+int qser_nw_client_deinit(nw_client_handle_type h_nw)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle)
+ {
+ int ret = mbtk_ril_close(MBTK_AT_PORT_DEF);;
+ if(ret)
+ {
+ LOGE("[qser_nw] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle = NULL;
+ lynq_func_cb_handle.handlerPtr = NULL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_nw] handle not inited.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+
+int qser_nw_set_config(nw_client_handle_type h_nw,QSER_NW_CONFIG_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("pt_info == NULL.");
+ return -1;
+ }
+
+ roaming_pref = pt_info->roaming_pref;
+
+ mbtk_band_info_t band;
+ memset(&band, 0, sizeof(mbtk_band_info_t));
+ tmp_mode = pt_info->preferred_nw_mode;//临时保存一下原本的mode
+
+ //printf("tmp_mode = [%llu]",tmp_mode);
+ band.net_pref = lynq_net_pre_change(FALSE, pt_info->preferred_nw_mode);
+ LOGI("band.net_pref = [%d] ",band.net_pref);
+
+ if(band.net_pref == 0xFF)
+ {
+ LOGE("lynq_net_pre_change() fail.");
+ return -1;
+ }
+
+ if(mbtk_current_band_set(qser_info_handle, &band))
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_nw_get_operator_name(nw_client_handle_type h_nw, QSER_NW_OPERATOR_NAME_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("pt_info == NULL.");
+ return -1;
+ }
+
+ char OperatorFN[128];
+ char OperatorSH[128];
+ char MccMnc[128];
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(qser_info_handle, &net) && net.plmn > 0)
+ {
+ // printf("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
+ int i = 0;
+ while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
+ {
+ if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(lynq_operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(OperatorFN, "UNKNOWN");
+ strcpy(OperatorSH, "UNKNOWN");
+ sprintf(MccMnc, "%d", net.plmn);
+ }
+ else
+ {
+ strcpy(OperatorFN, (char*)lynq_operator_mcc_mnc[i].lynq_operator_l);
+ strcpy(OperatorSH, (char*)lynq_operator_mcc_mnc[i].lynq_operator_s);
+ sprintf(MccMnc, "%d", lynq_operator_mcc_mnc[i].lynq_mcc_mnc);
+ }
+ memset(pt_info->long_eons,0,128);
+ memcpy(pt_info->long_eons,lynq_operator_mcc_mnc[i].lynq_operator_l,strlen((char*)lynq_operator_mcc_mnc[i].lynq_operator_l));
+ memset(pt_info->short_eons,0,128);
+ memcpy(pt_info->short_eons,lynq_operator_mcc_mnc[i].lynq_operator_s,strlen((char*)lynq_operator_mcc_mnc[i].lynq_operator_s));
+ memset(pt_info->mcc,0,4);
+ memset(pt_info->mnc,0,4);
+ sprintf(pt_info->mcc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
+ sprintf(pt_info->mnc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
+ //pt_info->act;
+ return 0;
+ }
+
+ return -1;
+}
+
+int qser_nw_get_reg_status(nw_client_handle_type h_nw, QSER_NW_REG_STATUS_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("pt_info == NULL.");
+ return -1;
+ }
+
+ /*VOICE/DATA/IMS*/
+ mbtk_net_reg_info_t reg;
+ int err = mbtk_net_reg_get(qser_info_handle, ®);
+ if(err)
+ {
+ LOGE("mbtk_net_reg_get fail.");
+ return -1;
+ }
+ else
+ {
+ memset(pt_info, 0x0, sizeof(QSER_NW_REG_STATUS_INFO_T));
+
+
+ char OperatorFN[128];
+ char OperatorSH[128];
+ char MccMnc[128];
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(qser_info_handle, &net) && net.plmn > 0)
+ {
+ // printf("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
+ int i = 0;
+ while(i < ARRAY_SIZE(lynq_operator_mcc_mnc))
+ {
+ if(lynq_operator_mcc_mnc[i].lynq_mcc_mnc == net.plmn)
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(lynq_operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(OperatorFN, "UNKNOWN");
+ strcpy(OperatorSH, "UNKNOWN");
+ sprintf(MccMnc, "%d", net.plmn);
+ }
+ else
+ {
+ sprintf(MccMnc, "%d", lynq_operator_mcc_mnc[i].lynq_mcc_mnc);
+ }
+ sprintf(pt_info->data_registration_details_3gpp.mcc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
+ sprintf(pt_info->data_registration_details_3gpp.mnc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
+ sprintf(pt_info->voice_registration_details_3gpp.mcc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);
+ sprintf(pt_info->voice_registration_details_3gpp.mnc, "%d", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);
+ //pt_info->act;
+ }
+
+ //暂时未知是否其他也被使用,现根据ql模块的传输情况,
+ //只配置3gpp,涉及call,data状态没有对应的匹配的就没有赋值
+
+ pt_info->voice_registration_valid = TRUE;
+ pt_info->voice_registration.deny_reason = 0;
+ pt_info->voice_registration.roaming = 0;
+ pt_info->voice_registration.tech_domain = 0;
+
+
+ pt_info->data_registration_valid = TRUE;
+ pt_info->data_registration.deny_reason = 0;
+ pt_info->data_registration.roaming = 0;
+ pt_info->data_registration.tech_domain = 0;
+
+ if (reg.call_state == 1 || reg.call_state == 5)
+ {
+ pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_FULL;
+ }
+ else if (reg.call_state == 0 || reg.call_state == 2 || reg.call_state == 3 || reg.call_state == 4)
+ {
+ pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+ }
+
+ if (reg.data_state == 1 || reg.data_state == 5)
+ {
+ pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_FULL;
+ }
+ else if (reg.data_state == 0 || reg.data_state == 2 || reg.data_state == 3 || reg.data_state == 4)
+ {
+ pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+ }
+
+
+ pt_info->voice_registration_details_3gpp_valid = TRUE;
+ pt_info->voice_registration_details_3gpp.lac = reg.lac;
+ pt_info->voice_registration_details_3gpp.cid = reg.ci;
+ //补位填0 or 1
+ pt_info->voice_registration_details_3gpp.tech_domain = 1;
+ pt_info->voice_registration_details_3gpp.roaming = 0;
+ pt_info->voice_registration_details_3gpp.forbidden = 0;
+ pt_info->voice_registration_details_3gpp.psc = 0;
+ pt_info->voice_registration_details_3gpp.tac = 0;
+
+ pt_info->data_registration_details_3gpp_valid = TRUE;
+ pt_info->data_registration_details_3gpp.lac = reg.lac;
+ pt_info->data_registration_details_3gpp.cid = reg.ci;
+ //补位填0 or 1
+ pt_info->data_registration_details_3gpp.tech_domain = 1;
+ pt_info->data_registration_details_3gpp.roaming = 0;
+ pt_info->data_registration_details_3gpp.forbidden = 0;
+ pt_info->data_registration_details_3gpp.psc = 0;
+ pt_info->data_registration_details_3gpp.tac = 0;
+
+
+ pt_info->voice_registration_details_3gpp2_valid = FALSE;
+ //pt_info->voice_registration_details_3gpp2
+
+ pt_info->data_registration_details_3gpp2_valid = FALSE;
+ //pt_info->data_registration_details_3gpp2
+
+
+ switch(reg.type)
+ {
+ case MBTK_RADIO_TECH_GSM:
+ case MBTK_RADIO_TECH_GSM_COMPACT:
+ case MBTK_RADIO_TECH_GSM_EGPRS:
+ case MBTK_RADIO_TECH_UTRAN_HSPA:
+ {
+ pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_HSPA;
+ pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_HSPA;
+ pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_HSPA;
+ pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_HSPA;
+ break;
+ }
+ case MBTK_RADIO_TECH_UTRAN:
+ case MBTK_RADIO_TECH_UTRAN_HSDPA:
+ case MBTK_RADIO_TECH_UTRAN_HSUPA:
+ case MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA:
+ {
+ pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+ pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+ pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+ pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+ break;
+ }
+ case MBTK_RADIO_TECH_E_UTRAN:
+ {
+ pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+ pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+ pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+ pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+ break;
+ }
+ default:
+ {
+ pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+ pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+ pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+ pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+ pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+ pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int qser_nw_get_signal_strength(nw_client_handle_type h_nw,QSER_NW_SIGNAL_STRENGTH_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("pt_info == NULL.");
+ return -1;
+ }
+
+ int ret;
+ mbtk_signal_info_t signal;
+ ret = mbtk_net_signal_get(qser_info_handle, &signal);
+ if(ret != 0) {
+ LOGE("mbtk_net_signal_get fail.");
+ return -1;
+ }
+ else
+ {
+ memset(pt_info, 0x0, sizeof(QSER_NW_SIGNAL_STRENGTH_INFO_T));
+ if(signal.type == MBTK_RADIO_TECH_GSM || signal.type == MBTK_RADIO_TECH_GSM_COMPACT || \
+ signal.type == MBTK_RADIO_TECH_GSM_EGPRS) //GSM
+ {
+ pt_info->gsm_sig_info_valid = TRUE;
+ pt_info->gsm_sig_info.rssi = rssi_convert_to_dBm(signal.rssi);
+ }
+ else if(signal.type == MBTK_RADIO_TECH_E_UTRAN) //LTE
+ {
+ pt_info->lte_sig_info_valid = TRUE;
+ pt_info->lte_sig_info.rsrp = rsrp_convert_to_dBm(signal.rsrp);
+ pt_info->lte_sig_info.rsrq = rsrq_convert_to_dB(signal.rsrq);
+ pt_info->lte_sig_info.snr = 0x7FFF;//->MBTK接口无该参数(对应参数为rssnr,该值INT_MAX:0x7FFFFFFFF表示无效值),写死值为0x7FFFFFFFF
+ pt_info->lte_sig_info.rssi = rssi_convert_to_dBm(signal.rssi);
+ }
+ else if (signal.type == MBTK_RADIO_TECH_UTRAN || signal.type == MBTK_RADIO_TECH_UTRAN_HSDPA || \
+ signal.type == MBTK_RADIO_TECH_UTRAN_HSUPA || signal.type == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA || \
+ signal.type == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
+ {
+ pt_info->wcdma_sig_info_valid = TRUE;
+ pt_info->wcdma_sig_info.rssi = rssi_convert_to_dBm(signal.rssi);
+ pt_info->wcdma_sig_info.ecio = ecno_convert_to_dB(signal.ecno);
+ }
+ else
+ {
+ return -1;
+ }
+ /*
+ pt_info->gsm_sig_info_valid = 1//signal.gw_sig_valid;
+ pt_info->gsm_sig_info.rssi = signal.rssi;//signal.rssi-110;
+ pt_info->wcdma_sig_info_valid = 1//signal.wcdma_sig_valid;
+ pt_info->wcdma_sig_info.rssi = signal.rscp;//signal.wcdma_signalstrength-110;
+ pt_info->wcdma_sig_info.ecio = //signal.ecno/5;
+ pt_info->tdscdma_sig_info_valid = 0;
+ pt_info->lte_sig_info_valid = 1//signal.lte_sig_valid;
+ pt_info->lte_sig_info.rssi = -125;//signal.lte_signalstrength-110;
+ pt_info->lte_sig_info.rsrp = signal.rsrp;//signal.rsrp*(-1);
+ pt_info->lte_sig_info.rsrq = signal.rsrq;//signal.rsrq*(-1);
+ pt_info->lte_sig_info.snr = 0x7FFFFFFFF;//signal.rssnr;
+ pt_info->cdma_sig_info_valid = 0;
+ pt_info->hdr_sig_info_valid = 0;
+ //mbtk 无nr
+ pt_info->nr_sig_info_valid = 0//signal.nr_sig_valid;
+ pt_info->nr_sig_info.ssRsrp = 0//signal.ssRsrp;
+ pt_info->nr_sig_info.ssRsrq = 0//signal.ssRsrq;
+ pt_info->nr_sig_info.ssSinr = 0//signal.ssSinr;
+ pt_info->nr_sig_info.csiRsrp = 0//signal.csiRsrp;
+ pt_info->nr_sig_info.csiRsrq = 0//signal.csiRsrq;
+ pt_info->nr_sig_info.csiSinr = 0//signal.csiSinr;
+ */
+ }
+
+ return 0;
+}
+
+int qser_nw_add_rx_msg_handler (nw_client_handle_type h_nw, QSER_NW_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ lynq_func_cb_handle.handlerPtr = handlerPtr;
+ lynq_func_cb_handle.contextPtr = contextPtr;
+
+ mbtk_signal_state_change_cb_reg(qser_signal_state_change_cb);
+
+ return 0;
+}
+
+int qser_nw_set_oos_config (nw_client_handle_type h_nw, QSER_NW_OOS_CONFIG_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if (pt_info == NULL)
+ {
+ LOGE("QSER_NW_OOS_CONFIG_INFO_T NULL");
+ return -1;
+ }
+
+ uint32 oosPhase_0, oosPhase_1, oosPhase_2;
+ char tmp_type;
+ mbtk_ril_oos_info_t oos_info;
+
+ memset(&oos_info, 0x00, sizeof(mbtk_ril_oos_info_t));
+
+
+ tmp_type = pt_info->type;
+
+ if (tmp_type == QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN)
+ {//如果没有配置对应的值,例如,10,20
+ //oosPhase_2这个位置没有配置,则使用默认值20,既不限制次数的5s进行一次扫描
+ //同理oosPhase_0,oosPhase_1这个位置没有配置,则使用默认值5,10,既限制次数5次的5s,10s进行一次扫描
+ //输入多少配置多少,可以缺省使用默认值
+ if (pt_info->u.full_band_scan_info.t_min < 0 || pt_info->u.full_band_scan_info.t_step < 0 || pt_info->u.full_band_scan_info.t_max < 0)
+ {
+ LOGE("qser_nw_set_oos_config set time < 0 ");
+ return -1;
+ }
+ else if ((pt_info->u.full_band_scan_info.t_min > 0 && pt_info->u.full_band_scan_info.t_min <= 255) && pt_info->u.full_band_scan_info.t_step == 0 && pt_info->u.full_band_scan_info.t_max == 0)
+ {
+ oosPhase_0 = pt_info->u.full_band_scan_info.t_min;
+ oos_info.state = 1;
+ oos_info.oosPhase[0] = oosPhase_0;
+ }
+ else if ((pt_info->u.full_band_scan_info.t_min > 0 && pt_info->u.full_band_scan_info.t_min <= 255) && (pt_info->u.full_band_scan_info.t_step > 0 && pt_info->u.full_band_scan_info.t_step <= 255) && pt_info->u.full_band_scan_info.t_max == 0)
+ {
+ oosPhase_0 = pt_info->u.full_band_scan_info.t_min;
+ oosPhase_1 = pt_info->u.full_band_scan_info.t_step;
+ oos_info.state = 1;
+ oos_info.oosPhase[0] = oosPhase_0;
+ oos_info.oosPhase[1] = oosPhase_1;
+ }
+ else if ((pt_info->u.full_band_scan_info.t_min > 0 && pt_info->u.full_band_scan_info.t_min <= 255) && (pt_info->u.full_band_scan_info.t_step > 0 && pt_info->u.full_band_scan_info.t_step <= 255) && (pt_info->u.full_band_scan_info.t_max > 0 && pt_info->u.full_band_scan_info.t_max <= 255))
+ {
+ oosPhase_0 = pt_info->u.full_band_scan_info.t_min;
+ oosPhase_1 = pt_info->u.full_band_scan_info.t_step;
+ oosPhase_2 = pt_info->u.full_band_scan_info.t_max;
+ oos_info.state = 1;
+ oos_info.oosPhase[0] = oosPhase_0;
+ oos_info.oosPhase[1] = oosPhase_1;
+ oos_info.oosPhase[2] = oosPhase_2;
+ }
+ else if (pt_info->u.full_band_scan_info.t_min == 0 && pt_info->u.full_band_scan_info.t_step == 0 && pt_info->u.full_band_scan_info.t_max == 0)
+ {
+ oos_info.state = 0;
+ }
+ else
+ {
+ LOGE("qser_nw_set_oos_config set Format err");
+ return -1;
+ }
+
+ int err = mbtk_oos_set(qser_info_handle, &oos_info);
+ if (err != 0)
+ {
+ LOGE("qser_nw_set_oos_config mbtk_oos_set err");
+ return -1;
+ }
+ }
+ else if (tmp_type == QSER_NW_OOS_CFG_TYPE_FAST_SCAN)
+ {
+ LOGE("Not currently supported");
+ return -1;
+ }
+ else
+ {
+ LOGE("type is error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_nw_get_oos_config (nw_client_handle_type h_nw, QSER_NW_OOS_CONFIG_INFO_T *pt_info)
+{
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if (pt_info == NULL)
+ {
+ LOGE("QSER_NW_OOS_CONFIG_INFO_T NULL");
+ return -1;
+ }
+
+ mbtk_ril_oos_info_t oos_info;
+// uint32 oosPhase_0, oosPhase_1, oosPhase_2;
+// char cmd[100] = {0};
+
+ memset(&oos_info, 0x00, sizeof(mbtk_ril_oos_info_t));
+
+ int err = mbtk_oos_get(qser_info_handle, &oos_info);
+ if (err != 0)
+ {
+ LOGE("qser_nw_get_oos_config mbtk_oos_get err ");
+ return -1;
+ }
+/*
+ printf("oos_info.mode =[%d] \n",oos_info.mode);
+ printf("oos_info.1 =[%d] \n",oos_info.oosPhase[0]);
+ printf("oos_info.2 =[%d] \n",oos_info.oosPhase[1]);
+ printf("oos_info.3 =[%d] \n",oos_info.oosPhase[2]);
+*/
+ if(oos_info.state == 0)//关闭状态
+ {
+ pt_info->u.full_band_scan_info.t_min = 0;
+ pt_info->u.full_band_scan_info.t_step = 0;
+ pt_info->u.full_band_scan_info.t_max = 0;
+ }
+ else
+ {
+ pt_info->u.full_band_scan_info.t_min = (int)oos_info.oosPhase[0];
+ pt_info->u.full_band_scan_info.t_step = (int)oos_info.oosPhase[1];
+ pt_info->u.full_band_scan_info.t_max = (int)oos_info.oosPhase[2];
+ }
+ pt_info->type = QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN;
+
+
+ if (pt_info == NULL)
+ {
+ LOGE("qser_nw_get_oos_config pt_info is null ");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_nw_set_rf_mode (nw_client_handle_type h_nw, E_QSER_NW_RF_MODE_TYPE_T rf_mode)
+{
+ //UNUSED(h_nw);
+ //UNUSED(rf_mode);
+ int ret;
+
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+/*
+ if (rf_mode == 4)
+ {
+ printf("Flight Mode no Support Now\n");
+ return -1;
+ }
+*/
+ if (rf_mode != 4 && rf_mode != 0 && rf_mode != 1)
+ {
+ LOGE("mode is error!");
+ return -1;
+ }
+
+ ret = mbtk_radio_state_set(qser_info_handle, rf_mode, 0);
+
+ //ret = mbtk_radio_state_set(qser_info_handle, rf_mode);
+ if (ret != 0)
+ {
+ LOGE("mbtk_radio_state_set fail.");
+ return -1;
+ }
+ else
+ {
+ LOGI("qser_nw_set_rf_mode is success\n");
+ }
+
+ return 0;
+}
+
+int qser_nw_get_rf_mode (nw_client_handle_type h_nw, E_QSER_NW_RF_MODE_TYPE_T *rf_mode)
+{
+ //UNUSED(h_nw);
+ //UNUSED(rf_mode);
+ int ret;
+ mbtk_radio_state_enum tmp_rf;
+
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_radio_state_get(qser_info_handle, &tmp_rf);
+
+ //ret = mbtk_radio_state_get(qser_info_handle, &tmp_rf);
+ if (ret != 0)
+ {
+ LOGE("mbtk_radio_state_get fail.");
+ return -1;
+ }
+ else
+ {
+ LOGI("qser_nw_get_rf_mode is success\n");
+ *rf_mode = tmp_rf;
+ }
+
+
+ return 0;
+}
+
+int qser_nw_set_ims_enable(nw_client_handle_type h_nw, E_QSER_NW_IMS_MODE_TYPE_T ims_mode)
+{
+ int ret = 0;
+
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_volte_state_set(qser_info_handle, ims_mode);
+ if (ret != 0)
+ {
+ LOGE("mbtk_net_ims_set fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_nw_get_ims_reg_status(nw_client_handle_type h_nw, QSER_NW_IMS_REG_STATUS_INFO_T *pt_info)
+{
+ int ret = 0;
+ int tmp_pt;
+
+ if(h_nw != qser_h_nw)
+ {
+ LOGE("[qser_nw] h_nw is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_volte_state_get(qser_info_handle, &tmp_pt);
+ if (ret != 0)
+ {
+ LOGE("mbtk_net_ims_get fail.");
+ return -1;
+ }
+
+ if (tmp_pt == 0)
+ pt_info->registration_state = E_QSER_NW_IMS_SERVICE_NONE;
+ else if (tmp_pt == 1)
+ pt_info->registration_state = E_QSER_NW_IMS_SERVICE_REGISTERED;
+ else
+ {
+ LOGE("mbtk_net_ims_get value error fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_sim.c b/mbtk/liblynq_lib_rilv2/lynq_sim.c
new file mode 100755
index 0000000..31a3b46
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_sim.c
@@ -0,0 +1,735 @@
+#include "lynq_qser_sim.h"
+#include "mbtk_type.h"
+#include "mbtk_ril_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+
+#define QSER_IMEI_SV_VERSION "01"
+
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+static mbtk_ril_handle* qser_info_handle;
+static const uint qser_h_sim = 0x5F6F7F8F;
+static QSER_SIM_RxMsgHandlerFunc_t qser_sim_state_cb = NULL;
+static bool qser_sim_cb_state = false;
+/****************************VARIABLE***************************************/
+
+/******************************FUNC*****************************************/
+void qser_sim_state_change_cb(const void* data, int data_len)
+{
+ //uint8 *ptr = (uint8*)data;
+ mbtk_ril_sim_state_info_t* ptr_state = (mbtk_ril_sim_state_info_t*)data;
+ LOGE("[qser_sim] SIM state : %d\n", ptr_state->sim_state);
+ QSER_SIM_CARD_STATUS_INFO_T qser_sim_statue = {0};
+ if(ptr_state->sim_state == 0)
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_ABSENT;
+ }
+ else if(ptr_state->sim_state == 1)
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_PRESENT;
+ }
+ else if(ptr_state->sim_state == 18)
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_ABSENT;
+ }
+ else
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_UNKNOWN;
+ }
+ if(qser_sim_state_cb != NULL)
+ {
+ qser_sim_state_cb(&qser_sim_statue);
+ }
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int qser_sim_client_init(sim_client_handle_type *ph_sim)
+{
+ //UNUSED(ph_voice);
+ if(ph_sim == NULL)
+ {
+ LOGE("[qser_sim] ph_sim is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(NULL == qser_info_handle)
+ {
+ qser_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+ if(NULL == qser_info_handle)
+ {
+ LOGE("[qser_sim] qser_info_handle get fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_sim] qser_info_handle has init.");
+ *ph_sim = qser_h_sim;
+ return QSER_RESULT_FAIL;
+ }
+ *ph_sim = qser_h_sim;
+
+ LOGE("[qser_sim] qser_info_handle get success.");
+
+
+ return QSER_RESULT_SUCCESS;
+
+}
+
+
+
+int qser_sim_getimsi(sim_client_handle_type h_sim, QSER_SIM_APP_ID_INFO_T *pt_info,char *imsi,size_t imsiLen)
+{
+ //UNUSED(h_sim);
+ UNUSED(pt_info);
+ //UNUSED(imsi);
+ //UNUSED(imsiLen);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(imsi == NULL || imsiLen < 15)
+ {
+ LOGE("[qser_sim] imsi is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ memset(imsi,0,imsiLen);
+ int err = mbtk_imsi_get(qser_info_handle, imsi);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_imsi_get is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(strlen(imsi) > imsiLen)
+ {
+ LOGE("[qser_sim] get datalength out of range.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_geticcid(sim_client_handle_type h_sim,QSER_SIM_SLOT_ID_TYPE_T simId,char *iccid, size_t iccidLen)
+{
+ //UNUSED(h_sim);
+ UNUSED(simId);
+ //UNUSED(iccid);
+ //UNUSED(iccidLen);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(iccid == NULL || iccidLen < QSER_SIM_ICCID_LEN_MAX)
+ {
+ LOGE("[qser_sim] iccid is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ memset(iccid, 0, iccidLen);
+ int err = mbtk_iccid_get(qser_info_handle, iccid);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_iccid_get is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(strlen(iccid) > iccidLen)
+ {
+ LOGE("[qser_sim] get datalength out of range.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_getphonenumber(sim_client_handle_type h_sim,QSER_SIM_APP_ID_INFO_T *pt_info, char*phone_num, size_t phoneLen)
+{
+ //UNUSED(h_sim);
+ UNUSED(pt_info);
+ //UNUSED(phone_num);
+ //UNUSED(phoneLen);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(phone_num == NULL || phoneLen < 11)
+ {
+ LOGE("[qser_sim] phone_num is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ memset(phone_num, 0, phoneLen);
+ int err = mbtk_phone_number_get(qser_info_handle, phone_num);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_phone_number_get is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(strlen(phone_num) > phoneLen)
+ {
+ LOGE("[qser_sim] get datalength out of range.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_verifypin(sim_client_handle_type h_sim,QSER_SIM_VERIFY_PIN_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(pt_info);
+ mbtk_sim_lock_info_t info = {0};
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PIN;
+ memcpy(info.pin1, pt_info->pin_value, strlen(pt_info->pin_value));
+
+ int err = mbtk_sim_lock_set(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_verify_pin is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_changepin(sim_client_handle_type h_sim,QSER_SIM_CHANGE_PIN_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(pt_info);
+ mbtk_sim_lock_info_t info = {0};
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ info.type = MBTK_SIM_LOCK_TYPE_CHANGE;
+ memcpy(info.pin1, pt_info->old_pin_value, strlen(pt_info->old_pin_value));
+ memcpy(info.pin2, pt_info->new_pin_value, strlen(pt_info->new_pin_value));
+
+ int err = mbtk_sim_lock_set(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_change_pin is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_unblockpin(sim_client_handle_type h_sim, QSER_SIM_UNBLOCK_PIN_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(pt_info);
+ mbtk_sim_lock_info_t info = {0};
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PUK;
+ memcpy(info.pin1, pt_info->new_pin_value, strlen(pt_info->new_pin_value));
+ memcpy(info.puk, pt_info->puk_value, strlen(pt_info->puk_value));
+
+ int err = mbtk_sim_lock_set(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_unlock_pin is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_enablepin(sim_client_handle_type h_sim, QSER_SIM_ENABLE_PIN_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(pt_info);
+ mbtk_sim_lock_info_t info = {0};
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ info.type = MBTK_SIM_LOCK_TYPE_ENABLE;
+ memcpy(info.pin1, pt_info->pin_value, strlen(pt_info->pin_value));
+
+ int err = mbtk_sim_lock_set(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_enable_pin is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_disablepin(sim_client_handle_type h_sim, QSER_SIM_DISABLE_PIN_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(pt_info);
+ mbtk_sim_lock_info_t info = {0};
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ info.type = MBTK_SIM_LOCK_TYPE_DISABLE;
+ memcpy(info.pin1, pt_info->pin_value, strlen(pt_info->pin_value));
+
+ int err = mbtk_sim_lock_set(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_enable_pin is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_getcardstatus(sim_client_handle_type h_sim,QSER_SIM_SLOT_ID_TYPE_T simId,QSER_SIM_CARD_STATUS_INFO_T *pt_info)
+{
+ //UNUSED(h_sim);
+ //UNUSED(simId);
+ //UNUSED(pt_info);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_info == NULL)
+ {
+ LOGE("[qser_sim] pt_info is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_sim_state_enum sim;
+ mbtk_sim_card_type_enum sim_card_type;
+ mbtk_pin_puk_last_times_t qser_last_times = {0};
+ int err = mbtk_sim_state_get(qser_info_handle, &sim);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ LOGE("[qser_sim] sim = %d.", sim);
+ memset(pt_info, 0x0, sizeof(QSER_SIM_CARD_STATUS_INFO_T));
+ switch (sim)
+ {
+ case 0: //ABSENT
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT;
+ break;
+ case 1: //NOT READY
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT;
+ break;
+ case 2: //READY
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT;
+ break;
+ case 3: //SIM PIN
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT;
+ break;
+ case 4: //SIM PUK
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT;
+ break;
+ case 5: //NETWORK
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_ERROR_SIM_TECHNICAL_PROBLEMS;
+ break;
+ default:
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_UNKNOWN;
+ break;
+ }
+ }
+
+ err = mbtk_sim_type_get(qser_info_handle, &sim_card_type);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(sim_card_type == 0 || sim_card_type == 2)
+ pt_info->e_card_type = QSER_SIM_CARD_TYPE_ICC;
+ else if(sim_card_type == 1 || sim_card_type == 3)
+ pt_info->e_card_type = QSER_SIM_CARD_TYPE_UICC;
+ else
+ pt_info->e_card_type = QSER_SIM_CARD_TYPE_UNKNOWN;
+ }
+
+ err = mbtk_sim_lock_retry_times_get(qser_info_handle, &qser_last_times);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_sim_state_get fail [err = %d].", err);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ pt_info->card_app_info.app_3gpp.pin1_num_retries = qser_last_times.p1_retry;
+ pt_info->card_app_info.app_3gpp.pin2_num_retries = qser_last_times.p2_retry;
+ pt_info->card_app_info.app_3gpp.puk1_num_retries = qser_last_times.puk1_retry;
+ pt_info->card_app_info.app_3gpp.puk2_num_retries = qser_last_times.puk2_retry;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_getimei(sim_client_handle_type h_sim, char *imei)
+{
+ //UNUSED(h_sim);
+ //UNUSED(imei);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(imei == NULL)
+ {
+ LOGE("[qser_sim] imei is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int err = mbtk_imei_get(qser_info_handle, imei);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_imei_get Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_get_imei_and_sv(sim_client_handle_type h_sim,char *imei, char*sv)
+{
+ //UNUSED(h_sim);
+ //UNUSED(imei);
+ //UNUSED(sv);
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(imei == NULL || sv == NULL)
+ {
+ LOGE("[qser_sim] param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int err = mbtk_imei_get(qser_info_handle, imei);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_imei_get Error: %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+
+ memcpy(sv, QSER_IMEI_SV_VERSION, strlen(QSER_IMEI_SV_VERSION));
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_reset_modem(sim_client_handle_type h_sim)
+{
+ //UNUSED(h_sim);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ for(int cid =0; cid < MBTK_APN_CID_MAX; cid++)
+ {
+ mbtk_data_call_stop(qser_info_handle, cid, 1);
+ }
+
+ mbtk_radio_state_enum radio = MBTK_RADIO_STATE_MINI_FUNC;
+ int reset = 0;
+ int err = mbtk_radio_state_set(qser_info_handle, radio, reset);
+
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+
+ radio = MBTK_RADIO_STATE_FULL_FUNC;
+ err = mbtk_radio_state_set(qser_info_handle, radio, reset);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_get_version(sim_client_handle_type h_sim, char *buf)
+{
+ //UNUSED(h_sim);
+ //UNUSED(buf);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(buf == NULL)
+ {
+ LOGE("[qser_sim] buf is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int err = mbtk_version_get(qser_info_handle, buf);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_version_get Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_reset_sim(sim_client_handle_type h_sim)
+{
+ //UNUSED(h_sim);
+
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_radio_state_enum radio = MBTK_RADIO_STATE_DIS_SIM;
+ int reset = 0;
+ int err = mbtk_radio_state_set(qser_info_handle, radio, reset);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+
+ radio = MBTK_RADIO_STATE_FULL_FUNC;
+ err = mbtk_radio_state_set(qser_info_handle, radio, reset);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_sim_addrxmsghandler(QSER_SIM_RxMsgHandlerFunc_t handlerPtr)
+{
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_sim] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(handlerPtr == NULL)
+ {
+ LOGE("[qser_sim] param is NULL.");
+ qser_sim_state_cb = NULL;
+ return QSER_RESULT_SUCCESS;
+ }
+
+ qser_sim_state_cb = handlerPtr;
+ if(!qser_sim_cb_state)
+ {
+ int ret = mbtk_sim_state_change_cb_reg(qser_sim_state_change_cb);
+ if(ret != 0)
+ {
+ LOGE("[qser_sim] set cb fail.");
+ qser_sim_state_cb = NULL;
+ return QSER_RESULT_FAIL;
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+
+int qser_sim_client_deinit(sim_client_handle_type h_sim)
+{
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle)
+ {
+ int ret = mbtk_ril_close(MBTK_AT_PORT_DEF);;
+ if(ret)
+ {
+ LOGE("[qser_sim] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle = NULL;
+ qser_sim_state_cb = NULL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_sim] handle not inited.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+
+/****************************API***************************************/
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_sleep.c b/mbtk/liblynq_lib_rilv2/lynq_sleep.c
new file mode 100755
index 0000000..91a8e28
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_sleep.c
@@ -0,0 +1,326 @@
+#include "lynq-qser-autosuspend.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/epoll.h>
+#include <linux/input.h>
+
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "mbtk_power.h"
+#include "mbtk_lpm.h"
+#include "mbtk_sleep.h"
+#include "mbtk_utils.h"
+#include "mbtk_ril_api.h"
+
+
+static bool call_Off = FALSE;
+static bool nw_off = FALSE;
+static bool sms_off = FALSE;
+static bool data_off = FALSE;
+
+static mbtk_ril_handle* whitelist_info_handle = NULL;
+
+
+int qser_autosuspend_enable(char enable)
+{
+ int ret = 0;
+
+ ret = mbtk_autosuspend_enable(enable);
+ if (ret == -1)
+ {
+ LOGE("qser_autosuspend_enable is error");
+ }
+
+ return ret;
+}
+
+int qser_wakelock_create(const char* name , size_t len)
+{
+ int ret = 0;
+
+ ret = mbtk_wakelock_create(name, len);
+ if (ret == -1)
+ {
+ LOGE("qser_wakelock_create is error");
+ }
+
+ return ret;
+}
+
+int qser_wakelock_lock(int fd)
+{
+ int ret = 0;
+
+ ret = mbtk_wakelock_lock(fd);
+ if (ret == -1)
+ {
+ LOGE("qser_wakelock_lock is error");
+ }
+
+ return ret;
+}
+
+int qser_wakelock_unlock(int fd)
+{
+ int ret = 0;
+
+ ret = mbtk_wakelock_unlock(fd);
+ if (ret == -1)
+ {
+ LOGE("qser_wakelock_unlock is error");
+ }
+
+ return ret;
+}
+
+int qser_wakelock_destroy(int fd)
+{
+ int ret = 0;
+
+ ret = mbtk_wakelock_destroy(fd);
+ if (ret == -1)
+ {
+ LOGE("qser_wakelock_destroy is error");
+ }
+
+ return ret;
+}
+
+int qser_lpm_init(qser_lpm_Handler_t qser_lpm_handler, qser_pm_cfg_t *qser_lpm_cfg)
+{
+ UNUSED(qser_lpm_cfg);
+
+ if(mbtk_lpm_init((mbtk_lpm_handler_t)qser_lpm_handler))
+ {
+ LOGE("qser_lpm_init fail");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_lpm_deinit(void)
+{
+ mbtk_lpm_deinit();
+
+ return 0;
+}
+
+/*
+例如AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报,
+其中PS DATA目前暂时不支持,只是保留了这个标志位;
+AP power state: 1~31 means suspend, bitmap: bit0 - NETWORK;bit1 - SIM;bit2 - SMS;bit3 - CS CALL;bit4 - PS DATA
+0 means resume all.
+目标文件"/system/etc/powerind"
+如果bit0-bit3都配置可以采用的值是1-15,如果是当前采用NETWORK SMS CALL 则值的取值是 1 4 8 5 9 12 13
+
+*/
+
+int qser_whitelist_set(char* whitelish)
+{
+ //UNUSED(whitelish);
+ uint32 on = 0;
+ int call_t, nw_t, data_t, sms_t, tmp;
+
+ int len = strlen(whitelish);
+
+ if (len != 4)
+ {
+ LOGE("whitelish num error num=[%d]",len);
+ return -1;
+ }
+
+ tmp = atoi(whitelish);
+
+ call_t = tmp/1000;
+ nw_t = tmp%1000/100;
+ data_t = tmp%1000%100/10;
+ sms_t = tmp%1000%100%10;
+
+ if (call_t == 1)
+ call_Off = TRUE;
+ else
+ call_Off = FALSE;
+
+ if (nw_t == 1)
+ nw_off = TRUE;
+ else
+ nw_off = FALSE;
+
+ if (data_t == 1)
+ data_off = TRUE;
+ else
+ data_off = FALSE;
+
+ if (sms_t == 1)
+ sms_off = TRUE;
+ else
+ sms_off = FALSE;
+
+ if (call_Off == FALSE && nw_off == FALSE && data_off == FALSE && sms_off == FALSE)
+ {
+ on = 29;//0000的情况,所有上报源都屏蔽,SIM的上报会一直被包含在内
+ }
+ else
+ {
+ if (call_Off == TRUE)
+ call_t = 8;
+ else
+ call_t = 0;
+
+ if (nw_off == TRUE)
+ nw_t = 1;
+ else
+ nw_t = 0;
+
+ if (data_off == TRUE)
+ data_t = 16;
+ else
+ data_t = 0;
+
+ if (sms_off == TRUE)
+ sms_t = 4;
+ else
+ sms_t = 0;
+
+ on = 29 - (call_t + nw_t + data_t + sms_t);//SIM的上报会一直被包含在内
+ }
+
+ if(whitelist_info_handle == NULL)
+ {
+ whitelist_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+ if(whitelist_info_handle)
+ {
+ LOGI("creat whitelist_info_handle is success");
+ }
+ else
+ {
+ LOGE("creat whitelist_info_handle is fail");
+ return -1;
+ }
+ }
+
+ int err = mbtk_wakeup_state_set(whitelist_info_handle, on);
+ if(err)
+ {
+ LOGE("whitelist_info_handle Error : %d", err);
+ return -1;
+ }
+
+ if(whitelist_info_handle != NULL)
+ {
+ int ret_ril = mbtk_ril_close(MBTK_AT_PORT_DEF);
+ if (ret_ril == MBTK_RIL_ERR_SUCCESS)
+ {
+ LOGI("deinit whitelist_info_handle is succuess");
+ whitelist_info_handle = NULL;
+ }
+ else
+ {
+ LOGE("deinit whitelist_info_handle is error(%d)",ret_ril);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
+int qser_whitelist_get(char* whitelish)
+{
+ //UNUSED(whitelish);
+ char list[10] = {0};
+ int get_tmp;
+
+ get_tmp = mbtk_powerrind_get();
+ LOGI(">>>powerrind_get: %d",get_tmp);
+ //call 8 nw 1 data 16 sms 4 SIM的上报会一直被包含在内
+ switch(get_tmp)
+ {
+ case 0:
+ sprintf(list, "%d%d%d%d", 1, 1, 1, 1);
+ break;
+ case 8:
+ sprintf(list, "%d%d%d%d", 0, 1, 1, 1);
+ break;
+ case 1:
+ sprintf(list, "%d%d%d%d", 1, 0, 1, 1);
+ break;
+ case 16:
+ sprintf(list, "%d%d%d%d", 1, 1, 0, 1);
+ break;
+ case 4:
+ sprintf(list, "%d%d%d%d", 1, 1, 1, 0);
+ break;
+
+ case 9:
+ sprintf(list, "%d%d%d%d", 0, 0, 1, 1);
+ break;
+ case 24:
+ sprintf(list, "%d%d%d%d", 0, 1, 0, 1);
+ break;
+ case 12:
+ sprintf(list, "%d%d%d%d", 0, 1, 1, 0);
+ break;
+ case 17:
+ sprintf(list, "%d%d%d%d", 1, 0, 0, 1);
+ break;
+ case 5:
+ sprintf(list, "%d%d%d%d", 1, 0, 1, 0);
+ break;
+ case 20:
+ sprintf(list, "%d%d%d%d", 1, 1, 0, 0);
+ break;
+
+ case 25:
+ sprintf(list, "%d%d%d%d", 0, 0, 0, 1);
+ break;
+ case 13:
+ sprintf(list, "%d%d%d%d", 0, 0, 1, 0);
+ break;
+ case 28:
+ sprintf(list, "%d%d%d%d", 0, 1, 0, 0);
+ break;
+ case 21:
+ sprintf(list, "%d%d%d%d", 1, 0, 0, 0);
+ break;
+
+ case 29:
+ sprintf(list, "%d%d%d%d", 0, 0, 0, 0);
+ break;
+
+ default :
+ LOGE("qser_whitelist_get is error");
+ return -1;
+ }
+
+ LOGI("whitelist list: %s",list);
+ strncpy(whitelish, list, strlen(list));
+
+ return 0;
+}
+
+
+int qser_suspend_timer_set(int time, mbtk_sleep_callback_func cb)
+{
+ int ret = 0;
+ ret = mbtk_suspend_timer_set(time, cb);
+ if(0 > ret)
+ {
+ LOGE("qser_suspend_timer_set failed");
+ }
+
+
+ return ret;
+}
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_sms.c b/mbtk/liblynq_lib_rilv2/lynq_sms.c
new file mode 100755
index 0000000..1c839a5
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_sms.c
@@ -0,0 +1,673 @@
+#include "lynq_qser_sms.h"
+#include "mbtk_type.h"
+#include "mbtk_pdu_sms.h"
+#include "lynq_sms.h"
+#include "mbtk_log.h"
+#include "mbtk_ril_api.h"
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#define TELEPHONE_NUM_MAX 16
+#define MSM_NUMBER_MAX 2048+1
+#define RES_NUM_MIN 128
+
+#define HAL_SMS_CONTENT_LEN 1024
+
+
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+
+#define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2"))
+
+static mbtk_ril_handle* qser_info_handle;
+static const uint qser_h_sms = 0x5F6F7F8F;
+
+
+static char sms_center_address[128] = {0};
+
+typedef struct
+{
+ QSER_SMS_RxMsgHandlerFunc_t handlerPtr;
+ void* contextPtr;
+} lynq_sms_cb_func;
+
+static lynq_sms_cb_func lynq_sms_func_cb_handle;
+
+void lynq_sms_state_change_cb(const void* data, int data_len)
+{
+ LOGV("sms_state_change_cb()----------start\n");
+ mbtk_ril_sms_state_info_t *ptr = (mbtk_ril_sms_state_info_t *)data;
+ //LOGD("3sms_state_change_cb() : %s\n", ptr->pdu);
+
+ QSER_SMS_Msg_t tmp_data;
+
+ memset(&tmp_data,0x00, sizeof(QSER_SMS_Msg_t));
+
+ char smsc[MDAPI_MAX_PDU_SIZE] = {0};
+ char received_pdu[MDAPI_MAX_PDU_SIZE] = {0};
+ char msg[MDAPI_MAX_PDU_SIZE] = {0};
+ char num[MDAPI_MAX_PDU_SIZE] = {0};
+ char date[32] = {0};
+ int charset = 0;
+ int ret = -1;
+ int curr_pack = 1;
+ int total_pack = 1;
+ if(ptr == NULL)
+ {
+ LOGE("ptr is null");
+ }
+ LOGE("ptr: %s\n,data_len = %d\n", (char *)ptr->pdu, data_len);
+ if(data_len > MDAPI_MAX_PDU_SIZE)
+ {
+ strncpy(received_pdu, (const char *)ptr->pdu, MDAPI_MAX_PDU_SIZE-1);
+ }
+ else
+ {
+ strncpy(received_pdu, (const char *)ptr->pdu, data_len);
+ }
+ ret = smsPduDecode((const char *)received_pdu, data_len, num, smsc, msg, &charset, &curr_pack, &total_pack,date);
+ if(ret != 0)
+ {
+ LOGE("smsPduDecode fail ret: %d\n",ret);
+ return ;
+ }
+
+ LOGE("[EVENT][MT_SMS]PDU decode:smsc: %s\n, phone number: %s\ncharset: %d\n msg_len: %d\n message content: %s\n curr_pack: %d\n total_pack: %d\n date: %s", smsc, num, charset, strlen(msg), msg, curr_pack, total_pack, date);
+
+ tmp_data.format = charset;
+ memcpy(tmp_data.src_addr, num, strlen(num));
+ tmp_data.sms_data_len = strlen(msg);
+ memcpy(tmp_data.sms_data, msg, strlen(msg));
+
+ if(total_pack > 1 && curr_pack < total_pack)
+ {
+ tmp_data.user_data_head_valid = TRUE;
+ tmp_data.user_data_head.total_segments = total_pack;
+ tmp_data.user_data_head.seg_number = curr_pack;
+ lynq_sms_func_cb_handle.handlerPtr(&tmp_data, &curr_pack);
+ }
+ else
+ {
+ tmp_data.user_data_head_valid = FALSE;
+ tmp_data.user_data_head.total_segments = total_pack;
+ tmp_data.user_data_head.seg_number = curr_pack;
+ lynq_sms_func_cb_handle.handlerPtr(&tmp_data, NULL);
+ }
+
+}
+
+
+int qser_sms_client_init(sms_client_handle_type *ph_sms)//out
+{
+ //UNUSED(ph_voice);
+ if(ph_sms == NULL)
+ {
+ LOGE("[qser_sms] ph_sms is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(NULL == qser_info_handle)
+ {
+ qser_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+ if(NULL == qser_info_handle)
+ {
+ LOGE("[qser_sms] qser_info_handle get fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_sms] qser_info_handle has init.");
+ *ph_sms = qser_h_sms;
+ return QSER_RESULT_FAIL;
+ }
+ *ph_sms = qser_h_sms;
+
+ LOGE("[qser_sms] qser_info_handle get success.");
+
+
+ return QSER_RESULT_SUCCESS;
+
+}
+
+
+int qser_sms_client_deinit(sms_client_handle_type h_sms)//in
+{
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle)
+ {
+ int ret = mbtk_ril_close(MBTK_AT_PORT_DEF);;
+ if(ret)
+ {
+ LOGE("[qser_sms] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle = NULL;
+ lynq_sms_func_cb_handle.handlerPtr = NULL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_sms] handle not inited.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+
+int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码
+{
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if (pt_sms_info == NULL)
+ {
+ LOGE("QSER_sms_info_t NULL");
+ return -1;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_send_sms qser_info_handle NULL");
+ return -1;
+ }
+
+ int8 *phone_num = NULL;
+ int8 *msg = NULL;
+ int32 msg_len;
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ char resp[RES_NUM_MIN] = {0};
+
+ char smscPDU[30] = {0};
+ char **pdu = NULL;
+ char smsc[4] = {0};
+ char msg_e_b[HAL_SMS_CONTENT_LEN] = {0};// +1 for end of string.*2:A char array contains two elements of a string for each value
+
+ int char_set = 0;
+ int lsms_flag = 0;
+ int err = 0;
+ int i = 0;
+
+ msg = (int8 *)pt_sms_info->sms_data;
+
+ msg_len = strlen(pt_sms_info->sms_data);
+
+ phone_num = (int8 *)pt_sms_info->src_addr;
+
+ lsms_flag = pt_sms_info->user_data_head_valid;
+
+ if(strcmp((char*)msg,"") == 0 || msg[0] == '\0')
+ {
+ LOGE("qser_sms_send_sms msg [%s]",msg);
+ return -1;
+ }
+
+ if(strcmp((char*)phone_num,"") == 0 || phone_num[0] == '\0')
+ {
+ LOGE("qser_sms_send_sms phone_num [%s]",phone_num);
+ return -1;
+ }
+
+ if (pt_sms_info->format == 0)//7
+ char_set = 0;
+ else if (pt_sms_info->format == 1)//8
+ char_set = 1;
+ else if (pt_sms_info->format == 2)//UCS2
+ char_set = 2;
+ else
+ {
+ LOGE("qser_sms_send_sms format error");
+ return -1;
+ }
+
+
+ //设置存储器
+/*
+ if (pt_sms_info->storage == 0)
+ {
+ strcpy(mem, "SM");
+ }
+ else if (pt_sms_info->storage == 1)
+ {
+ strcpy(mem, "ME");
+ }
+ else
+ {
+ LOGE("qser_sms_deletefromstorage storage is no Support");
+ return -1;
+ }
+
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cpms_set(qser_info_handle, mem, resp);
+ if(err) {
+ LOGE("Error : %d", err);
+ } else {
+ LOGI("cpms set success. resp:%s", resp);
+ }
+*/
+
+
+
+ kal_int32 msg_num = 0;
+ kal_int32 pdu_msg_len = 0;
+ kal_int32 status = MDAPI_RET_ERROR;
+ kal_int32 index = 0;
+
+ if(char_set == 1) //8bit
+ {
+ ArrayToStr((unsigned char *)msg, (unsigned int)msg_len, msg_e_b);
+ status = _mdapi_sms_get_msg_num(msg_e_b, char_set, &msg_num, &pdu_msg_len);
+ }
+ else //7bit usc2
+ {
+ status = _mdapi_sms_get_msg_num((char *)msg, char_set, &msg_num, &pdu_msg_len);
+ }
+
+ LOGE("msg_len = [%d] ,msg_num=[%d]",msg_len, msg_num);
+ if(status == MDAPI_RET_ERROR)
+ {
+ LOGE("get message number failed");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if (lsms_flag == TRUE || lsms_flag == FALSE)
+ {
+ if (lsms_flag == FALSE && msg_num > 1)
+ {
+ LOGE("msg_num %d user head need for true",msg_num);
+ return QSER_RESULT_FAIL;
+ }
+ else if (lsms_flag == TRUE && msg_num > 4)
+ {
+ LOGE("Only 4 long SMS messages are supported");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("1:TRUE long sms 0:FALSE short message set user head error:%d",lsms_flag);
+ return QSER_RESULT_FAIL;
+ }
+
+
+ //allocate memery for **pdu
+ pdu = (char **)malloc(sizeof(char *) * msg_num);
+ if(pdu == NULL)
+ {
+ LOGE("allocate memory for pdu failed");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ for(index = 0; index < msg_num; index++)
+ {
+ pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE);
+ if(pdu[index] == NULL)
+ {
+ for(i = 0; i < index; i++)
+ {
+ free(pdu[i]);
+ pdu[i] = NULL;
+ }
+ free(pdu);
+ pdu = NULL;
+ LOGE("allocate memory for pdu[%d] failed",index);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ memset(pdu[index], 0, MAX_PDU_SIZE);
+ LOGE("pdu[%d} init value is: %s ",index, pdu[index]);
+ }
+ }
+ }
+ }
+
+ //allocate memory for **pdu success
+ if(index == msg_num)
+ {
+ if(char_set == 1)//8bit
+ {
+ smsPduEncode(smsc, (char *)phone_num, msg_e_b, char_set, smscPDU, pdu);
+ }
+ else
+ {
+ smsPduEncode(smsc, (char *)phone_num, (char *)msg, char_set, smscPDU, pdu);
+ }
+
+ for(index = 0; index < msg_num; index++)
+ {
+ char pdu_data[MAX_PDU_SIZE] = {0};
+ char *p = pdu_data;
+
+ LOGE("index:%d",index);
+ LOGE("smscPDU: %s, pdu: %s",smscPDU, pdu[index]);
+ sprintf(p, "%s",smscPDU);
+ LOGE("pdu_data:%s\n", pdu_data);
+ int sc = strlen(pdu_data);
+ sprintf(p+strlen(p), "%s", pdu[index]);
+ LOGE("pdu_data:%s", pdu_data);
+
+ int t = strlen(pdu_data);
+ sprintf(cmgs, "%d,%s", (t-sc)/2, pdu_data);
+ LOGE("cmgs:%s\n", cmgs);
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgf_set(qser_info_handle, 0);
+ if(err)
+ {
+ LOGE("cmgf set error : %d", err);
+ for(index = 0; index < msg_num; index++){
+ free(pdu[index]);
+ pdu[index] = NULL;
+ }
+ free(pdu);
+ pdu = NULL;
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ LOGD("cmgf set success");
+ }
+
+ err = mbtk_sms_cmgs_set(qser_info_handle, cmgs, resp);
+ if(err)
+ {
+ LOGE("cmgs send fail (%d)",err);
+ for(index = 0; index < msg_num; index++){
+ free(pdu[index]);
+ pdu[index] = NULL;
+ }
+ free(pdu);
+ pdu = NULL;
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ LOGD("cmgs send success, resp:%s", resp);
+ }
+
+ }
+ }
+
+ for(index = 0; index < msg_num; index++){
+ free(pdu[index]);
+ pdu[index] = NULL;
+ }
+ free(pdu);
+ pdu = NULL;
+
+ return 0;
+}
+
+//注册接收新短信
+int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容
+{
+ //UNUSED(handlerPtr);
+ //UNUSED(contextPtr);
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_addrxmsghandler qser_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_cnmi_set(qser_info_handle);
+ if(err)
+ {
+ LOGE("set cnmi fail (%d)",err);
+ return -1;
+ }
+
+ lynq_sms_func_cb_handle.handlerPtr = handlerPtr;
+ lynq_sms_func_cb_handle.contextPtr = contextPtr;
+
+ err = mbtk_sms_state_change_cb_reg(lynq_sms_state_change_cb);
+ if(err)
+ {
+ LOGE("mbtk_sms_state_change_cb_reg fail (%d)",err);
+ return -1;
+ }
+
+ return 0;
+}
+
+//删除短信
+int qser_sms_deletefromstorage(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage)//in in 删除短信的信息
+{
+ //UNUSED(h_sms);
+ //UNUSED(pt_sms_storage);
+ char cmgd[128] = {0};
+ int err = 0;
+
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(pt_sms_storage == NULL)
+ {
+ LOGE("qser_sms_deletefromstorage pt_sms_storage NULL");
+ return -1;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_deletefromstorage qser_info_handle NULL");
+ return -1;
+ }
+/*
+ t_storage = pt_sms_storage->storage; //设置存储器
+
+ if (t_storage == 0)
+ {
+ strncpy(mem, "SM", 2);
+ }
+ else if (t_storage == 1)
+ {
+ strncpy(mem, "ME", 2);
+ }
+ else
+ {
+ LOGE("qser_sms_deletefromstorage storage is no Support");
+ return -1;
+ }
+
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cpms_set(qser_info_handle, mem, resp);
+ if(err) {
+ LOGE("Error : %d", err);
+ } else {
+ LOGI("cpms set success. resp:%s", resp);
+ }
+*/
+ uint32_t id_x = 0; //若后面其他产品是int类型则用宏控制
+ id_x = pt_sms_storage->storage_idx;//获取idx的值
+
+ if(id_x == -1) //delete all
+ {
+ memcpy(cmgd, "0,4", strlen("0,4"));
+ }
+ else
+ {
+ sprintf(cmgd,"%d",id_x);
+ }
+
+ LOGI("cmgd:%s", cmgd);
+
+ err = mbtk_sms_cmgd_set(qser_info_handle, cmgd);
+ if(err)
+ {
+ LOGE("qser_sms_deletefromstorage Error : %d", err);
+ return -1;
+ }
+ else
+ {
+ LOGI("qser_sms_deletefromstorage set success");
+ }
+
+ return 0;
+}
+
+//获取短信中心号码
+int qser_sms_getsmscenteraddress( sms_client_handle_type h_sms,QSER_sms_service_center_cfg_t *set_sca_cfg)//in out
+{
+ //UNUSED(h_sms);
+ //UNUSED(set_sca_cfg);
+ char sms_center_addree[254] = {0};
+ int len_t;
+ char *p1, *p2 ,*substr;
+
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if (set_sca_cfg == NULL)
+ {
+ LOGE("QSER_sms_service_center_cfg_t NULL");
+ return -1;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_getsmscenteraddress qser_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_get(qser_info_handle, sms_center_addree);
+ if(sms_center_addree[0] == '\0')
+ {
+ LOGE("qser_sms_getsmscenteraddress Error : %d", err);
+ return -1;
+ }
+ else
+ {
+ p1 = strchr(sms_center_addree, '\"');
+ p2 = strrchr(sms_center_addree, '\"');
+ if (p1 && p2 && p2 > p1)
+ {
+ len_t = p2 - p1 - 1;
+ char substr_t[len_t + 1];
+ strncpy(substr_t, p1 + 1, len_t);
+ substr_t[len_t] = '\0';
+
+ substr = substr_t;
+
+ memcpy(set_sca_cfg->service_center_addr, substr, strlen(substr));
+ memcpy(sms_center_address, substr, strlen(substr));
+
+ LOGI("qser_sms_getsmscenteraddress success");
+ }
+ else
+ {
+ LOGE("String inside double quotes not found");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+//设置短信中心号码
+int qser_sms_setsmscenteraddress( sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg)//in in
+{
+ //UNUSED(h_sms);
+ //UNUSED(get_sca_cfg);
+ char *destNum = NULL;
+
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_setsmscenteraddress qser_info_handle NULL");
+ return -1;
+ }
+
+ if(get_sca_cfg == NULL)
+ {
+ LOGE("qser_sms_setsmscenteraddress get_sca_cfg NULL");
+ return -1;
+ }
+
+ destNum = get_sca_cfg->service_center_addr;
+
+ //printf("1destNum:%s\n", destNum);
+ memset(sms_center_address, 0, sizeof(sms_center_address));
+ memcpy(sms_center_address, destNum, strlen(destNum));
+
+ if (destNum == NULL)
+ {
+ LOGE("qser_sms_setsmscenteraddress destNum NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_set(qser_info_handle, destNum);
+ if(err)
+ {
+ LOGE("Error : %d", err);
+ return -1;
+ }
+ else
+ {
+ // memset(sms_center_address, 0, sizeof(sms_center_address));
+ // memcpy(sms_center_address, destNum, strlen(destNum));
+ //printf("destNum:%s\n", destNum);
+ LOGI("qser_sms_setsmscenteraddress success");
+ }
+
+ return 0;
+}
+
+
+//显示删除列表
+int qser_sms_deletefromstoragelist( sms_client_handle_type h_sms, char* del_list)//in out
+{
+ //UNUSED(h_sms);
+ //UNUSED(get_sca_cfg);
+
+ if(h_sms != qser_h_sms)
+ {
+ LOGE("[qser_sms] h_sms is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("qser_sms_deletefromstoragelist qser_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_cmgd_get(qser_info_handle, del_list);
+ if(err > 0 && err != 300)//MBTK_INFO_ERR_SUCCESS
+ {
+ LOGE("Error : %d", err);
+ return -1;
+ }
+
+ return 0;
+}
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_thermal.c b/mbtk/liblynq_lib_rilv2/lynq_thermal.c
new file mode 100755
index 0000000..6d0c76f
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_thermal.c
@@ -0,0 +1,98 @@
+#if 1
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "lynq_qser_thermal.h"
+#include "mbtk_ril_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_FAIL -1
+#define QSER_RESULT_SUCCESS 0
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+static mbtk_ril_handle* qser_info_handle = NULL;
+
+/****************************VARIABLE***************************************/
+
+
+/******************************FUNC*****************************************/
+static int qser_thermal_client_init(void)
+{
+ qser_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
+
+ if (qser_info_handle == NULL)
+ {
+ LOGE("[qser_led] qser_info_handle fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ LOGI("[qser_led] qser_info_handle success.");
+ return QSER_RESULT_SUCCESS;
+ }
+}
+
+static int qser_thermal_client_deinit(void)
+{
+ if(qser_info_handle != NULL)
+ {
+ int ret_ril = mbtk_ril_close(MBTK_AT_PORT_DEF);
+ if (ret_ril == MBTK_RIL_ERR_SUCCESS)
+ {
+ LOGI("deinit qser_info_handle is succuess");
+ return QSER_RESULT_SUCCESS;
+ }
+ else
+ {
+ LOGE("deinit qser_info_handle is error(%d)",ret_ril);
+ return QSER_RESULT_FAIL;
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int get_thermal_zone(int *numbers, int size)
+{
+ if(numbers == NULL)
+ {
+ LOGE("[qser_thermal]: numbers is NULL!");
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = 0;
+ int thermal = -1;
+ int thermal_num = 0;
+ int temp = 0;
+
+ ret = qser_thermal_client_init();
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_thermal]qser_led_client_init fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_temp_get(qser_info_handle, 0, &temp);
+ thermal = temp;
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_thermal]mbtk_temp_get fail.");
+ qser_thermal_client_deinit();
+ return QSER_RESULT_FAIL;
+ }
+
+ qser_thermal_client_deinit();
+ numbers[thermal_num++] = thermal;
+ for(; thermal_num < size; thermal_num++)
+ {
+ numbers[thermal_num] = 0;
+ }
+
+ return size;
+}
+/****************************API***************************************/
+
+#endif
diff --git a/mbtk/liblynq_lib_rilv2/lynq_time.c b/mbtk/liblynq_lib_rilv2/lynq_time.c
new file mode 100755
index 0000000..29937bd
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_time.c
@@ -0,0 +1,418 @@
+#include "lynq_systime.h"
+#include "mbtk_type.h"
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <errno.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <netinet/in.h>
+
+#include <cutils/properties.h>
+#include <sys/time.h>
+
+
+#include "mbtk_ntp.h"
+#include "mbtk_net_control.h"
+#include "lynq_systime.h"
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
+
+
+#define MBTK_AT_NTP_LEN_MAX 128
+
+
+
+
+typedef enum {
+ LYNQ_TIME_TYPE_CELL = 0, //NITZ
+ LYNQ_TIME_TYPE_NTP,
+ LYNQ_TIME_TYPE_GNSS,
+ LYNQ_TIME_TYPE_USER,
+
+ LYNQ_TIME_TYPE_UNUSE
+} lynq_time_type_enum;
+
+//enable set time from ntp
+int ntp_sync_time(int enable);
+//enable set time from nitz
+int modem_time_enable(int enable);
+//enable set time from gnss
+int gnss_time_enable(int enable);
+//enable set time from user
+int user_set_time(char* date, char* time);
+// RTC TIME set to system
+int lynq_sync_time_from_rtc(void);
+//check sysytem type
+int lynq_get_time_src_status (time_src_status_s * time_src);
+// system time set to RTC
+int lynq_set_rtc_time(void);
+// get RTC time
+int lynq_get_rtc_time(unsigned long *ulsec);
+
+int sync_time_flag = 0;
+
+//int req_time_set(int type, char *time, int *cme_err);
+static int metis_strptime(char *str_time)
+{
+ LOGD("%s(), str_time:%s\n", __FUNCTION__, str_time);
+ struct tm stm;
+// char dateTime[30];
+ struct timeval tv;
+ if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
+ {
+ time_t _t = (long)mktime(&stm);
+ tzset();
+ tv.tv_sec = _t;
+ tv.tv_usec = 0;
+ if(_t == -1)
+ {
+ LOGD("Set time :%s", str_time);
+ LOGD("timestamp:%ld", _t);
+ LOGD("mktime error, reason: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if(settimeofday(&tv, NULL)) {
+ LOGD("Set time :%s", str_time);
+ LOGD("timestamp:%ld", _t);
+ LOGD("mktime error, reason: %s\n", strerror(errno));
+ return -1;
+ }
+
+ LOGD("Success Set time to %s.\n", str_time);
+ return 0;
+
+ } else {
+ LOGD("Set time fail.");
+ return -1;
+ }
+ return 0;
+}
+
+
+static void* ntp_pthread_run(int* ntp_flag)
+{
+ if (mbtk_net_state_get() == MBTK_NET_STATE_OFF)
+ {
+ LOGD("Network is disconnected. Set time fail.");
+ if(NULL != ntp_flag)
+ {
+ *ntp_flag = -1;
+ }
+ return NULL;
+ }
+ LOGD("Network is connected.");
+
+ char time_type[10];
+ while(1){
+ memset(time_type, 0, 10);
+ property_get("persist.mbtk.time_type", time_type, "0");
+ if(atoi(time_type) == LYNQ_TIME_TYPE_NTP) // NTP time
+ {
+// char time_str[100] = {0};
+ time_t time = 0;
+ if((time = (time_t)mbtk_at_systime()) == 0)
+ {
+ LOGD("NTP client fail!\n");
+ if(NULL != ntp_flag)
+ {
+ *ntp_flag = -1;
+ }
+ return NULL;
+ }
+#if 1
+ struct tm CurlocalTime;
+ localtime_r(&time, &CurlocalTime);
+ // CurlocalTime.tm_hour += 8; //cst
+ char dateTime[30];
+ strftime(dateTime, 30, "%Y-%m-%d %H:%M:%S %A", &CurlocalTime);
+
+ // printf("dateTime:%s, %ld\n", dateTime, time+28800); //cst
+ LOGD("dateTime:%s, %ld\n", dateTime, time);
+
+ struct timeval tv;
+ tv.tv_sec = time;
+ // tv.tv_sec += 28800; //cst
+ tv.tv_usec = 0;
+
+ if(settimeofday(&tv, NULL)) {
+ LOGD("Set time :%s", dateTime);
+ LOGD("timestamp:%ld, tv.tv_sec:%ld\n", time, tv.tv_sec);
+
+ if(settimeofday(&tv, NULL)) {
+ *ntp_flag = -1;
+ LOGD("mktime error, reason: %s\n", strerror(errno));
+ return NULL;
+ }
+ }
+ LOGD("Set time success\n");
+ lynq_set_rtc_time();
+#else
+
+ struct tm *tm_t;
+ tm_t = localtime(&time);
+ tm_t->tm_hour += 8;
+ strftime(time_str,128,"%F %T",tm_t);
+
+ // NTP time
+ if(metis_strptime(time_str))
+ {
+ *ntp_flag = -1;
+ return NULL;
+ }
+#endif
+ break;
+ } else {
+ break;
+ }
+
+ sleep(64); // Sleep 64s.
+ }
+ if(NULL != ntp_flag)
+ {
+ *ntp_flag = 0;
+ }
+ return NULL;
+}
+
+int set_time_user(char* data_time_str)
+{
+
+ int ret = 0;
+ if(strlen(data_time_str) > 0)
+ {
+ ret = metis_strptime(data_time_str);
+ }
+
+ return ret;
+}
+
+
+//MBTK_TIME_TYPE_CELL = 0, //NITZ
+//MBTK_TIME_TYPE_NTP,
+//MBTK_TIME_TYPE_GNSS,
+//MBTK_TIME_TYPE_USER
+void set_time_type(int mbtk_time_type)
+{
+ char type_str[10] = {0};
+ sprintf(type_str, "%d", mbtk_time_type);
+ property_set("persist.mbtk.time_type", type_str);
+
+ return;
+}
+
+static int mbtk_get_gnss_time_set_flag() {
+ int type = 0;
+ char time_type[] ={0};
+ property_get("persist.mbtk.gnss_time_type", time_type, "0");
+
+ type = atoi(time_type);
+ LOGD("persist.mbtk.gnss_time_type :%d\n", type);
+ return type;
+}
+
+
+int ntp_sync_time(int enable)
+{
+ if(0 != enable && 1 != enable)
+ {
+ return -1;
+ }
+ UNUSED(enable);
+ int ntp_status = 0;
+ int ret = 0;
+ sync_time_flag = 0;
+ if(enable)
+ {
+ set_time_type(LYNQ_TIME_TYPE_NTP);
+ ntp_pthread_run(&ntp_status);
+ if(ntp_status == 0)
+ {
+ ret = 0;
+ sync_time_flag = 0;
+ }
+ else
+ {
+ ret = -1;
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ sync_time_flag = -1;
+ }
+ }
+ else
+ {
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ }
+
+ return ret;
+}
+
+//enable set time from nitz
+int modem_time_enable(int enable)
+{
+ if(0 != enable && 1 != enable)
+ {
+ return -1;
+ }
+ UNUSED(enable);
+ sync_time_flag = 0;
+
+ if(enable)
+ {
+ set_time_type(LYNQ_TIME_TYPE_CELL);
+ }
+ else
+ {
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ }
+ return 0;
+}
+
+
+//enable set time from gnss
+int gnss_time_enable(int enable)
+{
+ if(0 != enable && 1 != enable)
+ {
+ return -1;
+ }
+ UNUSED(enable);
+ sync_time_flag = 0;
+ if(enable)
+ {
+ set_time_type(LYNQ_TIME_TYPE_GNSS);
+ }
+ else
+ {
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ }
+
+ return 0;
+}
+
+
+//enable set time from user
+int user_set_time(char* date, char* time)
+{
+ UNUSED(date);
+ UNUSED(time);
+ if(date == NULL || time == NULL)
+ {
+ return -1;
+ }
+
+ int ret = 0;
+ char time_str[128] ={0};
+ memset(time_str, 0x0, MBTK_AT_NTP_LEN_MAX);
+
+ char *p = time;
+ char *p1 = strstr(p, ":");
+ char *p2 = strstr(p1+1, ":");
+ if(p2 == NULL)
+ {
+ sprintf(time_str, "%s %s:00", date, time); //2023-11-30 11:30
+ set_time_type(LYNQ_TIME_TYPE_USER);
+ ret = set_time_user(time_str);
+ }else
+ {
+ sprintf(time_str, "%s %s", date, time); //2023-11-30 11:30:31
+ set_time_type(LYNQ_TIME_TYPE_USER);
+ ret = set_time_user(time_str);
+ }
+
+ return ret;
+}
+
+
+//check sysytem type
+int lynq_get_time_src_status (time_src_status_s * time_src)
+{
+ UNUSED(time_src);
+ int type = 0;
+ char time_type[] ={0};
+ property_get("persist.mbtk.time_type", time_type, "0");
+
+ type = atoi(time_type);
+ printf("time_type :%d", type);
+ if(type == LYNQ_TIME_TYPE_NTP)
+ {
+ time_src->ntp = 1;
+ time_src->nitz = 0;
+ time_src->gnss = 0;
+ }
+ else if(type == LYNQ_TIME_TYPE_CELL)
+ {
+ time_src->ntp = 0;
+ time_src->nitz = 1;
+ time_src->gnss = 0;
+ }
+ else if(type == LYNQ_TIME_TYPE_GNSS)
+ {
+ time_src->ntp = 0;
+ time_src->nitz = 0;
+ time_src->gnss = 1;
+ }
+ else if(type == LYNQ_TIME_TYPE_UNUSE)
+ {
+ time_src->ntp = 0;
+ time_src->nitz = 0;
+ time_src->gnss = 0;
+ }
+
+ return 0;
+}
+
+// RTC TIME set to system
+int lynq_sync_time_from_rtc(void)
+{
+ mbtk_system("hwclock --hctosys");
+ return 0;
+}
+
+// system time set to RTC
+int lynq_set_rtc_time(void)
+{
+// system("hwclock --systohc");
+ mbtk_system("hwclock -w rtc0");
+ return 0;
+}
+
+int lynq_get_rtc_time(unsigned long *ulsec)
+{
+ UNUSED(ulsec);
+
+ return 0;
+}
+
+
+int get_sync_time_result(void )
+{
+ int type = 0;
+ int gnss_status = 0;
+ char time_type[] ={0};
+ property_get("persist.mbtk.time_type", time_type, "0");
+ type = atoi(time_type);
+ printf("time_type :%d", type);
+ if(type == LYNQ_TIME_TYPE_GNSS)
+ {
+ gnss_status = mbtk_get_gnss_time_set_flag();
+ if(gnss_status) //success
+ {
+ sync_time_flag = 0;
+ }
+ else{
+ sync_time_flag = -1;
+ }
+ }
+ LOGD("mbtk_gnss_time_set_flag :%d", mbtk_get_gnss_time_set_flag());
+ return sync_time_flag;
+}
+
+
+
+
+
diff --git a/mbtk/liblynq_lib_rilv2/lynq_voice_call.c b/mbtk/liblynq_lib_rilv2/lynq_voice_call.c
new file mode 100755
index 0000000..97ddc63
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_voice_call.c
Binary files differ
diff --git a/mbtk/liblynq_lib_rilv2/lynq_wifi.c b/mbtk/liblynq_lib_rilv2/lynq_wifi.c
new file mode 100755
index 0000000..a2b08b7
--- /dev/null
+++ b/mbtk/liblynq_lib_rilv2/lynq_wifi.c
@@ -0,0 +1,1103 @@
+#include "sta_cli.h"
+#include "lynq_wifi.h"
+#include "mbtk_log.h"
+#include "mbtk_wifi_ap.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+
+#define STA_BUF_SIZE 2048
+#define PATH_MAX_LEN 64
+#define DEF_INTERFACE "wlan0"
+static lynq_wifi_event_handle_sta g_event_handle_sta_cb = NULL;
+static lynq_wifi_status_e g_ap_status = LYNQ_WIFI_AP_STATUS_NONE;
+
+
+
+int qser_wifi_enable(void)
+{
+ static char sta_cli_buf[STA_BUF_SIZE] = "OPEN";
+ char reply[STA_BUF_SIZE];
+ if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }
+ else
+ {
+ LOGE("No reply data(%s).\n",sta_cli_buf);
+ return LYNQ_ERR_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ return LYNQ_ERR_FAIL;
+ }
+
+ g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLING;
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_disable(void)
+{
+ static char sta_cli_buf[STA_BUF_SIZE] = "CLOSE";
+ char reply[STA_BUF_SIZE];
+ if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE)){
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }
+ else
+ {
+ LOGE("No reply data(%s).\n",sta_cli_buf);
+ return LYNQ_ERR_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ return LYNQ_ERR_FAIL;
+ }
+
+ g_ap_status = LYNQ_WIFI_AP_STATUS_IDLE;
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
+{
+ int ret = 0;
+ if(LYNQ_WIFI_WORK_MODE_AP0 == type)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "g");
+ }
+ else
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "a");
+ }
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == type)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "hw_mode", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('g' == value[0])
+ {
+ *type = LYNQ_WIFI_AP_INDEX_AP0;
+ }
+ else
+ {
+ *type = LYNQ_WIFI_AP_INDEX_AP1;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t* ap_stat)
+{
+ if(NULL == ap_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ int ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ap_stat->bssid, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ ap_stat->status = g_ap_status;
+ memcpy(ap_stat->ifname, DEF_INTERFACE, strlen(DEF_INTERFACE));
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
+{
+ int ret = 0;
+ char path[PATH_MAX_LEN] = {0};
+
+ if(NULL == mac_list)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ if(LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST == acl_rule)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "1");
+ memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
+
+ }
+ else if(LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST == acl_rule)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "0");
+ memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
+ }
+ else
+ {
+ LOGE("qser_wifi_ap_acl_set LYNQ_WIFI_MAC_ACL_RULE_NONE");
+ return LYNQ_ERR_SUCCESS;
+ }
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ ret = mbtk_wifi_set_file(path, mac_list);
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+ char path[PATH_MAX_LEN] = {0};
+
+ if(NULL == acl_rule || NULL == mac_list)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "macaddr_acl", value, SETTING_LINE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('1' == value[0])
+ {
+ *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST;
+ memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
+ }
+ else if('0' == value[0])
+ {
+ *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST;
+ memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
+ }
+ else
+ {
+ *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_NONE;
+ LOGE("qser_wifi_ap_acl_get LYNQ_WIFI_MAC_ACL_RULE_NONE");
+ return LYNQ_ERR_SUCCESS;
+ }
+
+ ret = mbtk_wifi_get_file(path, mac_list, SETTING_LINE_MAX_LEN);
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
+{
+ int ret = 0;
+
+ if(NULL == ssid)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ssid", ssid);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
+{
+ int ret = 0;
+
+ if(NULL == ssid)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ssid, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx,bool hide)
+{
+ int ret = 0;
+ if(true == hide)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "0");
+ }
+ else
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "1");
+ }
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx,bool* hide)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == hide)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "ignore_broadcast_ssid", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('0' == value[0])
+ {
+ *hide = true;
+ }
+ else
+ {
+ *hide = false;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
+{
+ int ret = 0;
+ if(LYNQ_WIFI_MODE_80211B == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211b", "1");
+ }
+ else if(LYNQ_WIFI_MODE_80211BG == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bg", "1");
+ }
+ else if(LYNQ_WIFI_MODE_80211BGN == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bgn", "1");
+ }
+ else if(LYNQ_WIFI_MODE_80211A == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211a", "1");
+ }
+ else if(LYNQ_WIFI_MODE_80211AN == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211an", "1");
+ }
+ else if(LYNQ_WIFI_MODE_80211AC == mode)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211ac", "1");
+ }
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e* mode)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == mode)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211b", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('1' == value[0])
+ {
+ *mode = LYNQ_WIFI_MODE_80211B;
+ }
+
+ memset(value, 0, SETTING_VALUE_MAX_LEN);
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211bg", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('1' == value[0])
+ {
+ *mode = LYNQ_WIFI_MODE_80211BG;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
+{
+ int ret = 0;
+ if(LYNQ_WIFI_BANDWIDTH_HT20 == bandwidth)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "0");
+ }
+ else if(LYNQ_WIFI_BANDWIDTH_HT40 == bandwidth)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "1");
+ }
+ else if(LYNQ_WIFI_BANDWIDTH_HT80 == bandwidth)
+ {
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "2");
+ }
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+
+}
+
+int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == bandwidth)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "vht_oper_chwidth", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if('0' == value[0])
+ {
+ *bandwidth = LYNQ_WIFI_BANDWIDTH_HT20;
+ }
+ else if ('1' == value[0])
+ {
+ *bandwidth = LYNQ_WIFI_BANDWIDTH_HT40;
+ }
+ else if ('2' == value[0])
+ {
+ *bandwidth = LYNQ_WIFI_BANDWIDTH_HT80;
+ }
+
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx,const char* country_code, int channel)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == country_code)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "country_code", country_code);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ sprintf(value, "%d", channel);
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "channel", value);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx,char* country_code, int* channel)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == country_code || NULL ==channel)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "country_code", country_code, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "channel", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ *channel = atoi(value);
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char * auth_passwd)
+{
+ int ret = 0;
+
+ if(NULL == auth_passwd)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa", "2");
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_key_mgmt", "WPA-PSK");
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_passphrase", auth_passwd);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+
+}
+
+int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char * auth_passwd)
+{
+ int ret = 0;
+
+ if(NULL == auth_mode || NULL == auth_passwd)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_passwd, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t* auth_mode)
+{
+ int ret = 0;
+
+ if(NULL == auth_mode)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_mode->passwd, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ sprintf(value, "%d", max_sta_num);
+ ret = mbtk_wifi_set_setting(SETTING_FILE, "max_num_sta", value);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int* max_sta_num)
+{
+ int ret = 0;
+ char value[SETTING_VALUE_MAX_LEN] = {0};
+
+ if(NULL == max_sta_num)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ ret = mbtk_wifi_get_setting(SETTING_FILE, "max_num_sta", value, SETTING_VALUE_MAX_LEN);
+
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ *max_sta_num = atoi(value);
+
+ return LYNQ_ERR_SUCCESS;
+
+}
+
+
+
+int qser_wifi_lanhost_get_list(lynq_lanhost_ts* lynq_arrays)
+{
+ if(NULL == lynq_arrays)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ if(0 > mbtk_wifi_get_dhcp((mbtk_lanhost_ts*)lynq_arrays))
+ {
+ LOGE("qser wifi get lanhost fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+
+ if(0 > mbkt_wifi_get_uptime((mbtk_lanhost_ts*)lynq_arrays))
+ {
+ LOGE("qser wifi get lanhost fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
+{
+ if(NULL == pkt_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
+ {
+ LOGE("qser wifi get pkt fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
+{
+ int ret = 0;
+
+ if(LYNQ_WIFI_AP_INDEX_AP0 == idx)
+ {
+ ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP0);
+ }
+ else
+ {
+ ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP1);
+ }
+ LOGI("qser_wifi_ap_start set hw_mode ret:%d\n", ret);
+ if(0 > ret)
+ {
+ LOGE("qser wifi fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ if(0 > mbtk_wifi_ap_start())
+ {
+ return LYNQ_ERR_FAIL;
+ }
+
+
+ g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLED;
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
+{
+ if(0 > mbtk_wifi_ap_stop())
+ {
+ return LYNQ_ERR_FAIL;
+ }
+
+ g_ap_status = LYNQ_WIFI_AP_STATUS_DISABLING;
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
+{
+ if(0 > mbtk_wifi_ap_stop())
+ {
+ return LYNQ_ERR_FAIL;
+ }
+
+ if(0 > mbtk_wifi_ap_start())
+ {
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
+{
+ if(NULL != event_handle_sta)
+ {
+ g_event_handle_sta_cb = event_handle_sta;
+
+ }
+ else
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
+{
+ if(NULL == param_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ sta_cli_ssid_set(param_stat->ssid);
+ sta_cli_psk_set(param_stat->passwd);
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
+{
+ int len = 0;
+
+ if(NULL == param_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ sta_cli_ssid_get(param_stat->ssid);
+ len = strlen(param_stat->ssid);
+ param_stat->ssid[len - 1] = '\0';
+ sta_cli_psk_get(param_stat->passwd);
+ len = strlen(param_stat->passwd);
+ param_stat->passwd[len - 1] = '\0';
+
+ LOGE("ssid: %s, passwd: %s", param_stat->ssid, param_stat->passwd);
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_sta_start(void)
+{
+ char reply[STA_BUF_SIZE];
+
+ if(sta_cli_cmd_parse("ADD_NETWORK", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+
+ if(sta_cli_cmd_parse("SELECT_NETWORK", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+ if(sta_cli_cmd_parse("ENABLE_NETWORK", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+ if(0 > system("udhcpc -i wlan0"))
+ {
+ return LYNQ_ERR_FAIL;
+ }
+
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_sta_stop(void)
+{
+ char reply[STA_BUF_SIZE];
+
+ if(sta_cli_cmd_parse("DISABLE_NETWORK", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+ if(sta_cli_cmd_parse("REMOVE_NETWORK", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+int qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
+{
+ char reply[STA_BUF_SIZE];
+ int i = 0, j = 0;
+ int status_flag = 0;
+
+ if(NULL == status_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ if(sta_cli_cmd_parse("STATUS", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+
+ for(i = 0; i < strlen(reply); i++)
+ {
+ if(',' == reply[i])
+ {
+ j = 0;
+ status_flag++;
+ continue;
+ }
+
+ if(0 == status_flag)
+ {
+ status_stat->status = 4;
+ j++;
+ }
+ else if(1 == status_flag)
+ {
+ status_stat->ap_bssid[j] = reply[i];
+ j++;
+ }
+ else if(2 == status_flag)
+ {
+ status_stat->ifname[j] = reply[i];
+ j++;
+ }
+ else if(8 == status_flag)
+ {
+ status_stat->has_addr = '1';
+ status_stat->addr[0].addr[j] = reply[i];
+ j++;
+ }
+
+
+
+ }
+ LOGE("state:%d, ap_bssid:%s, ifname:%s, has_addr:%c, addr:%s\n", status_stat->status, status_stat->ap_bssid, status_stat->ifname, status_stat->has_addr,
+ status_stat->addr[0].addr);
+
+ return LYNQ_ERR_SUCCESS;
+
+}
+
+
+int qser_wifi_get_sta_pkt_stats(lynq_wifi_pkt_stats_t *pkt_stat)
+{
+ if(NULL == pkt_stat)
+ {
+ LOGE("qser wifi ptr is null");
+ return LYNQ_ERR_BADPARAM;
+ }
+
+ if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
+ {
+ LOGE("qser wifi get pkt fail");
+ return LYNQ_ERR_FAIL;
+ }
+
+ return LYNQ_ERR_SUCCESS;
+}
+
+
+int qser_wifi_sta_start_scan(void)
+{
+ char reply[STA_BUF_SIZE] = {0};
+ lynq_wifi_sta_scan_list_t scan_list = {0};
+ int i = 0, j = 0;
+ int status_flag = 0;
+
+ if(sta_cli_cmd_parse("SCAN", reply, STA_BUF_SIZE))
+ {
+ if(strlen(reply) > 0)
+ {
+ LOGE("reply data(%s).\n",reply);
+ }else
+ {
+ LOGE("No reply data\n");
+ }
+ }
+ else
+ {
+ LOGE("Parse cmd fail.\n");
+ }
+
+
+
+ scan_list.cnt = 1;
+
+ for(i = 0; i < strlen(reply); i++)
+ {
+ if(',' == reply[i])
+ {
+ j = 0;
+ status_flag++;
+ continue;
+ }
+
+ if(0 == status_flag)
+ {
+ scan_list.info[0].bssid[j] = reply[i];
+ j++;
+ }
+ else if(1 == status_flag)
+ {
+ //scan_list.info[0].bssid = reply[i];
+ j++;
+ }
+ else if(2 == status_flag)
+ {
+ //scan_list.info[0].signal = atoi(reply[i]);
+ j++;
+ }
+ else if(4 == status_flag)
+ {
+ scan_list.info[0].essid[j] = reply[i];
+ j++;
+ }
+
+
+
+ }
+
+
+
+ g_event_handle_sta_cb(&scan_list);
+ return LYNQ_ERR_SUCCESS;
+}
+
+/*
+ void lynq_wifi_event_handle_demo(lynq_wifi_event_s *event, void *arg)
+ {
+ if(event->id == LYNQ_WIFI_EVENT_AP_STATION)
+ LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
+ else if(event->id == LYNQ_WIFI_EVENT_AP_STA_STATUS)
+ LOGE("[lynq-wifi-demo] %s:event-id = %d,%d,%s,%s\n", __func__, event->id,
+ event->ap_sta_info.connected, event->ap_sta_info.mac,event->ap_sta_info.hostname);
+ if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
+ LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
+ else
+ return;
+ }
+ */
+
+ void lynq_wifi_event_handle_sta_demo(lynq_wifi_sta_scan_list_t *event)
+ {
+ int i = 0;
+ if(NULL == event)
+ {
+ LOGE("qser wifi ptr is null");
+ return;
+ }
+
+ for (i = 0; i < event->cnt; i++)
+ {
+ LOGE("[lynq-wifi-demo] %s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i,
+ event->info[i].essid, event->info[i].auth,
+ event->info[i].cipher, event->info[i].channel, event->info[i].bssid,
+ event->info[i].signal_level,event->info[i].frequency,event->info[i].signal);
+ }
+ }
+
+
+
+