[Feature]1.Add modify Apn API 2.change DNS ADDR MAX LEN 3.change timeout for setupDatacallstate

Change-Id: Ie17adcda44313ba7464f117c423a1d01af1d811e
diff --git a/src/lynq/lib/liblynq-data/lynq_data.cpp b/src/lynq/lib/liblynq-data/lynq_data.cpp
index 1fe3e3e..115e50f 100755
--- a/src/lynq/lib/liblynq-data/lynq_data.cpp
+++ b/src/lynq/lib/liblynq-data/lynq_data.cpp
@@ -56,14 +56,21 @@
 static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t s_pdn_change_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t s_pdn_change_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;
+
 /**g_lynq_data_init_flag
 * @brief mark data initialization state
 * 0:deinit status
 * 1:init state
 */
 static int g_lynq_data_init_flag = 0;
-
-typedef struct{
+/**g_lynq_apn_result
+* @brief temp of apn result info
+*/
+char g_lynq_apn_result[1024] = {};
+typedef struct
+{
     char apn[LYNQ_APN_MAX_LEN];
     char apnType[LYNQ_APN_TYPE_MAX_LEN];
     char ifaceName[LYNQ_IFACE_NAME_MAX_LEN];
@@ -144,6 +151,33 @@
     lynq_apn_table[ret].hasUsed = 1;
     return ret;
 }
+int waitApnResult()
+{
+    int ret = 0;
+    LYINFLOG("start wait apn result!!!");
+    int sec = 0;
+    int usec = 0;
+    struct timeval now;
+    struct timespec timeout;
+    gettimeofday(&now, NULL);
+    sec = 20000 / 1000;
+    usec = 20000 % 1000;
+    timeout.tv_sec = now.tv_sec + sec;
+    timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000;
+    pthread_mutex_lock(&s_lynq_apn_change_mutex);
+    ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout);
+    pthread_mutex_unlock(&s_lynq_apn_change_mutex);
+    return ret;
+}
+
+void sendSignalApnChange()
+{
+    LYINFLOG("start send Signal Apn Change");
+    pthread_mutex_lock(&s_lynq_apn_change_mutex);
+    pthread_cond_signal(&s_lynq_apn_change_cond);
+    pthread_mutex_unlock(&s_lynq_apn_change_mutex);
+    return;
+}
 
 int waitPdnChange()
 {
@@ -386,6 +420,37 @@
                     }
                     break;
                 }
+            case 9004:
+            {
+                LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
+                urc_msg = strdupReadString_p(p);
+                if (NULL == urc_msg)
+                {
+                    LYERRLOG("error apn msg");
+                }
+                else
+                {
+                    bzero(g_lynq_apn_result, 1024);
+                    strcpy(g_lynq_apn_result, urc_msg);
+                    sendSignalApnChange();
+                }
+                break;
+            }
+            case 9005:
+            {
+                LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
+                urc_msg = strdupReadString_p(p);
+                if (NULL == urc_msg)
+                {
+                    LYERRLOG("error apn msg");
+                }
+                else
+                {
+                    bzero(g_lynq_apn_result, 1024);
+                    strcpy(g_lynq_apn_result, urc_msg);
+                    sendSignalApnChange();
+                }
+            }
                 default:
                     break;
             }
@@ -529,7 +594,7 @@
     lynq_data_call = 1;
     if(error==0)
     {
-        if(waitDataCallstateChange(20000)==ETIMEDOUT)//20s
+        if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
         {
             error = LYNQ_E_TIME_OUT;
             LYERRLOG("timeout:wait data Call state fail!!!");
@@ -803,3 +868,270 @@
     return 0;
 }
 /*Warren add for T800 platform 2021/11/19 end*/
+
+/*Typethree add for T800 platform 2022/04/21 start*/
+int insert_apn_char(char *agc, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
+{
+    char strtmp[10][32];
+    if (mcc == NULL)
+    {
+        sprintf(strtmp[1], "mcc=;");
+    }
+    else
+    {
+        sprintf(strtmp[1], "mcc=%s;", mcc);
+    }
+    if (mnc == NULL)
+    {
+        sprintf(strtmp[12], "mnc=;");
+    }
+    else
+    {
+        sprintf(strtmp[2], "mnc=%s;", mnc);
+    }
+    if (apn == NULL)
+    {
+        sprintf(strtmp[3], "apn=;");
+    }
+    else
+    {
+        sprintf(strtmp[3], "apn=%s;", apn);
+    }
+    if (apntype == NULL)
+    {
+        sprintf(strtmp[4], "apntype=;");
+    }
+    else
+    {
+        sprintf(strtmp[4], "apntype=%s;", apntype);
+    }
+    if (user == NULL)
+    {
+        sprintf(strtmp[5], "user=;");
+    }
+    else
+    {
+        sprintf(strtmp[5], "user=%s;", user);
+    }
+    if (password == NULL)
+    {
+        sprintf(strtmp[6], "password=;");
+    }
+    else
+    {
+        sprintf(strtmp[6], "password=%s;", password);
+    }
+    if (normalprotocol == NULL)
+    {
+        sprintf(strtmp[7], "normalprotocol=;");
+    }
+    else
+    {
+        sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
+    }
+    if (roamingprotocol == NULL)
+    {
+        sprintf(strtmp[8], "roamingprotocol=;");
+    }
+    else
+    {
+        sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
+    }
+    if (carrier == NULL)
+    {
+        sprintf(strtmp[9], "carrier=;");
+    }
+    else
+    {
+        sprintf(strtmp[9], "carrier=%s;", carrier);
+    }
+    sprintf(agc, "%s%s%s%s%s%s%s%s%s", strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
+    return 0;
+}
+
+int modify_apn_char(char *agc, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
+{
+    char strtmp[10][32];
+    if (id == NULL)
+    {
+        sprintf(strtmp[0], "id=;");
+    }
+    else
+    {
+        sprintf(strtmp[0], "id=%s;", id);
+    }
+    if (mcc == NULL)
+    {
+        sprintf(strtmp[1], "mcc=;");
+    }
+    else
+    {
+        sprintf(strtmp[1], "mcc=%s;", mcc);
+    }
+    if (mnc == NULL)
+    {
+        sprintf(strtmp[2], "mnc=;");
+    }
+    else
+    {
+        sprintf(strtmp[2], "mnc=%s;", mnc);
+    }
+    if (apn == NULL)
+    {
+        sprintf(strtmp[3], "apn=;");
+    }
+    else
+    {
+        sprintf(strtmp[3], "apn=%s;", apn);
+    }
+    if (apntype == NULL)
+    {
+        sprintf(strtmp[4], "apntype=;");
+    }
+    else
+    {
+        sprintf(strtmp[4], "apntype=%s;", apntype);
+    }
+    if (user == NULL)
+    {
+        sprintf(strtmp[5], "user=;");
+    }
+    else
+    {
+        sprintf(strtmp[5], "user=%s;", user);
+    }
+    if (password == NULL)
+    {
+        sprintf(strtmp[6], "password=;");
+    }
+    else
+    {
+        sprintf(strtmp[6], "password=%s;", password);
+    }
+    if (normalprotocol == NULL)
+    {
+        sprintf(strtmp[7], "normalprotocol=;");
+    }
+    else
+    {
+        sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol);
+    }
+    if (roamingprotocol == NULL)
+    {
+        sprintf(strtmp[8], "roamingprotocol=;");
+    }
+    else
+    {
+        sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol);
+    }
+    if (carrier == NULL)
+    {
+        sprintf(strtmp[9], "carrier=;");
+    }
+    else
+    {
+        sprintf(strtmp[9], "carrier=%s;", carrier);
+    }
+    sprintf(agc, "%s%s%s%s%s%s%s%s%s%s", strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]);
+    return 0;
+}
+
+static char *lynqStrdupReadString(Parcel &p)
+{
+    size_t stringlen;
+    const char16_t *s16;
+
+    s16 = p.readString16Inplace(&stringlen);
+    return strndup16to8(s16, stringlen);
+}
+
+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)
+{
+    if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
+    {
+        LYERRLOG("There are no valid parameters");
+        return -1;
+    }
+    lynq_client_t client;
+    char argc[512];
+    char recvline[LYNQ_REC_BUF];
+    int len = 0;
+    Parcel p;
+    if (cmd == 0) // insert apn db
+    {
+        insert_apn_char(argc, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
+        client.uToken = Global_uToken;
+        client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
+        client.paramLen = 2;
+        bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
+        sprintf(client.param, "%d %s", cmd, argc);
+    }
+    else if (cmd == 1)
+    {
+        if (NULL == id)
+        {
+            LYERRLOG("id is NULL!!!please input id: ");
+        }
+        sprintf(argc, "id=%s", id);
+        client.uToken = Global_uToken;
+        client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
+        client.paramLen = 2;
+        bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
+        sprintf(client.param, "%d %s", cmd, argc);
+    }
+    else if (cmd == 2)
+    {
+        modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
+        client.uToken = Global_uToken;
+        client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
+        client.paramLen = 2;
+        bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
+        sprintf(client.param, "%d %s", cmd, argc);
+    }
+    else if (cmd == 3)
+    {
+        modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier);
+        client.uToken = Global_uToken;
+        client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN
+        client.paramLen = 2;
+        bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
+        sprintf(client.param, "%d %s", cmd, argc);
+    }
+    else
+    {
+        LYERRLOG("incoming command is invalid");
+        return -1;
+    }
+    LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+    if(send_request(lynq_client_sockfd,&client)==-1)
+    {
+        LYERRLOG("send request fail");
+        return -1;
+    }
+    waitApnResult();
+    LYINFLOG(">>>>>output info:%s",out);
+    return 0;
+}
+
+int lynq_reset_apn(char *result)
+{
+    Parcel p;
+    lynq_client_t client;
+
+    client.uToken = Global_uToken;
+    client.request = 2000 + 194;
+    client.paramLen = 0;
+    bzero(client.param, LYNQ_REQUEST_PARAM_BUF);
+    LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param);
+    if (send_request(lynq_client_sockfd, &client) == -1)
+    {
+        LYERRLOG("send request fail");
+        return -1;
+    }
+    waitApnResult();
+    strcpy(result, g_lynq_apn_result);
+    LYINFLOG(">>>>>result:%s",result);
+    return 0;
+}
+
+/*Typethree add for T800 platform 2022/04/21 end*/
\ No newline at end of file