T108 sim Voie data network sms 支持双卡 ql 接口第一版

Change-Id: If5a9fb81971258bb5a3d811f3e4562b2df351853
diff --git a/mbtk/libql_lib_v2_rilv2/ql_sim.c b/mbtk/libql_lib_v2_rilv2/ql_sim.c
index 7028f1c..5869ee9 100755
--- a/mbtk/libql_lib_v2_rilv2/ql_sim.c
+++ b/mbtk/libql_lib_v2_rilv2/ql_sim.c
@@ -81,6 +81,33 @@
 /*----------------------------------------------GLOBAL STATIC VARIABLE---------------------------*/
 
 /*----------------------------------------------SIM FUNCTION-------------------------------------*/
+
+static bool check_slot_valid(QL_SIM_SLOT_E slot)
+{
+    if (slot != QL_SIM_SLOT_1 && slot != QL_SIM_SLOT_2)
+    {
+        QL_SIM_LOGE("bad slot: %d, slot should be 1 or 2", slot);
+        return false;
+    }
+    
+    return true;
+}
+
+static void ql_slot_convert_to_mbtk(QL_SIM_SLOT_E ql_slot,mbtk_sim_type_enum *mbtk_slot)
+{
+    if(ql_slot == QL_SIM_SLOT_1)
+    {
+        *mbtk_slot = MBTK_SIM_1;
+    }
+    
+    if(ql_slot == QL_SIM_SLOT_2)
+    {
+        *mbtk_slot = MBTK_SIM_2;
+    }
+    return;
+    
+}
+
 static void ql_sim_state_change_cb(const void* data, int data_len)
 {
     if(data_len != sizeof(mbtk_ril_sim_state_info_t))
@@ -221,7 +248,10 @@
                                     ql_sim_card_info_t sim_info = {0};
                                     ql_sim_get_card_info(QL_SIM_SLOT_1, &sim_info);
                                     info->status_cb(QL_SIM_SLOT_1, &sim_info);
+                                    ql_sim_get_card_info(QL_SIM_SLOT_2, &sim_info);
+                                    info->status_cb(QL_SIM_SLOT_2, &sim_info);
                                 }
+                                
                                 break;
                             }
                             default:
@@ -313,13 +343,20 @@
             goto error_1;
         }
 
-        int ret = mbtk_sim_state_change_cb_reg(ql_sim_state_change_cb);
+        int ret = mbtk_ds_sim_state_change_cb_reg(MBTK_SIM_1,ql_sim_state_change_cb);
         if(ret != MBTK_ERR_OK)
         {
             QL_SIM_LOGE("[%s] set sim state cb fail.[%d]", __func__, ret);
             goto error_2;
         }
 
+        ret = mbtk_ds_sim_state_change_cb_reg(MBTK_SIM_2,ql_sim_state_change_cb);
+        if(ret != MBTK_ERR_OK)
+        {
+            QL_SIM_LOGE("[%s] set sim state cb fail.[%d]", __func__, ret);
+            goto error_2;
+        }
+        
         ret = mbtk_ril_ser_state_change_cb_reg(ql_sim_server_change_cb);
         if(ret != MBTK_ERR_OK)
         {
@@ -412,9 +449,10 @@
 /*-----------------------------------------------------------------------------------------------*/
 int ql_sim_get_imsi(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type, char *imsi, int imsi_len)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
 
+    mbtk_sim_type_enum sim_id = -1;
     if(NULL == sim_handle)
     {
         QL_SIM_LOGE("[%s] sim handle not init.", __func__);
@@ -426,17 +464,24 @@
         QL_SIM_LOGE("[%s] imsi is NULL.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    
     if(imsi_len < QL_SIM_IMSI_LENGTH)
     {
         QL_SIM_LOGE("[%s] imsi buf is too short.", __func__);
         return QL_ERR_BUF_OVERFLOW;
     }
-
+    
+    if (!check_slot_valid(slot))
+    {
+         QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     char temp_buff[MBTK_BUFF_TEMP_SIZE_32] = {0};
     memset(imsi, 0x0, imsi_len);
     memset(temp_buff, 0x0, MBTK_BUFF_TEMP_SIZE_32);
-    int ret = mbtk_imsi_get(sim_handle->handle, (void *)temp_buff);
+    int ret = mbtk_ds_imsi_get(sim_handle->handle,sim_id,(void *)temp_buff);
     if(ret != MBTK_ERR_OK)
     {
         QL_SIM_LOGE("[%s] imsi get fail.[%d]", __func__, ret);
@@ -462,7 +507,7 @@
 /*-----------------------------------------------------------------------------------------------*/
 int ql_sim_get_iccid(QL_SIM_SLOT_E slot, char *iccid, int iccid_len)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
 
     if(NULL == sim_handle)
     {
@@ -481,11 +526,17 @@
         QL_SIM_LOGE("[%s] imsi buf is too short.", __func__);
         return QL_ERR_BUF_OVERFLOW;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
     char temp_buff[MBTK_BUFF_TEMP_SIZE_32] = {0};
     memset(iccid, 0x0, iccid_len);
     memset(temp_buff, 0x0, MBTK_BUFF_TEMP_SIZE_32);
-    int ret = mbtk_iccid_get(sim_handle->handle, (void *)temp_buff);
+    int ret = mbtk_ds_iccid_get(sim_handle->handle,sim_id, (void *)temp_buff);
     if(ret != MBTK_ERR_OK)
     {
         QL_SIM_LOGE("[%s] iccid get fail.[%d]", __func__, ret);
@@ -514,7 +565,7 @@
 int ql_sim_get_phone_num(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                           char *phone_num, int phone_num_len)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
 
     if(NULL == sim_handle)
@@ -535,10 +586,18 @@
         return QL_ERR_BUF_OVERFLOW;
     }
 
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     char temp_buff[MBTK_BUFF_TEMP_SIZE_128] = {0};
     memset(phone_num, 0x0, phone_num_len);
     memset(temp_buff, 0x0, MBTK_BUFF_TEMP_SIZE_128);
-    int ret = mbtk_phone_number_get(sim_handle->handle, (void *)temp_buff);
+    int ret = mbtk_ds_phone_number_get(sim_handle->handle,sim_id, (void *)temp_buff);
     if(ret != MBTK_ERR_OK)
     {
         QL_SIM_LOGE("[%s] phone_num get fail.[%d]", __func__, ret);
@@ -564,7 +623,7 @@
 /*-----------------------------------------------------------------------------------------------*/
 int ql_sim_get_operators(QL_SIM_SLOT_E slot, ql_sim_operator_list_t *list)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
 
     if(NULL == sim_handle)
     {
@@ -577,7 +636,13 @@
         QL_SIM_LOGE("[%s] list is NULL.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
 #if 0
     list_node_t* operators_list = NULL;
     mbtk_net_info_t* operator = NULL;
@@ -630,7 +695,7 @@
     operators_list = NULL;
 #else
     mbtk_net_info_array_t net_list;
-    mbtk_ril_err_enum err = mbtk_available_net_get(sim_handle->handle, &net_list);
+    mbtk_ril_err_enum err = mbtk_ds_available_net_get(sim_handle->handle,sim_id,&net_list);
     if(err != MBTK_RIL_ERR_SUCCESS) {
         LOGE("Error : %d", err);
     } else {
@@ -685,7 +750,7 @@
 int ql_sim_enable_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                              QL_SIM_PIN_E pin, const char *pin_value)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
     UNUSED(pin);
 
@@ -713,11 +778,18 @@
         return QL_ERR_INVALID_ARG;
     }
 
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
     mbtk_sim_lock_info_t info = {0};
     info.type = MBTK_SIM_LOCK_TYPE_ENABLE;
     memcpy(info.pin1, pin_value, pin_len);
 
-    int err = mbtk_sim_lock_set(sim_handle->handle, &info);
+    int err = mbtk_ds_sim_lock_set(sim_handle->handle,sim_id, &info);
     if(err)
     {
         QL_SIM_LOGE("[%s] enable pin fail.[%d]", __func__, err);
@@ -746,7 +818,7 @@
 int ql_sim_disable_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                              QL_SIM_PIN_E pin, const char *pin_value)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
     UNUSED(pin);
 
@@ -773,12 +845,19 @@
         QL_SIM_LOGE("[%s] pin length is too short.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     mbtk_sim_lock_info_t info = {0};
     info.type = MBTK_SIM_LOCK_TYPE_DISABLE;
     memcpy(info.pin1, pin_value, pin_len);
 
-    int err = mbtk_sim_lock_set(sim_handle->handle, &info);
+    int err = mbtk_ds_sim_lock_set(sim_handle->handle,sim_id, &info);
     if(err)
     {
         QL_SIM_LOGE("[%s] disenable pin fail.[%d]", __func__, err);
@@ -808,7 +887,7 @@
 int ql_sim_verify_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                              QL_SIM_PIN_E pin, const char *pin_value)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
     UNUSED(pin);
 
@@ -835,12 +914,19 @@
         QL_SIM_LOGE("[%s] pin length is too short.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     mbtk_sim_lock_info_t info = {0};
     info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PIN;
     memcpy(info.pin1, pin_value, pin_len);
 
-    int err = mbtk_sim_lock_set(sim_handle->handle, &info);
+    int err = mbtk_ds_sim_lock_set(sim_handle->handle,sim_id, &info);
     if(err)
     {
         QL_SIM_LOGE("[%s] verify pin fail.[%d]", __func__, err);
@@ -870,7 +956,7 @@
 int ql_sim_change_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                              QL_SIM_PIN_E pin, const char *old_pin_value, const char *new_pin_value)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
     UNUSED(pin);
 
@@ -898,13 +984,20 @@
         QL_SIM_LOGE("[%s] pin length is too short.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     mbtk_sim_lock_info_t info = {0};
     info.type = MBTK_SIM_LOCK_TYPE_CHANGE;
     memcpy(info.pin1, old_pin_value, old_pin_len);
     memcpy(info.pin2, new_pin_value, new_pin_len);
 
-    int err = mbtk_sim_lock_set(sim_handle->handle, &info);
+    int err = mbtk_ds_sim_lock_set(sim_handle->handle,sim_id, &info);
     if(err)
     {
         QL_SIM_LOGE("[%s] change pin fail.[%d]", __func__, err);
@@ -935,7 +1028,7 @@
 int ql_sim_unblock_pin(QL_SIM_SLOT_E slot, QL_SIM_APP_TYPE_E app_type,
                              QL_SIM_PIN_E pin, const char *puk_value, const char *pin_value)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
     UNUSED(app_type);
     UNUSED(pin);
 
@@ -963,13 +1056,20 @@
         QL_SIM_LOGE("[%s] length is too short.", __func__);
         return QL_ERR_INVALID_ARG;
     }
-
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     mbtk_sim_lock_info_t info = {0};
     info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PUK;
     memcpy(info.pin1, pin_value, pin_len);
     memcpy(info.puk, puk_value, puk_len);
 
-    int err = mbtk_sim_lock_set(sim_handle->handle, &info);
+    int err = mbtk_ds_sim_lock_set(sim_handle->handle,sim_id, &info);
     if(err)
     {
         QL_SIM_LOGE("[%s] unblock pin fail.[%d]", __func__, err);
@@ -993,7 +1093,7 @@
 /*-----------------------------------------------------------------------------------------------*/
 int ql_sim_get_card_info(QL_SIM_SLOT_E slot, ql_sim_card_info_t *p_info)
 {
-    UNUSED(slot);
+    //UNUSED(slot);
 
     if(NULL == sim_handle)
     {
@@ -1007,16 +1107,24 @@
         return QL_ERR_INVALID_ARG;
     }
 
+    mbtk_sim_type_enum sim_id = -1;
+    if(!check_slot_valid(slot))
+    {
+        QL_SIM_LOGE("[%s] check_slot_valid failed.", __func__);
+        return QL_ERR_INVALID_ARG;
+    }
+    ql_slot_convert_to_mbtk(slot,&sim_id);
+    
     mbtk_sim_state_enum sim;
-    int ret = mbtk_sim_state_get(sim_handle->handle, &sim);
+    int ret = mbtk_ds_sim_state_get(sim_handle->handle,sim_id, &sim);
     if(ret != MBTK_ERR_OK)
     {
         QL_SIM_LOGE("[%s] sim state get fail.[%d]", __func__, ret);
         return QL_ERR_FAILED;
     }
-
+    
     mbtk_sim_card_type_enum sim_card_type;
-    ret = mbtk_sim_type_get(sim_handle->handle, &sim_card_type);
+    ret = mbtk_ds_sim_type_get(sim_handle->handle,sim_id, &sim_card_type);
     if(ret)
     {
         QL_SIM_LOGE("[%s] sim type get fail.[%d]", __func__, ret);
@@ -1024,7 +1132,7 @@
     }
 
     mbtk_pin_puk_last_times_t sim_last_times = {0};
-    ret = mbtk_sim_lock_retry_times_get(sim_handle->handle, &sim_last_times);
+    ret = mbtk_ds_sim_lock_retry_times_get(sim_handle->handle,sim_id, &sim_last_times);
     if(ret)
     {
         QL_SIM_LOGE("[%s] sim pin puk times get fail.[%d]", __func__, ret);
@@ -1032,7 +1140,7 @@
     }
 
     int pin_state;
-    ret = mbtk_sim_lock_get(sim_handle->handle, &pin_state);
+    ret = mbtk_ds_sim_lock_get(sim_handle->handle,sim_id, &pin_state);
     if(ret)
     {
         QL_SIM_LOGE("[%s] sim pin state get fail.[%d]", __func__, ret);