Add DS support.

Change-Id: Ib8bc4e171dd5ca526f8e151ff3d467097582a8cb
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())

     {