[Feature][ZXW-262][ecall] T106 support Ecall

       Affected branch: unknown
       Affected module: unknown
       Is it affected on both ZXIC and MTK: ZXIC
       Self-test: Yes
       Doc Update: No

Change-Id: Ia7ac8405c625279002d13ecf43a3fabf5c0ff1dd
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
index d32a69e..7d68695 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
@@ -19,6 +19,11 @@
 #define MIN_VOLUME 0
 #define MAX_VOLUME 5
 
+#ifdef ECALL_SUPPORT
+static pthread_t s_lynq_ecall_tid = -1;
+static QSER_ECall_IndHandlerFunc_t   s_ecall_cb = NULL;
+static int s_ecall_thread_status = 0;
+#endif
 
 static pthread_t s_lynq_voice_tid = -1;
 static QSER_VoiceCall_StateHandlerFunc_t   s_voice_cb = NULL;
@@ -112,6 +117,24 @@
         LYERRLOG("init first");
         return RESULT_ERROR;
     }
+
+
+#ifdef ECALL_SUPPORT    
+    s_ecall_thread_status = 0;
+
+    if(s_lynq_ecall_tid!=-1)
+    {
+        int ret = pthread_cancel(s_lynq_ecall_tid);
+        LYINFLOG("pthread cancel waiting urc thread, ret = %d",ret);            
+  
+        ret = pthread_join(s_lynq_ecall_tid,NULL);
+        LYINFLOG("pthread join waiting urc thread ret = %d",ret);
+        s_lynq_ecall_tid =-1;
+    }
+	
+    s_ecall_cb=NULL;
+#endif
+
     return lynq_deinit_call();
 }
 
@@ -235,5 +258,89 @@
 
 }
 
+#ifdef ECALL_SUPPORT
+int qser_voice_fast_ecall(voice_client_handle_type*       h_voice,
+                        int                         *call_id,
+                        E_QSER_VOICE_ECALL_CATEGORY_T cat,
+                        E_QSER_VOICE_ECALL_VARIANT_T variant,
+                        const char *addr, 
+                        int addr_length, 
+                        const unsigned char *msd_data,
+                        int msd_length)
+{ 
+    if(h_voice == NULL || (*h_voice) == 0 )
+    {
+        LYERRLOG("%s input error", __func__);
+        return RESULT_ERROR;
+    }
+
+    return lynq_fast_ecall(call_id,(LYNQ_ECall_Category) cat,(LYNQ_ECall_Variant) variant,addr,addr_length,msd_data,msd_length);
+}
+
+int qser_voice_set_test_num(voice_client_handle_type*       h_voice,E_QSER_VOICE_ECALL_SET_TYPE_T type, const char *test_num, int test_num_length)
+{
+    if(h_voice == NULL || (*h_voice) == 0 )
+    {
+        LYERRLOG("%s input error", __func__);
+        return RESULT_ERROR;
+    }              
+
+    return lynq_set_test_num((LYNQ_ECall_Set_Type) type, test_num, test_num_length);
+}
+
+int qser_voice_set_msd(int callid, const unsigned char *msd_data, int msd_length)
+{           
+    return lynq_set_msd(callid, msd_data, msd_length);
+}
+
+void *ecall_thread_recv(void *context)
+{
+    int handle = 0;
+    LYNQ_ECall_Indication eCall_Indication;
+    while (s_ecall_thread_status)
+    {
+        lynq_wait_ecall_indication(&handle, &eCall_Indication);
+        if(s_ecall_thread_status == 0)
+        {
+            return NULL;
+        }       
+       
+        if (s_ecall_cb != NULL)
+        {
+            s_ecall_cb(&handle,(E_QSER_VOICE_ECALL_INDICATION_T) eCall_Indication,context);
+        }
+    }
+    return NULL;
+}
+
+int qser_voice_add_ecall_indhandler(voice_client_handle_type*          h_voice,
+                                  QSER_ECall_IndHandlerFunc_t   handlerPtr,                                  
+                                  void*                             contextPtr)
+{
+    if(h_voice == NULL || (*h_voice) == 0 || handlerPtr== NULL)
+    {
+        LYERRLOG("input error");
+        return RESULT_ERROR;
+    }
+    if (s_ecall_cb != NULL)
+    {
+        LYERRLOG("The existing state handle does not need to be added");
+        return RESULT_ERROR;
+    }
+    s_ecall_cb = handlerPtr;
+    s_ecall_thread_status = 1;
+    int rt = pthread_create(&s_lynq_ecall_tid, NULL, ecall_thread_recv, contextPtr);
+    if(rt < 0)
+    {
+        LYDBGLOG("qser_voice_call_addstatehandler pthread_create error!!!\n");
+        s_ecall_cb = NULL;
+        s_ecall_thread_status = 0;
+        s_lynq_ecall_tid = -1;
+        return RESULT_ERROR;
+    }
+    return RESULT_OK;
+}
+#endif
+
 DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_CALL)