[Bugfix][API-410][Ecall] if psap dose not answer ecall, gsw be responsible for redialing 2

Change-Id: I02aecf9d55aafab24d6460e6d65feee691f3ad7c
diff --git a/lib/liblynq-call/lynq_call.cpp b/lib/liblynq-call/lynq_call.cpp
index dd5685c..7359665 100755
--- a/lib/liblynq-call/lynq_call.cpp
+++ b/lib/liblynq-call/lynq_call.cpp
@@ -112,6 +112,7 @@
 #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 enum{

@@ -131,21 +132,28 @@
 

 #ifdef ECALL_SUPPORT

 int lynq_set_common_request(int request_id, int argc, const char* format,...);

-int is_ecall_dial = 0;

 int g_ecallId = INVALID_ID;

 typedef enum{        

     LYNQ_ECALL_TYPE_TEST = 0,     /* Test eCall */

     LYNQ_ECALL_TYPE_RECONFIG = 1,    /*    Reconfiguration eCall */    

     LYNQ_ECALL_MANUAL_EMERGENCY = 2,   /*Manual Emergency eCall */

-    LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3,   /* Automatic Emergency eCall */\

+    LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3,   /* Automatic Emergency eCall */

 }LYNQ_ECall_Type;

 

+typedef enum{   

+    LYNQ_ECALL_DAILING_STATE_NONE =0,

+    LYNQ_ECALL_DAILING_STATE_STARTED = 1,    

+    LYNQ_ECALL_DAILING_STATE_ANSWERED = 2,      

+}LYNQ_ECall_Dailing_State;

+

+LYNQ_ECall_Dailing_State is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

 char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};

 

 static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;

 static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;

 

 LYNQ_ECall_Indication g_lynqIncomingEcallIndication;

+int g_lynqIncomingEcallId;

 

 void sendSignalIncomingECallEvent()

 {

@@ -172,7 +180,7 @@
 

 int lynq_ecall_is_running()

 {

-    return (is_ecall_dial!=0) || (g_ecallId !=INVALID_ID);

+    return (is_ecall_dial!=LYNQ_ECALL_DAILING_STATE_NONE) || (g_ecallId !=INVALID_ID);

 }

 

 #endif

@@ -578,7 +586,7 @@
                 {  

                     LYINFLOG("need to hangup id %d", call_list[i].call_id);

 #ifdef ECALL_SUPPORT

-                    if(is_ecall_dial==1)

+                    if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)

                     {

                         LYINFLOG("ecall is dialing, for the timebeing, don't huangup");

                         continue;

@@ -754,90 +762,106 @@
                     p->readInt32(&ecall_ind);   

                     g_lynqIncomingEcallIndication = ecall_ind;

                     p->readInt32(&ecallId);

+                    g_lynqIncomingEcallId = ecallId;

                     LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS ,Id %d, ind %d, ecall dialing is %d, normal dialing is %d, local ecall id is %d",ecallId,ecall_ind,is_ecall_dial,isDial,g_ecallId);

-                    if(lynq_is_msd_suc(g_lynqIncomingEcallIndication)) 

-                    {                        

-                        if(is_ecall_dial)

-                        {

-                            LYINFLOG("ecall is dialing, recv suc indication");

-                            is_ecall_dial=0;

-                            if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)

-                            {

-                                  LYINFLOG("add ecall in loacl list");

-                                  g_ecallId = ecallId;

-                                  unused_callid=addAddr("ecall");

-                                  lynq_call_lists[unused_callid].call_id=g_ecallId;

-                            }        

-                            sendSignalToWaitCallStateChange();

-                        }        

-                        else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID)){

-                            LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");

-                            lynq_call_hungup(&ecallId);

-                        }   

-                        else 

-                        {

-                             LYERRLOG("ecall is not in dialing and not first recv suc indication");

-                        }

-                    } 

-                    else if (LYNQ_ECALL_PSAP_CALLBACK_START == g_lynqIncomingEcallIndication)

+                    switch (g_lynqIncomingEcallIndication) 

                     {

-                        if(lynq_ecall_is_running()==0)

-                        {

-                            LYINFLOG("ecall is not running, recv psap call back msd start, set ecall in dialing");

-                            if(find_call_id_with_call_id(ecallId)!=INVALID_ID)

+                       case LYNQ_ECALL_ACTIVE:

+                            if(is_ecall_dial)

                             {

-                                g_ecallId = ecallId;

-                                if(isDial)

-                                {

-                                    LYINFLOG("stop normal dial");

-                                    sendSignalToWaitCallStateChange();

-                                }

-                                else 

-                                {

-                                    LYINFLOG("no normal dial");

-                                }                            

+                                is_ecall_dial = LYNQ_ECALL_DAILING_STATE_ANSWERED;

                             }

-                            else 

-                            {

-                                 LYERRLOG("can't find ecall id in local list");

-                            }                            

-                        }

-                        else 

-                        {

-                            LYERRLOG("ecall is running, recv psap call back msd start");

-                        }

-                    }

-                    else if (LYNQ_ECALL_ABNORMAL_HANGUP == g_lynqIncomingEcallIndication)

-                    {

-                        if(is_ecall_dial==0)                             

-                        {

-                            LYERRLOG("ecall is not in dialing, recv abnormal hangup");

-                            g_ecallId = INVALID_ID;

-                        }

-                        else 

-                        {

-                            LYINFLOG("ecall is in dialing, recv abnormal hangup");

-                        }

-                    }

-                    else if (LYNQ_ECALL_DISCONNECTED == g_lynqIncomingEcallIndication ||

-                            LYNQ_ECALL_REDIAL_TIMER_OUT == g_lynqIncomingEcallIndication ||

-                            LYNQ_ECALL_T2_TIMER_OUT == g_lynqIncomingEcallIndication)

-                    {

-                        g_ecallId = INVALID_ID;

-                        if(is_ecall_dial)

-                        {

-                            LYERRLOG("ecall is in dialing, recv like disconnect indication");

-                            is_ecall_dial=0;

-                            sendSignalToWaitCallStateChange();

-                        }

-                        else 

-                        {

-                            LYINFLOG("ecall is not in dialing, recv like disconnect indication");

-                        }

-                    }

-                    else 

-                    {

-                        LYINFLOG("not special indication");

+                            break;

+                       case LYNQ_ECALL_LLACK_RECEIVED:

+                       case LYNQ_ECALL_ALACK_POSITIVE_RECEIVED:

+                       case LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED:

+                       case LYNQ_ECALL_T5_TIMER_OUT:

+                       case LYNQ_ECALL_T6_TIMER_OUT:

+                       case LYNQ_ECALL_T7_TIMER_OUT:                          

+                           if(is_ecall_dial)

+                           {

+                               LYINFLOG("ecall is dialing, recv suc indication");

+                               is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

+                               if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)

+                               {

+                                     LYINFLOG("add ecall in loacl list");

+                                     g_ecallId = ecallId;

+                                     unused_callid=addAddr("ecall");

+                                     lynq_call_lists[unused_callid].call_id=g_ecallId;

+                               }        

+                               sendSignalToWaitCallStateChange();

+                           }        

+                           else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID))

+                           {

+                               LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");

+                               lynq_call_hungup(&ecallId);

+                           }   

+                           else 

+                           {

+                               LYERRLOG("ecall is not in dialing and not first recv suc indication");

+                           }

+                           break;

+                       case LYNQ_ECALL_PSAP_CALLBACK_START:                            

+                           if(lynq_ecall_is_running()==0)

+                           {

+                               LYINFLOG("ecall is not running, recv psap call back msd start, set ecall in dialing");

+                               if(find_call_id_with_call_id(ecallId)!=INVALID_ID)

+                               {

+                                   g_ecallId = ecallId;

+                                   if(isDial)

+                                   {

+                                       LYINFLOG("stop normal dial");

+                                       sendSignalToWaitCallStateChange();

+                                   }

+                                   else 

+                                   {

+                                       LYINFLOG("no normal dial");

+                                   }                            

+                               }

+                               else 

+                               {

+                                    LYERRLOG("can't find ecall id in local list");

+                               }                            

+                           }

+                           else 

+                           {

+                               LYERRLOG("ecall is running, recv psap call back msd start");

+                           }

+                           break;                       

+                       case LYNQ_ECALL_ABNORMAL_HANGUP:

+                           if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_NONE)                             

+                           {

+                               LYERRLOG("ecall is not in dialing , recv abnormal hangup");

+                               g_ecallId = INVALID_ID;

+                           }

+                           else if (is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)

+                           {

+                               LYERRLOG("ecall is in dialing state, recv no answer, recv abnormal hangup, dont' redial");

+                               g_ecallId = INVALID_ID;

+                               sendSignalToWaitCallStateChange();                            

+                           }    

+                           else {

+                               LYINFLOG("ecall is in dialing and recv answer, recv abnormal hangup");

+                           }

+                           break;

+                       case LYNQ_ECALL_DISCONNECTED:

+                       case LYNQ_ECALL_REDIAL_TIMER_OUT:

+                       case LYNQ_ECALL_T2_TIMER_OUT :

+                       case LYNQ_ECALL_IMS_DISCONNECTED:

+                           g_ecallId = INVALID_ID;

+                           if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)

+                           {

+                               LYERRLOG("ecall is in dialing, recv like disconnect indication");

+                               is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

+                               sendSignalToWaitCallStateChange();

+                           }

+                           else 

+                           {

+                               LYINFLOG("ecall is not in dialing, recv like disconnect indication");

+                           }

+                           break;

+                       default:                          

+                           LYINFLOG("not special indication");

                     }                    

                     sendSignalIncomingECallEvent();

                     LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", g_ecallId);

@@ -1440,15 +1464,24 @@
    

     if(error==0)

     {   

-        is_ecall_dial = 1;

+        is_ecall_dial = LYNQ_ECALL_DAILING_STATE_STARTED;

         if(waitCallstateChange(180000)==ETIMEDOUT)//180000ms

         {

             LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");       

-            is_ecall_dial = 0;

+            is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

             lynqRespWatingEvent();                

             return LYNQ_E_TIME_OUT;

         }

-        is_ecall_dial = 0;

+        if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)

+        {

+            /*just dail, no recv answer*/

+            LYERRLOG("lynq_fast_ecall, no answer!");   

+            is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

+            lynqRespWatingEvent();         

+            return LYNQ_E_ECALL_DAILING_NO_ANSWER;            

+        }

+        

+        is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;

         lynqRespWatingEvent();        

         

         if(g_ecallId != INVALID_ID)

@@ -1562,11 +1595,12 @@
     return ret;

 }

 

-int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)

+int lynq_wait_ecall_indication(int* eCall_Id, LYNQ_ECall_Indication *eCall_Indication)

 {

     wait_ecall_event();

-    *eCall_Indication = g_lynqIncomingEcallIndication;

-    LYINFLOG("lynq_wait_ecall_indication id: %d",g_lynqIncomingEcallIndication);

+    *eCall_Id = g_lynqIncomingEcallId;

+    *eCall_Indication = g_lynqIncomingEcallIndication;  

+    LYINFLOG("lynq_wait_ecall_indication call id %d, Ind id: %d", *eCall_Id, *eCall_Indication);

     return 0;

 }