[Bugfix][API-1094] due to dislocation,get_data_call_list fail

Change-Id: I84891802df4f8f49e9a4e034c585f7c3c05b4584
diff --git a/lib/liblynq-data/lynq_data.cpp b/lib/liblynq-data/lynq_data.cpp
index 03df681..dc7e215 100755
--- a/lib/liblynq-data/lynq_data.cpp
+++ b/lib/liblynq-data/lynq_data.cpp
@@ -25,7 +25,7 @@
 #define USER_LOG_TAG "LYNQ_DATA"
 
 #define LYNQ_DATA_UCI_BUF 258
-#define LYNQ_DATA_TIME_OUT 1000*180
+#define LYNQ_DATA_TIME_OUT 1000*120
 
 
 using ::android::Parcel;
@@ -49,6 +49,10 @@
     /*Failed to execute sql statement*/
     LYNQ_E_SMS_SQL_FAIL = 8006,
     LYNQ_E_SMS_NOT_FIND = 8007,
+    LYNQ_E_GET_RESP_FAIL = 8008,
+    LYNQ_E_NOT_THIS_APN = 8087,
+    LYNQ_E_NOT_ANY_APN = 8088,
+    LYNQ_E_MD_NOT_READY = 8089,
     /* The logic conflict*/
     LYNQ_E_CONFLICT=9000,
     /*Null anomaly*/
@@ -65,6 +69,10 @@
 static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
 
+static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER;
+
+
 static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -297,6 +305,31 @@
     pthread_mutex_unlock(&s_data_call_state_change_mutex);
     return;
 }
+int waitDeactived(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_data_call_deactived_mutex);
+    ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout);
+    pthread_mutex_unlock(&s_data_call_deactived_mutex);
+    return ret;
+}
+void sendSignalDeactvied()
+{
+    pthread_mutex_lock(&s_data_call_deactived_mutex);
+    pthread_cond_signal(&s_data_call_deactived_cond);
+    pthread_mutex_unlock(&s_data_call_deactived_mutex);
+    return;
+}
+
 void sendSignalPdnChange()
 {
     pthread_mutex_lock(&s_lynq_urc_vector_mutex);
@@ -324,14 +357,98 @@
     }
     return 0;
 }
-int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
+/**@brief get utoken in range 0 to 10000
+* @return utoken
+*/
+int get_utoken()
 {
-    if(p.dataAvail() > 0)
+    return (Global_uToken++)%10000;/*0-10000*/
+}
+/**@brief wait response with expected token and write msg to parcel in some time
+* @param fd [IN]: socket fd
+* @param p [OUT]: quote the parcel,if return success need delete p.
+* @param token [IN]: the expected token for the response msg
+* @return
+*  0:success
+*  other:failure
+*/
+int wait_response(int sockfd,Parcel *& p,int utoken)
+{
+    int len = 0;
+    int flag = 1;
+    int count = 0;
+    int in_utoken = -1;
+    int resp_type = -1;
+    Parcel *temp = NULL;
+    char recvline[LYNQ_REC_BUF];
+    //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request.
+    //Here it does not return until the response corresponding to the request is read.
+    while(flag && (count < 20))//why?
     {
-        p.readInt32(resp_type);
-        p.readInt32(request);
-        p.readInt32(slot_id);
-        p.readInt32(error);
+        bzero(recvline,LYNQ_REC_BUF);
+        count++;
+        LYINFLOG("wait_response,count:%d",count);
+        len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len);
+        if(len == -1)
+        {
+            LYERRLOG("wait_response fail,errno:%d",errno);
+            return LYNQ_E_GET_RESP_FAIL;
+        }
+        if (len != 0)
+        {
+            temp = new Parcel;
+            int i = 0;
+            while((NULL == temp) && (i < 100))
+            {
+                usleep(1000);
+                temp = new Parcel;
+                i++;
+            }
+            if((i >= 100) || (NULL == temp))
+            {
+                LYERRLOG("wait_response i:%d",i);
+                return LYNQ_E_GET_RESP_FAIL;
+            }
+            temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
+            temp->setDataPosition(0);
+            temp->readInt32(&resp_type);
+            temp->readInt32(&in_utoken);
+            LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken);
+            if (in_utoken != utoken)
+            {
+                delete temp;
+                temp = NULL;
+                in_utoken = 0;
+                continue;
+            }
+            temp->setDataPosition(0);
+            p = temp;
+            flag = 0;
+            return 0;
+        }
+        else
+        {
+            LYERRLOG("recvline is null,errno:%d",errno);
+            return LYNQ_E_GET_RESP_FAIL;
+        }
+    }
+    return LYNQ_E_GET_RESP_FAIL;
+}
+
+int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error)
+{
+    if(NULL == p)
+    {
+        LYERRLOG("JumpHeader is null");
+        return -1;
+    }
+    if(p->dataAvail() > 0)
+    {
+        p->readInt32(resp_type);
+        p->readInt32(utoken);
+        p->readInt32(request);
+        p->readInt32(slot_id);
+        p->readInt32(error);
         return 0;
     }
     else
@@ -339,6 +456,14 @@
         return -1;
     }
 }
+void free_parcel(Parcel *p)
+{
+    if(p)
+    {
+        delete p;
+        p = NULL;
+    }
+}
 int send_request(int sockfd,lynq_client_t *client_tmp)
 {
     int ret=0;
@@ -587,6 +712,7 @@
                     pthread_mutex_lock(&s_lynq_urc_vector_mutex);
                     s_data_urc_wait_list.push_back(apnId);
                     pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
+                    sendSignalDeactvied();
                     sendSignalPdnChange();
                     printf_apn_table_debug(__FUNCTION__,__LINE__);
                 }
@@ -655,7 +781,7 @@
     pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
     return 0;
 }
-
+int get_imsi();
 int lynq_init_data(int uToken)
 {
     if (g_lynq_data_init_flag == 1)
@@ -689,6 +815,23 @@
         return -1;
     }
     memset(lynq_apn_table,0,sizeof(lynq_apn_table));
+    int count = 0;
+    while(count < 10)
+    {
+        result =  get_imsi();
+        if(result==0)
+        {
+            break;
+        }
+        sleep(1);
+        count++;
+    }
+    LYINFLOG("[%s] count is %d",__FUNCTION__,count);
+    if(result!=0)
+    {
+        LYDBGLOG("lynq init call fail!!!");
+        return LYNQ_E_MD_NOT_READY;//
+    }
     LYDBGLOG("lynq init call success!!!");
     return 0;
 
@@ -731,7 +874,7 @@
     LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__);
     error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL);
     #else
-    Parcel p;
+    Parcel *p = NULL;
     lynq_client_t client;
     int resp_type = -1;
     int request = -1;
@@ -742,7 +885,7 @@
         LYERRLOG("handle is null!!!");
         return LYNQ_E_NULL_ANONALY;
     }
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();
     client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
     client.paramLen = 0;
     bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
@@ -761,11 +904,21 @@
     {
         LYERRLOG("send request fail");
         perror("[LYNQ_DATA] send request fail:");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return LYNQ_E_NULL_ANONALY+2;
     }
-    get_response(lynq_client_sockfd,p);
+    //get_response(lynq_client_sockfd,p);
+    error = wait_response(lynq_client_sockfd,p,client.uToken);
+    if(error!=0)
+    {
+        LYERRLOG("wait_response fail,ret:%d",error);
+        printf_apn_table_debug(__FUNCTION__,__LINE__);
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+        return error;
+    }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
     JumpHeader(p,&resp_type,&request,&slot_id,&error);
+    free_parcel(p);
     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
     if(error==0)
     {
@@ -792,7 +945,7 @@
 
 int lynq_deactive_data_call(int *handle)
 {
-    Parcel p;
+    Parcel *p = NULL;
     lynq_client_t client;
     int resp_type = -1;
     int request = -1;
@@ -812,7 +965,7 @@
         return -1;
     }
     lynq_data_call_id = *handle;
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();
     client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL
     client.paramLen = 0;
     bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
@@ -832,19 +985,38 @@
     {
         LYERRLOG("send request fail");
         perror("[LYNQ_DATA] send request fail:");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return -1;
     }
-    get_response(lynq_client_sockfd,p);
+    //get_response(lynq_client_sockfd,p);
+    error = wait_response(lynq_client_sockfd,p,client.uToken);
+    if(error!=0)
+    {
+        LYERRLOG("wait_response fail,ret:%d",error);
+        printf_apn_table_debug(__FUNCTION__,__LINE__);
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+        return error;
+    }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
-    JumpHeader(p,&resp_type,&request,&slot_id,&error);
-    LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+    JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
+    LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
     cleanOnceApnTable(lynq_data_call_id);
     printf_apn_table_debug(__FUNCTION__,__LINE__);
+    if(error==0)
+    {
+        if(waitDeactived(20000)==ETIMEDOUT)
+        {
+            error = LYNQ_E_TIME_OUT;
+            LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!");
+            printf_apn_table_debug(__FUNCTION__,__LINE__);
+        }
+    }
+    free_parcel(p);
     return error;
 }
 int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol)
 {
-    Parcel p;
+    Parcel *p = NULL;
     lynq_client_t client;
     int resp_type = -1;
     int request = -1;
@@ -906,7 +1078,7 @@
     {
         argv[5] = roamingProtocol;
     }
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();
     client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL
     client.paramLen = 7;
     bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
@@ -936,12 +1108,22 @@
     {
         LYERRLOG("send request fail");
         perror("[LYNQ_DATA] send request fail:");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return LYNQ_E_NULL_ANONALY+2;
     }
-    get_response(lynq_client_sockfd,p);
+    //get_response(lynq_client_sockfd,p);
+    error = wait_response(lynq_client_sockfd,p,client.uToken);
+    if(error!=0)
+    {
+        LYERRLOG("wait_response fail,ret:%d",error);
+        printf_apn_table_debug(__FUNCTION__,__LINE__);
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+        return error;
+    }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
-    JumpHeader(p,&resp_type,&request,&slot_id,&error);
-    LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+    JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error);
+    LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
+    free_parcel(p);
     if(error==0)
     {
         data_timelimit = 1;
@@ -997,11 +1179,11 @@
 */
 int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum)
 {
-    Parcel p;
+    Parcel *p = NULL;
     lynq_client_t client;
     int resp_type = -1;
     int token;
-    int request = -1;    
+    int request = -1;
     int slot_id = -1;
     int error = -1;
     int version =0;
@@ -1012,8 +1194,7 @@
         LYERRLOG("dataCallList is null!!!");
         return -1;
     }
-    Global_uToken++;
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();;
     client.request = 57;//RIL_REQUEST_DATA_CALL_LIST
     client.paramLen = 0;
     bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
@@ -1023,79 +1204,81 @@
     {
         LYERRLOG("send request fail");
         perror("[LYNQ_DATA] send request fail:");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return -1;
     }
-    get_response(lynq_client_sockfd,p);
+    //get_response(lynq_client_sockfd,p);
+    error = wait_response(lynq_client_sockfd,p,client.uToken);
+    if(error!=0)
+    {
+        LYERRLOG("wait_response fail,ret:%d",error);
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+        return error;
+    }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
-    if(p.dataAvail() > 0)
+    if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
     {
-        p.readInt32(&resp_type);
-        p.readInt32(&token);
-        p.readInt32(&request);
-        p.readInt32(&slot_id);
-        p.readInt32(&error);
-    }
-    else
-    {
+        LYERRLOG("JumpHeader fail");
         return -1;
     }
-    LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,token,request,slot_id,error);
-    p.readInt32(&version);
+    LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
+    p->readInt32(&version);
     if(version==11)
     {
-        p.readInt32(&num);
+        p->readInt32(&num);
         *realNum = num;
         for (int i = 0; i < num; i++)
         {
-            p.readInt32(&dataCallList[i].status);
-            p.readInt32(&dataCallList[i].suggestedRetryTime);
-            p.readInt32(&dataCallList[i].cid);
-            p.readInt32(&dataCallList[i].active);
-            temp_char = strdupReadString(p);
+            p->readInt32(&dataCallList[i].status);
+            p->readInt32(&dataCallList[i].suggestedRetryTime);
+            p->readInt32(&dataCallList[i].cid);
+            p->readInt32(&dataCallList[i].active);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            temp_char = strdupReadString(p);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            temp_char = strdupReadString(p);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            temp_char = strdupReadString(p);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            temp_char = strdupReadString(p);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            temp_char = strdupReadString(p);
+            temp_char = strdupReadString_p(p);
             LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char);
             if(temp_char)
             {
                 memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1);
                 free(temp_char);
             }
-            p.readInt32(&dataCallList[i].mtu);
+            p->readInt32(&dataCallList[i].mtu);
         }
     }
+    free_parcel(p);
     return error;
 }
 
@@ -1468,7 +1651,7 @@
 }
 int get_imsi()
 {
-    Parcel p;
+    Parcel *p =NULL;
     lynq_client_t client;
     int resp_type = -1;
     int token;
@@ -1480,7 +1663,7 @@
     char *temp_char = NULL;
     char mccmnc[32] = {0};
     char mccmnckey[64] = {0};
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();
     client.request = 11;//RIL_REQUEST_GET_IMSI 11
     client.paramLen = 0;
     bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
@@ -1490,33 +1673,36 @@
     {
         LYERRLOG("send request fail");
         perror("[LYNQ_DATA] send request fail:");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return -1;
     }
-    get_response(lynq_client_sockfd,p);
-    pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
-    if(p.dataAvail() > 0)
+    //get_response(lynq_client_sockfd,p);
+    error = wait_response(lynq_client_sockfd,p,client.uToken);
+    if(error!=0)
     {
-        p.readInt32(&resp_type);
-        p.readInt32(&token);
-        p.readInt32(&request);
-        p.readInt32(&slot_id);
-        p.readInt32(&error);
-        LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,token,request,slot_id,error);
-        if(!error)
-        {
-            char * test = lynqStrdupReadString(p);
-            memcpy(mccmnc, test,5);
-            mccmnc[5]='\0';
-            free(test);
-            sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
-            system(mccmnckey);
-        }
+        LYERRLOG("wait_response fail,ret:%d",error);
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return error;
     }
-    else
+    pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+    if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0)
     {
+        LYERRLOG("JumpHeader fail");
         return -1;
     }
+    LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error);
+    if(error == 0)
+    {
+        char * test = strdupReadString_p(p);
+        memcpy(mccmnc, test,5);
+        mccmnc[5]='\0';
+        free(test);
+        sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
+        system(mccmnckey);
+        system("uci commit");
+    }
+    free_parcel(p);
+    return error;
 }
 int lynq_modify_apn_db(const int cmd, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier, char *out)
 {
@@ -1540,12 +1726,10 @@
         count++;
     }
     LYINFLOG("[%s] count is %d",__FUNCTION__,count);
-    Parcel p;
     if (cmd == 0) // insert apn db
     {
         res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
-
-        client.uToken = Global_uToken;
+        client.uToken = get_utoken();
         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
         client.paramLen = 2;
         bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
@@ -1558,7 +1742,7 @@
             LYERRLOG("id is NULL!!!please input id: ");
         }
         sprintf(argc, "id=%s", id);
-        client.uToken = Global_uToken;
+        client.uToken = get_utoken();
         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
         client.paramLen = 2;
         bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
@@ -1567,7 +1751,7 @@
     else if (cmd == 2) //query apn db
     {
         query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
-        client.uToken = Global_uToken;
+        client.uToken = get_utoken();
         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
         client.paramLen = 2;
         bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
@@ -1576,7 +1760,7 @@
     else if (cmd == 3)  //modify apn db
     {
         modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
-        client.uToken = Global_uToken;
+        client.uToken = get_utoken();
         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
         client.paramLen = 2;
         bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
@@ -1589,11 +1773,10 @@
     }
     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
     pthread_mutex_lock(&g_lynq_data_sendto_mutex);
-    LYINFLOG("[%s] wait 4s",__FUNCTION__);
-    sleep(4);
     if(send_request(lynq_client_sockfd,&client)==-1)
     {
         LYERRLOG("send request fail");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return -1;
     }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
@@ -1605,13 +1788,12 @@
 
 int lynq_reset_apn(char *result)
 {
-    Parcel p;
     lynq_client_t client;
     if (NULL == result)
     {
         LYERRLOG("incoming paramters error");
     }
-    client.uToken = Global_uToken;
+    client.uToken = get_utoken();
     client.request = 2000 + 194;
     client.paramLen = 0;
     bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
@@ -1620,6 +1802,7 @@
     if (send_request(lynq_client_sockfd, &client) == -1)
     {
         LYERRLOG("send request fail");
+        pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
         return -1;
     }
     pthread_mutex_unlock(&g_lynq_data_sendto_mutex);