Add DS support.

Change-Id: Ib8bc4e171dd5ca526f8e151ff3d467097582a8cb
diff --git a/mbtk/mbtk_rild_v2/src/atchannel.c b/mbtk/mbtk_rild_v2/src/atchannel.c
index 80f8e68..54313d0 100755
--- a/mbtk/mbtk_rild_v2/src/atchannel.c
+++ b/mbtk/mbtk_rild_v2/src/atchannel.c
@@ -38,20 +38,21 @@
 #define HANDSHAKE_TIMEOUT_MSEC 500
 #define AT_BUFF_MAX 1024
 
-static pthread_t s_tid_reader[ATPORTTYPE_NUM];
-static int s_at_fd[ATPORTTYPE_NUM] = {-1};    /* fd of the AT channel */
-static int s_uart_fd = -1;    /* fd of the UART channel */
+static pthread_t s_tid_reader[ATPORTID_NUM];
+static int s_at_fd[ATPORTID_NUM] = {-1};    /* fd of the AT channel */
+static int s_uart_fd[MBTK_SIM_NUM] = {-1};    /* fd of the UART channel */
 
-static ATUnsolHandler s_unsolHandler;
+static ATUnsolHandler s_unsolHandler[MBTK_SIM_NUM];
 
 /* for input buffering */
 
-static char s_ATBuffer[ATPORTTYPE_NUM][MAX_AT_RESPONSE+1];
-static char *s_ATBufferCur[ATPORTTYPE_NUM] = {s_ATBuffer[ATPORTTYPE_0], s_ATBuffer[ATPORTTYPE_1], s_ATBuffer[ATPORTTYPE_2]};
-static char s_UartBuffer[MAX_AT_RESPONSE+1];
-static char *s_UartBufferCur = s_UartBuffer;
+static char s_ATBuffer[ATPORTID_NUM][MAX_AT_RESPONSE+1];
+static char *s_ATBufferCur[ATPORTID_NUM] = {s_ATBuffer[ATPORTID_SIM1_0], s_ATBuffer[ATPORTID_SIM1_0], s_ATBuffer[ATPORTID_SIM1_0],
+                                            s_ATBuffer[ATPORTID_SIM2_0], s_ATBuffer[ATPORTID_SIM2_0], s_ATBuffer[ATPORTID_SIM2_0]};
+static char s_UartBuffer[MBTK_SIM_NUM][MAX_AT_RESPONSE+1];
+static char *s_UartBufferCur[MBTK_SIM_NUM] = {s_UartBuffer[MBTK_SIM_1], s_UartBuffer[MBTK_SIM_2]};
 
-static mbtk_ril_at_state_enum at_state[ATPORTTYPE_NUM] = {RIL_AT_STATE_CLOSED};
+static mbtk_ril_at_state_enum at_state[ATPORTID_NUM] = {RIL_AT_STATE_CLOSED};
 
 #if AT_DEBUG
 void  AT_DUMP(const char*  prefix, const char*  buff, int  len)
@@ -72,22 +73,22 @@
  */
 
 // "Wait" when AT process...
-static pthread_mutex_t s_commandmutex[ATPORTTYPE_NUM] = {PTHREAD_MUTEX_INITIALIZER};
-static pthread_cond_t s_commandcond[ATPORTTYPE_NUM] = {PTHREAD_COND_INITIALIZER};
+static pthread_mutex_t s_commandmutex[ATPORTID_NUM] = {PTHREAD_MUTEX_INITIALIZER};
+static pthread_cond_t s_commandcond[ATPORTID_NUM] = {PTHREAD_COND_INITIALIZER};
 
-static ATCommandType s_type[ATPORTTYPE_NUM];
-static const char *s_responsePrefix[ATPORTTYPE_NUM] = {NULL};
-static const char *s_smsPDU[ATPORTTYPE_NUM] = {NULL};
-static ATResponse *sp_response[ATPORTTYPE_NUM] = {NULL};
-static char s_curr_at[ATPORTTYPE_NUM][AT_BUFF_MAX];
+static ATCommandType s_type[ATPORTID_NUM];
+static const char *s_responsePrefix[ATPORTID_NUM] = {NULL};
+static const char *s_smsPDU[ATPORTID_NUM] = {NULL};
+static ATResponse *sp_response[ATPORTID_NUM] = {NULL};
+static char s_curr_at[ATPORTID_NUM][AT_BUFF_MAX];
 
 static void (*s_onTimeout)(void) = NULL;
 static void (*s_onReaderClosed)(void) = NULL;
 static int s_readerClosed;
 
-static void onReaderClosed(ATPortType_enum port);
-static int writeCtrlZ (ATPortType_enum port, const char *s);
-static int writeline (ATPortType_enum port, const char *s);
+static void onReaderClosed(ATPortId_enum port);
+static int writeCtrlZ (ATPortId_enum port, const char *s);
+static int writeline (ATPortId_enum port, const char *s);
 
 typedef struct
 {
@@ -137,7 +138,7 @@
 
 
 /** add an intermediate response to sp_response*/
-static void addIntermediate(ATPortType_enum port, const char *line)
+static void addIntermediate(ATPortId_enum port, const char *line)
 {
     ATLine *p_new;
 
@@ -170,7 +171,7 @@
     "NO ANSWER",
     "NO DIALTONE",
 };
-static int isFinalResponseError(ATPortType_enum port, const char *line)
+static int isFinalResponseError(ATPortId_enum port, const char *line)
 {
     size_t i;
 
@@ -220,7 +221,7 @@
  * See 27.007 annex B
  * WARNING: NO CARRIER and others are sometimes unsolicited
  */
-static int isFinalResponse(ATPortType_enum port, const char *line)
+static int isFinalResponse(ATPortId_enum port, const char *line)
 {
     return isFinalResponseSuccess(line) || isFinalResponseError(port, line);
 }
@@ -252,7 +253,7 @@
 
 
 /** assumes s_commandmutex is held */
-static void handleFinalResponse(ATPortType_enum port, const char *line)
+static void handleFinalResponse(ATPortId_enum port, const char *line)
 {
     sp_response[port]->finalResponse = strdup(line);
 
@@ -260,22 +261,22 @@
     pthread_cond_signal(&s_commandcond[port]);
 }
 
-static void handleUnsolicited(const char *line)
+static void handleUnsolicited(ATPortId_enum port, const char *line)
 {
-    if (s_unsolHandler != NULL)
+    if (s_unsolHandler[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] != NULL)
     {
-        s_unsolHandler(line, NULL);
+        s_unsolHandler[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2](line, NULL);
     }
 }
 
-static void processLine(ATPortType_enum port, const char *line)
+static void processLine(ATPortId_enum port, const char *line)
 {
     pthread_mutex_lock(&s_commandmutex[port]);
 //    LOGD("LINE : %s", line);
     if (sp_response[port] == NULL)
     {
         /* no command pending */
-        handleUnsolicited(line);
+        handleUnsolicited(port, line);
     }
     else if (isFinalResponseSuccess(line))
     {
@@ -297,7 +298,7 @@
     else switch (s_type[port])
         {
             case NO_RESULT:
-                handleUnsolicited(line);
+                handleUnsolicited(port, line);
                 break;
             case NUMERIC:
                 if (sp_response[port]->p_intermediates == NULL
@@ -310,7 +311,7 @@
                 {
                     /* either we already have an intermediate response or
                        the line doesn't begin with a digit */
-                    handleUnsolicited(line);
+                    handleUnsolicited(port, line);
                 }
                 break;
             case SINGLELINE:
@@ -343,7 +344,7 @@
                 else
                 {
                     /* we already have an intermediate response */
-                    handleUnsolicited(line);
+                    handleUnsolicited(port, line);
                 }
                 break;
             case MULTILINE:
@@ -353,13 +354,13 @@
                 }
                 else
                 {
-                    handleUnsolicited(line);
+                    handleUnsolicited(port, line);
                 }
                 break;
 
             default: /* this should never be reached */
                 LOGE("Unsupported AT command type %d\n", s_type[port]);
-                handleUnsolicited(line);
+                handleUnsolicited(port, line);
                 break;
         }
 
@@ -398,7 +399,7 @@
  * have buffered stdio.
  */
 
-static const char *readline(ATPortType_enum port)
+static const char *readline(ATPortId_enum port)
 {
     ssize_t count;
 
@@ -500,7 +501,7 @@
     return ret;
 }
 
-static const char *readlineUrc(ATPortType_enum port)
+static const char *readlineUrc(ATPortId_enum port)
 {
     ssize_t count;
 
@@ -508,37 +509,40 @@
     char *p_eol = NULL;
     char *ret;
 
+    mbtk_sim_type_enum sim_id = port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2;
+
+
     /* this is a little odd. I use *s_ATBufferCur == 0 to
      * mean "buffer consumed completely". If it points to a character, than
      * the buffer continues until a \0
      */
-    if (*s_UartBufferCur == '\0')
+    if (*s_UartBufferCur[sim_id] == '\0')
     {
         /* empty buffer */
-        s_UartBufferCur = s_UartBuffer;
-        *s_UartBufferCur = '\0';
-        p_read = s_UartBuffer;
+        s_UartBufferCur[sim_id] = s_UartBuffer[sim_id];
+        *s_UartBufferCur[sim_id] = '\0';
+        p_read = s_UartBuffer[sim_id];
     }
     else       /* *s_ATBufferCur != '\0' */
     {
         /* there's data in the buffer from the last read */
 
         // skip over leading newlines
-        while (*s_UartBufferCur == '\r' || *s_UartBufferCur == '\n')
-            s_UartBufferCur++;
+        while (*s_UartBufferCur[sim_id] == '\r' || *s_UartBufferCur[sim_id] == '\n')
+            s_UartBufferCur[sim_id]++;
 
-        p_eol = findNextEOL(s_UartBufferCur);
+        p_eol = findNextEOL(s_UartBufferCur[sim_id]);
 
         if (p_eol == NULL)
         {
             /* a partial line. move it up and prepare to read more */
             size_t len;
 
-            len = strlen(s_UartBufferCur);
+            len = strlen(s_UartBufferCur[sim_id]);
 
-            memmove(s_UartBuffer, s_UartBufferCur, len + 1);
-            p_read = s_UartBuffer + len;
-            s_UartBufferCur = s_UartBuffer;
+            memmove(s_UartBuffer[sim_id], s_UartBufferCur[sim_id], len + 1);
+            p_read = s_UartBuffer[sim_id] + len;
+            s_UartBufferCur[sim_id] = s_UartBuffer[sim_id];
         }
         /* Otherwise, (p_eol !- NULL) there is a complete line  */
         /* that will be returned the while () loop below        */
@@ -546,19 +550,19 @@
 
     while (p_eol == NULL)
     {
-        if (0 == MAX_AT_RESPONSE - (p_read - s_UartBuffer))
+        if (0 == MAX_AT_RESPONSE - (p_read - s_UartBuffer[sim_id]))
         {
             LOGE("ERROR: Input line exceeded buffer\n");
             /* ditch buffer and start over again */
-            s_UartBufferCur = s_UartBuffer;
-            *s_UartBufferCur = '\0';
-            p_read = s_UartBuffer;
+            s_UartBufferCur[sim_id] = s_UartBuffer[sim_id];
+            *s_UartBufferCur[sim_id] = '\0';
+            p_read = s_UartBuffer[sim_id];
         }
 
         do
         {
-            count = read(s_uart_fd, p_read,
-                         MAX_AT_RESPONSE - (p_read - s_UartBuffer));
+            count = read(s_uart_fd[sim_id], p_read,
+                         MAX_AT_RESPONSE - (p_read - s_UartBuffer[sim_id]));
             usleep(10000);
         }
         while (count < 0 && errno == EINTR);
@@ -570,10 +574,10 @@
             p_read[count] = '\0';
 
             // skip over leading newlines
-            while (*s_UartBufferCur == '\r' || *s_UartBufferCur == '\n')
-                s_UartBufferCur++;
+            while (*s_UartBufferCur[sim_id] == '\r' || *s_UartBufferCur[sim_id] == '\n')
+                s_UartBufferCur[sim_id]++;
 
-            p_eol = findNextEOL(s_UartBufferCur);
+            p_eol = findNextEOL(s_UartBufferCur[sim_id]);
             p_read += count;
         }
         else if (count <= 0)
@@ -593,18 +597,17 @@
 
     /* a full line in the buffer. Place a \0 over the \r and return */
 
-    ret = s_UartBufferCur;
+    ret = s_UartBufferCur[sim_id];
     *p_eol = '\0';
-    s_UartBufferCur = p_eol + 1; /* this will always be <= p_read,    */
+    s_UartBufferCur[sim_id] = p_eol + 1; /* this will always be <= p_read,    */
     /* and there will be a \0 at *p_read */
 
-    LOGD("[Port-%d]URC< %s", port, ret);
+    LOGD("[Sim-%d,Port-%d]URC< %s", sim_id, port, ret);
     return ret;
 }
 
 
-
-static void onReaderClosed(ATPortType_enum port)
+static void onReaderClosed(ATPortId_enum port)
 {
     LOGD("onReaderClosed()");
     if (s_onReaderClosed != NULL && s_readerClosed == 0)
@@ -633,7 +636,7 @@
 static void *readerLoop(void *arg)
 {
     UNUSED(arg);
-    ATPortType_enum *port = (ATPortType_enum*)arg;
+    ATPortId_enum *port = (ATPortId_enum*)arg;
     for (;;)
     {
         const char * line;
@@ -673,9 +676,9 @@
                 break;
             }
 
-            if (s_unsolHandler != NULL)
+            if (s_unsolHandler[*port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] != NULL)
             {
-                s_unsolHandler (line1, line2);
+                s_unsolHandler[*port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] (line1, line2);
             }
             free(line1);
         }
@@ -695,7 +698,7 @@
 static void *readerUrcLoop(void *arg)
 {
     UNUSED(arg);
-    ATPortType_enum *port = (ATPortType_enum*)arg;
+    ATPortId_enum *port = (ATPortId_enum*)arg;
     for (;;)
     {
         const char *line;
@@ -707,7 +710,7 @@
             break;
         }
 
-        handleUnsolicited(line);
+        handleUnsolicited(*port, line);
     }
 
     onReaderClosed(*port);
@@ -725,7 +728,7 @@
  * This function exists because as of writing, android libc does not
  * have buffered stdio.
  */
-static int writeline (ATPortType_enum port, const char *s)
+static int writeline (ATPortId_enum port, const char *s)
 {
     size_t cur = 0;
     size_t len = strlen(s);
@@ -776,7 +779,7 @@
     return 0;
 }
 
-static int writeCtrlZ (ATPortType_enum port, const char *s)
+static int writeCtrlZ (ATPortId_enum port, const char *s)
 {
     size_t cur = 0;
     size_t len = strlen(s);
@@ -824,7 +827,7 @@
     return 0;
 }
 
-static void clearPendingCommand(ATPortType_enum port)
+static void clearPendingCommand(ATPortId_enum port)
 {
     if (sp_response[port] != NULL)
     {
@@ -841,21 +844,21 @@
  * Starts AT handler on stream "fd'
  * returns 0 on success, -1 on error
  */
-int at_open(ATPortType_enum port, int at_fd, int uart_fd, ATUnsolHandler h)
+int at_open(ATPortId_enum port, int at_fd, int uart_fd, ATUnsolHandler h)
 {
     int ret;
     pthread_attr_t attr;
 
     s_at_fd[port] = at_fd;
-    s_uart_fd = uart_fd;
-    s_unsolHandler = h;
+    s_uart_fd[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] = uart_fd;
+    s_unsolHandler[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] = h;
     s_readerClosed = 0;
     s_responsePrefix[port] = NULL;
     s_smsPDU[port] = NULL;
     sp_response[port] = NULL;
 
-    ATPortType_enum *at_port_ptr = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
-    ATPortType_enum *urc_port_ptr = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
+    ATPortId_enum *at_port_ptr = (ATPortId_enum*)malloc(sizeof(ATPortId_enum));
+    ATPortId_enum *urc_port_ptr = (ATPortId_enum*)malloc(sizeof(ATPortId_enum));
     *at_port_ptr = port;
     *urc_port_ptr = port;
 
@@ -868,7 +871,7 @@
         return -1;
     }
 
-    if(port == ATPORTTYPE_0) { // URC only for ATPORTTYPE_0
+    if(port == ATPORTID_SIM1_0 || port == ATPORTID_SIM2_0) { // URC only for ATPORTTYPE_0
         pthread_t uart_tid_reader;
         ret = pthread_create(&uart_tid_reader, &attr, readerUrcLoop, urc_port_ptr);
         if (ret < 0)
@@ -882,19 +885,19 @@
 }
 
 /* FIXME is it ok to call this from the reader and the command thread? */
-void at_close(ATPortType_enum port)
+void at_close(ATPortId_enum port)
 {
     LOGD("at_close()");
     if (s_at_fd[port] >= 0)
     {
         close(s_at_fd[port]);
     }
-    if (s_uart_fd >= 0)
+    if (s_uart_fd[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] >= 0)
     {
-        close(s_uart_fd);
+        close(s_uart_fd[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2]);
     }
     s_at_fd[port] = -1;
-    s_uart_fd = -1;
+    s_uart_fd[port < ATPORTID_SIM2_0 ? MBTK_SIM_1 : MBTK_SIM_2] = -1;
 
     pthread_mutex_lock(&s_commandmutex[port]);
     s_readerClosed = 1;
@@ -976,7 +979,7 @@
  *
  * timeoutMsec == 0 means infinite timeout
  */
-static int at_send_command_full_nolock (ATPortType_enum port, const char *command, ATCommandType type,
+static int at_send_command_full_nolock (ATPortId_enum port, const char *command, ATCommandType type,
                                         const char *responsePrefix, const char *smspdu,
                                         long long timeoutMsec, ATResponse **pp_outResponse)
 {
@@ -1074,7 +1077,7 @@
  *
  * timeoutMsec == 0 means infinite timeout
  */
-static int at_send_command_full (ATPortType_enum port, const char *command, ATCommandType type,
+static int at_send_command_full (ATPortId_enum port, const char *command, ATCommandType type,
                                  const char *responsePrefix, const char *smspdu,
                                  long long timeoutMsec, ATResponse **pp_outResponse)
 {
@@ -1119,14 +1122,14 @@
  * if non-NULL, the resulting ATResponse * must be eventually freed with
  * at_response_free
  */
-int at_send_command (ATPortType_enum port, const char *command, ATResponse **pp_outResponse)
+int at_send_command (ATPortId_enum port, const char *command, ATResponse **pp_outResponse)
 {
     return at_send_command_full (port, command, NO_RESULT, NULL,
                                  NULL, 0, pp_outResponse);
 }
 
 
-int at_send_command_singleline (ATPortType_enum port, const char *command,
+int at_send_command_singleline (ATPortId_enum port, const char *command,
                                 const char *responsePrefix,
                                 ATResponse **pp_outResponse)
 {
@@ -1149,7 +1152,7 @@
     return err;
 }
 
-int at_send_command_singleline_with_timeout (ATPortType_enum port, const char *command,
+int at_send_command_singleline_with_timeout (ATPortId_enum port, const char *command,
         const char *responsePrefix,
         ATResponse **pp_outResponse,long long timeoutMsec)
 {
@@ -1174,7 +1177,7 @@
 
 
 
-int at_send_command_numeric (ATPortType_enum port, const char *command,
+int at_send_command_numeric (ATPortId_enum port, const char *command,
                              ATResponse **pp_outResponse)
 {
     int err;
@@ -1197,7 +1200,7 @@
 }
 
 
-int at_send_command_sms (ATPortType_enum port, const char *command,
+int at_send_command_sms (ATPortId_enum port, const char *command,
                          const char *pdu,
                          const char *responsePrefix,
                          ATResponse **pp_outResponse)
@@ -1222,7 +1225,7 @@
 }
 
 
-int at_send_command_multiline (ATPortType_enum port, const char *command,
+int at_send_command_multiline (ATPortId_enum port, const char *command,
                                const char *responsePrefix,
                                ATResponse **pp_outResponse)
 {
@@ -1258,7 +1261,7 @@
  * Periodically issue an AT command and wait for a response.
  * Used to ensure channel has start up and is active
  */
-int at_handshake(ATPortType_enum port)
+int at_handshake(ATPortId_enum port)
 {
 //    int i;
     int err = 0;
@@ -1340,12 +1343,12 @@
     return ret;
 }
 
-mbtk_ril_at_state_enum at_state_get(ATPortType_enum port)
+mbtk_ril_at_state_enum at_state_get(ATPortId_enum port)
 {
     return at_state[port];
 }
 
-void at_state_set(ATPortType_enum port, mbtk_ril_at_state_enum state)
+void at_state_set(ATPortId_enum port, mbtk_ril_at_state_enum state)
 {
     at_state[port] = state;
 }
@@ -1358,7 +1361,7 @@
     return true;
 }
 
-void unused_func(ATPortType_enum port)
+void unused_func(ATPortId_enum port)
 {
     isFinalResponse(port, NULL);
 }
diff --git a/mbtk/mbtk_rild_v2/src/main.c b/mbtk/mbtk_rild_v2/src/main.c
index a608201..e69ffce 100755
--- a/mbtk/mbtk_rild_v2/src/main.c
+++ b/mbtk/mbtk_rild_v2/src/main.c
@@ -97,28 +97,40 @@
 mbtk_ril_err_enum sms_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);

 mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);

 

-void data_call_retry(ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state);

+void data_call_retry(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state);

 

-void data_call_state_change_cb(int cid, bool action, bool auto_change, int reason);

+void data_call_state_change_cb(mbtk_sim_type_enum sim_id, int cid, bool action, bool auto_change, int reason);

 static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack);

-int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);

+int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);

+int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err);

+

+ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port)

+{

+    return (ATPortId_enum)(sim_id * ATPORTTYPE_NUM + port);

+}

 

 /* Called on command thread */

 static void onATTimeout()

 {

     LOGI("AT channel timeout; closing\n");

-    at_close(ATPORTTYPE_0);

-    at_close(ATPORTTYPE_1);

-    at_close(ATPORTTYPE_2);

+    at_close(ATPORTID_SIM1_0);

+    at_close(ATPORTID_SIM1_1);

+    at_close(ATPORTID_SIM1_2);

+    at_close(ATPORTID_SIM2_0);

+    at_close(ATPORTID_SIM2_1);

+    at_close(ATPORTID_SIM2_2);

 }

 

 /* Called on command or reader thread */

 static void onATReaderClosed()

 {

     LOGI("AT channel closed\n");

-    at_close(ATPORTTYPE_0);

-    at_close(ATPORTTYPE_1);

-    at_close(ATPORTTYPE_2);

+    at_close(ATPORTID_SIM1_0);

+    at_close(ATPORTID_SIM1_1);

+    at_close(ATPORTID_SIM1_2);

+    at_close(ATPORTID_SIM2_0);

+    at_close(ATPORTID_SIM2_1);

+    at_close(ATPORTID_SIM2_2);

 }

 

 static void sock_cli_free_func(void *data)
@@ -284,9 +296,9 @@
     }
 }
 
-static void ril_error_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, int err)

+static void ril_error_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, int err)

 {
-    ril_msg_pack_info_t* pack = ril_msg_pack_creat(port, RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);

+    ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, port, RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);

     if(pack)
     {

         pack->err = (uint16)err;

@@ -299,9 +311,9 @@
     }
 }
 
-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)

 {

-    ril_msg_pack_info_t* pack = ril_msg_pack_creat(port, RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);

+    ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, port, RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);

     if(pack)
     {
         pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;

@@ -321,9 +333,9 @@
     }
 }

 

-void ril_ind_pack_send(int fd, int msg_id, const void* data, int data_len)

+void ril_ind_pack_send(mbtk_sim_type_enum sim_id, int fd, int msg_id, const void* data, int data_len)

 {
-    ril_msg_pack_info_t* pack = ril_msg_pack_creat(ATPORTTYPE_NON, RIL_MSG_TYPE_IND, msg_id, RIL_MSG_INDEX_INVALID, data, data_len);

+    ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, ATPORTTYPE_NON, RIL_MSG_TYPE_IND, msg_id, RIL_MSG_INDEX_INVALID, data, data_len);

     if(pack)
     {
         pack->err = (uint16)0;

@@ -353,7 +365,7 @@
             int i;
             for(i = 0; i < IND_REGISTER_MAX; i++) {
                 if(cli->ind_register[i] == msg_id) {

-                    ril_ind_pack_send(cli->fd, msg_id, data, data_len);

+                    ril_ind_pack_send(MBTK_SIM_1, cli->fd, msg_id, data, data_len);

                     break;
                 }
             }
@@ -402,11 +414,12 @@
 // *SIMDETEC:1,SIM

 // *EUICC:1

 // +CPIN: SIM PIN

-static void urc_sim_state_change_process(const char *s, const char *sms_pdu)

+static void urc_sim_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     mbtk_ril_sim_state_info_t state;

     memset(&state, 0, sizeof(mbtk_ril_sim_state_info_t));

     state.sim_type = MBTK_UNKNOWN;

+    state.sim_id = sim_id;

 

     char* tmp_s = memdup(s,strlen(s) + 1);

     char *line = tmp_s;

@@ -429,14 +442,14 @@
 

         if(tmp_str) {

             if(strcmp(tmp_str, "NOS") == 0) {

-                state.sim_type = ril_info.sim_type;

+                state.sim_type = ril_info.sim_type[sim_id];

                 state.sim_state = MBTK_SIM_STATE_ABSENT;

-                ril_info.sim_state = MBTK_SIM_STATE_ABSENT;

+                ril_info.sim_state[sim_id] = MBTK_SIM_STATE_ABSENT;

                 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));

             } else if(strcmp(tmp_str, "SIM") == 0) {

-                state.sim_type = ril_info.sim_type;

+                state.sim_type = ril_info.sim_type[sim_id];

                 state.sim_state = MBTK_SIM_STATE_NOT_READY;

-                ril_info.sim_state = MBTK_SIM_STATE_NOT_READY;

+                ril_info.sim_state[sim_id] = MBTK_SIM_STATE_NOT_READY;

                 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));

             }

         }

@@ -514,8 +527,8 @@
              state.sim_state = MBTK_SIM_STATE_ABSENT;

         }

 

-        state.sim_type = ril_info.sim_type;

-        ril_info.sim_state = state.sim_state;

+        state.sim_type = ril_info.sim_type[sim_id];

+        ril_info.sim_state[sim_id] = state.sim_state;

 

         urc_msg_distribute(true, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));

     } else if(strStartsWith(s, "*EUICC:")){

@@ -527,7 +540,7 @@
         {

             goto SIM_STATE_EXIT;

         }

-        ril_info.sim_type = (mbtk_sim_card_type_enum)tmp_int;

+        ril_info.sim_type[sim_id] = (mbtk_sim_card_type_enum)tmp_int;

     } else {

         LOGW("Unknown URC.");

     }

@@ -539,7 +552,7 @@
 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0

 // +CALLDISCONNECT: 1

 // +CPAS: 4

-static void urc_call_state_change_process(const char *s, const char *sms_pdu)

+static void urc_call_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     char* tmp_s = memdup(s,strlen(s) + 1);

     char *line = tmp_s;

@@ -574,6 +587,7 @@
 

         LOGD("Found call id : %d", call_list[i].call_id);

 

+        call_list[i].sim_id = sim_id;

         if (at_tok_nextint(&line, &tmp_int) < 0)    // dir

         {

             goto CALL_STATE_EXIT;

@@ -635,6 +649,7 @@
         }

 

         call_list[i].state = MBTK_RIL_CALL_STATE_DISCONNECT;

+        call_list[i].sim_id = sim_id;

 

         urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));

 

@@ -651,10 +666,11 @@
 }

 

 // *ECALLDATA: <urc_id>[,<urc_data>]

-static void urc_ecall_state_change_process(const char *s, const char *sms_pdu)

+static void urc_ecall_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     mbtk_ril_ecall_state_info_t ecall_state;

     memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));

+    ecall_state.sim_id = sim_id;

 

     char* tmp_s = memdup(s,strlen(s) + 1);

     char *line = tmp_s;

@@ -685,11 +701,13 @@
 

 // +CMT: ,23

 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C

-static void urc_sms_state_change_process(const char *s, bool is_pdu)

+static void urc_sms_state_change_process(mbtk_sim_type_enum sim_id, const char *s, bool is_pdu)

 {

     static mbtk_ril_sms_state_info_t sms_info;

+    memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));

+    sms_info.sim_id = sim_id;

+

     if(!is_pdu) {

-        memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));

         char* tmp_s = memdup(s,strlen(s) + 1);

         char *line = tmp_s;

         char *tmp_str;

@@ -722,11 +740,12 @@
 // $CREG: 1, "8010", "000060a7", 0,, 2, 0

 // +CGREG: 1

 // +C5GREG: 1,"00280386","07e920010",11,1,"01"

-static void urc_net_reg_state_change_process(const char *s, const char *sms_pdu)

+static void urc_net_reg_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     mbtk_ril_net_reg_state_info_t state;

     memset(&state, 0, sizeof(mbtk_ril_net_reg_state_info_t));

     state.tech = MBTK_RADIO_TECH_UNKNOWN;

+    state.sim_id = sim_id;

 

     if(strStartsWith(s, "+CREG:"))

     {

@@ -784,7 +803,7 @@
     free(tmp_s);

 }

 

-static void urc_pdp_state_change_process(const char *s, const char *sms_pdu)

+static void urc_pdp_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     // "CONNECT"

     if(strStartsWith(s, "CONNECT"))

@@ -849,8 +868,8 @@
         // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1

         mbtk_ril_pdp_state_info_t cgev_info;

         memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));

+        cgev_info.sim_id = sim_id;

         int cid, reason = 0;

-        memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));

         if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {

             cgev_info.cid = (uint16)cid;

             cgev_info.action = FALSE;

@@ -893,7 +912,7 @@
         LOGD("+CGEV:cid - %d, act - %d, auto_change - %d, reason - %d", cgev_info.cid, cgev_info.action,

             cgev_info.auto_change, cgev_info.reason);

         if(cgev_info.cid >= MBTK_APN_CID_MIN && cgev_info.cid <= MBTK_APN_CID_MAX) {

-            data_call_state_change_cb(cgev_info.cid, cgev_info.action, cgev_info.auto_change, cgev_info.reason);

+            data_call_state_change_cb(sim_id, cgev_info.cid, cgev_info.action, cgev_info.auto_change, cgev_info.reason);

             urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));

         }

 

@@ -1089,7 +1108,7 @@
 }

 

 

-static void urc_cell_info_process(const char *s, const char *sms_pdu)

+static void urc_cell_info_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     // +EEMNRSVC: <mcc>,<lenOfMnc>,<mnc>,<tac>,<phyCellId>,<dlNrArfcn>,<dlScs>,<ulNrArfcn>,<ulScs>,<sulNrArfcn>,<sulScs>,<band>,<dlBandwidth>,<cellId>,<IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>,

     // <rsrp>,<rsrq>,<sinr>,<rssi>,<qRxLevMin>,<qQualMin>,<srxlev>,

@@ -2005,7 +2024,7 @@
 }

 

 

-static void onUnsolicited(const char *s, const char *sms_pdu)

+static void onUnsolicited(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)

 {

     LOGV("URC : %s", s);

     // MBTK_AT_READY

@@ -2014,11 +2033,11 @@
     // Get PDU data.

     if(cmt_found) {

         cmt_found = FALSE;

-        urc_sms_state_change_process(s, true);

+        urc_sms_state_change_process(sim_id, s, true);

     } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.

 

     } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {

-        urc_pdp_state_change_process(s, sms_pdu);

+        urc_pdp_state_change_process(sim_id, s, sms_pdu);

     } else if(strStartsWith(s, "+EEMNRSVC:") || strStartsWith(s, "+EEMNRINTER:")

         || strStartsWith(s, "+EEMNRINTERRAT:")

         || strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")

@@ -2027,7 +2046,7 @@
         || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")

         || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")

         || strStartsWith(s, "+EEMGINFONC:")) {

-        urc_cell_info_process(s, sms_pdu);

+        urc_cell_info_process(sim_id, s, sms_pdu);

     }

     else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"

     {

@@ -2039,6 +2058,7 @@
 

         mbtk_ril_radio_state_info_t state;

         memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));

+        state.sim_id = sim_id;

         if(*ptr == '1') {

             state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;

         } else {

@@ -2058,29 +2078,29 @@
          || strStartsWith(s, "+CREG:")     // GMS/WCDMA/LTE CS registed.

          || strStartsWith(s, "+C5GREG:"))   // NR data registed.

     {

-        urc_net_reg_state_change_process(s, sms_pdu);

+        urc_net_reg_state_change_process(sim_id, s, sms_pdu);

     }

     // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0

     else if(strStartsWith(s, "+CLCC:")

         || strStartsWith(s, "+CPAS:")

         || strStartsWith(s, "+CALLDISCONNECT:"))

     {

-        urc_call_state_change_process(s, sms_pdu);

+        urc_call_state_change_process(sim_id, s, sms_pdu);

     }

     else if(strStartsWith(s, "*SIMDETEC:")

         || strStartsWith(s, "*EUICC:")

         || strStartsWith(s, "+CPIN:"))

     {

-        urc_sim_state_change_process(s, sms_pdu);

+        urc_sim_state_change_process(sim_id, s, sms_pdu);

     }

     else if(strStartsWith(s, "+CMT:"))

     {

         cmt_found = TRUE;

-        urc_sms_state_change_process(s, false);

+        urc_sms_state_change_process(sim_id, s, false);

     }

     else if(strStartsWith(s, "*ECALLDATA:"))

     {

-        urc_ecall_state_change_process(s, sms_pdu);

+        urc_ecall_state_change_process(sim_id, s, sms_pdu);

     }

 #if 0

     // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0

@@ -2386,6 +2406,16 @@
     }

 }

 

+static void onUnsolicited1(const char *s, const char *sms_pdu)

+{

+    onUnsolicited(MBTK_SIM_1, s, sms_pdu);

+}

+

+static void onUnsolicited2(const char *s, const char *sms_pdu)

+{

+    onUnsolicited(MBTK_SIM_2, s, sms_pdu);

+}

+

 static int openSocket(const char* sockname)

 {

     int sock = socket(AF_UNIX, SOCK_STREAM, 0);

@@ -2413,30 +2443,66 @@
 }

 

 static void ril_at_ready_process()
-{
-    ril_info.radio_state = ril_radio_state_get(ATPORTTYPE_0);

-    if (ril_info.radio_state != MBTK_RADIO_STATE_FULL_FUNC)

+{

+    // SIM1 radio state config.

+    ril_info.radio_state[MBTK_SIM_1] = ril_radio_state_get(MBTK_SIM_1, ATPORTTYPE_0);

+    if (ril_info.radio_state[MBTK_SIM_1] != MBTK_RADIO_STATE_FULL_FUNC)

     {
-        ril_radio_state_set(ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);

+        ril_radio_state_set(MBTK_SIM_1, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);

     }

 
-    if(ril_info.radio_state == MBTK_RADIO_STATE_FULL_FUNC)

+    if(ril_info.radio_state[MBTK_SIM_1] == MBTK_RADIO_STATE_FULL_FUNC)

     {

-        at_send_command(ATPORTTYPE_0, "AT+CEREG=2", NULL);

-    }
-
-    ril_info.sim_state = ril_sim_state_get(ATPORTTYPE_0);

-    if(ril_info.sim_state == MBTK_SIM_STATE_READY)

+        at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+CEREG=2", NULL);

+    }

+

+    // SIM2 radio state config.

+    ril_info.radio_state[MBTK_SIM_2] = ril_radio_state_get(MBTK_SIM_2, ATPORTTYPE_0);

+    if (ril_info.radio_state[MBTK_SIM_2] != MBTK_RADIO_STATE_FULL_FUNC)

     {
-        LOGD("SIM READY!");
-        at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);

+        ril_radio_state_set(MBTK_SIM_2, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);

+    }

+
+    if(ril_info.radio_state[MBTK_SIM_2] == MBTK_RADIO_STATE_FULL_FUNC)

+    {

+        at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+CEREG=2", NULL);

+    }

+

+    // SIM1 state config.

+    ril_info.sim_state[MBTK_SIM_1] = ril_sim_state_get(MBTK_SIM_1, ATPORTTYPE_0);

+    if(ril_info.sim_state[MBTK_SIM_1] == MBTK_SIM_STATE_READY)

+    {
+        LOGD("SIM1 READY!");

+        at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+COPS=3", NULL);

 

         // Set APN from prop.

-        apn_auto_conf_from_prop(ATPORTTYPE_0);

+        apn_auto_conf_from_prop(MBTK_SIM_1, ATPORTTYPE_0);

     }
     else
     {
-        LOGE("SIM NOT READY!");
+        LOGE("SIM1 NOT READY!");

+    }

+

+    // SIM2 state config.

+    ril_info.sim_state[MBTK_SIM_2] = ril_sim_state_get(MBTK_SIM_2, ATPORTTYPE_0);

+    if(ril_info.sim_state[MBTK_SIM_2] == MBTK_SIM_STATE_READY)

+    {
+        LOGD("SIM1 READY!");

+        at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+COPS=3", NULL);

+

+        // Set APN from prop.

+        apn_auto_conf_from_prop(MBTK_SIM_2, ATPORTTYPE_0);

+    }
+    else
+    {
+        LOGE("SIM1 NOT READY!");

+    }

+

+    if(req_dual_sim_get(ATPORTTYPE_0, &(ril_info.cur_sim_id), NULL)) {

+        LOGE("req_dual_sim_get() fail, so set to SIM1.");

+        ril_info.cur_sim_id = MBTK_SIM_1;

+    } else {

+        LOGD("Current SIM : %d", ril_info.cur_sim_id);

     }

 }

 

@@ -2526,7 +2592,7 @@
                 ind_regisger(cli_info, pack->msg_id);

             }

 

-            ril_error_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, err);

+            ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, err);

 

             ril_msg_pack_free(pack);

         } else {

@@ -2596,36 +2662,45 @@
                 at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);

 

                 // Set APN from prop.

-                apn_auto_conf_from_prop(ATPORTTYPE_0);

+                apn_auto_conf_from_prop(state->sim_id, ATPORTTYPE_0);

             }

         }

         case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:

         {

             mbtk_ril_net_reg_state_info_t *reg_state = (mbtk_ril_net_reg_state_info_t*)msg->data;

-            data_call_retry(ATPORTTYPE_0, reg_state);

+            data_call_retry(reg_state->sim_id, ATPORTTYPE_0, reg_state);

             break;

         }

         case RIL_URC_MSG_BAND_SET:

         {

             int cme_err = MBTK_RIL_ERR_CME_NON;

-            if(req_band_set(ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)

+            if(req_band_set(MBTK_SIM_1, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)

             {

-                LOGE("Set band fail.");

+                LOGE("Set SIM1 band fail.");

             }

             else // Set band success.

             {

-                // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));

-                band_info.band_set_success = TRUE;

-                if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {

-                    property_set("persist.mbtk.band_config", "CN");

-                } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {

-                    property_set("persist.mbtk.band_config", "EU");

-                } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {

-                    property_set("persist.mbtk.band_config", "SA");

-                } else {

-                    property_set("persist.mbtk.band_config", "ALL");

+                LOGD("Set SIM1 band success.");

+                cme_err = MBTK_RIL_ERR_CME_NON;

+                if(req_band_set(MBTK_SIM_2, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)

+                {

+                    LOGE("Set SIM2 band fail.");

                 }

-                LOGD("Set band success.");

+                else // Set band success.

+                {

+                    LOGD("Set SIM2 band success.");

+                    // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));

+                    band_info.band_set_success = TRUE;

+                    if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {

+                        property_set("persist.mbtk.band_config", "CN");

+                    } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {

+                        property_set("persist.mbtk.band_config", "EU");

+                    } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {

+                        property_set("persist.mbtk.band_config", "SA");

+                    } else {

+                        property_set("persist.mbtk.band_config", "ALL");

+                    }

+                }

             }

             break;

         }

@@ -2723,13 +2798,14 @@
 

                                 // Default AT port.

                                 info->port = ATPORTTYPE_0;

+                                info->sim_id = MBTK_SIM_1;

 

                                 list_add(ril_info.sock_client_list, info);

                                 LOG("Add New Client FD Into List.");

 

                                 // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.

                                 mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;

-                                ril_ind_pack_send(client_fd, RIL_MSG_ID_IND_SER_STATE_CHANGE, &state, 1);

+                                ril_ind_pack_send(MBTK_SIM_1, client_fd, RIL_MSG_ID_IND_SER_STATE_CHANGE, &state, 1);

                             }
                             else
                             {
@@ -2746,7 +2822,7 @@
                         // Parse packet error,send error response to client.
                         if(pack == NULL)
                         {
-                            ril_error_pack_send(cli_info->port, cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);

+                            ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);

                         }
                         else
                         {
@@ -2755,6 +2831,11 @@
                             {

                                 // Update AT port in the first.

                                 cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);

+                                cli_info->sim_id = (mbtk_sim_type_enum)((*pack_ptr)->sim_id);

+                                if(cli_info->sim_id == MBTK_SIM_AUTO) {

+                                    cli_info->sim_id = ril_info.cur_sim_id;

+                                    LOGD("Auto sim => %d", cli_info->sim_id);

+                                }

 

                                 pack_distribute(cli_info, *pack_ptr);
                                 // Not free,will free in pack_process() or packet process thread.
@@ -2878,7 +2959,7 @@
                 err = pack_req_process(item->cli_info, pack);
                 if(err != MBTK_RIL_ERR_SUCCESS)

                 {
-                    ril_error_pack_send(item->cli_info->port, item->cli_info->fd, pack->msg_id, pack->msg_index, err);

+                    ril_error_pack_send(item->cli_info->sim_id, item->cli_info->port, item->cli_info->fd, pack->msg_id, pack->msg_index, err);

                 }
                 ril_info.at_process[*port] = false;

                 ril_msg_pack_free(pack);

@@ -3029,7 +3110,7 @@
     }
 

     ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));

-    *port_0 = ATPORTTYPE_0;

+    *port_0 = MBTK_AT_PORT_DEF;

     if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))

     {
         LOGE("pthread_create() fail.");

@@ -3037,7 +3118,7 @@
     }

 

     ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));

-    *port_1 = ATPORTTYPE_1;

+    *port_1 = MBTK_AT_PORT_VOICE;

     if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))

     {
         LOGE("pthread_create() fail.");

@@ -3045,7 +3126,7 @@
     }

 

     ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));

-    *port_2 = ATPORTTYPE_2;

+    *port_2 = MBTK_AT_PORT_DATA;

     if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))

     {
         LOGE("pthread_create() fail.");

@@ -3158,34 +3239,88 @@
         return -1;

     }

 

+    int uart_sock1 = openSocket("/tmp/atcmd_urc1");

+    if(uart_sock1 < 0)

+    {

+        LOGE("Open Uart Socket Fail[%d].", errno);

+        return -1;

+    }

+

+    int at_sock1 = openSocket("/tmp/atcmd_at1");

+    if(at_sock1 < 0)

+    {

+        LOGE("Open AT Socket Fail[%d].", errno);

+        return -1;

+    }

+

+    int at_sock1_1 = openSocket("/tmp/atcmd_at1_1");

+    if(at_sock1_1 < 0)

+    {

+        LOGE("Open AT Socket Fail[%d].", errno);

+        return -1;

+    }

+

+    int at_sock1_2 = openSocket("/tmp/atcmd_at1_2");

+    if(at_sock1_2 < 0)

+    {

+        LOGE("Open AT Socket Fail[%d].", errno);

+        return -1;

+    }

+

     at_set_on_reader_closed(onATReaderClosed);

     at_set_on_timeout(onATTimeout);

 

-    if(at_open(ATPORTTYPE_0, at_sock, uart_sock, onUnsolicited))

+    if(at_open(ATPORTID_SIM1_0, at_sock, uart_sock, onUnsolicited1))

     {

         LOGE("Start AT_0 thread fail.");

         return -1;

     }

 

-    if(at_open(ATPORTTYPE_1, at_sock_1, uart_sock, onUnsolicited))

+    if(at_open(ATPORTID_SIM1_1, at_sock_1, uart_sock, onUnsolicited1))

     {

         LOGE("Start AT_1 thread fail.");

         return -1;

     }

 

-    if(at_open(ATPORTTYPE_2, at_sock_2, uart_sock, onUnsolicited))

+    if(at_open(ATPORTID_SIM1_2, at_sock_2, uart_sock, onUnsolicited1))

     {

         LOGE("Start AT_1 thread fail.");

         return -1;

     }

 

-    if(at_handshake(ATPORTTYPE_0))

+    if(at_handshake(ATPORTID_SIM1_0))

     {

-        LOGE("AT handshake fail.");

+        LOGE("SIM1 AT handshake fail.");

         return -1;

     }

 

-    LOGD("AT OK.");

+    LOGD("SIM1 AT OK.");

+

+    if(at_open(ATPORTID_SIM2_0, at_sock1, uart_sock1, onUnsolicited2))

+    {

+        LOGE("Start AT_0 thread fail.");

+        return -1;

+    }

+

+    if(at_open(ATPORTID_SIM2_1, at_sock1_1, uart_sock1, onUnsolicited2))

+    {

+        LOGE("Start AT_1 thread fail.");

+        return -1;

+    }

+

+    if(at_open(ATPORTID_SIM2_2, at_sock1_2, uart_sock1, onUnsolicited2))

+    {

+        LOGE("Start AT_1 thread fail.");

+        return -1;

+    }

+

+    if(at_handshake(ATPORTID_SIM2_0))

+    {

+        LOGE("SIM2 AT handshake fail.");

+        return -1;

+    }

+

+    LOGD("SIM2 AT OK.");

 

     if(ril_server_start())

     {

diff --git a/mbtk/mbtk_rild_v2/src/ril_call.c b/mbtk/mbtk_rild_v2/src/ril_call.c
old mode 100644
new mode 100755
index ca80871..fe9d374
--- a/mbtk/mbtk_rild_v2/src/ril_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_call.c
@@ -17,21 +17,22 @@
 #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);
 
 /*
 ATDXXXXXXX;
 OK
 
 */
-static int req_call_start(ATPortType_enum port, char *phont_number, int *cme_err)
+static int req_call_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *phont_number, int *cme_err)
 {
     ATResponse *response = NULL;
 //    int tmp_int;
 //    char *tmp_str = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "ATD%s;", phont_number);
-    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);
         goto exit;
@@ -48,10 +49,10 @@
 OK
 
 */
-static int req_answer_call(ATPortType_enum port, int *cme_err)
+static int req_answer_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "AT+CHLD=2", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=2", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -67,10 +68,10 @@
 OK
 
 */
-static int req_hangup_call(ATPortType_enum port, int *cme_err)
+static int req_hangup_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "ATH", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "ATH", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -86,12 +87,12 @@
 OK
 
 */
-static int req_hangup_a_call(ATPortType_enum port, int phone_id, int *cme_err)
+static int req_hangup_a_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int phone_id, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+CHLD=1%d", phone_id);
-    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);
         goto exit;
@@ -107,10 +108,10 @@
 OK
 
 */
-static int req_hangup_waiting_or_background_call(ATPortType_enum port, int *cme_err)
+static int req_hangup_waiting_or_background_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "AT+CHLD=0", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=0", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -126,10 +127,10 @@
 OK
 
 */
-static int req_hangup_foreground_resume_background_call(ATPortType_enum port, int *cme_err)
+static int req_hangup_foreground_resume_background_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "AT+CHLD=1", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=1", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -145,13 +146,13 @@
 OK
 
 */
-static int req_waitin_call(ATPortType_enum port, mbtk_call_info_t *reg, int *cme_err)
+static int req_waitin_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_call_info_t *reg, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_str = NULL;
 
-    int err = at_send_command_multiline(port, "AT+CLCC", "+CLCC:", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CLCC", "+CLCC:", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -224,11 +225,11 @@
 
 OK
 */
-static int req_mute_get(ATPortType_enum port, int *state, int *cme_err)
+static int req_mute_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
-    int err = at_send_command_singleline(port, "AT+CMUT?", "+CMUT:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CMUT?", "+CMUT:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -258,13 +259,13 @@
 OK
 
 */
-static int req_mute_set(ATPortType_enum port, int state, int *cme_err)
+static int req_mute_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+CMUT=%d", state);
     LOG("Set the mute command is = %s.\n", cmd);
-    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);
         goto exit;
@@ -280,13 +281,13 @@
 OK
 
 */
-static int req_dtmf_set(ATPortType_enum port, mbtk_call_dtmf_info_t *state, int *cme_err)
+static int req_dtmf_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_call_dtmf_info_t *state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+VTS=%c,%d", state->character, state->duration);
     LOG("Set the DTMF command is = %s.\n", cmd);
-    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);
         goto exit;
@@ -297,11 +298,11 @@
     return err;
 }
 
-static int req_centric_get(ATPortType_enum port, int *state, int *cme_err)
+static int req_centric_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int = 0;
-    int err = at_send_command_singleline(port, "AT+CEUS?", "+CEUS:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CEUS?", "+CEUS:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -331,13 +332,13 @@
 OK
 
 */
-static int req_centric_set(ATPortType_enum port, int state, int *cme_err)
+static int req_centric_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+CEUS=%d", state);
     LOG("Set the centric command is = %s.\n", cmd);
-    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);
         goto exit;
@@ -367,7 +368,7 @@
             else     // Set
             {
                 char *pn = (char*)(pack->data);
-                if(req_call_start(cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_call_start(cli_info->sim_id, cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -378,7 +379,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);
                 }
             }
             break;
@@ -387,7 +388,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-               if(req_answer_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+               if(req_answer_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -398,7 +399,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);
                 }
             }
             else     // Set
@@ -412,7 +413,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -423,7 +424,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);
                 }
             }
             else     // Set
@@ -443,7 +444,7 @@
             else
             {
                 uint8 phone_id = *(pack->data);
-                if(req_hangup_a_call(cli_info->port, phone_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_a_call(cli_info->sim_id, cli_info->port, phone_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -454,7 +455,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);
                 }
             }
             break;
@@ -463,7 +464,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_waiting_or_background_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_waiting_or_background_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -474,7 +475,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);
                 }
             }
             else
@@ -488,7 +489,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_foreground_resume_background_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_foreground_resume_background_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -499,7 +500,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);
                 }
             }
             else
@@ -515,7 +516,7 @@
             {
                 mbtk_call_info_t reg;
                 memset(&reg, 0, sizeof(mbtk_call_info_t));
-                if(req_waitin_call(cli_info->port, &reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_waitin_call(cli_info->sim_id, cli_info->port, &reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -526,7 +527,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &reg, sizeof(mbtk_call_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &reg, sizeof(mbtk_call_info_t));
                 }
             }
             else     // Set
@@ -541,7 +542,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 int state;
-                if(req_mute_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_mute_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;
@@ -552,7 +553,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 mute state.
@@ -565,7 +566,7 @@
                     break;
                 }
 
-                if(req_mute_set(cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_mute_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;
@@ -576,7 +577,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);
                 }
             }
             break;
@@ -591,7 +592,7 @@
             else     // Set
             {
                 mbtk_call_dtmf_info_t *reg = (mbtk_call_dtmf_info_t *)pack->data;
-                if(req_dtmf_set(cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_dtmf_set(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -602,7 +603,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);
                 }
             }
             break;
@@ -612,7 +613,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 int state;
-                if(req_centric_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_centric_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;
@@ -623,7 +624,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(int));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(int));
                 }
             }
             else     // Set mute state.
@@ -636,7 +637,7 @@
                     break;
                 }
 
-                if(req_centric_set(cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_centric_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;
@@ -647,7 +648,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);
                 }
             }
             break;
diff --git a/mbtk/mbtk_rild_v2/src/ril_data_call.c b/mbtk/mbtk_rild_v2/src/ril_data_call.c
index 9aca13b..32f48bf 100755
--- a/mbtk/mbtk_rild_v2/src/ril_data_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_data_call.c
@@ -49,14 +49,15 @@
 int ril_cid_start = MBTK_APN_CID_MIN;
 
 
-static int req_apn_get(ATPortType_enum port, bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err);
-static int req_apn_set(ATPortType_enum port, mbtk_apn_info_t *apn, int *cme_err);
-static void apn_prop_get(mbtk_apn_info_array_t *apns);
-void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
-static int req_data_call_start(ATPortType_enum port, mbtk_ril_cid_enum cid, int *cme_err);
-static int req_data_call_state_get(ATPortType_enum port, mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err);
+static int req_apn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err);
+static int req_apn_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_apn_info_t *apn, int *cme_err);
+static void apn_prop_get(mbtk_sim_type_enum sim_id, mbtk_apn_info_array_t *apns);
+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);
+static int req_data_call_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_cid_enum cid, int *cme_err);
+static int req_data_call_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err);
 void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len);
 bool asr_auto_data_call_enable();
+ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port);
 
 /*
 IPv4 : 10.255.74.26
@@ -333,12 +334,12 @@
     }
 }
 
-void apn_auto_conf_from_prop(ATPortType_enum port)
+void apn_auto_conf_from_prop(mbtk_sim_type_enum sim_id, ATPortType_enum port)
 {
     mbtk_apn_info_array_t apns;
     int i = 0;
     memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
-    apn_prop_get(&apns);
+    apn_prop_get(sim_id, &apns);
     while(i < apns.num) {
         // Update apn info in buffer.
         int cid = apns.apns[i].cid;
@@ -354,7 +355,7 @@
             info_list[cid - 1].apn_info.as_dns, info_list[cid - 1].apn_info.apn);
 
         int cme_err = MBTK_RIL_ERR_CME_NON;
-        if(req_apn_set(port, &(apns.apns[i]), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+        if(req_apn_set(sim_id, port, &(apns.apns[i]), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
         {
             LOGD("Set APN fail.");
         }
@@ -375,7 +376,7 @@
     }
 }
 
-static int apn_check_and_cid_reset(ATPortType_enum port, mbtk_apn_info_t *apn)
+static int apn_check_and_cid_reset(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_apn_info_t *apn)
 {
     // Delete apn
     if(str_empty(apn->apn)) {
@@ -389,7 +390,7 @@
         mbtk_apn_info_array_t apns;
         int cme_err = MBTK_RIL_ERR_CME_NON;
         memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
-        if(req_apn_get(port, FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+        if(req_apn_get(sim_id, port, FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
         {
             LOGW("Get APN fail.");
             return 0;
@@ -410,7 +411,7 @@
         int cme_err = MBTK_RIL_ERR_CME_NON;
 
         memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
-        if(req_apn_get(port, TRUE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+        if(req_apn_get(sim_id, port, TRUE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
         {
             LOGW("Get APN fail.");
             if(apn->cid == MBTK_RIL_CID_NUL) {
@@ -503,7 +504,7 @@
     return 0;
 }
 
-static void apn_prop_get(mbtk_apn_info_array_t *apns)
+static void apn_prop_get(mbtk_sim_type_enum sim_id, mbtk_apn_info_array_t *apns)
 {
     char prop_name[128] = {0};
     char prop_data[1024] = {0};
@@ -924,7 +925,7 @@
     }
 }
 
-void data_call_retry(ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state)
+void data_call_retry(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state)
 {
     LOGV("NET_REG_STATE_CHANGE : type - %d, tech - %d, reg_state - %d", reg_state->type, reg_state->tech, reg_state->reg_state);
     // Only for 2g/3g/4g data domain.
@@ -962,7 +963,7 @@
 
                         // PDP active
                         int cme_err = MBTK_RIL_ERR_CME_NON;
-                        if(req_data_call_start(port, cid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_data_call_start(sim_id, port, cid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             LOGE("Restart data call fail.");
                             return;
@@ -978,7 +979,7 @@
                             // Get Ip informations.
                             // memset(&ip_info, 0, sizeof(ip_info));
                             cme_err = MBTK_RIL_ERR_CME_NON;
-                            if(req_data_call_state_get(port, cid, &(pdp_info.ip_info), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                            if(req_data_call_state_get(sim_id, port, cid, &(pdp_info.ip_info), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                             {
                                 LOGE("Get net informations fail.");
                                 return;
@@ -1020,10 +1021,10 @@
 OK
 
 */
-static int req_apn_get(ATPortType_enum port, bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err)
+static int req_apn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_multiline(port, "AT+CGDCONT?", "+CGDCONT:", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CGDCONT?", "+CGDCONT:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
@@ -1124,7 +1125,7 @@
 OK
 
 */
-static int req_apn_set(ATPortType_enum port, mbtk_apn_info_t *apn, int *cme_err)
+static int req_apn_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_apn_info_t *apn, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[400] = {0};
@@ -1134,7 +1135,7 @@
     // Delete apn
     if(str_empty(apn->apn)) {
         sprintf(cmd, "AT+CGDCONT=%d", apn->cid);
-        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){
             if(cme_err) {
                 *cme_err = at_get_cme_error(response);
@@ -1165,7 +1166,7 @@
             index += sprintf(cmd + index,"\"%s\"", apn->apn);
         }
 
-        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){
             if(cme_err) {
                 *cme_err = at_get_cme_error(response);
@@ -1189,7 +1190,7 @@
                 goto exit;
 
             sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
-            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){
                 if(cme_err) {
                     *cme_err = at_get_cme_error(response);
@@ -1214,7 +1215,7 @@
 OK
 
 */
-static int req_data_call_start(ATPortType_enum port, mbtk_ril_cid_enum cid, int *cme_err)
+static int req_data_call_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_cid_enum cid, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[400] = {0};
@@ -1225,7 +1226,7 @@
     cgact_wait.act = true;
 
     sprintf(cmd, "AT+CGACT=1,%d", cid);
-    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){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -1244,7 +1245,7 @@
 OK
 
 */
-static int req_data_call_stop(ATPortType_enum port, mbtk_ril_cid_enum cid, int timeout, int *cme_err)
+static int req_data_call_stop(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_cid_enum cid, int timeout, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[400] = {0};
@@ -1263,7 +1264,7 @@
     cgact_wait.act = false;
 
     sprintf(cmd, "AT+CGACT=0,%d", cid);
-    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){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -1285,7 +1286,7 @@
 OK
 
 */
-static int req_data_call_state_get(ATPortType_enum port, mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err)
+static int req_data_call_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[50] = {0};
@@ -1293,7 +1294,7 @@
 
     sprintf(cmd, "AT+CGCONTRDP=%d", cid);
 
-    err = at_send_command_multiline(port, cmd, "+CGCONTRDP:", &response);
+    err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "+CGCONTRDP:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -1435,7 +1436,7 @@
     return err;
 }
 
-void data_call_state_change_cb(int cid, bool action, bool auto_change, int reason)
+void data_call_state_change_cb(mbtk_sim_type_enum sim_id, int cid, bool action, bool auto_change, int reason)
 {
     // Will restart data call.
     if(auto_change && !action) {
@@ -1467,7 +1468,7 @@
             {
                 mbtk_apn_info_array_t apns;
                 memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
-                if(req_apn_get(cli_info->port, FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_apn_get(cli_info->sim_id, cli_info->port, FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1479,18 +1480,18 @@
                 else
                 {
                     LOGD("size - %d", sizeof(mbtk_apn_info_array_t));
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &apns, sizeof(mbtk_apn_info_array_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &apns, sizeof(mbtk_apn_info_array_t));
                 }
             }
             else     // Set
             {
                 mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data;
                 mbtk_ril_cid_enum return_cid = apn->cid;
-                if(apn_check_and_cid_reset(cli_info->port, apn)) {
+                if(apn_check_and_cid_reset(cli_info->sim_id, cli_info->port, apn)) {
                     err = MBTK_RIL_ERR_CID;
                 } else {
                     if(apn_conf_support(apn->cid)) {
-                        if(req_apn_set(cli_info->port, apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_apn_set(cli_info->sim_id, cli_info->port, apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             if(cme_err != MBTK_RIL_ERR_CME_NON) {
                                 err = MBTK_RIL_ERR_CME + cme_err;
@@ -1506,7 +1507,7 @@
                             }
 
                             return_cid = apn->cid;
-                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &return_cid, sizeof(mbtk_ril_cid_enum));
+                            ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &return_cid, sizeof(mbtk_ril_cid_enum));
                         }
                     } else {
                         err = MBTK_RIL_ERR_UNSUPPORTED;
@@ -1554,7 +1555,7 @@
                             int index = 0;
                             info_list[call_info->cid - 1].act_state = RIL_ACT_STATE_CONNECTING;
 data_call_retry:
-                            if(req_data_call_start(cli_info->port, call_info->cid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                            if(req_data_call_start(cli_info->sim_id, cli_info->port, call_info->cid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                             {
                                 if(call_info->retry_interval[index] > 0) {
                                     LOGD("Start data call fail, will retry in %d s.", call_info->retry_interval[index]);
@@ -1580,7 +1581,7 @@
 
                                 // Get Ip informations.
                                 cme_err = MBTK_RIL_ERR_CME_NON;
-                                if(req_data_call_state_get(cli_info->port, call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                                if(req_data_call_state_get(cli_info->sim_id, cli_info->port, call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                                 {
                                     LOGE("Get net informations fail.");
                                     err = MBTK_RIL_ERR_NET_CONF;
@@ -1599,7 +1600,7 @@
                                     // Data call success, valid will be true.
                                     info_list[call_info->cid - 1].valid = TRUE;
 
-                                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
+                                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
                                 }
                             }
                         }
@@ -1612,7 +1613,7 @@
                         }
 
                         info_list[call_info->cid - 1].act_state = RIL_ACT_STATE_DISCONNECTING;
-                        if(req_data_call_stop(cli_info->port, call_info->cid, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_data_call_stop(cli_info->sim_id, cli_info->port, call_info->cid, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             if(cme_err != MBTK_RIL_ERR_CME_NON) {
                                 err = MBTK_RIL_ERR_CME + cme_err;
@@ -1636,12 +1637,12 @@
                             }
 
                             info_list[call_info->cid - 1].act_state = RIL_ACT_STATE_DISCONNECTED;
-                            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 {
                         mbtk_ip_info_t ip_info;
                         memset(&ip_info, 0, sizeof(ip_info));
-                        if(req_data_call_state_get(cli_info->port, call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_data_call_state_get(cli_info->sim_id, cli_info->port, call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             if(cme_err != MBTK_RIL_ERR_CME_NON) {
                                 err = MBTK_RIL_ERR_CME + cme_err;
@@ -1652,7 +1653,7 @@
                         }
                         else
                         {
-                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
+                            ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
                         }
                     }
                 }
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;
diff --git a/mbtk/mbtk_rild_v2/src/ril_ecall.c b/mbtk/mbtk_rild_v2/src/ril_ecall.c
index ae8dcd7..3a13b61 100755
--- a/mbtk/mbtk_rild_v2/src/ril_ecall.c
+++ b/mbtk/mbtk_rild_v2/src/ril_ecall.c
@@ -40,9 +40,11 @@
 
 static mbtk_ecall_mode_type_enum ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
 
-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);
 
-static int cfg_ecalldata_get(ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
+
+static int cfg_ecalldata_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
@@ -51,7 +53,7 @@
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d", type);
-    err = at_send_command_singleline(port, cmd, "*ECALLDATA:", &response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), cmd, "*ECALLDATA:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -91,14 +93,14 @@
     return err;
 }
 
-static int cfg_ecalldata_set(ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 value, int *cme_err)
+static int cfg_ecalldata_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 value, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d,%d", type, value / 20);
-    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;
@@ -110,14 +112,14 @@
     return err;
 }
 
-static int cfg_ecalltimer_set(ATPortType_enum port, const char* type, uint32 value, int *cme_err)
+static int cfg_ecalltimer_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char* type, uint32 value, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=%s,%d", type, value);
-    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;
@@ -129,12 +131,12 @@
     return err;
 }
 
-static int req_ecall_msdcfg(ATPortType_enum port, mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
+static int req_ecall_msdcfg(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLMSDCFG=%d,\"%s\",0", cfg_info->item_type, cfg_info->data);
-    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);
         goto exit;
@@ -145,10 +147,10 @@
     return err;
 }
 
-static int req_ecall_msdgen(ATPortType_enum port, int *cme_err)
+static int req_ecall_msdgen(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "AT*ECALLMSDGEN", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT*ECALLMSDGEN", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -159,12 +161,12 @@
     return err;
 }
 
-static int req_ecall_msd_set(ATPortType_enum port, const uint8 *msd, int *cme_err)
+static int req_ecall_msd_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const uint8 *msd, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLMSD=\"%s\"", msd);
-    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);
         goto exit;
@@ -175,11 +177,11 @@
     return err;
 }
 
-static int req_ecall_msd_get(ATPortType_enum port, uint8 *msd, int *cme_err)
+static int req_ecall_msd_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 *msd, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT*ECALLMSD?", "*ECALLMSD:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLMSD?", "*ECALLMSD:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -209,10 +211,10 @@
     return err;
 }
 
-static int req_ecall_push(ATPortType_enum port, int *cme_err)
+static int req_ecall_push(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command(port, "AT*ECALLPUSH", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT*ECALLPUSH", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -230,12 +232,12 @@
 OK
 
 */
-static int req_ecall_only_get(ATPortType_enum port, mbtk_ecall_only_info_t *only_info, int *cme_err)
+static int req_ecall_only_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_only_info_t *only_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
     int tmp_int;
-    int err = at_send_command_singleline(port, "AT*ECALLONLY?", "*ECALLONLY:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLONLY?", "*ECALLONLY:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -296,12 +298,12 @@
 OK
 
 */
-static int req_ecall_only_set(ATPortType_enum port, const mbtk_ecall_only_info_t *only_info, int *cme_err)
+static int req_ecall_only_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ecall_only_info_t *only_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLONLY=%d,%s,%s", only_info->active,only_info->test_num,only_info->reconfig_num);
-    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);
         goto exit;
@@ -316,12 +318,12 @@
 AT*ECALLREG=0/1
 
 */
-static int req_ecall_reg_set(ATPortType_enum port, uint8 reg, int *cme_err)
+static int req_ecall_reg_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 reg, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[30] = {0};
     sprintf(cmd, "AT*ECALLREG=%d", reg);
-    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);
         goto exit;
@@ -339,11 +341,11 @@
 OK
 
 */
-static int req_ecall_dial_state_get(ATPortType_enum port, mbtk_ecall_dial_type_enum *type, int *cme_err)
+static int req_ecall_dial_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_dial_type_enum *type, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
-    int err = at_send_command_singleline(port, "AT+CECALL?", "+CECALL:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CECALL?", "+CECALL:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -374,12 +376,12 @@
 AT+CECALL=<ecalltype>
 OK
 */
-static int req_ecall_dial_start(ATPortType_enum port, mbtk_ecall_dial_type_enum type, int *cme_err)
+static int req_ecall_dial_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_dial_type_enum type, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT+CECALL=%d", type);
-    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);
         goto exit;
@@ -398,11 +400,11 @@
 OK
 
 */
-static int req_ecall_mode_get(ATPortType_enum port, mbtk_ecall_mode_type_enum *mode, int *cme_err)
+static int req_ecall_mode_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_mode_type_enum *mode, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT*ECALLMODE?", "*ECALLMODE:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLMODE?", "*ECALLMODE:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -445,7 +447,7 @@
 OK
 
 */
-static int req_ecall_mode_set(ATPortType_enum port, mbtk_ecall_mode_type_enum mode, int *cme_err)
+static int req_ecall_mode_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_mode_type_enum mode, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
@@ -454,7 +456,7 @@
     } else {
         sprintf(cmd, "AT*ECALLMODE=\"ERA\"");
     }
-    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);
         goto exit;
@@ -479,7 +481,7 @@
 OK
 
 */
-static int req_ecall_cfg_get(ATPortType_enum port, uint32 type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
+static int req_ecall_cfg_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint32 type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
@@ -489,7 +491,7 @@
     cfg->type = type;
 
     if(type & MBTK_ECALL_CFG_T3) {
-        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T3, &(cfg->data[MBTK_ECALL_CFG_ITEM_T3]), cme_err)
+        if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T3, &(cfg->data[MBTK_ECALL_CFG_ITEM_T3]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -498,7 +500,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T5) {
-        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T5, &(cfg->data[MBTK_ECALL_CFG_ITEM_T5]), cme_err)
+        if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T5, &(cfg->data[MBTK_ECALL_CFG_ITEM_T5]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -507,7 +509,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T6) {
-        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T6, &(cfg->data[MBTK_ECALL_CFG_ITEM_T6]), cme_err)
+        if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T6, &(cfg->data[MBTK_ECALL_CFG_ITEM_T6]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -516,7 +518,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T7) {
-        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T7, &(cfg->data[MBTK_ECALL_CFG_ITEM_T7]), cme_err)
+        if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T7, &(cfg->data[MBTK_ECALL_CFG_ITEM_T7]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -525,7 +527,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_TH) {
-        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_TH, &(cfg->data[MBTK_ECALL_CFG_ITEM_TH]), cme_err)
+        if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_TH, &(cfg->data[MBTK_ECALL_CFG_ITEM_TH]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -536,7 +538,7 @@
     if(type & (MBTK_ECALL_CFG_TIMER_CALLBACK | MBTK_ECALL_CFG_TIMER_CLEARDOWN | MBTK_ECALL_CFG_TIMER_DEREG
                 | MBTK_ECALL_CFG_TIMER_DIAL | MBTK_ECALL_CFG_TIMER_REDIAL | MBTK_ECALL_CFG_TIMER_SMS
                 | MBTK_ECALL_CFG_REDIALCNT | MBTK_ECALL_CFG_SMSPROCESS | MBTK_ECALL_CFG_SMSMSDCNT)) {
-        err = at_send_command_singleline(port, "AT*ECALLTIMER?", "*ECALLTIMER:", &response);
+        err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLTIMER?", "*ECALLTIMER:", &response);
         if (err < 0 || response->success == 0 || !response->p_intermediates){
             *cme_err = at_get_cme_error(response);
             goto exit;
@@ -653,7 +655,7 @@
 AT*ECALLTIMER=dereg,300
 OK
 */
-static int req_ecall_cfg_set(ATPortType_enum port, const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
+static int req_ecall_cfg_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
 {
     int err = 0;
     if(ecall_mode == MBTK_ECALL_MODE_TYPE_EU) {
@@ -668,7 +670,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T3) {
-        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T3, cfg_info->data[MBTK_ECALL_CFG_ITEM_T3], cme_err)
+        if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T3, cfg_info->data[MBTK_ECALL_CFG_ITEM_T3], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -676,7 +678,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T5) {
-        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T5, cfg_info->data[MBTK_ECALL_CFG_ITEM_T5], cme_err)
+        if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T5, cfg_info->data[MBTK_ECALL_CFG_ITEM_T5], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -684,7 +686,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T6) {
-        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T6, cfg_info->data[MBTK_ECALL_CFG_ITEM_T6], cme_err)
+        if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T6, cfg_info->data[MBTK_ECALL_CFG_ITEM_T6], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -692,7 +694,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T7) {
-        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T7, cfg_info->data[MBTK_ECALL_CFG_ITEM_T7], cme_err)
+        if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T7, cfg_info->data[MBTK_ECALL_CFG_ITEM_T7], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -700,7 +702,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_TH) {
-        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_TH, cfg_info->data[MBTK_ECALL_CFG_ITEM_TH], cme_err)
+        if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_TH, cfg_info->data[MBTK_ECALL_CFG_ITEM_TH], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -709,14 +711,14 @@
 
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CALLBACK)
     {
-        if(cfg_ecalltimer_set(port, "callback", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "callback", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CLEARDOWN)
     {
-        if(cfg_ecalltimer_set(port, "cleardown", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "cleardown", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
@@ -724,49 +726,49 @@
 
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_DEREG)
     {
-        if(cfg_ecalltimer_set(port, "dereg", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "dereg", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_DIAL)
     {
-        if(cfg_ecalltimer_set(port, "dial", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "dial", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_REDIAL)
     {
-        if(cfg_ecalltimer_set(port, "redialtmr", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "redialtmr", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_SMS)
     {
-        if(cfg_ecalltimer_set(port, "sms", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] / 1000, cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "sms", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_REDIALCNT)
     {
-        if(cfg_ecalltimer_set(port, "redialcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_REDIALCNT], cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "redialcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_REDIALCNT], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_SMSPROCESS)
     {
-        if(cfg_ecalltimer_set(port, "smsprocess", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS], cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "smsprocess", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_SMSMSDCNT)
     {
-        if(cfg_ecalltimer_set(port, "smsmsdcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT], cme_err)
+        if(cfg_ecalltimer_set(sim_id, port, "smsmsdcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
@@ -781,12 +783,12 @@
 OK
 
 */
-static int req_ecall_spkmute_set(ATPortType_enum port, int mute, int *cme_err)
+static int req_ecall_spkmute_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int mute, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*ECALLMUTESPK=%d", mute);
-    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);
         goto exit;
@@ -805,11 +807,11 @@
 OK
 
 */
-static int req_ecall_sms_num_get(ATPortType_enum port, uint8 *number, int *cme_err)
+static int req_ecall_sms_num_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 *number, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -844,12 +846,12 @@
 OK
 
 */
-static int req_ecall_sms_num_set(ATPortType_enum port, const uint8 *number, int *cme_err)
+static int req_ecall_sms_num_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const uint8 *number, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*ECALLSMSNUM=%s", number);
-    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);
         goto exit;
@@ -865,12 +867,12 @@
 OK
 
 */
-static int req_ecall_gain_set(ATPortType_enum port, mbtk_ecall_gain_info_t *gain, int *cme_err)
+static int req_ecall_gain_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_gain_info_t *gain, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*AUDGAIN=%d,%d", gain->gain, gain->mode);
-    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);
         goto exit;
@@ -899,7 +901,7 @@
             else     // Set
             {
                 mbtk_ecall_msd_cfg_info_t *cfg_info = (mbtk_ecall_msd_cfg_info_t*)(pack->data);
-                if(req_ecall_msdcfg(cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msdcfg(cli_info->sim_id, cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -910,7 +912,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);
                 }
             }
             break;
@@ -919,7 +921,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_msdgen(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msdgen(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -930,7 +932,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);
                 }
             }
             else     // Set
@@ -945,7 +947,7 @@
             memset(msd, 0, sizeof(msd));
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_msd_get(cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msd_get(cli_info->sim_id, cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -956,13 +958,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
                 }
             }
             else     // Set
             {
                 memcpy(msd, pack->data, pack->data_len);
-                if(req_ecall_msd_set(cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msd_set(cli_info->sim_id, cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -973,7 +975,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);
                 }
             }
             break;
@@ -982,7 +984,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_push(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_push(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -993,7 +995,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);
                 }
             }
             else     // Set
@@ -1008,7 +1010,7 @@
             {
                 mbtk_ecall_only_info_t only_info;
                 memset(&only_info, 0, sizeof(mbtk_ecall_only_info_t));
-                if(req_ecall_only_get(cli_info->port, &only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_only_get(cli_info->sim_id, cli_info->port, &only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1019,13 +1021,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
                 }
             }
             else     // Set
             {
                 mbtk_ecall_only_info_t *only_info = (mbtk_ecall_only_info_t*)(pack->data);
-                if(req_ecall_only_set(cli_info->port, only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_only_set(cli_info->sim_id, cli_info->port, only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1036,7 +1038,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);
                 }
             }
             break;
@@ -1050,7 +1052,7 @@
             else
             {
                 uint8 reg = pack->data[0];
-                if(req_ecall_reg_set(cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_reg_set(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1061,7 +1063,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);
                 }
             }
             break;
@@ -1071,7 +1073,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 mbtk_ecall_dial_type_enum type;
-                if(req_ecall_dial_state_get(cli_info->port, &type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_dial_state_get(cli_info->sim_id, cli_info->port, &type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1082,13 +1084,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
                 }
             }
             else
             {
                 mbtk_ecall_dial_type_enum type = (mbtk_ecall_dial_type_enum)pack->data[0];
-                if(req_ecall_dial_start(cli_info->port, type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_dial_start(cli_info->sim_id, cli_info->port, type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1099,7 +1101,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);
                 }
             }
             break;
@@ -1109,7 +1111,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 mbtk_ecall_mode_type_enum mode;
-                if(req_ecall_mode_get(cli_info->port, &mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_mode_get(cli_info->sim_id, cli_info->port, &mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1120,13 +1122,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
                 }
             }
             else
             {
                 mbtk_ecall_mode_type_enum mode = (mbtk_ecall_mode_type_enum)pack->data[0];
-                if(req_ecall_mode_set(cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_mode_set(cli_info->sim_id, cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1137,7 +1139,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);
                 }
             }
             break;
@@ -1152,7 +1154,7 @@
             {
                 if(pack->data_len == sizeof(mbtk_ecall_cfg_info_t)) { // Set
                     mbtk_ecall_cfg_info_t *cfg_info = (mbtk_ecall_cfg_info_t*)pack->data;
-                    if(req_ecall_cfg_set(cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_ecall_cfg_set(cli_info->sim_id, cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1163,13 +1165,13 @@
                     }
                     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);
                     }
                 } else { // Get
                     mbtk_ecall_cfg_info_t cfg_info;
                     memset(&cfg_info, 0, sizeof(mbtk_ecall_cfg_info_t));
                     uint32 *type = (uint32*)(pack->data);
-                    if(req_ecall_cfg_get(cli_info->port, *type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_ecall_cfg_get(cli_info->sim_id, cli_info->port, *type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1180,7 +1182,7 @@
                     }
                     else
                     {
-                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
+                        ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
                     }
                 }
             }
@@ -1192,7 +1194,7 @@
             memset(number, 0, sizeof(number));
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_sms_num_get(cli_info->port, number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_sms_num_get(cli_info->sim_id, cli_info->port, number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1203,13 +1205,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
                 }
             }
             else     // Set
             {
                 memcpy(number, pack->data, pack->data_len);
-                if(req_ecall_sms_num_set(cli_info->port, number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_sms_num_set(cli_info->sim_id, cli_info->port, number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1220,7 +1222,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);
                 }
             }
             break;
@@ -1241,7 +1243,7 @@
                     break;
                 }
 
-                if(req_ecall_spkmute_set(cli_info->port, mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_spkmute_set(cli_info->sim_id, cli_info->port, mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1252,7 +1254,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);
                 }
             }
             break;
@@ -1266,7 +1268,7 @@
             else     // Set
             {
                 mbtk_ecall_gain_info_t *gain_info = (mbtk_ecall_gain_info_t *)pack->data;
-                if(req_ecall_gain_set(cli_info->port, gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_gain_set(cli_info->sim_id, cli_info->port, gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1277,7 +1279,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);
                 }
             }
             break;
diff --git a/mbtk/mbtk_rild_v2/src/ril_net.c b/mbtk/mbtk_rild_v2/src/ril_net.c
index 7042954..7935352 100755
--- a/mbtk/mbtk_rild_v2/src/ril_net.c
+++ b/mbtk/mbtk_rild_v2/src/ril_net.c
@@ -23,7 +23,9 @@
 mbtk_cell_pack_info_t cell_info;
 
 extern ril_band_info_t band_info;
-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);
+
 
 static bool net_support_check(uint32 net_type, uint32 net_flag)
 {
@@ -37,10 +39,10 @@
 
 OK
 */
-static int req_available_net_get(ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err)
+static int req_available_net_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_singleline(port, "AT+COPS=?", "+COPS:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS=?", "+COPS:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
@@ -135,14 +137,14 @@
 OK
 
 */
-static int req_net_sel_mode_get(ATPortType_enum port, mbtk_net_info_t *net, int *cme_err)
+static int req_net_sel_mode_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_t *net, int *cme_err)
 {
     //LOG("req_net_sel_mode_get() 0");
     //sleep(1);
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS?", "+COPS:", &response);
     //LOG("req_net_sel_mode_get() 00");
     //sleep(1);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -221,7 +223,7 @@
 OK
 
 */
-static int req_net_sel_mode_set(ATPortType_enum port, mbtk_net_info_t* net, int *cme_err)
+static int req_net_sel_mode_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_t* net, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[50] = {0};
@@ -238,7 +240,7 @@
         }
      }
 
-    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) {
         if(cme_err) {
@@ -257,7 +259,7 @@
 OK
 
 */
-int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err)
+int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
@@ -352,7 +354,7 @@
         }
         if(band->net_pref == 0xFF) { // No change net_pref.
             int tmp_int;
-            err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
+            err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*BAND?", "*BAND:", &response);
             if (err < 0 || response->success == 0 || !response->p_intermediates){
                 if(cme_err) {
                     *cme_err = at_get_cme_error(response);
@@ -394,7 +396,7 @@
             }
         }
     }
-    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){
         if(cme_err) {
@@ -479,13 +481,13 @@
     65536 ?C FDDLTE _BAND_17
     524288 ?C FDDLTE _BAND_20
 */
-static int req_band_get(ATPortType_enum port, mbtk_band_info_t *band, int *cme_err)
+static int req_band_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t *band, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
 
     log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
-    int err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*BAND?", "*BAND:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -626,13 +628,13 @@
 OK
 
 */
-static int req_net_signal_get(ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err)
+static int req_net_signal_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_ptr = NULL;
     // AT+EEMOPT=1 in the first.
-    int err = at_send_command_singleline(port, "AT+CSQ", "+CSQ:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CSQ", "+CSQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -654,7 +656,7 @@
     signal->rssi = (uint8)tmp_int;
     at_response_free(response);
 
-    err = at_send_command_singleline(port, "AT+CESQ", "+CESQ:", &response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CESQ", "+CESQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -736,7 +738,7 @@
     }
 
     at_response_free(response);
-    err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS?", "+COPS:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -811,12 +813,12 @@
 
 
 */
-static int req_net_reg_get(ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err)
+static int req_net_reg_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_str = NULL;
-    int err = at_send_command(port, "AT+CREG=3", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT+CREG=3", &response);
     if (err < 0 || response->success == 0){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -825,7 +827,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline(port, "AT+CREG?", "+CREG:", &response);
+    err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CREG?", "+CREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -875,7 +877,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline(port, "AT+CEREG?", "+CEREG:", &response);
+    err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CEREG?", "+CEREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -924,7 +926,7 @@
         reg->type = (uint8)tmp_int;
     } else if(reg->data_state == 0 && (band_info.net_support & MBTK_NET_SUPPORT_5G)) {
         at_response_free(response);
-        err = at_send_command_multiline(port, "AT+C5GREG?", "+C5GREG:", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+C5GREG?", "+C5GREG:", &response);
         if (err < 0 || response->success == 0 || !response->p_intermediates){
             if(cme_err) {
                 *cme_err = at_get_cme_error(response);
@@ -975,7 +977,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline(port, "AT+CIREG?", "+CIREG:", &response);
+    err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CIREG?", "+CIREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         reg->ims_state = (uint8)0;
         err = 0;
@@ -1207,13 +1209,13 @@
 OK
 
 */
-static int req_cell_info_get(ATPortType_enum port, int *cme_err)
+static int req_cell_info_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     int buff_size = 0;
     // AT+EEMOPT=1 in the first.
-    int err = at_send_command(port, "AT+EEMOPT=1", &response);
+    int err = at_send_command(portType_2_portId(sim_id, port), "AT+EEMOPT=1", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -1224,7 +1226,7 @@
     cell_info.running = true;
     cell_info.cell_list.num = 0;
 
-    err = at_send_command_singleline(port, "AT+EEMGINFO?", "+EEMGINFO:", &response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+EEMGINFO?", "+EEMGINFO:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -1315,7 +1317,7 @@
     return buff_size;
 }
 
-static int req_cell_info_set(ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
+static int req_cell_info_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[500] = {0};
@@ -1328,7 +1330,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-        err = at_send_command_multiline(port, cmd, "", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "", &response);
 		if (err < 0 || response->success == 0 || !response->p_intermediates){
 			*cme_err = at_get_cme_error(response);
 			goto exit;
@@ -1374,7 +1376,7 @@
 ƽ̨±¾ÉíÊÇÓÐÒ»Ì×¼ä¸ôËÑÍø£¬Ò²ÓÐÀúʷƵµãÓÅÏÈ´¦ÀíµÄÂß¼­£¨²»ÐèÒªÎÒÃǽøÐд¦Àí£©£¬
 Ìṩ¸øÎÒÃǵÄAT+OOSPPÖ¸ÁîÊÇÈÃÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåËÑÍø¼ä¸ô
 */
-static int req_oos_set(ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err)
+static int req_oos_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
@@ -1407,7 +1409,7 @@
     }
 
     LOGI("Set the oos command is = [%s]\n", cmd);
-    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;
@@ -1425,11 +1427,11 @@
 ¹Ø£º
 +OOSPP:0
 */
-static int req_oos_get(ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err)
+static int req_oos_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err)
 {
     ATResponse *response = NULL;
 
-    int err = at_send_command_singleline(port, "AT+OOSPP?", "+OOSPP:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+OOSPP?", "+OOSPP:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -1501,7 +1503,7 @@
             {
                 mbtk_net_info_array_t net_array;
                 memset(&net_array, 0, sizeof(mbtk_net_info_array_t));
-                if(req_available_net_get(cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_available_net_get(cli_info->sim_id, cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1512,7 +1514,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
                 }
             }
             else     // Set
@@ -1528,7 +1530,7 @@
             {
                 mbtk_net_info_t info;
                 memset(&info, 0, sizeof(mbtk_net_info_t));
-                if(req_net_sel_mode_get(cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_sel_mode_get(cli_info->sim_id, cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1539,13 +1541,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
                 }
             }
             else     // Set
             {
                 mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data;
-                if(req_net_sel_mode_set(cli_info->port, info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_sel_mode_set(cli_info->sim_id, cli_info->port, info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1556,7 +1558,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);
                 }
             }
             break;
@@ -1574,7 +1576,7 @@
                     if(*(pack->data)) { // Get current bands.
                         mbtk_band_info_t band;
                         memset(&band, 0x0, sizeof(mbtk_band_info_t));
-                        if(req_band_get(cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_band_get(cli_info->sim_id, cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             if(cme_err != MBTK_RIL_ERR_CME_NON) {
                                 err = MBTK_RIL_ERR_CME + cme_err;
@@ -1585,10 +1587,10 @@
                         }
                         else
                         {
-                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
+                            ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
                         }
                     } else { // Get support bands.
-                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support, sizeof(mbtk_band_info_t));
+                        ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support, sizeof(mbtk_band_info_t));
                     }
                 } else { // Set current bands.
                     mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
@@ -1599,7 +1601,7 @@
                         break;
                     }
 
-                    if(req_band_set(cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_band_set(cli_info->sim_id, cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1610,7 +1612,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);
                     }
                 }
             }
@@ -1622,7 +1624,7 @@
             {
                 mbtk_signal_info_t signal;
                 memset(&signal, 0, sizeof(mbtk_signal_info_t));
-                if(req_net_signal_get(cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_signal_get(cli_info->sim_id, cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1633,7 +1635,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
                 }
             }
             else     // Set
@@ -1649,7 +1651,7 @@
             {
                 mbtk_net_reg_info_t net_reg;
                 memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t));
-                if(req_net_reg_get(cli_info->port, &net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_reg_get(cli_info->sim_id, cli_info->port, &net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1660,7 +1662,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
                 }
             }
             else     // Set
@@ -1674,7 +1676,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)   // Get net cell.
             {
-                if(req_cell_info_get(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cell_info_get(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1687,7 +1689,7 @@
                 {
                     LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num);
                     LOGD("data_len = %d", sizeof(mbtk_cell_info_array_t));
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cell_info.cell_list, sizeof(mbtk_cell_info_array_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cell_info.cell_list, sizeof(mbtk_cell_info_array_t));
                 }
             }
             else     // Lock cell
@@ -1695,7 +1697,7 @@
                 char *mem = (char*)(pack->data);
                 int len = pack->data_len;
                 char reg[100] = {0};
-                if(req_cell_info_set(cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cell_info_set(cli_info->sim_id, cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1705,7 +1707,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             break;
@@ -1716,7 +1718,7 @@
             {
                 mbtk_ril_oos_info_t oos_info;
                 memset(&oos_info, 0, sizeof(mbtk_ril_oos_info_t));
-                if(req_oos_get(cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_oos_get(cli_info->sim_id, cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1728,13 +1730,13 @@
                 else
                 {
                     LOG("req_oos_get() success,cell number: %d", oos_info.state);
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t));
                 }
             }
             else     // Set net oos.
             {
                 mbtk_ril_oos_info_t *oos_info = (mbtk_ril_oos_info_t*)(pack->data);
-                if(req_oos_set(cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_oos_set(cli_info->sim_id, cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1744,7 +1746,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);
                 }
             }
             break;
diff --git a/mbtk/mbtk_rild_v2/src/ril_pb.c b/mbtk/mbtk_rild_v2/src/ril_pb.c
index 1d93cc9..e6b7c23 100755
--- a/mbtk/mbtk_rild_v2/src/ril_pb.c
+++ b/mbtk/mbtk_rild_v2/src/ril_pb.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);
 
 //void net_list_free(void *data);
 // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
diff --git a/mbtk/mbtk_rild_v2/src/ril_sim.c b/mbtk/mbtk_rild_v2/src/ril_sim.c
index fc9221e..a0fc554 100755
--- a/mbtk/mbtk_rild_v2/src/ril_sim.c
+++ b/mbtk/mbtk_rild_v2/src/ril_sim.c
@@ -17,10 +17,11 @@
 #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);
 
 /** Returns SIM_NOT_READY on error */
-mbtk_sim_state_enum ril_sim_state_get(ATPortType_enum port)
+mbtk_sim_state_enum ril_sim_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port)
 {
     ATResponse *p_response = NULL;
     int err;
@@ -28,7 +29,7 @@
     char *cpinLine;
     char *cpinResult;
 
-    err = at_send_command_singleline(port, "AT+CPIN?", "+CPIN:", &p_response);
+    err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CPIN?", "+CPIN:", &p_response);
 
     if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
     {
@@ -144,7 +145,7 @@
     at_response_free(p_response);
     p_response = NULL;
     cpinResult = NULL;
-    ril_info.sim_state = ret;
+    ril_info.sim_state[sim_id] = ret;
     return ret;
 }
 
@@ -154,11 +155,11 @@
 
 OK
 */
-static int req_sim_type_get(ATPortType_enum port, uint8 *type, int *cme_err)
+static int req_sim_type_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 *type, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT*EUICC?", "*EUICC:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*EUICC?", "*EUICC:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -191,11 +192,11 @@
 
 OK
 */
-static int req_iccid_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_iccid_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+ICCID", "+ICCID:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+ICCID", "+ICCID:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -228,11 +229,11 @@
 OK
 
 */
-static int req_phone_number_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_phone_number_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+CNUM?", "+CNUM:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CNUM?", "+CNUM:", &response);
     if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
         if(response) {
             *cme_err = at_get_cme_error(response);
@@ -278,10 +279,10 @@
 OK
 
 */
-static int req_imsi_get(ATPortType_enum port, void *data, int *cme_err)
+static int req_imsi_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+CIMI", &response);
+    int err = at_send_command_numeric(portType_2_portId(sim_id, port), "AT+CIMI", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -294,12 +295,12 @@
     return err;
 }
 
-static int req_sim_lock_state_get(ATPortType_enum port, int *state, int *cme_err)
+static int req_sim_lock_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char cmd[64]={0};
 
-    int err = at_send_command_singleline(port, "AT+CLCK=SC,2", "+CLCK:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CLCK=SC,2", "+CLCK:", &response);
     if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
         if(response) {
             *cme_err = at_get_cme_error(response);
@@ -343,12 +344,12 @@
 
 *
 */
-static int req_sim_lock_switch(ATPortType_enum port, bool enable, uint8* pin, int *cme_err)
+static int req_sim_lock_switch(mbtk_sim_type_enum sim_id, ATPortType_enum port, bool enable, uint8* pin, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[64]={0};
     snprintf(cmd, sizeof(cmd), "AT+CLCK=SC,%d,%s", enable ? 1 : 0, pin);
-    int err = at_send_command_singleline(port, cmd, "+CLCK:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), cmd, "+CLCK:", &response);
     if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
         if(response) {
             *cme_err = at_get_cme_error(response);
@@ -393,22 +394,22 @@
     return err;
 }
 
-static int req_sim_pin_change(ATPortType_enum port, uint8* old_pin, uint8 *new_pin, int *cme_err)
+static int req_sim_pin_change(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8* old_pin, uint8 *new_pin, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[128]={0};
     int err = 0;
     int state;
-    if(req_sim_lock_state_get(port, &state, cme_err) || *cme_err != MBTK_RIL_ERR_CME_NON)
+    if(req_sim_lock_state_get(sim_id, port, &state, cme_err) || *cme_err != MBTK_RIL_ERR_CME_NON)
     {
         return -1;
     }
 
     if(state == 0) { // Sim lock not open.
-        return req_sim_lock_switch(port, TRUE, new_pin, cme_err);
+        return req_sim_lock_switch(sim_id, port, TRUE, new_pin, cme_err);
     } else {// Change password.
         snprintf(cmd, sizeof(cmd), "AT+CPWD=SC,%s,%s", old_pin, new_pin);
-        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){
             if(cme_err) {
                 *cme_err = at_get_cme_error(response);
@@ -422,12 +423,12 @@
     return err;
 }
 
-static int req_sim_pin_verify(ATPortType_enum port, uint8* pin, int *cme_err)
+static int req_sim_pin_verify(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8* pin, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[64]={0};
     sprintf(cmd, "AT+CPIN=%s", pin);
-    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){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -440,12 +441,12 @@
     return err;
 }
 
-static int req_sim_puk_verify(ATPortType_enum port, uint8* puk, uint8* pin, int *cme_err)
+static int req_sim_puk_verify(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8* puk, uint8* pin, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[64]={0};
     sprintf(cmd, "AT+CPIN=%s,%s", puk, pin);
-    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){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -458,29 +459,29 @@
     return err;
 }
 
-static int req_sim_lock_set(ATPortType_enum port, mbtk_sim_lock_info_t *lock_info, int *cme_err)
+static int req_sim_lock_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_sim_lock_info_t *lock_info, int *cme_err)
 {
     switch(lock_info->type)
     {
         case MBTK_SIM_LOCK_TYPE_DISABLE:
         {
-            return req_sim_lock_switch(port, FALSE, lock_info->pin1, cme_err);
+            return req_sim_lock_switch(sim_id, port, FALSE, lock_info->pin1, cme_err);
         }
         case MBTK_SIM_LOCK_TYPE_ENABLE:
         {
-            return req_sim_lock_switch(port, TRUE, lock_info->pin1, cme_err);
+            return req_sim_lock_switch(sim_id, port, TRUE, lock_info->pin1, cme_err);
         }
         case MBTK_SIM_LOCK_TYPE_CHANGE:
         {
-            return req_sim_pin_change(port, lock_info->pin1, lock_info->pin2, cme_err);
+            return req_sim_pin_change(sim_id, port, lock_info->pin1, lock_info->pin2, cme_err);
         }
         case MBTK_SIM_LOCK_TYPE_VERIFY_PIN:
         {
-            return req_sim_pin_verify(port, lock_info->pin1, cme_err);
+            return req_sim_pin_verify(sim_id, port, lock_info->pin1, cme_err);
         }
         case MBTK_SIM_LOCK_TYPE_VERIFY_PUK:
         {
-            return req_sim_puk_verify(port, lock_info->puk, lock_info->pin1, cme_err);
+            return req_sim_puk_verify(sim_id, port, lock_info->puk, lock_info->pin1, cme_err);
         }
         default:
         {
@@ -498,12 +499,12 @@
 
 OK
 */
-static int req_pin_puk_last_times_get(ATPortType_enum port, mbtk_pin_puk_last_times_t *times, int *cme_err)
+static int req_pin_puk_last_times_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_pin_puk_last_times_t *times, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
     int tmp_int;
-    int err = at_send_command_singleline(port, "AT+EPIN?", "+EPIN:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+EPIN?", "+EPIN:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -558,11 +559,11 @@
 
 OK
 */
-static int req_plmn_get(ATPortType_enum port, mbtk_plmn_info *info, int *cme_err)
+static int req_plmn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_plmn_info *info, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_multiline(port, "AT+CPOL?", "+CPOL:", &response);
+    int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CPOL?", "+CPOL:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -614,6 +615,69 @@
     return err;
 }
 
+/*
+>AT+SWITCHSIM?
+<+SWITCHSIM: 0
+
+<OK
+*/
+int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err)
+{
+    ATResponse *response = NULL;
+//    char *tmp_ptr = NULL;
+    int err = at_send_command_singleline(portType_2_portId(MBTK_SIM_1, port), "AT+SWITCHSIM?", "+SWITCHSIM:", &response);
+
+    if (err < 0 || response->success == 0 || !response->p_intermediates){
+        if(cme_err) {
+            *cme_err = at_get_cme_error(response);
+        }
+        goto exit;
+    }
+
+    char *line = response->p_intermediates->line;
+    err = at_tok_start(&line);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    int tmp_int = -1;
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    if(tmp_int != -1)
+        *sim_id = tmp_int;
+    goto exit;
+exit:
+    at_response_free(response);
+    return err;
+}
+
+/*
+>AT+SWITCHSIM?
+<+SWITCHSIM: 0
+
+<OK
+*/
+static int req_dual_sim_set(ATPortType_enum port, mbtk_sim_type_enum sim_id, int *cme_err)
+{
+    int err = -1;
+    ATResponse *response = NULL;
+
+    char cmd[64] = {0};
+    snprintf(cmd, sizeof(cmd), "AT+SWITCHSIM=%d", sim_id);
+    err = at_send_command(portType_2_portId(MBTK_SIM_1, port), cmd, &response);
+    if (err < 0 || response->success == 0){
+        *cme_err = at_get_cme_error(response);
+        goto exit;
+    }
+
+exit:
+    at_response_free(response);
+    return err;
+}
+
 //void net_list_free(void *data);
 // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
 // Otherwise, do not call pack_error_send().
@@ -627,7 +691,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                mbtk_sim_state_enum state = ril_sim_state_get(cli_info->port);
+                mbtk_sim_state_enum state = ril_sim_state_get(cli_info->sim_id, cli_info->port);
                 if(state == MBTK_SIM_STATE_UNKNOWN)
                 {
                     err = MBTK_RIL_ERR_UNKNOWN;
@@ -635,7 +699,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
@@ -650,7 +714,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 uint8 sim_card_type;
-                if(req_sim_type_get(cli_info->port, &sim_card_type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_sim_type_get(cli_info->sim_id, cli_info->port, &sim_card_type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -661,7 +725,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &sim_card_type, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &sim_card_type, sizeof(uint8));
                 }
             }
             else     // Set
@@ -676,7 +740,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char imsi[20] = {0};
-                if(req_imsi_get(cli_info->port, imsi, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_imsi_get(cli_info->sim_id, cli_info->port, imsi, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -687,7 +751,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imsi, strlen(imsi));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imsi, strlen(imsi));
                 }
             }
             else     // Set
@@ -702,7 +766,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char pn[50] = {0};
-                if(req_phone_number_get(cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_phone_number_get(cli_info->sim_id, cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -713,7 +777,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, pn, strlen(pn));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, pn, strlen(pn));
                 }
             }
             else     // Set
@@ -728,7 +792,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 char iccid[50] = {0};
-                if(req_iccid_get(cli_info->port, iccid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_iccid_get(cli_info->sim_id, cli_info->port, iccid, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -739,7 +803,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, iccid, strlen(iccid));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, iccid, strlen(iccid));
                 }
             }
             else     // Set
@@ -754,7 +818,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 int state;
-                if(req_sim_lock_state_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_sim_lock_state_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;
@@ -765,13 +829,13 @@
                 }
                 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
             {
                 mbtk_sim_lock_info_t *lock_info = (mbtk_sim_lock_info_t*)pack->data;
-                if(req_sim_lock_set(cli_info->port, lock_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_sim_lock_set(cli_info->sim_id, cli_info->port, lock_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -782,7 +846,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);
                 }
             }
             break;
@@ -792,7 +856,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 mbtk_pin_puk_last_times_t last_times;
-                if(req_pin_puk_last_times_get(cli_info->port, &last_times, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_pin_puk_last_times_get(cli_info->sim_id, cli_info->port, &last_times, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -803,7 +867,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &last_times, sizeof(mbtk_pin_puk_last_times_t));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &last_times, sizeof(mbtk_pin_puk_last_times_t));
                 }
             }
             else     // Set
@@ -819,7 +883,7 @@
             {
                 mbtk_plmn_info info;
                 memset(&info, 0, sizeof(mbtk_plmn_info));
-                if(req_plmn_get(cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_plmn_get(cli_info->sim_id, cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -830,7 +894,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_plmn_info));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_plmn_info));
                 }
             }
             else     // Set
@@ -840,6 +904,45 @@
             }
             break;
         }
+        case RIL_MSG_ID_SIM_SWITCH:
+        {
+            if(pack->data_len == 0 || pack->data == NULL)
+            {
+                mbtk_sim_type_enum sim_id;
+                if(req_dual_sim_get(cli_info->port, &sim_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                {
+                    if(cme_err != MBTK_RIL_ERR_CME_NON) {
+                        err = MBTK_RIL_ERR_CME + cme_err;
+                    } else {
+                        err = MBTK_RIL_ERR_UNKNOWN;
+                    }
+                    LOG("Get SWITCHSIM fail.");
+                }
+                else
+                {
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &sim_id, sizeof(mbtk_sim_type_enum));
+                }
+            }
+            else     // Set
+            {
+                mbtk_sim_type_enum *sim_id = (mbtk_sim_type_enum*)pack->data;
+                if(req_dual_sim_set(cli_info->port, *sim_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                {
+                    if(cme_err != MBTK_RIL_ERR_CME_NON) {
+                        err = MBTK_RIL_ERR_CME + cme_err;
+                    } else {
+                        err = MBTK_RIL_ERR_UNKNOWN;
+                    }
+                    LOG("Set SWITCHSIM fail.");
+                }
+                else
+                {
+                    ril_info.cur_sim_id = *sim_id;
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                }
+            }
+            break;
+        }
         default:
         {
             err = MBTK_RIL_ERR_REQ_UNKNOWN;
diff --git a/mbtk/mbtk_rild_v2/src/ril_sms.c b/mbtk/mbtk_rild_v2/src/ril_sms.c
index 8ed30f4..50c7acd 100755
--- a/mbtk/mbtk_rild_v2/src/ril_sms.c
+++ b/mbtk/mbtk_rild_v2/src/ril_sms.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+CMGF?
@@ -26,11 +27,11 @@
 OK
 
 */
-static int req_cmgf_get(ATPortType_enum port, int *state, int *cme_err)
+static int req_cmgf_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+CMGF?", "", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CMGF?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -61,7 +62,7 @@
 
 OK
 */
-static int req_cmgf_set(ATPortType_enum port, int state, int *cme_err)
+static int req_cmgf_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err)
 {
     LOGD("req_cmgf_set()-------------start");
     LOGD("state:%d",state);
@@ -77,7 +78,7 @@
     }
 
     LOGD("req_cmgf_set()----cmd:%s", cmd);
-    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);
@@ -91,7 +92,7 @@
 }
 
 /*set AT+CNMI=1,2*/
-static int req_cnmi_set(ATPortType_enum port, int *cme_err)
+static int req_cnmi_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
 {
     printf("req_cnmi_set()-------------start3\n");
     ATResponse *response = NULL;
@@ -100,7 +101,7 @@
 	strcpy(cmd, "AT+CNMI=1,2");
 
     printf("req_cnmi_set()----cmd:%s\n", cmd);
-    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) {
 		printf("err:%d, response->success:%d \n", err, response->success);
@@ -123,12 +124,12 @@
 OK
 
 */
-static int req_cpms_get(ATPortType_enum port, char *reg, int *cme_err)
+static int req_cpms_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *reg, int *cme_err)
 {
 	printf("req_cpms_get------------start(3)\n");
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+CPMS?", "", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CPMS?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -170,7 +171,7 @@
 OK
 
 */
-static int req_cpms_set(ATPortType_enum port, const char *mem, char *reg, int len, int *cme_err)
+static int req_cpms_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char *mem, char *reg, int len, int *cme_err)
 {
     printf("req_cpms_set(2)----------------start\n");
     printf("mem:%s\n", mem);
@@ -192,7 +193,7 @@
 
 	if(strlen(cmd) > 8)
 	{
-        err = at_send_command_multiline(port, cmd, "+CPMS:", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "+CPMS:", &response);
         if (err < 0 || response->success == 0){
             *cme_err = at_get_cme_error(response);
             goto exit;
@@ -226,7 +227,7 @@
 */
 #define MBTK_AT_MAX_SMS_NUM 4
 #define MBTK_AT_SMS_MAX_LEN 160*MBTK_AT_MAX_SMS_NUM
-static int req_cmgs_set(ATPortType_enum port, char *cmgs, char *reg, int len, int *cme_err)
+static int req_cmgs_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *cmgs, char *reg, int len, int *cme_err)
 {
     LOGD("req_cmgs_set()----------------start");
     LOGD("cmgs:%s", cmgs);
@@ -260,7 +261,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-		int err = at_send_command_sms(port, cmd, data, "+CMGS: ", &response);
+		int err = at_send_command_sms(portType_2_portId(sim_id, port), cmd, data, "+CMGS: ", &response);
 		LOGD("err:%d, response:%d", err, response->success);
 
 		if (err < 0 || response->success == 0) {
@@ -279,7 +280,7 @@
     return err;
 }
 
-static int req_cmgw_set(ATPortType_enum port, char *cmgw,int len, int *cme_err)
+static int req_cmgw_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *cmgw,int len, int *cme_err)
 {
     printf("req_cmgw_set()----------------start\n");
     printf("cmgw:%s\n", cmgw);
@@ -305,7 +306,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-		int err = at_send_command_sms(port, cmd, data, "+CMGW: ", &response);
+		int err = at_send_command_sms(portType_2_portId(sim_id, port), cmd, data, "+CMGW: ", &response);
 		printf("err:%d, response:%d\n", err, response->success);
 
 		if (err < 0 || response->success == 0) {
@@ -328,7 +329,7 @@
 
 +MMSG: 1, 0
 */
-static int req_cmgd_set(ATPortType_enum port, char *cmgd, int len, int *cme_err)
+static int req_cmgd_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *cmgd, int len, int *cme_err)
 {
     printf("0req_cmgd_set()--------------start\n");
     printf("cmgd:%s\n", cmgd);
@@ -345,7 +346,7 @@
 
 	if(strlen(cmd) > 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);
 	        goto exit;
@@ -370,11 +371,11 @@
 OK
 
 */
-static int req_cmgd_get(ATPortType_enum port, char *reg, int *cme_err)
+static int req_cmgd_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *reg, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+CMGD=?", "+CMGD:", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CMGD=?", "+CMGD:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -418,7 +419,7 @@
 
 */
 
-static int req_cmgl_set(ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
+static int req_cmgl_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
 {
     printf("req_cmgl_set(2)-----------------start\n");
     printf("cmgl:%s\n", cmgl);
@@ -461,7 +462,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-        err = at_send_command_multiline(port, cmd, "", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "", &response);
 		if (err < 0 || response->success == 0 || !response->p_intermediates){
 			*cme_err = at_get_cme_error(response);
             printf("at_send_command_multiline() is err-----------------\n");
@@ -532,11 +533,11 @@
 +CSCA: "+8613800280500",145
 OK
 */
-static int req_csca_get(ATPortType_enum port, char *req, int *cme_err)
+static int req_csca_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *req, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
-    int err = at_send_command_singleline(port, "AT+CSCA?", "", &response);
+    int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CSCA?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -563,7 +564,7 @@
     return err;
 }
 
-static int req_csca_set(ATPortType_enum port, char *csca, int len, int *cme_err)
+static int req_csca_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *csca, int len, int *cme_err)
 {
     printf("req_csca_set()--------------start\n");
     printf("csca:%s\n", csca);
@@ -580,7 +581,7 @@
 
 	if(strlen(cmd) > 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);
 	        goto exit;
@@ -596,7 +597,7 @@
     return err;
 }
 
-static int req_csmp_set(ATPortType_enum port, char *csmp, int len, int *cme_err)
+static int req_csmp_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *csmp, int len, int *cme_err)
 {
     printf("req_csmp_set()-------------------start\n");
     printf("csmp:%s\n", csmp);
@@ -613,7 +614,7 @@
 
 	if(strlen(cmd) > 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);
 	        goto exit;
@@ -629,7 +630,7 @@
     return err;
 }
 
-static int req_cscb_set(ATPortType_enum port, char *cscb,int len, int *cme_err)
+static int req_cscb_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *cscb,int len, int *cme_err)
 {
     printf("req_cscb_set()----------------start\n");
     printf("cscb:%s\n", cscb);
@@ -646,7 +647,7 @@
 
 	if(strlen(cmd) > 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);
 	        goto exit;
@@ -667,7 +668,7 @@
 +CMSS: 81
 OK
 */
-static int req_cmss_set(ATPortType_enum port, const char *cmss, char *reg, int len, int *cme_err)
+static int req_cmss_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char *cmss, char *reg, int len, int *cme_err)
 {
     printf("req_cmss_set()----------------start\n");
     printf("cmss:%s\n", cmss);
@@ -690,7 +691,7 @@
 
 	if(strlen(cmd) > 8)
 	{
-        err = at_send_command_multiline(port, cmd, "+CMSS:", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "+CMSS:", &response);
 		if (err < 0 || response->success == 0){
 			*cme_err = at_get_cme_error(response);
 			goto exit;
@@ -735,7 +736,7 @@
 
 OK
 */
-static int req_cmgr_set(ATPortType_enum port, int index, char *reg, int *cme_err)
+static int req_cmgr_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int index, char *reg, int *cme_err)
 {
     printf("0req_cmgr_set()-------------------start\n");
     printf("index:%d\n", index);
@@ -748,7 +749,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-        err = at_send_command_multiline(port, cmd, "", &response);
+        err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "", &response);
 		if (err < 0 || response->success == 0 || !response->p_intermediates){
 			*cme_err = at_get_cme_error(response);
             printf("at_send_command_multiline() is err-----------------\n");
@@ -800,7 +801,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 int state;
-                if(req_cmgf_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgf_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;
@@ -811,7 +812,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.
@@ -824,7 +825,7 @@
                     break;
                 }
 
-                if(req_cmgf_set(cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgf_set(cli_info->sim_id, cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -835,7 +836,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);
                 }
             }
             break;
@@ -845,7 +846,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // SET at+cnmi=1,2.
             {
 //                int state;
-                if(req_cnmi_set(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cnmi_set(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -856,7 +857,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);
                 }
             }
 			break;
@@ -866,7 +867,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 char reg[100] = {0};
-                if(req_cpms_get(cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cpms_get(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -877,7 +878,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             else     // Set VoLTE state.
@@ -887,7 +888,7 @@
                 char reg[100] = {0};
                 LOGD("mem:%s, len:%d", pack->data, pack->data_len);
 
-                if(req_cpms_set(cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cpms_set(cli_info->sim_id, cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -899,7 +900,7 @@
                 else
                 {
                     LOGD("cpms_set success, reg:%s", reg);
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             break;
@@ -917,7 +918,7 @@
 				char reg[50] ={0};
                 LOGD("mbtk_sms,cmgs:%s,len:%d", cmgs, len);
 
-                if(req_cmgs_set(cli_info->port, cmgs,reg,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgs_set(cli_info->sim_id, cli_info->port, cmgs,reg,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -928,7 +929,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             break;
@@ -946,7 +947,7 @@
                 char reg[128] = {0};
                 LOGD("mbtk_sms,cmgs:%s, len:%d", cmss, len);
 
-                if(req_cmss_set(cli_info->port, cmss,reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmss_set(cli_info->sim_id, cli_info->port, cmss,reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -958,7 +959,7 @@
                 else
                 {
                     LOGD("req_cmss_set success, reg:%s", reg);
-                    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;
@@ -980,7 +981,7 @@
                     break;
                 }
 
-                if(req_cmgr_set(cli_info->port, index, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgr_set(cli_info->sim_id, cli_info->port, index, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -991,7 +992,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             break;
@@ -1008,7 +1009,7 @@
 				int len = pack->data_len;
                 LOGD("mbtk_sms,cmgw:%s,len:%d", cmgw, len);
 
-                if(req_cmgw_set(cli_info->port, cmgw, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgw_set(cli_info->sim_id, cli_info->port, cmgw, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1019,7 +1020,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);
                 }
             }
             break;
@@ -1029,7 +1030,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 char reg[1024] = {0};
-                if(req_cmgd_get(cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgd_get(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1040,7 +1041,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             else     // Set VoLTE state.
@@ -1049,7 +1050,7 @@
 				int len = pack->data_len;
                 LOGD("mbtk_sms,cmgs:%s,len:%d", cmgd, len);
 
-                if(req_cmgd_set(cli_info->port, cmgd,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgd_set(cli_info->sim_id, cli_info->port, cmgd,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1060,7 +1061,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);
                 }
 
             }
@@ -1079,7 +1080,7 @@
                 char reg[5*1024] = {0};
                 char reg1[1024+1] = {0};
 
-                if(req_cmgl_set(cli_info->port, cmgl, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cmgl_set(cli_info->sim_id, cli_info->port, cmgl, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1091,7 +1092,7 @@
                 else
                 {
                     memcpy(reg1, reg, 1024);
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg1, strlen(reg1));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg1, strlen(reg1));
                 }
             }
             break;
@@ -1101,7 +1102,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 char csca[50]={0};
-                if(req_csca_get(cli_info->port, csca, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_csca_get(cli_info->sim_id, cli_info->port, csca, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1112,7 +1113,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, csca, strlen(csca));
+                    ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, csca, strlen(csca));
                 }
                 err = MBTK_RIL_ERR_UNSUPPORTED;
             }
@@ -1121,7 +1122,7 @@
 				char *csca = (char*)pack->data;
 				int len = pack->data_len;
 
-                if(req_csca_set(cli_info->port, csca, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_csca_set(cli_info->sim_id, cli_info->port, csca, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1132,7 +1133,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);
                 }
             }
             break;
@@ -1148,7 +1149,7 @@
 				char *csmp = (char*)pack->data;
 				int len = pack->data_len;
 
-                if(req_csmp_set(cli_info->port, csmp,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_csmp_set(cli_info->sim_id, cli_info->port, csmp,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1159,7 +1160,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);
                 }
             }
             break;
@@ -1175,7 +1176,7 @@
 				char *cscb = (char*)pack->data;
 				int len = pack->data_len;
 
-                if(req_cscb_set(cli_info->port, cscb,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cscb_set(cli_info->sim_id, cli_info->port, cscb,len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1186,7 +1187,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);
                 }
             }
             break;