[Feature][T108-yd][task-view-1906][data] add ql_data_call_set_attach_apn_config interface

Only Configure:No
Affected branchmaster
Affected module:voice
Is it affected on:asr
Doc Update:No

Change-Id: I7a79fed347baa5f6cd3ff13f676207718c6faafd
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
index 6443d31..62f59ce 100755
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -545,6 +545,7 @@
     uint8 redial_enable;    // Support redialing or not.
     uint8 def_route;
     uint8 as_dns;
+    uint8 b_initial_attach_apn;
     uint8 apn[APN_NAME_STR_MAX];
     uint8 user[APN_STR_MAX];
     uint8 pass[APN_STR_MAX];
diff --git a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
index f0abfd0..014b2e9 100755
--- a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
+++ b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
@@ -1992,16 +1992,18 @@
         return MBTK_RIL_ERR_PORT;
     }
 
-    if(str_empty(apn->apn)) { // Delete APN
-        if(!ril_cid_check(apn->cid)) {
-            return MBTK_RIL_ERR_CID;
-        }
-    } else { // Set APN
-        if(apn->cid != MBTK_RIL_CID_NUL && !ril_cid_check(apn->cid)) {
-            return MBTK_RIL_ERR_CID;
+    if(!apn->b_initial_attach_apn)
+    {
+        if(str_empty(apn->apn)) { // Delete APN
+            if(!ril_cid_check(apn->cid)) {
+                return MBTK_RIL_ERR_CID;
+            }
+        } else { // Set APN
+            if(apn->cid != MBTK_RIL_CID_NUL && !ril_cid_check(apn->cid)) {
+                return MBTK_RIL_ERR_CID;
+            }
         }
     }
-
     err = ril_req_process(sim_id, port_info->port, RIL_MSG_ID_DATA_CALL_APN, apn, sizeof(mbtk_apn_info_t), &return_cid, FALSE, 0);
     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 24490c6..a44ff38 100755
--- a/mbtk/mbtk_rild_v2/src/ril_data_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_data_call.c
@@ -1461,6 +1461,100 @@
     }
 }
 
+int req_apn_init_attach_apn_inner(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_apn_info_t *apn, int *cme_err)
+{
+    ATResponse *response = NULL;
+    char cmd[400] = {0};
+    int index = 0;
+    int err = 0;
+
+    index += sprintf(cmd, "AT*CGDFLT=1,");//not save to nvm
+    switch(apn->ip_type) {
+        case MBTK_IP_TYPE_IP: {
+            index += sprintf(cmd + index,"\"IP\",");
+            break;
+        }
+        case MBTK_IP_TYPE_IPV6: {
+            index += sprintf(cmd + index,"\"IPV6\",");
+            break;
+        }
+        case MBTK_IP_TYPE_IPV4V6: {
+            index += sprintf(cmd + index,"\"IPV4V6\",");
+            break;
+        }
+        default: {
+            index += sprintf(cmd + index,"\"PPP\",");
+            break;
+        }
+    }
+    if(strlen((char*)apn->apn) > 0) {
+        index += sprintf(cmd + index,"\"%s\",,,,,,,,,,,,,,,,,,1", apn->apn);
+    }
+    else
+    {
+        index += sprintf(cmd + index,"\"%s\",,,,,,,,,,,,,,,,,,0", "");
+    }
+    
+    err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
+    if (err < 0 || response->success == 0){
+        if(cme_err) {
+            *cme_err = at_get_cme_error(response);
+        }
+        goto exit;
+    }
+  
+    if(!str_empty(apn->user) || !str_empty(apn->pass)) {
+        at_response_free(response);
+        response = NULL;
+  
+        memset(cmd,0,400);
+        int cmd_auth=0;
+        if(apn->auth == MBTK_APN_AUTH_PROTO_NONE)
+            cmd_auth = 0;
+        else if(apn->auth == MBTK_APN_AUTH_PROTO_PAP)
+            cmd_auth = 1;
+        else if(apn->auth == MBTK_APN_AUTH_PROTO_CHAP)
+            cmd_auth = 2;
+        else
+            goto exit;
+  
+        sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
+        err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
+        if (err < 0 || response->success == 0){
+            if(cme_err) {
+                *cme_err = at_get_cme_error(response);
+            }
+            goto exit;
+        }
+    }
+  exit:
+      at_response_free(response);
+      return err;
+
+}
+
+int req_apn_init_attach_apn(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack,mbtk_apn_info_t *apn)
+{
+    int err = 0;
+    int cme_err = MBTK_RIL_ERR_CME_NON;
+    if(req_apn_init_attach_apn_inner(cli_info->sim_id, cli_info->port, apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+   {
+       if(cme_err != MBTK_RIL_ERR_CME_NON) {
+           err = MBTK_RIL_ERR_CME + cme_err;
+       } else {
+           err = MBTK_RIL_ERR_UNKNOWN;
+       }
+       LOGD("Set initial attach APN fail, err is %d",err);
+   }
+   else
+   {
+       mbtk_ril_cid_enum return_cid = apn->cid;
+       ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &return_cid, sizeof(mbtk_ril_cid_enum));
+   }
+   return err;
+
+}
+
 //void net_list_free(void *data);
 // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
 // Otherwise, do not call pack_error_send().
@@ -1494,6 +1588,11 @@
             else     // Set
             {
                 mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data;
+                if(apn->b_initial_attach_apn)
+                {
+                    err=req_apn_init_attach_apn(cli_info,pack,apn);
+                    break;
+                }
                 mbtk_ril_cid_enum return_cid = apn->cid;
                 if(apn_check_and_cid_reset(cli_info->sim_id, cli_info->port, apn)) {
                     err = MBTK_RIL_ERR_CID;