Add DS support.

Change-Id: Ib8bc4e171dd5ca526f8e151ff3d467097582a8cb
diff --git a/mbtk/mbtk_rild_v2/src/ril_dev.c b/mbtk/mbtk_rild_v2/src/ril_dev.c
index 763ed41..d34143e 100755
--- a/mbtk/mbtk_rild_v2/src/ril_dev.c
+++ b/mbtk/mbtk_rild_v2/src/ril_dev.c
@@ -17,7 +17,8 @@
 #include "mbtk_utils.h"
 #include "ril_info.h"
 
-void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
+void ril_rsp_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
+ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port);
 
 /*
 AT+CGSN
@@ -25,10 +26,10 @@
 
 OK
 */
-static int req_imei_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_imei_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_numeric(port, "AT+CGSN", &response);
+    int err = at_send_command_numeric(portType_2_portId(sim_id, port), "AT+CGSN", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates) {
         *cme_err = at_get_cme_error(response);
@@ -48,11 +49,11 @@
 OK
 
 */
-static int req_sn_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_sn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+MRD_SN=R", "+MRD_SN:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+MRD_SN=R", "+MRD_SN:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -102,13 +103,13 @@
 OK
 
 */
-static int req_version_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
 {
     ATResponse *response = NULL;
 
 //    sleep(3);
 
-    int err = at_send_command_multiline(port, "ATI", "", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -149,10 +150,10 @@
 OK
 
 */
-static int req_model_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_model_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_multiline(port, "ATI", "", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -190,7 +191,7 @@
 
 OK
 */
-static int req_volte_set(ATPortType_enum port, int state, int *cme_err)
+static int req_volte_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[30] = {0};
@@ -202,7 +203,7 @@
     {
         strcpy(cmd, "AT+ACONFIG=\"IMSD=0\"");
     }
-    int err = at_send_command(port, cmd, &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
 
     if (err < 0 || response->success == 0) {
         *cme_err = at_get_cme_error(response);
@@ -221,11 +222,11 @@
 
 OK
 */
-static int req_volte_get(ATPortType_enum port, int *state, int *cme_err)
+static int req_volte_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+ACONFIG?", "", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+ACONFIG?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -267,15 +268,15 @@
 OK
 
 */
-static int req_temp_get(ATPortType_enum port, mbtk_temp_type_enum type, int16 *temp, int *cme_err)
+static int req_temp_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_temp_type_enum type, int16 *temp, int *cme_err)
 {
     ATResponse *response = NULL;
     int err = -1;
     int tmp_int;
     if(type == MBTK_TEMP_TYPE_SOC) { // Soc
-        err = at_send_command_singleline(port, "AT*SOCTEMP", "*SOCTEMP:", &response);
+        err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*SOCTEMP", "*SOCTEMP:", &response);
     } else { // RF
-        err = at_send_command_singleline(port, "AT*RFTEMP", "*RFTEMP:", &response);
+        err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*RFTEMP", "*RFTEMP:", &response);
     }
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -319,11 +320,11 @@
 OK
 
 */
-static int req_cell_time_get(ATPortType_enum port, char *data, int *cme_err)
+static int req_cell_time_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *data, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+CCLK?", "+CCLK:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CCLK?", "+CCLK:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -357,14 +358,14 @@
 6: turn off full secondary receive.
 -1: fail
 */
-mbtk_radio_state_enum ril_radio_state_get(ATPortType_enum port)
+mbtk_radio_state_enum ril_radio_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port)
 {
     ATResponse *p_response = NULL;
     int err;
     char *line;
     int ret;
 
-    err = at_send_command_singleline(port, "AT+CFUN?", "+CFUN:", &p_response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CFUN?", "+CFUN:", &p_response);
 
     if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
     {
@@ -382,21 +383,21 @@
 
     at_response_free(p_response);
 
-    ril_info.radio_state = (mbtk_radio_state_enum)ret;
+    ril_info.radio_state[sim_id] = (mbtk_radio_state_enum)ret;
 
-    return ril_info.radio_state;
+    return ril_info.radio_state[sim_id];
 done:
     at_response_free(p_response);
     return MBTK_RADIO_STATE_UNKNOWN;
 }
 
-mbtk_ril_err_enum ril_radio_state_set(ATPortType_enum port, mbtk_radio_state_enum state, bool reset)
+mbtk_ril_err_enum ril_radio_state_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_radio_state_enum state, bool reset)
 {
     int err;
     ATResponse *p_response = NULL;
     mbtk_ril_err_enum ret = MBTK_RIL_ERR_UNKNOWN;
 
-    if(state == ril_info.radio_state) {
+    if(state == ril_info.radio_state[sim_id]) {
         LOGE("Radio state is same.");
         //return MBTK_RIL_ERR_PARAMETER;
         return MBTK_RIL_ERR_SUCCESS;
@@ -410,21 +411,21 @@
     } else {
         snprintf(cmd, sizeof(cmd), "AT+CFUN=%d", state);
     }
-    err = at_send_command(port, cmd, &p_response);
+    err = at_send_command(portType_2_portId(sim_id, port), cmd, &p_response);
     if (err || !p_response->success) {
         goto done;
     }
 
     if(state == MBTK_RADIO_STATE_FULL_FUNC) { // +CFUN=1
-        if(ril_radio_state_get(port) == MBTK_RADIO_STATE_FULL_FUNC) { // success
-            ril_info.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
+        if(ril_radio_state_get(sim_id, port) == MBTK_RADIO_STATE_FULL_FUNC) { // success
+            ril_info.radio_state[sim_id] = MBTK_RADIO_STATE_FULL_FUNC;
             ret = MBTK_RIL_ERR_SUCCESS;
             LOGD("Radio open success.");
         } else {
             LOGW("Radio open fail.");
         }
     } else {
-        ril_info.radio_state = state;
+        ril_info.radio_state[sim_id] = state;
         ret = MBTK_RIL_ERR_SUCCESS;
         LOGD("Set radio state to %d success.", state);
     }
@@ -453,7 +454,7 @@
 bit4 - PS DATA
 
 */
-static int req_powerind_set(ATPortType_enum port, uint8 state, int *cme_err)
+static int req_powerind_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 state, int *cme_err)
 {
     ATResponse *response = NULL;
     int err = -1;
@@ -462,7 +463,7 @@
     {
         char cmd[100] = {0};
         sprintf(cmd, "AT*POWERIND=%d", state);
-        err = at_send_command(port, cmd, &response);
+        err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
         if (err < 0 || response->success == 0){
             *cme_err = at_get_cme_error(response);
             goto exit;
@@ -474,10 +475,10 @@
     return err;
 }
 
-static int req_md_version_get(ATPortType_enum port,void *data, int *cme_err)
+static int req_md_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port,void *data, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_multiline(port,"AT*CGMR", "", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT*CGMR", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates)
     {
@@ -541,7 +542,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get IMEI
             {
                 char imei[20] = {0};
-                if(req_imei_get(cli_info->port, imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_imei_get(cli_info->sim_id, cli_info->port, imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -552,7 +553,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imei, strlen(imei));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imei, strlen(imei));
                 }
             }
             else     // Set IMEI(Unsupport).
@@ -567,7 +568,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char sn[20] = {0};
-                if(req_sn_get(cli_info->port, sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_sn_get(cli_info->sim_id, cli_info->port, sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -578,7 +579,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, sn, strlen(sn));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, sn, strlen(sn));
                 }
             }
             else     // Set
@@ -607,7 +608,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char version[50] = {0};
-                if(req_version_get(cli_info->port, version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_version_get(cli_info->sim_id, cli_info->port, version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -618,7 +619,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen(version));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen(version));
                 }
             }
             else     // Set
@@ -633,7 +634,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char model[50] = {0};
-                if(req_model_get(cli_info->port, model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_model_get(cli_info->sim_id, cli_info->port, model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -644,7 +645,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, model, strlen(model));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, model, strlen(model));
                 }
             }
             else     // Set
@@ -659,7 +660,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 int state;
-                if(req_volte_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_volte_get(cli_info->sim_id, cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -670,7 +671,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
                 }
             }
             else     // Set VoLTE state.
@@ -684,7 +685,7 @@
                 }
 
                 uint8 on = *(pack->data);
-                if(req_volte_set(cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_volte_set(cli_info->sim_id, cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -695,7 +696,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
 
                     // Restart is required to take effect.
                     // LOG("Will reboot system...");
@@ -708,7 +709,7 @@
             if(pack->data && pack->data_len == sizeof(uint8)) {
                 int16 temp;
                 mbtk_temp_type_enum type = (mbtk_temp_type_enum)(*(pack->data));
-                if(req_temp_get(cli_info->port, type, &temp, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_temp_get(cli_info->sim_id, cli_info->port, type, &temp, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -719,7 +720,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &temp, sizeof(int16));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &temp, sizeof(int16));
                 }
             } else {
                 err = MBTK_RIL_ERR_UNSUPPORTED;
@@ -732,7 +733,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get Time
             {
                 char time[100] = {0};
-                if(req_cell_time_get(cli_info->port, time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cell_time_get(cli_info->sim_id, cli_info->port, time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -743,7 +744,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, time, strlen(time));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, time, strlen(time));
                 }
             }
             else     // Set Time
@@ -757,7 +758,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->port);
+                mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->sim_id, cli_info->port);
                 if(radio_state == MBTK_RADIO_STATE_UNKNOWN)
                 {
                     err = MBTK_RIL_ERR_UNKNOWN;
@@ -765,7 +766,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &radio_state, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &radio_state, sizeof(uint8));
                 }
             }
             else     // Set
@@ -774,9 +775,9 @@
                 if(pack->data && pack->data_len == 2) {
                     mbtk_radio_state_enum radio_state = (mbtk_radio_state_enum)(*(pack->data));
                     bool reset = *(pack->data + 1);
-                    err = ril_radio_state_set(cli_info->port, radio_state, reset);
+                    err = ril_radio_state_set(cli_info->sim_id, cli_info->port, radio_state, reset);
                     if(MBTK_RIL_ERR_SUCCESS == err) {
-                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                        ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                     }
                 } else {
                     err = MBTK_RIL_ERR_FORMAT;
@@ -794,7 +795,7 @@
             else     // Set powerind state.
             {
                 uint8 state = *(pack->data);
-                if(req_powerind_set(cli_info->port, state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_powerind_set(cli_info->sim_id, cli_info->port, state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -806,7 +807,7 @@
                 else
                 {
                     // pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0);
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             break;
@@ -816,7 +817,7 @@
                 if(pack->data_len == 0 || pack->data == NULL)   // Get VERSION
                 {
                     char version[50] = {0};
-                    if(req_md_version_get(cli_info->port,version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_md_version_get(cli_info->sim_id, cli_info->port,version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -827,7 +828,7 @@
                     }
                     else
                     {
-                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen((char*)version));
+                        ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen((char*)version));
                     }
                 }
                 break;