[Feature][T108][task-view-1465] 1.Solve the problem of failed apn authentication Settings
[Feature][T108][task-view-1478] 2.configure the mapping relationship between linkid, apnid, and cid
[Feature][T108][task-view-1478] 3.The cid1 successful dial-up callback function does not return the ip

Only Configure: No
Affected branch: GSW_V1453
Affected module: DATA_CALL
Is it affected on IC: only ASR
Self-test: yes
Doc Update: no

Change-Id: Iafcda91d75931bacea7213c748fd99c08b9a673c
diff --git a/mbtk/libgsw_lib/gsw_data_interface.c b/mbtk/libgsw_lib/gsw_data_interface.c
index bb9d045..abb8676 100755
--- a/mbtk/libgsw_lib/gsw_data_interface.c
+++ b/mbtk/libgsw_lib/gsw_data_interface.c
@@ -17,6 +17,8 @@
 #define MBTK_APN_PASSWORD_SIZE 127+1

 #define MBTK_APN_TYPE_SIZE 127+1

 

+#define MBTK_CHANNEL_ID_1 1

+#define MBTK_CHANNEL_ID_2 2

 

 #ifndef FALSE

 #define FALSE   (0)

@@ -89,6 +91,10 @@
 #endif

 } mbtk_apn_auth_proto_enum;

 

+typedef enum {

+    GSW_ID_CONVERT_TYPE_LINKID = 0,

+    GSW_ID_CONVERT_TYPE_APNID

+}gsw_id_convert_type_e;

 

 typedef struct {

     bool valid;

@@ -108,8 +114,6 @@
     uint32 NetMask[4];

 } __attribute__((packed)) mbtk_ipv6_info_t;

 

-

-

 typedef struct {

 	int cid;                /*!< UMTS/CDMA profile ID. range: 0 - 7*/

 	mbtk_ip_type_enum ip_type;               /*!< Packet Data Protocol (PDP) type specifies the type of data payload

@@ -545,21 +549,22 @@
     uint8 *net_data = NULL;

     net_data = (uint8 *)data;

     //disconnected

-    LOGE("net_data = %d\n", *net_data);

+    LOGE("net_data = %d", *net_data);

     if(*net_data > 100 && *net_data < 200)

     {   

-        int apn_id = *net_data - 100;

-        int handle_temp = apn_id-2;

-        LOGE("apn_id = %d\n", apn_id);

+        int cid = *net_data - 100;

+        LOGE("[%s] apn_id = %d", __func__, cid);

         linkState_arr->state = 0;//disconnected

-        linkState_arr->cid = -1;

-        linkState_arr->handle = handle_temp;

+        linkState_arr->cid = cid;

+        linkState_arr->handle = cid;

 

         //get data_call_state

+#if 0

         if(!data_call_lock)

         {

-            data_call_state_query(apn_id, linkState_arr);

+            data_call_state_query(cid, linkState_arr);

         }

+#endif

 

         if(gsw_data_call_evt_cb)

         {

@@ -569,17 +574,17 @@
 

     else if(*net_data > 200 && *net_data < 220)

     {

-        LOGE("cid[%d] is open.\n", *net_data - 200);

-        int apn_id = *net_data-200;

-        int handle_temp = apn_id-2;

+        LOGE("[%s] cid[%d] is open", __func__, *net_data - 200);

+        int cid = *net_data-200;

+        //int handle_temp = apn_id-2;

 

         linkState_arr->state = 2;//connected

-        linkState_arr->cid = apn_id;

-        linkState_arr->handle = handle_temp;

+        linkState_arr->cid = cid;

+        linkState_arr->handle = cid;

         //get data_call_state

         if(!data_call_lock)

         {

-            data_call_state_query(apn_id, linkState_arr);

+            data_call_state_query(cid, linkState_arr);

         }

         

         if(gsw_data_call_evt_cb)

@@ -591,17 +596,17 @@
     else if(*net_data > 220)

     {

         LOGE("cid [%d] is reopen.\n", *net_data - 220);

-        int apn_id = *net_data-220;

-        int handle_temp = apn_id-2;

+        int cid = *net_data-220;

+        //int handle_temp = apn_id-2;

         

         linkState_arr->state = 2;//connected

-        linkState_arr->cid = apn_id;

-        linkState_arr->handle = handle_temp;

+        linkState_arr->cid = cid;

+        linkState_arr->handle = cid;

 

         //get data_call_state

         if(!data_call_lock)

         {

-            data_call_state_query(apn_id, linkState_arr);

+            data_call_state_query(cid, linkState_arr);

         }

 

         if(gsw_data_call_evt_cb)

@@ -628,7 +633,54 @@
 

 }

 

+static int gsw_id_convert_to_channel_id(int gsw_id, gsw_id_convert_type_e type, int *channel_id)

+{

+    if(GSW_ID_CONVERT_TYPE_LINKID == type)

+    {

+        switch(gsw_id)

+        {

+            case 0:

+            {

+                *channel_id = MBTK_CHANNEL_ID_2;

+                break;

+            }

+            case 1:

+            {

+                *channel_id = MBTK_CHANNEL_ID_1;

+                break;

+            }

+            default :

+            {

+                LOGE("[%s] gsw_id(linkid) unknown.[%d]", __func__, gsw_id);

+                return -1;

+            }

+        }

+    }

+    else

+    {

+        switch(gsw_id)

+        {

+            case 1:

+            case -2:

+            {

+                *channel_id = MBTK_CHANNEL_ID_1;

+                break;

+            }

+            case -1:

+            {

+                *channel_id = MBTK_CHANNEL_ID_2;

+                break;

+            }

+            default :

+            {

+                LOGE("[%s] gsw_id(apnid) unknown.[%d]", __func__, gsw_id);

+                return -1;

+            }

+        }

+    }

 

+    return 0;

+}

 

 

 

@@ -667,13 +719,14 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

+#if 0

     ret = mbtk_pdp_state_change_cb_reg((mbtk_info_handle_t*)data_info_handle, data_call_state_change_cb);

     if (ret != 0) 

     {

         LOGE("mbtk_pdp_state_change_cb_reg fail\n");

         return GSW_HAL_NORMAL_FAIL;

     }

-

+#endif

     gsw_data_call_evt_cb = evt_cb;

     data_init_flag = 1;

     return GSW_HAL_SUCCESS;

@@ -721,19 +774,21 @@
 

     if(LinkInf == NULL)

     {

-        LOGE("apn info is null\n");

+        LOGE("apn info is null");

         return GSW_HAL_NORMAL_FAIL;

     }

 

     int ret = 0;

+    int cid = -1;

+    int apnid = -1;

     mbtk_ip_type_enum ip_type;

-    int auth_type = -1;

+    char auth_type[GSW_AUTH_TYPE_MAX_LEN + 1] = {0};

 

     //pdp type

-    if(strcmp(LinkInf->normalProtocol,"IPV4") == 0)

+    if(strcmp(LinkInf->normalProtocol,"IP") == 0)

     {

         ip_type = MBTK_IP_TYPE_IP;

-        LOGE("pdp_type(protocol) is IPV4\n");

+        LOGE("pdp_type(protocol) is IP\n");

     }

     else if(strcmp(LinkInf->normalProtocol,"IPV6") == 0)

     {

@@ -751,10 +806,47 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

-    //auth type

-    auth_type = atoi(LinkInf->authType);

+    apnid = atoi(LinkInf->apnid);

+    ret = gsw_id_convert_to_channel_id(apnid, GSW_ID_CONVERT_TYPE_APNID, &cid);

+    if(0 != ret)

+    {

+        LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);

+        return GSW_HAL_NORMAL_FAIL;

+    }

 

-    ret = mbtk_apn_set(data_info_handle, LinkInf->handle+2, ip_type, LinkInf -> apn, LinkInf -> usr, LinkInf -> pwd, (const void *)auth_type);

+    //bypass solution for authparams issue

+    #if 0

+    memset(LinkInf->usr, 0x00, sizeof(LinkInf->usr));

+    memset(LinkInf->pwd, 0x00, sizeof(LinkInf->pwd));

+    memset(LinkInf->authType, 0x00, sizeof(LinkInf->authType));

+    #endif

+    //auth type

+    memset(auth_type, 0x00, GSW_AUTH_TYPE_MAX_LEN + 1);

+    if(0 == strlen(LinkInf->authType) || 0 == strcmp(LinkInf->authType, "0"))

+    {

+        memcpy(auth_type, "NONE", strlen("NONE"));

+    }

+    else if(0 == strcmp(LinkInf->authType, "1"))

+    {

+        memcpy(auth_type, "PAP", strlen("PAP"));

+    }

+    else if(0 == strcmp(LinkInf->authType, "2"))

+    {

+        memcpy(auth_type, "CHAP", strlen("CHAP"));

+    }

+    else if(0 == strcmp(LinkInf->authType, "3"))

+    {

+        //nonsupport

+        LOGE("[%s] LinkInf->authType(3) nonsupport", __func__);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    else

+    {

+        LOGE("[%s] LinkInf->authType(%s) unknown", __func__, LinkInf->authType);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+

+    ret = mbtk_apn_set(data_info_handle, cid, ip_type, LinkInf -> apn, LinkInf -> usr, LinkInf -> pwd, (const void *)auth_type);

     if(ret != 0)

     {

         LOGE("[%s] mbtk_apn_set fail() fail.[%d]", __func__, ret);

@@ -777,6 +869,8 @@
 int gsw_data_call_connect(int linkid, Link_Info_s *LinkInf)

 {

     int ret = -1;

+    int cid = -1;

+    uint8_t cid_temp = 0;

     if(data_init_flag == 0 && data_info_handle == NULL)

     {

         return GSW_HAL_NORMAL_FAIL;

@@ -784,7 +878,7 @@
 

     if(LinkInf == NULL)

     {

-        LOGE("apn info is null\n");

+        LOGE("apn info is null");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -795,17 +889,29 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

+    ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);

+    if(0 != ret)

+    {

+        LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    

     data_call_lock = 1;

-    ret = mbtk_data_call_start((mbtk_info_handle_t*)data_info_handle, linkid + 2, 0, FALSE, 0);

+    ret = mbtk_data_call_start((mbtk_info_handle_t*)data_info_handle, cid, 0, FALSE, 0);

     data_call_lock = 0;

     if(ret != 0)

     {

-        LOGE("[%s] mbtk_data_call_start fail.[%d]\n", __func__, ret);

+        LOGE("[%s] mbtk_data_call_start fail.[%d]", __func__, ret);

         return GSW_HAL_NORMAL_FAIL;

     }

 

-    uint8_t cid_temp = (uint8_t)(linkid + 202);

-    data_call_state_change_cb(&cid_temp,1);

+    cid_temp = (uint8_t)(cid + 200);

+    //LOGE("[%s] cid = %d, cid_temp = %d", __func__, cid, cid_temp);

+    data_call_state_change_cb(&cid_temp, sizeof(uint8_t));

+

+    LinkInf->handle = cid;

+    memset(LinkInf->apnid, 0x00, sizeof(LinkInf->apnid));

+    sprintf(LinkInf->apnid, "%d", cid);

 

     return GSW_HAL_SUCCESS;

 }

@@ -823,6 +929,8 @@
 int gsw_data_call_disconnect(int linkid, Link_Info_s *LinkInf)

 {

     int ret = -1;

+    int cid = -1;

+    uint8_t cid_temp = 0;

     if(data_init_flag == 0 && data_info_handle == NULL)

     {

         return GSW_HAL_NORMAL_FAIL;

@@ -830,20 +938,28 @@
 

     if(LinkInf == NULL)

     {

-        LOGE("apn info is null\n");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    data_call_lock = 1;

-    ret = mbtk_data_call_stop((mbtk_info_handle_t*)data_info_handle, linkid + 2, 15);

-    data_call_lock = 0;

-    if(ret != 0)

-    {

-        LOGE("mbtk_data_call_stop fail,ret = %d\n",ret);

+        LOGE("apn info is null");

         return GSW_HAL_NORMAL_FAIL;

     }

 

-    uint8_t cid_temp = (uint8_t)(linkid + 102);

-    data_call_state_change_cb(&cid_temp,1);

+    ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);

+    if(0 != ret)

+    {

+        LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    

+    data_call_lock = 1;

+    ret = mbtk_data_call_stop((mbtk_info_handle_t*)data_info_handle, cid, 15);

+    data_call_lock = 0;

+    if(ret != 0)

+    {

+        LOGE("[%s] mbtk_data_call_stop() fail.[%d]",__func__, ret);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+

+    cid_temp = (uint8_t)(cid + 100);

+    data_call_state_change_cb(&cid_temp, sizeof(uint8_t));

 

     return GSW_HAL_SUCCESS;

 }

diff --git a/mbtk/test/libgsw_lib/gsw_data_test.c b/mbtk/test/libgsw_lib/gsw_data_test.c
index 6efa383..61f1256 100755
--- a/mbtk/test/libgsw_lib/gsw_data_test.c
+++ b/mbtk/test/libgsw_lib/gsw_data_test.c
@@ -220,11 +220,11 @@
     strcpy(pub_LinkInf->mcc,"460");
     strcpy(pub_LinkInf->mnc,"11");
     strcpy(pub_LinkInf->apn,"pub_apn");
-    strcpy(pub_LinkInf->apnid,"pub_apnid");
+    strcpy(pub_LinkInf->apnid,"-1");
     strcpy(pub_LinkInf->apnType,"default");
-    strcpy(pub_LinkInf->usr,"");
-    strcpy(pub_LinkInf->pwd,"");
-    strcpy(pub_LinkInf->authType,"0");
+    strcpy(pub_LinkInf->usr,"123");
+    strcpy(pub_LinkInf->pwd,"123");
+    strcpy(pub_LinkInf->authType,"2");
     strcpy(pub_LinkInf->normalProtocol,"IPV4V6");
     strcpy(pub_LinkInf->roamingProtocol,"IPV4V6");
     strcpy(pub_LinkInf->carrier,"CHINA TELECOM");
@@ -233,11 +233,11 @@
     strcpy(pri_LinkInf->mcc,"460");
     strcpy(pri_LinkInf->mnc,"11");
     strcpy(pri_LinkInf->apn,"pri_apn");
-    strcpy(pri_LinkInf->apnid,"pri_apnid");
+    strcpy(pri_LinkInf->apnid,"1");
     strcpy(pri_LinkInf->apnType,"mms");
-    strcpy(pri_LinkInf->usr,"");
-    strcpy(pri_LinkInf->pwd,"");
-    strcpy(pri_LinkInf->authType,"0");
+    strcpy(pri_LinkInf->usr,"456");
+    strcpy(pri_LinkInf->pwd,"456");
+    //strcpy(pri_LinkInf->authType,"1");
     strcpy(pri_LinkInf->normalProtocol,"IPV4V6");
     strcpy(pri_LinkInf->roamingProtocol,"IPV4V6");
     strcpy(pri_LinkInf->carrier,"CHINA TELECOM");
@@ -307,12 +307,19 @@
 
             case 4:
             {
-                printf("gsw_data_call_connect start\n");
+                printf("gsw_data_call_connect start\n");                
                 ret = gsw_data_call_connect(pub_LinkInf->handle, pub_LinkInf);
                 if (ret != 0) {
-                    printf("gsw_data_call_connect failed, ret = %d\n",ret);
+                    printf("gsw_data_call_connect pub_LinkInf failed, ret = %d\n",ret);
                     continue;
                 }
+#if 1
+                ret = gsw_data_call_connect(pri_LinkInf->handle, pri_LinkInf);
+                if (ret != 0) {
+                    printf("gsw_data_call_connect pri_LinkInf failed, ret = %d\n",ret);
+                    continue;
+                }
+#endif
                 printf("gsw_data_call_connect success\n");
                 break;
             }
@@ -322,9 +329,16 @@
                 printf("gsw_data_call_disconnect start\n");
                 ret = gsw_data_call_disconnect(pub_LinkInf->handle, pub_LinkInf);
                 if (ret != 0) {
-                    printf("gsw_data_call_disconnect failed,ret = %d\n",ret);
+                    printf("gsw_data_call_disconnect pub_LinkInf failed,ret = %d\n",ret);
                     continue;
                 }
+#if 1
+                ret = gsw_data_call_disconnect(pri_LinkInf->handle, pri_LinkInf);
+                if (ret != 0) {
+                    printf("gsw_data_call_disconnect pri_LinkInf failed,ret = %d\n",ret);
+                    continue;
+                }
+#endif
                 printf("gsw_data_call_disconnect success\n");
                 break;
             }