data_call: add T108 data_call api

Change-Id: I382cbcccc416233fca7a267db67b0d0238dc56eb
diff --git a/mbtk/include/lynq/lynq-qser-data.h b/mbtk/include/lynq/lynq-qser-data.h
index 0d85f67..1140e86 100755
--- a/mbtk/include/lynq/lynq-qser-data.h
+++ b/mbtk/include/lynq/lynq-qser-data.h
@@ -180,6 +180,18 @@
 extern int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err);
 
 /**
+ * Starts a data call. If profile index is zero, it will call CDMA profile.
+ *
+ * @param [in] data_call        The data call parameters
+ * @param [out] error           Error code returned by data call 
+ *
+ * @return 
+ *   On success, 0 is returned.  On error, -1 is returned.
+ * 
+ */
+extern int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err);
+
+/**
  * Stop a data call.
  *
  * @param [in] profile_idx      UMTS/CDMA profile ID
diff --git a/mbtk/lynq_lib/Makefile b/mbtk/lynq_lib/Makefile
index fc5e2dd..b543be5 100755
--- a/mbtk/lynq_lib/Makefile
+++ b/mbtk/lynq_lib/Makefile
@@ -7,7 +7,7 @@
 
 LIB_DIR +=
 
-LIBS += -llog -lmbtk_lib
+LIBS += -llog -lmbtk_lib -lprop2uci
 ifeq ($(BUILD_PLATFORM), asr1806)
 LIBS += -lmbtk_audio_lib
 endif
diff --git a/mbtk/lynq_lib/src/lynq_data_call.c b/mbtk/lynq_lib/src/lynq_data_call.c
index d65c3b6..88f2074 100755
--- a/mbtk/lynq_lib/src/lynq_data_call.c
+++ b/mbtk/lynq_lib/src/lynq_data_call.c
@@ -2,15 +2,20 @@
 #include "mbtk_type.h"
 #include "mbtk_info_api.h"
 
+#include <pthread.h>
+#include <cutils/properties.h>
+#include <string.h>
 /****************************DEFINE***************************************/
 #define QSER_RESULT_SUCCESS 0
 #define QSER_RESULT_FAIL -1
 
+#define QSER_APN_NUM 8
 //default  range: 0 - 7
 //AT+CGACT range: 1 - 8
 //1 default IDX, 8 IMS IDX
 #define QSER_PROFILE_IDX_MIN 1
 #define QSER_PROFILE_IDX_MAX 6
+
 /****************************DEFINE***************************************/
 
 /****************************VARIABLE***************************************/
@@ -18,10 +23,45 @@
 int qser_info_handle_num = 0;
 static bool inited = FALSE;
 static qser_data_call_evt_cb_t qser_net_status_cb = NULL;
-static qser_apn_info_s qser_apn_info[8] = {0};
+static qser_apn_info_s qser_apn_info[QSER_APN_NUM] = {0};
+static bool qser_apn_info_state[QSER_APN_NUM] = {0};
+static char qser_apn_add_save_state[QSER_APN_NUM + 1] = {0};
+static qser_data_call_s qser_data_backup;
+int now_idx = 0;
 /****************************VARIABLE***************************************/
 
 /******************************FUNC*****************************************/
+char qser_get_apn_profile_idx(void)
+{
+    char i = 0;
+    for(i = QSER_PROFILE_IDX_MIN; i < 8; i++)
+    {
+        if(qser_apn_info_state[i] == FALSE)
+        {
+            return i;
+        }
+    }
+
+    return i;
+}
+
+int qser_check_profile_idx(unsigned char profile_idx)
+{
+    if(profile_idx < QSER_PROFILE_IDX_MIN || profile_idx > QSER_PROFILE_IDX_MAX)
+    {
+        LOGE("[qser_data_call] IDX range error.");
+        return QSER_RESULT_FAIL;
+    }
+    
+    if(qser_apn_info_state[profile_idx] != TRUE)
+    {
+        LOGE("[qser_data_call] profile_idx is not exist.");
+        return QSER_RESULT_FAIL;
+    }
+
+    return QSER_RESULT_SUCCESS;
+}
+
 int qser_apn_info_param_convert(int profile_idx, qser_apn_info_s *new_apn, mbtk_apn_info_t *old_apn)
 {
     if(new_apn == NULL || old_apn == NULL)
@@ -147,9 +187,40 @@
 
     if(qser_net_status_cb != NULL)
     {
-        //
+        qser_data_call_state_s state = {0};
+        state.profile_idx = now_idx;
+        state.ip_family = qser_apn_info[now_idx].pdp_type;
+        if((*net_data > 100 && *net_data < 200) || *net_data == 1)
+        {
+            state.state = QSER_DATA_CALL_CONNECTED;
+            state.err = QSER_DATA_CALL_ERROR_NONE;
+        }
+        else if(*net_data > 200)
+        {
+            state.state = QSER_DATA_CALL_DISCONNECTED;
+            state.err = QSER_DATA_CALL_ERROR_NONE;
+        }
+        else
+        {
+            return;
+        }
+
+        qser_net_status_cb(&state);
     }
 }
+
+static void* data_call_async_thread(void* arg)
+{
+    qser_data_call_error_e err;
+    int ret = qser_data_call_start(&qser_data_backup, &err);
+    if(ret != QSER_RESULT_SUCCESS)
+    {
+        LOGE("[qser_data_call] qser_data_call_start() fail.");
+    }
+
+    return NULL;
+}
+
 /******************************FUNC*****************************************/
 
 /****************************API***************************************/
@@ -182,6 +253,43 @@
     }
     qser_net_status_cb = evt_cb;
 
+    property_get("persist.qser.datacall.apn", qser_apn_add_save_state, "00000000");
+    LOGE("[qser_data_call] qser_apn_add_save_state = %s", qser_apn_add_save_state);
+    mbtk_apn_info_t apns[10] = {0};
+    int apn_num = 10;
+    char qser_apn_type[32] = {0};
+    int ret = mbtk_apn_get(qser_info_handle, &apn_num, apns);
+    if(ret != 0)
+    {
+        LOGE("[qser_data_call] 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;
+            for(i = 0; i < apn_num; i++)
+            {
+                if(qser_apn_add_save_state[apns[i].cid - 1] == '0')
+                {
+                    LOGE("[qser_data_call] idx no open.");
+                    continue;
+                }
+                if(qser_apn_info_param_convert(apns[i].cid - 1, &qser_apn_info[apns[i].cid - 1], &apns[i]) != 0)
+                {
+                    LOGE("[qser_data_call] qser_apn_info_param_convert fail");
+                    return QSER_RESULT_FAIL;
+                }
+                else
+                {
+                    qser_apn_info_state[apns[i].cid - 1] = TRUE;
+                    sprintf(qser_apn_type, "persist.qser.apn.type%d", apns[i].cid - 1);
+                    property_get(qser_apn_type, qser_apn_info[apns[i].cid - 1].apn_type, NULL);
+                }
+            }
+        }
+    }
     LOGE("[qser_data_call] mbtk_info_handle_get() success.");
     return QSER_RESULT_SUCCESS;
 }
@@ -237,9 +345,9 @@
         return QSER_RESULT_FAIL;
     }
 
-    if(data_call->profile_idx < QSER_PROFILE_IDX_MIN || data_call->profile_idx > QSER_PROFILE_IDX_MAX)
+    if(qser_check_profile_idx(data_call->profile_idx) < 0)
     {
-        LOGE("[qser_data_call] IDX range error.");
+        LOGE("[qser_data_call] profile_idx is invalid.");
         *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
         return QSER_RESULT_FAIL;
     }
@@ -256,6 +364,59 @@
     {
         *err = QSER_DATA_CALL_ERROR_NONE;
     }
+
+    now_idx = data_call->profile_idx;
+    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_call] 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_call] handle is NULL.");
+        *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_check_profile_idx(data_call->profile_idx) < 0)
+    {
+        LOGE("[qser_data_call] profile_idx is invalid.");
+        *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+        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_call] pthread_attr_setdetachstate() fail.");
+        *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+        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, NULL))
+    {
+        LOGE("[qser_data_call] pthread_create() fail.");
+        *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
+        return QSER_RESULT_FAIL;
+    }
+    pthread_attr_destroy(&thread_attr);
+    now_idx = data_call->profile_idx;
+    
     return QSER_RESULT_SUCCESS;
 }
 
@@ -277,9 +438,9 @@
         return QSER_RESULT_FAIL;
     }
 
-    if(profile_idx < QSER_PROFILE_IDX_MIN || profile_idx > QSER_PROFILE_IDX_MAX)
+    if(qser_check_profile_idx(profile_idx) < 0)
     {
-        LOGE("[qser_data_call] IDX range error.");
+        LOGE("[qser_data_call] profile_idx is invalid.");
         *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
         return QSER_RESULT_FAIL;
     }
@@ -296,7 +457,8 @@
     {
         *err = QSER_DATA_CALL_ERROR_NONE;
     }
-    
+
+    now_idx = 0;
     return QSER_RESULT_SUCCESS;
 }
 
@@ -325,9 +487,9 @@
         return QSER_RESULT_FAIL;
     }
 
-    if(profile_idx < QSER_PROFILE_IDX_MIN || profile_idx > QSER_PROFILE_IDX_MAX)
+    if(qser_check_profile_idx(profile_idx) < 0)
     {
-        LOGE("[qser_data_call] IDX range error.");
+        LOGE("[qser_data_call] profile_idx is invalid.");
         *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
         return QSER_RESULT_FAIL;
     }
@@ -438,9 +600,9 @@
         return QSER_RESULT_FAIL;
     }
 
-    if(apn->profile_idx < QSER_PROFILE_IDX_MIN || apn->profile_idx > QSER_PROFILE_IDX_MAX)
+    if(qser_check_profile_idx(apn->profile_idx) < 0)
     {
-        LOGE("[qser_data_call] IDX range error.");
+        LOGE("[qser_data_call] profile_idx is invalid.");
         return QSER_RESULT_FAIL;
     }
 
@@ -450,8 +612,15 @@
         return QSER_RESULT_FAIL;
     }
 
+    if(memcmp(apn->apn_type, "iot_default", strlen("iot_default")) == 0)
+    {
+        LOGE("[qser_data_call] iot_default is exist.");
+        return QSER_RESULT_FAIL;
+    }
+
     int ret = -1;
     char mbtk_auth[32]={0};
+    char qser_apn_type[32] = {0};
     mbtk_ip_type_enum pdp_type = MBTK_IP_TYPE_IPV4V6;
     
     if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
@@ -508,7 +677,7 @@
     {
         LOGE("[qser_data_call] setapn: %d, %d, %s, NULL, NULL, %s, %s.",apn->profile_idx, pdp_type, apn->apn_name, apn->username, apn->password, mbtk_auth, apn->apn_type);
     }
-
+    
     ret = mbtk_apn_set(qser_info_handle, apn->profile_idx + 1, pdp_type, apn->apn_name, apn->username, apn->password, mbtk_auth);
     if(ret < 0)
     {
@@ -516,6 +685,8 @@
         return QSER_RESULT_FAIL;
     }
 
+    sprintf(qser_apn_type, "persist.qser.apn.type%d", apn->profile_idx);
+    property_set(qser_apn_type, apn->apn_type);
     memcpy(&qser_apn_info[apn->profile_idx], apn, sizeof(qser_apn_info_s));
     return QSER_RESULT_SUCCESS;
 }
@@ -536,9 +707,9 @@
         return QSER_RESULT_FAIL;
     }
 
-    if(profile_idx < QSER_PROFILE_IDX_MIN || profile_idx > QSER_PROFILE_IDX_MAX)
+    if(qser_check_profile_idx(profile_idx) < 0)
     {
-        LOGE("[qser_data_call] IDX range error.");
+        LOGE("[qser_data_call] profile_idx is invalid.");
         return QSER_RESULT_FAIL;
     }
 
@@ -580,17 +751,71 @@
 
 int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
 {
-    UNUSED(apn);
-    UNUSED(profile_idx);
+    //UNUSED(apn);
+    //UNUSED(profile_idx);
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+    
+    if(apn == NULL)
+    {
+        LOGE("[qser_data_call] apn param is NULL.");
+        return QSER_RESULT_FAIL;
+    }
 
-    return 0;
+    int ret = 0;
+    char idx = qser_get_apn_profile_idx();
+    if(idx >= 8)
+    {
+        LOGE("[qser_data_call] idx is full.");
+        return QSER_RESULT_FAIL;
+    }
+    else
+    {
+        qser_apn_info_state[idx] = TRUE;
+        qser_apn_info_s set_apn;
+        set_apn.profile_idx = idx;
+        set_apn.pdp_type = apn->pdp_type;
+        set_apn.auth_proto = apn->auth_proto;
+        memcpy(set_apn.apn_name, apn->apn_name, QSER_APN_NAME_SIZE);
+        memcpy(set_apn.username, apn->username, QSER_APN_USERNAME_SIZE);
+        memcpy(set_apn.password, apn->password, QSER_APN_PASSWORD_SIZE);
+        memcpy(set_apn.apn_type, apn->apn_type, QSER_APN_NAME_SIZE);
+        ret = qser_apn_set(&set_apn);
+        if(ret != 0)
+        {
+            LOGE("[qser_data_call] qser_apn_set fail.");
+            qser_apn_info_state[idx] = FALSE;
+            return QSER_RESULT_FAIL;
+        }
+        *profile_idx = idx;
+        qser_apn_add_save_state[idx] = '1';
+        property_set("persist.qser.datacall.apn", qser_apn_add_save_state);
+    }
+    return QSER_RESULT_SUCCESS;
 }
 
 int qser_apn_del(unsigned char profile_idx)
 {
-    UNUSED(profile_idx);
+    //UNUSED(profile_idx);
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
 
-    return 0;
+    if(qser_check_profile_idx(profile_idx) < 0)
+    {
+        LOGE("[qser_data_call] profile_idx is invalid.");
+        return QSER_RESULT_FAIL;
+    }
+
+    qser_apn_info_state[profile_idx] = FALSE;
+    qser_apn_add_save_state[profile_idx] = '0';
+    property_set("persist.qser.datacall.apn", qser_apn_add_save_state);
+    return QSER_RESULT_SUCCESS;
 }
 
 int qser_apn_get_list(qser_apn_info_list_s *apn_list)
@@ -609,6 +834,8 @@
         return QSER_RESULT_FAIL;
     }
 
+    property_get("persist.qser.datacall.apn", qser_apn_add_save_state, "00000000");
+    LOGE("[qser_data_call] qser_apn_add_save_state = %s", qser_apn_add_save_state);
     mbtk_apn_info_t apns[10] = {0};
     int apn_num = 10;
     int ret = mbtk_apn_get(qser_info_handle, &apn_num, apns);
@@ -622,15 +849,21 @@
         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_add_save_state[apns[i].cid - 1] == '0')
+                {
+                    LOGE("[qser_data_call] idx no open.");
+                    continue;
+                }
                 if(qser_apn_info_param_convert(apns[i].cid - 1, &apn_list->apn[i], &apns[i]) != 0)
                 {
                     LOGE("[qser_data_call] qser_apn_info_param_convert fail");
                     return QSER_RESULT_FAIL;
                 }
+                apn_list->cnt++;
             }
-            apn_list->cnt = apn_num;
         }
         else if(apn_num > QSER_APN_MAX_LIST)
         {
diff --git a/mbtk/test/asr1806/qser_data_call_test.c b/mbtk/test/asr1806/qser_data_call_test.c
new file mode 100644
index 0000000..5d6ba59
--- /dev/null
+++ b/mbtk/test/asr1806/qser_data_call_test.c
@@ -0,0 +1,490 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <sys/epoll.h>
+#include <string.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "lynq-qser-data.h"
+#include "mbtk_log.h"
+
+static void help()
+{
+    printf("apn_get <cid> : Get current apns.\n");
+    printf("apn_del <cid> : del apns.\n");
+    printf("apn_list <cid> : list apns.\n");
+    printf("apn_set <cid> <0/1/2/3> <apn> <apn_type> [<user> <pass> <(0 1)/2/3>] : \n");
+    printf("Set apn (1-6) (IPV4/PPP/IPV6/IPV4V6) (150) (iot_net_i) (127) (127) (NONE/PAP/CHAP).\n");
+    printf("apn_add <0/1/2/3> <apn> <apn_type> [<user> <pass> <(0 1)/2/3>] : \n");
+    printf("data_call <0/1/2/3> <cid> <type> <re-con> <user> <pass>: Stop/Start/State data call.\n");
+    printf("data_call <0/1/2/3> <cid> <IPV4/IPV6/IPV4V6> [<0/1> <user> <pass>].\n");
+}
+
+static int proc_exit()
+{
+    qser_data_call_destroy();
+    return 0;
+}
+
+static void sig_process(int sig)
+{
+    LOGI("I got signal %d\n", sig);
+    switch(sig)
+    {
+        case SIGINT: // Ctrl + C
+        {
+            LOGI("Exit by SIGINT.\n");
+            proc_exit();
+            exit(0);
+        }
+        case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件)
+        {
+            LOGI("Exit by SIGQUIT.\n");
+            proc_exit();
+            exit(0);
+        }
+        case SIGTERM:// 默认kill   (同 SIGKILL ,但 SIGKILL 不可捕获)
+        {
+            LOGI("Exit by SIGTERM.\n");
+            proc_exit();
+            exit(0);
+        }
+        case SIGTSTP:// Ctrl + Z (同 SIGSTOP ,但 SIGSTOP 不可捕获)
+        {
+            LOGI("Exit by SIGTSTP.\n");
+            exit(0);
+        }
+        case SIGSEGV: // 如空指针
+        {
+            LOGI("Exit by SIGSEGV.\n");
+            exit(0);
+        }
+        default:
+        {
+            LOGI("Unknown sig:%d\n",sig);
+            break;
+        }
+    }
+}
+
+static void data_call_status_cb(qser_data_call_state_s *state)
+{
+    printf("entry data_call_status_cb\n");
+    if(state == NULL)
+    {
+        printf("state is NULL\n");
+    }
+    printf("DATA_DEMO_CALL_BACK: profile_idx=%d, name=%s, ip_family=%d, state=%d, error=%d\n"
+        , state->profile_idx, state->name, state->ip_family, state->state, state->err);
+}
+
+int main(int argc, char *argv[])
+{
+    signal(SIGINT, sig_process);
+    signal(SIGQUIT, sig_process);
+    signal(SIGTERM, sig_process);
+    //signal(SIGTSTP, sig_process);
+    //signal(SIGSEGV, sig_process);
+
+    mbtk_log_init(NULL,"MBTK_QSER_DATA_CALL_TEST");
+
+    //test2(0, "192.168.1.198");
+    //test2(1, "2409:8162:140:cd3c:1:2:1494:72ba");
+    //test2(1, "254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239");
+    //test2(1, "2400:3200::1");
+
+    int err = qser_data_call_init(data_call_status_cb);
+    if(err)
+    {
+        printf("qser_data_call_init fail.");
+        return -1;
+    }
+
+    printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n");
+    char cmd[100];
+    while(1)
+    {
+        memset(cmd, 0, 100);
+        if(fgets(cmd, 100, stdin))
+        {
+            char *ptr = cmd + strlen(cmd) - 1;
+            while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
+            {
+                *ptr-- = '\0';
+            }
+
+            if(!strncasecmp(cmd, "apn", 3)){
+                if(!strncasecmp(cmd, "apn_get", 7)) { // Get apn
+                    char *ptr = strstr(cmd, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    int cid = atoi(ptr);
+                    qser_apn_info_s qser_apn = {0};
+                    err = qser_apn_get(cid, &qser_apn);
+                    if(err) {
+                        printf("Error : %d\n", err);
+                    } else {
+                        printf("APN : %d, %d, %s, %s, %s, %d, %s.\n",qser_apn.profile_idx, qser_apn.pdp_type, qser_apn.apn_name, qser_apn.username, qser_apn.password, qser_apn.auth_proto, qser_apn.apn_type);
+                    }
+                } else if(!strncasecmp(cmd, "apn_list", 8)){
+                    qser_apn_info_list_s apn_list = {0};
+                    err = qser_apn_get_list(&apn_list);
+                    if(err)
+                    {
+                        printf("Error : %d\n", err);
+                    }
+                    else
+                    {
+                        printf("cnt: %d.\n", apn_list.cnt);
+                        for(int i = 0; i < apn_list.cnt; i++)
+                        {
+                            printf("APN : %d, %d, %s, %s, %s, %d, %s.\n", apn_list.apn[i].profile_idx, apn_list.apn[i].pdp_type, apn_list.apn[i].apn_name, apn_list.apn[i].username, apn_list.apn[i].password, apn_list.apn[i].auth_proto, apn_list.apn[i].apn_type);
+                        }
+                    }
+                } else if(!strncasecmp(cmd, "apn_del", 7)){
+                    char *ptr = strstr(cmd, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    char profile_idx = atoi(ptr);
+                    err = qser_apn_del(profile_idx);
+                    if(err)
+                    {
+                        printf("Error : %d\n", err);
+                    }
+                    else
+                    {
+                        printf("APN set success.\n");
+                    }
+                } else if(!strncasecmp(cmd, "apn_add", 7)){
+                    char qser_idx = 0;
+                    qser_apn_add_s qser_apn = {0};
+                    char *ptr = strstr(cmd, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    qser_apn.pdp_type = (qser_apn_pdp_type_e)atoi(ptr);
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_apn.apn_name, ptr, strlen(ptr));
+                    char *tmp = qser_apn.apn_name;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_apn.apn_type, ptr, strlen(ptr));
+                    tmp = qser_apn.apn_type;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+                    
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL) {
+                        err = qser_apn_add(&qser_apn, &qser_idx);
+                    } else {
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        memcpy(qser_apn.username, ptr, strlen(ptr));
+                        tmp = qser_apn.username;
+                        while(*tmp) {
+                            if(*tmp == ' ') {
+                                *tmp = '\0';
+                                break;
+                            }
+                            tmp++;
+                        }
+
+                        ptr = strstr(ptr, " ");
+                        if(ptr == NULL)
+                            continue;
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        memcpy(qser_apn.password, ptr, strlen(ptr));
+                        tmp = qser_apn.password;
+                        while(*tmp) {
+                            if(*tmp == ' ') {
+                                *tmp = '\0';
+                                break;
+                            }
+                            tmp++;
+                        }
+
+                        ptr = strstr(ptr, " ");
+                        if(ptr == NULL)
+                            continue;
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        qser_apn.auth_proto = (qser_apn_auth_proto_e)atoi(ptr);
+
+                        err = qser_apn_add(&qser_apn, &qser_idx);
+                    }
+                    if(err) {
+                        printf("Error : %d\n", err);
+                    } else {
+                        printf("APN set success. get idx = [%d]\n", qser_idx);
+                    }
+                }
+                else { // apn <cid> <0/1/2> <apn> [<user> <pass> <auth>]
+                    qser_apn_info_s qser_apn = {0};
+                    char *ptr = strstr(cmd, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    qser_apn.profile_idx = atoi(ptr);
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    qser_apn.pdp_type = (qser_apn_pdp_type_e)atoi(ptr);
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_apn.apn_name, ptr, strlen(ptr));
+                    char *tmp = qser_apn.apn_name;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_apn.apn_type, ptr, strlen(ptr));
+                    tmp = qser_apn.apn_type;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+                    
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL) {
+                       err = qser_apn_set(&qser_apn);
+                    } else {
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        memcpy(qser_apn.username, ptr, strlen(ptr));
+                        tmp = qser_apn.username;
+                        while(*tmp) {
+                            if(*tmp == ' ') {
+                                *tmp = '\0';
+                                break;
+                            }
+                            tmp++;
+                        }
+
+                        ptr = strstr(ptr, " ");
+                        if(ptr == NULL)
+                            continue;
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        memcpy(qser_apn.password, ptr, strlen(ptr));
+                        tmp = qser_apn.password;
+                        while(*tmp) {
+                            if(*tmp == ' ') {
+                                *tmp = '\0';
+                                break;
+                            }
+                            tmp++;
+                        }
+
+                        ptr = strstr(ptr, " ");
+                        if(ptr == NULL)
+                            continue;
+                        while(*ptr != '\0' && *ptr == ' ')
+                            ptr++;
+                        qser_apn.auth_proto = (qser_apn_auth_proto_e)atoi(ptr);
+
+                        err = qser_apn_set(&qser_apn);
+                    }
+                    if(err) {
+                        printf("Error : %d\n", err);
+                    } else {
+                        printf("APN set success\n");
+                    }
+                }
+            } else if(!strncasecmp(cmd, "data_call", 9)){ // data_call <0/1/2> <cid> <timeout>
+                // data_call <0/1/2> <cid> <type> <re-con> <user> <pass>
+                qser_data_call_s qser_data_call = {0};
+                char *ptr = strstr(cmd, " ");
+                if(ptr == NULL)
+                    continue;
+                while(*ptr != '\0' && *ptr == ' ')
+                    ptr++;
+                int type = atoi(ptr);
+
+                ptr = strstr(ptr, " ");
+                if(ptr == NULL)
+                    continue;
+                while(*ptr != '\0' && *ptr == ' ')
+                    ptr++;
+                int cid = atoi(ptr);
+
+                ptr = strstr(ptr, " ");
+                if(ptr == NULL)
+                    continue;
+                while(*ptr != '\0' && *ptr == ' ')
+                    ptr++;
+                qser_data_call_ip_family_e ip_type = atoi(ptr);
+
+                ptr = strstr(ptr, " ");
+                if(ptr == NULL)
+                {
+                    
+                }
+                else
+                {
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    qser_data_call.reconnect = atoi(ptr);
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_data_call.cdma_username, ptr, strlen(ptr));
+                    char *tmp = qser_data_call.cdma_username;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+
+                    ptr = strstr(ptr, " ");
+                    if(ptr == NULL)
+                        continue;
+                    while(*ptr != '\0' && *ptr == ' ')
+                        ptr++;
+                    memcpy(qser_data_call.cdma_password, ptr, strlen(ptr));
+                    tmp = qser_data_call.cdma_password;
+                    while(*tmp) {
+                        if(*tmp == ' ') {
+                            *tmp = '\0';
+                            break;
+                        }
+                        tmp++;
+                    }
+                }
+#if 1
+                qser_data_call_error_e qser_err;
+                switch (type)
+                {
+                    case 0:
+                        err = qser_data_call_stop(cid, ip_type, &qser_err);
+                        break;
+                    case 1:
+                        qser_data_call.profile_idx = cid;
+                        qser_data_call.ip_family = ip_type;
+                        err = qser_data_call_start(&qser_data_call, &qser_err);
+                        break;
+                    case 2: {
+                        qser_data_call_info_s info;
+                        err = qser_data_call_info_get(cid, ip_type, &info, &qser_err);
+                        if(!err) {
+                            printf("cid : %d, ip_type : %d\n", info.profile_idx, info.ip_family);
+                            if(info.v4.state) {
+                                printf("%s: %s, %s, %s\n", info.v4.name, inet_ntoa(info.v4.addr.ip), inet_ntoa(info.v4.addr.pri_dns), inet_ntoa(info.v4.addr.sec_dns));
+                            } else {
+                                printf("IPV4 not available.\n");
+                            }
+
+                            if(info.v6.state) {
+                                char IP_buf[128] = {0};
+                                char pri_dns_buf[128] = {0};
+                                char sec_dns_buf[128] = {0};
+                                ipv6_2_str(&(info.v6.addr.ip), IP_buf);
+                                ipv6_2_str(&(info.v6.addr.pri_dns), pri_dns_buf);
+                                ipv6_2_str(&(info.v6.addr.sec_dns), sec_dns_buf);
+                                printf("%s: %s, %s, %s\n", info.v6.name, IP_buf, pri_dns_buf, sec_dns_buf);
+                            } else {
+                                printf("IPV6 not available.\n");
+                            }
+                        }
+                        break;
+                    }
+                    case 3:
+                    {
+                        qser_data_call.profile_idx = cid;
+                        qser_data_call.ip_family = ip_type;
+                        err = qser_data_call_start_async(&qser_data_call, &qser_err);
+                        break;
+                    }
+                    default:
+                        printf("Type error:%d\n", type);
+                        break;
+                }
+#endif
+                printf("qser_err: %d\n", qser_err);
+                if(err) {
+                    printf("Error : %d\n", err);
+                } else {
+                    printf("DATA_CALL success\n");
+                }
+            }
+            else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) {
+                help();
+            } else if(!strcasecmp(cmd, "q")) {
+                break;
+            } else {
+                printf("\n");
+            }
+        }
+    }
+
+    proc_exit();
+
+    LOGI("Client exec complete.");
+#if 1
+    while(1)
+    {
+        sleep(1000 * 365 * 24 * 60 * 60);
+    }
+#else
+    sleep(1);
+#endif
+    return 0;
+}
+