fix data_call v2 bug

Change-Id: Ie4df9d44223819fd9f34c6114d0d73f1b5caf14c
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
index 43b2877..84c4e87 100755
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -1015,7 +1015,7 @@
 /*
 * Set current APN informations.
 */
-mbtk_ril_err_enum mbtk_apn_set(mbtk_ril_handle* handle, const mbtk_apn_info_t *apn);
+mbtk_ril_err_enum mbtk_apn_set(mbtk_ril_handle* handle, mbtk_apn_info_t *apn);
 
 /*
 * Start data call.
diff --git a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
index 8a37ce4..8ef6b98 100755
--- a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
+++ b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
@@ -1560,7 +1560,7 @@
 /*
 * Set current APN informations.
 */
-mbtk_ril_err_enum mbtk_apn_set(mbtk_ril_handle* handle, const mbtk_apn_info_t *apn)
+mbtk_ril_err_enum mbtk_apn_set(mbtk_ril_handle* handle, mbtk_apn_info_t *apn)
 {
     if(!ril_cli.ril_ready)
     {
@@ -1573,6 +1573,8 @@
         return MBTK_RIL_ERR_PARAMETER;
     }
 
+    mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
+    mbtk_ril_cid_enum return_cid = MBTK_RIL_CID_NUL;
     ril_at_port_info_t *port_info = (ril_at_port_info_t*)handle;
     if(!at_port_check(port_info->port)) {
         return MBTK_RIL_ERR_PORT;
@@ -1588,7 +1590,9 @@
         }
     }
 
-    return ril_req_process(port_info->port, RIL_MSG_ID_DATA_CALL_APN, apn, sizeof(mbtk_apn_info_t), NULL, FALSE);
+    err = ril_req_process(port_info->port, RIL_MSG_ID_DATA_CALL_APN, apn, sizeof(mbtk_apn_info_t), &return_cid, FALSE);
+    apn->cid = return_cid;
+    return err;
 }
 
 /*
diff --git a/mbtk/mbtk_rild_v2/src/ril_data_call.c b/mbtk/mbtk_rild_v2/src/ril_data_call.c
index 9cb630a..f806659 100755
--- a/mbtk/mbtk_rild_v2/src/ril_data_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_data_call.c
@@ -643,7 +643,7 @@
             return -1;
         }
         if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
-            memcpy(apn->user, ptr_1, ptr_2 - ptr_1); // pass
+            memcpy(apn->pass, ptr_1, ptr_2 - ptr_1); // pass
         }
 
         ptr_2++; // Jump ',' to type
@@ -721,11 +721,11 @@
             return -1;
         }
         if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
-            memcpy(apn->user, ptr_1, ptr_2 - ptr_1); // pass
+            memcpy(apn->pass, ptr_1, ptr_2 - ptr_1); // pass
         }
 
         ptr_2++; // Jump ',' to type
-        if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+        if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
             memcpy(apn->type, ptr_2, strlen(ptr_2)); // pass
         }
 
@@ -754,7 +754,7 @@
                 apn->apn,
                 str_empty(apn->user) ? "NULL" : (char*)apn->user,
                 str_empty(apn->pass) ? "NULL" : (char*)apn->pass,
-                str_empty(apn->pass) ? "NULL" : (char*)apn->type);
+                str_empty(apn->type) ? "NULL" : (char*)apn->type);
         }
 
 #if 0
@@ -810,7 +810,7 @@
     }
 
     // Update apn info in buffer.
-    if(!str_empty(apn->apn)) {
+    if(str_empty(apn->apn)) {
         memset(&(info_list[apn->cid - 1]), 0, sizeof(ril_data_call_info_t));
     } else {
         info_list[apn->cid - 1].valid = true;
@@ -1113,6 +1113,7 @@
 
         if(!str_empty(apn->user) || !str_empty(apn->pass)) {
             at_response_free(response);
+            response = NULL;
 
             memset(cmd,0,400);
             int cmd_auth=0;
@@ -1404,6 +1405,7 @@
             else     // Set
             {
                 mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data;
+                mbtk_ril_cid_enum return_cid = apn->cid;
                 if(apn_check_and_cid_reset(cli_info->port, apn)) {
                     err = MBTK_RIL_ERR_CID;
                 } else {
@@ -1423,7 +1425,8 @@
                                 LOGE("Save APN fail.");
                             }
 
-                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                            return_cid = apn->cid;
+                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &return_cid, sizeof(mbtk_ril_cid_enum));
                         }
                     } else {
                         err = MBTK_RIL_ERR_UNSUPPORTED;
@@ -1492,13 +1495,14 @@
                                 cme_err = MBTK_RIL_ERR_CME_NON;
                                 if(req_data_call_state_get(cli_info->port, call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                                 {
-                                    LOGD("Get net informations fail.");
+                                    LOGE("Get net informations fail.");
                                     err = MBTK_RIL_ERR_NET_CONF;
                                 }
                                 else
                                 {
                                     // Config network informations.
-                                    if(net_ifc_reconfig(call_info->cid, call_info->def_route, call_info->as_dns, &ip_info)) {
+                                    if(net_ifc_reconfig(call_info->cid, info_list[call_info->cid - 1].apn_info.def_route,
+                                                        info_list[call_info->cid - 1].apn_info.as_dns, &ip_info)) {
                                         err = MBTK_RIL_ERR_NET_CONF;
                                         break;
                                     }