sim: add sim api

Change-Id: Idc822bc23dc498e78241e5f8e5cca8e6b00eb7ec
diff --git a/mbtk/include/lynq/lynq_qser_sim.h b/mbtk/include/lynq/lynq_qser_sim.h
index bf2782a..e1cada7 100755
--- a/mbtk/include/lynq/lynq_qser_sim.h
+++ b/mbtk/include/lynq/lynq_qser_sim.h
@@ -37,7 +37,7 @@
     QSER_SIM_APP_TYPE_T         e_app;      /**< Indicates the type of the application. */
 }QSER_SIM_APP_ID_INFO_T;  /* Type */
 
-#define QSER_SIM_PIN_LEN_MAX  8   /**  Maximum length of PIN data. */
+#define QSER_SIM_PIN_LEN_MAX  8 + 1   /**  Maximum length of PIN data. */
 
 typedef enum
 {
@@ -376,7 +376,98 @@
     QSER_SIM_CARD_STATUS_INFO_T   *pt_info   ///< [OUT] Cart status infor output
 );
 
+/*===========================================================================
 
+  FUNCTION:  qser_sim_getimei
+
+===========================================================================*/
+/*
+    @brief
+    get imei
+
+    @return
+    int
+*/
+/*=========================================================================*/
+int qser_sim_getimei
+(
+    sim_client_handle_type h_sim,
+    char *imei
+);
+
+/*===========================================================================
+
+  FUNCTION:  qser_get_imei_and_sv
+
+===========================================================================*/
+/*
+    @brief
+    get imei and sv
+
+    @return
+    int
+*/
+/*=========================================================================*/
+int qser_get_imei_and_sv
+(
+    sim_client_handle_type h_sim,
+    char *imei, char*sv
+);
+
+/*===========================================================================
+
+  FUNCTION:  qser_reset_modem
+
+===========================================================================*/
+/*
+    @brief
+    reboot modem
+
+    @return
+    int
+*/
+/*=========================================================================*/
+int qser_reset_modem
+(
+    sim_client_handle_type h_sim
+);
+
+/*===========================================================================
+
+  FUNCTION:  qser_reset_modem
+
+===========================================================================*/
+/*
+    @brief
+    reboot modem
+
+    @return
+    int
+*/
+/*=========================================================================*/
+int qser_get_version
+(
+    sim_client_handle_type h_sim,
+    char *buf
+);
+
+/*===========================================================================
+
+  FUNCTION:  qser_reset_modem
+
+===========================================================================*/
+/*
+    @brief
+    reboot modem
+
+    @return
+    int
+*/
+/*=========================================================================*/
+int qser_reset_sim
+(
+    sim_client_handle_type h_sim
+);
 #ifdef __cplusplus
 }
 #endif
diff --git a/mbtk/lynq_lib/src/lynq_sim.c b/mbtk/lynq_lib/src/lynq_sim.c
index 6bb6ed1..a086b40 100755
--- a/mbtk/lynq_lib/src/lynq_sim.c
+++ b/mbtk/lynq_lib/src/lynq_sim.c
@@ -1,96 +1,643 @@
 #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***************************************/
+
+/****************************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;
+/****************************VARIABLE***************************************/
+
+/******************************FUNC*****************************************/
+/******************************FUNC*****************************************/
+
+/****************************API***************************************/
 int qser_sim_client_init(sim_client_handle_type *ph_sim)
 {
-    UNUSED(ph_sim);
+    //UNUSED(ph_sim);
+    if(ph_sim == NULL)
+    {
+        LOGE("[qser_data_call] ph_sim is NULL.");
+        return QSER_RESULT_FAIL;
+    }
 
-    return 0;
+    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_call] 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_data_call] 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(h_sim);
     UNUSED(pt_info);
-    UNUSED(imsi);
-    UNUSED(imsiLen);
+    //UNUSED(imsi);
+    //UNUSED(imsiLen);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(imsi == NULL || imsiLen < 15)
+    {
+        LOGE("[qser_data_call] imsi is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    memset(imsi,0,imsiLen);
+    int err = mbtk_imsi_get(qser_info_handle, imsi);
+    if(err)
+    {
+        LOGE("[qser_data_call] mbtk_imsi_get is fail.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(strlen(imsi) > imsiLen)
+    {
+        LOGE("[qser_data_call] 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(h_sim);
     UNUSED(simId);
-    UNUSED(iccid);
-    UNUSED(iccidLen);
+    //UNUSED(iccid);
+    //UNUSED(iccidLen);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(iccid == NULL || iccidLen < 15)
+    {
+        LOGE("[qser_data_call] iccid is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    memset(iccid, 0, iccidLen);
+    int err = mbtk_iccid_get(qser_info_handle, iccid);
+    if(err)
+    {
+        LOGE("[qser_data_call] mbtk_iccid_get is fail.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(strlen(iccid) > iccidLen)
+    {
+        LOGE("[qser_data_call] 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(h_sim);
     UNUSED(pt_info);
-    UNUSED(phone_num);
-    UNUSED(phoneLen);
+    //UNUSED(phone_num);
+    //UNUSED(phoneLen);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(phone_num == NULL || phoneLen < 11)
+    {
+        LOGE("[qser_data_call] 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_data_call] mbtk_phone_number_get is fail.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(strlen(phone_num) > phoneLen)
+    {
+        LOGE("[qser_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] pt_info is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    int err = mbtk_verify_pin(qser_info_handle, pt_info->pin_value);
+    if(err)
+    {
+        LOGE("[qser_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] 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_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] 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_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] 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_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] 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_data_call] 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);
+    //UNUSED(h_sim);
+    //UNUSED(simId);
+    //UNUSED(pt_info);
 
-    return 0;
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(pt_info == NULL)
+    {
+        LOGE("[qser_data_call] 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_data_call] mbtk_sim_state_get fail [err = %d].", err);
+        return QSER_RESULT_FAIL;
+    }
+    else
+    {
+        LOGE("[qser_data_call] 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_UNKNOWN;
+                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_UNKNOWN;
+                break;
+            case 4:                     //SIM PUK
+                pt_info->e_card_state = QSER_SIM_CARD_STATE_UNKNOWN;
+                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_data_call] 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_data_call] 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_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(imei == NULL)
+    {
+        LOGE("[qser_data_call] imei is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    int err = mbtk_imei_get(qser_info_handle, imei);
+    if(err)
+    {
+        LOGE("[qser_data_call] 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_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(imei == NULL || sv == NULL)
+    {
+        LOGE("[qser_data_call] param is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    int length = 0;
+    int err = mbtk_imei_get(qser_info_handle, imei);
+    if(err)
+    {
+        LOGE("[qser_data_call] mbtk_imei_get Error: %d\n", err);
+        return QSER_RESULT_FAIL;
+    }
+
+    length = strlen(imei);
+    memcpy(sv, imei, length);
+    memcpy(sv + length - 1, "01", 2);
+    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_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    mbtk_system_reboot(0);
+    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_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(buf == NULL)
+    {
+        LOGE("[qser_data_call] buf is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    int err = mbtk_version_get(qser_info_handle, buf);
+    if(err)
+    {
+        LOGE("[qser_data_call] 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_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+
+    if(qser_info_handle == NULL)
+    {
+        LOGE("[qser_data_call] handle is NULL.");
+        return QSER_RESULT_FAIL;
+    }
+
+    //mbtk_sim_power_set(0);
+    //sleep(1);
+    //mbtk_sim_power_set(1);
+    return QSER_RESULT_SUCCESS;
 }
 
 int qser_sim_client_deinit(sim_client_handle_type h_sim)
 {
-    UNUSED(h_sim);
+    //UNUSED(h_sim);
+    if(h_sim != qser_h_sim)
+    {
+        LOGE("[qser_data_call] h_sim is error.");
+        return QSER_RESULT_FAIL;
+    }
+    
+    if(qser_info_handle)
+    {
+        LOGE("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_call] mbtk_info_handle_free() fail.");
+                return QSER_RESULT_FAIL;
+            }
+            else
+            {
+                qser_info_handle_num = 0;
+                qser_info_handle = NULL;
+                inited = FALSE;
+            }
+        } 
+        else
+        {
+            qser_info_handle_num--;
+        }
+    }
+    else
+    {
+        LOGE("[qser_data_call] handle not inited.");
+        return QSER_RESULT_FAIL;
+    }
 
-    return 0;
+    return QSER_RESULT_SUCCESS;
 }
+/****************************API***************************************/
 
diff --git a/mbtk/test/asr1806/qser_sim_test.c b/mbtk/test/asr1806/qser_sim_test.c
new file mode 100644
index 0000000..d6478c4
--- /dev/null
+++ b/mbtk/test/asr1806/qser_sim_test.c
@@ -0,0 +1,441 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+#include"lynq_qser_sim.h"
+
+
+#define BUF_SIZE 32
+#define BUF_PIN 16
+#define VER_SIZE 128
+
+typedef uint32_t sim_client_handle_type;
+
+sim_client_handle_type  ph_sim = 2023;
+sim_client_handle_type  h_sim = 2023;
+int flag_init = 0;
+
+typedef struct
+{
+    int  cmdIdx;
+    const char *funcName;
+} st_api_test_case;
+    
+//for server test
+st_api_test_case at_api_testcases[] = 
+{
+    {0,   "qser_sim_init"},
+    {1,   "qser_get_imsi"},
+    {2,   "qser_get_iccid"},
+    {3,   "qser_get_phonenumber"},
+    {4,   "qser_verify_pin"},
+    {5,   "qser_change_pin"},
+    {6,   "qser_unlock_pin"},
+    {7,   "qser_enable_pin"},
+    {8,   "qser_disable_pin"},
+    {9,   "qser_get_sim_status"},
+    {10,   "qser_get_imei"},
+    {11,   "qser_get_imei_and_sv"},
+    {12,   "qser_reset_modem"},
+    {13,   "qser_get_version"},
+    {14,   "qser_reset_sim"},
+    {15,   "qser_deinit_sim"},
+    {-1,    NULL}
+};
+
+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);
+    }
+}
+
+int main(int argc, char const *argv[])
+{
+    int cmdIdx = 0;
+    int res    = 0;
+
+    print_help();
+    while(1)
+    {
+        printf("\nplease input cmd index(-1 exit): ");
+        scanf("%d", &cmdIdx);
+        if(cmdIdx == -1)
+        {
+            break;
+        }
+
+        switch(cmdIdx)
+        {
+            //"qser_sim_init"
+            case 0:
+            {
+                if(flag_init == 1)
+                {
+                   printf("init is already\n"); 
+                   break;
+                }
+                else{
+                    //int token;
+                    //printf("input token\n");
+                    //scanf("%d", &token);
+                    res = qser_sim_client_init(&h_sim);
+                    if(res == 0)
+                    {
+                        printf("Run qser_sim_client_init\n");
+                        flag_init = 1;
+                    }else{
+                        printf("qser_sim_client_init error\n");
+                    }
+ 
+                    break;
+                }
+            }
+    
+            //"qser_sim_getimsi"
+            case 1:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char imsi[BUF_SIZE] = {0};
+                    QSER_SIM_APP_ID_INFO_T pt_info;
+                    res = qser_sim_getimsi(h_sim, &pt_info, imsi, 32);
+                    if(res == 0)
+                    {
+                        printf("imsi is %s!!!\n",imsi);
+                    }else{
+                        printf("get imsi error, res = %d\n", res);
+                    }
+                }
+                break;
+            }
+
+            //"qser_get_iccid"
+            case 2:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char iccid[BUF_SIZE] = {0};
+                    res = qser_sim_geticcid(h_sim, QSER_SIM_SLOT_ID_1, iccid, 32);
+                    if(res == 0)
+                    {
+                        printf("get iccid success!!! iccid is %s\n",iccid);
+                    }else{
+                        printf("get iccid error, res = %d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_get_phonenumber
+            case 3:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char phonenumber[BUF_SIZE] = "";
+                    QSER_SIM_APP_ID_INFO_T pt_info;
+                    res = qser_sim_getphonenumber(h_sim, &pt_info, phonenumber, 32);
+                    if(res == 0)
+                    {
+                        printf("get phonenumber success!!! phonenumber is %s\n",phonenumber);
+                    }else{
+                        printf("get phonenumber error, res = %d\n", res);
+                    }
+                }
+                break;
+           }
+            //qser_verify_pin
+            case 4:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char pin[BUF_PIN] = {0};
+                    QSER_SIM_VERIFY_PIN_INFO_T pt_info;
+                    printf("input pin\n");
+                    scanf("%s", pin);
+                    strncpy(pt_info.pin_value, pin, BUF_PIN);
+                    printf("pin_value = %s , pin = %s\n", pt_info.pin_value, pin);
+                    pt_info.pin_value_len = strlen(pt_info.pin_value);
+                    
+                    res = qser_sim_verifypin(h_sim, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("verify pin success!!!\n");
+                    }else{
+                        printf("verify pin error, res = %d\n", res);
+                    }
+
+                }
+                break;
+            }
+            //qser_change_pin
+            case 5:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char old_pin[BUF_PIN] = {0};
+                    QSER_SIM_CHANGE_PIN_INFO_T pt_info;
+                    printf("input old pin\n");
+                    scanf("%s", old_pin);
+                    char new_pin[BUF_PIN] = {0};
+                    printf("input new pin\n");
+                    scanf("%s", new_pin);
+                    strncpy(pt_info.old_pin_value, old_pin, BUF_PIN);
+                    strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
+                    printf("pt_info.old_pin_value = %s, old_pin = %s\n", pt_info.old_pin_value, old_pin);
+                    printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
+                    pt_info.old_pin_value_len = strlen(pt_info.old_pin_value);
+                    pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
+
+                    res = qser_sim_changepin(h_sim, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("change pin success!!!\n");
+                    }else{
+                        printf("change pin error, res = %d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_unlock_pin
+            case 6:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char puk[BUF_PIN] = {0};
+                    QSER_SIM_UNBLOCK_PIN_INFO_T pt_info;
+                    printf("input  puk\n");
+                    scanf("%s", puk);
+                    char new_pin[BUF_PIN] = {0};
+                    printf("input new pin\n");
+                    scanf("%s", new_pin);
+
+                    strncpy(pt_info.puk_value, puk, BUF_PIN);
+                    strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
+                    printf("pt_info.puk_value = %s, puk = %s\n", pt_info.puk_value, puk);
+                    printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
+                    pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
+                    pt_info.puk_value_len = strlen(pt_info.puk_value);
+                        
+                    res = qser_sim_unblockpin(h_sim, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("unlock pin success!!!\n");
+                    }else{
+                        printf("unlock pin error, res = %d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_enable_pin
+            case 7:
+           {   
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char pin[BUF_PIN] = {0};
+                    QSER_SIM_ENABLE_PIN_INFO_T pt_info;
+                    printf("input pin\n");
+                    scanf("%s", pin);
+                    strncpy(pt_info.pin_value, pin, BUF_PIN);
+                    pt_info.pin_value_len = strlen(pt_info.pin_value);
+                    
+                    res = qser_sim_enablepin(h_sim, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("pin enabled!!!\n");
+                    }else{
+                        printf("pin enable error, res =%d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_disable_pin
+            case 8:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char pin[BUF_PIN] = {0};
+                    QSER_SIM_ENABLE_PIN_INFO_T pt_info;
+                    printf("input pin\n");
+                    scanf("%s", pin);
+                    strncpy(pt_info.pin_value, pin, BUF_PIN);
+                    pt_info.pin_value_len = strlen(pt_info.pin_value);
+                    
+                    res = qser_sim_disablepin(h_sim, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("pin disnabled!!!\n");
+                    }else{
+                        printf("pin disable error,res = %d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_get_sim_status   
+            case 9:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    QSER_SIM_CARD_STATUS_INFO_T pt_info;
+
+                    res = qser_sim_getcardstatus(h_sim, QSER_SIM_SLOT_ID_1, &pt_info);
+                    if(res == 0)
+                    {
+                        printf("state is %d !!!\n",pt_info.e_card_state);
+                    }else{
+                        printf("get imsi error,res = %d\n", res);
+                    }
+                }
+                break;
+            }
+            //qser_get_imei
+            case 10:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    char imei[BUF_SIZE]="";
+                    res = qser_sim_getimei(h_sim, imei);
+                    if(res == 0)
+                    {
+                        printf("get imei success!!! imei = %s\n", imei);
+                    }else{
+                        printf("get imei error, res = %d\n", res);
+                    }
+                }
+                //flag_init = 0;
+                break;
+            }
+            //qser_get_imei_and_sv
+            case 11:
+            {
+                char imei[BUF_SIZE]="";
+                char sv[BUF_SIZE]="";
+
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    res = qser_get_imei_and_sv(h_sim, imei, sv);
+                    if(res == 0)
+                    {
+                        printf("get imei and sv success!!!imei = %s sv = %s\n", imei, sv);
+                    }else{
+                        printf("get imei and sv error, res = %d\n", res);
+                    }
+                }
+                //flag_init = 0;
+                break;
+            }
+            //qser_reset_modem
+            case 12:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    res = qser_reset_modem(h_sim);
+                    if(res == 0)
+                    {
+                        printf("reset modem success!!!\n");
+                    }else{
+                        printf("reset modem error, res = %d\n", res);
+                    }
+                }
+                //flag_init = 0;
+                break;
+            }
+            //qser_get_version
+            case 13:
+            {
+                char buf[VER_SIZE]="";
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    res = qser_get_version(h_sim, buf);
+                    if(res == 0)
+                    {
+                        printf("get version success!!! ver = %s\n", buf);
+                    }else{
+                        printf("get version error, res = %d\n", res);
+                    }
+                }
+                //flag_init = 0;
+                break;
+            }
+            //qser_reset_sim
+            case 14:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    res = qser_reset_sim(h_sim);
+                    if(res == 0)
+                    {
+                        printf("reset sim success!!!\n");
+                    }else{
+                        printf("reset sim error, res = %d\n", res);
+                    }
+                }
+                //flag_init = 0;
+                break;
+            }
+            //qser_deinit_sim
+            case 15:
+            {
+                if(flag_init == 0){
+                    printf("must init first\n");
+                }
+                else{
+                    res = qser_sim_client_deinit(h_sim);
+                    if(res == 0)
+                    {
+                        printf("sim deinit success is!!!\n");
+                    }else{
+                        printf("sim deint errors, res = %d\n", res);
+                    }
+                }
+                flag_init = 0;
+                break;
+            }
+            default:
+                print_help();
+                break;
+        }
+            
+    }
+    
+   return 0;
+}