Add mbtk/liblynq_lib_v2/ mbtk/libql_lib_v2/
Change-Id: Idbb802cd805b34603ccf65bff9818725a6955e51
diff --git a/mbtk/liblynq_lib_v2/Makefile b/mbtk/liblynq_lib_v2/Makefile
new file mode 100755
index 0000000..e756641
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/Makefile
@@ -0,0 +1,68 @@
+BUILD_ROOT = $(shell pwd)/..
+include $(BUILD_ROOT)/Make.defines
+
+LOCAL_PATH=$(BUILD_ROOT)/lynq_lib_v2
+
+INC_DIR +=
+
+LIB_DIR +=
+
+#LIBS += -llog -lmbtk_lib
+LIBS += -lmbtk_lib -lrilutil -lprop2uci -lmtel -laudio-apu -lcutils -ltinyalsa -lacm -llog -ljson-c -lblobmsg_json
+LIBS += -lmbtk_audio -lmbtk_ril -lmbtk_fota -lmbtk_factory -lmbtk_net -lmbtk_gnss
+
+CFLAGS += -shared -Wl,-shared,-Bsymbolic
+
+DEFINE +=
+
+MY_FILES_PATH:=$(LOCAL_PATH)/src
+#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
+
+#LOCAL_SRC_FILES = $(wildcard src/*.c) $(wildcard src/*.cpp)
+LOCAL_SRC_FILES = src/lynq_adc.c \
+ src/lynq_alarm.c \
+ src/lynq_data_call.c \
+ src/lynq_fota.c \
+ src/lynq_gpio.c \
+ src/lynq_irq.c \
+ src/lynq_log.c \
+ src/lynq_net_light.c \
+ src/lynq_network.c \
+ src/lynq_sim.c \
+ src/lynq_sleep.c \
+ src/lynq_sms.c \
+ src/lynq_thermal.c \
+ src/lynq_time.c \
+ src/lynq_voice_call.c \
+ src/lynq_chip_id.c \
+ src/lynq_gnss.c
+
+ifeq ($(BUILD_PLATFORM), v2102)
+LOCAL_SRC_FILES += src/lynq_audio.c
+endif
+
+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 $@
+
+%.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_v2/src/lynq_adc.c b/mbtk/liblynq_lib_v2/src/lynq_adc.c
new file mode 100755
index 0000000..4317e17
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_adc.c
@@ -0,0 +1,34 @@
+#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;
+#if defined(MBTK_PROJECT_T108) || defined(MBTK_PROJECT_L508_X6)
+ case ADC2:
+ adc = MBTK_ADC2;
+ break;
+#endif
+ default:
+ LOGE("Unsupport adc : %d", qadc);
+ return -1;
+ }
+
+ return mbtk_adc_get(adc);
+}
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_alarm.c b/mbtk/liblynq_lib_v2/src/lynq_alarm.c
new file mode 100755
index 0000000..461a045
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_alarm.c
@@ -0,0 +1,88 @@
+#include <math.h>
+#include <stdlib.h>
+
+#include "mbtk_alarm.h"
+#include "lynq_alarm.h"
+#include "mbtk_str.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;
+}
+
+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;
+ }
+
+ return -1;
+}
+
+//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 %d -m on &", time_sec);
+ 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_v2/src/lynq_audio.c b/mbtk/liblynq_lib_v2/src/lynq_audio.c
new file mode 100755
index 0000000..259661e
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/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_v2/src/lynq_chip_id.c b/mbtk/liblynq_lib_v2/src/lynq_chip_id.c
new file mode 100755
index 0000000..10e21c9
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_chip_id.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <time.h>
+#include "mbtk_info_api.h"
+
+int lynq_get_time_sec(char *time_t)
+{
+ struct timeval tv;
+ int ret=gettimeofday(&tv,NULL);
+ sprintf(time_t, "%ld", tv.tv_sec);
+ return 0;
+}
+
+int lynq_imet_get(char *imei_t)
+{
+ static mbtk_info_handle_t* info_handle = NULL;
+ info_handle = mbtk_info_handle_get();
+ if(!info_handle)
+ {
+ 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(!ret)
+ {
+ sprintf(chip_id,"%s%s",imei, time);
+// printf("%s\n",chip_id );
+ }
+ else{
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_data_call.c b/mbtk/liblynq_lib_v2/src/lynq_data_call.c
new file mode 100755
index 0000000..73e4692
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_data_call.c
@@ -0,0 +1,867 @@
+#include "lynq-qser-data.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+
+#include <pthread.h>
+#include <cutils/properties.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+/****************************DEFINE***************************************/
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+
+#define MBTK_INFO_ERR_CID_EXIST 311
+#define MBTK_INFO_ERR_CID_NO_EXIST 312
+#define MBTK_INFO_ERR_NO_APN 500
+
+#define QSER_APN_NUM 8
+//default range: 0 - 7
+//AT+CGACT range: 1 - 8
+//1 default IDX, 8 IMS IDX
+#if defined(MBTK_ALL_CID_SUPPORT)
+#if defined(MBTK_SG_SUPPORT)
+#define QSER_PROFILE_IDX_MIN 0
+#else
+#define QSER_PROFILE_IDX_MIN 1
+#endif
+#else
+#define QSER_PROFILE_IDX_MIN 1
+#endif
+#define QSER_PROFILE_IDX_MAX 6
+
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+mbtk_info_handle_t* qser_info_handle = NULL;
+int qser_info_handle_num = 0;
+static bool inited = FALSE;
+static qser_data_call_evt_cb_t qser_net_status_cb = NULL;
+/****************************VARIABLE***************************************/
+
+/******************************FUNC*****************************************/
+static int qser_apn_info_param_convert(int profile_idx, qser_apn_info_s *new_apn, mbtk_qser_apn_info_s *old_apn)
+{
+ if(new_apn == NULL || old_apn == NULL)
+ {
+ LOGE("[qser_data] qser_apn_info_param_convert apn param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ memset(new_apn, 0x0, sizeof(qser_apn_info_s));
+ new_apn->profile_idx = old_apn->cid - 1;
+ //get ip type
+ if(old_apn->ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6
+ {
+ new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4V6;
+ }
+ else if(old_apn->ip_type == MBTK_IP_TYPE_IP) // IPV4
+ {
+ new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4;
+ }
+ else if(old_apn->ip_type == MBTK_IP_TYPE_IPV6) // IPV6
+ {
+ new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV6;
+ }
+ else
+ {
+ new_apn->pdp_type = QSER_APN_PDP_TYPE_PPP;
+ }
+
+ //get apn name
+ if(strlen((char *)old_apn->apn_name) > QSER_APN_NAME_SIZE)
+ {
+ LOGE("[qser_data] apn_nmea length verylong.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(strlen((char *)old_apn->apn_name) > 0)
+ {
+ memcpy(new_apn->apn_name, old_apn->apn_name,strlen((char *)old_apn->apn_name));
+ }
+ }
+
+ //get apn user
+ if(strlen((char *)old_apn->user_name) > QSER_APN_USERNAME_SIZE)
+ {
+ LOGE("[qser_data] apn_user length verylong.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(strlen((char *)old_apn->user_name) > 0)
+ {
+ memcpy(new_apn->username, old_apn->user_name, strlen((char *)old_apn->user_name));
+ }
+ }
+
+ //get apn password
+ if(strlen((char *)old_apn->user_pass) > QSER_APN_PASSWORD_SIZE)
+ {
+ LOGE("[qser_data] apn_password length verylong.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(strlen((char *)old_apn->user_pass) > 0)
+ {
+ memcpy(new_apn->password, old_apn->user_pass, strlen((char *)old_apn->user_pass));
+ }
+ }
+
+ //get apn proto
+ new_apn->auth_proto = (qser_apn_auth_proto_e)old_apn->auth_proto;
+
+ //get apn type
+ if(strlen((char *)old_apn->apn_type) > QSER_APN_PASSWORD_SIZE)
+ {
+ LOGE("[qser_data] apn_type length verylong.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(strlen((char *)old_apn->apn_type) > 0)
+ {
+ memcpy(new_apn->apn_type, old_apn->apn_type, strlen((char *)old_apn->apn_type));
+ }
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+static void qser_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));
+ }
+}
+
+void qser_wan_net_state_change_cb(const void* data, int data_len)
+{
+ if(data == NULL || data_len == 0)
+ {
+ return;
+ }
+
+ uint8 *net_data = NULL;
+ net_data = (uint8 *)data;
+
+ if(*net_data > 100 && *net_data < 200)
+ {
+ int idx = *net_data - 101;
+ if(idx <= QSER_PROFILE_IDX_MAX)
+ {
+ qser_data_call_state_s state = {0};
+ qser_state_init(&state);
+ state.profile_idx = idx;
+ state.state = QSER_DATA_CALL_DISCONNECTED;
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
+ }
+ else
+ {
+ LOGE("[qser_data] cb fail,idx is %d.", idx);
+ }
+
+ }
+ else if(*net_data > 200 && *net_data < 220)
+ {
+ LOGE("[qser_data] cid[%d] is open.", *net_data - 201);
+ }
+ else if(*net_data > 220)
+ {
+ LOGE("[qser_data] cid[%d] is reopen.", *net_data - 221);
+ int idx = *net_data - 221;
+ if(idx <= QSER_PROFILE_IDX_MAX)
+ {
+ qser_data_call_state_s state = {0};
+ qser_state_init(&state);
+ state.profile_idx = idx;
+ state.state = QSER_DATA_CALL_CONNECTED;
+ snprintf(state.name, 16, "ccinet%d", idx);
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
+ }
+ }
+ else if(*net_data == 1)
+ {
+ LOGE("[qser_data] pdp is open.");
+ }
+ else
+ {
+ LOGE("[qser_data] unkonwn param [%d].", *net_data);
+ }
+}
+
+static void* data_call_async_thread(void* arg)
+{
+ LOGE("[qser_data] entry data_call_async_thread.");
+ qser_data_call_error_e err = QSER_DATA_CALL_ERROR_NONE;
+
+ qser_data_call_s qser_data_backup = {0};
+ qser_data_call_info_s info = {0};
+ if(arg != NULL)
+ {
+ memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s));
+ }
+ else
+ {
+ LOGE("[qser_data] arg is NULL.");
+ }
+
+ qser_data_call_state_s state = {0};
+ qser_state_init(&state);
+ 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;
+
+ int ret = qser_data_call_start(&qser_data_backup, &err);
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_data] qser_data_call_start() fail.");
+ 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 != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_data] qser_data_call_info_get() fail.");
+ 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(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
+ return NULL;
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
+{
+ //UNUSED(evt_cb);
+ if(!inited && qser_info_handle == NULL)
+ {
+ qser_info_handle = mbtk_info_handle_get();
+ if(qser_info_handle)
+ {
+ qser_info_handle_num++;
+ inited = TRUE;
+ mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
+ }
+ else
+ {
+ LOGE("[qser_data] mbtk_info_handle_get() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ if(!inited)
+ {
+ qser_info_handle_num++;
+ inited = TRUE;
+ mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
+ }
+ }
+ qser_net_status_cb = evt_cb;
+
+ LOGE("[qser_data] mbtk_info_handle_get() success.");
+ return QSER_RESULT_SUCCESS;
+}
+
+void qser_data_call_destroy(void)
+{
+ if(qser_info_handle)
+ {
+ LOGE("[qser_data] qser_info_handle_num = %d", qser_info_handle_num);
+ if(qser_info_handle_num == 1)
+ { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&qser_info_handle);
+ if(ret)
+ {
+ LOGE("[qser_data] mbtk_info_handle_free() fail.");
+ }
+ else
+ {
+ qser_info_handle_num = 0;
+ qser_info_handle = NULL;
+ qser_net_status_cb = NULL;
+ inited = FALSE;
+ }
+ }
+ else
+ {
+ qser_info_handle_num--;
+ qser_net_status_cb = NULL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_data] handle not inited.");
+ }
+}
+
+int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
+{
+ //UNUSED(data_call);
+ //UNUSED(err);
+ if(data_call == NULL || err == NULL)
+ {
+ LOGE("[qser_data] data_call or err is NULL.");
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = -1;
+ ret = mbtk_data_call_start(qser_info_handle, data_call->profile_idx + 1, 0, FALSE, 0);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_data_call_start fail.[ret = %d]", ret);
+ if(ret == MBTK_INFO_ERR_CID_EXIST)
+ {
+ *err = QSER_DATA_CALL_ERROR_PDP_ACTIVATE;
+ }
+ else
+ {
+ *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)
+{
+ //UNUSED(data_call);
+ UNUSED(err);
+ if(data_call == NULL || err == NULL)
+ {
+ LOGE("[qser_data] data_call or err is NULL.");
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_FAIL;
+ }
+
+ pthread_attr_t thread_attr;
+ pthread_t data_call_thread_id;
+ pthread_attr_init(&thread_attr);
+ if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+ {
+ LOGE("[qser_data] pthread_attr_setdetachstate() fail.");
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ return QSER_RESULT_FAIL;
+ }
+
+ //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s));
+ if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, (void *) data_call))
+ {
+ LOGE("[qser_data] pthread_create() fail.");
+ *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(profile_idx);
+ UNUSED(ip_family);
+ //UNUSED(err);
+ if(err == NULL)
+ {
+ LOGE("[qser_data] err is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = -1;
+ ret = mbtk_data_call_stop(qser_info_handle, profile_idx + 1, 15);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_data_call_stop fail.[ret = %d]", ret);
+ if(ret == MBTK_INFO_ERR_CID_NO_EXIST)
+ {
+ *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE;
+ }
+ else
+ {
+ *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(profile_idx);
+ UNUSED(ip_family);
+ //UNUSED(info);
+ //UNUSED(err);
+
+ if(info == NULL || err == NULL)
+ {
+ LOGE("[qser_data] info or err is NULL.");
+ if(err != NULL)
+ {
+ *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+ }
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ *err = QSER_DATA_CALL_ERROR_NO_INIT;
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = -1;
+ mbtk_ipv4_info_t ipv4;
+ mbtk_ipv6_info_t ipv6;
+#ifdef QSER_TEST
+ char v4_buff[32] = {0};
+ char v6_buff[128] = {0};
+#endif
+ memset(info, 0, sizeof(qser_data_call_info_s));
+ ret = mbtk_data_call_state_get(qser_info_handle, profile_idx + 1, &ipv4, &ipv6);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_data_call_state_get fail.[ret = %d]", ret);
+ if(ret == MBTK_INFO_ERR_CID_NO_EXIST)
+ {
+ *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE;
+ }
+ else
+ {
+ *err = QSER_DATA_CALL_ERROR_UNKNOWN;
+ }
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ info->profile_idx = profile_idx;
+ if(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 = ipv4.IPAddr;
+ info->v4.addr.pri_dns.s_addr = ipv4.PrimaryDNS;
+ info->v4.addr.sec_dns.s_addr = ipv4.SecondaryDNS;
+
+#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(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), &(ipv6.IPV6Addr), sizeof(ipv6.IPV6Addr));
+ memcpy(&(info->v6.addr.pri_dns), &(ipv6.PrimaryDNS), sizeof(ipv6.PrimaryDNS));
+ memcpy(&(info->v6.addr.sec_dns), &(ipv6.SecondaryDNS), sizeof(ipv6.SecondaryDNS));
+#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(ipv4.valid && ipv6.valid)
+ {
+ info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
+ }
+
+ if(!ipv4.valid && !ipv6.valid)
+ {
+ info->v4.state = QSER_DATA_CALL_DISCONNECTED;
+ info->v6.state = QSER_DATA_CALL_DISCONNECTED;
+ }
+ }
+
+ *err = QSER_DATA_CALL_ERROR_NONE;
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_set(qser_apn_info_s *apn)
+{
+ //UNUSED(apn);
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(apn == NULL)
+ {
+ LOGE("[qser_data] apn param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = 0;
+ mbtk_qser_apn_info_s apninfo;
+ memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s));
+ apninfo.cid = apn->profile_idx + 1;
+
+ if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IP;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IPV6;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IPV4V6;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_PPP;
+ }
+ else
+ {
+ LOGE("[qser_data] pdp_type error.");
+ return QSER_RESULT_FAIL;
+ }
+
+
+ apninfo.req_type = MBTK_APN_REQ_TYPE_SET;
+ apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto;
+ if(strlen(apn->apn_name))
+ {
+ memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name));
+ }
+ else
+ {
+ LOGE("[qser_data] apn_name is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+ if(strlen(apn->username))
+ {
+ memcpy(apninfo.user_name, apn->username, strlen(apn->username));
+ }
+ if(strlen(apn->password))
+ {
+ memcpy(apninfo.user_pass, apn->password, strlen(apn->password));
+ }
+ if(strlen(apn->apn_type))
+ {
+ memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type));
+ }
+ ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, NULL);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_qser_apn_set fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
+{
+ //UNUSED(profile_idx);
+ //UNUSED(apn);
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(apn == NULL)
+ {
+ LOGE("[qser_data] apn param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ //get apn info
+ mbtk_qser_apn_info_s apns[10] = {0};
+ int apn_num = 10;
+ int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ int i = 0;
+ for(i = 0; i < apn_num; i++)
+ {
+ if(apns[i].cid == profile_idx + 1)
+ {
+ LOGE("[qser_data] find IDX.");
+ break;
+ }
+ }
+
+ if(i == apn_num)
+ {
+ LOGE("[qser_data] not find IDX.[apn_num = %d]", apn_num);
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_apn_info_param_convert(profile_idx, apn, &apns[i]) != 0)
+ {
+ LOGE("[qser_data] qser_apn_info_param_convert fail");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
+{
+ //UNUSED(apn);
+ //UNUSED(profile_idx);
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(apn == NULL || profile_idx == NULL)
+ {
+ LOGE("[qser_data] apn param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = 0;
+ unsigned char idx[2] = {0};
+ mbtk_qser_apn_info_s apninfo;
+ memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s));
+ apninfo.cid = 0;
+
+ if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IP;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IPV6;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_IPV4V6;
+ }
+ else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP)
+ {
+ apninfo.ip_type = MBTK_IP_TYPE_PPP;
+ }
+ else
+ {
+ LOGE("[qser_data] pdp_type error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ apninfo.req_type = MBTK_APN_REQ_TYPE_ADD;
+ apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto;
+ if(strlen(apn->apn_name))
+ {
+ memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name));
+ }
+
+ if(strlen(apn->username))
+ {
+ memcpy(apninfo.user_name, apn->username, strlen(apn->username));
+ }
+ if(strlen(apn->password))
+ {
+ memcpy(apninfo.user_pass, apn->password, strlen(apn->password));
+ }
+ if(strlen(apn->apn_type))
+ {
+ memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type));
+ }
+ ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, idx);
+ if(ret != 0)
+ {
+ LOGE("[qser_data] mbtk_qser_apn_set fail.");
+ return QSER_RESULT_FAIL;
+ }
+ *profile_idx = idx[0] - 1;
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_del(unsigned char profile_idx)
+{
+ int ret = 0;
+
+ //UNUSED(profile_idx);
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_apn_del(qser_info_handle, profile_idx);
+ if(ret < 0)
+ {
+ LOGE("[qser_data] mbtk_apn_del fail!");
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_apn_get_list(qser_apn_info_list_s *apn_list)
+{
+ //UNUSED(apn_list);
+
+ if(qser_info_handle == NULL)
+ {
+ LOGE("[qser_data] handle is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(apn_list == NULL)
+ {
+ LOGE("[qser_data] apn_list param is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ mbtk_qser_apn_info_s apns[10] = {0};
+ int apn_num = 10;
+ int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns);
+ if(ret != 0)
+ {
+ if(ret == MBTK_INFO_ERR_NO_APN)
+ {
+ apn_list->cnt = 0;
+ return QSER_RESULT_SUCCESS;
+ }
+ LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret);
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ if(apn_num > 0 && apn_num <= QSER_APN_MAX_LIST)
+ {
+ int i = 0;
+ apn_list->cnt = 0;
+ for(i = 0; i < apn_num; i++)
+ {
+ if(qser_apn_info_param_convert(apns[i].cid - 1, &apn_list->apn[apn_list->cnt], &apns[i]) != 0)
+ {
+ LOGE("[qser_data] qser_apn_info_param_convert fail");
+ return QSER_RESULT_FAIL;
+ }
+ apn_list->cnt++;
+ }
+ }
+ else if(apn_num > QSER_APN_MAX_LIST)
+ {
+ LOGE("[qser_data] apn_num overlong");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ apn_list->cnt = 0;
+ }
+ }
+ return QSER_RESULT_SUCCESS;
+}
+/****************************API***************************************/
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_fota.c b/mbtk/liblynq_lib_v2/src/lynq_fota.c
new file mode 100755
index 0000000..1ac1b68
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_fota.c
@@ -0,0 +1,111 @@
+#include "lynq-qser-fota.h"
+#include "mbtk_type.h"
+#include "mbtk_fota.h"
+
+
+char addr_buf[128]={0};
+int segment_size =0;
+
+
+int Process_flag = 0;
+
+
+int fota_cb(int status, int percent)
+{
+// printf("%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);
+ printf("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ printf("addr_buf:%s, segment_size:%d\n", addr_buf, segment_size);
+ ret = mbtk_fota_init(fota_cb);
+ if(!strcmp(addr_buf, "http"))
+ {
+
+ 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)
+ {
+ printf("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);
+ printf("111%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;
+
+ printf("addr_buf:%s, value:%s\n", addr_buf, value);
+ printf("segment_size:%d, size:%d\n", segment_size, size);
+
+ return 0;
+}
+
+int lynq_fota_nrestart(void)
+{
+ printf("%s, %d", __FUNCTION__, __LINE__);
+ int ret = 0;
+
+ ret = mbtk_fota_init(fota_cb);
+ if(!strcmp(addr_buf, "http"))
+ {
+ 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)
+ {
+ printf("lynq_fota_nrestart fail\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int lynq_get_upgrade_status(void)
+{
+ printf("%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_v2/src/lynq_gnss.c b/mbtk/liblynq_lib_v2/src/lynq_gnss.c
new file mode 100755
index 0000000..2bb1fc1
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_gnss.c
@@ -0,0 +1,485 @@
+#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
+
+/**********************************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.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ LOGE("[qser_gnss] mbtk_gnss_init() fail.");
+ 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.");
+ 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.");
+ 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.");
+ 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.");
+ 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;
+ }
+
+ if(host != NULL)
+ {
+ memcpy(qser_agps_info_save.host, host, QSER_LEN_MAX);
+ }
+
+ if(id != NULL)
+ {
+ memcpy(qser_agps_info_save.id, id, QSER_LEN_MAX);
+ }
+
+ if(password != NULL)
+ {
+ memcpy(qser_agps_info_save.passwd, password, QSER_LEN_MAX);
+ }
+ return QSER_RESULT_SUCCESS;
+}
+
+int qser_Gnss_download_tle()
+{
+ if(!inited)
+ {
+ LOGE("[qser_gnss] api not init.");
+ 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;
+ }
+ 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;
+ length = 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.");
+ return QSER_RESULT_FAIL;
+ }
+ return QSER_RESULT_SUCCESS;
+}
+/**********************************API***********************************/
+
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_gpio.c b/mbtk/liblynq_lib_v2/src/lynq_gpio.c
new file mode 100755
index 0000000..4dcd694
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_gpio.c
@@ -0,0 +1,339 @@
+#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;
+}
+
+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;
+}
+
+
+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];
+ char path[10];
+ int file =-1;
+ int result =-1;
+ int value;
+
+ memset(path,0,50);
+ memset(buffer,0,10);
+ sprintf(path,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(path,O_RDONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] fail.", gpio);
+ return -1;
+ }
+ result = read(file,buffer,5);
+ if(result <= 0)
+ {
+ LOGE("Get gpio[%d] value fail", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+ value = atoi(buffer);
+ return value;
+}
+
+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_v2/src/lynq_irq.c b/mbtk/liblynq_lib_v2/src/lynq_irq.c
new file mode 100755
index 0000000..c6050ae
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_irq.c
@@ -0,0 +1,498 @@
+#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)
+ {
+ return -1;
+ }
+#if defined(MBTK_PROJECT_T108)
+
+ 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;
+ }
+
+#endif
+
+ 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)
+{
+#if defined(MBTK_PROJECT_T108)
+ line = line-117;
+#endif
+
+ int ret;
+ 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)
+{
+#if defined(MBTK_PROJECT_T108)
+ line = line-117;
+
+ if (trig_type != 0 && trig_type != 1)
+ {
+ LOGE("lynq_irq_set_type error trig_type:%d", trig_type);
+ return -1;
+ }
+#endif
+
+ int ret;
+ if(trig_type < 0)
+ {
+ return -1;
+ }
+ 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)
+{
+#if defined(MBTK_PROJECT_T108)
+ line = line-117;
+#endif
+
+ int ret;
+ int trig_type;
+ 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)
+{
+#if defined(MBTK_PROJECT_T108)
+ line = line-117;
+#endif
+
+ int ret;
+ if((en != 0) && (en != 1))
+ {
+ LOGE("wake_state is not 0 or 1");
+ return -1;
+ }
+
+ 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)
+{
+#if defined(MBTK_PROJECT_T108)
+ line = line-117;
+#endif
+
+ int ret;
+ int en;
+ 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_v2/src/lynq_log.c b/mbtk/liblynq_lib_v2/src/lynq_log.c
new file mode 100755
index 0000000..e096f8a
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_log.c
@@ -0,0 +1,494 @@
+#include <stdarg.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include "json-c/json.h"
+#include "lynq_deflog.h"
+#include "mbtk_type.h"
+
+#define LOG_CONFIG_PATH "/etc/mbtk/mbtk_log.json"
+#define SYSLOG_PATCH "syslog"
+#define SYSLOG_NAME "syslog"
+#define SYSLOG_INDEX 0
+
+void lynq_log_configuration_init(const char *log_name)
+{
+ //UNUSED(log_name);
+ mbtk_log_init(SYSLOG_PATCH, 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;
+ 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);
+ 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");
+ 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");
+ 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;
+ 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;
+ 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;
+ 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_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);
+ 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);
+ 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 serverFd,clientFd,addrLen,nwrite,nread;
+ 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;
+}
\ No newline at end of file
diff --git a/mbtk/liblynq_lib_v2/src/lynq_net_light.c b/mbtk/liblynq_lib_v2/src/lynq_net_light.c
new file mode 100755
index 0000000..ee84b71
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_net_light.c
@@ -0,0 +1,140 @@
+#include "lynq_led.h"
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "mbtk_info_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_FAIL -1
+#define QSER_RESULT_SUCCESS 0
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+extern mbtk_info_handle_t* qser_info_handle;
+extern int qser_info_handle_num;
+/****************************VARIABLE***************************************/
+
+
+/******************************FUNC*****************************************/
+static int qser_led_client_init(void)
+{
+ if(qser_info_handle == NULL)
+ {
+ qser_info_handle = mbtk_info_handle_get();
+ if(qser_info_handle)
+ {
+ qser_info_handle_num++;
+ }
+ else
+ {
+ LOGE("[qser_led] mbtk_info_handle_get() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ qser_info_handle_num++;
+ }
+
+ LOGE("[qser_led] mbtk_info_handle_get() success.");
+ return QSER_RESULT_SUCCESS;
+}
+
+static int qser_led_client_deinit(void)
+{
+ if(qser_info_handle)
+ {
+ LOGE("[qser_led] qser_info_handle_num = %d", qser_info_handle_num);
+ if(qser_info_handle_num == 1)
+ { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&qser_info_handle);
+ if(ret)
+ {
+ LOGE("[qser_led] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle_num = 0;
+ qser_info_handle = NULL;
+ }
+ }
+ else
+ {
+ qser_info_handle_num--;
+ }
+ }
+ else
+ {
+ LOGE("[qser_led] handle not inited.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int lynq_set_netled_on(int led_mode)
+{
+ //UNUSED(led_mode);
+
+ if(led_mode != 0 && led_mode != 1)
+ {
+ LOGE("[qser_led]param is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+
+ int ret = qser_led_client_init();
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_led]qser_led_client_init fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_led_set(qser_info_handle, MBTK_LED_TYPE_NET, led_mode);
+ if(ret != 0)
+ {
+ LOGE("[qser_led]mbtk_led_gpio_init fail.");
+ qser_led_client_init();
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = qser_led_client_init();
+
+ return QSER_RESULT_SUCCESS;
+}
+
+int lynq_set_statusled_on(int led_mode)
+{
+ //UNUSED(led_mode);
+
+ if(led_mode != 0 && led_mode != 1)
+ {
+ LOGE("[qser_led]param is fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = qser_led_client_init();
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_led]qser_led_client_init fail.");
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = mbtk_led_set(qser_info_handle, MBTK_LED_TYPE_STATUS, led_mode);
+ if(ret != 0)
+ {
+ LOGE("[qser_led]mbtk_led_gpio_init fail.");
+ qser_led_client_init();
+ return QSER_RESULT_FAIL;
+ }
+
+ ret = qser_led_client_init();
+
+ return QSER_RESULT_SUCCESS;
+}
+/****************************API***************************************/
+
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_network.c b/mbtk/liblynq_lib_v2/src/lynq_network.c
new file mode 100755
index 0000000..be3816e
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_network.c
@@ -0,0 +1,1225 @@
+#include "lynq_qser_network.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+#include "mbtk_log.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+mbtk_info_handle_t* lynq_nw_info_handle = NULL;
+uint64_t tmp_mode = 0xFF;
+
+nw_client_handle_type g_nw_val = -1;
+
+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[] =
+{
+ {"China Mobile","CMCC",46000},
+ {"China Unicom","CU",46001},
+ {"China Mobile","CMCC",46002},
+ {"China Telecom","CT",46003},
+ {"China Mobile","CMCC",46004},
+ {"China Telecom","CT",46005},
+ {"China Unicom","CU",46006},
+ {"China Mobile","CMCC",46007},
+ {"China Mobile","CMCC",46008},
+ {"China Unicom","CU",46009},
+ {"China Telecom","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
+
+
+
+void lynq_signal_state_change_cb(const void* data, int data_len)
+{
+#if 0
+
+/*
+ uint8 *net_data = NULL;
+
+ net_data = (uint8*)data;
+
+ if(data && data_len > 0)
+ {
+ if(*net_data == 0)
+ { // CS
+ printf("CS:act=%d, mode=%d\n", *(net_data + 1), *(net_data + 2));
+ }
+ else
+ { // PS
+ printf("PS[%s]:act=%d, mode=%d\n", *(net_data + 3) == 0 ? "GSM/WCDMA" : "LTE", *(net_data + 1), *(net_data + 2));
+ }
+ }
+ else
+ {
+ printf("NET_CB : NULL");
+ }
+*/
+
+ if(s_handlerPtr != NULL)//数据原样输出
+ {
+ s_handlerPtr(g_nw_val, NW_IND_DATA_REG_EVENT_IND_FLAG, data, data_len, NULL);
+ }
+#endif
+
+ /*
+ 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;
+ */
+
+ uint8 *net_data = NULL;
+ QSER_NW_SINGNAL_EVENT_IND_T msg_buf;
+
+ if(data && data_len > 0)
+ {
+ net_data = (uint8*)data;
+ //printf("net_data[0] => *net_data =%d\n",*net_data);
+ msg_buf.gsm_sig_info_valid = FALSE;
+ msg_buf.lte_sig_info_valid = FALSE;
+ msg_buf.wcdma_sig_info_valid = FALSE;
+
+ if(*net_data == MBTK_RADIO_TECH_GSM || *net_data == MBTK_RADIO_TECH_GSM_COMPACT || \
+ *net_data == MBTK_RADIO_TECH_GSM_EGPRS) //GSM
+ {
+ msg_buf.gsm_sig_info_valid = TRUE;
+ msg_buf.gsm_sig_info.rssi = *(net_data + 1);
+ }
+ else if(*net_data == MBTK_RADIO_TECH_E_UTRAN) //LTE
+ {
+ msg_buf.lte_sig_info_valid = TRUE;
+ msg_buf.lte_sig_info.rssi = *(net_data + 1);
+ msg_buf.lte_sig_info.rsrp = *(net_data + 7);//signalstrength.rsrp;
+ msg_buf.lte_sig_info.rsrq = *(net_data + 6);//signalstrength.rsrq;
+ msg_buf.lte_sig_info.snr = 0x7FFFFFFFF; //signalstrength.rssnr;(当前mbtk没有该参数)
+ }
+ else if (*net_data == MBTK_RADIO_TECH_UTRAN || *net_data == MBTK_RADIO_TECH_UTRAN_HSDPA || \
+ *net_data == MBTK_RADIO_TECH_UTRAN_HSUPA || *net_data == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA || \
+ *net_data == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
+ {
+ msg_buf.wcdma_sig_info_valid = TRUE;
+ msg_buf.wcdma_sig_info.rssi = *(net_data + 1);//signalstrength.rssi;
+ msg_buf.wcdma_sig_info.ecio = *(net_data + 5);//signalstrength.ecno;
+ }
+
+ //msg_buf.gsm_sig_info_valid = TRUE;//signalstrength.gw_sig_valid;
+ //msg_buf.gsm_sig_info.rssi = *(net_data + 1);//signalstrength.rssi;
+ //printf("rssi = %d\n", *(net_data + 1));
+ //msg_buf.wcdma_sig_info_valid = TRUE;//.wcdma_sig_valid;
+ //msg_buf.wcdma_sig_info.rssi = *(net_data + 1);//signalstrength.rssi;
+ //printf("rscp = %d\n", *(net_data + 4));
+ //msg_buf.wcdma_sig_info.ecio = *(net_data + 5);//signalstrength.ecno;
+ //printf("ecno = %d\n", *(net_data + 5));
+ //msg_buf.lte_sig_info_valid = TRUE;//signalstrength.lte_sig_valid;
+ //msg_buf.lte_sig_info.rssi = *(net_data + 1);
+ //msg_buf.lte_sig_info.rsrp = *(net_data + 7);//signalstrength.rsrp;
+ //printf("rsrp = %d\n", *(net_data + 7));
+ //msg_buf.lte_sig_info.rsrq = *(net_data + 6);//signalstrength.rsrq;
+ //printf("rsrq = %d\n", *(net_data + 6));
+ //msg_buf.lte_sig_info.snr = 0x7FFFFFFFF; //signalstrength.rssnr;(当前mbtk没有该参数)
+ msg_buf.tdscdma_sig_info_valid = FALSE;
+ msg_buf.cdma_sig_info_valid = FALSE;
+ msg_buf.hdr_sig_info_valid = FALSE;
+ msg_buf.nr_sig_info_valid = FALSE;//(当前mbtk没有该参数)
+ msg_buf.nr_sig_info.ssRsrp = 0;
+ msg_buf.nr_sig_info.ssRsrq = 0;
+ msg_buf.nr_sig_info.ssSinr = 0;
+ msg_buf.nr_sig_info.csiRsrp = 0;
+ msg_buf.nr_sig_info.csiRsrq = 0;
+ msg_buf.nr_sig_info.csiSinr = 0;
+
+ void *ind_msg_buf= &msg_buf;
+ if(lynq_func_cb_handle.handlerPtr != NULL)
+ {
+ lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG, ind_msg_buf, sizeof (msg_buf), lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_VOICE_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_DATA_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_IMS_REG_EVENT_IND_FLAG, NULL, 0, lynq_func_cb_handle.contextPtr);
+ }
+ }
+ else
+ {
+ LOGE("lynq_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_nw);
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ lynq_nw_info_handle = mbtk_info_handle_get();
+ if(lynq_nw_info_handle)
+ {
+ LOGI("creat lynq_nw_info_handle is success");
+ *ph_nw = lynq_nw_info_handle->client_fd;
+ g_nw_val = lynq_nw_info_handle->client_fd;
+ }
+ else
+ {
+ LOGE("creat lynq_nw_info_handle is fail");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int qser_nw_client_deinit(nw_client_handle_type h_nw)
+{
+ //UNUSED(h_nw);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ mbtk_signal_state_change_cb_reg(lynq_nw_info_handle, NULL);
+
+ if(lynq_nw_info_handle)
+ {
+ mbtk_info_handle_free(&lynq_nw_info_handle);
+ }
+ else
+ {
+ LOGE("deinit lynq_nw_info_handle is fail");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_nw_set_config(nw_client_handle_type h_nw,QSER_NW_CONFIG_INFO_T *pt_info)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_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(lynq_nw_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)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_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(lynq_nw_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, lynq_operator_mcc_mnc[i].lynq_operator_l);
+ strcpy(OperatorSH, 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(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(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)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_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(lynq_nw_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(lynq_nw_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_GPRS;
+ pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_GSM;
+ pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_GPRS;
+ pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_GSM;
+ 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)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_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(lynq_nw_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 = 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 = signal.rsrp;
+ pt_info->lte_sig_info.rsrq = signal.rsrq;
+ pt_info->lte_sig_info.snr = 0x7FFFFFFFF; //->MBTK接口无该参数(对应参数为rssnr,该值INT_MAX:0x7FFFFFFFF表示无效值),写死值为0x7FFFFFFFF
+ pt_info->lte_sig_info.rssi = 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 = signal.rssi;
+ pt_info->wcdma_sig_info.ecio = 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;
+}
+
+void net_state_change_cb(const void* data, int data_len)
+{
+ printf("Recv event indication : NET REG EVENT\n");
+ if(data && data_len > 0) {
+ const uint8 *ptr = (const uint8*)data;
+ if(*ptr == 0) { // CS
+ printf("CS:act=%d, mode=%d\n", *(ptr + 1), *(ptr + 2));
+ } else { // PS
+ printf("PS[%s]:act=%d, mode=%d\n", *(ptr + 3) == 0 ? "GSM/WCDMA" : "LTE", *(ptr + 1), *(ptr + 2));
+ }
+ } else
+ LOGD("ind is NULL");
+}
+
+
+int qser_nw_add_rx_msg_handler (nw_client_handle_type h_nw, QSER_NW_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)
+{
+ //UNUSED(h_nw);
+ //UNUSED(handlerPtr);
+ //UNUSED(contextPtr);
+
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_info_handle == NULL.");
+ return -1;
+ }
+
+ lynq_func_cb_handle.handlerPtr = handlerPtr;
+ lynq_func_cb_handle.contextPtr = contextPtr;
+
+ mbtk_signal_state_change_cb_reg(lynq_nw_info_handle, lynq_signal_state_change_cb);
+ mbtk_net_state_change_cb_reg(lynq_nw_info_handle, net_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)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ 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_oos_info oos_info;
+
+ memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
+
+
+ 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.mode = 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.mode = 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.mode = 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.mode = 0;
+ }
+ else
+ {
+ LOGE("qser_nw_set_oos_config set Format err");
+ return -1;
+ }
+
+ int err = mbtk_oos_set(lynq_nw_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)
+{
+ //UNUSED(h_nw);
+ //UNUSED(pt_info);
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ mbtk_oos_info oos_info;
+ uint32 oosPhase_0, oosPhase_1, oosPhase_2;
+ char cmd[100] = {0};
+
+ memset(&oos_info, 0x00, sizeof(mbtk_oos_info));
+
+ int err = mbtk_oos_get(lynq_nw_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.mode == 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;
+ mbtk_modem_info_t info;
+
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_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;
+ }
+
+ info.fun = rf_mode;
+ info.rst = 0;
+ ret = mbtk_set_modem_fun(lynq_nw_info_handle, &info);
+
+ //ret = mbtk_radio_state_set(lynq_nw_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;
+ int tmp_rf;
+
+ if (h_nw != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_get_modem_fun(lynq_nw_info_handle, &tmp_rf);
+
+ //ret = mbtk_radio_state_get(lynq_nw_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 != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_net_ims_set(lynq_nw_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 != g_nw_val || g_nw_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(lynq_nw_info_handle == NULL)
+ {
+ LOGE("lynq_nw_info_handle == NULL.");
+ return -1;
+ }
+
+ ret = mbtk_net_ims_reg_state_get(lynq_nw_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_v2/src/lynq_sim.c b/mbtk/liblynq_lib_v2/src/lynq_sim.c
new file mode 100755
index 0000000..78af51b
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_sim.c
@@ -0,0 +1,746 @@
+#include "lynq_qser_sim.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_SUCCESS 0
+#define QSER_RESULT_FAIL -1
+
+#define QSER_IMEI_SV_VERSION "01"
+
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+extern mbtk_info_handle_t* qser_info_handle;
+extern int qser_info_handle_num;
+static bool inited = FALSE;
+static 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;
+ LOGE("[qser_sim] SIM state : %d\n", *ptr);
+ QSER_SIM_CARD_STATUS_INFO_T qser_sim_statue = {0};
+ if(*ptr == 0)
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_ABSENT;
+ }
+ else if(*ptr == 1)
+ {
+ qser_sim_statue.e_card_state = QSER_SIM_CARD_STATE_PRESENT;
+ }
+ else if(*ptr == 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_sim);
+ if(ph_sim == NULL)
+ {
+ LOGE("[qser_sim] ph_sim is NULL.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(!inited && qser_info_handle == NULL)
+ {
+ qser_info_handle = mbtk_info_handle_get();
+ if(qser_info_handle)
+ {
+ qser_info_handle_num++;
+ inited = TRUE;
+ //mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
+ }
+ else
+ {
+ LOGE("[qser_sim] mbtk_info_handle_get() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ if(!inited)
+ {
+ qser_info_handle_num++;
+ inited = TRUE;
+ //mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
+ }
+ }
+ *ph_sim = qser_h_sim;
+
+ LOGE("[qser_sim] mbtk_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);
+
+ 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;
+ }
+
+ int err = mbtk_verify_pin(qser_info_handle, pt_info->pin_value);
+ 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);
+
+ 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_change_pin_info pin_info = {0};
+ memcpy(pin_info.old_pin_value, pt_info->old_pin_value, pt_info->old_pin_value_len);
+ memcpy(pin_info.new_pin_value, pt_info->new_pin_value, pt_info->new_pin_value_len);
+ int err = mbtk_change_pin(qser_info_handle, &pin_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);
+
+ 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_unlock_pin_info puk_pin_info = {0};
+ memcpy(puk_pin_info.pin_value, pt_info->new_pin_value, pt_info->new_pin_value_len);
+ memcpy(puk_pin_info.puk_value, pt_info->puk_value, pt_info->puk_value_len);
+ int err = mbtk_unlock_pin(qser_info_handle, &puk_pin_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);
+
+ 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_enable_pin_info pin_info = {0};
+ memcpy(pin_info.pin_value, pt_info->pin_value, pt_info->pin_value_len);
+ pin_info.enable = 1;
+ int err = mbtk_enable_pin(qser_info_handle, &pin_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);
+
+ 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_enable_pin_info pin_info = {0};
+ memcpy(pin_info.pin_value, pt_info->pin_value, pt_info->pin_value_len);
+ pin_info.enable = 0;
+ int err = mbtk_enable_pin(qser_info_handle, &pin_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 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_card_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_pin_last_num_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_system_reboot(0);
+ mbtk_modem_info_t info;
+ info.fun = MBTK_DEV_MODEM_MIN_FUN;
+ info.rst = 0;
+ int err = mbtk_set_modem_fun(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+
+ info.fun = MBTK_DEV_MODEM_FULL_FUN;
+ err = mbtk_set_modem_fun(qser_info_handle, &info);
+ 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_sim_power_set(0);
+ //sleep(1);
+ //mbtk_sim_power_set(1);
+ mbtk_modem_info_t info;
+ info.fun = MBTK_DEV_MODEM_DISABLE_SIM;
+ info.rst = 0;
+ int err = mbtk_set_modem_fun(qser_info_handle, &info);
+ if(err)
+ {
+ LOGE("[qser_sim] mbtk_set_modem_fun Error : %d\n", err);
+ return QSER_RESULT_FAIL;
+ }
+
+ info.fun = MBTK_DEV_MODEM_FULL_FUN;
+ err = mbtk_set_modem_fun(qser_info_handle, &info);
+ 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_info_handle, 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)
+{
+ //UNUSED(h_sim);
+ if(h_sim != qser_h_sim)
+ {
+ LOGE("[qser_sim] h_sim is error.");
+ return QSER_RESULT_FAIL;
+ }
+
+ if(qser_info_handle)
+ {
+ LOGE("[qser_sim] qser_info_handle_num = %d", qser_info_handle_num);
+ if(qser_info_handle_num == 1)
+ { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&qser_info_handle);
+ if(ret)
+ {
+ LOGE("[qser_sim] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle_num = 0;
+ qser_info_handle = NULL;
+ qser_sim_state_cb = NULL;
+ inited = FALSE;
+ }
+ }
+ else
+ {
+ qser_info_handle_num--;
+ 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_v2/src/lynq_sleep.c b/mbtk/liblynq_lib_v2/src/lynq_sleep.c
new file mode 100755
index 0000000..8c14793
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_sleep.c
@@ -0,0 +1,694 @@
+#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_info_api.h"
+#include "mbtk_power.h"
+
+/*
+This module is system sleep, the system cannot sleep when the lock exists
+To verify whether it is in sleep state, it is necessary to test the power consumption
+Power management principle, as long as a wakelock lock exists, the system will not enter the Suspend state
+So the name can be arbitrarily chosen to indicate that such a lock is needed so that the system does not sleep
+*/
+#if defined(MBTK_PLATFORM_KERNEL_5)
+#define MTBK_POWERIND "/system/etc/powerind" //1806
+#elif defined(MBTK_PLATFORM_KERNEL_3)
+#define MTBK_POWERIND "/etc/powerind" //1803
+#endif
+
+static bool call_Off = FALSE;
+static bool nw_off = FALSE;
+static bool sms_off = FALSE;
+static bool data_off = FALSE;
+
+static pthread_t lpm_t;
+static int edge_t = 0;
+static int epoll_fd_t = -1;
+static int fd_t = -1;
+static int socket_t[2];
+
+typedef struct{
+ qser_lpm_wakeupin_data_t wakeupin;
+ qser_lpm_wakeupout_data_t wakeupout;
+ qser_lpm_Handler_t wakehandle;
+}lynq_wake_t;
+
+static lynq_wake_t lpm_init;
+
+
+typedef struct
+{
+ int fd;
+ char name[64];
+} lock_name;
+
+#define LOCK_MAX_SIZE 129
+
+lock_name lynq_lock_name[LOCK_MAX_SIZE]={0};
+static bool autosleep_enable = FALSE;
+
+static mbtk_info_handle_t* whitelist_info_handle = NULL;
+
+static int powerrind_get()
+{
+ char buffer[4];
+ int ret = 0;
+
+ int fd = open(MTBK_POWERIND, O_RDWR | O_SYNC, 0662);
+ if (fd != -1)
+ {
+ read(fd, buffer, strlen(buffer)+1);
+ close(fd);
+ }
+
+ ret = atoi(buffer);
+
+ return ret;
+}
+
+#if 1
+static int sleep_epoll_deregister(int epoll_fd,int fd )
+{
+ int ret;
+ do {
+ ret = epoll_ctl( epoll_fd, EPOLL_CTL_DEL, fd, NULL );
+ } while (ret < 0 && errno == EINTR);
+ return ret;
+}
+
+static int sleep_epoll_register(int epoll_fd, int fd)
+{
+ struct epoll_event ev;
+ int ret, flags;
+
+ /* important: make the fd non-blocking */
+ flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+
+ ev.events = EPOLLIN;
+ ev.data.fd = fd;
+ do {
+ ret = epoll_ctl( epoll_fd, EPOLL_CTL_ADD, fd, &ev );
+ } while (ret < 0 && errno == EINTR);
+
+ return ret;
+}
+#endif
+
+int qser_autosuspend_enable(char enable)
+{
+ //UNUSED(enable);
+
+ if((enable == 1) || enable == '1')
+ {
+ //if(!mbtk_system_sleep())
+ if(!access("/sys/power/autosleep", W_OK))
+ {
+ system("echo mem > /sys/power/autosleep");
+ autosleep_enable = TRUE;
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/autosleep can not write.");
+ return -1;
+ }
+ }
+ else if((enable == 0) || enable == '0')
+ {
+ if(!access("/sys/power/autosleep", W_OK))
+ {
+ system("echo off > /sys/power/autosleep");
+ autosleep_enable = FALSE;
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/autosleep can not write.");
+ return -1;
+ }
+ }
+ else
+ {
+ LOGE("qser_autosuspend_enablecan enable err.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_wakelock_create(const char* name , size_t len)
+{
+ //UNUSED(name);
+ //UNUSED(len);
+ int len_t;
+/*
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+*/
+ len_t = strlen(name);
+
+ if((name != NULL) && (len < 33) && (len_t < 33))
+ {
+ int i;
+ //name
+ for(i=1 ;i<LOCK_MAX_SIZE;i++)
+ {
+ if(strcmp(lynq_lock_name[i].name, name) == 0)
+ {
+ LOGE("Repeated names.");
+ return -1;
+ }
+ }
+
+ for(i=1 ;i<LOCK_MAX_SIZE;i++)
+ {
+ if(lynq_lock_name[i].fd == 0)
+ break;
+ }
+
+ if (i >= LOCK_MAX_SIZE)
+ {
+ LOGE("Fd is full.");
+ return -1;
+ }
+
+ memcpy(lynq_lock_name[i].name, name, strlen(name)+1);
+ lynq_lock_name[i].fd = i;
+ return lynq_lock_name[i].fd -1;//Starting from scratch
+ }
+ else
+ return -1;
+
+ return -1;
+}
+
+int qser_wakelock_lock(int fd)
+{
+ //UNUSED(fd);
+/*
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+*/
+ int i;
+ for(i=1;i<LOCK_MAX_SIZE;i++)
+ {
+ if(lynq_lock_name[i].fd -1 == fd)
+ break;
+ }
+ if(i == LOCK_MAX_SIZE)
+ {
+ LOGE("LOCK_MAX_SIZE is full\n");
+ return -1;
+ }
+
+ if(!access("/sys/power/wake_lock", W_OK))
+ {
+ char cmd[128]={0};
+ sprintf(cmd, "echo %s > /sys/power/wake_lock", lynq_lock_name[i].name);
+ system(cmd);
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/wake_lock can not write.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_wakelock_unlock(int fd)
+{
+ //UNUSED(fd);
+/*
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+*/
+ int i;
+ for(i=1;i<LOCK_MAX_SIZE;i++)
+ {
+ if(lynq_lock_name[i].fd -1 == fd)
+ break;
+ }
+ if(i == LOCK_MAX_SIZE)
+ {
+ LOGE("LOCK_MAX_SIZE is full\n");
+ return -1;
+ }
+
+ if(!access("/sys/power/wake_unlock", W_OK))
+ {
+ char cmd[128]={0};
+ sprintf(cmd, "echo %s > /sys/power/wake_unlock", lynq_lock_name[i].name);
+ system(cmd);
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/wake_unlock can not write.");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_wakelock_destroy(int fd)
+{
+ //UNUSED(fd);
+/*
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+*/
+ int i;
+ for(i=1;i<LOCK_MAX_SIZE;i++)
+ {
+ if(lynq_lock_name[i].fd -1 == fd)
+ break;
+ }
+
+ if(i == LOCK_MAX_SIZE)
+ {
+ LOGE("LOCK_MAX_SIZE is full\n");
+ return -1;
+ }
+ else
+ {
+ lynq_lock_name[i].fd = 0;
+ memset(lynq_lock_name[i].name, 0, 64);
+ return 0;
+ }
+
+ return 0;
+}
+
+void *threadFunction(void *arg)
+{
+ int pinValue;
+ int i;
+ char buf[8] = {0};
+ struct input_event ev_input = { 0 };
+ const int size = sizeof(struct input_event);
+
+ epoll_fd_t = epoll_create(2);
+/*
+ struct epoll_event event;
+ memset(&event, 0, sizeof(struct epoll_event));
+ event.events = EPOLLIN | EPOLLET;
+ event.data.fd = open("/dev/input/event0", O_RDONLY); // 根据实际情况指定正确的GPIO设备文件名
+
+ fd_t = event.data.fd;
+ if (epoll_ctl(epoll_fd_t, EPOLL_CTL_ADD, event.data.fd, &event) == -1)
+ {
+ LOGE("Failed to add GPIO device file.");
+ return NULL;
+ }
+
+ memset(&event, 0, sizeof(struct epoll_event));
+ event.events = EPOLLIN | EPOLLET;
+ event.data.fd = socket_t[0];
+ LOGE("threadFunction event.data.fd =[%d] ", event.data.fd);
+
+ if (epoll_ctl(epoll_fd_t, EPOLL_CTL_ADD, event.data.fd, &event) == -1)
+ {
+ LOGE("Failed to add GPIO device file.");
+ return NULL;
+ }
+*/
+
+#if defined(MBTK_SG_SUPPORT)
+ fd_t = open("/dev/input/event1", O_RDONLY);
+ LOGI("init sg pthread_event");
+#else
+ fd_t = open("/dev/input/event0", O_RDONLY);
+#endif
+
+ sleep_epoll_register(epoll_fd_t, fd_t);
+ sleep_epoll_register(epoll_fd_t, socket_t[1]);
+
+ while (true)
+ {
+ struct epoll_event events[2];
+ struct epoll_event ev;
+ int cmd = 0;
+
+ int numEvents = epoll_wait(epoll_fd_t, events, 2, -1);
+
+ for (i = 0; i < numEvents; ++i)
+ {
+ if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP))
+ {
+ LOGE("Error on GPIO device.");
+ return NULL;
+ }
+ else if ((events[i].events & EPOLLIN) || (events[i].events & EPOLLET))
+ {
+ //handleInterrupt(events[i].data.fd);
+ if (events[i].data.fd == socket_t[1])
+ {
+ memset(buf, 0, sizeof(buf));
+ read(socket_t[1], buf, sizeof(buf));
+ if (1 == atoi(buf))
+ {
+ if(close(fd_t) == 0)
+ LOGI("close(fd_t)ing");
+
+ sleep_epoll_deregister(epoll_fd_t, socket_t[1]);
+ sleep_epoll_deregister(epoll_fd_t, fd_t);
+ /*
+ memset(&ev, 0, sizeof(struct epoll_event));
+ ev.events = EPOLLIN | EPOLLET;
+ ev.data.fd = socket_t[1];
+ epoll_ctl( epoll_fd_t, EPOLL_CTL_DEL, ev.data.fd, &ev);
+
+ memset(&ev, 0, sizeof(struct epoll_event));
+ ev.events = EPOLLIN | EPOLLET;
+ ev.data.fd = fd_t;
+ epoll_ctl( epoll_fd_t, EPOLL_CTL_DEL, ev.data.fd, &ev);
+ */
+ LOGI("do pthread_exit");
+ return NULL;
+ }
+ }
+ else if (events[i].data.fd == fd_t)
+ {
+ LOGI("go pthread_event");
+ memset(&ev_input, 0x00, size);
+ read(fd_t, &ev_input, size);
+ LOGI("ev_input type = %x, code = %x, value = %x", ev_input.type, ev_input.code,ev_input.value);
+ if (ev_input.code == 2)
+ {
+ LOGI(">>>>ev_input.value = [%d]",ev_input.value);
+ pinValue = (int)ev_input.value;
+ edge_t = pinValue;
+ lpm_init.wakehandle(edge_t);
+ }
+ }
+ else
+ {
+ LOGE("Unknown events[i].data.fd = %d", events[i].data.fd);
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+int qser_lpm_init(qser_lpm_Handler_t qser_lpm_handler, qser_pm_cfg_t *qser_lpm_cfg)
+{
+ //UNUSED(qser_lpm_handler);
+ //UNUSED(qser_lpm_cfg);
+ if (socketpair( AF_LOCAL, SOCK_STREAM, 0, socket_t ) < 0 )
+ {
+ LOGE("[qser_lpm_init] could not create thread control socket pair: %s", strerror(errno));
+
+ /*close the control socket pair && Retry again.*/
+ if(socket_t[0] > 0)
+ {
+ close(socket_t[0] );
+ socket_t[0] = -1;
+ }
+
+ if(socket_t[1] > 0)
+ {
+ close(socket_t[1] );
+ socket_t[1] = -1;
+ }
+ return -1;
+ }
+ lpm_init.wakeupin.wakeupin_pin = qser_lpm_cfg->wakeupin.wakeupin_pin;
+ LOGI(">>pin = %d",lpm_init.wakeupin.wakeupin_pin);
+ lpm_init.wakeupin.wakeupin_edge = qser_lpm_cfg->wakeupin.wakeupin_edge;
+ LOGI(">>edge = %d",lpm_init.wakeupin.wakeupin_edge);
+ edge_t = qser_lpm_cfg->wakeupin.wakeupin_edge;//保留原始状态值 0 or 1
+ lpm_init.wakehandle = qser_lpm_handler;
+
+ pthread_attr_t thread_attr;
+ pthread_attr_init(&thread_attr);
+
+ if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+ {
+ LOGE("pthread_attr_setdetachstate() fail");
+ return -1;
+ }
+
+ if(pthread_create(&lpm_t, &thread_attr, threadFunction, NULL))
+ //if(pthread_create(&lpm_t, NULL, threadFunction, NULL))
+ {
+ LOGE("qser_lpm_init can't create thread");
+ return -1;
+ }
+
+ pthread_attr_destroy(&thread_attr);
+
+ //if (edge_t != qser_lpm_cfg->wakeupin.wakeupin_edge)//说明有变化,并且和原来的值不相同
+ //qser_lpm_handler(edge_t);
+
+ return 0;
+}
+
+int qser_lpm_deinit(void)
+{
+ char buf[4]={0};
+
+ if (fd_t == -1)
+ return 0;
+
+ if (fd_t != -1)
+ {
+ //char cmd = 1;
+ strcpy(buf, "1");
+ void* dummy = NULL;
+ write( socket_t[0], buf, sizeof(buf) );
+ //pthread_join(lpm_t, &dummy);
+
+ sleep(1);
+ // close the control socket pair
+ if(socket_t[0] > 0)
+ {
+ close(socket_t[0] );
+ socket_t[0] = -1;
+ }
+ if(socket_t[1] > 0)
+ {
+ close(socket_t[1] );
+ socket_t[1] = -1;
+ }
+
+ //重置还原
+ fd_t = -1;
+
+ }
+
+ 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_info_handle_get();
+ 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;
+ }
+
+ return 0;
+}
+
+
+int qser_whitelist_get(char* whitelish)
+{
+ //UNUSED(whitelish);
+ char list[10]={0};
+ int call_t, nw_t, data_t, sms_t;
+ int get_tmp;
+
+ get_tmp = powerrind_get();
+ //LOGI(">>>get_tmp: %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");
+ break;
+ }
+
+ //LOGI(">>>get list: %s",list);
+ strncpy(whitelish, list, strlen(list));
+
+ if(whitelist_info_handle != NULL)
+ {
+ mbtk_info_handle_free(&whitelist_info_handle);
+ LOGI("deinit whitelist_info_handle is succuess");
+ }
+
+ return 0;
+}
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_sms.c b/mbtk/liblynq_lib_v2/src/lynq_sms.c
new file mode 100755
index 0000000..ed9c1b3
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_sms.c
@@ -0,0 +1,563 @@
+#include "lynq_qser_sms.h"
+#include "mbtk_type.h"
+#include "mbtk_pdu_sms.h"
+#include "mbtk_info_api.h"
+#include "lynq_sms.h"
+#include "mbtk_log.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#define TELEPHONE_NUM_MAX 16
+#define MSM_NUMBER_MAX 1024+1
+#define RES_NUM_MIN 128
+
+
+#define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2"))
+
+static mbtk_info_handle_t* sms_info_handle = NULL;
+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;
+
+sms_client_handle_type g_sms_val = -1;
+
+
+void lynq_sms_state_change_cb(const void* data, int data_len)
+{
+ LOGV("sms_state_change_cb()----------start\n");
+ uint8 *ptr = (uint8*)data;
+ //printf("3sms_state_change_cb() : %s\n", ptr);
+
+ if (!strncmp("+CMT:", ptr, 5))//丢弃无用消息
+ return ;
+
+ struct SMS_Struct s = PDUDecoding(ptr);
+ /*
+ printf("服务中心地址: %s\n", s.SCA);
+ printf("发送方地址: %s\n", s.OA);
+ printf("服务中心时间戳: %s\n", s.SCTS);
+ printf("消息内容: %s\n", s.UD);
+ printf("数据编码方案: %s\n", DSC_to_msg(s.DCS));
+ */
+ QSER_SMS_Msg_t* tmp_data = NULL;
+
+ tmp_data = (QSER_SMS_Msg_t*)malloc(sizeof(QSER_SMS_Msg_t));
+ memset(tmp_data,0x00, sizeof(QSER_SMS_Msg_t));
+
+ tmp_data->format = s.DCS;
+ //printf("t数据编码方案: %d\n", tmp_data->format);
+ memcpy(tmp_data->src_addr, s.OA, strlen(s.OA));
+ //printf("t发送方地址: %s\n", tmp_data->src_addr);
+ memcpy(tmp_data->timestamp, s.SCTS, strlen(s.SCTS));
+ //printf("t服务中心时间戳: %s\n", tmp_data->timestamp);
+ tmp_data->sms_data_len = strlen(s.UD);
+ //printf("t消息内容长度: %d\n", tmp_data->sms_data_len);
+ memcpy(tmp_data->sms_data, s.UD, strlen(s.UD));
+ //printf("t消息内容: %s\n", tmp_data->sms_data);
+
+ lynq_sms_func_cb_handle.handlerPtr(tmp_data, NULL);
+
+ free(tmp_data);
+
+}
+
+
+int qser_sms_client_init(sms_client_handle_type *ph_sms)//out
+{
+ //UNUSED(ph_sms);
+
+ if(sms_info_handle == NULL)
+ {
+ sms_info_handle = mbtk_info_handle_get();
+ if(sms_info_handle)
+ {
+ LOGI("creat sms_info_handle is success");
+ *ph_sms = sms_info_handle->client_fd;
+ g_sms_val = sms_info_handle->client_fd;
+ }
+ else
+ {
+ LOGE("creat sms_info_handle is fail");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int qser_sms_client_deinit(sms_client_handle_type h_sms)//in
+{
+ //UNUSED(h_sms);
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL\n");
+ return -1;
+ }
+
+ mbtk_sms_state_change_cb_reg(sms_info_handle, NULL);
+
+ if(sms_info_handle)
+ {
+ mbtk_info_handle_free(&sms_info_handle);
+ LOGI("deinit sms_info_handle is succuess");
+ }
+ else
+ {
+ LOGE("deinit sms_info_handle is fail");
+ return -1;
+ }
+
+ return 0;
+}
+
+int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码
+{
+ //UNUSED(h_sms);
+ //UNUSED(pt_sms_info);
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if (pt_sms_info == NULL)
+ {
+ LOGE("QSER_sms_info_t NULL");
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_send_sms sms_info_handle NULL");
+ return -1;
+ }
+
+ uint8_t *phone_num = NULL, *data = NULL;
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ char resp[RES_NUM_MIN] = {0};
+ char pdu_data[512] = {0};
+ char phone_lenth[10] = {0};
+ char mem[10] = {0};
+ char *p = pdu_data;
+ int mode = 0;
+ int err = 0;
+ int i = 0;
+
+ data = pt_sms_info->sms_data;
+
+ phone_num = pt_sms_info->src_addr;
+
+ if (pt_sms_info->format == 0)//7
+ mode = 1;
+ else if (pt_sms_info->format == 1)//8
+ return SMS_ERR;
+ else if (pt_sms_info->format == 2)//USC2
+ mode = 0;
+ else
+ 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(sms_info_handle, mem, resp);
+ if(err) {
+ LOGE("Error : %d", err);
+ } else {
+ LOGI("cpms set success. resp:%s", resp);
+ }
+*/
+ if(data == NULL)
+ {
+ LOGE("qser_sms_send_sms data NULL");
+ return -1;
+ }
+
+ if(phone_num == NULL)
+ {
+ LOGE("qser_sms_send_sms phone_num NULL");
+ return -1;
+ }
+
+ if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
+ {
+ LOGE("strlen(telephony_num):%d", strlen(phone_num));
+ LOGE("strlen(msg):%d", strlen(data));
+ return -1;
+ }
+
+ if (mode == 0)// PDU
+ {
+#if 1
+ if (sms_center_address[0] == '\0')
+ {
+ memset(sms_center_address, 0, sizeof(sms_center_address));
+ memcpy(sms_center_address, "+8613800280500", strlen("+8613800280500"));
+ }
+
+ //printf("phone_num:%s\n", phone_num);
+ //printf("sms_center_address:%s\n", sms_center_address);
+ //printf("data:%s\n", data);
+
+ char* pdu = NULL;
+ char* smsc = SCAEncoding(sms_center_address);
+ struct PDUS *pdus = PDUEncoding(sms_center_address,phone_num, data, NULL);
+
+ for (i = 0; i < pdus->count; i++)
+ {
+ LOGI("第 %d 条:", i + 1);
+ LOGI("%s\n", pdus->PDU[i]);
+ pdu = pdus->PDU[i];
+ }
+
+ sprintf(p, "%s",smsc);
+ LOGI("pdu_data:%s", pdu_data);
+ sprintf(p+strlen(p), "%s", pdu);
+ LOGI("pdu_data:%s",pdu_data);
+
+ //sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data);
+ int t = strlen(pdu_data);
+ sprintf(cmgs,"%d,%s",(t-18)/2, pdu_data);
+ LOGI("cmgs:%s", cmgs);
+#else
+ char *tmp_t = "0891683108200805F011000D91688189914026F3000800044F60597D";
+ sprintf(cmgs,"%d,%s",19,tmp_t);
+ printf("cmgs:%s\n", cmgs);
+#endif
+
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgf_set(sms_info_handle, mode);
+ if(err)
+ {
+ LOGE("cmgf set error : %d", err);
+ }
+ else
+ {
+ LOGI("cmgf set success");
+ }
+
+ err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp);
+ if(err)
+ {
+ LOGE("Error : %d", err);
+ return -1;
+ }
+ else
+ {
+ LOGI("cmgs set success . resp:%s", resp);
+ }
+ }
+ else if (mode == 1) // text
+ {
+ err = mbtk_sms_cmgf_set(sms_info_handle, mode);
+ if(err)
+ {
+ LOGE("cmgf set error : %d", err);
+ }
+ else
+ {
+ LOGI("cmgf set success");
+ }
+
+ sprintf(cmgs,"%s,%s", phone_num, data);
+ LOGI("cmgs:%s", cmgs);
+
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp);
+ if(err)
+ {
+ LOGE("Error : %d", err);
+ return -1;
+ }
+ else
+ {
+ LOGI("cmgs set success . resp:%s", resp);
+ }
+ }
+ else
+ {
+ LOGE("Error : mode");
+ return -1;
+ }
+
+ return 0;
+}
+
+//注册接收新短信
+int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容
+{
+ //UNUSED(handlerPtr);
+ //UNUSED(contextPtr);
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_addrxmsghandler sms_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_cnmi_set(sms_info_handle);
+ if(err)
+ {
+ LOGE("set cnmi fail");
+ return -1;
+ }
+
+ lynq_sms_func_cb_handle.handlerPtr = handlerPtr;
+ lynq_sms_func_cb_handle.contextPtr = contextPtr;
+
+ mbtk_sms_state_change_cb_reg(sms_info_handle, lynq_sms_state_change_cb);
+
+ 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;
+
+ int t_storage = 0;
+ char mem[10] = {0};
+ char resp[RES_NUM_MIN] = {0};
+
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(pt_sms_storage == NULL)
+ {
+ LOGE("qser_sms_deletefromstorage pt_sms_storage NULL");
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_deletefromstorage sms_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(sms_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(sms_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 != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if (set_sca_cfg == NULL)
+ {
+ LOGE("QSER_sms_service_center_cfg_t NULL");
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_getsmscenteraddress sms_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_get(sms_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 != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_setsmscenteraddress sms_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(sms_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 != g_sms_val || g_sms_val == -1)
+ {
+ LOGE("handle NULL");
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ LOGE("qser_sms_deletefromstoragelist sms_info_handle NULL");
+ return -1;
+ }
+
+ int err = mbtk_sms_cmgd_get(sms_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_v2/src/lynq_thermal.c b/mbtk/liblynq_lib_v2/src/lynq_thermal.c
new file mode 100755
index 0000000..f3e6e3d
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_thermal.c
@@ -0,0 +1,120 @@
+#if 1
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+#include "lynq_qser_thermal.h"
+#include "mbtk_info_api.h"
+
+/****************************DEFINE***************************************/
+#define QSER_RESULT_FAIL -1
+#define QSER_RESULT_SUCCESS 0
+/****************************DEFINE***************************************/
+
+/****************************VARIABLE***************************************/
+extern mbtk_info_handle_t* qser_info_handle;
+extern int qser_info_handle_num;
+/****************************VARIABLE***************************************/
+
+
+/******************************FUNC*****************************************/
+static int qser_thermal_client_init(void)
+{
+ if(qser_info_handle == NULL)
+ {
+ qser_info_handle = mbtk_info_handle_get();
+ if(qser_info_handle)
+ {
+ qser_info_handle_num++;
+ }
+ else
+ {
+ LOGE("[qser_thermal] mbtk_info_handle_get() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ }
+ else
+ {
+ qser_info_handle_num++;
+ }
+
+ LOGE("[qser_thermal] mbtk_info_handle_get() success.");
+ return QSER_RESULT_SUCCESS;
+}
+
+static int qser_thermal_client_deinit(void)
+{
+ if(qser_info_handle)
+ {
+ LOGE("[qser_thermal] qser_info_handle_num = %d", qser_info_handle_num);
+ if(qser_info_handle_num == 1)
+ { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&qser_info_handle);
+ if(ret)
+ {
+ LOGE("[qser_thermal] mbtk_info_handle_free() fail.");
+ return QSER_RESULT_FAIL;
+ }
+ else
+ {
+ qser_info_handle_num = 0;
+ qser_info_handle = NULL;
+ }
+ }
+ else
+ {
+ qser_info_handle_num--;
+ }
+ }
+ else
+ {
+ LOGE("[qser_thermal] handle not inited.");
+ return QSER_RESULT_FAIL;
+ }
+
+ return QSER_RESULT_SUCCESS;
+}
+
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
+int get_thermal_zone(int *numbers, int size)
+{
+ if(numbers == NULL || size < 6)
+ {
+ LOGE("[qser_thermal]: numbers is NULL!");
+ return QSER_RESULT_FAIL;
+ }
+
+ int ret = 0;
+ int thermal = -1;
+ int thermal_num = 0;
+ mbtk_thermal_info_t temp;
+ memset(&temp, 0, sizeof(mbtk_thermal_info_t));
+
+ 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.ther;
+ 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 6;
+}
+/****************************API***************************************/
+
+#endif
diff --git a/mbtk/liblynq_lib_v2/src/lynq_time.c b/mbtk/liblynq_lib_v2/src/lynq_time.c
new file mode 100755
index 0000000..8f432f0
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_time.c
@@ -0,0 +1,318 @@
+#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"
+
+
+#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 req_time_set(int type, char *time, int *cme_err);
+static int metis_strptime(char *str_time)
+{
+ printf("%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 = mktime(&stm);
+ tv.tv_sec = _t;
+ if(settimeofday(&tv, NULL)) {
+ printf("Set time fail:%d");
+ return -1;
+ } else {
+ printf("Set time to %s.", str_time);
+ return 0;
+ }
+ } else {
+ printf("Set time fail.");
+ return -1;
+ }
+ return 0;
+}
+
+
+
+static void* ntp_pthread_run(int* ntp_flag)
+{
+ if (mbtk_net_state_get() == MBTK_NET_STATE_OFF)
+ {
+ printf("Network is disconnected. Set time fail.");
+ if(NULL != ntp_flag)
+ {
+ *ntp_flag = -1;
+ }
+ return NULL;
+ }
+ printf("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)
+ {
+ printf("NTP client fail!\n");
+ if(NULL != ntp_flag)
+ {
+ *ntp_flag = -1;
+ }
+ return NULL;
+ }
+ struct tm *tm_t;
+ tm_t = localtime(&time);
+ strftime(time_str,128,"%F %T",tm_t);
+
+ // NTP time
+ metis_strptime(time_str);
+ 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;
+}
+
+
+
+
+int ntp_sync_time(int enable)
+{
+ if(0 != enable && 1 != enable)
+ {
+ return -1;
+ }
+ UNUSED(enable);
+ int ntp_status = 0;
+ if(enable)
+ {
+ ntp_pthread_run(&ntp_status);
+ if(ntp_status == 0)
+ {
+ set_time_type(LYNQ_TIME_TYPE_NTP);
+ }
+ else
+ {
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ }
+ }
+ else
+ {
+ set_time_type(LYNQ_TIME_TYPE_UNUSE);
+ }
+
+ return 0;
+}
+
+//enable set time from nitz
+int modem_time_enable(int enable)
+{
+ UNUSED(enable);
+
+ 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)
+{
+ UNUSED(enable);
+ 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)
+{
+ system("hwclock --hctosys");
+ return 0;
+}
+
+// system time set to RTC
+int lynq_set_rtc_time(void)
+{
+// system("hwclock --systohc");
+ system("hwclock -w rtc0");
+ return 0;
+}
+
+int lynq_get_rtc_time(unsigned long *ulsec)
+{
+ UNUSED(ulsec);
+
+ return 0;
+}
+
+
diff --git a/mbtk/liblynq_lib_v2/src/lynq_voice_call.c b/mbtk/liblynq_lib_v2/src/lynq_voice_call.c
new file mode 100755
index 0000000..9aea174
--- /dev/null
+++ b/mbtk/liblynq_lib_v2/src/lynq_voice_call.c
Binary files differ
diff --git a/mbtk/libql_lib_v2/Makefile b/mbtk/libql_lib_v2/Makefile
new file mode 100755
index 0000000..43259aa
--- /dev/null
+++ b/mbtk/libql_lib_v2/Makefile
@@ -0,0 +1,51 @@
+BUILD_ROOT = $(shell pwd)/..
+include $(BUILD_ROOT)/Make.defines
+
+LOCAL_PATH=$(BUILD_ROOT)/libql_lib_v2
+
+INC_DIR +=
+
+LIB_DIR +=
+
+LIBS += -llog -lubus -lubox -lblobmsg_json -lrilutil -lmbtk_lib -lmbtk_ril -lmbtk_fota -lmbtk_http -lmbtk_factory -lmbtk_audio
+
+CFLAGS += -shared -Wl,-shared,-Bsymbolic
+
+DEFINE +=
+
+MY_FILES_PATH:=$(LOCAL_PATH)/src
+#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 = $(wildcard src/*.c) $(wildcard src/*.cpp)
+$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
+
+OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(LOCAL_SRC_FILES)))
+$(info OBJS = $(OBJS))
+
+dtarget := $(OUT_DIR)/lib/libql_lib.so
+
+all: $(dtarget)
+
+$(dtarget): $(OBJS)
+ $(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $(OBJS) -o $@
+
+%.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/libql_lib_v2/src/ql_adc.c b/mbtk/libql_lib_v2/src/ql_adc.c
new file mode 100755
index 0000000..812427e
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_adc.c
@@ -0,0 +1,12 @@
+#include "mbtk_adc.h"
+#include "ql/ql_adc.h"
+
+int ql_adc_show(Enum_QADC qadc)
+{
+ if(qadc == ADC0 || qadc == ADC1) {
+ return mbtk_adc_get((mbtk_adc_enum)qadc);
+ } else {
+ return -1;
+ }
+}
+
diff --git a/mbtk/libql_lib_v2/src/ql_atc.c b/mbtk/libql_lib_v2/src/ql_atc.c
new file mode 100755
index 0000000..cd1cf49
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_atc.c
@@ -0,0 +1,43 @@
+#include "mbtk_at.h"
+/*******************************************************
+* @method: ql_atc_init
+* @Description: initialize environment variables.
+* @param: void
+* @return:
+ success: return 0
+ error: return !0
+********************************************************/
+int ql_atc_init()
+{
+ return mbtk_at_init();
+}
+
+/*******************************************************
+* @method: ql_atc_release
+* @Description: release environment variables.
+* @param: void
+* @return:
+ success: return 0
+ error: return !0
+********************************************************/
+int ql_atc_release()
+{
+ return mbtk_at_deinit();
+}
+
+/*******************************************************
+* @method: ql_atc_send
+* @Description: send at command(synchronous)
+ use this api should first call init api and finish call release api
+* @param:
+ cmd: at command
+ resp: at return value
+ len: response value length
+* @return:
+ success: return 0
+ error: return !0
+********************************************************/
+int ql_atc_send(char* cmd, char* resp, int resp_len)
+{
+ return mbtk_at_send(cmd, resp, resp_len);
+}
diff --git a/mbtk/libql_lib_v2/src/ql_audio.c b/mbtk/libql_lib_v2/src/ql_audio.c
new file mode 100755
index 0000000..d95ca9e
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_audio.c
@@ -0,0 +1,875 @@
+
+#include "ql/ql_audio.h"
+#include "mbtk_log.h"
+#include "mbtk_audio2.h"
+
+typedef enum {
+ AUDIO_PLAY_STATE_STOP,
+ AUDIO_PLAY_STATE_RUNNING,
+ AUDIO_PLAY_STATE_PAUSE
+} audio_play_state_enum;
+
+#define AUDIO_HANDLE 1
+#define WAV_PLAY_BUFF 1024
+
+#ifdef MBTK_AF_SUPPORT
+static mbtk_audio_handle player_hdl = NULL;
+static int player_hdl_1 = AUDIO_HANDLE;
+static _cb_onRecorder record_cb_fun = NULL;
+static int Samprate = 8000;
+#endif
+
+static int sample_rate = 8000;
+static int play_handle = AUDIO_HANDLE;
+static _cb_onPlayer play_cb_func = NULL;
+static _cb_onRecorder recorder_cb_fun = NULL;
+static int is_running = 0;
+static audio_play_state_enum play_state = AUDIO_PLAY_STATE_STOP;
+static int play_exit = 1;
+
+static void recorder_cb_func(void *data, uint32 data_len)
+{
+ if(recorder_cb_fun) {
+ recorder_cb_fun(AUD_RECORDER_START, (unsigned char*)data, data_len);
+ }
+}
+
+static int play_stream(unsigned char* pData, unsigned int length)
+{
+ int rc, len, frames = 0;
+ int result = 0;
+
+ play_state = AUDIO_PLAY_STATE_RUNNING;
+ play_exit = 0;
+ int data_send = 0;
+
+ if (mbtk_audio_pcm_play_start()) {
+ printf("%s: error opening output device.", __FUNCTION__);
+ return -1;
+ }
+
+ if(pData && length > 0) {
+ while (play_state != AUDIO_PLAY_STATE_STOP) {
+ if(play_state == AUDIO_PLAY_STATE_RUNNING) {
+ if (data_send >= length) {
+ LOGE("%s: Read pcm stream end.", __FUNCTION__);
+ break;
+ }
+
+ if(length - data_send > WAV_PLAY_BUFF) {
+ len = WAV_PLAY_BUFF;
+ } else {
+ len = length - data_send;
+ }
+
+ if((rc = mbtk_audio_pcm_play_data_send(pData + data_send, len)) != len) {
+ LOGE("Send data %d/%d", rc, len);
+ result = -1;
+ goto thread_end;
+ }
+
+ data_send += len;
+
+ LOGD("%s: No.%d frame playback", __FUNCTION__, ++frames);
+ } else {
+ usleep(200000);
+ }
+ }
+ } else {
+ result = -1;
+ }
+
+ play_state = AUDIO_PLAY_STATE_STOP;
+
+
+thread_end:
+ mbtk_audio_pcm_play_stop();
+ play_exit = 1;
+ LOGD("%s: finished pcm playback.", __FUNCTION__);
+ return result;
+}
+
+static int play_by_fd(int fd, int offset)
+{
+ int rc, len, frames = 0;
+ int result = 0;
+ char buf[WAV_PLAY_BUFF];
+
+ play_state = AUDIO_PLAY_STATE_RUNNING;
+ if(play_cb_func)
+ play_cb_func(play_handle , AUDIO_PLAY_STATE_RUNNING);
+ play_exit = 0;
+ if(fd > 0) {
+ if(offset > 0) {
+ lseek(fd, offset, SEEK_SET);
+ }
+
+ if (mbtk_audio_pcm_play_start()) {
+ printf("%s: error opening output device.", __FUNCTION__);
+ return -1;
+ }
+
+
+ while (play_state != AUDIO_PLAY_STATE_STOP) {
+ if(play_state == AUDIO_PLAY_STATE_RUNNING) {
+ memset(buf, 0x00, sizeof(buf));
+ len = read(fd, buf, WAV_PLAY_BUFF);
+ if (len == -1) {
+ LOGE("%s: error reading from file", __FUNCTION__);
+ result = -1;
+ goto thread_end;
+ }
+
+ if (len == 0) {
+ /* reached EOF */
+ LOGE("%s: Read wav file end.", __FUNCTION__);
+ break;
+ }
+
+ if((rc = mbtk_audio_pcm_play_data_send(buf, len)) < len) {
+ LOGE("Send data %d/%d", rc, len);
+ result = -1;
+ goto thread_end;
+ }
+
+ LOGD("%s: No.%d frame playback", __FUNCTION__, ++frames);
+ } else {
+ usleep(200000);
+ }
+ }
+ } else {
+ result = -1;
+ }
+
+ play_state = AUDIO_PLAY_STATE_STOP;
+ if(play_cb_func)
+ play_cb_func(play_handle , AUDIO_PLAY_STATE_STOP);
+
+thread_end:
+ mbtk_audio_pcm_play_stop();
+ play_exit = 1;
+ LOGD("%s: finished pcm playback.", __FUNCTION__);
+ return result;
+}
+
+/*****************************************************************
+* Function: Ql_AudPlayer_Open
+*
+* Description:
+* Open audio play device, and specify the callback function.
+* This function can be called twice to play different audio sources.
+*
+* Parameters:
+* device : a string that specifies the PCM device.
+* NULL, means the audio will be played on the default PCM device.
+*
+* If you want to mixedly play audio sources, you can call this
+* API twice with specifying different PCM device.
+* The string devices available:
+* "hw:0,0" (the default play device)
+* "hw:0,13" (this device can mix audio and TTS)
+* "hw:0,14"
+*
+* cb_func : callback function for audio player.
+* The results of all operations on audio player
+* are informed in callback function.
+*
+* Return:
+* pcm device handle on success
+* -1 for failure
+*****************************************************************/
+int Ql_AudPlayer_Open(char* device, _cb_onPlayer cb_func)
+{
+#ifdef MBTK_AF_SUPPORT
+ player_hdl = mbtk_audio_open_new(MBTK_AUTIO_TYPE_OUT, 1, Samprate, cb_func);
+ if(player_hdl == NULL)
+ {
+ return -1;
+ }
+ else
+ {
+ return player_hdl_1 = AUDIO_HANDLE;
+ }
+#else
+ if(is_running || mbtk_audio_pcm_init()) {
+ return -1;
+ } else {
+ play_cb_func = cb_func;
+ is_running = 1;
+ return play_handle;
+ }
+#endif
+}
+
+/*========================================================================
+ FUNCTION: Ql_AudPlayer_Play
+=========================================================================*/
+/** @brief
+ This function writes pcm data to pcm device to play.
+
+ @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
+ @param[in] pData, pointer to the start address of pcm data.
+ @param[in] length, the length of pcm data.
+
+ @return
+ on success, the return value is the number of bytes to play
+ on failure, the return value is -1;
+
+ @dependencies
+ Ql_AudPlayer_Open() must be first called successfully.
+*/
+/*=======================================================================*/
+int Ql_AudPlayer_Play(int hdl, unsigned char* pData, unsigned int length)
+{
+#ifdef MBTK_AF_SUPPORT
+ if(hdl != player_hdl_1 || player_hdl == NULL){
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+ return mbtk_audio_play_stream_new((void *)player_hdl, pData, length,50);
+
+#else
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ return play_stream(pData, length);
+#endif
+}
+
+/*========================================================================
+ FUNCTION: Ql_AudPlayer_PlayFrmFile
+=========================================================================*/
+/** @brief
+ This function plays the pcm data from the specified file.
+
+ @param[in] hdl, the handle returned by Ql_AudPlayer_Open().
+ @param[in] fd, a file descriptor that contains pcm data.
+ Note:
+ the file offset should be set to the start position of pcm
+ data region, which means you should move the file offset
+ skipping the file header (such as wave header, amr header).
+ @param[in] offset, file offset. Please set it to -1 if no need to use.
+
+ @return
+ 0 on success
+ -1 on failure
+
+ @dependencies
+ Ql_AudPlayer_Open() must be first called successfully.
+*/
+/*=======================================================================*/
+
+int Ql_AudPlayer_PlayFrmFile(int hdl, int fd, int offset)
+{
+#ifdef MBTK_AF_SUPPORT
+ if(hdl != player_hdl_1 || player_hdl == NULL){
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ return mbtk_audio_play_file_new((void *)player_hdl, fd, offset);
+
+#else
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ return play_by_fd(fd, offset);
+#endif
+}
+
+//
+// Function: Ql_AudPlayer_Pause
+//
+// Description:
+// Pause playing.
+// @param hdl:
+// Handle received from Ql_AudPlayer_Open().
+int Ql_AudPlayer_Pause(int hdl)
+{
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ play_state = AUDIO_PLAY_STATE_PAUSE;
+
+ while(!play_exit) {
+ usleep(10000);
+ }
+
+ return 0;
+}
+
+//
+// Function: Ql_AudPlayer_Resume
+//
+// Description:
+// Resume playing.
+// @param hdl:
+// Handle received from Ql_AudPlayer_Open().
+int Ql_AudPlayer_Resume(int hdl)
+{
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ play_state = AUDIO_PLAY_STATE_RUNNING;
+
+ while(!play_exit) {
+ usleep(10000);
+ }
+ return 0;
+}
+
+//
+// Function: Ql_AudPlayer_Stop
+//
+// Description:
+// Stop playing audio
+// hdl:
+// Handle received from Ql_AudPlayer_Open().
+void Ql_AudPlayer_Stop(int hdl)
+{
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return;
+ }
+
+ play_state = AUDIO_PLAY_STATE_STOP;
+
+ while(!play_exit) {
+ usleep(10000);
+ }
+}
+
+//
+// Function: Ql_AudPlayer_Close
+//
+// Description:
+// Close player, and free the resource.
+// @param hdl:
+// Handle received from Ql_AudPlayer_Open().
+void Ql_AudPlayer_Close(int hdl)
+{
+#ifdef MBTK_AF_SUPPORT
+ if(hdl != player_hdl_1 || player_hdl == NULL){
+ LOGE("Handle error : %d", hdl);
+ return -1;
+ }
+
+ mbtk_audio_close_new((void *)player_hdl);
+ player_hdl_1 = 0;
+
+#else
+ if(!is_running || hdl != play_handle) {
+ LOGE("Handle error : %d", hdl);
+ return;
+ }
+ play_state = AUDIO_PLAY_STATE_STOP;
+
+ while(!play_exit) {
+ usleep(10000);
+ }
+
+ is_running = 0;
+ mbtk_audio_pcm_deinit();
+#endif
+}
+
+
+int Ql_AudPlayer_set_LessDataThreshold(int hdl, unsigned short threshSize)
+{
+
+ return 0;
+}
+
+int Ql_AudPlayer_get_freeSpace(int hdl)
+{
+
+ return 0;
+}
+
+
+/*****************************************************************
+* Function: Ql_AudRecorder_Open
+*
+* Description:
+* Open audio record device, and specify the callback function.
+*
+* Parameters:
+* device : not used. MUST be NULL.
+*
+* cb_func : callback function for audio player.
+* The results of all operations on audio recorder
+* are informed in callback function.
+*
+* Return:
+* pcm device handle
+* -1 for failure
+*****************************************************************/
+int Ql_AudRecorder_Open(char* device, _cb_onRecorder cb_fun)
+{
+ if(is_running || mbtk_audio_pcm_init()) {
+ return -1;
+ } else {
+ is_running = 1;
+ recorder_cb_fun = cb_fun;
+ return play_handle;
+ }
+}
+
+//
+// Function: Ql_AudRecorder_StartRecord
+//
+// Description:
+// Start to record.
+// The record data is output in _cb_onRecorder.
+//
+// Return:
+// 0 on success
+// -1 on failure
+int Ql_AudRecorder_StartRecord(void)
+{
+ if(!is_running) {
+ LOGE("No open device.");
+ return -1;
+ }
+
+ return mbtk_audio_pcm_recorder_start(recorder_cb_func);
+}
+
+//
+// Function: Ql_AudRecorder_Pause
+//
+// Description:
+// Pause recording
+int Ql_AudRecorder_Pause(void)
+{
+ if(!is_running) {
+ LOGE("No open device.");
+ return -1;
+ }
+
+ return mbtk_audio_pcm_recorder_pause();
+}
+
+//
+// Function: Ql_AudRecorder_Resume
+//
+// Description:
+// Resume recording
+int Ql_AudRecorder_Resume(void)
+{
+ if(!is_running) {
+ LOGE("No open device.");
+ return -1;
+ }
+
+ return mbtk_audio_pcm_recorder_resume();
+}
+
+//
+// Function: Ql_AudRecorder_Stop
+//
+// Description:
+// Stop recording
+void Ql_AudRecorder_Stop(void)
+{
+ if(!is_running) {
+ LOGE("No open device.");
+ return;
+ }
+
+ mbtk_audio_pcm_recorder_stop();
+}
+
+//
+// Function: Ql_AudRecorder_Close
+//
+// Description:
+// Close recorder, and free the resource
+void Ql_AudRecorder_Close(void)
+{
+ if(!is_running) {
+ LOGE("No open device.");
+ return;
+ }
+
+ is_running = 0;
+ mbtk_audio_pcm_deinit();
+}
+
+//
+// Function: Ql_clt_set_mixer_value
+//
+// Description:
+// Close recorder, and free the resource
+boolean Ql_clt_set_mixer_value(const char *device, int count, const char *value)
+{
+
+ return FALSE;
+}
+
+
+int Ql_AudTone_Open(char* device, _cb_onPlayer cb)//cb not support now
+{
+ return 0;
+}
+
+int Ql_AudTone_Start(int hdl, struct Ql_TonePara *para)
+{
+ return 0;
+}
+
+void Ql_AudTone_Stop(int hdl)
+{
+
+}
+
+void Ql_AudTone_Close(int hdl)
+{
+
+}
+
+
+//****************QL Codec API************************//
+
+//
+// Function: Ql_AudCodec_Set_ALC5616_DRCAGC
+//
+// Description:
+// Set ALC5616 DRC/AGC configuration
+int Ql_AudCodec_Set_ALC5616_DRCAGC(const char *i2c, struct Ql_ALC5616_DRCAGC *cfg)
+{
+ return 0;
+}
+
+//
+// Function: Ql_Update_wav_size
+//
+// Description:
+// update wav format file size in the header
+// @param fd:
+// wav file discriptor
+// @param size:
+// wav file size to update
+int Ql_Update_wav_size(int fd, int size)
+{
+ return 0;
+}
+
+//add by grady, 2018-5-29
+/*
+ * describe : this function is use to open pcm device
+ * paras :
+ * device : this should be fix to hw:0,0
+ * flags ; pcm play flags
+ * rate: sample rate
+ * channels : audio channal 1 or 2
+ * format: format to play or record, 16bit line,MP3
+ * hostless: if there is no file it is true
+ * return :
+ * pcm : pcm handle, use can use this handle to read write data
+ */
+struct pcm *quec_pcm_open(char *device, unsigned flags, unsigned rate, unsigned channels, unsigned format, unsigned hostless)
+{
+ return NULL;
+}
+
+/*
+ * describe : this function is use to close pcm handle
+ * paras :
+ * pcm : pcm handle to close
+ * return :
+ */
+int quec_pcm_close(struct pcm *pcm )
+{
+ return 0;
+}
+
+/*
+ * describe : this function is use to read pcm buffer
+ * paras :
+ * pcm : pcm handle to write date
+ * buffer: data buffer
+ * lenth: data length
+ * return :
+ */
+int quec_read_pcm(struct pcm *pcm, void * buffer, int length)
+{
+
+ return 0;
+}
+
+/*
+ * describe : this function is use to get pcm buffer lenth
+ * paras :
+ * lenth: data length
+ * return
+ * buffer length
+ */
+int quec_get_pem_buffer_len(struct pcm *pcm)
+{
+
+ return 0;
+}
+
+void dtmf_cb1(char dtmf)
+{
+ printf("%s:%c\n", __FUNCTION__, dtmf);
+}
+
+/**
+ * @brief Set RX DSP Gain
+ * @details
+ * Gain support [-36,12] dB
+ *
+ * @param gain
+ * DSP gain
+ */
+
+int Ql_Rxgain_Set(int value)
+{
+#ifdef MBTK_AF_SUPPORT
+ int volume =0;
+ if(value < -36 || value > 13)
+ {
+ volume = 0;
+ }
+ else
+ {
+ volume = value;
+ }
+
+ if(player_hdl==NULL)
+ return 0;
+
+ char databuf[1025]={0};
+ memcpy(databuf, " ", 1024);
+
+ mbtk_audio_play_stream_new(player_hdl, databuf, 1024, volume);
+ return 0;
+#else
+ mbtk_dsp_gain_set(1, value);
+ return 0;
+#endif
+ return 0;
+}
+
+
+/** Ql_Playback_Samprate_Set
+ * @brief Set Playback PCM Samprate
+ * @details
+ * 0 for NB 1 for WB
+ *
+ * @param samprate
+ * samprate for PCM playback,default value is PCM NB
+ */
+int Ql_Playback_Samprate_Set(int samprate)
+{
+ printf("samprate is %d \n",samprate);
+ if(samprate == 1)
+ {
+ sample_rate = 16000;
+ mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_16000);
+ }
+ else{
+ mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_8000);
+ sample_rate = 8000;
+ }
+
+ return 0;
+}
+
+int Ql_Mp3_To_Wav(const char *wavpath, char *mp3path)
+{
+ return 0;
+}
+
+int Ql_Mp3_To_Play(char *mp3path, int hdl,int sample_rate)
+{
+ return 0;
+}
+
+//add by grady, 2018-6-2
+/*
+ * describe : this function is use to open mixer device
+ * paras :
+ * device: mixer device
+ * return
+ * mixer handle
+ */
+struct mixer *quec_mixer_open(const char *device)
+{
+
+ return NULL;
+}
+
+/*
+ * describe : this function is use to close mixer device
+ * paras :
+ * mixer: mixer handle
+ * return
+ * none
+ */
+void quec_mixer_close(struct mixer *mixer)
+{
+
+
+}
+
+/*
+ * describe : this function is use to get mixer devie control
+ * paras :
+ * mixer: mixer handle
+ * name: mixer device
+ * index: mixer index
+ * return
+ * mixer control
+ */
+struct mixer_ctl *quec_mixer_get_control(struct mixer *mixer, const char *name, unsigned index)
+{
+
+ return NULL;
+}
+
+/*
+ * describe : this function is use to set mulvalues
+ * paras :
+ * mixer: mixer handle
+ * count: count
+ * argv: data
+ * return :
+ *
+ */
+int quec_mixer_ctl_mulvalues(struct mixer_ctl *ctl, int count, char ** argv)
+{
+
+ return 0;
+}
+
+
+//end grady
+
+/*****************************************************************
+* Function: Ql_AudPlayer_OpenExt
+*
+* Description:
+* expend function from Ql_AudPlayer_OpenExt
+* Open audio play device, and specify the callback function.
+* This function can be called twice to play different audio sources.
+*
+* Parameters:
+* device : a string that specifies the PCM device.
+* NULL, means the audio will be played on the default PCM device.
+*
+* If you want to mixedly play audio sources, you can call this
+* API twice with specifying different PCM device.
+* The string devices available:
+* "hw:0,0" (the default play device)
+* "hw:0,13" (this device can mix audio and TTS)
+* "hw:0,14"
+*
+* cb_func : callback function for audio player.
+* The results of all operations on audio player
+* are informed in callback function.
+*
+* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
+*
+* channels: pcm sample channels.
+*
+* rate : pcm sample rate.
+*
+* format : pcm sample fromat
+*
+* Return:
+* pcm device handle
+* NULL, fail
+*****************************************************************/
+int Ql_AudPlayer_OpenExt(
+ char *dev,
+ _cb_onPlayer cb_fun,
+ int flags,
+ int channels,
+ int rate,
+ int format)
+{
+ return 0;
+}
+
+/*****************************************************************
+* Function: Ql_AudRecorder_Open
+*
+* Description:
+* Open audio record device, and specify the callback function.
+*
+* Parameters:
+* device : not used. MUST be NULL.
+*
+* cb_func : callback function for audio player.
+* The results of all operations on audio recorder
+* are informed in callback function.
+*
+* flags : pcm flags, eg: PCM_MMAP, PCM_NMMAP.
+*
+* channels: pcm sample channels.
+*
+* rate : pcm sample rate.
+*
+* format : pcm sample fromat
+*
+* Return:
+* pcm device handle
+* NULL, fail
+*****************************************************************/
+int Ql_AudRecorder_OpenExt(
+ char *dev,
+ _cb_onRecorder cb_fun,
+ int flags,
+ int channels,
+ int rate,
+ int format)
+{
+
+
+ return 0;
+}
+
+/*
+* Function: uac enable
+*
+* Description:
+* uac enable
+*
+* Parameters:
+* none
+* Return:
+* TURE or FALSE
+*/
+int ql_uac_enable(void)
+{
+
+ return 0;
+}
+
+/*
+* Function: uac disable
+*
+* Description:
+* uac disable
+*
+* Parameters:
+* none
+* Return:
+* TURE or FALSE
+*/
+int ql_uac_disable(void)
+{
+
+ return 0;
+}
diff --git a/mbtk/libql_lib_v2/src/ql_call.c b/mbtk/libql_lib_v2/src/ql_call.c
new file mode 100755
index 0000000..700f93d
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_call.c
@@ -0,0 +1,821 @@
+/**
+ * \file ql_call.c
+ * \brief A Documented file.
+ *
+ * Detailed description
+ * \Author: js.wang<js.wang@mobiletek.cn>
+ * \Version: 1.0.0
+ * \Date: 2022-01-18
+ */
+#include "ql/ql_mcm_call.h"
+#include <telephony/ril.h>
+#include <telephony/ril_ext.h>
+#include "ql/ql_mcm.h"
+#include "rilutil.h"
+#include "mbtk_log.h"
+
+// #define DEBUG 1
+
+#ifdef DEBUG
+ #define mbtk_call_log(...) printf(__VA_ARGS__)
+#else
+ #define mbtk_call_log(...)
+#endif
+
+struct ql_call_ubus_t
+{
+ struct ubus_context *ctx;
+
+ /* RIL */
+ struct ubus_subscriber ril_ind_event;
+ uint32_t ril_subscriber_id;
+ uint32_t ril_request_id;
+ uint8_t auto_answer;
+ uint32_t answer_time;
+ pthread_t call_status_pthread;
+ ql_mcm_voice_calls_state_t call_state;
+ QL_VoiceCall_CommonStateHandlerFunc_t _voice_call_common_state_handler;
+ QL_VoiceCall_StateHandlerFunc_t _voice_call_state_handler;
+};
+
+const char *RIL_MessageMap[] =
+{
+ "RIL_CALL_ACTIVE", //0,
+ "RIL_CALL_HOLDING", //1,
+ "RIL_CALL_DIALING", //2, /* MO call only */
+ "RIL_CALL_ALERTING", //3, /* MO call only */
+ "RIL_CALL_INCOMING", //4, /* MT call only */
+ "RIL_CALL_WAITING", //5, /* MT call only */
+ "RIL_CALL_OFFERING", //6, /* MT call offering (call setup) */
+ "RIL_CALL_DISCONNECTING",//7, /* call in disconnect procedure */
+ "RIL_CALL_DISCONNECTED" //8, /* call is disconnected */
+};
+static struct ql_call_ubus_t *ql_call_ubus = NULL;
+static void ql_voice_call_answer(struct uloop_timeout *timeout);
+static struct uloop_timeout voice_call_answer_timeout =
+{
+ .cb = ql_voice_call_answer,
+};
+
+static void ql_voice_call_answer(struct uloop_timeout *timeout)
+{
+ QL_Voice_Call_Answer(ql_call_ubus, 0);
+ // uloop_timeout_set(timeout, 2000);
+ return;
+}
+
+int ql_call_handle_ril_ind(struct ubus_context *ctx, unsigned int rilid, unsigned int rilerror, char *data, int data_len)
+{
+ UNUSED(data_len);
+ UNUSED(ctx);
+
+ int datalen = 0, callID = 0;
+ int ret = 0;
+
+ if (rilerror) {
+ return -1;
+ }
+
+ mbtk_call_log("call_handle_ril_ind: rcv %d\n", rilid);
+
+ switch(rilid)
+ {
+ case RIL_UNSOL_ECALLDATA: //+ecalldata
+ // ecallHandleEcalldata(data);
+ break;
+
+ case RIL_UNSOL_ECALLONLY: //+ecallonly
+ // ecallHandleEcallonly(data);
+ break;
+
+ case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED_EXT: /*"CC" 1510*/
+ {
+ RIL_Call *rilCall = (RIL_Call *)data;
+ callID = rilCall->index;
+
+ mbtk_call_log("%s: id %d=RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED_EXT (len=%d) (state=%s), call index=%d\n",
+ __FUNCTION__, rilid, datalen, RIL_MessageMap[(int)rilCall->state], callID);
+
+ mbtk_call_log("Received from Ril, name=%s, num=%s\n", rilCall->name, rilCall->number);
+ ql_call_ubus->call_state.calls_len = 1;
+ ql_call_ubus->call_state.calls[0].call_id;
+ memcpy(ql_call_ubus->call_state.calls[0].number, rilCall->number, strlen(rilCall->number));
+ ql_call_ubus->call_state.calls[0].state = rilCall->state;
+ switch (rilCall->state)
+ {
+ //Call connected, for MO & MT both
+ case RIL_CALL_ACTIVE:
+ mbtk_call_log("%s, RIL_CALL_ACTIVE, call index=%d connected!!\n", __FUNCTION__, callID);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_ACTIVE;
+ break;
+
+ //MT call only
+ case RIL_CALL_INCOMING:
+ mbtk_call_log("%s, RIL_CALL_INCOMING!!\n", __FUNCTION__);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_INCOMING;
+ if(!ql_call_ubus->auto_answer)
+ {
+ mbtk_call_log("%s, auto_answer:%d!!\n", __FUNCTION__, ql_call_ubus->answer_time);
+ uloop_timeout_set(&voice_call_answer_timeout, ql_call_ubus->answer_time);
+ }
+ break;
+
+ //MO call only
+ case RIL_CALL_ALERTING:
+ mbtk_call_log("%s, RIL_CALL_ALERTING, call index=%d alerting!!\n", __FUNCTION__, callID);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_ALERTING;
+ break;
+
+ case RIL_CALL_WAITING: //MT call only
+ mbtk_call_log("%s, RIL_CALL_WAITING, call index=%d alerting!!\n", __FUNCTION__, callID);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_WAITING;
+ break;
+
+ case RIL_CALL_DISCONNECTED:
+ mbtk_call_log("%s, RIL_CALL_DISCONNECTED, call index=%d disconnected!!\n", __FUNCTION__, callID);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_END;
+ break;
+
+ case RIL_CALL_HOLDING:
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_HOLDING;
+ mbtk_call_log("%s, RIL_CALL_HOLDING, call index=%d hold!!\n", __FUNCTION__, callID);
+ break;
+
+ case RIL_CALL_DIALING: //MO call only
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_DIALING;
+ mbtk_call_log("%s, RIL_CALL_DIALING, call index=%d hold!!\n", __FUNCTION__, callID);
+ break;
+ case RIL_CALL_OFFERING:
+ case RIL_CALL_DISCONNECTING:
+ default:
+ printf("%s, state=%s ignored!!\n", __FUNCTION__, RIL_MessageMap[(int)rilCall->state]);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_END;
+ break;
+ }
+ if(ql_call_ubus->_voice_call_common_state_handler && ql_call_ubus)
+ {
+ ql_call_ubus->_voice_call_common_state_handler(E_QL_MCM_VOICE_CALL_IND, &ql_call_ubus->call_state, sizeof(ql_mcm_voice_call_ind));
+ }
+ }
+ break;
+ case RIL_UNSOL_CALL_NO_CARRIER_EXT: /*"CC" 1511*/
+ mbtk_call_log("%s: id %d=RIL_UNSOL_CALL_NO_CARRIER_EXT (len=%d)\n",
+ __FUNCTION__, rilid, datalen);
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_END;
+ if(ql_call_ubus->_voice_call_common_state_handler && ql_call_ubus)
+ {
+ ql_call_ubus->_voice_call_common_state_handler(E_QL_MCM_VOICE_CALL_IND, &ql_call_ubus->call_state, sizeof(ql_mcm_voice_call_ind));
+ }
+ break;
+
+ case RIL_UNSOL_CALL_RING: /*"CC" 1018*/
+ printf("%s: id %d=RIL_UNSOL_CALL_RING (len=%d), ignored!!\n",
+ __FUNCTION__, rilid, datalen);
+ break;
+
+ case RIL_UNSOL_DISCONNECT_CALLID: /*"CC" 1538*/
+ callID = *(int *)data;
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_END;
+ mbtk_call_log("%s: id %d=RIL_UNSOL_DISCONNECT_CALLID (len=%d), call index=%d!\n",
+ __FUNCTION__, rilid, datalen, *(int *)data);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+static void ql_call_requset_cb(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+ unsigned int requestid;
+ unsigned int rilerrno;
+ void *response = NULL;
+ int responselen;
+ int ret = 0;
+
+ ret = rilutil_parseResponse(msg, &requestid, &rilerrno, &response, &responselen);
+ if(ret)
+ {
+ fprintf(stderr, "parse blob error\n");
+ goto done;
+ }
+
+ if(rilerrno)
+ {
+ // RIL_REQUEST_RELEASE_CALL
+ fprintf(stderr, "unsolicited id %d, error code %d\n", requestid, rilerrno);
+ goto done;
+ }
+
+ //process response here
+
+done:
+ if(response)
+ rilutil_freeResponseData(requestid, response, responselen);
+
+ return;
+}
+
+int ql_call_subscriber_cb(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method, struct blob_attr *msg)
+{
+ UNUSED(ctx);
+ UNUSED(obj);
+ UNUSED(req);
+ UNUSED(method);
+
+ unsigned int requestid = 0;
+ unsigned int rilerrno = 0;
+ void *response = NULL;
+ int responselen = 0;
+ int ret = 0;
+
+ ret = rilutil_parseResponse(msg, &requestid, &rilerrno, &response, &responselen);
+ if (ret)
+ goto end;
+
+ mbtk_call_log("call_subscriber_cb: rcv %d\n", requestid);
+
+ ql_call_handle_ril_ind(ctx, requestid, rilerrno, response, responselen);
+
+end:
+ if (response)
+ rilutil_freeResponseData(requestid,response,responselen);
+
+ return 0;
+}
+
+void ql_call_subscriber_remove_cb(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id)
+{
+ UNUSED(ctx);
+ UNUSED(obj);
+ UNUSED(id);
+ mbtk_call_log("ql_call_subscriber_remove_cb\n");
+}
+
+static void ql_call_register_ril(void* hdl)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)hdl;
+ int ret;
+
+ if(hdl == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ pthread_detach(pthread_self());
+ ret = ubus_register_subscriber(voice_call_ubus->ctx, &voice_call_ubus->ril_ind_event);
+ if (ret) {
+ printf("call_daemon: Failed to add ecall_subscriber: %s\n", ubus_strerror(ret));
+ return ret;
+ }
+
+ voice_call_ubus->ril_ind_event.cb = ql_call_subscriber_cb;
+ voice_call_ubus->ril_ind_event.remove_cb = ql_call_subscriber_remove_cb;
+
+ //register for CC ind
+ if (ubus_lookup_id(voice_call_ubus->ctx, "ril.unsol.cc", &voice_call_ubus->ril_subscriber_id)) {
+ printf("call_daemon: Failed to look up ril.unsol.cc object\n");
+ return ret;
+ }
+
+ ubus_subscribe(voice_call_ubus->ctx, &voice_call_ubus->ril_ind_event, voice_call_ubus->ril_subscriber_id);
+ mbtk_call_log("call_daemon: subscribe ril.unsol.cc object ok\n");
+ mbtk_call_log("%s!\n", __FUNCTION__);
+ while(1)
+ {
+ uloop_run();
+ printf("%s uloop_run done!\n", __FUNCTION__);
+ }
+ pthread_exit(NULL);
+}
+/* Init voice module and return h_voice, this should be called before any other APIs */
+int QL_Voice_Call_Client_Init(voice_client_handle_type *ph_voice)
+{
+ int id;
+ // Set call handle.
+ //*ph_voice = 1;
+ if(ph_voice == NULL)
+ {
+ printf("ARG error or has inited.");
+ return -1;
+ }
+ ql_call_ubus = malloc(sizeof(struct ql_call_ubus_t));
+ if(NULL == ql_call_ubus)
+ {
+ printf("malloc memory error\n");
+ }
+ memset(ql_call_ubus, 0, sizeof(struct ql_call_ubus_t));
+ uloop_init();
+
+ ql_call_ubus->ctx = ubus_connect(NULL);
+ if(!ql_call_ubus->ctx)
+ {
+ printf("Failed to connect to ubus");
+ goto out;
+ }
+
+ ubus_add_uloop(ql_call_ubus->ctx);
+
+ if (ubus_lookup_id(ql_call_ubus->ctx, "ril", &ql_call_ubus->ril_request_id)) {
+ fprintf(stderr, "%s, Failed to look up test object\n", __FUNCTION__);
+ return -1;
+ }
+ ql_call_ubus->auto_answer = E_QL_MCM_VOICE_AUTO_ANSWER_DISABLE;
+ ql_call_ubus->call_state.calls[0].state = E_QL_MCM_VOICE_CALL_STATE_END;
+ pthread_create(&ql_call_ubus->call_status_pthread, NULL, (void *)ql_call_register_ril, (void *)ql_call_ubus);
+ *ph_voice = ql_call_ubus;
+
+ return 0;
+out:
+ //uloop_done();
+
+ return 0;
+}
+
+/* DeInit voice module and release resources, this should be called at last */
+int QL_Voice_Call_Client_Deinit(voice_client_handle_type h_voice)
+{
+ int ret;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ // Free handle.
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ LOGE("ARG error or not inited.");
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ ret = pthread_cancel(voice_call_ubus->call_status_pthread);
+ mbtk_call_log("kill pthread : %d \n", ret);
+ pthread_join(voice_call_ubus->call_status_pthread, NULL);
+ do{
+ ret = pthread_kill(voice_call_ubus->call_status_pthread, 0);
+ mbtk_call_log("kill pthread: %d \n", ret);
+ if(ret == ESRCH)
+ printf("The specified thread does not exist or has terminated\n");
+ else if(ret == EINVAL)
+ printf("Useless signal\n");
+ else
+ mbtk_call_log("The thread exists\n");
+ usleep(100000);
+ }while(0 == ret);
+ free(h_voice);
+ ql_call_ubus = NULL;
+ uloop_done();
+ ubus_free(voice_call_ubus->ctx);
+ return 0;
+}
+
+/* Add callback function, if any call state changed, handlerPtr will be called to notify App */
+int QL_Voice_Call_AddStateHandler(voice_client_handle_type h_voice,
+ QL_VoiceCall_StateHandlerFunc_t handlerPtr,
+ void* contextPtr)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ ret = pthread_kill(voice_call_ubus->call_status_pthread, 0);
+ mbtk_call_log("kill pthread: %d \n", ret);
+ if(ret == ESRCH)
+ mbtk_call_log("The specified thread does not exist or has terminated\n");
+ else if(ret == EINVAL)
+ printf("Useless signal\n");
+ else
+ mbtk_call_log("The thread exists\n");
+ if(voice_call_ubus->ril_subscriber_id)
+ {
+ voice_call_ubus->_voice_call_state_handler = handlerPtr;
+ }
+ else
+ {
+ printf("%s error!!\n", __func__);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Remove callback function, won't receive any notify anymore */
+int QL_Voice_Call_RemoveStateHandler(voice_client_handle_type h_voice)
+{
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ LOGE("ARG error or not inited.");
+ return -1;
+ }
+ voice_call_ubus->_voice_call_state_handler = NULL;
+
+ return 0;
+}
+
+
+/* Add callback function, if any call state changed, handlerPtr will be called to notify App */
+int QL_Voice_Call_AddCommonStateHandler(voice_client_handle_type h_voice,
+ QL_VoiceCall_CommonStateHandlerFunc_t handlerPtr)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ LOGE("ARG error or not inited.");
+ return -1;
+ }
+ ret = pthread_kill(voice_call_ubus->call_status_pthread, 0);
+ mbtk_call_log("kill pthread: %d \n", ret);
+ if(ret == ESRCH)
+ mbtk_call_log("The specified thread does not exist or has terminated\n");
+ else if(ret == EINVAL)
+ printf("Useless signal\n");
+ else
+ mbtk_call_log("The thread exists\n");
+ if(voice_call_ubus->ril_subscriber_id)
+ {
+ voice_call_ubus->_voice_call_common_state_handler = handlerPtr;
+ }
+ else
+ {
+ printf("%s error!!\n", __func__);
+ return -1;
+ }
+
+
+ return 0;
+}
+
+/* Remove callback function, won't receive any notify anymore */
+int QL_Voice_Call_RemoveCommonStateHandler(voice_client_handle_type h_voice)
+{
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ LOGE("ARG error or not inited.");
+ return -1;
+ }
+ voice_call_ubus->_voice_call_common_state_handler = NULL;
+
+ return 0;
+}
+
+
+/* Start call and return call_id, this can be used in the later */
+int QL_Voice_Call_Start(voice_client_handle_type h_voice,
+ E_QL_VCALL_ID_T simId,
+ char* phone_number, ///< [IN] Destination identifier for the voice
+ int *call_id) ///< [OUT] call id
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ static struct blob_buf b;
+ int id, ret;
+ RIL_Dial dial_data;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ if(voice_call_ubus->call_state.calls[0].state == E_QL_MCM_VOICE_CALL_STATE_ACTIVE ||
+ voice_call_ubus->call_state.calls[0].state == E_QL_MCM_VOICE_CALL_STATE_INCOMING ||
+ voice_call_ubus->call_state.calls[0].state == E_QL_MCM_VOICE_CALL_STATE_ALERTING)
+ {
+ printf("A call already exists, Voice Call incoming or active!!\n");
+ return -1;
+ }
+ memset(&dial_data, 0, sizeof(RIL_Dial));
+ dial_data.address = phone_number;
+ printf("call number %s\n", dial_data.address);
+ if (ubus_lookup_id(ql_call_ubus->ctx, "ril", &ql_call_ubus->ril_request_id)) {
+ fprintf(stderr, "%s, Failed to look up test object\n", __FUNCTION__);
+ return -1;
+ }
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_DIAL, &dial_data, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("sim_get_imsi,ubus_invoke Failed %s\n", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+
+ return 0;
+}
+
+/* End call of call_id, which returned by QL_Voice_Call_Start or callback func register via QL_Voice_Call_AddStateHandler */
+int QL_Voice_Call_End(voice_client_handle_type h_voice,
+ int call_id) ///< [IN] call id, return by QL_Voice_Start
+{
+ static struct ubus_request req;
+ static struct blob_buf b;
+ int ret;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ mbtk_call_log("Voice Call State:%s, %d\n", voice_call_ubus->call_state.calls[0].number, voice_call_ubus->call_state.calls[0].state);
+ if(voice_call_ubus->call_state.calls[0].state != E_QL_MCM_VOICE_CALL_STATE_ACTIVE &&
+ voice_call_ubus->call_state.calls[0].state != E_QL_MCM_VOICE_CALL_STATE_INCOMING &&
+ voice_call_ubus->call_state.calls[0].state != E_QL_MCM_VOICE_CALL_STATE_ALERTING)
+ {
+ printf("No Voice Call incoming or active!!\n");
+ return -1;
+ }
+ //use rilutil's API, just a example
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_RELEASE_CALL, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("sim_get_imsi,ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+/* Answer the call of call_id, which returned by callback func register via QL_Voice_Call_AddStateHandler */
+int QL_Voice_Call_Answer(voice_client_handle_type h_voice,
+ int call_id )
+{
+ static struct ubus_request req;
+ static struct blob_buf b;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_ANSWER, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("ql call, ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+int QL_Voice_Call_Hold( voice_client_handle_type h_voice)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ static struct blob_buf b;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_HANGUP, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("ql call, ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+int QL_Voice_Call_UnHold( voice_client_handle_type h_voice)
+{
+
+ return 0;
+}
+
+int QL_Voice_Call_Conference( voice_client_handle_type h_voice)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ static struct blob_buf b;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_CONFERENCE, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("ql call, ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+int QL_Voice_Call_EndConference( voice_client_handle_type h_voice)
+{
+
+ return 0;
+}
+
+int QL_Voice_Call_Ecall(voice_client_handle_type h_voice,
+ E_QL_VCALL_ID_T simId,
+ char* phone_number,
+ ql_mcm_ecall_info ecall_info,
+ int *call_id)
+{
+// RIL_REQUEST_SET_CECALL
+// RIL_REQUEST_GET_CECALL
+// RIL_REQUEST_SET_ECALLONLY
+// RIL_REQUEST_GET_ECALLONLY
+// RIL_REQUEST_SET_ECALLREG
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ static struct blob_buf b;
+ int ret;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ //use rilutil's API, just a example
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_CONFERENCE, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("ql call, ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+
+int QL_Voice_Call_SetAutoAnswer(voice_client_handle_type h_voice,
+ E_QL_MCM_VOICE_AUTO_ANSWER_T eAnswerType,
+ uint32_t uAnswerTime)
+{
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ voice_call_ubus->auto_answer = eAnswerType;
+ voice_call_ubus->answer_time = uAnswerTime;
+
+ return 0;
+}
+
+int QL_Voice_Call_Ecall_HangUp(voice_client_handle_type h_voice)
+{
+ return 0;
+}
+
+int QL_Voice_Call_Ecall_UpdateMsd(voice_client_handle_type h_voice,const char *msd,uint32_t msd_len)
+{
+ return 0;
+}
+
+//Ecall Push caommand
+int QL_Voice_Call_Ecall_MsdPush(voice_client_handle_type h_voice,
+ E_QL_MCM_ECALL_STATE_T *ecall_state)
+{
+ return 0;
+}
+
+//Get Ecall config info
+int QL_Voice_Call_Ecall_GetConfigInfo(voice_client_handle_type h_voice,
+ ql_mcm_ecall_config_info *ecall_config)
+{
+// RIL_REQUEST_SET_ECALLCFG
+// RIL_REQUEST_GET_ECALLCFG
+ return 0;
+}
+
+int QL_Voice_Call_Ecall_SetConfigInfo(voice_client_handle_type h_voice,
+ E_QL_MCM_ECALL_CONFIG_T ecall_config_type,
+ uint8_t value)
+{
+ return 0;
+}
+
+//Cancel dial
+int QL_Voice_Call_CancelDial( voice_client_handle_type h_voice)
+{
+ static struct ubus_request req;
+ static struct blob_buf b;
+ int ret;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ //use rilutil's API, just a example
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_RELEASE_CALL, NULL, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("sim_get_imsi,ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+//VTS API
+int QL_Voice_Call_Dtmf(voice_client_handle_type h_voice, uint8_t digit, int call_id)
+{
+ static struct ubus_request req;
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+ static struct blob_buf b;
+ int ret;
+ char code = digit;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ rilutil_makeRequestBlob(&b, RIL_REQUEST_DTMF, &code, 0);
+ ret = ubus_invoke(voice_call_ubus->ctx, voice_call_ubus->ril_request_id, "ril_request", b.head, ql_call_requset_cb, 0,0);
+ if(ret != 0)
+ {
+ printf("ql call, ubus_invoke Failed %s", ubus_strerror(ret));
+ return E_QL_ERROR_GENERIC;
+ }
+ return 0;
+}
+
+int QL_Voice_Call_GetCallStatus
+(
+ int h_voice,
+ int call_id, // If call_id<0, means to get all calls state, or get specified call_id info
+ ql_mcm_voice_calls_state_t *pt_callstate
+)
+{
+ struct ql_call_ubus_t *voice_call_ubus = (struct ql_call_ubus_t *)h_voice;
+
+ if(h_voice == NULL || ql_call_ubus == NULL)
+ {
+ printf("ARG error or not inited.");
+ return -1;
+ }
+ memcpy((void *)pt_callstate, &voice_call_ubus->call_state, sizeof(ql_mcm_voice_calls_state_t));
+ return 0;
+}
+
+//Set forwarding
+int QL_Voice_Call_SetForwarding
+(
+ int h_voice,
+ E_QL_MCM_VOICE_CALL_SERVICE_T service,
+ E_QL_MCM_VOICE_CALL_FORWARDING_REASON_T reason,
+ char *number
+)
+{
+
+ return 0;
+}
+
+//Get forwarding status
+int QL_Voice_Call_GetForwardingStatus(
+ int h_voice,
+ E_QL_MCM_VOICE_CALL_FORWARDING_REASON_T reason,
+ ql_mcm_voice_call_forwarding_status_list_t *pt_status)
+{
+
+ return 0;
+}
+
+
+//Set voice call waiting
+int QL_Voice_Call_SetWaiting
+(
+ int h_voice,
+ ql_mcm_voice_call_waiting_service_t e_service
+)
+{
+// RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
+ return 0;
+}
+
+//Get voice call waiting status
+int QL_Voice_Call_GetWaitingStatus
+(
+ int h_voice,
+ ql_mcm_voice_call_waiting_service_t *pe_service
+)
+{
+
+ return 0;
+}
diff --git a/mbtk/libql_lib_v2/src/ql_cell_locator.c b/mbtk/libql_lib_v2/src/ql_cell_locator.c
new file mode 100755
index 0000000..b36075d
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_cell_locator.c
@@ -0,0 +1,347 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define LOG_TAG "mbtk_http"
+#include "mbtk_type.h"
+#include "mbtk_http.h"
+#include "mbtk_log.h"
+#include "mbtk_info_api.h"
+#include "ql/ql_cell_locator.h"
+
+
+static int http_handle;
+static int http_session;
+
+static char Server[128]={0};
+static char Token[128] = {0};
+static char Loction[128]={0};
+static int PORT = 0;
+static int locator_timeout = 60; // 60s for default.
+
+static int mbtk_lbs_http_parse_location(char* buf, int len, char* rspBuf)
+{
+ if(buf != NULL && len != 0)
+ {
+ char* pos0 = NULL;
+ char* pos1 = NULL;
+ char fac[64] = {'\0'};
+ pos0 = strstr(buf, "<info>");
+ if(pos0 != NULL)
+ {
+ pos1 = strstr(pos0 + 1, "</info>");
+ if(pos1 != NULL)
+ {
+ strncpy(fac, pos0 + 6, pos1 - pos0 - 6);
+ }
+ if(strcmp(fac, "OK") == 0)
+ {
+ char* l_pos0 = NULL;
+ char* l_pos1 = NULL;
+ char* type_pos0 = NULL;
+ char* type_pos1 = NULL;
+ char fac_type[64] = {'\0'};
+ type_pos0 = strstr(buf, "<type>");
+ if(type_pos0 != NULL)
+ {
+ type_pos1 = strstr(type_pos0 + 1, "</type>");
+ if(type_pos1 != NULL)
+ {
+ strncpy(fac_type, type_pos0 + 6, type_pos1 - type_pos0 - 6);
+ if(strcmp(fac_type, "0") == 0)
+ {
+ return -1;
+ }
+ }
+ }
+ l_pos0 = strstr(buf, "<location>");
+ if(l_pos0 != NULL)
+ {
+ l_pos1 = strstr(l_pos0 + 1, "</location>");
+ if(l_pos1 != NULL)
+ {
+ strncpy(rspBuf, l_pos0 + 10, l_pos1 - l_pos0 - 10);
+ }
+ return 0;
+ }
+ }
+ else //key error http chunk
+ {
+ printf("info is %s", fac);
+ }
+ }
+ }
+ return -1;
+}
+
+
+
+static void http_data_cb_func1(
+ int session_id, mbtk_http_data_type_enum type,
+ void *data,int data_len)
+{
+ if(type == MBTK_HTTP_DATA_HEADER) {
+ LOGE("Header(%d):%s\n",data_len,(char*)data);
+ } else if(type == MBTK_HTTP_DATA_CONTENT) {
+ LOGE("Data(%d):%s\n",data_len,(char*)data);
+ mbtk_lbs_http_parse_location((char*)data, data_len, Loction);
+ } else {
+ LOGI(">>>>>Complete<<<<<\n");
+ }
+}
+
+
+int ql_cell_locator_init()
+{
+ http_handle = mbtk_http_handle_get(TRUE, http_data_cb_func1);
+ if(http_handle < 0)
+ {
+ LOGE("mbtk_http_handle_get() fail.");
+ return -1;
+ }
+
+ http_session = mbtk_http_session_create(http_handle,HTTP_OPTION_GET,HTTP_VERSION_1_1);
+ if(http_session < 0)
+ {
+ LOGE("mbtk_http_session_create() fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int ql_cell_locator_release()
+{
+ if(mbtk_http_handle_free(http_handle))
+ {
+ LOGE("mbtk_http_handle_free() fail.");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @brief set locator query server and port, server length must be less than 255 bytes.
+ @param[in] server the query server ip address
+ @param[in] port the query server port
+ @return if success return 0, else return -1
+ */
+/*-----------------------------------------------------------------------------------------------*/
+int ql_cell_locator_set_server(const char *server, unsigned short port)
+{
+ if(server == NULL)
+ {
+ return -1;
+ }
+
+ memset(Server, 0, sizeof(Server));
+ memcpy(Server, server, strlen(server));
+ PORT = port;
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @brief set locator query timeout, the value must between 1-300 [seconds]
+ @param[in] timeout value of query timeout
+ @return if success return 0, else return -1
+ */
+/*-----------------------------------------------------------------------------------------------*/
+int ql_cell_locator_set_timeout(unsigned short timeout)
+{
+ locator_timeout = timeout;
+ return 0;
+}
+
+
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @brief set locator query token, token length must be 16 bytes. the token Used to verify that
+ the client accessing the service is valid.
+ @param[in] token string of token which want to be setted.
+ @param[in] length of token string.
+ @return if success return 0, else return -1
+ */
+/*-----------------------------------------------------------------------------------------------*/
+int ql_cell_locator_set_token(const char *token, int len)
+{
+ if(token == NULL && (strlen(token) != len) && len > 128)
+ {
+ return -1;
+ }
+
+ memset(Token, 0, sizeof(token));
+ memcpy(Token, token, strlen(token));
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @brief perform cell locator query
+ @param[out] resp include query result or set the error_msg and error_code
+ @return if success return 0, else return -1
+ */
+/*-----------------------------------------------------------------------------------------------*/
+int ql_cell_locator_perform(ql_cell_resp *resp)
+{
+
+ int ret = 0;
+ int ret1 = 0;
+
+ char url[1024] = {0};
+ char imei[50] ={0};
+ char cellinfo[512] = {0};
+ char *p = cellinfo;
+ int i =0;
+ int mcc,mnc,tac,ci,rsrp;
+
+ mbtk_info_handle_t* info_handle = mbtk_info_handle_get();
+ if(!info_handle)
+ {
+ return -1;
+ }
+
+ mbtk_imei_get(info_handle, imei);
+
+ list_node_t* cell_list = NULL;
+ int type, err;
+ int CellId;
+ err = mbtk_cell_get(info_handle, &type, &cell_list);
+ if(err || cell_list == NULL) {
+ printf("Error : %d\n", err);
+ }
+ else
+ {
+ list_first(cell_list);
+ mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
+ if(cell)
+ { // Current server cell.
+ switch(type)
+ {
+ case 0:
+ LOGE("GSM : mcc=%d, mnc=%d, lac=%d, ci=%d, arfcn=%d, bsic=%d\n",cell->value5, cell->value6,cell->value1, cell->value2, cell->value3, cell->value4);
+ mcc = cell->value5;
+ mnc = cell->value6;
+ tac = cell->value1;
+ ci = cell->value2;
+ rsrp = 30;
+ break;
+ case 1:
+ LOGE("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
+ break;
+ case 2:
+ LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d, mcc=%d, mnc=%d ,cid=%d, rsrp=%d\n",
+ cell->value1, cell->value2, cell->value3, cell->value4, cell->value5,cell->value6, cell->value7, cell->value8,cell->value9);
+//// LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band, mcc, mnc ,cid, rsrp
+ mcc = cell->value6;
+ mnc = cell->value7;
+ tac = cell->value1;
+ ci = cell->value10;
+ rsrp = cell->value9;
+
+ // LOGE(cellinfo,"&bts=%X,%X,%d,%d,%d&nearbts=",mcc,mnc,tac,ci,rsrp-140);
+ // LOGE("cellinfo:%s\n", cellinfo);
+
+ break;
+ default:
+ break;
+ }
+ }
+
+ sprintf(cellinfo,"&bts=%X,%X,%d,%d,%d&nearbts=",mcc,mnc,tac,ci,rsrp-140);
+ while ((cell = (mbtk_cell_info_t*) list_next(cell_list)))
+ {
+ switch(type)
+ {
+ case 0:
+ LOGE("CELL : %d, %d, %d, %d, %d", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
+ if(i < 3)
+ {
+ sprintf(p+strlen(p),"%X,%X,%d,%d,%d|",cell->value5,cell->value6,cell->value1,cell->value2,29-140);
+ i++;
+ }
+ break;
+ case 1:
+ LOGE("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);
+ break;
+ case 2:
+ CellId = cell->value5;
+ // if(CellId > 0 && cell->value5 != -1)
+ if(CellId > 0 )
+ {
+ if(i < 3)
+ {
+ sprintf(p+strlen(p),"%X,%X,%d,%d,%d|",mcc,mnc,tac,cell->value5,cell->value3-140);
+ i++;
+ }
+ }
+ LOGE("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d, cellId:%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ list_free(cell_list);
+
+ sprintf(url,"http://%s:%d/position?accesstype=0&imei=%s&cdma=0%s&output=xml&key=%s",\
+ Server, PORT, imei,cellinfo, Token);
+
+
+ memset(Loction, 0, sizeof(Loction));
+
+
+ if(mbtk_http_session_url_set(http_handle, http_session, url)) {
+ LOGE("mbtk_http_session_url_set() fail.\n");
+ return -1;
+ }
+
+ const mbtk_http_session_t* session = mbtk_http_session_get(http_handle, http_session);
+ LOGI("HTTP:%d,%s,%d,%s\n",session->option,session->host,session->port,session->uri);
+
+
+ mbtk_http_session_head_add(http_handle, http_session, "Connection", "KeepAlive");
+
+
+ if(mbtk_http_session_start(http_handle, http_session)) {
+ LOGE("mbtk_http_session_start() fail.\n");
+ return -1;
+ }
+
+ if(strlen(Loction))
+ {
+ char Lon[20] ={0};
+ char Lat[20] = {0};
+ char *lon = Loction;
+ char *lat = strstr(Loction, ",");
+ if(lat != NULL )
+ {
+ memcpy(Lon, Loction, lat- lon);
+
+ lat++;
+ memcpy(Lat, lat, strlen(lat));
+
+ sscanf((char*)Lon,"%lf",&resp->lon);
+ sscanf((char*)Lat,"%lf",&resp->lat);
+ }
+
+ }
+
+// printf("lon:%f, lat:%f\n", resp->lon, resp->lat);
+// printf("\nloction:%s\n", Loction);
+
+ return 0;
+}
+
+
+
+
+
diff --git a/mbtk/libql_lib_v2/src/ql_common.c b/mbtk/libql_lib_v2/src/ql_common.c
new file mode 100755
index 0000000..70d0ad3
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_common.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include "ql/ql_common.h"
+
+void Ql_Powerdown(int mode)
+{
+ switch (mode)
+ {
+ case 1:
+ system("halt");
+ break;
+ case 2:
+ system("reboot");
+ break;
+ default:
+ printf("mode error");
+ }
+
+ return ;
+
+}
+
diff --git a/mbtk/libql_lib_v2/src/ql_data_call.c b/mbtk/libql_lib_v2/src/ql_data_call.c
new file mode 100755
index 0000000..218e14b
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_data_call.c
@@ -0,0 +1,658 @@
+#include "ql/DSI_ConnectManager.h"
+#include "mbtk_info_api.h"
+#include <fcntl.h>
+
+extern mbtk_info_handle_t* ql_info_handle;
+extern int ql_info_handle_num;
+static bool inited = FALSE;
+
+typedef struct
+{
+ bool active;
+ uint8 cid;
+ int ip_type;
+ char user[128];
+ char pass[128];
+ QL_DSI_AUTH_PREF_T auth;
+} apn_info;
+
+// 2 - 7
+static apn_info ql_apn_info[9]={0};
+static int mbtk_interval_sec = 0;
+static nw_status_cb ql_net_status_cb = NULL;
+static ex_conn_status_cb ql_net_ex_status_cb = NULL;
+static int now_cid = 0;
+
+void ql_wan_net_state_change_cb(const void* data, int data_len)
+{
+ uint8 *net_data = NULL;
+ net_data = (uint8 *)data;
+
+ if(*net_data > 100 && *net_data < 200)
+ {
+ int cid;
+ cid = *net_data;
+ cid = cid - 100;
+ ql_apn_info[cid].active = FALSE;//close
+ if(ql_net_ex_status_cb != NULL)
+ {
+ ql_net_ex_status_cb(cid, ql_apn_info[cid].ip_type, CONNECT_DISCON, 0);
+ }
+ }
+ else if(*net_data > 200)
+ {
+ int cid;
+ cid = *net_data;
+ cid = cid - 200;
+ ql_apn_info[cid].active = TRUE;//open
+ }
+ else
+ {
+ if(ql_net_status_cb != NULL)
+ {
+ ql_net_status_cb(*net_data);
+
+ if(*net_data == 25 || *net_data == 26 || *net_data == 27)
+ {
+ ql_net_status_cb(CONNECT_CONSUCCESS);
+ }
+ }
+
+ if(ql_net_ex_status_cb != NULL)
+ {
+ if(*net_data == 1)
+ {
+ ql_net_ex_status_cb(now_cid, ql_apn_info[now_cid].ip_type, CONNECT_CONSUCCESS, 0);
+ }
+ }
+ }
+
+}
+
+int ql_wan_init(void)
+{
+ if(!inited && ql_info_handle == NULL)
+ {
+ ql_info_handle = mbtk_info_handle_get();
+ if(ql_info_handle)
+ {
+ ql_info_handle_num++;
+ inited = TRUE;
+ mbtk_pdp_state_change_cb_reg(ql_info_handle, ql_wan_net_state_change_cb);
+
+ //return 0;
+ } else {
+ LOGE("mbtk_info_handle_get() fail.");
+ return -1;
+ }
+ } else {
+ if(!inited) {
+ ql_info_handle_num++;
+ inited = TRUE;
+ mbtk_pdp_state_change_cb_reg(ql_info_handle, ql_wan_net_state_change_cb);
+ }
+ //return 0;
+ }
+
+ mbtk_apn_info_t apns[10] = {0};
+ int apn_num = MBTK_APN_CID_MAX;
+ int ret = mbtk_apn_get(ql_info_handle, &apn_num, apns);
+ if(ret != 0)
+ {
+ LOGD("mbtk_apn_get ret = %d",ret);
+ }
+ else
+ {
+ int i;
+ int profile_idx;
+ for(i=0;i<MBTK_APN_CID_MAX;i++)
+ {
+ if(apns[i].cid > 0 && apns[i].cid <= MBTK_APN_CID_MAX)
+ {
+ profile_idx = apns[i].cid;
+ if(apns[i].ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6
+ ql_apn_info[profile_idx].ip_type = 0;
+ else if(apns[i].ip_type == MBTK_IP_TYPE_IP) // IPV4
+ ql_apn_info[profile_idx].ip_type = 1;
+ else if(apns[i].ip_type == MBTK_IP_TYPE_IPV6) // IPV6
+ ql_apn_info[profile_idx].ip_type = 2;
+ else
+ ql_apn_info[profile_idx].ip_type = 0;
+ }
+ }
+ }
+ return 0;
+}
+
+int ql_wan_release(void)
+{
+ if(ql_info_handle)
+ {
+ LOGD("ql_info_handle_num = %d", ql_info_handle_num);
+ if(ql_info_handle_num == 1) { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&ql_info_handle);
+ if(ret) {
+ LOGE("mbtk_info_handle_free() fail.");
+ return -1;
+ }
+ else
+ {
+ ql_info_handle_num = 0;
+ ql_info_handle = NULL;
+ return 0;
+ }
+ } else {
+ ql_info_handle_num--;
+ return 0;
+ }
+ }
+ else
+ {
+ LOGE("DATA handle not inited.");
+ return -1;
+ }
+}
+/*
+*Set data call over time.
+*/
+int ql_wan_set_autoconnect(int auto_status, int interval_sec)
+{
+ if(auto_status == 0) //不开启失败重连
+ mbtk_interval_sec = 0;
+ else //开启失败重连等待时间
+ {
+ if(interval_sec <= 0)
+ mbtk_interval_sec = interval_sec;
+ else
+ mbtk_interval_sec = 5; // 默认为5s
+ }
+ return 0;
+}
+
+#ifdef MBTK_AF_SUPPORT
+int mbtk_route_config(int profile_idx)
+{
+ char buf[1024] = {0};
+ char dns[128] = {0};
+ int offset = 0;
+ int fd = -1;
+ mbtk_ipv4_info_t ipv4;
+ mbtk_ipv6_info_t ipv6;
+ sprintf(buf, "route add default dev ccinet%d", profile_idx -1);
+ system(buf);
+
+ int ret = mbtk_data_call_state_get(ql_info_handle, profile_idx, &ipv4, &ipv6);
+ if(ret != 0)
+ return -1;
+ else
+ {
+ memset(buf, 0x0, 1024);
+ memset(dns, 0x0, 128);
+ offset = sprintf(buf, "search lan\n");
+ if(ipv4.valid)
+ {
+ if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), dns, 32) == NULL) {
+ LOGD("PrimaryDNS error.");
+ } else {
+ LOGD("PrimaryDNS : %s", dns);
+ }
+ offset += sprintf(buf + offset, "nameserver %s\n", dns);
+ memset(dns, 0x0, 128);
+ if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), dns, 32) == NULL) {
+ LOGD("SecondaryDNS error.");
+ } else {
+ LOGD("SecondaryDNS : %s", dns);
+ }
+ offset += sprintf(buf + offset, "nameserver %s\n", dns);
+ }
+ if(ipv6.valid)
+ {
+ memset(dns, 0x0, 128);
+ if(ipv6_2_str(&(ipv6.PrimaryDNS), dns))
+ {
+ LOGD("PrimaryDNS error.");
+ } else {
+ LOGD("PrimaryDNS : %s", dns);
+ }
+ offset += sprintf(buf + offset, "nameserver %s\n", dns);
+ memset(dns, 0x0, 128);
+ if(ipv6_2_str(&(ipv6.SecondaryDNS), dns))
+ {
+ LOGD("SecondaryDNS error.");
+ } else {
+ LOGD("SecondaryDNS : %s", dns);
+ }
+ offset += sprintf(buf + offset, "nameserver %s\n", dns);
+ }
+
+ if(offset > 0)
+ {
+ fd = open("/tmp/resolv.conf", O_WRONLY | O_TRUNC);
+ if(fd < 0)
+ {
+ LOGD("mbtk_route_config : open fail.");
+ return -1;
+ }
+
+ ret = write(fd, buf, offset);
+ if(ret < 0)
+ {
+ LOGD("mbtk_route_config : write fail.");
+ }
+
+ close(fd);
+ }
+ }
+
+ return 0;
+}
+#endif
+
+int ql_wan_start_ex(int profile_idx, int op, ex_conn_status_cb nw_cb)
+{
+ int ret = -1;
+ int count = 0;
+ if(ql_info_handle == NULL)
+ {
+ return -1;
+ }
+
+ ql_net_ex_status_cb = nw_cb;
+ ql_net_status_cb = NULL;
+ now_cid = profile_idx;
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ LOGD("ql_wan_start_ex() cid out of range.");
+#if 0
+ if(ql_net_ex_status_cb)
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type ,PDP_CID_EXIST_FAIL, 0);
+#endif
+ return -1;
+ }
+
+ //ql_netw_status_cb(ql_apn_info[profile_idx].cid);
+ if(op == 0)
+ {
+ ret = ql_wan_stop(profile_idx);
+ goto exit;
+ }
+
+#if 0
+ if(ql_apn_info[profile_idx].active)
+ {
+ if(ql_net_ex_status_cb)
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, PDP_CID_EXIST_FAIL, 0);
+ return -1;
+ }
+#endif
+
+ if(ql_net_ex_status_cb) {
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_DIAL_IMMEDIATELY, 0);
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_CONNING, 0);
+ }
+
+data_call_continue:
+ ret = mbtk_data_call_start(ql_info_handle, profile_idx, 0, op == 3 ? TRUE : FALSE, 0);
+ if(ret != 0)
+ {
+ if(mbtk_interval_sec <= 0)
+ {
+ if(ql_net_ex_status_cb)
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_DISCON, 0);
+ return ret;
+ }
+ else
+ {
+ if(count >= 5)
+ goto exit;
+ sleep(mbtk_interval_sec);
+ count++;
+ if(ql_net_ex_status_cb)
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_REDIAL, 0);
+ goto data_call_continue;
+ }
+ LOGD("mbtk_data_call_start() fail.");
+ }
+ else
+ {
+ //ql_apn_info[8].cid=profile_idx;
+ //ql_netw_status_cb(CONNECT_CONSUCCESS);
+#ifdef MBTK_AF_SUPPORT
+ if(profile_idx == 1)
+ {
+ mbtk_route_config(profile_idx);
+
+ }
+#endif
+ LOGD("mbtk_data_call_start() success.");
+ }
+exit:
+ return ret;
+}
+
+
+/*
+* Start data call.
+*/
+int ql_wan_start(int profile_idx, int op, nw_status_cb nw_cb)
+{
+ int ret = -1;
+ int count = 0;
+ if(ql_info_handle == NULL)
+ {
+ return -1;
+ }
+
+ ql_net_status_cb = nw_cb;
+ ql_net_ex_status_cb = NULL;
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ ql_net_status_cb(PDP_ERROR_UNSPECIFIED);
+ return -1;
+ }
+
+ //ql_netw_status_cb(ql_apn_info[profile_idx].cid);
+ if(op == 0)
+ {
+ ret = ql_wan_stop(profile_idx);
+ goto exit;
+ }
+
+ if(ql_apn_info[profile_idx].active)
+ {
+ ql_net_status_cb(PDP_CID_EXIST_FAIL);
+ return -1;
+ }
+
+ ql_net_status_cb(CONNECT_DIAL_IMMEDIATELY);
+ ql_net_status_cb(CONNECT_CONNING);
+data_call_continue:
+ ret = mbtk_data_call_start(ql_info_handle, profile_idx, 0, op == 3 ? TRUE : FALSE, 0);
+ if(ret != 0)
+ {
+ if(mbtk_interval_sec <= 0)
+ {
+ ql_net_status_cb(CONNECT_DISCON);
+ return ret;
+ }
+ else
+ {
+ if(count >= 5)
+ goto exit;
+ sleep(mbtk_interval_sec);
+ count++;
+ ql_net_status_cb(CONNECT_REDIAL);
+ goto data_call_continue;
+ }
+ }
+ else
+ {
+ //ql_apn_info[8].cid=profile_idx;
+ //ql_netw_status_cb(CONNECT_CONSUCCESS);
+ LOGD("mbtk_data_call_start() success.");
+ }
+exit:
+ return ret;
+}
+
+/*
+* Stop data call.
+*/
+int ql_wan_stop(int profile_idx)
+{
+ int err;
+ if(ql_info_handle == NULL)
+ {
+ return -1;
+ }
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ LOGE("CID error.");
+ return -1;
+ }
+
+#if 0 //mbtk wyq for data_call add "if 0"
+ if(!ql_apn_info[profile_idx].active)
+ {
+ if(ql_net_ex_status_cb)
+ ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type ,PDP_CID_EXIST_FAIL, 0);
+ if(ql_net_status_cb)
+ ql_net_status_cb(PDP_CID_EXIST_FAIL);
+ return -1;
+ }
+#endif
+ err = mbtk_data_call_stop(ql_info_handle, profile_idx, 15);
+
+ return err;
+}
+
+/*
+* Query data call state.
+*/
+int ql_get_data_call_info(int profile_idx, ql_data_call_info *info)
+{
+ if(ql_info_handle == NULL || info == NULL)
+ {
+ return -1;
+ }
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ LOGE("CID error.");
+ return -1;
+ }
+ mbtk_ipv4_info_t ipv4;
+ mbtk_ipv6_info_t ipv6;
+ memset(info, 0, sizeof(ql_data_call_info));
+ int ret = mbtk_data_call_state_get(ql_info_handle, profile_idx, &ipv4, &ipv6);
+ if(ret != 0)
+ return -1;
+ else
+ {
+ info->profile_idx = profile_idx;
+ if(ipv4.valid)
+ {
+ info->ip_type = 1; // IPV4
+ info->v4.state = 1;
+ sprintf(info->v4.addr.name, "ccinet%d", profile_idx - 1);
+ if(inet_ntop(AF_INET, &(ipv4.IPAddr), info->v4.addr.ip, 32) == NULL) {
+ LOGD("IP error.");
+ } else {
+ LOGD("IP : %s", info->v4.addr.ip);
+ }
+ if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), info->v4.addr.pri_dns, 32) == NULL) {
+ LOGD("PrimaryDNS error.");
+ } else {
+ LOGD("PrimaryDNS : %s", info->v4.addr.pri_dns);
+ }
+ if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), info->v4.addr.sec_dns, 32) == NULL) {
+ LOGD("SecondaryDNS error.");
+ } else {
+ LOGD("SecondaryDNS : %s", info->v4.addr.sec_dns);
+ }
+ }
+ if(ipv6.valid)
+ {
+ info->ip_type = 2; // IPV6
+ info->v6.state = 1;
+ sprintf(info->v6.addr.name, "ccinet%d", profile_idx - 1);
+ if(ipv6_2_str(&(ipv6.IPV6Addr), info->v6.addr.ip))
+ {
+ LOGD("IP error.");
+ } else {
+ LOGD("IP : %s", info->v6.addr.ip);
+ }
+ if(ipv6_2_str(&(ipv6.PrimaryDNS), info->v6.addr.pri_dns))
+ {
+ LOGD("PrimaryDNS error.");
+ } else {
+ LOGD("PrimaryDNS : %s", info->v6.addr.pri_dns);
+ }
+ if(ipv6_2_str(&(ipv6.SecondaryDNS), info->v6.addr.sec_dns))
+ {
+ LOGD("SecondaryDNS error.");
+ } else {
+ LOGD("SecondaryDNS : %s", info->v6.addr.sec_dns);
+ }
+ }
+ if(ipv4.valid && ipv6.valid)
+ info->ip_type = 0; // IPV4V6
+ if(!ipv4.valid && !ipv6.valid)
+ {
+ info->v4.state = 0;
+ info->v6.state = 0;
+ }
+ return 0;
+ }
+
+}
+
+/*
+* Set specific APN informations.
+*
+* cid : 2-7
+*/
+int ql_wan_setapn(int profile_idx, int ip_type, const char *apn, const char *userName,
+ const char *password, QL_DSI_AUTH_PREF_T auth)
+{
+ if(ql_info_handle == NULL)
+ {
+ return -1;
+ }
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ LOGE("CID error.");
+ return -1;
+ }
+ /*
+ QL_DSI_AUTH_PREF_NULL = 0, //无认证
+ QL_DSI_AUTH_PREF_ONLY_PAP, //PAP 认证
+ QL_DSI_AUTH_PREF_ONLY_CHAP, //CHAP 认证
+ QL_DSI_AUTH_PREF_BOTH_PAP_CHAP //PAP 和 CHAP 认证
+ */
+ char mbtk_auth[64]={0};
+ if(auth == QL_DSI_AUTH_PREF_NULL)
+ memcpy(mbtk_auth,"NONE",strlen("NONE")+1);
+ else if(auth == QL_DSI_AUTH_PREF_ONLY_PAP)
+ memcpy(mbtk_auth,"PAP",strlen("PAP")+1);
+ else if(auth == QL_DSI_AUTH_PREF_ONLY_CHAP)
+ memcpy(mbtk_auth,"CHAP",strlen("CHAP")+1);
+ else
+ {
+ LOGD("auth input error!");
+ return -1;
+ }
+
+ memset(&(ql_apn_info[profile_idx]), 0, sizeof(apn_info));
+ ql_apn_info[profile_idx].cid = profile_idx;
+ ql_apn_info[profile_idx].ip_type = ip_type;
+ if(!str_empty(userName) && !str_empty(password)) {
+ memcpy(ql_apn_info[profile_idx].user, userName, strlen(userName));
+ memcpy(ql_apn_info[profile_idx].pass, password, strlen(password));
+ ql_apn_info[profile_idx].auth = auth;
+ LOGD("ql_wan_setapn: %d, %d, %s, %s, %s, %s",profile_idx, ip_type, apn, userName, password, mbtk_auth);
+ } else {
+ LOGD("ql_wan_setapn: %d, %d, %s, NULL, NULL, %s",profile_idx, ip_type, apn, mbtk_auth);
+ }
+
+ /*
+ if(ip_type < 0 || ip_type > 3)
+ ql_netw_status_cb(PDP_UNKNOWN_PDP_ADDRESS_TYPE);
+ */
+ if(ip_type == 0) // IPV4V6
+ ip_type = MBTK_IP_TYPE_IPV4V6;
+ else if(ip_type == 1) // IPV4
+ ip_type = MBTK_IP_TYPE_IP;
+ else if(ip_type == 2) // IPV6
+ ip_type = MBTK_IP_TYPE_IPV6;
+
+ return mbtk_apn_set(ql_info_handle, profile_idx, ip_type, apn, userName, password, mbtk_auth);
+}
+
+/*
+* Get current all APN informations.
+*/
+int __ql_wan_getapn(int profile_idx, int *ip_type, char *apn, int apnLen, char *userName, int userLen, char *password, int pwdLen,int* auth)
+{
+ if(ql_info_handle == NULL || apn == NULL)
+ {
+ return -1;
+ }
+ if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX)
+ {
+ LOGE("CID error.");
+ return -1;
+ }
+ mbtk_apn_info_t apns[10];
+ int apn_num = MBTK_APN_CID_MAX;
+ int ret = mbtk_apn_get(ql_info_handle, &apn_num, apns);
+ if(ret != 0)
+ {
+ LOGD("mbtk_apn_get ret = %d",ret);
+ return -1;
+ }
+ else
+ {
+ int i;
+ for(i=0;i<MBTK_APN_CID_MAX;i++)
+ {
+ if(apns[i].cid == profile_idx)
+ break;
+ }
+ if(i == MBTK_APN_CID_MAX)
+ return -1;
+ LOGD("cid = %d",i);
+ if(apns[i].ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6
+ *ip_type = 0;
+ else if(apns[i].ip_type == MBTK_IP_TYPE_IP) // IPV4
+ *ip_type = 1;
+ else if(apns[i].ip_type == MBTK_IP_TYPE_IPV6) // IPV6
+ *ip_type = 2;
+ else
+ *ip_type = 0;
+
+ if(strlen(apns[i].apn)+1 > apnLen)
+ return -1;
+ else
+ memcpy(apn, apns[i].apn,strlen(apns[i].apn)+1);
+
+ if(strlen(apns[i].user)+1 > userLen)
+ return -1;
+ else
+ {
+ if(strlen(apns[i].user) > 0)
+ memcpy(userName, apns[i].user, strlen(apns[i].user)+1);
+ else
+ memcpy(userName, ql_apn_info[profile_idx].user, strlen(ql_apn_info[profile_idx].user)+1);
+ }
+
+ if(strlen(apns[i].pass)+1 > pwdLen)
+ return -1;
+ else
+ {
+ if(strlen(apns[i].pass) > 0)
+ memcpy(password, apns[i].pass, strlen(apns[i].pass)+1);
+ else
+ memcpy(password, ql_apn_info[profile_idx].pass, strlen(ql_apn_info[profile_idx].pass)+1);
+ }
+
+ if(strlen(apns[i].auth) > 0) {
+ if(strcmp(apns[i].auth, "NONE") == 0)
+ *auth = QL_DSI_AUTH_PREF_NULL;
+ else if(strcmp(apns[i].auth, "PAP") == 0)
+ *auth = QL_DSI_AUTH_PREF_ONLY_PAP;
+ else if(strcmp(apns[i].auth, "CHAP") == 0)
+ *auth = QL_DSI_AUTH_PREF_ONLY_CHAP;
+ else
+ {
+ LOGD("auth error!");
+ return -1;
+ }
+ } else {
+ *auth = ql_apn_info[profile_idx].auth;
+ }
+
+ return 0;
+ }
+}
+
+
diff --git a/mbtk/libql_lib_v2/src/ql_dev_api.c b/mbtk/libql_lib_v2/src/ql_dev_api.c
new file mode 100755
index 0000000..d473ab8
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_dev_api.c
@@ -0,0 +1,179 @@
+//**********************
+#include "ql/ql_dev.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+
+//**********************
+
+mbtk_info_handle_t* ql_info_handle = NULL;
+int ql_info_handle_num = 0;
+static bool inited = FALSE;
+
+//**********************
+QL_DEV_ERROR_CODE ql_dev_init()
+{
+ if(!inited && ql_info_handle == NULL)
+ {
+ ql_info_handle = mbtk_info_handle_get();
+ if(ql_info_handle)
+ {
+ ql_info_handle_num++;
+ inited = TRUE;
+ return QL_DEV_SUCCESS;
+ } else {
+ LOGE("mbtk_info_handle_get() fail.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+ } else {
+ if(!inited) {
+ ql_info_handle_num++;
+ inited = TRUE;
+ }
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_release()
+{
+ if(ql_info_handle)
+ {
+ LOGD("ql_info_handle_num = %d", ql_info_handle_num);
+ if(ql_info_handle_num == 1) { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&ql_info_handle);
+ if(ret) {
+ LOGE("mbtk_info_handle_free() fail.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+ else
+ {
+ ql_info_handle_num = 0;
+ ql_info_handle = NULL;
+ return QL_DEV_SUCCESS;
+ }
+ } else {
+ ql_info_handle_num--;
+ return QL_DEV_SUCCESS;
+ }
+ }
+ else
+ {
+ LOGE("DEV handle not inited.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_get_imei(char* imei)
+{
+ if(ql_info_handle == NULL || imei == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+
+ if(mbtk_imei_get(ql_info_handle, imei)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_get_firmware_version(char* version)
+{
+ if(ql_info_handle == NULL || version == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+
+ if(mbtk_version_get(ql_info_handle, version)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_get_model(char* model)
+{
+ if(ql_info_handle == NULL || model == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+
+ if(mbtk_model_get(ql_info_handle, model)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_get_sn(char* sn)
+{
+ if(ql_info_handle == NULL || sn == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+
+ if(mbtk_sn_get(ql_info_handle, sn)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_set_modem_fun(QL_DEV_MODEM_FUNCTION function, int rst)
+{
+ if(ql_info_handle == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+ mbtk_modem_info_t modem;
+ modem.rst = rst;
+ switch (function)
+ {
+ case QL_DEV_MODEM_MIN_FUN:
+ modem.fun = MBTK_DEV_MODEM_MIN_FUN;
+ break;
+ case QL_DEV_MODEM_FULL_FUN:
+ modem.fun = MBTK_DEV_MODEM_FULL_FUN;
+ break;
+ case QL_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS:
+ modem.fun = MBTK_DEV_MODEM_DISABLE_RECEIVE_RF_CIRCUITS;
+ break;
+ case QL_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS:
+ modem.fun = MBTK_DEV_MODEM_DISABLE_TRANSMIT_AND_RECEIVE_RF_CIRCUITS;
+ break;
+ case QL_DEV_MODEM_DISABLE_SIM:
+ modem.fun = MBTK_DEV_MODEM_DISABLE_SIM;
+ break;
+ case QL_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE:
+ modem.fun = MBTK_DEV_MODEM_TURN_OFF_FULL_SECONDARY_RECEIVE;
+ break;
+ default:
+ break;
+ }
+ if(mbtk_set_modem_fun(ql_info_handle, &modem)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+QL_DEV_ERROR_CODE ql_dev_get_modem_fun(int *function)
+{
+ if(ql_info_handle == NULL || function == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_DEV_GENERIC_FAILURE;
+ }
+
+ if(mbtk_get_modem_fun(ql_info_handle, function)) {
+ return QL_DEV_GENERIC_FAILURE;
+ } else {
+ return QL_DEV_SUCCESS;
+ }
+}
+
+//**********************
diff --git a/mbtk/libql_lib_v2/src/ql_fota.c b/mbtk/libql_lib_v2/src/ql_fota.c
new file mode 100755
index 0000000..eb0afc7
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_fota.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <fcntl.h>
+#include "mbtk_fota.h"
+
+
+int ql_fota_init(fota_callback cb)
+{
+ return mbtk_fota_init(cb);
+}
+
+/*******************************************************************************
+* @brief write firmware package, the firmware package is written in segments.
+ and The result of the write is output by calling the callback function.
+ the firmware package size must less than 32MB
+ @param
+ fname: firmware package file
+ segment_size: the length of once write, recommending 3*1024*1024 bytes
+ @return
+ if success return 0, else return -1
+ *******************************************************************************/
+int ql_fota_fw_write(char* fname, int segment_size)
+{
+ return mbtk_fota_fw_write(fname, segment_size);
+}
+
+
+/*******************************************************************************
+* @brief download firmware by url, and write firmware package, the firmware
+ package is written in segments. The result of the write is output by
+ calling the callback function. the firmware package size must less than
+ 32MB
+ @param
+ url: [IN] the address of download firmware package file, the url
+ support http or https protocol.
+ segment_size: [IN] the length of once write, recommending 3*1024*1024 bytes
+ conn_timeout: [IN] timeout to connect to the server, if set 0 that means
+ switch to the default build-in connection timeout(300s)
+ download_timeout: [IN] timeout for download the firmware file. if set 0 that means
+ it never time out
+ @return
+ if success return 0, else return -1
+ *******************************************************************************/
+int ql_fota_fw_write_by_url(char* url, int segment_size,
+ int conn_timeout, int download_timeout)
+{
+ return mbtk_fota_fw_write_by_url(url, segment_size,conn_timeout, download_timeout);
+}
+/*******************************************************************************
+* @brief reboot system and clear env
+ @param
+ is_reboot: if set 1, after fota success, reboot system
+ @return
+ if success return 0, else return -1
+ *******************************************************************************/
+int ql_fota_done(int is_reboot)
+{
+ return mbtk_fota_done1(is_reboot);
+}
diff --git a/mbtk/libql_lib_v2/src/ql_gpio.c b/mbtk/libql_lib_v2/src/ql_gpio.c
new file mode 100755
index 0000000..9be2026
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_gpio.c
@@ -0,0 +1,741 @@
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
+#include "ql/ql_gpio.h"
+
+typedef struct {
+ int pin;
+ int gpio;
+} pin_gpio_mmap_s;
+
+#ifdef MBTK_PROJECT_L508
+static pin_gpio_mmap_s pin_gpio_mmap[] = {
+ {PINNAME_GPIO1, -1}, /*PIN-1*/
+ {PINNAME_GPIO2, -1}, /*PIN-2*/
+ {PINNAME_GPIO3, -1}, /*PIN-3*/
+ {PINNAME_GPIO4, -1}, /*PIN-4*/
+ {PINNAME_GPIO5, -1}, /*PIN-5*/
+ {PINNAME_NET_STATUS, -1}, /*PIN-6*/
+ {PINNAME_DBG_RXD, -1}, /*PIN-11*/
+ {PINNAME_DBG_TXD, -1}, /*PIN-12*/
+ {PINNAME_USIM_PRESENCE, 19}, /*PIN-13*/
+ {PINNAME_SD_INT_DET, -1}, /*PIN-23*/
+ {PINNAME_PCM_IN, 28}, /*PIN-24*/
+ {PINNAME_PCM_OUT, 27}, /*PIN-25*/
+ {PINNAME_PCM_SYNC, -1}, /*PIN-26*/
+ {PINNAME_PCM_CLK, -1}, /*PIN-27*/
+ {PINNAME_SDC2_DATA3, 21}, /*PIN-28*/
+ {PINNAME_SDC2_DATA2, -1}, /*PIN-29*/
+ {PINNAME_SDC2_DATA1, 4}, /*PIN-30*/
+ {PINNAME_SDC2_DATA0, -1}, /*PIN-31*/
+ {PINNAME_SDC2_CLK, -1}, /*PIN-32*/
+ {PINNAME_SDC2_CMD, -1}, /*PIN-33*/
+ {PINNAME_SPI_CS_N, -1}, /*PIN-37*/
+ {PINNAME_SPI_MOSI, -1}, /*PIN-38*/
+ {PINNAME_SPI_MISO, -1}, /*PIN-39*/
+ {PINNAME_SPI_CLK, -1}, /*PIN-40*/
+ {PINNAME_I2C_SCL, -1}, /*PIN-41*/
+ {PINNAME_I2C_SDA, -1}, /*PIN-42*/
+ {PINNAME_GPIO20, 20}, /*PIN-45*/
+ {PINNAME_STATUS, 13}, /*PIN-49*/
+ {PINNAME_NETLIGHT, 14}, /*PIN-51*/
+ {PINNAME_GPIO6, -1}, /*PIN-62*/
+ {PINNAME_DCD, -1}, /*PIN-63*/
+ {PINNAME_DTR, -1}, /*PIN-66*/
+ {PINNAME_MAIN_CTS, -1}, /*PIN-64*/
+ {PINNAME_MAIN_RTS, -1}, /*PIN-65*/
+ {PINNAME_MAIN_TXD, -1}, /*PIN-67*/
+ {PINNAME_MAIN_RXD, -1}, /*PIN-68*/
+ {PINNAME_RMII_RXD1, -1}, /*PIN-73*/
+ {PINNAME_RMII_RXCL, -1}, /*PIN-74*/
+ {PINNAME_RMII_CLK, 3}, /*PIN-75*/
+ {PINNAME_RMII_RXD0, 1}, /*PIN-76*/
+ {PINNAME_RMII_TXD0, -1}, /*PIN-77*/
+ {PINNAME_RMII_TXD1, -1}, /*PIN-78*/
+ {PINNAME_RMII_RXD2, -1}, /*PIN-79*/
+ {PINNAME_RMII_TXD2, -1}, /*PIN-80*/
+ {PINNAME_RMII_TX_CTRL, -1}, /*PIN-81*/
+ {PINNAME_RMII_RXD3, -1}, /*PIN-82*/
+ {PINNAME_RMII_TXCL, -1}, /*PIN-83*/
+ {PINNAME_RMII_TXD3, 5}, /*PIN-84*/
+ {PINNAME_WLAN_SLP_CLK, -1}, /*PIN-118*/
+ {PINNAME_RMII_RST, 20}, /*PIN-119*/
+ {PINNAME_RMII_INT, -1}, /*PIN-120*/
+ {PINNAME_RMII_MDIO, 17}, /*PIN-121*/
+ {PINNAME_RMII_MDC, 16}, /*PIN-122*/
+ {PINNAME_PRI_TDI, 117}, /*PIN-123*/
+ {PINNAME_WLAN_PER_EN, 24}, /*PIN-127*/
+ {PINNAME_WLAN_WAKE, 21}, /*PIN-135*/
+ {PINNAME_WLAN_EN, 22}, /*PIN-136*/
+ {PINNAME_GPIO8, -1}, /*PIN-139*/
+};
+#else
+static pin_gpio_mmap_s pin_gpio_mmap[] = {
+ {PINNAME_GPIO1, -1}, /*PIN-1*/
+ {PINNAME_GPIO2, -1}, /*PIN-2*/
+ {PINNAME_GPIO3, -1}, /*PIN-3*/
+ {PINNAME_GPIO4, -1}, /*PIN-4*/
+ {PINNAME_GPIO5, -1}, /*PIN-5*/
+ {PINNAME_NET_STATUS, -1}, /*PIN-6*/
+ {PINNAME_DBG_RXD, -1}, /*PIN-11*/
+ {PINNAME_DBG_TXD, -1}, /*PIN-12*/
+ {PINNAME_USIM_PRESENCE, 19}, /*PIN-13*/
+ {PINNAME_SD_INT_DET, -1}, /*PIN-23*/
+ {PINNAME_PCM_IN, 28}, /*PIN-24*/
+ {PINNAME_PCM_OUT, 27}, /*PIN-25*/
+ {PINNAME_PCM_SYNC, -1}, /*PIN-26*/
+ {PINNAME_PCM_CLK, -1}, /*PIN-27*/
+ {PINNAME_SDC2_DATA3, 21}, /*PIN-28*/
+ {PINNAME_SDC2_DATA2, -1}, /*PIN-29*/
+ {PINNAME_SDC2_DATA1, 4}, /*PIN-30*/
+ {PINNAME_SDC2_DATA0, -1}, /*PIN-31*/
+ {PINNAME_SDC2_CLK, -1}, /*PIN-32*/
+ {PINNAME_SDC2_CMD, -1}, /*PIN-33*/
+ {PINNAME_SPI_CS_N, -1}, /*PIN-37*/
+ {PINNAME_SPI_MOSI, -1}, /*PIN-38*/
+ {PINNAME_SPI_MISO, -1}, /*PIN-39*/
+ {PINNAME_SPI_CLK, -1}, /*PIN-40*/
+ {PINNAME_I2C_SCL, -1}, /*PIN-41*/
+ {PINNAME_I2C_SDA, -1}, /*PIN-42*/
+ {PINNAME_GPIO20, 20}, /*PIN-45*/
+ {PINNAME_STATUS, 13}, /*PIN-49*/
+ {PINNAME_NETLIGHT, 14}, /*PIN-51*/
+ {PINNAME_GPIO6, -1}, /*PIN-62*/
+ {PINNAME_DCD, -1}, /*PIN-63*/
+ {PINNAME_DTR, -1}, /*PIN-66*/
+ {PINNAME_MAIN_CTS, -1}, /*PIN-64*/
+ {PINNAME_MAIN_RTS, -1}, /*PIN-65*/
+ {PINNAME_MAIN_TXD, -1}, /*PIN-67*/
+ {PINNAME_MAIN_RXD, -1}, /*PIN-68*/
+ {PINNAME_RMII_RXD1, -1}, /*PIN-73*/
+ {PINNAME_RMII_RXCL, -1}, /*PIN-74*/
+ {PINNAME_RMII_CLK, 3}, /*PIN-75*/
+ {PINNAME_RMII_RXD0, 1}, /*PIN-76*/
+ {PINNAME_RMII_TXD0, -1}, /*PIN-77*/
+ {PINNAME_RMII_TXD1, -1}, /*PIN-78*/
+ {PINNAME_RMII_RXD2, -1}, /*PIN-79*/
+ {PINNAME_RMII_TXD2, -1}, /*PIN-80*/
+ {PINNAME_RMII_TX_CTRL, -1}, /*PIN-81*/
+ {PINNAME_RMII_RXD3, -1}, /*PIN-82*/
+ {PINNAME_RMII_TXCL, -1}, /*PIN-83*/
+ {PINNAME_RMII_TXD3, 5}, /*PIN-84*/
+ {PINNAME_WLAN_SLP_CLK, -1}, /*PIN-118*/
+ {PINNAME_RMII_RST, 20}, /*PIN-119*/
+ {PINNAME_RMII_INT, -1}, /*PIN-120*/
+ {PINNAME_RMII_MDIO, 17}, /*PIN-121*/
+ {PINNAME_RMII_MDC, 16}, /*PIN-122*/
+ {PINNAME_PRI_TDI, 117}, /*PIN-123*/
+ {PINNAME_WLAN_PER_EN, 24}, /*PIN-127*/
+ {PINNAME_WLAN_WAKE, 21}, /*PIN-135*/
+ {PINNAME_WLAN_EN, 22}, /*PIN-136*/
+ {PINNAME_GPIO8, -1}, /*PIN-139*/
+};
+
+#endif
+
+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.", gpio);
+ 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;
+}
+
+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;
+}
+
+
+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];
+ char path[10];
+ int file =-1;
+ int result =-1;
+ int value;
+
+ memset(path,0,50);
+ memset(buffer,0,10);
+ sprintf(path,"/sys/class/gpio/gpio%d/value", gpio);
+ file = open(path,O_RDONLY);
+ if(file == -1)
+ {
+ LOGE("Open gpio[%d] fail.", gpio);
+ return -1;
+ }
+ result = read(file,buffer,5);
+ if(result <= 0)
+ {
+ LOGE("Get gpio[%d] value fail", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+ value = atoi(buffer);
+ return value;
+}
+
+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.", gpio);
+ close(file);
+ return -1;
+ }
+ close(file);
+
+ return 0;
+}
+
+static int pin_2_gpio(Enum_PinName pin_name)
+{
+#if 0
+ switch(pin_name){
+ case PINNAME_USIM_PRESENCE: /*PIN-13*/
+ return 19;
+ case PINNAME_PCM_IN: /*PIN-24*/
+ return 28;
+ case PINNAME_PCM_OUT: /*PIN-25*/
+ return 27;
+ case PINNAME_RMII_CLK: /*PIN-75*/
+ return 3;
+ case PINNAME_RMII_RXD0: /*PIN-76*/
+ return 1;
+ case PINNAME_RMII_RST: /*PIN-119*/
+ return 20;
+ case PINNAME_RMII_MDIO: /*PIN-121*/
+ return 17;
+ case PINNAME_RMII_MDC: /*PIN-122*/
+ return 16;
+ case PINNAME_WLAN_PER_EN: /*PIN-127*/
+ return 24;
+ case PINNAME_WLAN_WAKE: /*PIN-135*/
+ return 21;
+ case PINNAME_WLAN_EN: /*PIN-136*/
+ return 22;
+
+ // Unknown PIN.
+ case PINNAME_GPIO1: /*PIN-1*/
+ case PINNAME_GPIO2: /*PIN-2*/
+ case PINNAME_GPIO3: /*PIN-3*/
+ case PINNAME_GPIO4: /*PIN-4*/
+ case PINNAME_GPIO5: /*PIN-5*/
+ case PINNAME_NET_STATUS: /*PIN-6*/
+ case PINNAME_DBG_RXD: /*PIN-11*/
+ case PINNAME_DBG_TXD: /*PIN-12*/
+ case PINNAME_SD_INT_DET: /*PIN-23*/
+ case PINNAME_PCM_SYNC: /*PIN-26*/
+ case PINNAME_PCM_CLK: /*PIN-27*/
+ case PINNAME_SDC2_DATA3: /*PIN-28*/
+ case PINNAME_SDC2_DATA2: /*PIN-29*/
+ case PINNAME_SDC2_DATA1: /*PIN-30*/
+ case PINNAME_SDC2_DATA0: /*PIN-31*/
+ case PINNAME_SDC2_CLK: /*PIN-32*/
+ case PINNAME_SDC2_CMD: /*PIN-33*/
+ case PINNAME_SPI_CS_N: /*PIN-37*/
+ case PINNAME_SPI_MOSI: /*PIN-38*/
+ case PINNAME_SPI_MISO: /*PIN-39*/
+ case PINNAME_SPI_CLK: /*PIN-40*/
+ case PINNAME_I2C_SCL: /*PIN-41*/
+ case PINNAME_I2C_SDA: /*PIN-42*/
+ case PINNAME_GPIO6: /*PIN-62*/
+ case PINNAME_DCD: /*PIN-63*/
+ case PINNAME_DTR: /*PIN-66*/
+ case PINNAME_MAIN_CTS: /*PIN-64*/
+ case PINNAME_MAIN_RTS: /*PIN-65*/
+ case PINNAME_MAIN_TXD: /*PIN-67*/
+ case PINNAME_MAIN_RXD: /*PIN-68*/
+ case PINNAME_RMII_RXD1: /*PIN-73*/
+ case PINNAME_RMII_RXCL: /*PIN-74*/
+ case PINNAME_RMII_TXD0: /*PIN-77*/
+ case PINNAME_RMII_TXD1: /*PIN-78*/
+ case PINNAME_RMII_RXD2: /*PIN-79*/
+ case PINNAME_RMII_TXD2: /*PIN-80*/
+ case PINNAME_RMII_TX_CTRL: /*PIN-81*/
+ case PINNAME_RMII_RXD3: /*PIN-82*/
+ case PINNAME_RMII_TXCL: /*PIN-83*/
+ case PINNAME_RMII_TXD3: /*PIN-84*/
+ case PINNAME_WLAN_SLP_CLK: /*PIN-118*/
+ case PINNAME_RMII_INT: /*PIN-120*/
+ case PINNAME_GPIO8: /*PIN-139*/
+ default:
+ LOGE("Unknown PIN : %d", pin_name);
+ return -1;
+ }
+#else
+ int i = 0;
+ while(i < ARRAY_SIZE(pin_gpio_mmap)) {
+ if(pin_name == pin_gpio_mmap[i].pin) {
+ return pin_gpio_mmap[i].gpio;
+ }
+ i++;
+ }
+
+ LOGE("No found PIN : %d", pin_name);
+ return -1;
+#endif
+}
+
+
+/*****************************************************************
+* Function: Ql_GPIO_Init
+*
+* Description:
+* This function enables the GPIO function of the specified pin,
+* and initialize the configurations, including direction,
+* level and pull selection.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* dir:
+* The initial direction of GPIO, one value of Enum_PinDirection.
+* level:
+* The initial level of GPIO, one value of Enum_PinLevel.
+* pull_sel:
+* Pull selection, one value of Enum_PinPullSel.
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_Init(Enum_PinName pin_name,
+ Enum_PinDirection dir,
+ Enum_PinLevel level,
+ Enum_PinPullSel pull_sel
+ )
+{
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ if(gpio_export(gpio))
+ {
+ LOGE("gpio_export() fail.");
+ return RES_IO_ERROR;
+ }
+
+ if(gpio_direct_set(gpio, dir == PINDIRECTION_IN ? "in" : "out"))
+ {
+ LOGE("gpio_direct_set() fail.");
+ return RES_IO_ERROR;
+ }
+
+ if(dir == PINDIRECTION_OUT){
+ if(gpio_value_set(gpio, level))
+ {
+ LOGE("gpio_value_set() fail.");
+ return RES_IO_ERROR;
+ }
+ }
+ // No support pull mode now.
+
+ return RES_OK;
+}
+
+/*****************************************************************
+* Function: Ql_GPIO_Base_Init
+*
+* Description:
+* This function enables the GPIO function of the specified pin.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+*
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+*****************************************************************/
+int Ql_GPIO_Base_Init(Enum_PinName pin_name );
+
+/*****************************************************************
+* Function: Ql_GPIO_SetLevel
+*
+* Description:
+* This function sets the level of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* level:
+* The initial level of GPIO, one value of Enum_PinLevel.
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_SetLevel(Enum_PinName pin_name, Enum_PinLevel level)
+{
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ if(gpio_value_set(gpio, level)) {
+ LOGE("gpio_value_set() fail.");
+ return RES_IO_ERROR;
+ } else {
+ return RES_OK;
+ }
+}
+
+/*****************************************************************
+* Function: Ql_GPIO_GetLevel
+*
+* Description:
+* This function gets the level of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* Return:
+* The level value of the specified GPIO, which is
+* nonnegative integer.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+*****************************************************************/
+int Ql_GPIO_GetLevel(Enum_PinName pin_name)
+{
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ return gpio_value_get(gpio);
+}
+
+/*****************************************************************
+* Function: Ql_GPIO_SetDirection
+*
+* Description:
+* This function sets the direction of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* dir:
+* The initial direction of GPIO, one value of Enum_PinDirection.
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_SetDirection(Enum_PinName pin_name, Enum_PinDirection dir)
+{
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ if(gpio_direct_set(gpio, dir == PINDIRECTION_IN ? "in" : "out")) {
+ LOGE("gpio_direct_set() fail.");
+ return RES_IO_ERROR;
+ } else {
+ return RES_OK;
+ }
+}
+
+/*****************************************************************
+* Function: Ql_GPIO_GetDirection
+*
+* Description:
+* This function gets the direction of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* Return:
+* 0 INPUT
+* 1 OUTPUT
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_GetDirection(Enum_PinName pin_name)
+{
+ char buff[10];
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ if(gpio_direct_get(gpio, buff, 10)) {
+ LOGE("gpio_direct_get() fail.");
+ return RES_IO_NOT_SUPPORT;
+ } else {
+ if(strncmp(buff, "in",2) == 0) {
+ return PINDIRECTION_IN;
+ } else if(strncmp(buff, "out",3) == 0) {
+ return PINDIRECTION_OUT;
+ } else {
+ return RES_IO_NOT_SUPPORT;
+ }
+ }
+}
+
+/*****************************************************************
+* Function: Ql_GPIO_SetPullSelection
+*
+* Description:
+* This function sets the pull selection of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* Enum_PinPullSel:
+* Pull selection, one value of Enum_PinPullSel.
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_SetPullSelection(Enum_PinName pin_name, Enum_PinPullSel pull_sel);
+
+/*****************************************************************
+* Function: ql_gpio_get_pull_selection
+*
+* Description:
+* This function gets the pull selection of the specified GPIO.
+*
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* Return:
+* 0<<13 no pull
+* 5<<13 pull down
+* 6<<13 pull up
+*****************************************************************/
+int Ql_GPIO_GetPullSelection(Enum_PinName pin_name);
+
+
+/*****************************************************************
+* Function: Ql_GPIO_Uninit
+*
+* Description:
+* This function releases the specified GPIO that was
+* initialized by calling Ql_GPIO_Init() previously.
+* After releasing, the GPIO can be used for other purpose.
+* Parameters:
+* pin_name:
+* Pin name, one value of Enum_PinName.
+* Return:
+* RES_OK, this function succeeds.
+* RES_IO_NOT_SUPPORT, the input GPIO is invalid.
+* RES_IO_ERR, the function failed
+* other place. For example this GPIO has been using as EINT.
+*****************************************************************/
+int Ql_GPIO_Uninit(Enum_PinName pin_name)
+{
+ int gpio = pin_2_gpio(pin_name);
+ if(gpio == -1) {
+ return RES_IO_ERROR;
+ }
+ LOGD("PIN-%d => GPIO-%d", pin_name, gpio);
+
+ if(gpio_unexport(gpio))
+ {
+ LOGE("gpio_unexport() fail.");
+ return RES_IO_ERROR;
+ }
+
+ return RES_OK;
+}
+
+//------------------------------------------------------------------------------
+/*
+* Function: Ql_EINT_Enable
+*
+* Description:
+* Set the interrupt sense mode, and enable interrupt.
+*
+* Parameters:
+* eint_pin_name:
+* EINT pin name, one value of Enum_PinName that has
+* the interrupt function.
+*
+* eint_type:
+* Interrupt type, level-triggered or edge-triggered.
+* Now, only edge-triggered interrupt is supported.
+*
+* eint_callback:
+* call back function
+*
+* Return:
+* RES_OK, this function succeeds.
+* else failed to execute the function.
+*/
+//------------------------------------------------------------------------------
+int Ql_EINT_Enable(Enum_PinName eint_pin_name, Enum_EintType eint_type, Ql_EINT_Callback eint_callback);
+
+
+//------------------------------------------------------------------------------
+/*
+* Function: Ql_EINT_Disable
+*
+* Description:
+* Disable the interrupt sense.
+*
+* Parameters:
+* eint_pin_name:
+* EINT pin name, one value of Enum_PinName that has
+* the interrupt function.
+*
+* Return:
+* RES_OK, this function succeeds.
+* else failed to execute the function.
+*/
+//------------------------------------------------------------------------------
+int Ql_EINT_Disable(Enum_PinName eint_pin_name);
+
diff --git a/mbtk/libql_lib_v2/src/ql_i2c.c b/mbtk/libql_lib_v2/src/ql_i2c.c
new file mode 100755
index 0000000..8b8c6a0
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_i2c.c
@@ -0,0 +1,222 @@
+#include <stdio.h>
+#include <linux/types.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <assert.h>
+#include <string.h>
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
+
+#include "mbtk_log.h"
+#include "ql/ql_i2c.h"
+
+int Ql_I2C_Init(char *dev_name)
+{
+ int fd = open(dev_name, O_RDWR);
+ if(fd <= 0) {
+ LOGE("open (%s) fail:errno - %d", dev_name, errno);
+ return -1;
+ }
+ return fd;
+}
+
+
+int Ql_I2C_Read(int fd, unsigned short slaveAddr, unsigned char ofstAddr, unsigned char* ptrBuff, unsigned short length)
+{
+ uint8_t outbuf[1];
+ struct i2c_rdwr_ioctl_data packets;
+ struct i2c_msg messages[2];
+
+ outbuf[0] = ofstAddr;
+ messages[0].addr = slaveAddr;
+ messages[0].flags = 0;
+ messages[0].len = sizeof(outbuf);
+ messages[0].buf = outbuf;
+
+ /* The data will get returned in this structure */
+ messages[1].addr = slaveAddr;
+ messages[1].flags = I2C_M_RD/* | I2C_M_NOSTART*/;
+ messages[1].len = length;
+ messages[1].buf = ptrBuff;
+
+ /* Send the request to the kernel and get the result back */
+ packets.msgs = messages;
+ packets.nmsgs = 2;
+ if(ioctl(fd, I2C_RDWR, &packets) < 0)
+ {
+ LOGE("Error: Unable to send data");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int Ql_I2C_Write(int fd, unsigned short slaveAddr, unsigned char ofstAddr, unsigned char* ptrData, unsigned short length)
+{
+ uint8_t *outbuf = NULL;
+ struct i2c_rdwr_ioctl_data packets;
+ struct i2c_msg messages[1];
+
+ outbuf = malloc(length + 1);
+ if (!outbuf) {
+ printf("Error: No memory for buffer\n");
+ return -1;
+ }
+
+ outbuf[0] = ofstAddr;
+ memcpy(outbuf + 1, ptrData, length);
+
+ messages[0].addr = slaveAddr;
+ messages[0].flags = 0;
+ messages[0].len = length + 1;
+ messages[0].buf = outbuf;
+
+ /* Transfer the i2c packets to the kernel and verify it worked */
+ packets.msgs = messages;
+ packets.nmsgs = 1;
+ if(ioctl(fd, I2C_RDWR, &packets) < 0)
+ {
+ printf("Error: Unable to send data");
+ free(outbuf);
+ return -1;
+ }
+
+ free(outbuf);
+
+ return 0;
+}
+
+
+int Ql_I2C_Deinit(int fd)
+{
+ if (fd <= 0)
+ return -1;
+
+ close(fd);
+ return 0;
+}
+
+#if 0
+int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
+{
+ int file, len;
+
+ len = snprintf(filename, size, "/dev/i2c/%d", i2cbus);
+ if (len >= (int)size) {
+ fprintf(stderr, "%s: path truncated\n", filename);
+ return -EOVERFLOW;
+ }
+ file = open(filename, O_RDWR);
+
+ if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) {
+ len = snprintf(filename, size, "/dev/i2c-%d", i2cbus);
+ if (len >= (int)size) {
+ fprintf(stderr, "%s: path truncated\n", filename);
+ return -EOVERFLOW;
+ }
+ file = open(filename, O_RDWR);
+ }
+ ...
+ return file;
+}
+
+static int i2c_read_bytes(int fd, uint8_t slave_addr, uint8_t reg_addr, uint8_t *values, uint8_t len)
+{
+ uint8_t outbuf[1];
+ struct i2c_rdwr_ioctl_data packets;
+ struct i2c_msg messages[2];
+
+ outbuf[0] = reg_addr;
+ messages[0].addr = slave_addr;
+ messages[0].flags = 0;
+ messages[0].len = sizeof(outbuf);
+ messages[0].buf = outbuf;
+
+ /* The data will get returned in this structure */
+ messages[1].addr = slave_addr;
+ messages[1].flags = I2C_M_RD/* | I2C_M_NOSTART*/;
+ messages[1].len = len;
+ messages[1].buf = values;
+
+ /* Send the request to the kernel and get the result back */
+ packets.msgs = messages;
+ packets.nmsgs = 2;
+ if(ioctl(fd, I2C_RDWR, &packets) < 0)
+ {
+ printf("Error: Unable to send data");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int i2c_write_bytes(int fd, uint8_t slave_addr, uint8_t reg_addr, uint8_t *values, uint8_t len)
+{
+ uint8_t *outbuf = NULL;
+ struct i2c_rdwr_ioctl_data packets;
+ struct i2c_msg messages[1];
+
+ outbuf = malloc(len + 1);
+ if (!outbuf) {
+ printf("Error: No memory for buffer\n");
+ return -1;
+ }
+
+ outbuf[0] = reg_addr;
+ memcpy(outbuf + 1, values, len);
+
+ messages[0].addr = slave_addr;
+ messages[0].flags = 0;
+ messages[0].len = len + 1;
+ messages[0].buf = outbuf;
+
+ /* Transfer the i2c packets to the kernel and verify it worked */
+ packets.msgs = messages;
+ packets.nmsgs = 1;
+ if(ioctl(fd, I2C_RDWR, &packets) < 0)
+ {
+ printf("Error: Unable to send data");
+ free(outbuf);
+ return -1;
+ }
+
+ free(outbuf);
+
+ return 0;
+}
+
+
+int set_slave_addr(int file, int address, int force)
+{
+ /* With force, let the user read from/write to the registers
+ even when a driver is also running */
+ if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
+ fprintf(stderr,
+ "Error: Could not set address to 0x%02x: %s\n",
+ address, strerror(errno));
+ return -errno;
+ }
+
+ return 0;
+}
+
+
+int main(void)
+{
+ int fd = -1;
+ char send_data[64] = {0};
+ send_data[0] = 0x55;
+ send_data[1] = 0x00;
+ send_data[2] = 0x84;
+ fd= open_i2c_dev(0, "i2c_test", 5, 0);
+ i2c_write_bytes(fd, 0x12, 0x10,send_data, 3)
+}
+#endif
diff --git a/mbtk/libql_lib_v2/src/ql_quec_nw.c b/mbtk/libql_lib_v2/src/ql_quec_nw.c
new file mode 100755
index 0000000..51598e9
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_quec_nw.c
@@ -0,0 +1,945 @@
+#include "ql/ql_nw.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+
+extern mbtk_info_handle_t* ql_info_handle;
+extern int ql_info_handle_num;
+static bool inited = FALSE;
+
+#define SIGNAL_STRENGTH_INVALID_1 99
+#define SIGNAL_STRENGTH_INVALID_2 255
+
+
+typedef struct
+{
+ uint8 *operator_l;
+ uint8 *operator_s;
+ uint32 mcc_mnc;
+} operator_mcc_mnc_t;
+
+typedef struct
+{
+ QL_NW_EventHandlerFunc_t handlerPtr;
+ void* contextPtr;
+} ql_cust_cb_func;
+
+static ql_cust_cb_func ql_func_cb_handle;
+
+static int roaming_pref = 1; // Open roaming for default.
+
+static operator_mcc_mnc_t operator_mcc_mnc [] =
+{
+ {"China Mobile","CMCC",46000},
+ {"China Unicom","CU",46001},
+ {"China Mobile","CMCC",46002},
+ {"China Telecom","CT",46003},
+ {"China Mobile","CMCC",46004},
+ {"China Telecom","CT",46005},
+ {"China Unicom","CU",46006},
+ {"China Mobile","CMCC",46007},
+ {"China Mobile","CMCC",46008},
+ {"China Unicom","CU",46009},
+ {"China Telecom","CT",46011}
+};
+
+typedef enum {
+ RADIO_TECH_3GPP = 1, /* 3GPP Technologies - GSM, WCDMA */
+ RADIO_TECH_3GPP2 = 2 /* 3GPP2 Technologies - CDMA */
+} RIL_RadioTechnologyFamily;
+
+void ql_nw_state_change_cb(const void* data, int data_len)
+{
+ ///mbtk_net_info_t *reg = (mbtk_net_info_t *)data;
+ uint8 *net_data = NULL;
+
+ net_data = (uint8*)data;
+ /*
+ uint8 data[3];
+ data[0] = (uint8)MBTK_NET_CS_STATE;
+
+ net_data[0] = *(uint8 *)(data); //MBTK_NET_PS_STATE
+ net_data[1] = *(uint8 *)(data + sizeof(uint8)); //mbtk_net_reg_state_enum state Reg State
+ net_data[2] = *(uint8 *)(data + sizeof(uint8) + sizeof(uint8)); //act
+ */
+ if(roaming_pref == 0)
+ {
+ mbtk_modem_info_t info;
+ if(*net_data == 5)
+ {
+ info.fun=4;
+ //ql_netw_status_cb(5);
+ }
+ else
+ info.fun=1;
+ info.rst=0;
+ //mbtk_set_modem_fun(ql_info_handle, &info);
+ }
+
+ if(ql_func_cb_handle.handlerPtr != NULL)
+ {
+ ql_func_cb_handle.handlerPtr(QL_NW_IND_DATA_REG_EVENT_FLAG,&(net_data[2]), sizeof(&(net_data[2])), NULL);
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_init()
+{
+ if(!inited && ql_info_handle == NULL)
+ {
+ ql_info_handle = mbtk_info_handle_get();
+ if(ql_info_handle)
+ {
+ ql_info_handle_num++;
+ inited = TRUE;
+ return QL_NW_SUCCESS;
+ } else {
+ LOGE("mbtk_info_handle_get() fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ } else {
+ if(!inited) {
+ ql_info_handle_num++;
+ inited = TRUE;
+ }
+ return QL_NW_SUCCESS;
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_release()
+{
+ if(ql_info_handle)
+ {
+ LOGD("ql_info_handle_num = %d", ql_info_handle_num);
+ if(ql_info_handle_num == 1) { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&ql_info_handle);
+ if(ret) {
+ LOGE("mbtk_info_handle_free() fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ else
+ {
+ ql_info_handle_num = 0;
+ ql_info_handle = NULL;
+ return QL_NW_SUCCESS;
+ }
+ } else {
+ ql_info_handle_num--;
+ return QL_NW_SUCCESS;
+ }
+ }
+ else
+ {
+ LOGE("NW handle not inited.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+}
+
+static uint8 net_pre_change(bool mbtk_2_ql,int net_mode)
+{
+ uint8 mbtk_net_pre = 0xFF;
+
+ /*
+ QL_NW_PREF_NET_TYPE_GSM_WCDMA = 0, //4
+ QL_NW_PREF_NET_TYPE_GSM_ONLY = 1, //0
+ QL_NW_PREF_NET_TYPE_WCDMA = 2, //1
+ QL_NW_PREF_NET_TYPE_GSM_WCDMA_AUTO = 3, //2
+ QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA = 9, //12
+ QL_NW_PREF_NET_TYPE_LTE_ONLY = 11, //5
+ QL_NW_PREF_NET_TYPE_LTE_WCDMA = 12, //9
+ QL_NW_PREF_NET_TYPE_LTE_GSM_GSM_PREF = 13, //7
+ QL_NW_PREF_NET_TYPE_LTE_GSM_LTE_PREF = 14, //8
+ QL_NW_PREF_NET_TYPE_LTE_GSM = 15, //6
+ QL_NW_PREF_NET_TYPE_LTE_WCDMA_WCDMA_PREF = 16, //10
+ QL_NW_PREF_NET_TYPE_LTE_WCDMA_LTE_PREF = 17, //11
+ QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_GSM_PREF = 19, //13
+ QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_WCDMA_PREF = 20, //14
+ QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_LTE_PREF = 21, //15
+ */
+ /*
+ 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_ql) {
+ switch(net_mode)
+ {
+ case MBTK_NET_PREF_GSM_UMTS_UMTS_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_GSM_WCDMA;
+ break;
+ case MBTK_NET_PREF_GSM_ONLY:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_GSM_ONLY;
+ break;
+ case MBTK_NET_PREF_UMTS_ONLY:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_WCDMA;
+ break;
+ case MBTK_NET_PREF_GSM_UMTS_AUTO:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_GSM_WCDMA_AUTO;
+ break;
+ case MBTK_NET_PREF_GSM_UMTS_LTE_AUTO:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA;
+ break;
+ case MBTK_NET_PREF_LTE_ONLY:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_ONLY;
+ break;
+ case MBTK_NET_PREF_UMTS_LTE_AUTO:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_WCDMA;
+ break;
+ case MBTK_NET_PREF_GSM_LTE_GSM_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_GSM_PREF;
+ break;
+ case MBTK_NET_PREF_GSM_LTE_LTE_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_LTE_PREF;
+ break;
+ case MBTK_NET_PREF_GSM_LTE_AUTO:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM;
+ break;
+ case MBTK_NET_PREF_UMTS_LTE_UMTS_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_WCDMA_WCDMA_PREF;
+ break;
+ case MBTK_NET_PREF_UMTS_LTE_LTE_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_WCDMA_LTE_PREF;
+ break;
+ case MBTK_NET_PREF_GSM_UMTS_LTE_GSM_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_GSM_PREF;
+ break;
+ case MBTK_NET_PREF_GSM_UMTS_LTE_UMTS_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_WCDMA_PREF;
+ break;
+ case MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF:
+ mbtk_net_pre = QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_LTE_PREF;
+ break;
+ default:
+ mbtk_net_pre = 0xFF;
+ break;
+ }
+ } else {
+ switch(net_mode)
+ {
+ case QL_NW_PREF_NET_TYPE_GSM_WCDMA:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_GSM_ONLY:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_ONLY;
+ break;
+ case QL_NW_PREF_NET_TYPE_WCDMA:
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_ONLY;
+ break;
+ case QL_NW_PREF_NET_TYPE_GSM_WCDMA_AUTO:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_AUTO;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_AUTO;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_ONLY:
+ mbtk_net_pre = MBTK_NET_PREF_LTE_ONLY;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_WCDMA:
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_LTE_AUTO;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_GSM_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_LTE_GSM_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_LTE_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_LTE_LTE_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_LTE_AUTO;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_WCDMA_WCDMA_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_LTE_UMTS_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_WCDMA_LTE_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_UMTS_LTE_LTE_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_GSM_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_GSM_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_WCDMA_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_UMTS_PREF;
+ break;
+ case QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_LTE_PREF:
+ mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF;
+ break;
+ default:
+ mbtk_net_pre = 0xFF;
+ break;
+ }
+ }
+ return mbtk_net_pre;
+}
+
+QL_NW_ERROR_CODE ql_nw_set_config(QL_NW_CONFIG_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ if(pt_info->preferred_nw_mode < QL_NW_PREF_NET_TYPE_GSM_WCDMA || pt_info->preferred_nw_mode > QL_NW_PREF_NET_TYPE_LTE_GSM_WCDMA_LTE_PREF)
+ {
+ LOGE("Unknown preferred_nw_mode(%d) error.", pt_info->preferred_nw_mode);
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ roaming_pref = pt_info->roaming_pref;
+
+ mbtk_band_info_t band;
+ memset(&band, 0, sizeof(mbtk_band_info_t));
+ band.net_pref = net_pre_change(FALSE, pt_info->preferred_nw_mode);
+ if(band.net_pref == 0xFF)
+ {
+ LOGE("net_pre_change() fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ if(mbtk_current_band_set(ql_info_handle, &band)) {
+ return QL_NW_GENERIC_FAILURE;
+ } else {
+ return QL_NW_SUCCESS;
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_get_config(QL_NW_CONFIG_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ pt_info->roaming_pref = roaming_pref;
+ mbtk_band_info_t band;
+ if(mbtk_current_band_get(ql_info_handle, &band)) {
+ return QL_NW_GENERIC_FAILURE;
+ } else {
+ pt_info->preferred_nw_mode = (QL_NW_PREFERRED_NETWORK_TYPE)net_pre_change(TRUE, band.net_pref);
+ return QL_NW_SUCCESS;
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_get_nitz_time_info(QL_NW_NITZ_TIME_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ memset(pt_info, 0x0, sizeof(QL_NW_NITZ_TIME_INFO_T));
+ char time_str[100]={0};
+ ///printf("mbtk_net_time_get begin\n");
+ int err = mbtk_net_time_get(ql_info_handle, time_str);
+ if(err) {
+ LOGE("mbtk_net_time_get() fail.");
+ return QL_NW_GENERIC_FAILURE;
+ } else {
+ memset(pt_info->nitz_time,0,32);
+ memcpy(pt_info->nitz_time,time_str,strlen(time_str));
+ if(mbtk_get_abs_time(time_str, &(pt_info->abs_time))) {
+ LOGE("mbtk_get_abs_time() fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ pt_info->leap_sec = 0;
+
+ return QL_NW_SUCCESS;
+ }
+}
+
+//--------------------------------------------------------------------------------------
+QL_NW_ERROR_CODE ql_nw_event_register(unsigned int bitmask)
+{
+ /*
+ NW_IND_VOICE_REG_EVENT_IND_FLAG 语音拨号注册事件
+ NW_IND_DATA_REG_EVENT_IND_FLAG (1 << 1) 数据拨号注册事件
+ NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG (1 << 2) 信号强度事件
+ NW_IND_NITZ_TIME_UPDATE_EVENT_IND_FLAG (1 << 3) 网络时间更新事件
+ */
+ if(bitmask == QL_NW_IND_VOICE_REG_EVENT_FLAG)
+ {}
+ if(bitmask == QL_NW_IND_DATA_REG_EVENT_FLAG)
+ {}
+ if(bitmask == QL_NW_IND_SIGNAL_STRENGTH_EVENT_FLAG)
+ {}
+ if(bitmask == QL_NW_IND_NITZ_TIME_UPDATE_EVENT_FLAG)
+ {}
+ return QL_NW_SUCCESS;
+}
+//--------------------------------------------------------------------------------------
+
+QL_NW_ERROR_CODE ql_nw_get_operator_name(QL_NW_OPERATOR_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ char OperatorFN[128];
+ char OperatorSH[128];
+ char MccMnc[128];
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(ql_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(operator_mcc_mnc))
+ {
+ if(operator_mcc_mnc[i].mcc_mnc == net.plmn)
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(OperatorFN, "UNKNOWN");
+ strcpy(OperatorSH, "UNKNOWN");
+ sprintf(MccMnc, "%d", net.plmn);
+ }
+ else
+ {
+ strcpy(OperatorFN, operator_mcc_mnc[i].operator_l);
+ strcpy(OperatorSH, operator_mcc_mnc[i].operator_s);
+ sprintf(MccMnc, "%d", operator_mcc_mnc[i].mcc_mnc);
+ }
+ memset(pt_info->long_eons,0,128);
+ memcpy(pt_info->long_eons,operator_mcc_mnc[i].operator_l,strlen(operator_mcc_mnc[i].operator_l));
+ memset(pt_info->short_eons,0,128);
+ memcpy(pt_info->short_eons,operator_mcc_mnc[i].operator_s,strlen(operator_mcc_mnc[i].operator_s));
+ memset(pt_info->mcc,0,4);
+ memset(pt_info->mnc,0,4);
+ sprintf(pt_info->mcc, "%d", (operator_mcc_mnc[i].mcc_mnc)/100);
+ if(0 == operator_mcc_mnc[i].mcc_mnc % 100)
+ {
+ strcpy(pt_info->mnc, "00");
+ }
+ else
+ {
+ sprintf(pt_info->mnc, "%d", (operator_mcc_mnc[i].mcc_mnc)%100);
+ }
+ //pt_info->act;
+ return QL_NW_SUCCESS;
+ }
+
+ return QL_NW_GENERIC_FAILURE;
+}
+
+QL_NW_ERROR_CODE ql_nw_perform_scan(QL_NW_SCAN_RESULT_LIST_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return -1;
+ }
+ list_node_t* net_list = NULL;
+ int ret = mbtk_available_net_get(ql_info_handle, &net_list);
+ if(ret != 0)
+ {
+ LOGE("mbtk_available_net_get fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ else
+ {
+ memset(pt_info, 0x0, sizeof(QL_NW_SCAN_RESULT_LIST_INFO_T));
+ mbtk_net_info_t* net = NULL;
+ list_first(net_list);
+ int i=0;
+ while ((net = (mbtk_net_info_t*) list_next(net_list)))
+ {
+ //printf("Net : %d, %d, %d, %d\n", net->net_sel_mode, net->net_type, net->net_state, net->plmn);
+ if(net->net_state == 8)
+ pt_info->entry[i].status = QL_NW_ACCESS_TECH_E_UTRAN_CA;
+ else if(net->net_state == 0xff)
+ pt_info->entry[i].status = QL_NW_ACCESS_TECH_NONE;
+ else
+ pt_info->entry[i].status = net->net_state;
+
+ int j = 0;
+ while(j < ARRAY_SIZE(operator_mcc_mnc))
+ {
+ if(operator_mcc_mnc[j].mcc_mnc == net->plmn)
+ break;
+ j++;
+ }
+ if(j == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(pt_info->entry[i].operator_name.long_eons, "UNKNOWN");
+ strcpy(pt_info->entry[i].operator_name.short_eons, "UNKNOWN");
+ sprintf(pt_info->entry[i].operator_name.mcc, "%d", (net->plmn)/100);
+ sprintf(pt_info->entry[i].operator_name.mnc, "%d", (net->plmn)%100);
+ }
+ else
+ {
+ strcpy(pt_info->entry[i].operator_name.long_eons, operator_mcc_mnc[j].operator_l);
+ strcpy(pt_info->entry[i].operator_name.short_eons, operator_mcc_mnc[j].operator_s);
+ sprintf(pt_info->entry[i].operator_name.mcc, "%d", (net->plmn)/100);
+ sprintf(pt_info->entry[i].operator_name.mnc, "%d", (net->plmn)%100);
+ }
+ pt_info->entry[i].operator_name ;
+ pt_info->entry[i].act = net->net_type;
+ i++;
+ if(i > 40)
+ break;
+ }
+ pt_info->entry_len = i;
+ list_free(net_list);
+ return QL_NW_SUCCESS;
+ }
+}
+
+#if 0
+static int ql_query_registration_state(const char *type, int* regState,int *imsRegState,int * LAC, int *CID,int *netType,int * radioTechFam,int *netRejected)
+{
+ if(ql_info_handle == NULL || str_empty(type) || regState == NULL || imsRegState == NULL
+ || LAC == NULL || CID == NULL || netType == NULL || radioTechFam == NULL || netRejected == NULL)
+ {
+ return -1;
+ }
+ mbtk_net_reg_info_t reg;
+ int err = mbtk_net_reg_get(ql_info_handle, ®);
+ if(err) {
+ *netRejected = err;
+ return -1;
+ } else {
+ //printf("REG : %d, %d, %d, %04x, %08o\n", reg.state, reg.type, reg.ims_reg, reg.lac, reg.ci);
+ // Voice/Data/IMS
+ if(strcmp("VOICE", type) == 0) {
+ *regState = reg.call_state;
+ } else if(strcmp("DATA", type) == 0) {
+ *regState = reg.data_state;
+ } else if(strcmp("IMS", type) == 0) {
+ *imsRegState = reg.ims_state;
+ } else {
+ return -1;
+ }
+
+ if(reg.call_state != MBTK_NET_REG_STATE_NON || reg.data_state != MBTK_NET_REG_STATE_NON || reg.ims_state != MBTK_NET_REG_STATE_NON) {
+ sprintf(LAC, "%04x", reg.lac);
+ sprintf(CID, "%08o", reg.ci);
+ *netType = reg.type;
+ *radioTechFam = RADIO_TECH_3GPP;
+ }
+ return 0;
+ }
+
+}
+#endif
+
+QL_NW_ERROR_CODE ql_nw_get_reg_status(QL_NW_REG_STATUS_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ /*VOICE/DATA/IMS*/
+ mbtk_net_reg_info_t reg;
+ int err = mbtk_net_reg_get(ql_info_handle, ®);
+ if(err) {
+ LOGE("mbtk_net_reg_get fail.");
+ return QL_NW_GENERIC_FAILURE;
+ } else {
+ memset(pt_info, 0x0, sizeof(QL_NW_REG_STATUS_INFO_T));
+ pt_info->data_reg.state = (QL_NW_REG_STATE)reg.data_state;
+ pt_info->data_reg.lac = reg.lac;
+ pt_info->data_reg.cid = reg.ci;
+ pt_info->voice_reg.state = (QL_NW_REG_STATE)reg.call_state;
+ pt_info->voice_reg.lac = reg.lac;
+ pt_info->voice_reg.cid = reg.ci;
+ 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_reg.rat = QL_NW_RADIO_TECH_GPRS;
+ pt_info->voice_reg.rat = QL_NW_RADIO_TECH_GSM;
+ 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_reg.rat = QL_NW_RADIO_TECH_UMTS;
+ pt_info->voice_reg.rat = QL_NW_RADIO_TECH_UMTS;
+ break;
+ }
+ case MBTK_RADIO_TECH_E_UTRAN:
+ {
+ pt_info->data_reg.rat = QL_NW_RADIO_TECH_LTE;
+ pt_info->voice_reg.rat = QL_NW_RADIO_TECH_LTE;
+ break;
+ }
+ default:
+ {
+ pt_info->data_reg.rat = QL_NW_RADIO_TECH_UNKNOWN;
+ pt_info->voice_reg.rat = QL_NW_RADIO_TECH_UNKNOWN;
+ break;
+ }
+ }
+ }
+
+ return 0;
+
+#if 0
+ int ret = ql_query_registration_state("VOICE", &(pt_info->voice_reg.state), &imsRegState, &(pt_info->voice_reg.lac), &(pt_info->voice_reg.cid), &netType, &(pt_info->voice_reg.rejectCause), &netRejected);
+ if(ret != 0)
+ err = QL_NW_GENERIC_FAILURE;
+ else
+ err = QL_NW_SUCCESS;
+ ret = ql_query_registration_state("DATA", &(pt_info->data_reg.state), &imsRegState, &(pt_info->data_reg.lac), &(pt_info->data_reg.cid), &netType, &(pt_info->data_reg.rejectCause), &netRejected);
+ if(ret != 0)
+ err = QL_NW_GENERIC_FAILURE;
+ else
+ err = QL_NW_SUCCESS;
+
+ if(err == QL_NW_SUCCESS)
+ {
+ if(netType < 0 || netType > 8)
+ pt_info->data_reg.rat = QL_NW_ACCESS_TECH_NONE;
+ else
+ pt_info->data_reg.rat = netType;
+ }
+ return err;
+#endif
+}
+
+QL_NW_ERROR_CODE ql_nw_set_selection(QL_NW_SELECTION_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ mbtk_net_info_t net;
+ net.net_type = 0xFF;
+ char mccmnc[10];
+ if(pt_info->nw_selection_mode == 0)
+ {
+ net.net_sel_mode = 0;
+ net.plmn = 0;
+ }
+ else if(pt_info->nw_selection_mode == 1 && !str_empty(pt_info->mnc) && !str_empty(pt_info->mcc))
+ {
+ net.net_sel_mode = 1;
+ memset(mccmnc, 0, 10);
+ //memcpy(mccmnc, pt_info->mcc, 3);
+ //memcpy(mccmnc + 3, pt_info->mnc, 3);
+ sprintf(mccmnc,"%s%s",pt_info->mcc,pt_info->mnc);
+ net.plmn = (uint32)atoi(mccmnc);
+ if(pt_info->act < QL_NW_ACCESS_TECH_GSM || pt_info->act > QL_NW_ACCESS_TECH_UTRAN_HSPAP)
+ net.net_type = 0xff;
+ else
+ net.net_type = pt_info->act;
+ }
+ else
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ //printf("mccmnc = %s\n",mccmnc);
+ //printf("net.plmn = %d\n",net.plmn);
+ int ret = mbtk_net_sel_mode_set(ql_info_handle, &net);
+ if(ret == 0)
+ {
+ return QL_NW_SUCCESS;
+ }
+ else
+ {
+ printf("mbtk_net_sel_mode_set error: %d\n",ret );
+ return QL_NW_GENERIC_FAILURE;
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_get_selection(QL_NW_SELECTION_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ char OperatorFN[128];
+ char OperatorSH[128];
+ char MccMnc[128];
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(ql_info_handle, &net) && net.plmn > 0)
+ {
+ memset(pt_info, 0x0, sizeof(QL_NW_SELECTION_INFO_T));
+ // printf("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
+ int i = 0;
+ while(i < ARRAY_SIZE(operator_mcc_mnc))
+ {
+ if(operator_mcc_mnc[i].mcc_mnc == net.plmn)
+ break;
+ i++;
+ }
+ if(i == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(OperatorFN, "UNKNOWN");
+ strcpy(OperatorSH, "UNKNOWN");
+ sprintf(MccMnc, "%d", net.plmn);
+ }
+ else
+ {
+ strcpy(OperatorFN, operator_mcc_mnc[i].operator_l);
+ strcpy(OperatorSH, operator_mcc_mnc[i].operator_s);
+ sprintf(MccMnc, "%d", operator_mcc_mnc[i].mcc_mnc);
+
+ sprintf(pt_info->mcc,"%d",operator_mcc_mnc[i].mcc_mnc/100);
+ sprintf(pt_info->mnc,"%d",operator_mcc_mnc[i].mcc_mnc%100);
+
+ }
+ pt_info->nw_selection_mode = net.net_sel_mode;
+
+ pt_info->act = net.net_type;
+ return QL_NW_SUCCESS;
+ }
+
+ return QL_NW_GENERIC_FAILURE;
+
+}
+
+QL_NW_ERROR_CODE ql_nw_get_signal_strength(QL_NW_SIGNAL_STRENGTH_INFO_T *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ int ret;
+ mbtk_signal_info_t signal;
+ ret = mbtk_net_signal_get(ql_info_handle, &signal);
+ if(ret != 0) {
+ LOGE("mbtk_net_signal_get fail.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ else
+ {
+ int rssi = 0;
+ if(SIGNAL_STRENGTH_INVALID_1 == signal.rssi)
+ {
+ rssi = SIGNAL_STRENGTH_INVALID_1;
+ }
+ else
+ {
+ rssi = 2 * signal.rssi - 113;
+ }
+ if(signal.type == MBTK_RADIO_TECH_GSM) //GSM
+ {
+ pt_info->GW_SignalStrength.bitErrorRate = signal.ber;
+ pt_info->GW_SignalStrength.ecio = signal.ecno;
+ pt_info->GW_SignalStrength.rscp = signal.rscp;
+ pt_info->GW_SignalStrength.rssi = rssi;
+
+ pt_info->LTE_SignalStrength.rsrp = SIGNAL_STRENGTH_INVALID_1;
+ pt_info->LTE_SignalStrength.rsrq = SIGNAL_STRENGTH_INVALID_1;
+ pt_info->LTE_SignalStrength.rssnr = SIGNAL_STRENGTH_INVALID_2;
+ pt_info->LTE_SignalStrength.rssi = SIGNAL_STRENGTH_INVALID_1;
+ }
+ else if(signal.type == MBTK_RADIO_TECH_E_UTRAN) //LTE
+ {
+ pt_info->LTE_SignalStrength.cqi = SIGNAL_STRENGTH_INVALID_1;
+ pt_info->LTE_SignalStrength.rsrp = signal.rsrp;
+ pt_info->LTE_SignalStrength.rsrq = signal.rsrq;
+ pt_info->LTE_SignalStrength.rssnr = signal.ecno;
+ pt_info->LTE_SignalStrength.rssi = rssi;
+
+ pt_info->GW_SignalStrength.bitErrorRate = SIGNAL_STRENGTH_INVALID_1;
+ pt_info->GW_SignalStrength.ecio = SIGNAL_STRENGTH_INVALID_2;
+ pt_info->GW_SignalStrength.rscp = SIGNAL_STRENGTH_INVALID_2;
+ pt_info->GW_SignalStrength.rssi = SIGNAL_STRENGTH_INVALID_1;
+ }
+ else
+ {
+ return QL_NW_GENERIC_FAILURE;
+ }
+ LOGI("ql_GW_SignalStrength: %d , %d, %d, %d", pt_info->GW_SignalStrength.rssi,
+ pt_info->GW_SignalStrength.bitErrorRate, pt_info->GW_SignalStrength.rscp, pt_info->GW_SignalStrength.ecio);
+ LOGI("ql_LTE_SignalStrength: %d , %d, %d, %d", pt_info->LTE_SignalStrength.rssi,
+ pt_info->LTE_SignalStrength.rsrp, pt_info->LTE_SignalStrength.rsrq, pt_info->LTE_SignalStrength.rssnr, pt_info->LTE_SignalStrength.cqi);
+ return QL_NW_SUCCESS;
+ }
+}
+
+QL_NW_ERROR_CODE ql_nw_get_cell_info(QL_NW_CELL_INFO_T *pt_info)
+{
+ list_node_t* cell_list = NULL;
+ mbtk_cell_type_enum type;
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+
+ memset(pt_info, 0, sizeof(QL_NW_CELL_INFO_T));
+ int err = mbtk_cell_get(ql_info_handle, &type, &cell_list);
+ if(err || cell_list == NULL) {
+ LOGE("mbtk_cell_get fail.");
+ return QL_NW_GENERIC_FAILURE;
+ } else {
+ list_first(cell_list);
+ mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);
+ if(cell) { // Current server cell.
+ switch(type)
+ {
+ case MBTK_CELL_TYPE_GSM:
+ {
+ LOGD("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d", cell->value1, cell->value2, cell->value3, cell->value4);
+ pt_info->gsm_info[0].lac = cell->value1;
+ pt_info->gsm_info[0].cid = cell->value2;
+ pt_info->gsm_info[0].arfcn = cell->value3;
+ pt_info->gsm_info[0].bsic = cell->value4;
+ pt_info->gsm_info[0].mcc = cell->value5;
+ pt_info->gsm_info[0].mnc = cell->value6;
+ pt_info->gsm_info[0].flag = 0;
+ pt_info->gsm_info_num++;
+ pt_info->gsm_info_valid = 1;
+ }
+ break;
+ case MBTK_CELL_TYPE_UMTS:
+ {
+ LOGD("UMTS : lac=%d, ci=%d, arfcn=%d", cell->value1, cell->value2, cell->value3);
+ pt_info->umts_info[0].lac = cell->value1;
+ pt_info->umts_info[0].cid = cell->value2;
+ pt_info->umts_info[0].uarfcn = cell->value3;
+ pt_info->umts_info[0].mcc = cell->value4;
+ pt_info->umts_info[0].mnc = cell->value5;
+ pt_info->umts_info[0].psc = cell->value6;
+ pt_info->umts_info[0].flag = 0;
+ pt_info->umts_info_num++;
+ pt_info->umts_info_valid = 1;
+ }
+ break;
+ case MBTK_CELL_TYPE_LTE:
+ {
+ LOGD("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
+ pt_info->lte_info[0].tac = cell->value1;
+ pt_info->lte_info[0].pci = cell->value2;
+ pt_info->lte_info[0].earfcn = cell->value3;
+ pt_info->lte_info[0].cid = cell->value8;
+ pt_info->lte_info[0].mcc = cell->value6;
+ pt_info->lte_info[0].mnc = cell->value7;
+ pt_info->lte_info[0].flag = 0;
+ pt_info->lte_info_num++;
+ pt_info->lte_info_valid = 1;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ while ((cell = (mbtk_cell_info_t*) list_next(cell_list)))
+ {
+ switch(type)
+ {
+ case MBTK_CELL_TYPE_GSM:
+ {
+ LOGD("CELL : %d, %d, %d, %d, %d", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
+ pt_info->gsm_info[pt_info->gsm_info_num].lac = cell->value1;
+ pt_info->gsm_info[pt_info->gsm_info_num].cid = cell->value2;
+ pt_info->gsm_info[pt_info->gsm_info_num].arfcn = cell->value3;
+ pt_info->gsm_info[pt_info->gsm_info_num].bsic = cell->value4;
+ pt_info->gsm_info[pt_info->gsm_info_num].flag = 1;
+ pt_info->gsm_info_num++;
+ pt_info->gsm_info_valid = 1;
+ }
+ break;
+ case MBTK_CELL_TYPE_UMTS:
+ {
+ LOGD("CELL : lac=%d, ci=%d, arfcn=%d", cell->value1, cell->value2, cell->value3);
+ pt_info->umts_info[pt_info->umts_info_num].lac = cell->value1;
+ pt_info->umts_info[pt_info->umts_info_num].cid = cell->value2;
+ pt_info->umts_info[pt_info->umts_info_num].uarfcn = cell->value3;
+ pt_info->umts_info[pt_info->umts_info_num].flag = 1;
+ pt_info->umts_info_num++;
+ pt_info->umts_info_valid = 1;
+ }
+ break;
+ case MBTK_CELL_TYPE_LTE:
+ {
+ LOGD("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d", cell->value1, cell->value2, cell->value3, cell->value4);
+ pt_info->lte_info[pt_info->lte_info_num].cid = cell->value1;
+ pt_info->lte_info[pt_info->lte_info_num].earfcn = cell->value2;
+ pt_info->lte_info[pt_info->lte_info_num].tac = cell->value3;
+ pt_info->lte_info[pt_info->lte_info_num].pci = cell->value4;
+ pt_info->lte_info[pt_info->lte_info_num].flag = 1;
+ pt_info->lte_info_num++;
+ pt_info->lte_info_valid = 1;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ list_free(cell_list);
+ }
+
+ LOGD("get_cell_success: %d, %d, %d.",pt_info->gsm_info_valid, pt_info->umts_info_valid, pt_info->lte_info_valid);
+ return QL_NW_SUCCESS;
+}
+
+QL_NW_ERROR_CODE ql_nw_add_event_handler(QL_NW_EventHandlerFunc_t handlerPtr,void* contextPtr)
+{
+ if(ql_info_handle == NULL || handlerPtr == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ mbtk_net_state_change_cb_reg(ql_info_handle, ql_nw_state_change_cb);
+ ql_func_cb_handle.handlerPtr = handlerPtr;
+ ql_func_cb_handle.contextPtr = contextPtr;
+ return QL_NW_SUCCESS;
+}
+
+QL_NW_ERROR_CODE ql_nw_get_volte_state(VOLTE_STATE *state)
+{
+ int ret;
+ if(ql_info_handle == NULL || state == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ ret = mbtk_volte_state_get(ql_info_handle, &(state->reg_state));
+ if(ret != 0)
+ return QL_NW_GENERIC_FAILURE;
+ else
+ return QL_NW_SUCCESS;
+}
+
+QL_NW_ERROR_CODE ql_nw_csq_get_signal_strength(QL_NW_CSQ_SIGNAL_STRENGTH_INFO_T *pt_info)
+{
+ int ret;
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_NW_GENERIC_FAILURE;
+ }
+ mbtk_signal_info_t signal;
+ ret = mbtk_net_signal_get(ql_info_handle, &signal);
+ if(ret != 0)
+ return QL_NW_GENERIC_FAILURE;
+ else
+ {
+ pt_info->rssi = (signal.rssi * 2 - 113);
+ pt_info->bitErrorRate = signal.ber;
+ LOGD("pt_info->rssi = %d pt_info->bitErrorRate = %d",pt_info->rssi,pt_info->bitErrorRate);
+ return QL_NW_SUCCESS;
+ }
+}
+
+//*********************************************************************************
+
diff --git a/mbtk/libql_lib_v2/src/ql_quec_sim.c b/mbtk/libql_lib_v2/src/ql_quec_sim.c
new file mode 100755
index 0000000..edcef9a
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_quec_sim.c
@@ -0,0 +1,406 @@
+#include "ql/ql_sim.h"
+#include "mbtk_type.h"
+#include "mbtk_info_api.h"
+
+extern mbtk_info_handle_t* ql_info_handle;
+extern int ql_info_handle_num;
+static bool inited = FALSE;
+
+QL_SIM_CardStatusIndMsgHandlerFunc_t handlerPtr_cb = NULL;
+
+typedef struct
+{
+ uint8 *operator_l;
+ uint8 *operator_s;
+ uint32 mcc_mnc;
+} operator_mcc_mnc_t;
+
+static operator_mcc_mnc_t operator_mcc_mnc[] =
+{
+ {"China Mobile","CMCC",46000},
+ {"China Unicom","CU",46001},
+ {"China Mobile","CMCC",46002},
+ {"China Telecom","CT",46003},
+ {"China Mobile","CMCC",46004},
+ {"China Telecom","CT",46005},
+ {"China Unicom","CU",46006},
+ {"China Mobile","CMCC",46007},
+ {"China Mobile","CMCC",46008},
+ {"China Unicom","CU",46009},
+ {"China Telecom","CT",46011}
+};
+
+void ql_sim_state_change_cb(const void* data, int data_len)
+{
+ if(handlerPtr_cb != NULL)
+ {
+ //QL_SIM_NFY_MSG_ID msg_id, void *pv_data, int pv_data_len, void *contextPtr
+ //handlerPtr_cb(net_data[2]);
+ }
+ mbtk_sim_card_info *info = NULL;
+ info = (mbtk_sim_card_info*)data;
+
+ QL_SIM_CARD_STATUS_INFO sim_card_info = {0};
+ sim_card_info.card_state = info->sim;
+ sim_card_info.card_type = info->sim_card_type;
+ /*
+ sim_client_handle_type h_sim,
+ E_QL_SIM_NFY_MSG_ID_T e_msg_id,
+ void *pv_data,
+ void *contextPtr
+ */
+ handlerPtr_cb(QL_SIM_CARD_STATUS_UPDATE_EVENT, &sim_card_info, sizeof(QL_SIM_CARD_STATUS_INFO), NULL);
+}
+
+QL_SIM_ERROR_CODE ql_sim_init()
+{
+ if(!inited && ql_info_handle == NULL)
+ {
+ ql_info_handle = mbtk_info_handle_get();
+ if(ql_info_handle)
+ {
+ ql_info_handle_num++;
+ inited = TRUE;
+ return QL_SIM_SUCCESS;
+ } else {
+ LOGE("mbtk_info_handle_get() fail.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ } else {
+ if(!inited) {
+ ql_info_handle_num++;
+ inited = TRUE;
+ }
+ return QL_SIM_SUCCESS;
+ }
+}
+
+
+QL_SIM_ERROR_CODE ql_sim_release()
+{
+ if(ql_info_handle)
+ {
+ LOGD("ql_info_handle_num = %d", ql_info_handle_num);
+ if(ql_info_handle_num == 1) { // 最后一个引用,可释放。
+ int ret = mbtk_info_handle_free(&ql_info_handle);
+ if(ret) {
+ LOGE("mbtk_info_handle_free() fail.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ else
+ {
+ ql_info_handle_num = 0;
+ ql_info_handle = NULL;
+ return QL_SIM_SUCCESS;
+ }
+ } else {
+ ql_info_handle_num--;
+ return QL_SIM_SUCCESS;
+ }
+ }
+ else
+ {
+ LOGE("Sim handle not inited.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+}
+
+
+QL_SIM_ERROR_CODE ql_sim_get_imsi(uint8_t *imsi, size_t imsiLen)
+{
+ if(ql_info_handle == NULL || imsi == NULL || imsiLen <= 0)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ memset(imsi,0,imsiLen);
+ int err = mbtk_imsi_get(ql_info_handle, imsi);
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_get_iccid(uint8_t *iccid, size_t iccidLen)
+{
+ if(ql_info_handle == NULL || iccid == NULL || iccidLen <= 0)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ memset(iccid, 0, iccidLen);
+ int err = mbtk_iccid_get(ql_info_handle, iccid);
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_get_phonenumber(uint8_t *phone_num, size_t phoneLen)
+{
+ if(ql_info_handle == NULL || phone_num == NULL || phoneLen <= 0)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ memset(phone_num, 0, phoneLen);
+ int err = mbtk_phone_number_get(ql_info_handle, phone_num);
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_get_operator_plmn_list(QL_SIM_PREFERRED_OPERATOR_LIST *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+
+ mbtk_plmn_info plmn;
+ int err = mbtk_get_plmn_list(ql_info_handle, &plmn);
+ if(err) {
+ LOGE("mbtk_get_plmn_list file : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ memset(pt_info, 0x0, sizeof(QL_SIM_PREFERRED_OPERATOR_LIST));
+ pt_info->preferred_operator_list_num = plmn.count;
+ int list_count;
+ for(list_count = 0; list_count < plmn.count; list_count++)
+ {
+ if(plmn.mbtk_plmn_name[list_count].format == 2) //number
+ {
+ uint32 plmn_name = (uint32)atoi(plmn.mbtk_plmn_name[list_count].plmn_name);
+ sprintf(pt_info->preferred_operator_list[list_count].mcc,"%d",plmn_name/100);
+ sprintf(pt_info->preferred_operator_list[list_count].mnc,"%02d",plmn_name%100);
+ }
+ else if(plmn.mbtk_plmn_name[list_count].format == 0)
+ {
+ int i = 0;
+ while(i < ARRAY_SIZE(operator_mcc_mnc))
+ {
+ if(!strcmp(operator_mcc_mnc[i].operator_l,plmn.mbtk_plmn_name))
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ memcpy(pt_info->preferred_operator_list[list_count].mcc,0,3);
+ memcpy(pt_info->preferred_operator_list[list_count].mnc,0,3);
+ }
+ else
+ {
+ sprintf(pt_info->preferred_operator_list[list_count].mcc, "%d", (operator_mcc_mnc[i].mcc_mnc)/100);
+ sprintf(pt_info->preferred_operator_list[list_count].mnc, "%d", (operator_mcc_mnc[i].mcc_mnc)%100);
+ }
+ }
+ else
+ {
+ int i = 0;
+ while(i < ARRAY_SIZE(operator_mcc_mnc))
+ {
+ if(!strcmp(operator_mcc_mnc[i].operator_s,plmn.mbtk_plmn_name))
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ memcpy(pt_info->preferred_operator_list[list_count].mcc,0,3);
+ memcpy(pt_info->preferred_operator_list[list_count].mnc,0,3);
+ }
+ else
+ {
+ sprintf(pt_info->preferred_operator_list[list_count].mcc, "%d", (operator_mcc_mnc[i].mcc_mnc)/100);
+ sprintf(pt_info->preferred_operator_list[list_count].mnc, "%d", (operator_mcc_mnc[i].mcc_mnc)%100);
+ }
+ }
+ }
+ int i;
+ for (i=0;i<pt_info->preferred_operator_list_num;i++)
+ {
+ LOGD("pt_info->preferred_operator_list[%d].mcc=%s",i, pt_info->preferred_operator_list[i].mcc);
+ LOGD("pt_info->preferred_operator_list[%d].mnc=%s",i, pt_info->preferred_operator_list[i].mnc);
+ }
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_verify_pin(QL_SIM_VERIFY_PIN_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+
+ int err = mbtk_verify_pin(ql_info_handle, pt_info->pin_value);
+ if(err) {
+ LOGE("mbtk_verify_pin fail : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_change_pin(QL_SIM_CHANGE_PIN_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ mbtk_change_pin_info pin_info = {0};
+ memcpy(pin_info.old_pin_value, pt_info->old_pin_value, strlen(pt_info->old_pin_value));
+ memcpy(pin_info.new_pin_value, pt_info->new_pin_value, strlen(pt_info->new_pin_value));
+ int err = mbtk_change_pin(ql_info_handle, &pin_info);
+ if(err) {
+ LOGE("mbtk_change_pin fail : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_unblock_pin(QL_SIM_UNBLOCK_PIN_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ mbtk_unlock_pin_info puk_pin_info = {0};
+ memcpy(puk_pin_info.pin_value, pt_info->new_pin_value, strlen(pt_info->new_pin_value));
+ memcpy(puk_pin_info.puk_value, pt_info->puk_value, strlen(pt_info->puk_value));
+ int err = mbtk_unlock_pin(ql_info_handle, &puk_pin_info);
+ if(err) {
+ LOGE("mbtk_unlock_pin fail : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_enable_pin(QL_SIM_VERIFY_PIN_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ mbtk_enable_pin_info pin_info = {0};
+ memcpy(pin_info.pin_value, pt_info->pin_value, strlen(pt_info->pin_value));
+ pin_info.enable = 1;
+ int err = mbtk_enable_pin(ql_info_handle, &pin_info);
+ if(err) {
+ LOGE("mbtk_enable_pin fail : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_disable_pin(QL_SIM_VERIFY_PIN_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("ARG error.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ mbtk_enable_pin_info pin_info = {0};
+ memcpy(pin_info.pin_value, pt_info->pin_value, strlen(pt_info->pin_value));
+ pin_info.enable = 0;
+ int err = mbtk_enable_pin(ql_info_handle, &pin_info);
+ if(err) {
+ LOGE("ql_sim_disable_pin fail : %d",err);
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ return QL_SIM_SUCCESS;
+ }
+}
+
+QL_SIM_ERROR_CODE ql_sim_get_card_status(QL_SIM_CARD_STATUS_INFO *pt_info)
+{
+ if(ql_info_handle == NULL || pt_info == NULL)
+ {
+ LOGE("sim not init.");
+ return QL_SIM_GENERIC_FAILURE;
+ }
+
+ mbtk_sim_state_enum sim;
+ mbtk_sim_card_type_enum sim_card_type;
+ mbtk_pin_puk_last_times ql_last_times = {0};
+ int err = mbtk_sim_state_get(ql_info_handle, &sim);
+ LOGD("mbtk_sim_state_get - %d");
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ memset(pt_info, 0x0, sizeof(QL_SIM_CARD_STATUS_INFO));
+ pt_info->card_state = sim;
+ switch (sim)
+ {
+ case 0: //ABSENT
+ pt_info->card_state = QL_SIM_STAT_NOT_INSERTED;
+ break;
+ case 1: //NOT READY
+ pt_info->card_state = QL_SIM_STAT_UNKNOWN;
+ break;
+ case 2: //READY
+ pt_info->card_state = QL_SIM_STAT_READY;
+ break;
+ case 3: //SIM PIN
+ pt_info->card_state = QL_SIM_STAT_SIM_PIN;
+ break;
+ case 4: //SIM PUK
+ pt_info->card_state = QL_SIM_STAT_SIM_PUK;
+ break;
+ case 5: //NETWORK
+ pt_info->card_state = QL_SIM_STAT_UNKNOWN;
+ break;
+ default:
+ pt_info->card_state = QL_SIM_STAT_UNKNOWN;
+ break;
+ }
+ }
+ err = mbtk_sim_card_type_get(ql_info_handle, &sim_card_type);
+ LOGD("mbtk_sim_card_type_get - %d", err);
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ if(sim_card_type == 0 || sim_card_type == 2)
+ pt_info->card_type = QL_SIM_CARD_TYPE_ICC;
+ else if(sim_card_type == 1 || sim_card_type == 3)
+ pt_info->card_type = QL_SIM_CARD_TYPE_UICC;
+ else
+ pt_info->card_type = QL_SIM_CARD_TYPE_UNKNOWN;
+ }
+ err = mbtk_pin_last_num_get(ql_info_handle, &ql_last_times);
+ LOGD("mbtk_pin_last_num_get - %d", err);
+ if(err) {
+ return QL_SIM_GENERIC_FAILURE;
+ } else {
+ pt_info->card_pin_info.pin1_num_retries = ql_last_times.p1_retry;
+ pt_info->card_pin_info.pin2_num_retries = ql_last_times.p2_retry;
+ pt_info->card_pin_info.puk1_num_retries = ql_last_times.puk1_retry;
+ pt_info->card_pin_info.puk2_num_retries = ql_last_times.puk2_retry;
+ }
+ return QL_SIM_SUCCESS;
+}
+
+QL_SIM_ERROR_CODE ql_sim_add_event_handler(QL_SIM_CardStatusIndMsgHandlerFunc_t handlerPtr, void* contextPtr)
+{
+ if(ql_info_handle == NULL || handlerPtr == NULL)
+ {
+ return QL_SIM_GENERIC_FAILURE;
+ }
+ handlerPtr_cb = handlerPtr;
+ mbtk_sim_state_change_cb_reg(ql_info_handle, ql_sim_state_change_cb);
+ return QL_SIM_SUCCESS;
+}
+
diff --git a/mbtk/libql_lib_v2/src/ql_sleep_wakelock.c b/mbtk/libql_lib_v2/src/ql_sleep_wakelock.c
new file mode 100755
index 0000000..03f356c
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_sleep_wakelock.c
@@ -0,0 +1,161 @@
+/*
+*
+* Data : 2023/03/28 16:00:28
+* Author : Hanzhiyu
+*
+*/
+#include "ql/ql_sleep_wakelock.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stddef.h>
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+
+typedef struct
+{
+ int fd;
+ char name[128];
+} lock_name;
+
+lock_name ql_lock_name[512]={0};
+static bool autosleep_enable = FALSE;
+
+extern int Ql_Autosleep_Enable(char enable)
+{
+ if(enable == 1)
+ {
+ if(!access("/sys/power/autosleep", W_OK))
+ {
+ system("echo mem > /sys/power/autosleep");
+ autosleep_enable = TRUE;
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/autosleep can not write.");
+ return -1;
+ }
+ }
+ else
+ {
+ if(!access("/sys/power/autosleep", W_OK))
+ {
+ system("echo off > /sys/power/autosleep");
+ autosleep_enable = FALSE;
+ return 0;
+ }
+ else
+ {
+ LOGE("/sys/power/autosleep can not write.");
+ return -1;
+ }
+ }
+}
+
+extern int Ql_SLP_WakeLock_Create(const char *name, size_t len)
+{
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+
+ if(name != NULL && len < 127)
+ {
+ int i;
+ for(i=0;i<512;i++)
+ {
+ if(ql_lock_name[i].fd == 0)
+ break;
+ }
+ memcpy(ql_lock_name[i].name, name, strlen(name)+1);
+ ql_lock_name[i].fd = i;
+ return ql_lock_name[i].fd;
+ }
+ else
+ return -1;
+}
+
+extern int Ql_SLP_WakeLock_Lock(int fd)
+{
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+
+ int i;
+ for(i=0;i<512;i++)
+ {
+ if(ql_lock_name[i].fd == fd)
+ break;
+ }
+ if(i == 512)
+ return -1;
+
+ if(!access("/sys/power/wake_lock", W_OK))
+ {
+ char cmd[128]={0};
+ sprintf(cmd, "echo %s > /sys/power/wake_lock", ql_lock_name[i].name);
+ system(cmd);
+ return 0;
+ }
+ else
+ {
+ printf("/sys/power/wake_lock can not write.");
+ return -1;
+ }
+}
+
+extern int Ql_SLP_WakeLock_Unlock(int fd)
+{
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+
+ int i;
+ for(i=0;i<512;i++)
+ {
+ if(ql_lock_name[i].fd == fd)
+ break;
+ }
+ if(i == 512)
+ return -1;
+
+ if(!access("/sys/power/wake_unlock", W_OK))
+ {
+ char cmd[128]={0};
+ sprintf(cmd, "echo %s > /sys/power/wake_unlock", ql_lock_name[i].name);
+ system(cmd);
+ return 0;
+ }
+ else
+ {
+ printf("/sys/power/wake_unlock can not write.");
+ return -1;
+ }
+
+}
+
+extern int Ql_SLP_WakeLock_Destroy(int fd)
+{
+ if(!autosleep_enable) {
+ LOGE("Autosleep not enable.");
+ return -1;
+ }
+
+ int i;
+ for(i=0;i<512;i++)
+ {
+ if(ql_lock_name[i].fd == fd)
+ break;
+ }
+ if(i == 512)
+ return -1;
+ else
+ {
+ ql_lock_name[i].fd = 0;
+ memset(ql_lock_name[i].name, 0, 128);
+ return 0;
+ }
+}
+
diff --git a/mbtk/libql_lib_v2/src/ql_sms.c b/mbtk/libql_lib_v2/src/ql_sms.c
new file mode 100755
index 0000000..cbad623
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_sms.c
@@ -0,0 +1,493 @@
+//#include "lynq/lynq_sms_api.h"
+#include "mbtk_info_api.h"
+#include "mbtk_pdu_sms.h"
+#include "ql/ql_sms.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#define TELEPHONE_NUM_MAX 16
+#define MSM_NUMBER_MAX 1024+1
+#define RES_NUM_MIN 128
+
+#define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2"))
+
+static mbtk_info_handle_t* info_handle = NULL;
+static char center_address[15] = {0};
+
+
+// 编码后短信
+
+#if 0
+struct PDUS {
+ unsigned int count;
+ char **PDU;
+};
+#endif
+
+void lynq_sms_state_change_cb(const void* data, int data_len)
+{
+ LOGV("sms_state_change_cb()----------start\n");
+ uint8 *ptr = (uint8*)data;
+ printf("3sms_state_change_cb() : %s\n", ptr);
+
+ struct SMS_Struct s = PDUDecoding(ptr);
+ printf("服务中心地址: %s\n", s.SCA);
+ printf("发送方地址: %s\n", s.OA);
+ printf("服务中心时间戳: %s\n", s.SCTS);
+ printf("消息内容: %s\n", s.UD);
+ printf("数据编码方案: %s\n", DSC_to_msg(s.DCS));
+}
+
+
+QL_SMS_ERROR_CODE ql_sms_init()
+{
+ if(info_handle == NULL)
+ {
+ info_handle = mbtk_info_handle_get();
+ if(info_handle)
+ {
+ printf("creat info_handle is success\n");
+ }
+ else{
+ printf("creat info_handle is fail\n");
+ return QL_SMS_GENERIC_FAILURE;
+ }
+ }
+
+ return QL_SMS_SUCCESS;
+}
+
+
+QL_SMS_ERROR_CODE ql_sms_release()
+{
+ int ret = QL_SMS_SUCCESS;
+ if(info_handle)
+ {
+ ret = mbtk_info_handle_free(&info_handle);
+ }
+ else
+ {
+ ret = QL_SMS_GENERIC_FAILURE;
+ }
+
+ return ret;
+}
+
+
+/*
+*AT+CMGS="10086", CMGS TEST // Send a SMS
+> CMGS TEST
++CMGS: 17
+OK
+*/
+/*
+int charset: send sms mode
+ 0:pdu, 1:text
+
+*/
+//当state 设置为 0(pdu)模式时,telephony_num应该设置为pud 数据大小的长度;msg:为pud 数据
+
+QL_SMS_ERROR_CODE ql_sms_send_pdu_msg(uint8_t *phone_num,uint8_t *data,int sms_type)
+{
+ if(info_handle == NULL || phone_num == NULL || data == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ char resp[RES_NUM_MIN] = {0};
+ char pdu_data[512] = {0};
+ char phone_lenth[10] = {0};
+ char *p = pdu_data;
+ int mode = 0;
+ int err = 0;
+ int i = 0;
+
+ if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
+ {
+ printf("strlen(telephony_num):%d\n", strlen(phone_num));
+ printf("strlen(msg):%d\n", strlen(data));
+ return -1;
+ }
+
+ memset(center_address, 0, sizeof(center_address));
+ memcpy(center_address, "+8613800280500", strlen("+8613800280500"));
+
+ printf("phone_num:%s\n", phone_num);
+ printf("center_address:%s\n", center_address);
+ printf("data:%s\n", data);
+
+
+ mode = 0; // PDU
+
+ char* pdu = NULL;
+ char* smsc = SCAEncoding(center_address);
+ struct PDUS *pdus = PDUEncoding(center_address,phone_num, data, NULL);
+
+ for (i = 0; i < pdus->count; i++) {
+ printf("第 %d 条:\n", i + 1);
+ printf("%s\n", pdus->PDU[i]);
+ pdu = pdus->PDU[i];
+ }
+
+ sprintf(p, "%s",smsc);
+ printf("pdu_data:%s\n", pdu_data);
+ sprintf(p+strlen(p), "%s", pdu);
+ printf("pdu_data:%s\n",pdu_data);
+
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+ sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data);
+ printf("cmgs:%s\n", cmgs);
+
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgs_set(info_handle, cmgs, resp);
+ if(err) {
+ printf("Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgs set success . resp:%s\n", resp);
+ }
+
+ return 0;
+
+}
+QL_SMS_ERROR_CODE ql_sms_send_text_msg(uint8_t *phone_num,uint8_t *data,int sms_type)
+{
+ if(info_handle == NULL || phone_num == NULL || data == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ char resp[RES_NUM_MIN] = {0};
+ int mode = 0;
+ int err = 0;
+ if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
+ {
+ printf("strlen(telephony_num):%d\n", strlen(phone_num));
+ printf("strlen(msg):%d\n", strlen(data));
+ return -1;
+ }
+
+ mode = 1; // text
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+ sprintf(cmgs,"%s,%s",phone_num, data);
+ printf("cmgs:%s\n", cmgs);
+
+/* char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgs, 0, sizeof(cmgs));
+ memcpy(cmgs, ptr, strlen(ptr));
+ printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs));
+ }
+*/
+
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgs_set(info_handle, cmgs, resp);
+ if(err) {
+ printf("Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgs set success . resp:%s\n", resp);
+ }
+
+ return 0;
+
+}
+
+
+QL_SMS_ERROR_CODE ql_sms_add_event_handler(QL_SMS_StatusIndMsgHandlerFunc_t handlerPtr, void* contextPtr)
+{
+ if(info_handle == NULL)
+ {
+ return QL_SMS_GENERIC_FAILURE;
+ }
+
+ int ret = mbtk_sms_cnmi_set(info_handle);
+ if(ret)
+ {
+ printf("set cnmi fail\n");
+ return QL_SMS_GENERIC_FAILURE;
+ }
+
+ mbtk_sms_state_change_cb_reg(info_handle, lynq_sms_state_change_cb);
+ return QL_SMS_SUCCESS;
+}
+
+
+/*
+ AT+CMGD=<index>[,<delflag>]
+
+ Deletes message based on index
+ node:
+ index is -1, delete all message
+ delflag set 4
+*/
+
+QL_SMS_ERROR_CODE ql_sms_delete_msg(size_t index)
+{
+ char cmgd[128] = {0};
+ int err = 0;
+
+ if(index == -1) //delete all
+ {
+ memcpy(cmgd, ",4", strlen(",4"));
+ }
+ else
+ {
+ sprintf(cmgd,"%d",index);
+ }
+
+ printf("cmgd:%s\n", cmgd);
+
+ err = mbtk_sms_cmgd_set(info_handle, cmgd);
+ if(err) {
+ printf("lynq_delete_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("lynq_delete_sms set success\n");
+ }
+
+ return 0;
+
+}
+
+
+QL_SMS_ERROR_CODE ql_search_sms_text_message(int index, recvmessage* payload)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ int mode = 1; // text
+ int err = 0;
+ char *data = "ALL";
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+
+ char cmgl[128] = {0};
+ char resp[1024+1] ={0};
+ sprintf(cmgl,"%d,%s", index, data);
+/*
+ char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgl, 0, sizeof(cmgl));
+ memcpy(cmgl, ptr, strlen(ptr));
+ printf("0cmgl:%s\n", cmgl);
+ }
+*/
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
+ if(err) {
+ printf("lynq_list_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgl set success, reg:%s\n",resp);
+ }
+
+ return 0;
+
+}
+QL_SMS_ERROR_CODE ql_search_sms_pdu_message(int index, recvmessage* payload)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ int mode = 0; // pud
+ int err = 0;
+ char *data = "ALL";
+
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+
+ char cmgl[128] = {0};
+ char resp[1024+1] ={0};
+ sprintf(cmgl,"%d,%s", index, data);
+/*
+ char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgl, 0, sizeof(cmgl));
+ memcpy(cmgl, ptr, strlen(ptr));
+ printf("0cmgl:%s\n", cmgl);
+ }
+*/
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
+ if(err) {
+ printf("lynq_list_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgl set success, reg:%s\n",resp);
+ }
+
+ return 0;
+
+}
+
+
+/*
+function: lynq_list_sms
+stat:0:pud, 1:text
+index: 0, list index;
+ > 0,
+
+*/
+QL_SMS_ERROR_CODE ql_sms_list_sms(int stat, int index, char *data)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ int mode = 0;
+ int err = 0;
+
+ if(stat) // text
+ {
+ mode = 1;
+ }
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+
+ char cmgl[128] = {0};
+ char resp[1024+1] ={0};
+ sprintf(cmgl,"%d,%s", index, data);
+/*
+ char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgl, 0, sizeof(cmgl));
+ memcpy(cmgl, ptr, strlen(ptr));
+ printf("0cmgl:%s\n", cmgl);
+ }
+*/
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
+ if(err) {
+ printf("lynq_list_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgl set success, reg:%s\n",resp);
+ }
+
+ return 0;
+}
+
+
+
+int ql_sms_query_sms_storage_status(void)
+{
+ char mem[128] = {0};
+ int err = mbtk_sms_cpms_get(info_handle, mem);
+ if(err) {
+ printf("cpms query is fail Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cpms query is success : %s\n", mem);
+ }
+
+ return 0;
+}
+
+QL_SMS_ERROR_CODE ql_sms_get_sms_center_address(uint8_t *sms_center_addree)
+{
+ char csca[128] = {0};
+ if(info_handle == NULL || sms_center_addree == NULL)
+ {
+ return QL_SMS_GENERIC_FAILURE;
+ }
+
+ int err = mbtk_sms_csca_get(info_handle, sms_center_addree);
+ if(err) {
+ printf("lynq_get_smsc_address Error : %d\n", err);
+ return QL_GET_RESPONSE_ERROR;
+ } else {
+ printf("lynq_get_smsc_address success\n");
+ }
+
+ return 0;
+}
+
+
+QL_SMS_ERROR_CODE ql_sms_set_sms_center_address(unsigned char *destNum)
+{
+ printf("1destNum:%s\n", destNum);
+ memset(center_address, 0, sizeof(center_address));
+ memcpy(center_address, destNum, strlen(destNum));
+ if(info_handle == NULL || destNum == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_set(info_handle, destNum);
+ if(err) {
+ printf("Error : %d\n", err);
+ return err;
+ } else {
+ // memset(center_address, 0, sizeof(center_address));
+ // memcpy(center_address, destNum, strlen(destNum));
+ printf("destNum:%s\n", destNum);
+ printf("lynq_set_smsc_address success\n");
+ }
+ return 0;
+
+}
+
+
+
+
+
diff --git a/mbtk/libql_lib_v2/src/ql_spi.c b/mbtk/libql_lib_v2/src/ql_spi.c
new file mode 100755
index 0000000..4fc5d9f
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_spi.c
@@ -0,0 +1,342 @@
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h>
+#include <linux/types.h>
+#include <linux/spi/spidev.h>
+
+#include <stdint.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/types.h>
+#include <linux/spi/spidev.h>
+#include <errno.h>
+
+#include "ql/ql_spi.h"
+#include "mbtk_log.h"
+
+#if 0
+static const char *device = "/dev/spidev1.0\0";
+static uint8_t mode = 3; /* SPI通信使用全双工,设置CPOL=0,CPHA=0。 */
+static uint8_t bits = 8; /* 8bits读写,MSB first。*/
+static uint32_t speed = 100 * 1000;/* 设置0.5M传输速度 */
+static uint16_t delay = 500;
+
+int SPI_Transfer(const uint8_t *TxBuf, uint8_t *RxBuf, int len)
+{
+ int ret;
+ int fd = g_SPI_Fd;
+
+
+ struct spi_ioc_transfer tr ;
+ memset(&tr,0x00,sizeof(tr));
+ tr.tx_buf = (unsigned long) TxBuf,
+ tr.rx_buf = (unsigned long) RxBuf,
+ tr.len =len,
+ tr.delay_usecs = delay;
+ tr.speed_hz=speed;
+ tr.bits_per_word=bits;
+ ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
+ if (ret < 1)
+ {
+ printf("can't send spi message");
+ }
+ else
+ {
+ //printf("Send spi message OK %d\n",RxBuf[0]);
+ }
+ return 1;
+}
+
+/**
+* 功 能:关闭SPI模块
+*/
+int SPI_Close(void)
+{
+ int fd = g_SPI_Fd;
+
+
+ if (fd == 0) /* SPI是否已经打开*/
+ return 0;
+ close(fd);
+ g_SPI_Fd = 0;
+
+
+ return 0;
+}
+
+int SPI_Write(uint8_t *TxBuf, int len)
+{
+ int ret;
+ int fd = g_SPI_Fd;
+
+ printf("fd : %d\n",fd);
+ ret = write(fd, TxBuf, len);
+ if (ret < 0)
+ printf("SPI Write errorn");
+
+ return ret;
+}
+
+int SPI_Open(void)
+{
+ int fd;
+ int ret = 0;
+
+ printf("open spi dev:%s \r\n", device);
+ fd = open(device, O_RDWR);
+ if (fd < 0)
+ {
+ printf("can't open device \n");
+ return -1;
+ }
+ else
+ printf("SPI - Open Succeed. Start Init SPI...n\n");
+
+ /*
+ * spi mode
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
+ if (ret == -1)
+ printf("can't set spi mode\n");
+
+
+ ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
+ if (ret == -1)
+ printf("can't get spi mode\n");
+
+
+ /*
+ * bits per word
+ */
+ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
+ if (ret == -1)
+ printf("can't set bits per word\n");
+
+
+ ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
+ if (ret == -1)
+ printf("can't get bits per word\n");
+
+
+ /*
+ * max speed hz
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
+ if (ret == -1)
+ printf("can't set max speed hz\n");
+
+
+ ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
+ if (ret == -1)
+ printf("can't get max speed hz\n");
+
+ g_SPI_Fd=fd;
+ return ret;
+}
+#endif
+
+/**
+ * Function: Ql_SPI_Init
+ * Description: spi init
+ * Parameters: dev_name---device name
+ * mode---spi mode
+ * bits---spi per word
+ * speed---spi transfer clock
+ * Return: spi fd
+ **/
+int Ql_SPI_Init(const char *dev_name, SPI_MODE mode, unsigned char bits, SPI_SPEED speed)
+{
+ int fd;
+ int ret = 0;
+
+ LOGD("open spi dev:%s.", dev_name);
+ fd = open(dev_name, O_RDWR);
+ if (fd < 0)
+ {
+ LOGE("can't open device, errno - %d", errno);
+ return -1;
+ }
+ else
+ LOGD("SPI - Open Succeed. Start Init SPI...");
+
+ /*
+ * spi mode
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
+ if (ret == -1) {
+ LOGE("can't set spi mode");
+ goto error;
+ }
+
+#if 0
+ ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
+ if (ret == -1) {
+ LOGE("can't get spi mode");
+ goto error;
+ }
+#endif
+
+ /*
+ * bits per word
+ */
+ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
+ if (ret == -1) {
+ LOGE("can't set bits per word");
+ goto error;
+ }
+
+#if 0
+ ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
+ if (ret == -1) {
+ LOGE("can't get bits per word");
+ goto error;
+ }
+#endif
+
+ /*
+ * max speed hz
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
+ if (ret == -1) {
+ LOGE("can't set max speed hz");
+ goto error;
+ }
+
+#if 0
+ ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
+ if (ret == -1) {
+ LOGE("can't get max speed hz");
+ goto error;
+ }
+#endif
+
+ return fd;
+error:
+ if(fd > 0)
+ {
+ close(fd);
+ }
+ return -1;
+}
+
+/**
+ * Function: Ql_SPI_DeInit
+ * Description: spi deinit
+ * Parameters: fd---spi fd
+ * Return:
+ */
+int Ql_SPI_DeInit(int fd)
+{
+ if (fd <= 0)
+ return -1;
+
+ close(fd);
+ return 0;
+}
+
+/**
+ * Function: Ql_SPI_Write_Read
+ * Description: spi write read function
+ * Parameters: fd---spi fd
+ * w_buf---write buffer
+ * r_buf---read buffer
+ * len---spi transfer length
+ * Return: 0---transfer success
+ * other---failed
+ **/
+int Ql_SPI_Write_Read(int fd, unsigned char *w_buf, unsigned char *r_buf, unsigned int len)
+{
+ int ret;
+ struct spi_ioc_transfer tr ;
+ memset(&tr,0x00,sizeof(tr));
+ tr.tx_buf = (unsigned long) w_buf,
+ tr.rx_buf = (unsigned long) r_buf,
+ tr.len =len,
+ tr.delay_usecs = 500;
+ //tr.speed_hz=speed;
+ //tr.bits_per_word=bits;
+ ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
+ if (ret < 1)
+ {
+ LOGE("can't send spi message");
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+#if 0
+int main(int argc, char *argv[])
+{
+
+ char send_data[64] = {0};
+ char read_data[64] = {0};
+ char crc = 0;
+ int i = 0;
+ int j = 0;
+
+ system("echo PB6 > /sys/kernel/debug/sunxi_pinctrl/sunxi_pin");
+ system("echo PB6 1 > /sys/kernel/debug/sunxi_pinctrl/function");
+ system("echo PB6 0 > /sys/kernel/debug/sunxi_pinctrl/data");
+
+ /* spi 初始化程序 */
+ SPI_Open();
+
+ send_data[0] = 0x55;
+ send_data[1] = 0x00;
+ send_data[2] = 0x84;
+ send_data[3] = 0x00;
+ send_data[4] = 0x08;
+ send_data[5] = 0x00;
+ send_data[6] = 0x00;
+
+ crc = send_data[1];
+ for (i = 2; i < 7; i++)
+ {
+ crc ^= send_data[i];
+ }
+ crc = ~crc;
+
+ send_data[7] = crc;
+
+ printf("send data:");
+ for (i = 0; i < 8; i++)
+ {
+ printf("%#x, ", send_data[i]);
+ }
+ printf("\n");
+
+ /* spi 发送数据 */
+ SPI_Transfer(send_data,read_data,8);
+
+ printf("read data:");
+ for (j = 0; j < 20; j++)
+ {
+ printf("%#x, ", read_data[j]);
+ }
+
+ usleep(10000);
+
+
+ memset(read_data, 0, sizeof(read_data));
+ memset(send_data, 0, sizeof(send_data));
+
+ /* spi 读取数据 */
+ SPI_Transfer(send_data,read_data,16);
+
+ printf("read data:");
+ for (j = 0; j < 20; j++)
+ {
+ printf("%#x, ", read_data[j]);
+ }
+
+ return 0;
+}
+#endif
diff --git a/mbtk/libql_lib_v2/src/ql_uart.c b/mbtk/libql_lib_v2/src/ql_uart.c
new file mode 100755
index 0000000..ca6f779
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_uart.c
@@ -0,0 +1,432 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "mbtk_log.h"
+#include "ql/ql_uart.h"
+
+int Ql_UART_Open(const char* port, Enum_BaudRate baudrate, Enum_FlowCtrl flowctrl)
+{
+ int fd;
+ if((fd = open(port, O_RDWR | O_NOCTTY)) < 0)
+ {
+ LOGE("open %s failed - %d", port, errno);
+ return -1;
+ }
+
+ LOGD("Open %s success.", port);
+
+ /* set newtio */
+ struct termios newtio;
+ memset(&newtio, 0, sizeof(newtio));
+ if (tcflush(fd, TCIOFLUSH) < 0) {
+ LOGE("Could not flush uart port");
+ return -1;
+ }
+
+ newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
+ newtio.c_cc[VMIN] = 0; /* blocking read until 5 chars received */
+
+ if(flowctrl == FC_RTSCTS) {
+ newtio.c_cflag |= CRTSCTS;
+ } else if(flowctrl == FC_XONXOFF) {
+ newtio.c_cflag |= (IXON | IXOFF);
+ } else {
+ // newtio.c_cflag |= CRTSCTS;
+ }
+ /* c_iflag 输入模式 */
+ newtio.c_iflag &= ~(ICRNL | INLCR);
+ newtio.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+ // /* c_lflag 本地模式 */
+ newtio.c_cflag &= ~ INPCK;
+ newtio.c_cflag |= (CLOCAL | CREAD);
+
+ // /* c_lflag 本地模式 */
+ newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+ /* c_oflag 输出模式 */
+ newtio.c_oflag &= ~ OPOST;
+ newtio.c_oflag &= ~(ONLCR | OCRNL);
+
+ /* c_cflag 控制模式 */
+ newtio.c_cflag &= ~ CSIZE;
+ newtio.c_cflag |= CS8;
+ newtio.c_cflag &= ~ CSTOPB;
+ newtio.c_cflag &= ~ PARENB;
+
+ switch(baudrate)
+ {
+ case B_300:
+ cfsetospeed(&newtio, B300);
+ cfsetispeed(&newtio, B300);
+ break;
+ case B_600:
+ cfsetospeed(&newtio, B600);
+ cfsetispeed(&newtio, B600);
+ break;
+ case B_1200:
+ cfsetospeed(&newtio, B1200);
+ cfsetispeed(&newtio, B1200);
+ break;
+ case B_2400:
+ cfsetospeed(&newtio, B2400);
+ cfsetispeed(&newtio, B2400);
+ break;
+ case B_4800:
+ cfsetospeed(&newtio, B4800);
+ cfsetispeed(&newtio, B4800);
+ break;
+ case B_9600:
+ cfsetospeed(&newtio, B9600);
+ cfsetispeed(&newtio, B9600);
+ break;
+ case B_19200:
+ cfsetospeed(&newtio, B19200);
+ cfsetispeed(&newtio, B19200);
+ break;
+ case B_38400:
+ cfsetospeed(&newtio, B38400);
+ cfsetispeed(&newtio, B38400);
+ break;
+ case B_57600:
+ cfsetospeed(&newtio, B57600);
+ cfsetispeed(&newtio, B57600);
+ break;
+ case B_115200:
+ cfsetospeed(&newtio, B115200);
+ cfsetispeed(&newtio, B115200);
+ break;
+ case B_230400:
+ cfsetospeed(&newtio, B230400);
+ cfsetispeed(&newtio, B230400);
+ break;
+ case B_460800:
+ cfsetospeed(&newtio, B460800);
+ cfsetispeed(&newtio, B460800);
+ break;
+ case B_921600:
+ cfsetospeed(&newtio, B921600);
+ cfsetispeed(&newtio, B921600);
+ break;
+ case B_3000000:
+ cfsetospeed(&newtio, B3000000);
+ cfsetispeed(&newtio, B3000000);
+ break;
+ case B_4000000:
+ cfsetospeed(&newtio, B4000000);
+ cfsetispeed(&newtio, B4000000);
+ break;
+ default:
+ cfsetospeed(&newtio, B115200);
+ cfsetispeed(&newtio, B115200);
+ break;
+ }
+
+ if (tcsetattr(fd, TCSANOW, &newtio) < 0) {
+ LOGE("Can't set port setting");
+ return -1;
+ }
+ /* Blocking behavior */
+ fcntl(fd, F_SETFL, 0);
+
+ return fd;
+}
+
+int Ql_UART_Read(int fd, char* buf, unsigned int buf_len)
+{
+ return read(fd, buf, buf_len);
+}
+
+
+int Ql_UART_Write(int fd, const char* buf, unsigned int buf_len)
+{
+ return write(fd, buf, buf_len);
+}
+
+
+int Ql_UART_SetDCB(int fd, ST_UARTDCB *dcb)
+{
+ struct termios newtio;
+ memset(&newtio, 0, sizeof(newtio));
+
+ if(tcgetattr(fd, &newtio) != 0)
+ {
+ LOGE("Serial port configuration backup errno");
+ return -1;
+ }
+
+ switch(dcb->baudrate)
+ {
+ case B_300:
+ cfsetospeed(&newtio, B300);
+ cfsetispeed(&newtio, B300);
+ break;
+ case B_600:
+ cfsetospeed(&newtio, B600);
+ cfsetispeed(&newtio, B600);
+ break;
+ case B_1200:
+ cfsetospeed(&newtio, B1200);
+ cfsetispeed(&newtio, B1200);
+ break;
+ case B_2400:
+ cfsetospeed(&newtio, B2400);
+ cfsetispeed(&newtio, B2400);
+ break;
+ case B_4800:
+ cfsetospeed(&newtio, B4800);
+ cfsetispeed(&newtio, B4800);
+ break;
+ case B_9600:
+ cfsetospeed(&newtio, B9600);
+ cfsetispeed(&newtio, B9600);
+ break;
+ case B_19200:
+ cfsetospeed(&newtio, B19200);
+ cfsetispeed(&newtio, B19200);
+ break;
+ case B_38400:
+ cfsetospeed(&newtio, B38400);
+ cfsetispeed(&newtio, B38400);
+ break;
+ case B_57600:
+ cfsetospeed(&newtio, B57600);
+ cfsetispeed(&newtio, B57600);
+ break;
+ case B_115200:
+ cfsetospeed(&newtio, B115200);
+ cfsetispeed(&newtio, B115200);
+ break;
+ case B_230400:
+ cfsetospeed(&newtio, B230400);
+ cfsetispeed(&newtio, B230400);
+ break;
+ case B_460800:
+ cfsetospeed(&newtio, B460800);
+ cfsetispeed(&newtio, B460800);
+ break;
+ case B_921600:
+ cfsetospeed(&newtio, B921600);
+ cfsetispeed(&newtio, B921600);
+ break;
+ case B_3000000:
+ cfsetospeed(&newtio, B3000000);
+ cfsetispeed(&newtio, B3000000);
+ break;
+ case B_4000000:
+ cfsetospeed(&newtio, B4000000);
+ cfsetispeed(&newtio, B4000000);
+ break;
+ default:
+ LOGD("No set speed.");
+ break;
+ }
+
+ switch(dcb->databit)
+ {
+ case DB_CS5:
+ newtio.c_cflag &= ~CSIZE;
+ newtio.c_cflag |= CS5;
+ break;
+ case DB_CS6:
+ newtio.c_cflag &= ~CSIZE;
+ newtio.c_cflag |= CS6;
+ break;
+ case DB_CS7:
+ newtio.c_cflag &= ~CSIZE;
+ newtio.c_cflag |= CS7;
+ break;
+ case DB_CS8:
+ newtio.c_cflag &= ~CSIZE;
+ newtio.c_cflag |= CS8;
+ break;
+ default:
+ LOGD("No set databit.");
+ break;
+ }
+
+ if(dcb->stopbit == SB_2) {
+ newtio.c_cflag |= CSTOPB;
+ } else {
+ newtio.c_cflag &= ~CSTOPB;
+ }
+
+ switch (dcb->parity)
+ {
+ case PB_ODD:// 奇校验
+ newtio.c_cflag |= PARENB;
+ newtio.c_cflag |= PARODD;
+ break;
+ case PB_EVEN:// 偶校验
+ newtio.c_cflag |= PARENB;
+ newtio.c_cflag &= ~PARODD;
+ break;
+ case PB_NONE:// 无奇偶校验
+ newtio.c_cflag &= ~PARENB;
+ break;
+ default:
+ LOGD("No set parity.");
+ break;
+ }
+
+ switch (dcb->flowctrl)
+ {
+ case FC_RTSCTS:
+ newtio.c_cflag |= CRTSCTS;
+ tcflush(fd, TCIFLUSH);
+ break;
+ case FC_XONXOFF:
+ newtio.c_iflag |= (IXON | IXOFF);
+ tcflush(fd, TCIFLUSH);
+ break;
+ case FC_NONE:
+ newtio.c_cflag &= ~CRTSCTS;
+ newtio.c_iflag &= ~(IXON | IXOFF);
+ tcflush(fd, TCIFLUSH);
+ break;
+ default:
+ LOGD("No set flow ctrl.");
+ break;
+ }
+
+ if(tcsetattr(fd, TCSANOW, &newtio) != 0)
+ {
+ LOGE("Serial port configuration backup errno");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int Ql_UART_GetDCB(int fd, ST_UARTDCB *dcb)
+{
+ struct termios newtio;
+ memset(&newtio, 0, sizeof(newtio));
+
+ if(tcgetattr(fd, &newtio) != 0)
+ {
+ LOGE("Serial port configuration backup errno");
+ return -1;
+ }
+
+ switch(cfgetispeed(&newtio))
+ {
+ case B300:
+ dcb->baudrate = B_300;
+ break;
+ case B600:
+ dcb->baudrate = B_600;
+ break;
+ case B1200:
+ dcb->baudrate = B_1200;
+ break;
+ case B2400:
+ dcb->baudrate = B_2400;
+ break;
+ case B4800:
+ dcb->baudrate = B_4800;
+ break;
+ case B9600:
+ dcb->baudrate = B_9600;
+ break;
+ case B19200:
+ dcb->baudrate = B_19200;
+ break;
+ case B38400:
+ dcb->baudrate = B_38400;
+ break;
+ case B57600:
+ dcb->baudrate = B_57600;
+ break;
+ case B115200:
+ dcb->baudrate = B_115200;
+ break;
+ case B230400:
+ dcb->baudrate = B_230400;
+ break;
+ case B460800:
+ dcb->baudrate = B_460800;
+ break;
+ case B921600:
+ dcb->baudrate = B_921600;
+ break;
+ case B3000000:
+ dcb->baudrate = B_3000000;
+ break;
+ case B4000000:
+ dcb->baudrate = B_4000000;
+ break;
+ default:
+ dcb->baudrate = B_115200;
+ break;
+ }
+
+ switch(newtio.c_cflag & CSIZE)
+ {
+ case CS5:
+ dcb->databit = DB_CS5;
+ break;
+ case CS6:
+ dcb->databit = DB_CS6;
+ break;
+ case CS7:
+ dcb->databit = DB_CS7;
+ break;
+ case CS8:
+ dcb->databit = DB_CS8;
+ break;
+ default:
+ dcb->databit = DB_CS8;
+ break;
+ }
+
+ if(newtio.c_cflag & CSTOPB) {
+ dcb->stopbit = SB_2;
+ } else {
+ dcb->stopbit = SB_1;
+ }
+
+ if(newtio.c_cflag & PARENB) { // 启用了奇偶校验
+ if(newtio.c_cflag & PARODD) {
+ dcb->parity = PB_ODD; // 奇校验
+ } else {
+ dcb->parity = PB_EVEN; // 偶校验
+ }
+ } else {
+ dcb->parity = PB_NONE;
+ }
+
+ if(newtio.c_cflag & CRTSCTS) {
+ dcb->flowctrl = FC_RTSCTS;
+ } else if(newtio.c_iflag & (IXON | IXOFF) == (IXON | IXOFF)){
+ dcb->flowctrl = FC_XONXOFF;
+ } else {
+ dcb->flowctrl = FC_NONE;
+ }
+
+ return 0;
+}
+
+
+int Ql_UART_IoCtl(int fd, unsigned int cmd, void* pValue)
+{
+ return 0;
+}
+
+
+int Ql_UART_Close(int fd)
+{
+ if (fd <= 0)
+ return -1;
+
+ close(fd);
+ return 0;
+}
+
diff --git a/mbtk/libql_lib_v2/src/ql_voice.c b/mbtk/libql_lib_v2/src/ql_voice.c
new file mode 100755
index 0000000..9df4053
--- /dev/null
+++ b/mbtk/libql_lib_v2/src/ql_voice.c
@@ -0,0 +1,229 @@
+#include "mbtk_type.h"
+#include "ql/ql_at.h"
+#include "ql/ql_vcall.h"
+#include "ql/ql_mcm_call.h"
+#include "ql/ql_voice.h"
+
+typedef struct
+{
+ int cmdIdx;
+ char *funcName;
+} st_api_test_case;
+
+//for server test
+st_api_test_case at_api_testcases[] =
+{
+ {0, "print_help"},
+ {1, "QL_Voice_Call_Ecall"},
+ {2, "QL_Voice_Call_Ecall_HangUp"},
+
+ {-1, NULL}
+};
+
+
+voice_client_handle_type h_voice = 0;
+
+
+void print_help(void)
+{
+ int i;
+
+ printf("Supported test cases:\n");
+ for(i = 0; ; i++)
+ {
+ if(at_api_testcases[i].cmdIdx == -1)
+ {
+ break;
+ }
+ printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
+ }
+}
+
+static void ql_voice_call_ind_func(unsigned int ind_id,
+ void* ind_data,
+ uint32_t ind_data_len)
+{
+ if(NULL == ind_data)
+ {
+ return;
+ }
+
+ switch(ind_id)
+ {
+ case E_QL_MCM_VOICE_CALL_IND:
+ {
+ if(ind_data_len != sizeof(ql_mcm_voice_call_ind))
+ {
+ break;
+ }
+
+ ql_mcm_voice_call_ind *pVoiceCallInd = (ql_mcm_voice_call_ind*)ind_data;
+
+ char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
+
+ int i = 0;
+ for(i = 0; i < pVoiceCallInd->calls_len; i++)
+ {
+ printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n",
+ pVoiceCallInd->calls[i].call_id, pVoiceCallInd->calls[i].number, call_state[pVoiceCallInd->calls[i].state]);
+ }
+
+ break;
+ }
+
+ case E_QL_MCM_VOICE_ECALL_STATUE_IND:
+ {
+ if(ind_data_len != sizeof(ql_mcm_voice_ecall_status_ind))
+ {
+ break;
+ }
+
+ ql_mcm_voice_ecall_status_ind *pEcallStatusInd
+ = (ql_mcm_voice_ecall_status_ind*)ind_data;
+
+ if (pEcallStatusInd->ecall_msd_tx_status_valid)
+ {
+ if (pEcallStatusInd->ecall_msd_tx_status == E_QL_MCM_VOICE_ECALL_MSD_TRANSMISSION_STATUS_SUCCESS)
+ {
+ printf("========== Ecall status call_id =%d , ecall msd tx success.\r\n", pEcallStatusInd->call_id);
+ }
+ else
+ {
+ printf("========== Ecall status call_id =%d , ecall msd tx failure.\r\n", pEcallStatusInd->call_id);
+ }
+ }
+ else
+ {
+ printf("========== Ecall status call_id =%d \r\n", pEcallStatusInd->call_id);
+ }
+
+ break;
+ }
+
+ case E_QL_MCM_VOICE_UNKOWN_IND:
+ default:
+ break;
+ }
+}
+
+//"\t1 call init\n"
+QL_VOICE_ERROR_CODE ql_voice_call_init()
+{
+ int ret = 0;
+ ret = QL_Voice_Call_Client_Init(&h_voice);
+ if(ret < 0)
+ {
+ printf("QL_Voice_Call_Client_Init FAIL. ret:%d\n",ret);
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+ else{
+ printf("QL_Voice_Call_Client_Init ret = %d, with h_voice=%d\n", ret, h_voice);
+ }
+
+ return ret;
+}
+
+//"\t9 call deinit\n"
+QL_VOICE_ERROR_CODE ql_voice_call_release()
+{
+ int ret = 0;
+ ret = QL_Voice_Call_Client_Deinit(h_voice);
+ if(ret)
+ {
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+
+ return ret;
+}
+
+//\t2 call register handle\n"
+QL_VOICE_ERROR_CODE ql_voice_call_event_register(QL_VOICE_EventHandlerFunc_t handlerPtr, void* contextPtr)
+{
+ int ret = 0;
+ ret = QL_Voice_Call_AddCommonStateHandler(h_voice, (QL_VoiceCall_CommonStateHandlerFunc_t)ql_voice_call_ind_func);
+ if(ret < 0)
+ {
+ printf("QL_Voice_Call_AddCommonStateHandler FAIL. ret:%d\n",ret);
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+
+ return ret;
+}
+
+/*
+ Phone call.
+ -call_num : dst phone number
+*/
+QL_VOICE_ERROR_CODE ql_voice_call_start(char* call_num)
+{
+ int ret = 0;
+
+ ret = QL_Voice_Call_Start(h_voice, 0, call_num, NULL);
+ if(ret)
+ {
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+ return ret;
+}
+
+
+/*
+ Put through.
+*/
+QL_VOICE_ERROR_CODE ql_voice_call_answer()
+{
+ int ret = 0;
+ ret = QL_Voice_Call_Answer(h_voice, 0);
+ if(ret)
+ {
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+ return ret;
+}
+QL_VOICE_ERROR_CODE ql_voice_auto_answer(int seconds)
+{
+ int ret = 0;
+
+ ret = QL_Voice_Call_SetAutoAnswer(h_voice, E_QL_MCM_VOICE_AUTO_ANSWER_ENABLE, 6000);
+ if(ret)
+ {
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+ return ret;
+}
+
+/*
+ Hang up.
+*/
+QL_VOICE_ERROR_CODE ql_voice_call_end()
+{
+ int ret = 0;
+ ret = QL_Voice_Call_End(h_voice, 0);
+ if(ret)
+ {
+ ret = QL_VOICE_GENERIC_FAILURE;
+ }
+
+ return ret;
+}
+
+
+/* hold the voice */
+QL_VOICE_ERROR_CODE ql_voice_call_hold()
+{
+ int ret = 0;
+ QL_Voice_Call_Hold(h_voice);
+
+ return ret;
+}
+
+/* unhold the voice */
+QL_VOICE_ERROR_CODE ql_voice_call_unhold()
+{
+ int ret = 0;
+
+ QL_Voice_Call_UnHold(h_voice);
+
+ return ret;
+}
+