[Feature][L805-15] RIL FWK update for DSDS

Only Configure:No
Affected branch:DSDS
Affected module:RIL
Is it affected on both ZXIC and MTK: both
Self-test: Yes
Doc Update:Yes

Change-Id: Ica4204d89e843274d04e5809ed25e81b66e2e35a
diff --git a/IC_meta/mtk/2735/liblynq-sim/liblynq-sim.bb b/IC_meta/mtk/2735/liblynq-sim/liblynq-sim.bb
index fad21ae..0077bfa 100755
--- a/IC_meta/mtk/2735/liblynq-sim/liblynq-sim.bb
+++ b/IC_meta/mtk/2735/liblynq-sim/liblynq-sim.bb
@@ -1,9 +1,9 @@
 inherit externalsrc package
 
-DESCRIPTION = "liblynq-uci.so demo"
+DESCRIPTION = "liblynq-sim.so"
 LICENSE = "CLOSED"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
-DEPENDS += "platform-libs platform-libs-common libpal liblynq-log libvendor-ril"
+DEPENDS += "platform-libs platform-libs-common libpal liblynq-log libvendor-ril lynq-ril-service"
 inherit workonsrc
 WORKONSRC = "${TOPDIR}/../LYNQ_PUBLIC/common_src/lib/liblynq-sim/"
 
diff --git a/IC_meta/mtk/2735/lynq-ril-service/lynq-ril-service.bb b/IC_meta/mtk/2735/lynq-ril-service/lynq-ril-service.bb
index 7ec9ecf..14bd0ab 100755
--- a/IC_meta/mtk/2735/lynq-ril-service/lynq-ril-service.bb
+++ b/IC_meta/mtk/2735/lynq-ril-service/lynq-ril-service.bb
@@ -43,7 +43,8 @@
 		install -d ${D}${systemd_unitdir}/system/
 		install -m 0644 ${B}/lynq_ril_service.service ${D}${systemd_unitdir}/system
 	fi
-#	install -d ${D}${includedir}
+	install -d ${D}${includedir}/lynq-ril
+	install ${S}/lynq_interface.h ${D}${includedir}/lynq-ril
 #	install ${S}/atci/ATCI.h ${D}${includedir}
 #	cp -R ${S}/demoscript ${D}${bindir}/
 	if test "${TARGET_PLATFORM}" = "mt2731"; then
diff --git a/common_src/framework/lynq-ril-service/src/common.cpp b/common_src/framework/lynq-ril-service/src/common.cpp
index b87b051..26cdce0 100755
--- a/common_src/framework/lynq-ril-service/src/common.cpp
+++ b/common_src/framework/lynq-ril-service/src/common.cpp
@@ -39,6 +39,7 @@
 #include "cc.h"
 #include "include/lynq_systime.h"
 #include <include/lynq_uci.h>
+#include "lynq_interface.h"
 #ifdef LED_SUPPORT
 #include "led.h"
 #endif
@@ -422,6 +423,15 @@
             Radio_capability_switch_util::sendRadioCapabilityRequest(slot);
         }
     }
+    else
+    {
+        android::Parcel allow_data_p;
+        allow_data_p.writeInt32 (1);
+        allow_data_p.writeInt32 (LYNQ_URC_ALLOW_DATA);
+        allow_data_p.writeInt32 (slot);
+        allow_data_p.writeInt32 (RIL_E_GENERIC_FAILURE);
+        android::LYNQ_RIL_urcBroadcast(allow_data_p,LYNQ_URC_ALLOW_DATA);
+    }
     pthread_mutex_unlock(&s_DataMutex);
 }
 
diff --git a/common_src/framework/lynq-ril-service/src/common.h b/common_src/framework/lynq-ril-service/src/common.h
index 959d4ab..46da418 100755
--- a/common_src/framework/lynq-ril-service/src/common.h
+++ b/common_src/framework/lynq-ril-service/src/common.h
@@ -91,25 +91,6 @@
 **The range of error values unique to LYNQ is 8000 to 10000.
 **The sim card state is error.
 */
-typedef enum{
-    LYNQ_E_CARDSTATE_ERROR=8000,
-    /* The voice service state is out of service*/
-    LYNQ_E_STATE_OUT_OF_SERVICE=8001,
-    /* The voice service state is EMERGENCY_ONLY*/
-    LYNQ_E_STATE_EMERGENCY_ONLY=8002,
-    /* The radio power is power off*/
-    LYNQ_E_STATE_POWER_OFF=8003,
-    LYNQ_E_TIME_OUT=8004,
-    /*create or open sms DB fail */
-    LYNQ_E_SMS_DB_FAIL=8005,
-    /*Failed to execute sql statement*/
-    LYNQ_E_SMS_SQL_FAIL = 8006,
-    LYNQ_E_SMS_NOT_FIND = 8007,
-    /* The logic conflict*/
-    LYNQ_E_CONFLICT=9000,
-    /*Null anomaly*/
-    LYNQ_E_NULL_ANONALY=9001
-}LYNQ_E;
 /*Warren add for t800 RIL Service 2021/12/10 start*/
 
 typedef struct{
diff --git a/common_src/framework/lynq-ril-service/src/lynq_interface.h b/common_src/framework/lynq-ril-service/src/lynq_interface.h
index 401b9bd..963e306 100755
--- a/common_src/framework/lynq-ril-service/src/lynq_interface.h
+++ b/common_src/framework/lynq-ril-service/src/lynq_interface.h
@@ -13,6 +13,7 @@
 #define LYNQ_URC_MODIFY_APNDB (LYNQ_URC_VENDOR_BASE+4)
 #define LYNQ_URC_RESET_APNDB (LYNQ_URC_VENDOR_BASE+5)
 
+#define LYNQ_URC_ALLOW_DATA (LYNQ_URC_VENDOR_BASE + 10)
 
 #define LYNQ_REQUEST_WRITE_SMS_TO_MEMORY (LYNQ_REQUEST_VENDOR_BASE +4)
 #define LYNQ_REQUEST_READ_SMS_FROM_MEMORY (LYNQ_REQUEST_VENDOR_BASE + 5)
@@ -49,6 +50,44 @@
 #define RIL_UNSOL_ECALL_AUTO_ANS_TIMER_OUT 9005
 #define RIL_UNSOL_ECALL_AUTO_ANS_IMS_TIMER_OUT 9006
 #endif
+//Warren add for plantform 2024_04_11 start
+/* 
+**The range of error values unique to LYNQ is 7000 to 10000.
+**The sim card state is error.
+*/
+typedef enum{
+    /*base abnormal*/
+    LYNQ_E_PARAMETER_ANONALY=7000,
+    LYNQ_E_SEND_REQUEST_FAIL=7001,
+    LYNQ_E_GET_HEAD_ERROR=7002,
+    LYNQ_E_INNER_ERROR=7100,
+    LYNQ_E_MALLOC_ERROR=7101,
+    /**/
+    LYNQ_E_CARDSTATE_ERROR=8000,
+    /* The voice service state is out of service*/
+    LYNQ_E_STATE_OUT_OF_SERVICE=8001,
+    /* The voice service state is EMERGENCY_ONLY*/
+    LYNQ_E_STATE_EMERGENCY_ONLY=8002,
+    /* The radio power is power off*/
+    LYNQ_E_STATE_POWER_OFF=8003,
+    LYNQ_E_TIME_OUT=8004,
+    /*create or open sms DB fail */
+    LYNQ_E_SMS_DB_FAIL=8005,
+    /*Failed to execute sql statement*/
+    LYNQ_E_SMS_SQL_FAIL = 8006,
+    LYNQ_E_SMS_NOT_FIND = 8007,
+    /* The logic conflict*/
+    LYNQ_E_CONFLICT=9000,
+    /*Null anomaly*/
+    LYNQ_E_NULL_ANONALY=9001,
+    /*Invalid id anomaly*/
+    LYNQ_E_INVALID_ID_ANONALY=9002,
+#ifdef ECALL_SUPPORT
+    LYNQ_E_ECALL_BEING_RUNNING =9003,
+    LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
+    LYNQ_E_ECALL_DAILING_NO_ANSWER =9005,
+#endif
+}LYNQ_E;
 
 typedef struct{
     int request;
diff --git a/common_src/framework/lynq-ril-service/src/ril.cpp b/common_src/framework/lynq-ril-service/src/ril.cpp
index 1c0a080..a5f9a15 100755
--- a/common_src/framework/lynq-ril-service/src/ril.cpp
+++ b/common_src/framework/lynq-ril-service/src/ril.cpp
@@ -4518,6 +4518,15 @@
                 sleep(WAIT_TIME_FOR_SIM_SWITCH);
                 setupDataCall(0, NULL, (RIL_SOCKET_ID)0, NULL);
             }
+            if(utils::is_support_dsds() && get_default_sim_data() == socket_id)
+            {
+                Parcel allow_data_p;
+                allow_data_p.writeInt32 (1);
+                allow_data_p.writeInt32 (LYNQ_URC_ALLOW_DATA);
+                allow_data_p.writeInt32 (socket_id);
+                allow_data_p.writeInt32 (e);
+                LYNQ_RIL_urcBroadcast(allow_data_p,LYNQ_URC_ALLOW_DATA);
+            }
             break;
         }
 #ifdef KEEP_ALIVE
@@ -6112,6 +6121,8 @@
     RLOGD("LYNQ_RIL_RecSocket start\n");
     char *argv[MAX_ARGS];
     int argc = 0;
+    int ril_slot_status = 0;
+    int ril_slot = 0;
     int ep_fd = 0;
     int en_fd = 0;
     struct epoll_event lynq_ev;
@@ -6188,10 +6199,9 @@
                 while(recvfrom(server_socket_fd, buffer, LYNQ_SOCKET_BUFFER,0,(struct sockaddr*)&lynqClient_addr, &client_addr_length) != -1)//add while by hq for bug 760 2023/02/09
                 {
                     client_tmp = (lynq_client_t*)buffer;
-                    RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
-                    //char test[36] = {};
-                    //sprintf(test,"test okay len = %d",client_tmp->paramLen);
-                    //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
+                    ril_slot_status = (int)(buffer+(1024*8+sizeof(int)*3))[0] - '0';
+                    ril_slot = (int)(buffer+(1024*8+sizeof(int)*3)+1)[0] - '0';
+                    RLOGD("[LYNQ socketId] utoken=%d,request=%d,slot_status=%d,slot=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,ril_slot_status,ril_slot,client_tmp->paramLen,client_tmp->param);
                     argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
                     argc = 0;
                     if(client_tmp->paramLen > 0)
@@ -6218,10 +6228,17 @@
                     int32_t request;
                     request = command->request;
                     RIL_SOCKET_ID id = RIL_SOCKET_1;
-                    if(utils::is_support_dsds()) {
-                        id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
-                    } else if(utils::is_suppport_dsss()) {
-                        id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
+                    if((ril_slot_status == 1) && ((ril_slot == 0) | (ril_slot == 1)))
+                    {
+                        id = (RIL_SOCKET_ID)ril_slot;
+                    }
+                    else
+                    {
+                        if(utils::is_support_dsds()) {
+                            id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
+                        } else if(utils::is_suppport_dsss()) {
+                            id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
+                        }
                     }
                     if(request == -1)
                     {
diff --git a/common_src/framework/lynq-ril-service/src/rtp/call_rtp_inner.h b/common_src/framework/lynq-ril-service/src/rtp/call_rtp_inner.h
index 0a1ebd0..a92c350 100755
--- a/common_src/framework/lynq-ril-service/src/rtp/call_rtp_inner.h
+++ b/common_src/framework/lynq-ril-service/src/rtp/call_rtp_inner.h
@@ -24,7 +24,6 @@
 

 #define RESULT_OK (0)

 #define RESULT_ERROR (-1)

-#define LYNQ_E_PARAMETER_ANONALY 7000

 

 typedef enum{

     Rtp_Ssrc_random = 0,     

diff --git a/common_src/framework/lynq-ril-service/src/sms/lynqSmsManager/lynq_sms_manager.cpp b/common_src/framework/lynq-ril-service/src/sms/lynqSmsManager/lynq_sms_manager.cpp
index 0d926df..14bd941 100755
--- a/common_src/framework/lynq-ril-service/src/sms/lynqSmsManager/lynq_sms_manager.cpp
+++ b/common_src/framework/lynq-ril-service/src/sms/lynqSmsManager/lynq_sms_manager.cpp
@@ -6,6 +6,7 @@
 #include <stdlib.h>

 #include <string.h>

 #include "common.h"

+#include "lynq_interface.h"

 sms_manager * g_smsManagement;

 int sms_indexs[LYNQ_MAX_SMS_LIST]={0};

 int next_index = 0;

diff --git a/common_src/lib/liblynq-sim/include/lynq_sim.h b/common_src/lib/liblynq-sim/include/lynq_sim.h
index c2d7793..ac00626 100755
--- a/common_src/lib/liblynq-sim/include/lynq_sim.h
+++ b/common_src/lib/liblynq-sim/include/lynq_sim.h
@@ -84,6 +84,14 @@
  * 
  */
 int lynq_factory_radio_state(int num);
+/**
+ * @brief set default sim card
+ * @param slot: type [IN] <slot> sim card slot
+ * @return int
+ * 0:success
+ * other:fail
+ */
+int lynq_set_default_sim(const int slot);
 
 
 #ifdef __cplusplus
diff --git a/common_src/lib/liblynq-sim/lynq_sim_urc.cpp b/common_src/lib/liblynq-sim/lynq_sim_urc.cpp
new file mode 100755
index 0000000..daee1d3
--- /dev/null
+++ b/common_src/lib/liblynq-sim/lynq_sim_urc.cpp
@@ -0,0 +1,173 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <string.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include <list>
+#include <vendor-ril/telephony/ril.h>
+#include <vendor-ril/telephony/mtk_ril_sp.h>
+#include "liblog/lynq_deflog.h"
+#include "lynq_sim_urc.h"
+
+int module_len_urc_addr_serv;
+struct sockaddr_in module_urc_addr_serv;
+static int module_urc_sock_fd = -1;
+int module_urc_status = 1;
+pthread_t module_urc_tid = -1;
+
+static pthread_mutex_t s_ProcessUrcMsgBlockMutex = PTHREAD_MUTEX_INITIALIZER;
+#define BLOCK_PROCESS_URC_MSG_INIT() pthread_mutex_init(&s_ProcessUrcMsgBlockMutex,NULL)
+#define BLOCK_PROCESS_URC_MSG_LOCK() pthread_mutex_lock(&s_ProcessUrcMsgBlockMutex)
+#define BLOCK_PROCESS_URC_MSG_UNLOCK() pthread_mutex_unlock(&s_ProcessUrcMsgBlockMutex)
+
+bool is_support_urc(int urc_id)
+{
+    switch(urc_id)
+    {
+        case LYNQ_URC_ALLOW_DATA:
+            return true;
+        default:
+            return false;
+    }
+}
+
+void *thread_urc_recv(void *p)
+{
+    Parcel *urc_p =NULL;
+    char urc_data[LYNQ_REC_BUF];
+    int res = 0;
+    lynq_head_t* phead;
+    LYINFLOG("urc recv thread is running");
+    while(module_urc_status)
+    {
+        bzero(urc_data,LYNQ_REC_BUF);
+        res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);
+        if(res<sizeof(int32_t)*2)
+        {
+            LYERRLOG("thread_urc_recv step2 fail: res is %d",res);
+            continue;
+        }
+
+        phead=(lynq_head_t*) urc_data;
+        if(is_support_urc(phead->urcid)==false)
+        {
+            continue;
+        }
+        urc_p = new Parcel();
+        if(urc_p == NULL)
+        {
+            LYERRLOG("new parcel failure!!!");
+            continue;
+        }
+        urc_p->setData((uint8_t *)urc_data,res); // p.setData((uint8_t *) buffer, buflen);
+        urc_p->setDataPosition(0);
+        if(urc_p->dataAvail()>0)
+        {
+            urc_msg_process(urc_p);
+        }
+        else 
+        {
+            delete urc_p;
+            urc_p = NULL;
+        }        
+    }
+    LYINFLOG("urc recv thread ended");
+    return NULL;
+}
+
+void lynq_close_urc_rev_thread()
+{
+    int ret;
+
+    BLOCK_PROCESS_URC_MSG_LOCK();  //just cancel urc process tid when recv from
+    module_urc_status = 0;
+    if(module_urc_tid!=-1)
+    {
+        ret = pthread_cancel(module_urc_tid);
+        LYINFLOG("pthread cancel urc rev ret = %d",ret);
+    }
+    BLOCK_PROCESS_URC_MSG_UNLOCK();
+    if(module_urc_tid != -1)
+    {
+        ret = pthread_join(module_urc_tid,NULL);
+        LYINFLOG("pthread join urc tid ret = %d",ret);
+        module_urc_tid =-1;
+    }
+}
+
+void lynq_close_urc_socket()
+{
+    if (module_urc_sock_fd >= 0)
+    {
+        close(module_urc_sock_fd);
+        module_urc_sock_fd =-1;
+    }
+}
+
+int lynq_setup_urc_socket()
+{
+    int on = 1;
+    int ret = 0;
+    module_len_urc_addr_serv = sizeof(sockaddr_in);
+    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (module_urc_sock_fd <0){
+        LYERRLOG("urc socket error");
+        return RESULT_ERROR;  
+    }
+    module_urc_addr_serv.sin_family = AF_INET;
+    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);
+    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);
+    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
+    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
+    if(ret <0)
+    {
+        LYERRLOG("urc socket set error");
+        close(module_urc_sock_fd);
+        module_urc_sock_fd =-1;
+        return RESULT_ERROR;  
+    }
+    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));
+    if(ret <0)
+    {
+        LYERRLOG("urc socket bind error");
+        close(module_urc_sock_fd);
+        module_urc_sock_fd =-1;
+        return RESULT_ERROR;
+    }
+    return RESULT_OK;
+}
+
+int lynq_start_all_urc_socket_thread()
+{
+    int ret= lynq_setup_urc_socket();
+    if(ret!=RESULT_OK)
+    {
+        LYERRLOG("call lynq_setup_urc_socket fail");
+        return RESULT_ERROR;
+    }
+
+    module_urc_status = 1;
+    ret = pthread_create(&module_urc_tid,NULL,thread_urc_recv,NULL);
+    if(ret <0)
+    {
+        LYERRLOG("urc recv pthread create error");
+        module_urc_status = 0;
+        lynq_close_urc_socket();
+        return RESULT_ERROR;
+    }
+    LYINFLOG("urc start success");
+    return RESULT_OK;  
+}
+
+void lynq_close_all_urc_socket_thread()
+{
+    lynq_close_urc_rev_thread();
+    lynq_close_urc_socket();
+    LYERRLOG("close all urc socket thread!!!");
+}
+
diff --git a/common_src/lib/liblynq-sim/lynq_sim_urc.h b/common_src/lib/liblynq-sim/lynq_sim_urc.h
new file mode 100755
index 0000000..5173311
--- /dev/null
+++ b/common_src/lib/liblynq-sim/lynq_sim_urc.h
@@ -0,0 +1,23 @@
+#include "lynq_interface.h"
+using ::android::Parcel;
+
+#define LYNQ_ADDRESS "127.0.0.1"
+#define LYNQ_URC_SERVICE_PORT 8086
+#ifdef GSW_RIL_CFG
+#define LYNQ_URC_ADDRESS "127.255.255.255" /*hong.liu change broadcast addr on 2024.2.18*/
+#else
+#define LYNQ_URC_ADDRESS "0.0.0.0"
+#endif
+#define LYNQ_REC_BUF 8192
+
+#define RESULT_OK (0)
+#define RESULT_ERROR (-1)
+
+typedef struct{
+    int resp_type;
+    int urcid;   
+}lynq_head_t;
+
+void urc_msg_process(Parcel *p);
+int lynq_start_all_urc_socket_thread();
+void lynq_close_all_urc_socket_thread();
diff --git a/common_src/lib/liblynq-sim/makefile b/common_src/lib/liblynq-sim/makefile
index f34e6b0..25758ec 100755
--- a/common_src/lib/liblynq-sim/makefile
+++ b/common_src/lib/liblynq-sim/makefile
@@ -45,6 +45,7 @@
   -I$(ROOT)$(includedir)/vendor-ril \
   -I$(ROOT)$(includedir)/logger \
   -I$(ROOT)$(includedir)/liblog \
+  -I$(ROOT)$(includedir)/lynq-ril \
 
 
 LOCAL_LIBS := \
diff --git a/common_src/lib/liblynq-sim/src/lynq_sim.cpp b/common_src/lib/liblynq-sim/src/lynq_sim.cpp
index c780859..cbc8459 100755
--- a/common_src/lib/liblynq-sim/src/lynq_sim.cpp
+++ b/common_src/lib/liblynq-sim/src/lynq_sim.cpp
@@ -24,14 +24,16 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "lynq_sim.h"
+#include "liblog/lynq_deflog.h"
+#include "lynq_sim_urc.h"
+
+
 #define MAX_BUF 20
 #define MAX_NUM 80
-#define LYNQ_REQUEST_SET_DEFAULT_SIM_ALL 8008
-#define LYNQ_REQUEST_CHANGE_SCREEN_STATE 8014 /*add for two sim suspend on 20220919*/
-#define LYNQ_REQUEST_CHANGE_RADIO 8015
+
 #define MAX_LEN 1024*8
-#define MAX_NUM 10
-#define LOG_TAG "LYNQ_SIM"
+
+#define USER_LOG_TAG "LYNQ_SIM"
 #define FLAG_TESS 0
 using ::android::Parcel;
 #define DEST_PORT 8088
@@ -79,42 +81,37 @@
     int error;
 }lynq_resp_t;
 
-#define RESULT_OK (0)
-#define RESULT_ERROR (-1)
+static pthread_mutex_t s_sim_allow_data_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_sim_allow_data_cond = PTHREAD_COND_INITIALIZER;
+static int s_sim_allow_data_value = -1;
+#define SIM_ALLOW_DATA_TIMEOUT 60*1000
 
-typedef enum{
-    /*base abnormal*/
-    LYNQ_E_PARAMETER_ANONALY=7000,
-    LYNQ_E_SEND_REQUEST_FAIL=7001,
-    LYNQ_E_GET_HEAD_ERROR=7002,
-    LYNQ_E_INNER_ERROR=7100,
-    LYNQ_E_MALLOC_ERROR=7101,
-    /**/
-    LYNQ_E_CARDSTATE_ERROR=8000,
-    /* The voice service state is out of service*/
-    LYNQ_E_STATE_OUT_OF_SERVICE=8001,
-    /* The voice service state is EMERGENCY_ONLY*/
-    LYNQ_E_STATE_EMERGENCY_ONLY=8002,
-    /* The radio power is power off*/
-    LYNQ_E_STATE_POWER_OFF=8003,
-    LYNQ_E_TIME_OUT=8004,
-    /*create or open sms DB fail */
-    LYNQ_E_SMS_DB_FAIL=8005,
-    /*Failed to execute sql statement*/
-    LYNQ_E_SMS_SQL_FAIL = 8006,
-    LYNQ_E_SMS_NOT_FIND = 8007,
-    /* The logic conflict*/
-    LYNQ_E_CONFLICT=9000,
-    /*Null anomaly*/
-    LYNQ_E_NULL_ANONALY=9001,
-     /*Invalid id anomaly*/
-    LYNQ_E_INVALID_ID_ANONALY=9002,
-#ifdef ECALL_SUPPORT
-    LYNQ_E_ECALL_BEING_RUNNING =9003,
-    LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
-    LYNQ_E_ECALL_DAILING_NO_ANSWER =9005,
-#endif
-}LYNQ_E;
+int waitAllowDataSignal(int mtime)
+{
+    int ret = 0;
+    int sec = 0;
+    int usec = 0;
+    struct timeval now;
+    struct timespec timeout;
+    gettimeofday(&now,NULL);
+    sec = mtime/1000;
+    usec = mtime%1000;
+    timeout.tv_sec = now.tv_sec+sec;
+    timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
+    pthread_mutex_lock(&s_sim_allow_data_mutex);
+    ret = pthread_cond_timedwait(&s_sim_allow_data_cond,&s_sim_allow_data_mutex,&timeout);
+    pthread_mutex_unlock(&s_sim_allow_data_mutex);
+    return ret;
+}
+
+void sendAllowDataSignal(int value)
+{
+    pthread_mutex_lock(&s_sim_allow_data_mutex);
+    s_sim_allow_data_value = value;
+    pthread_cond_signal(&s_sim_allow_data_cond);
+    pthread_mutex_unlock(&s_sim_allow_data_mutex);
+    return;
+}
 
 /**@brief print solicied response msg's head information
 * @param head [IN]: head information
@@ -213,7 +210,8 @@
 }
 
 int lynq_sim_init(int utoken){
-
+    LYLOGSET(LOG_DEBUG);
+    LYLOGEINIT(USER_LOG_TAG);
     RLOGE("%s start, parameter is %d", __func__,utoken);
     
     if(g_lynq_sim_init_flag == 1)
@@ -249,17 +247,24 @@
     timeOut.tv_usec = 0;
     if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0) 
     {
-        RLOGD("time out setting failed\n"); 
+        RLOGD("time out setting failed\n");
         return -1;
     }
-    /* 设置address */  
-    memset(&addr_serv, 0, sizeof(addr_serv));  
-    addr_serv.sin_family = AF_INET;  
-    addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);  
-    addr_serv.sin_port = htons(DEST_PORT);  
-    len_addr_serv = sizeof(addr_serv);  
-    /*test*/
 
+    memset(&addr_serv, 0, sizeof(addr_serv));
+    addr_serv.sin_family = AF_INET;  
+    addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
+    addr_serv.sin_port = htons(DEST_PORT);
+    len_addr_serv = sizeof(addr_serv);
+
+#ifdef MODE_DSDS
+    ret = lynq_start_all_urc_socket_thread();
+    if(ret != RESULT_OK)
+    {
+        LYERRLOG("init socket urc fail!!!");
+        return LYNQ_E_INNER_ERROR;
+    }
+#endif
     RLOGE("%s end suc", __func__);
     return 0;
 }
@@ -273,6 +278,10 @@
         RLOGD("lynq_sim_deinit  failed");
         return -1;
     }
+
+#ifdef DMODE_DSDS
+    lynq_close_all_urc_socket_thread();
+#endif
     g_lynq_sim_init_flag = 0;
     close(sock_fd);
 
@@ -639,6 +648,44 @@
     return 0;
 }
 
+#ifdef MODE_DSDS
+int lynq_set_default_sim(const int slot)
+{
+    if(g_lynq_sim_init_flag == 0)
+    {
+        RLOGE("can`t init SIM module");
+        return -1;
+    }
+    if(!judge(slot))
+    {
+        RLOGD("is not 0 or 1");
+        return -1;
+    }
+    int send_num = 0;
+    lynq_client_t client_t;
+    client_t.request = LYNQ_REQUEST_SET_DEFAULT_SIM_ALL;
+    client_t.paramLen = 1;
+    client_t.uToken = Global_uToken;
+    sprintf(client_t.param, "%d\n", slot);
+    pthread_mutex_lock(&g_lynq_sim_sendto_mutex);
+    send_num = sendto(sock_fd, &client_t, sizeof(client_t), 0, (struct sockaddr *)&addr_serv, len_addr_serv);
+    if(send_num < 0)
+    {
+        RLOGD("function %s sendto error:", __FUNCTION__);
+        return send_num;
+    }
+
+    if(waitAllowDataSignal(SIM_ALLOW_DATA_TIMEOUT) == ETIMEDOUT)
+    {
+        LYERRLOG("timeout:wait allow data fail!!!");
+        return LYNQ_E_TIME_OUT;
+    }
+    pthread_mutex_unlock(&g_lynq_sim_sendto_mutex);
+    LYERRLOG("sim allow data value %d",s_sim_allow_data_value);
+    return s_sim_allow_data_value;
+}
+#endif
+
 int lynq_switch_card(int slot){
     if(g_lynq_sim_init_flag == 0)
     {
@@ -914,3 +961,29 @@
     return 0;
 }
 
+void urc_msg_process(Parcel *p)
+{
+    int resp_type;
+    int urcid;
+    int slot_id;
+    int error_code;
+
+    int size=p->dataSize();
+    p->readInt32(&resp_type);
+    p->readInt32(&urcid);
+    p->readInt32(&slot_id);
+    LYINFLOG("%s urc id = %d, slot_id = %d, size is %d",__func__, urcid,slot_id,size);
+    switch (urcid)
+    {
+        case LYNQ_URC_ALLOW_DATA://new sms received
+        {
+            LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
+            p->readInt32(&error_code);
+            sendAllowDataSignal(error_code);
+            break;
+        }
+        default:
+            break;
+    }
+}
+