data_call:添加AF宏控制

Change-Id: Iccb89c80a95afbf47aa0dd8d6f875f7dc6c28a32
diff --git a/mbtk/Make.defines b/mbtk/Make.defines
index f6cca72..fbd4cd1 100755
--- a/mbtk/Make.defines
+++ b/mbtk/Make.defines
@@ -98,6 +98,9 @@
 

 endif

 

+# Only for AF custom.

+# DEFINE += -DMBTK_AF_SUPPORT

+

 LIB_DIR = \

 	-L$(OUT_DIR)/lib

 

diff --git a/mbtk/include/mbtk/mbtk_info_api.h b/mbtk/include/mbtk/mbtk_info_api.h
index 3e52eb3..411f309 100755
--- a/mbtk/include/mbtk/mbtk_info_api.h
+++ b/mbtk/include/mbtk/mbtk_info_api.h
@@ -21,8 +21,12 @@
 
 #define CELL_NUM_MAX 50
 #define APN_STR_MAX 128
+#ifdef MBTK_AF_SUPPORT
+#define MBTK_APN_CID_MIN 1
+#else
 // 2 - 7
 #define MBTK_APN_CID_MIN 2
+#endif
 #define MBTK_APN_CID_MAX 7
 #define MBTK_DATA_CALL_TIMEOUT_DEFAULT 10  // 10s
 
diff --git a/mbtk/mbtk_ril/src/main.c b/mbtk/mbtk_ril/src/main.c
index 3f036e8..abb575e 100755
--- a/mbtk/mbtk_ril/src/main.c
+++ b/mbtk/mbtk_ril/src/main.c
@@ -320,8 +320,13 @@
                 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));

             } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>

                 //apn_state_set(atoi(s + 19), true);

+#ifdef MBTK_AF_SUPPORT

+				//data[0] = (uint8)1;

+                //data[1] = (uint8)atoi(s + 19);

+#else

                 data[0] = (uint8)1;

                 data[1] = (uint8)atoi(s + 19);

+#endif

             } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>

                 //apn_state_set(atoi(s + 19), true);

                 data[0] = (uint8)0;

diff --git a/mbtk/mbtk_ril/src/mbtk_info_server.c b/mbtk/mbtk_ril/src/mbtk_info_server.c
index 341c9c9..4073f5f 100755
--- a/mbtk/mbtk_ril/src/mbtk_info_server.c
+++ b/mbtk/mbtk_ril/src/mbtk_info_server.c
@@ -2753,6 +2753,10 @@
 
 
 */
+#ifdef MBTK_AF_SUPPORT
+mbtk_ip_type_enum default_iptype = MBTK_IP_TYPE_IPV4V6;
+#endif
+
 static int req_apn_get(void *data, int *data_len, int *cme_err)
 {
     ATResponse *response = NULL;
@@ -2813,6 +2817,12 @@
                 apn.ip_type = MBTK_IP_TYPE_PPP;
             }
 
+#ifdef MBTK_AF_SUPPORT
+            if(apn.cid == 1)
+            {
+                default_iptype = apn.ip_type;
+            }
+#endif
             err = at_tok_nextstr(&line, &tmp_str); // apn
             if (err < 0)
             {
@@ -4686,6 +4696,12 @@
                     else
                     {
                         // Save apn.
+#ifdef MBTK_AF_SUPPORT
+                        if(apn.cid == 1)
+                        {
+                            default_iptype = apn.ip_type;
+                        }
+#endif
                         apn_prop_set(&apn);
 
                         pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, NULL, 0);
@@ -4786,6 +4802,28 @@
                                 else
                                 {
                                     // Config IPv4 address.
+#ifdef MBTK_AF_SUPPORT
+                                    if(cid == 1)
+                                    {
+                                        //uint8 pdp_data = cid;
+                                        //pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
+                                        ipv4.valid = false;
+                                        ipv6.valid = false;
+                                        if(default_iptype == MBTK_IP_TYPE_IP)
+                                        {
+                                            ipv4.valid = true;
+                                        }
+                                        else if(default_iptype == MBTK_IP_TYPE_IPV6)
+                                        {
+                                            ipv6.valid = true;
+                                        }
+                                        else
+                                        {
+                                            ipv4.valid = true;
+                                            ipv6.valid = true;
+                                        }
+                                    }
+#endif
 #if 1
                                     if(ipv4.valid) {
                                         char dev[20] = {0};
@@ -4883,7 +4921,26 @@
 
                             int timeout = pack->data[2];
                             //mbtk wyq for data_call_ex add end
-                            
+#ifdef MBTK_AF_SUPPORT
+                            if(cid == 1)
+                            {
+                                char dev[20] = {0};
+                                uint8 pdp_data = cid + 100;
+                                pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
+                                
+                                sprintf(dev, "ccinet%d", cid - 1);
+
+                                // Config network.
+                                if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
+                                    LOGD("Config %s IPv4 0 fail.", dev);
+                                } else {
+                                    LOGD("Config %s IPv4 0 success.", dev);
+                                }
+                                cid_active[cid] = 0;
+                                pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
+                                break;
+                            }
+#endif
                             cgact_wait.waitting = true;
                             cgact_wait.cid = cid;
                             cgact_wait.act = false;
@@ -4926,6 +4983,11 @@
                             break;
                         }
                         case MBTK_DATA_CALL_STATE: {
+                            if(cid_active[cid] == 0)
+                            {
+                                err = MBTK_INFO_ERR_CID_NO_EXIST;
+                                break;
+                            }
                             mbtk_ipv4_info_t ipv4;
                             mbtk_ipv6_info_t ipv6;
                             memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
@@ -4943,6 +5005,26 @@
                             {
                                 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
                                 int buff_len = 0;
+#ifdef MBTK_AF_SUPPORT
+                                if(cid == 1)
+                                {
+                                    ipv4.valid = false;
+                                    ipv6.valid = false;
+                                    if(default_iptype == MBTK_IP_TYPE_IP)
+                                    {
+                                        ipv4.valid = true;
+                                    }
+                                    else if(default_iptype == MBTK_IP_TYPE_IPV6)
+                                    {
+                                        ipv6.valid = true;
+                                    }
+                                    else
+                                    {
+                                        ipv4.valid = true;
+                                        ipv6.valid = true;
+                                    }
+                                }
+#endif
                                 if(ipv4.valid && ipv6.valid) {
                                     buff[0] = (uint8)2;
                                     buff_len++;
@@ -5674,6 +5756,26 @@
         int cme_err = MBTK_INFO_ERR_CME_NON;
         if(!req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
         {
+#ifdef MBTK_AF_SUPPORT
+            if(cid == 1)
+            {
+                ipv4.valid = false;
+                ipv6.valid = false;
+                if(default_iptype == MBTK_IP_TYPE_IP)
+                {
+                    ipv4.valid = true;
+                }
+                else if(default_iptype == MBTK_IP_TYPE_IPV6)
+                {
+                    ipv6.valid = true;
+                }
+                else
+                {
+                    ipv4.valid = true;
+                    ipv6.valid = true;
+                }
+            }
+#endif
             // Config IPv4 address.
             if(ipv4.valid) {
                 char ip[20] = {0};
diff --git a/mbtk/ql_lib/src/ql_data_call.c b/mbtk/ql_lib/src/ql_data_call.c
index b08f228..218e14b 100755
--- a/mbtk/ql_lib/src/ql_data_call.c
+++ b/mbtk/ql_lib/src/ql_data_call.c
@@ -1,5 +1,6 @@
 #include "ql/DSI_ConnectManager.h"
 #include "mbtk_info_api.h"
+#include <fcntl.h>
 
 extern mbtk_info_handle_t* ql_info_handle;
 extern int ql_info_handle_num;
@@ -168,6 +169,85 @@
     return 0;
 }
 
+#ifdef MBTK_AF_SUPPORT
+int mbtk_route_config(int profile_idx)
+{
+    char buf[1024] = {0};
+    char dns[128] = {0};
+    int offset = 0;
+    int fd = -1;
+    mbtk_ipv4_info_t ipv4;
+    mbtk_ipv6_info_t ipv6;
+    sprintf(buf, "route add default dev ccinet%d", profile_idx -1);
+    system(buf);
+
+    int ret = mbtk_data_call_state_get(ql_info_handle, profile_idx, &ipv4, &ipv6);
+    if(ret != 0)
+        return -1;
+    else
+    {
+        memset(buf, 0x0, 1024);
+        memset(dns, 0x0, 128);
+        offset = sprintf(buf, "search lan\n");
+        if(ipv4.valid)
+        {
+            if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), dns, 32) == NULL) {
+                LOGD("PrimaryDNS error.");
+            } else {
+                LOGD("PrimaryDNS : %s", dns);
+            }
+            offset += sprintf(buf + offset, "nameserver %s\n", dns);
+            memset(dns, 0x0, 128);
+            if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), dns, 32) == NULL) {
+                LOGD("SecondaryDNS error.");
+            } else {
+                LOGD("SecondaryDNS : %s", dns);
+            }
+            offset += sprintf(buf + offset, "nameserver %s\n", dns);
+        }
+        if(ipv6.valid)
+        {
+            memset(dns, 0x0, 128);
+			if(ipv6_2_str(&(ipv6.PrimaryDNS), dns))
+            {
+				LOGD("PrimaryDNS error.");
+			} else {
+				LOGD("PrimaryDNS : %s", dns);
+			}
+            offset += sprintf(buf + offset, "nameserver %s\n", dns);
+            memset(dns, 0x0, 128);
+			if(ipv6_2_str(&(ipv6.SecondaryDNS), dns))
+            {
+				LOGD("SecondaryDNS error.");
+			} else {
+				LOGD("SecondaryDNS : %s", dns);
+			}
+            offset += sprintf(buf + offset, "nameserver %s\n", dns);
+        }
+
+        if(offset > 0)
+        {
+            fd = open("/tmp/resolv.conf", O_WRONLY | O_TRUNC);
+            if(fd < 0)
+            {
+                LOGD("mbtk_route_config : open fail.");
+                return -1;
+            }
+
+            ret = write(fd, buf, offset);
+            if(ret < 0)
+            {
+                LOGD("mbtk_route_config : write fail.");
+            }
+
+            close(fd);
+        }
+    }
+
+    return 0;
+}
+#endif
+
 int ql_wan_start_ex(int profile_idx, int op, ex_conn_status_cb nw_cb)
 {
     int ret = -1;
@@ -237,6 +317,13 @@
     {
         //ql_apn_info[8].cid=profile_idx;
         //ql_netw_status_cb(CONNECT_CONSUCCESS);
+#ifdef MBTK_AF_SUPPORT
+        if(profile_idx == 1)
+        {
+            mbtk_route_config(profile_idx);
+            
+        }
+#endif
         LOGD("mbtk_data_call_start() success.");
     }
 exit: