zte's code,first commit

Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/app/zte_comm/zte_mainctrl/net_other.c b/ap/app/zte_comm/zte_mainctrl/net_other.c
new file mode 100755
index 0000000..804c65b
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/net_other.c
@@ -0,0 +1,1377 @@
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <sys/ioctl.h>
+#include    <arpa/inet.h>
+#include    <net/if.h>
+#include    <net/route.h>
+#include    <string.h>
+#include    <dirent.h>
+
+#include "zte_mainctrl.h"
+
+extern void str_vary_dit(char * str, char *result);
+#if 0
+/*
+ * substitution of getNthValue which dosen't destroy the original value
+ */
+static int static_getNthValueSafe(int index, char *value, char delimit, char *result, int len)
+{
+	int i = 0, result_len = 0;
+	char *begin, *end;
+
+	if (!value || !result || !len)
+		return -1;
+
+	begin = value;
+	end = strchr(begin, delimit);
+
+	while (i < index && end) {
+		begin = end + 1;
+		end = strchr(begin, delimit);
+		i++;
+	}
+
+	//no delimit
+	if (!end) {
+		if (i == index) {
+			end = begin + strlen(begin);
+			result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+		} else
+			return -1;
+	} else
+		result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+
+	memcpy(result, begin, result_len);
+	*(result + result_len) = '\0';
+
+	return 0;
+}
+
+/*change the value of the Nth macip list */
+/*the macip list format is:
+  [mac1]+[ip1];[mac2]+[ip2];....*/
+/*add by lyf 2012/5/21*/
+static int changeNthValue(int index, char *value, char delimit, char *result, char *web_list)
+{
+	int i = 0;
+	int front_len = 0;
+	int end_len = 0;
+	int edit_len = 0;
+	int total_len = 0;
+
+	char *begin, *end;
+	char tempchar[NV_MACIP_LIST_MAX_LEN] = {0};
+
+	if (!value || !result || !web_list)
+		return -1;
+
+	begin = value;
+	end = strchr(begin, delimit);
+
+	while (i < index && end) {
+		begin = end + 1;
+		end = strchr(begin, delimit);
+		i++;
+	}
+
+	//no delimit
+	if (!end) {
+		if (i == index) {
+			end = begin + strlen(begin) - 1;
+			front_len = begin - value;
+			strncpy(tempchar, value, front_len);
+			strncpy(tempchar + front_len, web_list, (strlen(web_list)));
+			total_len = front_len + strlen(web_list);
+		} else {
+			return -1;
+		}
+	} else {
+		front_len = begin - value;
+		edit_len = end - begin;
+		end_len = strlen(value) - front_len - edit_len;
+		strncpy(tempchar, value, front_len);
+		strncpy(tempchar + front_len, web_list, strlen(web_list));
+		strncpy(tempchar + front_len + strlen(web_list), value + front_len + edit_len, end_len);
+		total_len = front_len + strlen(web_list) + end_len;
+
+
+	}
+
+	memcpy(result, tempchar, total_len);
+	*(result + total_len) = '\0';
+
+	return 0;
+}
+
+/*delete the value of the Nth macip list*/
+/*the macip list format is:
+  [mac1]+[ip1];[mac2]+[ip2];....*/
+/*add by lyf 2012/5/21*/
+static int deleteNthValue(int index,  char *value, char delimit)
+{
+	char *begin, *end;
+	int i = 0, j = 0;
+	int need_check_flag = 0;
+	char *buf = NULL;
+	int default_len = 0;
+
+	if (!value)
+		return -1;
+	buf = strdup(value);
+	begin = buf;
+	end = strchr(begin, delimit);
+	while (end) {
+		if (i == index) {
+			memset(begin, 0, end - begin);
+			if (index == 0)
+				need_check_flag = 1;
+			break;
+		}
+		begin = end;
+		end = strchr(begin + 1, delimit);
+		i++;
+	}
+
+	if (!end && index == i)
+		memset(begin, 0, strlen(begin));
+
+	if (need_check_flag) {
+		for (i = 0; i < strlen(value); i++) {
+			if (buf[i] == '\0')
+				continue;
+			if (buf[i] == ';')
+				buf[i] = '\0';
+			break;
+		}
+	}
+	default_len = strlen(value);
+	for (i = 0, j = 0; i < strlen(value); i++) {
+		if (buf[i] != '\0') {
+			value[j++] = buf[i];
+		}
+	}
+	for (i = j; i < default_len; i++)
+		value[i] = '\0';
+
+	free(buf);
+	return 0;
+}
+//·ÅÈëzte_router½ø³ÌʵÏÖ,opms_wan_modeÓ¦¸Ã¸ù¾Ýµ±Ç°µÄȱʡÍâÍø¿Ú£¬Ê¶±ð³öethwan_mode¡¢pswan_mode¡¢wifiwan_modeÆäÖеÄÒ»ÖÖ
+void zte_qos_list_run(void)
+{
+	char Qos_enable[CONFIG_DEFAULT_LENGTH] = {0};
+	char Qos_auto_control[CONFIG_DEFAULT_LENGTH] = {0};
+	char list[NV_QOS_LIST_MAX_LEN] = {0};
+	char rec[NV_QOS_LIST_MAX_LEN] = {0};
+	char opms_wan_mode[CONFIG_DEFAULT_LENGTH] = {0};
+	char wan_if[CONFIG_DEFAULT_LENGTH] = {0};
+	char lan_if_cable[CONFIG_DEFAULT_LENGTH] = {0};
+	char lan_if_wifi[CONFIG_DEFAULT_LENGTH] = {0};
+	char uplimit_total[CONFIG_DEFAULT_LENGTH] = {0};
+	char downlimit_total[CONFIG_DEFAULT_LENGTH] = {0};
+	int i = 0;
+	char ip_list[32] = {0};
+	char maxdownload[32] = {0};
+	char maxupload[32] = {0};
+	char tempchar[32] = {0};
+	cfg_get_item("Qos_enable", Qos_enable, sizeof(Qos_enable));
+	cfg_get_item("Qos_auto_control", Qos_auto_control, sizeof(Qos_auto_control));
+	cfg_get_item("opms_wan_mode", opms_wan_mode, sizeof(opms_wan_mode));
+	cfg_get_item("Qos_control_list", list, sizeof(list));
+	cfg_get_item("UpLimit_Total", uplimit_total, sizeof(uplimit_total));
+	cfg_get_item("DownLimit_Total", downlimit_total, sizeof(downlimit_total));
+
+	if (0 == strlen(opms_wan_mode)) {
+		return;
+	}
+
+	if (!strcmp(opms_wan_mode, "PPPOE")) {
+		strcpy(wan_if, "ppp0");
+		strcpy(lan_if_cable, "eth1");
+		strcpy(lan_if_wifi, "ath0");
+
+	}
+	if (!strcmp(opms_wan_mode, "PPP")) {
+		strcpy(wan_if, "usb0");
+		strcpy(lan_if_cable, "eth0");
+		strcpy(lan_if_wifi, "ath0");
+
+	}
+	if (!strcmp(opms_wan_mode, "DHCP") || !strcmp(opms_wan_mode, "STATIC")) {
+		strcpy(wan_if, "eth0");
+		strcpy(lan_if_cable, "eth1");
+		strcpy(lan_if_wifi, "ath0");
+
+	}
+	if (!strcmp(opms_wan_mode, "BRIDGE")) {
+		return;
+	}
+	/*clear the qdisc first before func return,important!(the qos state from enabled to disabled)*/
+	/*clear upload*/
+	ZTE_LOG(LOG_INFO, "delete the qdisc ################"); /*lint !e26*/
+	doSystem("tc qdisc del dev %s root", wan_if);
+	/*clear download*/
+	doSystem("tc qdisc del dev %s root", lan_if_cable);
+	doSystem("tc qdisc del dev %s root", lan_if_wifi);
+	/*flush the mangle table*/
+	doSystem("iptables -t mangle -F");
+	ZTE_LOG(LOG_INFO, "delete over qdisc::"); /*lint !e26*/
+
+	if (!strlen(Qos_enable)) {
+		return;
+	}
+	if (!atoi(Qos_enable)) {
+		return;
+	}
+	if (atoi(Qos_auto_control)) {
+		return;
+	}
+
+	if (0 == strlen(list)) {
+		return;
+	}
+	ZTE_LOG(LOG_INFO, "list= %s", list); /*lint !e26*/
+
+	/*mark data first for the upload limit(because of SNAT )*/
+	doSystem("iptables -t mangle -A PREROUTING  -p tcp -m length --length :64 -j MARK --set-mark 256 ");
+	doSystem("iptables -t mangle -A PREROUTING  -p tcp -m length --length :64 -j RETURN  ");
+
+	while ((static_getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
+		// get ip
+		if ((static_getNthValueSafe(0, rec, '+', ip_list, sizeof(ip_list)) == -1)) {
+			continue;
+		}
+		if (strlen(ip_list)) {
+			ZTE_LOG(LOG_INFO, "ip_list= %s", ip_list); /*lint !e26*/
+			sprintf(tempchar, "%d", i);
+			doSystem("iptables -t mangle -A PREROUTING -s %s -j MARK --set-mark %s ", ip_list, tempchar);
+			doSystem("iptables -t mangle -A PREROUTING -s %s -j RETURN ", ip_list);
+			memset(tempchar, 0, sizeof(tempchar));
+		}
+		memset(ip_list, 0, sizeof(ip_list));
+		memset(rec, 0, sizeof(rec));
+	}
+	/*upload&&download*/
+	doSystem("tc qdisc add dev %s root handle 1: htb", wan_if);
+	doSystem("tc qdisc add dev %s root handle 1: htb default 256", lan_if_cable);
+	doSystem("tc qdisc add dev %s root handle 1: htb default 256", lan_if_wifi);
+
+	doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", wan_if, uplimit_total, uplimit_total);
+	doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", lan_if_cable, downlimit_total, downlimit_total);
+	doSystem("tc class add dev %s parent 1: classid 1:256 htb rate %skbit ceil %skbit prio 0 ", lan_if_wifi, downlimit_total, downlimit_total);
+
+
+	doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", wan_if);
+	doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", lan_if_cable);
+	doSystem("tc qdisc add dev %s parent 1:256 handle 256: sfq perturb 5 ", lan_if_wifi);
+
+	doSystem("tc filter add dev %s parent 1:0 protocol ip prio 0 handle 256 fw classid 1:256", wan_if);
+
+	i = 0;
+	while ((static_getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
+		// get ip
+		if ((static_getNthValueSafe(0, rec, '+', ip_list, sizeof(ip_list)) == -1)) {
+			continue;
+		}
+		// get maxdownload
+		if ((static_getNthValueSafe(1, rec, '+', maxdownload, sizeof(maxdownload)) == -1)) {
+			continue;
+		}
+		// get maxupload
+		if ((static_getNthValueSafe(2, rec, '+', maxupload, sizeof(maxupload)) == -1)) {
+			continue;
+		}
+		/*the max download and upload can be 0*/
+		if (strlen(ip_list)) {
+
+			sprintf(tempchar, "%d", i);
+			doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", wan_if, tempchar, maxupload, maxupload);
+			doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", lan_if_cable, tempchar, maxdownload, maxdownload);
+			doSystem("tc class add dev %s parent 1: classid 1:%s htb rate %skbit ceil %skbit prio 1", lan_if_wifi, tempchar, maxdownload, maxdownload);
+			doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", wan_if, tempchar, tempchar);
+			doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", lan_if_cable, tempchar, tempchar);
+			doSystem("tc qdisc add dev %s parent 1:%s handle 1%s: sfq perturb 15", lan_if_wifi, tempchar, tempchar);
+			doSystem("tc filter add dev %s protocol ip parent 1:0 handle %s fw classid 1:%s", wan_if, tempchar, tempchar);
+			doSystem("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s flowid 1:%s", lan_if_cable, ip_list, tempchar);
+			doSystem("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s flowid 1:%s", lan_if_wifi, ip_list, tempchar);
+			memset(tempchar, 0, sizeof(tempchar));
+		}
+		memset(rec, 0, sizeof(rec));
+		memset(ip_list, 0, sizeof(ip_list));
+		memset(maxdownload, 0, sizeof(maxdownload));
+		memset(maxupload, 0, sizeof(maxupload));
+
+	}
+	cfg_save();
+}
+
+
+/*add a Qos list to the Qos control list */
+/*the Qos list format is:
+  [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
+/*add by lyf 2012/6/11*/
+void zte_goform_qoslist_add_process(char_t *web_ip, char_t *max_download, char_t *max_upload, char_t *web_comment)
+{
+
+
+	/* value of make qos list */
+	char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
+	char list[NV_QOS_LIST_MAX_LEN] = {0};
+
+	if (!max_download || !web_ip || !max_upload)
+		return;
+	cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
+	if (0 != strlen(qos_list)) {
+		snprintf(list, sizeof(list), "%s;%s+%s+%s+%s", qos_list, web_ip, max_download, max_upload, web_comment);
+	} else {
+		snprintf(list, sizeof(list), "%s+%s+%s+%s", web_ip, max_download, max_upload, web_comment);
+	}
+
+	cfg_set("Qos_control_list", list);
+
+	zte_qos_list_run();
+	cfg_save();
+
+}
+
+
+/*delete a Qos list from the  list */
+/*the Qos list format is:
+  [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
+/*add by lyf 2012/6/11*/
+void zte_goform_qoslist_del_process(char_t *index)/*lint !e129*/
+{
+	char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
+	//int list_count=0;
+	int deleIndex = 0;
+
+	if (!index)
+		return;
+	/*the web index begin from 1,but the fun index begin from 0*/
+	deleIndex = atoi(index) - 1;
+	cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
+	if (0 == strlen(qos_list)) {
+		return;
+	}
+
+	deleteNthValue(deleIndex, qos_list, ';');
+	cfg_set("Qos_control_list", qos_list);
+	zte_qos_list_run();
+	cfg_save();
+
+
+
+}
+
+
+
+/*edit a qos list of the list */
+/*the Qos list format is:
+  [ip]+[maxdownload]+[maxupload]+[comment];[ip]+[maxdownload]+[maxupload]+[comment];....*/
+/*add by lyf 2012/6/11*/
+void zte_goform_qoslist_edit_process(char_t *web_ip, char_t *maxdownload, char_t *maxupload, char_t *web_comment, char_t *index) /*lint !e129*/
+{
+	char qos_address[64] = {0};
+	char qos_list[NV_QOS_LIST_MAX_LEN] = {0};
+	char rec[NV_QOS_LIST_MAX_LEN] = {0};
+	int editIndex = 0;
+
+	if (!web_ip || !maxdownload || !maxupload || !index)
+		return;
+	/*the web index begin from 1,but the fun index begin from 0*/
+	editIndex = atoi(index) - 1;
+	cfg_get_item("Qos_control_list", qos_list, sizeof(qos_list));
+	if (0 == strlen(qos_list)) {
+		return;
+	}
+
+	sprintf(qos_address, "%s+%s+%s+%s", web_ip, maxdownload, maxupload, web_comment);
+	changeNthValue(editIndex, qos_list, ';', rec, qos_address);
+	cfg_set("Qos_control_list", rec);
+	zte_qos_list_run();
+	cfg_save();
+
+}
+
+
+/*QoS£¬ÔÝδʵÏÖÐèÇó£¬opms_wan_modeÓ¦¸Ã¸ù¾Ýµ±Ç°µÄȱʡÍâÍø¿Ú£¬Ê¶±ð³öethwan_mode¡¢pswan_mode¡¢wifiwan_modeÆäÖеÄÒ»ÖÖ*/
+void zte_goform_Qos(void)/*lint !e18*/
+{
+	char Qos_enable[CONFIG_DEFAULT_LENGTH] = {0};
+	char Qos_auto_control[CONFIG_DEFAULT_LENGTH] = {0};
+	char opms_wan_mode[CONFIG_DEFAULT_LENGTH] = {0};
+	char ack_enable[CONFIG_DEFAULT_LENGTH] = {0};
+
+	cfg_get_item("Qos_enable", Qos_enable, sizeof(Qos_enable));
+	cfg_get_item("Qos_auto_control", Qos_auto_control, sizeof(Qos_auto_control));
+	cfg_get_item("opms_wan_mode", opms_wan_mode, sizeof(opms_wan_mode));
+	cfg_get_item("Qos_control_list", ack_enable, sizeof(ack_enable));
+
+	if (!atoi(Qos_enable)) {
+		/*if the wanmode is ppp0,then to call the ack first shall scrip*/
+		if (atoi(ack_enable)) {
+			if (!strcmp(opms_wan_mode, "PPP")) {
+				ZTE_LOG(LOG_INFO, "ack first is running////////////"); /*lint !e26*/
+				doSystem("ack_first.sh");
+			}
+			cfg_save();
+			return ;/*lint !e533 !e110 */
+		}
+
+
+
+		doSystem("speed_limit_ini.sh");
+		cfg_save();
+		return ;/*lint !e533 !e110 */
+	}
+
+	if (!atoi(Qos_auto_control)) {
+		zte_qos_list_run();
+	} else {
+		ZTE_LOG(LOG_INFO, "QoS auto traffic control is starting!");/*lint !e26*/
+
+		doSystem("qos.sh");
+
+	}
+	cfg_save();
+}
+
+/******************************************************
+* Function: zte_static_route_list_ini_run()
+* Description:  run the static route list after the device reboot
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
+* Input:
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_ini_run(void)
+{
+	//char name[CONFIG_DEFAULT_LENGTH] = {0};
+	char des_ip[32] = {0};
+	char subnet_mask[32] = {0};
+	char gateway[32] = {0};
+	char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char rec[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char pirvate[3] = {0}; /*private button*/
+	char active[3] = {0}; /*active button*/
+	char metric[3] = {0};
+	int list_index = 0;
+	int active_flag = 0;
+
+	cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
+	if (0 == strlen(static_routelist)) {
+		return;
+	}
+	while ((getNthValueSafe(list_index++, static_routelist, ';', rec, sizeof(rec)) != -1)) {
+		/*get private info*/
+		if ((getNthValueSafe(1, rec, '+', pirvate, sizeof(pirvate)) == -1)) {
+			continue;
+		}
+		/*get active info*/
+		if ((getNthValueSafe(2, rec, '+', active, sizeof(active)) == -1)) {
+			continue;
+		}
+		/*get des ip address*/
+		if ((getNthValueSafe(3, rec, '+', des_ip, sizeof(des_ip)) == -1)) {
+			continue;
+		}
+		/*get subnet mask*/
+		if ((getNthValueSafe(4, rec, '+', subnet_mask, sizeof(subnet_mask)) == -1)) {
+			continue;
+		}
+		/*get gateway*/
+		if ((getNthValueSafe(5, rec, '+', gateway, sizeof(gateway)) == -1)) {
+			continue;
+		}
+		/*get metric*/
+		if ((getNthValueSafe(6, rec, '+', metric, sizeof(metric)) == -1)) {
+			continue;
+		}
+		if ((0 != strlen(active)) && (0 != strlen(des_ip))
+		    && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
+			if (active_flag = atoi(active)) {
+				if (!strcmp(subnet_mask, "255.255.255.255")) {
+					doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
+				} else {
+					doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
+				}
+			}
+		}
+
+
+	}
+
+	cfg_save();
+
+
+}
+
+/******************************************************
+* Function: zte_static_route_list_add()
+* Description:  add a list to the static route list
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
+* Input:  static route info from the web
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_add(char *name, char *private, char *active, char *des_ip, char *subnet_mask, char *gateway, char *metric)
+{
+	char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	int active_flag = 0;
+
+	if (!name || !des_ip || !subnet_mask || !gateway) { /*private,active,metric may equal to 0*/
+		return;
+	}
+	cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
+
+	if (0 != strlen(static_routelist)) {
+		snprintf(list, sizeof(list), "%s;%s+%s+%s+%s+%s+%s+%s", static_routelist, name, private, active, des_ip, subnet_mask, gateway, metric);
+	} else {
+		snprintf(list, sizeof(list), "%s+%s+%s+%s+%s+%s+%s", name, private, active, des_ip, subnet_mask, gateway, metric);
+	}
+
+	cfg_set("static_route_list", list);
+	if (active_flag = atoi(active)) {
+		if (!strcmp(subnet_mask, "255.255.255.255")) {
+			doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
+		} else {
+			doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
+		}
+	}
+
+	cfg_save();
+}
+/******************************************************
+* Function: zte_static_route_list_run_one()
+* Description:  run one list from the static route list
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric]
+* Input:
+  list--the list to run
+  delimit -- delimitor
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_run_one(char *list, char delimit)
+{
+	char des_ip[32] = {0};
+	char subnet_mask[32] = {0};
+	char gateway[32] = {0};
+	char pirvate[3] = {0};
+	char active[3] = {0};
+	char metric[3] = {0};
+	int active_flag = 0;
+
+	if (!list) {
+		return;
+	}
+
+	/*get private info*/
+	if ((getNthValueSafe(1, list, delimit, pirvate, sizeof(pirvate)) == -1)) { /*the index begin from 1,ingore the name(index 0)*/
+		return;
+	}
+	/*get active info*/
+	if ((getNthValueSafe(2, list, delimit, active, sizeof(active)) == -1)) {
+		return;
+	}
+	/*get des ip address*/
+	if ((getNthValueSafe(3, list, delimit, des_ip, sizeof(des_ip)) == -1)) {
+		return;
+	}
+	/*get subnet mask*/
+	if ((getNthValueSafe(4, list, delimit, subnet_mask, sizeof(subnet_mask)) == -1)) {
+		return;
+	}
+	/*get gateway*/
+	if ((getNthValueSafe(5, list, delimit, gateway, sizeof(gateway)) == -1)) {
+		return;
+	}
+	/*get metric*/
+	if ((getNthValueSafe(6, list, delimit, metric, sizeof(metric)) == -1)) {
+		return;
+	}
+	if ((0 != strlen(active)) && (0 != strlen(des_ip))
+	    && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
+		if (active_flag = atoi(active)) {
+			if (!strcmp(subnet_mask, "255.255.255.255")) {
+				doSystem("route add -host %s gw %s metric %s", des_ip, gateway, metric);
+			} else {
+				doSystem("route add -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
+			}
+		}
+	}
+
+}
+/******************************************************
+* Function: zte_static_route_list_del_one()
+* Description:  delete one list from the static route list
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric]
+* Input:
+  list--the list to delete
+  delimit -- delimitor
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_del_one(char *list, char delimit)
+{
+	char des_ip[32] = {0};
+	char subnet_mask[32] = {0};
+	char gateway[32] = {0};
+	char pirvate[3] = {0};
+	char active[3] = {0};
+	char metric[3] = {0};
+	int active_flag = 0;
+
+	if (!list) {
+		return;
+	}
+
+	/*get private info*/
+	if ((getNthValueSafe(1, list, delimit, pirvate, sizeof(pirvate)) == -1)) { /*the index begin from 1,ingore the name(index 0)*/
+		return;
+	}
+	/*get active info*/
+	if ((getNthValueSafe(2, list, delimit, active, sizeof(active)) == -1)) {
+		return;
+	}
+	/*get des ip address*/
+	if ((getNthValueSafe(3, list, delimit, des_ip, sizeof(des_ip)) == -1)) {
+		return;
+	}
+	/*get subnet mask*/
+	if ((getNthValueSafe(4, list, delimit, subnet_mask, sizeof(subnet_mask)) == -1)) {
+		return;
+	}
+	/*get gateway*/
+	if ((getNthValueSafe(5, list, delimit, gateway, sizeof(gateway)) == -1)) {
+		return;
+	}
+	/*get metric*/
+	if ((getNthValueSafe(6, list, delimit, metric, sizeof(metric)) == -1)) {
+		return;
+	}
+	if ((0 != strlen(active)) && (0 != strlen(des_ip))
+	    && (0 != strlen(subnet_mask)) && (0 != strlen(gateway))) {
+		if (active_flag = atoi(active)) {
+			if (!strcmp(subnet_mask, "255.255.255.255")) {
+				doSystem("route del -host %s gw %s metric %s", des_ip, gateway, metric);
+			} else {
+				doSystem("route del -net %s netmask %s gw %s metric %s", des_ip, subnet_mask, gateway, metric);
+			}
+		}
+	}
+
+}
+/******************************************************
+* Function: zte_static_route_list_del()
+* Description:  delete a list from the static route list according to the delete index
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
+* Input:
+  index--the index  of deleted items
+  delimit -- delimitor
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_del(int index, char delimit)
+{
+	char static_routelist[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};/*temp list*/
+	//int active_flag=0;
+	char *begin = NULL;
+	char *end = NULL;
+	char *buf = NULL;
+	int i = 0;
+	int j = 0;
+	int need_check_flag = 0;
+	int default_len = 0;
+
+	cfg_get_item("static_route_list", static_routelist, sizeof(static_routelist));
+	if (!strlen(static_routelist)) {
+		return;
+	}
+
+	buf = strdup(static_routelist);
+	begin = buf;
+	end = strchr(begin, delimit);
+	while (end) {
+		if (i == index) {
+			strncpy(list, begin, end - begin);
+			zte_static_route_list_del_one(list, '+');
+			memset(begin, 0, end - begin);
+			memset(list, 0, strlen(list));
+			if (index == 0)
+				need_check_flag = 1;
+			break;
+		}
+		begin = end;
+
+		end = strchr(begin + 1, delimit);
+		i++;
+	}
+	if (!end && index == i) {
+		strncpy(list, begin, strlen(begin));
+		zte_static_route_list_del_one(list, '+');
+		memset(list, 0, strlen(list)); /*set the temp list to 0*/
+		memset(begin, 0, strlen(begin));
+
+	}
+
+
+	if (need_check_flag) {
+		for (i = 0; i < strlen(static_routelist); i++) {
+			if (buf[i] == '\0') {
+				continue;
+			}
+			if (buf[i] == ';') {
+				buf[i] = '\0';
+			}
+			break;
+		}
+	}
+	default_len = strlen(static_routelist);
+	for (i = 0, j = 0; i < strlen(static_routelist); i++) {
+		if (buf[i] != '\0') {
+			static_routelist[j++] = buf[i];
+		}
+	}
+	for (i = j; i < default_len; i++)
+		static_routelist[i] = '\0';
+
+	cfg_set("static_route_list", static_routelist);
+	cfg_save();
+	free(buf);
+
+
+}
+/******************************************************
+* Function: zte_static_route_list_edit_one()
+* Description:  edit a list from the static route list
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
+* Input:
+  index--the index of deleted item
+  value--the static route list
+  delimit--delimitor
+  web_list--static route info from the web
+* Output:
+  result-- the edited static route list
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+int zte_static_route_list_edit_one(int index, char *value, char delimit, char *result, char *web_list)
+{
+	int i = 0;
+	int front_len = 0;
+	int end_len = 0;
+	int edit_len = 0;
+	int total_len = 0;
+	char *begin = NULL;
+	char *end = NULL;
+	char tempchar[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char dosys_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+
+	if (!value || !result || !web_list)
+		return -1;
+
+	begin = value;
+	end = strchr(begin, delimit);
+	while (i < index && end) {
+		begin = end + 1;
+		end = strchr(begin, delimit);
+		i++;
+	}
+
+	//no delimit
+	if (!end) {
+		if (i == index) {
+			end = begin + strlen(begin) - 1;
+			strncpy(dosys_list, begin, end - begin + 1);
+			printf(dosys_list);
+			zte_static_route_list_del_one(dosys_list, '+');
+			memset(dosys_list, 0, strlen(dosys_list));
+			front_len = begin - value;
+			strncpy(tempchar, value, front_len);
+			strncpy(tempchar + front_len, web_list, (strlen(web_list)));
+			zte_static_route_list_run_one(web_list, '+');
+			total_len = front_len + strlen(web_list);
+		} else {
+			return -1;
+		}
+	} else {
+		front_len = begin - value;
+		edit_len = end - begin;
+		end_len = strlen(value) - front_len - edit_len;
+		strncpy(dosys_list, begin, end - begin);
+		printf(dosys_list);
+		zte_static_route_list_del_one(dosys_list, '+');
+		memset(dosys_list, 0, strlen(dosys_list));
+		strncpy(tempchar, value, front_len);
+		strncpy(tempchar + front_len, web_list, strlen(web_list));
+		strncpy(tempchar + front_len + strlen(web_list), value + front_len + edit_len, end_len);
+		zte_static_route_list_run_one(web_list, '+');
+		total_len = front_len + strlen(web_list) + end_len;
+	}
+	memcpy(result, tempchar, total_len);
+	*(result + total_len) = '\0';
+
+	return 0;
+
+}
+/******************************************************
+* Function: zte_static_route_list_edit()
+* Description:  edit a list from the static route list
+  call zte_static_route_list_edit_one() to process
+  the static route list format is:
+   [name]+[private]+[active]+[des ip]+[ip subnet mask]+[GateWay]+[metric];.....
+* Input:
+  index--the index of deleted item
+  list info from the web
+* Output:
+* Return:
+* Others:
+* 2012/5/21  created by Liu Yifei
+*******************************************************/
+void zte_static_route_list_edit(char *index, char *web_name, char *web_private, char *web_active, char *web_des_ip, char *web_subnet_mask, char *web_gateway, char *web_metric)
+{
+	char staticroute_one_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char static_route_list[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	char rec[NV_STATIC_ROUTE_LIST_MAX_LEN] = {0};
+	int editIndex = 0;
+	if (!web_name || !web_des_ip || !web_subnet_mask || !web_gateway) { /*private,active,metric may equal to 0*/
+		return;
+	}
+	editIndex = atoi(index) - 1;
+	cfg_get_item("static_route_list", static_route_list, sizeof(static_route_list));
+	if (!strlen(static_route_list)) {
+		return;
+	}
+	sprintf(staticroute_one_list, "%s+%s+%s+%s+%s+%s+%s", web_name, web_private, web_active, web_des_ip, web_subnet_mask, web_gateway, web_metric);
+	zte_static_route_list_edit_one(editIndex, static_route_list, ';', rec, staticroute_one_list);
+	cfg_set("static_route_list", rec);
+	cfg_save();
+}
+#endif
+
+//add by gongxuanhui 03/13/2014
+static void zte_router_make_MTU_Rule(char *buf, int len, char *wan_name, char *mtu_value)
+{
+	snprintf(buf, len, "ifconfig %s mtu %s ", wan_name,  mtu_value);
+}
+
+//add by gongxuanhui 03/13/2014
+void zte_router_MTU_set(void)
+{
+
+	char cmd[1024] = {0};
+	char mtu[128] = {0};
+	int mtu_int;
+
+	memset(cmd, 0, sizeof(cmd));
+
+	//zte_router_nvconfig_read("mtu");
+	//strcpy(mtu , g_router_nvconfig_buf);
+
+	cfg_get_item("mtu", mtu, sizeof(mtu));
+
+	if (0 == strcmp(mtu, "")) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: mtu  valu is null \n");
+		return;
+	}
+
+	if ((mtu_int = atoi(mtu)) < 1280 || mtu_int > 1500) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: mtu value is illgality\n");
+		return;
+	}
+
+	zte_router_make_MTU_Rule(cmd, sizeof(cmd), defwan_rel, mtu);
+
+	system_cmd_ex(cmd);
+	//system_cmd_ex("firewall_init.sh");
+	return;
+}
+
+//1217
+void zte_unpn_set(void)
+{
+	char upnpEnabled[8] = {0};
+	
+	cfg_get_item("upnpEnabled", upnpEnabled, sizeof(upnpEnabled));
+	slog(NET_PRINT, SLOG_NORMAL, "router : start to set upnp %s\n", upnpEnabled);
+	if(atoi(upnpEnabled))
+		system_cmd_ex("upnp.sh");
+}
+void zte_router_dhcp_set_process(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "router : start to set dhcp \n");
+	system_cmd_ex("lan.sh");
+	//doSystem("killall fullshare");
+	//doSystem("killall smbd");
+	//doSystem("killall nmbd");
+	//doSystem("fullshare &");
+	//doSystem("smbd -D");
+	//doSystem("nmbd -D");
+	//doSystem("sh /mnt/jffs2/scripts/upnp.sh");
+}
+
+//add by gongxuanhui 03/13/2014
+void zte_router_mtu_set_process(void)
+{
+	//zte_router_MTU_set();
+	zte_router_init();
+}
+
+
+//set  mac_ip_list when get msg from web_firewall 08/09/2015
+void zte_macip_list_run(void)
+{
+	char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char list[NV_MACIP_LIST_MAX_LEN] = {0};
+	char mac_address[32] = {0};   /*mac address */
+	char ip_address[32]  = {0};  /*ip address */
+
+	int dhcp_server_enable = 0;
+	int i = 0;
+	char rec[NV_MACIP_LIST_MAX_LEN] = {0};
+	char cmd[1024] = {0};
+
+	cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
+	if (0 == strlen(dhcp_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
+		return;
+	}
+	dhcp_server_enable = atoi(dhcp_enable);
+	/* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == dhcp_server_enable) {
+		return;
+	}
+
+	cfg_get_item("mac_ip_list", list, sizeof(list));
+
+	/*kill udhcpd*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -k");
+	/*clear the static_lease list in udhcpd.conf file*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -S");
+	while ((getNthValueSafe(i++, list, ';', rec, sizeof(rec)) != -1)) {
+		// get mac
+		if ((getNthValueSafe(1, rec, '+', mac_address, sizeof(mac_address)) == -1)) {
+			continue;
+		}
+		// get ip
+		if ((getNthValueSafe(2, rec, '+', ip_address, sizeof(ip_address)) == -1)) {
+			continue;
+		}
+		if ((0 != strlen(mac_address))
+		    && (0 != strlen(ip_address))) {
+			memset(cmd, 0, sizeof(cmd));
+			sprintf(cmd, "config-udhcpd.sh \"lan\" -S %s %s", mac_address, ip_address);
+			system_cmd_ex(cmd);
+			//system_cmd_ex("config-udhcpd.sh -S %s %s",mac_address,ip_address);
+		}
+
+
+	}
+
+	/*restart udhcpd*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -r");
+
+}
+
+void zte_bind_macip_list(void)
+{
+	char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+
+	cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
+	if (0 == strlen(dhcp_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
+		return;
+	}
+	/* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == atoi(dhcp_enable)) {
+		return;
+	}
+
+	/*kill udhcpd*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -k");
+
+	cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
+
+	//static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õudhcpd.confÎļþÖа󶨵ÄMAC-IP
+	//static_dhcp_enable=1,¿ªÆôMAC-IP°ó¶¨¹¦ÄÜ£¬½«Ö®Ç°µÄMAC-IP°ó¶¨¹ØÏµÖØÐÂдÈëudhcpd.conf
+	if (0 == atoi(static_dhcp_enable)) {
+		/*clear the static_lease list in udhcpd.conf file*/
+		system_cmd_ex("config-udhcpd.sh \"lan\" -S");
+	} else
+		system_cmd_ex("config-udhcpd.sh \"lan\" -E");
+
+	system_cmd_ex("config-udhcpd.sh \"lan\" -r");
+
+}
+
+void zte_bind_macip_list_add(struct static_macip_info *static_macip)
+{
+	char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char* mac_address = NULL;   /*mac address  to add*/
+	char* ip_address = NULL;  /*ip address to add */
+	char cmd[200] = {0};
+
+	cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
+	if (0 == strlen(dhcp_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
+		return;
+	}
+	/* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == atoi(dhcp_enable)) {
+		return;
+	}
+
+	mac_address = static_macip->mac;
+	ip_address = static_macip->ip;
+
+	/*kill udhcpd*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -k");
+
+	cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
+
+	//static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õ°ó¶¨µÄMAC-IP
+	if (1 == atoi(static_dhcp_enable)) {
+		//Ôö¼ÓMAC-IP°ó¶¨¹æÔò
+		if ((0 != strlen(mac_address)) && (0 != strlen(ip_address))) {
+			sprintf(cmd, "config-udhcpd.sh \"lan\" -S %s %s", mac_address, ip_address);
+			system_cmd_ex(cmd);
+		}
+	}
+
+	system_cmd_ex("config-udhcpd.sh \"lan\" -r");
+
+}
+
+void zte_bind_macip_list_del(char* mac)
+{
+	char dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char static_dhcp_enable[ROUTER_DEFAULT_LEN] = {0};
+	char cmd[200] = {0};
+
+	cfg_get_item("dhcpEnabled", dhcp_enable, sizeof(dhcp_enable));
+	if (0 == strlen(dhcp_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Error: can't find \"dhcpEnabled\" in flash.\n"); /*lint !e26*/
+		return;
+	}
+	/* if dhcp is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == atoi(dhcp_enable)) {
+		return;
+	}
+
+	/*kill udhcpd*/
+	system_cmd_ex("config-udhcpd.sh \"lan\" -k");
+
+	cfg_get_item("static_dhcp_enable", static_dhcp_enable, sizeof(static_dhcp_enable));
+
+	//static_dhcp_enable=0,¹Ø±ÕMAC-IP°ó¶¨¹¦ÄÜ£¬Çå¿Õ°ó¶¨µÄMAC-IP
+	if (1 == atoi(static_dhcp_enable)) {
+		//ɾ³ýMAC-IP°ó¶¨¹æÔò
+		if (0 != strlen(mac)) {
+			sprintf(cmd, "config-udhcpd.sh \"lan\" -D %s", mac);
+			system_cmd_ex(cmd);
+		}
+	}
+
+	system_cmd_ex("config-udhcpd.sh \"lan\" -r");
+
+}
+
+
+void get_mac_hostname_pro(struct mac_hostname_info *mac_hostname_)
+{
+	char *mac = NULL;
+	char *hostname = NULL;
+	char cmd[200] = {0};
+	mac = mac_hostname_->mac;
+	hostname = mac_hostname_->hostname;
+	sprintf(cmd, "config-hostname.sh \"%s\" \"%s\"", mac, hostname);
+	system_cmd_ex(cmd);
+
+}
+
+void children_device_add(struct mac_hostname_info *mac_hostname)
+{
+	char *mac = NULL;
+	char *hostname = NULL;
+	char cmd[200] = {0};
+	mac = mac_hostname->mac;
+	hostname = mac_hostname->hostname;
+	slog(NET_PRINT, SLOG_NORMAL, "children_device_add:mac= %s, hostname = %s\n", mac, hostname);
+	if ((0 != strlen(mac)) && (0 != strlen(hostname))) {
+		sprintf(cmd, "config-parents.sh device \"%s\" \"%s\"", mac, hostname);
+		system_cmd_ex(cmd);
+	}
+}
+
+void children_device_del(char * mac)
+{
+	char cmd[100] = {0};
+	if (0 != strlen(mac)) {
+		sprintf(cmd, "config-parents.sh device \"%s\"", mac);
+		system_cmd_ex(cmd);
+	}
+}
+
+
+void white_site_add(struct white_site_info * white_site)
+{
+	char *name = NULL;
+	char *site = NULL;
+	char cmd[600] = {0};
+	name = white_site->name;
+	site = white_site->site;
+	slog(NET_PRINT, SLOG_NORMAL, "white_site_add:site= %s, name = %s\n", site, name);
+	if (0 != strlen(site)) {
+		sprintf(cmd, "config-parents.sh white_site -A \"%s\" \"%s\"", site, name);
+		system_cmd_ex(cmd);
+	}
+
+}
+
+
+void white_site_remove(char * ids)
+{
+	char cmd[100] = {0};
+	if (0 != strlen(ids)) {
+		sprintf(cmd, "config-parents.sh white_site -D \"%s\"", ids);
+		system_cmd_ex(cmd);
+	}
+}
+
+
+void zte_children_start_nonet(void)
+{
+	char sys_cmd_bufer[500] = {0};
+
+	FILE *chilren_device_file = NULL;
+	char line[200] = {0};
+	char mac[18] = {0};
+	char path_conf[50] = {0};
+	char path_file[100] = {0};
+	cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/children_device_file", path_conf);
+
+	/*flush filter chain*/
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_MAC_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_PHONE_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+
+
+	chilren_device_file = fopen(path_file, "r");
+	if (chilren_device_file == NULL) {
+		fprintf(stderr, "can not open file children_device_file.");
+		return;
+	}
+
+	while (fgets(line, 200, chilren_device_file) != NULL) {
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+
+		strncpy(mac, line, 17);
+
+		if (strcmp(mac, "") != 0) {
+			sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -j DROP", CLILDREN_MAC_CHAIN, mac);
+			slog(NET_PRINT, SLOG_NORMAL, "%s \n", sys_cmd_bufer);
+			system_cmd_ex(sys_cmd_bufer);
+		}
+
+		memset(line, 0, sizeof(line));
+		memset(mac, 0, sizeof(mac));
+	}
+	fclose(chilren_device_file);
+}
+
+static void make_children_white_site_rule(char mac[])
+{
+	slog(NET_PRINT, SLOG_NORMAL, "make_children_white_site_rule start! \n");
+	char sys_cmd_bufer[600] = {0};
+	FILE *white_site_file = NULL;
+	char url_hexstring[ZTE_ROUTER_URL_FILTER_LEN] = {0};
+	char line[600] = {0};
+	char site[600] = {0};//klocwork
+	char temp_site[600] = {0};
+
+	unsigned int len = 0;
+
+	char path_conf[50] = {0};
+	char path_file[100] = {0};
+	cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/white_site_file", path_conf);
+
+	white_site_file = fopen(path_file, "r");
+	if (white_site_file == NULL) {
+		fprintf(stderr, "can not open file white_site_file.");
+
+		//PCÖÕ¶Ë:ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_CHAIN, mac);
+		system_cmd_ex(sys_cmd_bufer);
+
+		//ÊÖ»úÖÕ¶Ë:ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_PHONE_CHAIN, mac);
+		system_cmd_ex(sys_cmd_bufer);
+
+		return;
+	}
+
+	while (fgets(line, 600, white_site_file) != NULL) {
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		memset(url_hexstring, 0, sizeof(url_hexstring));
+
+		int i = 0;
+		for (i = 0; i < 600; i++) {
+			if (line[i] == ',') {
+				len = i;
+				break;
+			}
+		}
+		strncpy(site, line, len);
+
+		if (strcmp(site, "") != 0) {
+			//È¥³ý꿅Ⴁ̾µÄhttpÍ·²¿
+			if (!strncasecmp(site, "http://", strlen("http://"))) {
+				strncpy(site, site + strlen("http://"), sizeof(site)-1);
+			}
+			if (!strncasecmp(site, "https://", strlen("https://"))) {
+				strncpy(site, site + strlen("https://"), sizeof(site)-1);
+			}
+			//È¥³ýÍøÖ·ºóÃæ.com/ºóµÄβ²¿
+			int seq = 0;
+			int len_site = 0;
+			memset(temp_site, 0, sizeof(temp_site));
+			strcpy(temp_site, site);
+			for (seq = 0; seq < strlen(temp_site); seq++) {
+				if (temp_site[seq] == '/') {
+					len_site = seq;
+					memset(site, 0, sizeof(site));
+					strncpy(site, temp_site, len_site);
+					break;
+				}
+			}
+
+
+
+			str_vary_dit(site, url_hexstring);
+			slog(NET_PRINT, SLOG_NORMAL, "site=%s url_hexstring=%s\n", site, url_hexstring);
+			snprintf(sys_cmd_bufer, sizeof(sys_cmd_bufer), "iptables -A %s -m mac --mac-source %s -m string --hex-string  \"|%s|\" --algo kmp -j ACCEPT", \
+			        CLILDREN_WEB_CHAIN, mac, url_hexstring);//klocwork
+			system_cmd_ex(sys_cmd_bufer);
+
+			memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+			snprintf(sys_cmd_bufer, sizeof(sys_cmd_bufer), "iptables -A %s -m mac --mac-source %s -m string --hex-string  \"|%s|\" --algo kmp -j ACCEPT", \
+			        CLILDREN_WEB_PHONE_CHAIN, mac, url_hexstring);
+			system_cmd_ex(sys_cmd_bufer);
+
+		}
+
+		memset(line, 0, sizeof(line));
+		memset(site, 0, sizeof(site));
+		len = 0;
+	}
+
+	fclose(white_site_file);
+
+	//ĬÈϽ«macµØÖ·µÄ53¶Ë¿ÚµÄ°ü¶ªµô
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_CHAIN, mac);
+	system_cmd_ex(sys_cmd_bufer);
+
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -A %s -m mac --mac-source %s -p udp --dport 53 -j DROP", CLILDREN_WEB_PHONE_CHAIN, mac);
+	system_cmd_ex(sys_cmd_bufer);
+
+
+}
+
+void zte_children_stop_nonet(void)
+{
+	char sys_cmd_bufer[500] = {0};
+	FILE *chilren_device_file = NULL;
+	char line[200] = {0};
+	char mac[18] = {0};
+
+	char path_conf[50] = {0};
+	char path_file[100] = {0};
+	cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/children_device_file", path_conf);
+
+	system_cmd_ex("iptables -t filter -D INPUT -p udp --dport 53  -j ACCEPT");
+	system_cmd_ex("iptables -t filter -D FORWARD -p udp --dport 53  -j ACCEPT");
+
+
+
+	/*flush filter chain*/
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_MAC_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", CLILDREN_WEB_PHONE_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+
+	chilren_device_file = fopen(path_file, "r");
+	if (chilren_device_file == NULL) {
+		fprintf(stderr, "can not open file children_device_file.");
+		return;
+	}
+
+	while (fgets(line, 200, chilren_device_file) != NULL) {
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+
+		strncpy(mac, line, 17);
+
+		if (strcmp(mac, "") != 0) {
+			make_children_white_site_rule(mac);
+		}
+
+		memset(line, 0, sizeof(line));
+		memset(mac, 0, sizeof(mac));
+	}
+	fclose(chilren_device_file);
+}
+
+/* DHCP_SETTING_REQ */
+void zte_router_dhcp_setting_req_process(dhcp_setting_req *pdhcp_setting_req)
+{
+	(void)cfg_set("lan_ipaddr", pdhcp_setting_req->lan_ip);
+	(void)cfg_set("lan_netmask", pdhcp_setting_req->lan_netmask);
+	if (!pdhcp_setting_req->dhcp_enabled) {
+		(void)cfg_set("dhcpEnabled", "0");
+	} else {
+		(void)cfg_set("dhcpEnabled", "1");
+		(void)cfg_set("dhcpStart", pdhcp_setting_req->dhcp_start);
+		(void)cfg_set("dhcpEnd", pdhcp_setting_req->dhcp_end);
+		(void)cfg_set("dhcpDns", pdhcp_setting_req->dhcp_dns);
+		(void)cfg_set("dhcpLease_hour", pdhcp_setting_req->dhcp_lease);
+	}
+
+	system_cmd_ex("user-config-udhcpd.sh");
+}
+
diff --git a/ap/app/zte_comm/zte_mainctrl/net_xfrm.c b/ap/app/zte_comm/zte_mainctrl/net_xfrm.c
new file mode 100755
index 0000000..cb43e18
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/net_xfrm.c
@@ -0,0 +1,1690 @@
+#include "zte_mainctrl.h"
+
+char g_router_nvconfig_buf[ROUTER_NV_ITEM_VALUE_MAX_LEN];
+char defwan_rel[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+
+static char defwan6_rel[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+//static struct url_list old_url_list;
+extern int g_limit_time_flag;
+
+
+/******************************************************
+* Func:    system_cmd_ex
+* Desc:    do system cmd, but printf it first
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+*
+*******************************************************/
+
+void str_vary_dit(char * str, char *result)
+{
+	char ch_num = 0;
+	int i, firstnumber;
+	char *pos = result;
+	char *tmpstr;
+	if (0 == strlen(str)) {
+		result = NULL;
+		return;
+	}
+	tmpstr = (char *)malloc(strlen(str) + 1);
+	if (!tmpstr) {
+		result = NULL;
+		return;
+	}
+	memset(tmpstr, 0x00, strlen(str) + 1);
+	strcpy(tmpstr, str);
+	for (i = 0; i < strlen(str); i ++) {
+		if (str[i] != '.') {
+			continue;
+		}
+		break;
+	}
+	firstnumber = i;
+	for (i = strlen(str) - 1; i >= 0; i --) {
+		if (tmpstr[i] != '.') {
+			ch_num ++;
+		} else {
+			tmpstr[i] = ch_num;
+			ch_num = 0;
+		}
+	}
+	pos = result;
+	sprintf(pos, "%.2x", firstnumber);
+	pos += 2;
+	for (i = 0; i < strlen(str); i ++) {
+		sprintf(pos, "%.2x", tmpstr[i]);
+		pos += 2;
+	}
+	//sprintf(pos, "%.2x", 0);
+	free(tmpstr);
+	tmpstr = NULL;
+}
+
+void system_cmd_ex(char * cmd)
+{
+	int rtn = -1;
+	if (NULL == cmd) {
+		slog(NET_PRINT, SLOG_ERR, "system_cmd_ex: NULL-------------------------------\n");
+		return;
+	}
+
+	rtn = soft_system(cmd);
+
+	if (0 != rtn) {
+		slog(NET_PRINT, SLOG_ERR, "cmd [%s] failed \n", cmd);
+	}
+	return;
+}
+
+int zte_router_nvconfig_read(char *i_item_name)
+{
+	if (NULL == i_item_name) {
+		slog(NET_PRINT, SLOG_ERR, "[zte_router_nvconfig_read] , point null\n");
+		return 0;
+	}
+	memset(g_router_nvconfig_buf, 0, sizeof(g_router_nvconfig_buf));
+	cfg_get_item(i_item_name, g_router_nvconfig_buf, sizeof(g_router_nvconfig_buf));
+
+	return 1;
+
+}
+
+static int isAllNumAndSlash(char *str)
+{
+	int i = 0;
+	int len = 0;
+	if (NULL == str) {
+		slog(NET_PRINT, SLOG_ERR, "isAllNumAndSlash: str in is NULL\n");
+		return 0;
+	}
+	len = (int)strlen(str);
+	for (i = 0; i < len; i++) {
+		if ((str[i] >= '0' && str[i] <= '9') || str[i] == '.' || str[i] == '/')
+			continue;
+		return 0;
+	}
+	return 1;
+}
+static int isNumOnly(char *str)
+{
+	int i = 0;
+	int len = 0;
+	if (NULL == str) {
+		slog(NET_PRINT, SLOG_ERR, "isNumOnly: str in is NULL\n");
+		return 0;
+	}
+	len = (int)strlen(str);
+	for (i = 0; i < len; i++) {
+		if ((str[i] >= '0' && str[i] <= '9'))
+			continue;
+		return 0;
+	}
+	return 1;
+}
+static int isOnlyOneSlash(char *str)
+{
+	int i = 0, count = 0;
+	int len = 0;
+	if (NULL == str) {
+		slog(NET_PRINT, SLOG_ERR, "isOnlyOneSlash: str in is NULL\n");
+		return 0;
+	}
+	len = (int)strlen(str);
+	for (i = 0; i < len; i++)
+		if (str[i] == '/')
+			count++;
+	return count <= 1 ? 1 : 0;
+}
+
+static int isIpValid(char *str)
+{
+	struct in_addr addr;    // for examination
+	//if( (! strcmp(T("any"), str)) || (! strcmp(T("any/0"), str)))
+	if ((! strcmp("any", str)) || (! strcmp("any/0", str)))
+		return 1;
+
+	if (!(inet_aton(str, &addr))) {
+		slog(NET_PRINT, SLOG_ERR, "isIpValid(): %s is not a valid IP address.\n", str);
+		return 0;
+	}
+	return 1;
+}
+static int isMacValid(char *str)
+{
+	int i = 0;
+	int len = 0;
+	if (NULL == str) {
+		slog(NET_PRINT, SLOG_ERR, "isMacValid: NULL str ");
+		return 0;
+	}
+	len = (int)strlen(str);
+	if (len != 17)
+		return 0;
+
+	for (i = 0; i < 5; i++) {
+		if ((!isxdigit(str[i * 3])) || (!isxdigit(str[i * 3 + 1])) || (str[i * 3 + 2] != ':'))
+			return 0;
+	}
+	return (isxdigit(str[15]) && isxdigit(str[16])) ? 1 : 0;
+}
+
+static int isIpNetmaskValid(char *s)
+{
+	char str[32] = {0};
+	char *slash;
+	struct in_addr addr;    // for examination
+
+	if (!s || !strlen(s)) {
+		return 0;
+	}
+
+	strncpy(str, s, sizeof(str) - 1);
+
+	if ((!strcmp("any", str)) || (!strcmp("any/0", str)))
+		return 1;
+
+	if (!isAllNumAndSlash(str)) {
+		return 0;
+	}
+
+	if (!isOnlyOneSlash(str)) {
+		return 0;
+	}
+
+	slash = strchr(str, '/');
+	if (slash) {
+		int mask;
+
+		*slash = '\0';
+		slash++;
+		if (!strlen(slash)) {
+			return 0;
+		}
+
+		if (!isNumOnly(slash)) {
+			return 0;
+		}
+
+		mask = atoi(slash);
+		if (mask < 0 || mask > 32) {
+			return 0;
+		}
+	}
+
+	if (!(inet_aton(str, &addr))) {
+		slog(NET_PRINT, SLOG_ERR, "isIpNetmaskValid(): %s is not a valid IP address.\n", str);
+		return 0;
+	}
+	return 1;
+}
+
+static void iptablesPortForwardFlush(void)
+{
+	system_cmd_ex("iptables -t nat -F "PORT_FORWARD_CHAIN);
+	return;
+}
+
+/*
+ * substitution of getNthValue which dosen't destroy the original value
+ */
+int getNthValueSafe(int index, char *value, char delimit, char *result, int len)
+{
+	int i = 0, result_len = 0;
+	char *begin = NULL;
+	char *end = NULL;
+	if (!value || !result || !len) {
+		slog(NET_PRINT, SLOG_ERR, "getNthValueSafe: null in\n");
+		return -1;
+	}
+
+	begin = value;
+	end = strchr(begin, delimit);
+
+	while (i < index && end) {
+		begin = end + 1;
+		end = strchr(begin, delimit);
+		i++;
+	}
+
+	//no delimit
+	if (!end) {
+		if (i == index) {
+			end = begin + strlen(begin);
+			result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+		} else
+			return -1;
+	} else
+		result_len = (len - 1) < (end - begin) ? (len - 1) : (end - begin);
+
+	memcpy(result, begin, result_len);
+	*(result + result_len) = '\0';
+
+	return 0;
+}
+
+void zte_router_ping_diagnostics(void)
+{
+	char cmd[256]		 	= {0};
+	char ip_address[32] 	 	= {0};
+	char diag_interface[32] 	= {0};
+	char repetition_count[20] = {0};
+	char time_out[20] 			= {0};
+	char data_size[20] 	= {0};
+	char path_tmp[50]         = {0};
+	int len = 0;
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_router_ping_diagnostics start! \n");
+
+	cfg_get_item("ping_diag_addr", ip_address, sizeof(ip_address));
+	cfg_get_item("ping_repetition_count", repetition_count, sizeof(repetition_count));
+	cfg_get_item("ping_time_out", time_out, sizeof(time_out));
+	cfg_get_item("ping_data_size", data_size, sizeof(data_size));
+	cfg_get_item("ping_diag_interface", diag_interface, sizeof(diag_interface));
+
+	if (!isIpValid(ip_address) || (0 == strlen(ip_address))) {
+		slog(NET_PRINT, SLOG_ERR, "Error: zte_router_ping_diagnostics, %s is not a valid IP address", ip_address);
+		return;
+	}
+
+	system("killall ping");
+
+	//ɾ³ý֮ǰ´æ´¢Îļþ
+	cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp));
+	sprintf(cmd, "rm %s/ping_diagnostics.txt", path_tmp);
+	slog(NET_PRINT, SLOG_NORMAL, "zte_router_ping_diagnostics rm_cmd:%s \n", cmd);
+	system_cmd_ex(cmd);
+
+	//ÖØÐÂping
+	memset(cmd, 0, 256);
+	sprintf(cmd, "ping ");
+	if (strcmp(repetition_count, "") && strcmp(repetition_count, "\0")) {
+		len = strlen(cmd);
+		sprintf(cmd + len, "-c %d ", atoi(repetition_count));
+	}
+
+	if (strcmp(data_size, "") && strcmp(data_size, "\0")) {
+		len = strlen(cmd);
+		sprintf(cmd + len, "-s %d ", atoi(data_size));
+	}
+
+	if (strcmp(time_out, "") && strcmp(time_out, "\0")) {
+		len = strlen(cmd);
+		sprintf(cmd + len, "-w %d ", atoi(time_out));
+	}
+
+	if (strcmp(diag_interface, "") && strcmp(diag_interface, "\0")) {
+		len = strlen(cmd);
+		sprintf(cmd + len, "-I %s ", diag_interface);
+	}
+
+	len = strlen(cmd);
+	slog(NET_PRINT, SLOG_DEBUG, "zte_router_ping_diagnostics cmd:%s, len:%d \n", cmd, len);
+	sprintf(cmd + len, "%s > %s/ping_diagnostics.txt & ", ip_address, path_tmp);
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_router_ping_diagnostics ping_cmd:%s \n", cmd);
+	system_cmd_ex(cmd);
+}
+
+/******************************************************
+* Function: zte_iptables_make_filter_rule()
+* Description:  make filter rules, e.g.
+*               iptables -A macipport_filter -m mac --mac-source [mac_address]
+*                                                    -s 10.128.48.88
+*                                                    -d 192.168.0.2
+*                                                     -p tcp --sport 1:80 --dport 40:500
+*                                                     -j ACCEPT
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2010/12/13      V1.0      MaXiaoliang        create
+*******************************************************/
+static void zte_iptables_make_filter_rule(char *buf, int len, char *mac_address,
+        char *sip_1, char *sip_2, int sprf_int, int sprt_int,
+        char *dip_1, char *dip_2, int dprf_int, int dprt_int, int proto, int action)
+{
+	int rc = 0;
+	char *pos = buf;
+
+	rc = snprintf(pos, len - rc,
+	              "iptables -A %s ", IPPORT_FILTER_CHAIN);
+	pos = pos + rc;
+
+	// write mac address
+	if (mac_address && strlen(mac_address)) {
+		rc = snprintf(pos, len - rc, "-m mac --mac-source %s ", mac_address);
+		pos = pos + rc;
+	}
+
+	// write source ip
+	if (sip_1 && strlen(sip_1)) {
+		rc = snprintf(pos, len - rc, "-s %s ", sip_1);
+		pos = pos + rc;
+	}
+
+	// write dest ip
+	if (dip_1 && strlen(dip_1)) {
+		rc = snprintf(pos, len - rc, "-d %s ", dip_1);
+		pos = pos + rc;
+	}
+
+	// write protocol type
+	if (proto == PROTO_NONE) {
+		rc = snprintf(pos, len - rc, " ");
+		pos = pos + rc;
+	} else if (proto == PROTO_ICMP) {
+		rc = snprintf(pos, len - rc, "-p icmp ");
+		pos = pos + rc;
+	} else {
+		if (proto == PROTO_TCP)
+			rc = snprintf(pos, len - rc, "-p tcp ");
+		else if (proto == PROTO_UDP)
+			rc = snprintf(pos, len - rc, "-p udp ");
+		pos = pos + rc;
+
+		// write source port
+		if (sprf_int) {
+			if (sprt_int)
+				rc = snprintf(pos, len - rc, "--sport %d:%d ", sprf_int, sprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--sport %d ", sprf_int);
+			pos = pos + rc;
+		}
+
+		// write dest port
+		if (dprf_int) {
+			if (dprt_int)
+				rc = snprintf(pos, len - rc, "--dport %d:%d ", dprf_int, dprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--dport %d ", dprf_int);
+			pos = pos + rc;
+		}
+	}
+
+	switch (action) {
+	case ACTION_DROP:            // 1 == ENABLE--DROP mode
+		rc = snprintf(pos, len - rc, "-j DROP");
+		break;
+	case ACTION_ACCEPT:            // 2 == ENABLE--ACCEPT mode
+		rc = snprintf(pos, len - rc, "-j ACCEPT");
+		break;
+	default:
+		slog(NET_PRINT, SLOG_ERR, "Unknown action %d.", action);
+		break;
+	}
+}
+/*===========================================================================
+    Function:
+        zte_make_filter_rules_ipv6
+
+    Description:
+        make ipportfilter rules.
+        example:
+            iptables -A macipport_filter
+                        -m mac --mac-source 00:11:22:33:44:55
+                        -m iprange --src-range 192.168.1.10-192.168.1.50
+                        -m iprange --dst-range 10.128.10.10-10.128.10.100
+                        -p tcp --sport 10:2000 --dport 4000:5000
+                        -j DROP
+
+    Param:
+        buf - cmd buffer to store rule cmd
+        len - length of cmd buffer
+        mac_address - mac address
+        sip_1 - source ip 1
+        sip_2 - source ip 2 (not support now)
+        sprf_int - source ip from port
+        sprt_int - source ip to port
+        dip_1 - dest ip 1
+        dip_2 - dest ip 2 (not support now)
+        dprf_int - dest ip from port
+        dprt_int - dest ip to port
+        proto - protocol
+        action - accept or drop
+
+    Modify Date     Version     Author                  Modification
+    2010/07/12      V1.0        zhangyuelong10100551    Create
+    2012/03/15      V1.1        liuweipeng            port
+===========================================================================*/
+void zte_make_filter_rules_v6(char *buf, int len, char *mac_address,
+                              char *sip_1, char *sip_2, int sprf_int, int sprt_int,
+                              char *dip_1, char *dip_2, int dprf_int, int dprt_int, int proto, int action)
+{
+	int rc = 0;
+	char *pos = buf;
+
+	/*begin by zhangyuelong10100551 2010.12.21*/
+	if (NULL == buf) {
+		slog(NET_PRINT, SLOG_ERR, "[ERROR]zte_make_filter_rules_ipv6: buf NULL");
+		return;
+	}
+	/*end by zhangyuelong10100551 2010.12.21*/
+
+	rc = snprintf(pos, len - rc, "ip6tables -t filter -A %s ", IPPORT_FILTER_CHAIN);
+	pos = pos + rc;
+
+	// write mac address
+	if (mac_address && strlen(mac_address)) {
+		rc = snprintf(pos, len - rc, "-m mac --mac-source %s ", mac_address);
+		pos = pos + rc;
+	}
+
+	// write source ip
+	if (sip_1 && strlen(sip_1) > 0) {
+		if (sip_2 && strlen(sip_2) > 0) {
+			rc = snprintf(pos, len - rc, "-m iprange --src-range %s-%s ", sip_1, sip_2);
+			pos = pos + rc;
+		} else {
+			rc = snprintf(pos, len - rc, "-s %s ", sip_1);
+			pos = pos + rc;
+		}
+	} else {
+		rc = snprintf(pos, len - rc, "-s any/0 ");
+		pos = pos + rc;
+	}
+
+	// write dest ip
+	if (dip_1 && strlen(dip_1) > 0) {
+		if (dip_2 && strlen(dip_2) > 0) {
+			rc = snprintf(pos, len - rc, "-m iprange --dst-range %s-%s ", dip_1, dip_2);
+			pos = pos + rc;
+		} else {
+			rc = snprintf(pos, len - rc, "-d %s ", dip_1);
+			pos = pos + rc;
+		}
+	} else {
+		rc = snprintf(pos, len - rc, "-d any/0 ");
+		pos = pos + rc;
+	}
+
+	// write protocol type
+	if (proto == PROTO_NONE) {
+		//rc = snprintf(pos, len-rc, " ");
+		//pos = pos + rc;
+	} else if (proto == PROTO_ICMP) {
+		rc = snprintf(pos, len - rc, "-p icmpv6 ");
+		pos = pos + rc;
+	} else if (proto == PROTO_TCP || proto == PROTO_UDP) {
+		if (proto == PROTO_TCP)
+			rc = snprintf(pos, len - rc, "-p tcp ");
+		else/* if (proto == PROTO_UDP)*/ //kw 3
+			rc = snprintf(pos, len - rc, "-p udp ");
+		pos = pos + rc;
+
+		// write source port
+		if (sprf_int) {
+			if (sprt_int)
+				rc = snprintf(pos, len - rc, "--sport %d:%d ", sprf_int, sprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--sport %d ", sprf_int);
+			pos = pos + rc;
+		}
+
+		// write dest port
+		if (dprf_int) {
+			if (dprt_int)
+				rc = snprintf(pos, len - rc, "--dport %d:%d ", dprf_int, dprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--dport %d ", dprf_int);
+			pos = pos + rc;
+		}
+	}
+
+	switch (action) {
+	case ACTION_DROP:       // 1 == ENABLE--DROP mode
+		rc = snprintf(pos, len - rc, "-j DROP");
+		break;
+	case ACTION_ACCEPT:     // 2 == ENABLE--ACCEPT mode
+		rc = snprintf(pos, len - rc, "-j ACCEPT");
+		break;
+	default:
+		slog(NET_PRINT, SLOG_ERR, "[ERROR]zte_make_filter_rules_v6: unknown action");
+		break;
+	}
+}  /* zte_make_filter_rules_v6() */
+
+//modified by myc for web5.0 2012-12-12 //split the function zte_iptables_filter_run
+void zte_iptables_filter_rule_run(void)
+{
+	char mac_address[32] = {0};
+	char sprf[8] = {0};   /* source port from */
+	char sprt[8] = {0};   /* source port to */
+	char dprf[8] = {0};  /* dest port from */
+	char dprt[8] = {0};  /* dest port to */
+	char sip_1[32]  = {0};  /* src ip address */
+	char sip_2[32]  = {0};
+	char dip_1[32]  = {0};  /* dest ip address */
+	char dip_2[32]  = {0};
+	char protocol[8] = {0};
+	char action_str[4] = {0};
+
+	int i = 0;
+	char rec[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+	char cmd[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+	//char rule[NV_FW_RULE_MAX_LEN] = {0};
+	char tmp[ROUTER_DEFAULT_LEN] = {0};
+	char sys_cmd_bufer[500] = {0};
+	int sprf_int = 0;
+	int sprt_int = 0;
+	int dprf_int = 0;
+	int dprt_int = 0;
+	int proto = 0;
+	int action = 0;
+
+	for (i = 0; i < RULE_MAX; i++) {
+		sprintf(tmp, "IPPortFilterRules_%d", i);
+		memset(rec, 0, sizeof(rec));
+		//zte_router_nvconfig_read(tmp);
+		//strcpy(rec,g_router_nvconfig_buf);
+		cfg_get_item(tmp, rec, sizeof(rec));
+		// get sip 1
+		if ((getNthValueSafe(0, rec, ',', sip_1, sizeof(sip_1)) == -1)) {
+			continue;
+		}
+		if (!isIpNetmaskValid(sip_1)) {
+			continue;
+		}
+
+		// get source ip port range "from"
+		if ((getNthValueSafe(2, rec, ',', sprf, sizeof(sprf)) == -1)) {
+			continue;
+		}
+		if ((sprf_int = atoi(sprf)) > 65535) {
+			continue;
+		}
+
+		// get dest ip port range "to"
+		if ((getNthValueSafe(3, rec, ',', sprt, sizeof(sprt)) == -1)) {
+			continue;
+		}
+		if ((sprt_int = atoi(sprt)) > 65535) {
+			continue;
+		}
+
+		/* Destination Part */
+		// get dip 1
+		if ((getNthValueSafe(4, rec, ',', dip_1, sizeof(dip_1)) == -1)) {
+			continue;
+		}
+		if (!isIpNetmaskValid(dip_1)) {
+			continue;
+		}
+
+		// get dest ip port range "from"
+		if ((getNthValueSafe(6, rec, ',', dprf, sizeof(dprf)) == -1)) {
+			continue;
+		}
+		if ((dprf_int = atoi(dprf)) > 65535) {
+			continue;
+		}
+
+		// get dest ip port range "to"
+		if ((getNthValueSafe(7, rec, ',', dprt, sizeof(dprt)) == -1)) {
+			continue;
+		}
+		if ((dprt_int = atoi(dprt)) > 65535) {
+			continue;
+		}
+
+		// get protocol
+		if ((getNthValueSafe(8, rec, ',', protocol, sizeof(protocol)) == -1)) {
+			continue;
+		}
+		proto = atoi(protocol);
+
+		// get action
+		if ((getNthValueSafe(9, rec, ',', action_str, sizeof(action_str)) == -1)) {
+			continue;
+		}
+		action = atoi(action_str);
+
+		// getNthValueSafe(10) is "comment".
+
+		// get mac address
+		if ((getNthValueSafe(11, rec, ',', mac_address, sizeof(mac_address)) == -1)) {
+			continue;
+		}
+		if (strlen(mac_address) && !isMacValid(mac_address)) {
+			continue;
+		}
+		if (PROTO_TCP_UDP == proto) {
+			zte_iptables_make_filter_rule(cmd, sizeof(cmd), mac_address, sip_1, sip_2, sprf_int, sprt_int, dip_1, dip_2, dprf_int, dprt_int, PROTO_TCP, action);
+			memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+			sprintf(sys_cmd_bufer, "%s %s", cmd, FMT_ECHO_IPTABLES_CMD);
+			system_cmd_ex(sys_cmd_bufer);
+			zte_iptables_make_filter_rule(cmd, sizeof(cmd), mac_address, sip_1, sip_2, sprf_int, sprt_int, dip_1, dip_2, dprf_int, dprt_int, PROTO_UDP, action);
+			memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+			sprintf(sys_cmd_bufer, "%s %s", cmd, FMT_ECHO_IPTABLES_CMD);
+			system_cmd_ex(sys_cmd_bufer);
+		} else {
+			zte_iptables_make_filter_rule(cmd, sizeof(cmd), mac_address, sip_1, sip_2, sprf_int, sprt_int, dip_1, dip_2, dprf_int, dprt_int, proto, action);
+			memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+			sprintf(sys_cmd_bufer, "%s %s", cmd, FMT_ECHO_IPTABLES_CMD);
+			system_cmd_ex(sys_cmd_bufer);
+		}
+	}
+}
+
+/******************************************************
+* Function: zte_iptables_filter_run()
+* Description:  load rules from "IPPortFilterRules", make rules, and run
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2010/12/13      V1.0      MaXiaoliang        create
+*******************************************************/
+void zte_iptables_filter_run(void)
+{
+
+	char firewall_enable[ROUTER_DEFAULT_LEN] = {0};
+	char default_policy[ROUTER_DEFAULT_LEN] = {0};
+	char sys_cmd_bufer[500] = {0};
+	int filter_enable = 0;
+
+	/*flush filter chain*/
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", IPPORT_FILTER_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+
+	//zte_router_nvconfig_read("IPPortFilterEnable");
+	//strcpy(firewall_enable , g_router_nvconfig_buf);
+	cfg_get_item("IPPortFilterEnable", firewall_enable, sizeof(firewall_enable));
+
+	if (0 == strlen(firewall_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "IPPortFilter have been disable one .\n");
+		system_cmd_ex("iptables -t filter -P FORWARD ACCEPT");
+		return;
+	}
+	filter_enable = atoi(firewall_enable);
+	/* if firewall is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == filter_enable) {
+		system_cmd_ex("iptables -t filter -P FORWARD ACCEPT");
+		slog(NET_PRINT, SLOG_ERR, "IPPortFilter have been disable two .\n");
+		return;
+	}
+
+	/* 0: accept   1: drop */
+	//zte_router_nvconfig_read("DefaultFirewallPolicy");
+	//strcpy(default_policy , g_router_nvconfig_buf);
+	cfg_get_item("DefaultFirewallPolicy", default_policy, sizeof(default_policy));
+
+	if (0 == strlen(default_policy)) {
+		strcpy(default_policy, "0");
+	}
+
+	zte_iptables_filter_rule_run();
+
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A %s -m state --state RELATED,ESTABLISHED -j ACCEPT", IPPORT_FILTER_CHAIN);
+	system_cmd_ex(sys_cmd_bufer);
+
+
+	switch (atoi(default_policy)) {
+	case 0:
+		system_cmd_ex("iptables -t filter -P FORWARD ACCEPT");
+		break;
+	case 1:
+		system_cmd_ex("iptables -t filter -P FORWARD DROP");
+		break;
+	default:
+		slog(NET_PRINT, SLOG_ERR, "Unknown default_policy %d.", atoi(default_policy));
+		break;
+	}
+
+}
+
+/******************************************************
+* Function: zte_iptables_sys_fw_run()
+* Description:  make system security rules, then run, e.g.
+*                   iptables -A INPUT -i ppp0 -p icmp --icmp-type echo-reply -j ACCEPT
+*                   iptables -t filter -A INPUT -i ppp0  -j DROP             // disable remote control
+*                   iptables -t filter -A INPUT -i ppp0 -p icmp -j DROP  // disable ping
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2010/12/13      V1.0      MaXiaoliang        create
+*******************************************************/
+void zte_iptables_sys_fw_run(void)
+{
+	char rmE[ROUTER_NV_FW_RULE_MAX_LEN]  = {0};
+	char wpfE[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+	char sys_cmd_bufer[500] = {0};
+	//zte_router_nvconfig_read("RemoteManagement");
+	///strcpy(rmE , g_router_nvconfig_buf);
+	cfg_get_item("RemoteManagement", rmE, sizeof(rmE));
+
+	//zte_router_nvconfig_read("WANPingFilter");
+	//strcpy(wpfE ,g_router_nvconfig_buf);
+	cfg_get_item("WANPingFilter", wpfE, sizeof(wpfE));
+
+
+	/* flush INPUT chain is OK;  the macipport_filter chain is in FORWARD chain. */
+	system_cmd_ex("iptables -t filter -F INPUT");
+	/*added by myc for shutdown 1900 and 53 port to wan 2013-05-22 begin*/
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p tcp --dport 1900 -j DROP ", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	/*added by myc for shutdown 1900 and 53 port to wam 2013-05-22 end*/
+	/* allow request to dnsmasq from the lan */
+	//system_cmd_ex("iptables -t filter -I INPUT -p udp --sport 53  -j ACCEPT");
+	//system_cmd_ex("iptables -t filter -I INPUT -p udp --dport 53  -j ACCEPT");
+	//system_cmd_ex("iptables -t filter -I INPUT -p tcp --sport 53  -j ACCEPT");
+	//system_cmd_ex("iptables -t filter -I INPUT -p tcp --dport 53  -j ACCEPT");
+
+	/* modify by dlf begin, --2016-09-7 */
+	//ÍøÂ簲ȫÉèÖÃfor lan ssh
+#if 0 //for aq
+	system_cmd_ex("iptables -A INPUT -p tcp --dport 22 -j DROP");
+	system_cmd_ex("iptables -A INPUT -p udp --dport 22 -j DROP");
+	system_cmd_ex("iptables -A INPUT -p tcp --dport 5555 -j DROP");
+	system_cmd_ex("iptables -A INPUT -p udp --dport 5555 -j DROP");
+#endif
+	//ÍøÂ簲ȫÉèÖÃfor wan
+	//disable 22£ºsh
+	/*
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p udp --dport 22 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p tcp --dport 22 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	*/
+	//disable 23£ºtelnet
+	/*
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p udp --dport 23 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p tcp --dport 23 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	*/
+	//disable 53£ºdomin
+	
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p udp --dport 53 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p tcp --dport 53 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"ip6tables -t filter -A INPUT -i %s -p udp --dport 53 -j DROP", defwan6_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"ip6tables -t filter -A INPUT -i %s -p tcp --dport 53 -j DROP", defwan6_rel);
+	system_cmd_ex(sys_cmd_bufer);
+
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p udp --dport 67 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"ip6tables -t filter -A INPUT -i %s -p udp --dport 67 -j DROP", defwan6_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	
+	//disable 1900£ºupnp
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p udp --dport 1900 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p tcp --dport 1900 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p udp --dport 1900 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p tcp --dport 1900 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	//disable 5555£ºfreeciv
+	/*
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p udp --dport 5555 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer,"iptables -t filter -A INPUT -i %s -p tcp --dport 5555 -j DROP", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+	*/
+	/* modify by dlf end, --2016-09-7 */
+
+	/* modify by maxl begin, --2011-01-28 */
+	/*added by myc for shutdown 1900 and 53 port to wan 2013-05-22 begin*/
+	//memset(sys_cmd_bufer,0,sizeof(sys_cmd_bufer));
+	//sprintf(sys_cmd_bufer,"iptables -t filter -I INPUT -i %s -p tcp --dport 53 -j DROP ", defwan_rel);
+	// system_cmd_ex(sys_cmd_bufer);
+	/*added by myc for shutdown 1900 and 53 port to wam 2013-05-22 end*/
+	/*open telnet 4719 port*/
+#if 0 //for aq
+	system_cmd_ex("iptables -t filter -I INPUT -p tcp --dport 4719 -j ACCEPT");
+	system_cmd_ex("iptables -t filter -I INPUT -p udp --dport 4719 -j ACCEPT");
+#endif	
+	/* modify by maxl end, --2011-01-28 */
+
+	/* allow ping from WAN interface */
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "iptables -A INPUT -i %s -p icmp --icmp-type echo-reply -j ACCEPT", defwan_rel);
+	system_cmd_ex(sys_cmd_bufer);
+
+	system_cmd_ex("ip6tables -t filter -F INPUT");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p udp --sport 53 -j ACCEPT");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p udp --dport 53 -j ACCEPT");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p tcp --sport 53 -j ACCEPT");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p tcp --dport 53 -j ACCEPT");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p tcp --dport 23 -j DROP");
+	system_cmd_ex("ip6tables -t filter -I INPUT -p udp --dport 23 -j DROP");
+	// allow ping from WAN interface
+	memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+	sprintf(sys_cmd_bufer, "ip6tables -A INPUT -i %s -p icmpv6 --icmpv6-type echo-reply -j ACCEPT", defwan6_rel);
+	system_cmd_ex(sys_cmd_bufer);
+
+	/* remote management is enable */
+	if (atoi(rmE) == 1) {
+		/*
+		 * The INPUT chain will be flushed every time, and the default policy of INPUT is ACCEPT,
+		 * so it needn't to add the rules for RemoteManagement.
+		 */
+	} else { /* disable */
+		//system_cmd_ex("iptables -t filter -A INPUT -i %s  -j DROP", defwan_rel);
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p tcp --dport 80  -j DROP", defwan_rel);
+		system_cmd_ex(sys_cmd_bufer);
+
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p tcp --dport 80 -j DROP", defwan6_rel);
+		system_cmd_ex(sys_cmd_bufer);
+
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p tcp --dport 443  -j DROP", defwan_rel);
+		system_cmd_ex(sys_cmd_bufer);
+
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p tcp --dport 443 -j DROP", defwan6_rel);
+		system_cmd_ex(sys_cmd_bufer);
+	}
+
+	/* allow ping */
+	if (atoi(wpfE) == 1) { /* enable */
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -t filter -I INPUT -i %s -p icmp -j ACCEPT", defwan_rel);
+		system_cmd_ex(sys_cmd_bufer);
+
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "ip6tables -t filter -I INPUT -i %s -p icmpv6 -j ACCEPT", defwan6_rel);
+		system_cmd_ex(sys_cmd_bufer);
+	} else {                     /* disable */
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		sprintf(sys_cmd_bufer, "iptables -t filter -A INPUT -i %s -p icmp -j DROP", defwan_rel);
+		system_cmd_ex(sys_cmd_bufer);
+
+		memset(sys_cmd_bufer, 0, sizeof(sys_cmd_bufer));
+		//sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p icmpv6 -j DROP", defwan_rel);
+		sprintf(sys_cmd_bufer, "ip6tables -t filter -A INPUT -i %s -p icmpv6 --icmpv6-type echo-request -j DROP", defwan6_rel);
+		system_cmd_ex(sys_cmd_bufer);
+	}
+
+	// vpn pass through
+	//system_cmd_ex("vpn_pass.sh");
+
+}
+
+
+static void zte_iptables_make_DMZ_Rule(char *buf, int len, char *wan_name, char *ip_address)
+{
+	/* iptables -t nat -A PREROUTING -i br0 -j DNAT --to 5.6.7.8 */
+	//rc = snprintf(buf, len-rc , "iptables -t nat -A %s -j DNAT -i %s -p udp --dport ! %d --to %s", DMZ_CHAIN, wan_name, getGoAHeadServerPort(), ip_address);
+	snprintf(buf, len, "iptables -t nat -A %s -j DNAT -i %s  --to %s", DMZ_CHAIN, wan_name,  ip_address);
+}
+void zte_iptables_DMZ_Run(void)
+{
+	char cmd[1024] = {0}, ip_address[128] = {0};
+	char dmz_enable[128] = {0};
+
+	/*flush DMZ chain*/
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "iptables -t nat -F %s %s", DMZ_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(cmd);
+
+	memset(cmd, 0, sizeof(cmd));
+
+	//zte_router_nvconfig_read("DMZEnable");
+	//strcpy(dmz_enable , g_router_nvconfig_buf);
+	cfg_get_item("DMZEnable", dmz_enable, sizeof(dmz_enable));
+
+	if (0 == strcmp(dmz_enable, "")) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: DMZ have been disable one\n");
+		return;
+	}
+	if (!atoi(dmz_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: DMZ have been disable two\n");
+		return;
+	}
+
+	//zte_router_nvconfig_read("DMZIPAddress");
+	// strcpy(ip_address , g_router_nvconfig_buf);
+	cfg_get_item("DMZIPAddress", ip_address, sizeof(ip_address));
+
+
+	if (0 == strcmp(ip_address, "")) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: can't find \"DMZIPAddress\" in flash\n");
+		return;
+	}
+	//system_cmd_ex("iptables -t nat -I PREROUTING -i %s  -m state --state RELATED,ESTABLISHED,NEW -j ACCEPT",getWanIfNamePPP);
+
+	sprintf(cmd, "iptables -t nat -A %s -j ACCEPT -i %s -p udp --dport 67:68", DMZ_CHAIN, defwan_rel);
+	//ZTE_SYSLOG(6,"zte_mainctrl DMZ:%s",cmd);
+	system_cmd_ex(cmd);
+
+	memset(cmd, 0, sizeof(cmd));
+
+	zte_iptables_make_DMZ_Rule(cmd, sizeof(cmd), defwan_rel, ip_address);
+
+	system_cmd_ex(cmd);
+	return;
+}
+
+
+
+
+//12133
+/******************************************************
+* Function: zte_iptables_make_port_forward_rule()
+* Description:  make port forward rules, then run, e.g.
+*                   iptables -t nat -A port_forward -j DNAT -i ppp0 -p tcp --dport 10:400 --to 192.168.0.100
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2010/12/13      V1.0      MaXiaoliang        create
+*******************************************************/
+static void zte_iptables_make_port_forward_rule(char *buf, int len, char *wan_name,
+        char *ip_address, int proto, int prf_int, int prt_int)
+{
+	int rc = 0;
+	char *pos = buf;
+
+	rc = snprintf(pos, len - rc, "iptables -t nat -A %s -j DNAT -i %s ", PORT_FORWARD_CHAIN, wan_name);
+	pos = pos + rc;
+
+	/* protocol type */
+	if (proto == PROTO_TCP)
+		rc = snprintf(pos, len - rc, "-p tcp ");
+	else if (proto == PROTO_UDP)
+		rc = snprintf(pos, len - rc, "-p udp ");
+	else if (proto == PROTO_TCP_UDP)
+		rc = snprintf(pos, len - rc, " ");
+	pos = pos + rc;
+
+	/* port */
+	if (prt_int != 0)
+		rc = snprintf(pos, len - rc, "--dport %d:%d ", prf_int, prt_int);
+	else
+		rc = snprintf(pos, len - rc, "--dport %d ", prf_int);
+	pos = pos + rc;
+
+	/* dest ip, forward to who */
+	rc = snprintf(pos, len - rc, "--to %s ", ip_address);
+}
+
+//12134
+
+/******************************************************
+* Function: zte_iptables_port_forward_run()
+* Description:  make port forward rules, then run
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2010/12/13      V1.0      MaXiaoliang        create
+*******************************************************/
+void zte_iptables_port_forward_run(void)
+{
+	char forward_enable[10] = {0};
+	//char rule[NV_FW_RULE_MAX_LEN] = {0};
+
+	int i = 0;
+	char rec[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+	char cmd[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+
+	int prf_int;
+	int prt_int;
+	int proto;
+	char ip_address[32] = {0};
+	char prf[8] = {0};
+	char prt[8] = {0};
+	char protocol[8] = {0};
+	char tmp[ROUTER_DEFAULT_LEN] = {0};
+	/* if port forward is disabled or PortForwardRules is NULL, then return */
+	//zte_router_nvconfig_read("PortForwardEnable");
+	//strcpy(forward_enable , g_router_nvconfig_buf);
+	cfg_get_item("PortForwardEnable", forward_enable, sizeof(forward_enable));
+
+	if (0 == strlen(forward_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: PortForward have been disable one \n");
+		return;
+	}
+	//iptablesPortForwardFlush();
+	system_cmd_ex("iptables -t nat -F "PORT_FORWARD_CHAIN);
+
+	/* 0: disable  1: enable */
+	if (0 == atoi(forward_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Warning: PortForward have been disable two \n");
+		return;
+	}
+
+	sprintf(cmd, "iptables -t nat -A %s -j ACCEPT -i %s -p udp --dport 67:68", PORT_FORWARD_CHAIN, defwan_rel);
+	//ZTE_SYSLOG(6,"zte_mainctrl port_forward:%s",cmd);
+	system_cmd_ex(cmd);
+	memset(cmd, 0, sizeof(cmd));
+
+	for (i = 0; i < RULE_MAX; i++) {
+		sprintf(tmp, "PortForwardRules_%d", i);
+		memset(rec, 0, sizeof(rec));
+		//zte_router_nvconfig_read(tmp);
+		//strcpy(rec , g_router_nvconfig_buf);
+		cfg_get_item(tmp, rec, sizeof(rec));
+
+		// get ip address
+		if ((getNthValueSafe(0, rec, ',', ip_address, sizeof(ip_address)) == -1)) {
+			continue;
+		}
+		if (!isIpValid(ip_address)) {
+			continue;
+		}
+
+		// get port range "from"
+		if ((getNthValueSafe(1, rec, ',', prf, sizeof(prf)) == -1)) {
+			continue;
+		}
+		if ((prf_int = atoi(prf)) == 0 || prf_int > 65535) {
+			continue;
+		}
+
+		// get port range "to"
+		if ((getNthValueSafe(2, rec, ',', prt, sizeof(prt)) == -1)) {
+			continue;
+		}
+		if ((prt_int = atoi(prt)) > 65535) {
+			continue;
+		}
+
+		// get protocol
+		if ((getNthValueSafe(3, rec, ',', protocol, sizeof(protocol)) == -1)) {
+			continue;
+		}
+		proto = atoi(protocol);
+
+		switch (proto) {
+		case PROTO_TCP:
+		case PROTO_UDP:
+			zte_iptables_make_port_forward_rule(cmd, sizeof(cmd), defwan_rel, ip_address, proto, prf_int, prt_int);
+			system_cmd_ex(cmd);
+			break;
+		case PROTO_TCP_UDP:
+			zte_iptables_make_port_forward_rule(cmd, sizeof(cmd), defwan_rel, ip_address, PROTO_TCP, prf_int, prt_int);
+			system_cmd_ex(cmd);
+			zte_iptables_make_port_forward_rule(cmd, sizeof(cmd), defwan_rel, ip_address, PROTO_UDP, prf_int, prt_int);
+			system_cmd_ex(cmd);
+			break;
+
+		default:
+			continue;
+		}
+	}
+
+}
+
+/******************************************************
+* Function: zte_iptables_make_portmap_rule()
+* Description:  make filter rules, e.g.
+*                   iptables -t nat -A PREROUTING -p udp --port 77 -j DNAT --to 192.168.8.100:88
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2015/08/03     V1.0      gebin          create
+*******************************************************/
+static void zte_iptables_make_portmap_rule(char *buf, int len, char *wan_name, char *ip, int spr_int, int dpr_int, int proto)
+{
+	int rc = 0;
+	char *pos = buf;
+
+	rc = snprintf(pos, len - rc, "iptables -t nat -A %s -j DNAT -i %s ", PORT_MAPPING_CHAIN, wan_name);
+	//rc = snprintf(pos, len - rc, "iptables -t nat -A PREROUTING ");
+	pos = pos + rc;
+
+	// write protocol type
+	if (proto == PROTO_TCP)
+		rc = snprintf(pos, len - rc, "-p tcp ");
+	else if (proto == PROTO_UDP)
+		rc = snprintf(pos, len - rc, "-p udp ");
+	else if (proto == PROTO_TCP_UDP)
+		rc = snprintf(pos, len - rc, " ");
+	pos = pos + rc;
+
+	// write source port
+	if (spr_int) {
+		rc = snprintf(pos, len - rc, "--dport %d ", spr_int);
+		pos = pos + rc;
+	}
+
+	// write ip
+	if (ip && strlen(ip)) {
+		rc = snprintf(pos, len - rc, "--to %s", ip);
+		pos = pos + rc;
+	}
+
+	// write dest port
+	if (dpr_int) {
+		rc = snprintf(pos, len - rc, ":%d", dpr_int);
+		pos = pos + rc;
+	}
+}
+
+/******************************************************
+* Function: zte_iptables_port_map_run()
+* Description:  load rules from "PortMapRules", make rules, and run
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2015/08/03     V1.0      gebin          create
+*******************************************************/
+static void zte_iptables_port_map_run(char *portMapRule)
+{
+	//char portmap_enable[CONFIG_DEFAULT_LENGTH] = {0};
+	char ip[32]  = {0};    /* ip address */
+	char spr[8]  = {0};    /* source port from */
+	char dpr[8]  = {0};    /* dest port from */
+	char protocol[8] = {0};
+
+	int spr_int = 0;
+	int dpr_int = 0;
+	int proto = 0;
+	char cmd[300] = {0};
+
+	// get ip address
+	if ((getNthValueSafe(0, portMapRule, ',', ip, sizeof(ip)) == -1)) {
+		return;
+	}
+	if (!isIpNetmaskValid(ip)) {
+		return;
+	}
+
+	// get source ip port
+	if ((getNthValueSafe(1, portMapRule, ',', spr, sizeof(spr)) == -1)) {
+		return;
+	}
+	if ((spr_int = atoi(spr)) > 65535) {
+		return;
+	}
+
+	// get dest ip port
+	if ((getNthValueSafe(2, portMapRule, ',', dpr, sizeof(dpr)) == -1)) {
+		return;
+	}
+	if ((dpr_int = atoi(dpr)) > 65535) {
+		return;
+	}
+
+	// get protocol
+	if ((getNthValueSafe(3, portMapRule, ',', protocol, sizeof(protocol)) == -1)) {
+		return;
+	}
+	proto = atoi(protocol);
+
+	/*
+	# iptables example
+	# iptables -t nat -A PREROUTING -p udp --port 77 -j DNAT --to 192.168.8.100/88
+	*/
+	if (PROTO_TCP_UDP == proto) {
+		zte_iptables_make_portmap_rule(cmd, sizeof(cmd), defwan_rel, ip, spr_int, dpr_int, PROTO_TCP);
+		system_cmd_ex(cmd);
+		zte_iptables_make_portmap_rule(cmd, sizeof(cmd), defwan_rel, ip, spr_int, dpr_int, PROTO_UDP);
+		system_cmd_ex(cmd);
+	} else {
+		zte_iptables_make_portmap_rule(cmd, sizeof(cmd), defwan_rel, ip, spr_int, dpr_int, proto);
+		system_cmd_ex(cmd);
+	}
+}
+
+/******************************************************
+* Function: zte_iptables_port_map_all_run()
+* Description:  load rules from "PortMapRules", make rules, and run
+* Input:
+* Output:
+* Return:
+* Others:
+* Modify Date    Version   Author         Modification
+* 2015/08/03     V1.0      gebin          create
+*******************************************************/
+void zte_iptables_port_map_all_run(void)
+{
+	int i = 0;
+	char PortMapRules[300] = {0};
+	char PortMapRules_x[50] = {0};
+	char portmap_enable[64] = {0}; /* 0: Disabled  1: Enabled */
+	int portmap_int = 0;
+	char cmd[ROUTER_NV_FW_RULE_MAX_LEN] = {0};
+
+	//read port_map setting
+	cfg_get_item("PortMapEnable", portmap_enable, sizeof(portmap_enable));
+	slog(NET_PRINT, SLOG_NORMAL, "portmap_enable: %s \n", portmap_enable);
+	if (0 == strlen(portmap_enable)) {
+		slog(NET_PRINT, SLOG_ERR, "Error: can't find \"PortMapRules\" in flash.\n"); /*lint !e26*/
+		return;
+	}
+
+	system_cmd_ex("iptables -t nat -F "PORT_MAPPING_CHAIN);
+
+	portmap_int = atoi(portmap_enable);
+	/* if firewall is disable, then return directly: 0 mean disable, 1 means enable */
+	if (0 == portmap_int) {
+		return;
+	}
+
+	sprintf(cmd, "iptables -t nat -A %s -j ACCEPT -i %s -p udp --dport 67:68", PORT_MAPPING_CHAIN, defwan_rel);
+	system_cmd_ex(cmd);
+	memset(cmd, 0, sizeof(cmd));
+
+	for (i = 0; i <= 9; i++) {
+		(void)snprintf(PortMapRules_x, 50, "PortMapRules_%d", i);
+		memset(PortMapRules, 0, sizeof(PortMapRules));
+		cfg_get_item(PortMapRules_x, PortMapRules, sizeof(PortMapRules));
+		if (0 == strcmp(PortMapRules, "")) {
+			continue;
+		}
+		zte_iptables_port_map_run(PortMapRules);
+		slog(NET_PRINT, SLOG_NORMAL, "zte_iptables_port_map_all_run %s: %s", PortMapRules_x, PortMapRules);
+	}
+}
+
+/*===========================================================================
+    Function:
+        zte_iptables_make_filter_rule_v6
+
+    Description:
+        make ipportfilter rules.
+        example:
+            iptables -A macipport_filter
+                        -m mac --mac-source 00:11:22:33:44:55
+                        -m iprange --src-range 192.168.1.10-192.168.1.50
+                        -m iprange --dst-range 10.128.10.10-10.128.10.100
+                        -p tcp --sport 10:2000 --dport 4000:5000
+                        -j DROP
+
+    Param:
+        buf - cmd buffer to store rule cmd
+        len - length of cmd buffer
+        mac_address - mac address
+        sip_1 - source ip 1
+        sip_2 - source ip 2 (not support now)
+        sprf_int - source ip from port
+        sprt_int - source ip to port
+        dip_1 - dest ip 1
+        dip_2 - dest ip 2 (not support now)
+        dprf_int - dest ip from port
+        dprt_int - dest ip to port
+        proto - protocol
+        action - accept or drop
+
+    Modify Date     Version     Author                  Modification
+    2010/07/12      V1.0        zhangyuelong10100551    Create
+===========================================================================*/
+static void zte_iptables_make_filter_rule_v6(char *buf, int len, char *mac_address,
+        char *sip_1, char *sip_2, int sprf_int, int sprt_int,
+        char *dip_1, char *dip_2, int dprf_int, int dprt_int, int proto, int action)
+{
+	int rc = 0;
+	char *pos = buf;
+
+	if (NULL == buf) {
+		slog(NET_PRINT, SLOG_ERR, "[zte_iptables_make_filter_rule_v6]: buf NULL");
+		return;
+	}
+
+	rc = snprintf(pos, len - rc, "ip6tables -A %s ", IPPORT_FILTER_CHAIN);
+	pos = pos + rc;
+
+	// write mac address
+	if (mac_address && strlen(mac_address)) {
+		rc = snprintf(pos, len - rc, "-m mac --mac-source %s ", mac_address);
+		pos = pos + rc;
+	}
+
+	// write source ip
+	if (sip_1 && strlen(sip_1)) {
+		if (0 != strcmp("any/0", sip_1)) {
+			rc = snprintf(pos, len - rc, "-s %s ", sip_1);
+			pos = pos + rc;
+		}
+	}
+
+	// write dest ip
+	if (dip_1 && strlen(dip_1)) {
+		if (0 != strcmp("any/0", dip_1)) {
+			rc = snprintf(pos, len - rc, "-d %s ", dip_1);
+			pos = pos + rc;
+		}
+	}
+
+	// write protocol type
+	if (proto == PROTO_NONE) {
+		//rc = snprintf(pos, len-rc, " ");
+		//pos = pos + rc;
+	} else if (proto == PROTO_ICMP) {
+		rc = snprintf(pos, len - rc, "-p icmpv6 ");
+		pos = pos + rc;
+	} else if (proto == PROTO_TCP || proto == PROTO_UDP) {
+		if (proto == PROTO_TCP)
+			rc = snprintf(pos, len - rc, "-p tcp ");
+		else/* if (proto == PROTO_UDP)*/ //kw 3
+			rc = snprintf(pos, len - rc, "-p udp ");
+		pos = pos + rc;
+
+		// write source port
+		if (sprf_int) {
+			if (sprt_int)
+				rc = snprintf(pos, len - rc, "--sport %d:%d ", sprf_int, sprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--sport %d ", sprf_int);
+			pos = pos + rc;
+		}
+
+		// write dest port
+		if (dprf_int) {
+			if (dprt_int)
+				rc = snprintf(pos, len - rc, "--dport %d:%d ", dprf_int, dprt_int);
+			else
+				rc = snprintf(pos, len - rc, "--dport %d ", dprf_int);
+			pos = pos + rc;
+		}
+	}
+
+	switch (action) {
+	case ACTION_DROP:       // 1 == ENABLE--DROP mode
+		rc = snprintf(pos, len - rc, "-j DROP");
+		break;
+	case ACTION_ACCEPT:     // 2 == ENABLE--ACCEPT mode
+		rc = snprintf(pos, len - rc, "-j ACCEPT");
+		break;
+	default:
+		slog(NET_PRINT, SLOG_ERR, "[zte_iptables_make_filter_rule_v6]: unknown action", "");
+		break;
+	}
+}  /* zte_iptables_make_filter_rule_v6() */
+void zte_iptables_filter_run_v6(void)
+{
+	char filter_flag[ROUTER_DEFAULT_LEN] = {0}, filter_default_policy[ROUTER_DEFAULT_LEN] = {0}, cmd[500] = {0}, each_rule[ROUTER_NV_FW_RULE_MAX_LEN] = {0}, tmp[ROUTER_DEFAULT_LEN] = {0}, dip_2[ZTE_FW_IP_ADDR_LEN_V6] = {0}, protocol[ZTE_ROUTER_FW_FLAG_LEN] = {0}, mac_address[ROUTER_DEFAULT_LEN] = {0},
+	                                       sip_1[ZTE_FW_IP_ADDR_LEN_V6] = {0}, sip_2[ZTE_FW_IP_ADDR_LEN_V6] = {0}, sprf[ZTE_ROUTER_FW_PORT_LEN] = {0}, sprt[ZTE_ROUTER_FW_PORT_LEN] = {0}, dip_1[ZTE_FW_IP_ADDR_LEN_V6] = {0}, dprf[ZTE_ROUTER_FW_PORT_LEN] = {0}, dprt[ZTE_ROUTER_FW_PORT_LEN] = {0}, action[ZTE_ROUTER_FW_FLAG_LEN] = {0};
+	int i = 0;
+
+	/* flush all filter rules */
+	system_cmd_ex("ip6tables -F "IPPORT_FILTER_CHAIN);
+	/* default policy */
+	system_cmd_ex("ip6tables -t filter -P FORWARD ACCEPT");
+	system_cmd_ex("ip6tables -t filter -A "IPPORT_FILTER_CHAIN" -m state --state RELATED,ESTABLISHED -j ACCEPT");
+
+	/* check whether run filter */
+	//zte_router_nvconfig_read("IPPortFilterEnable");
+	//strcpy(filter_flag, g_router_nvconfig_buf);
+	cfg_get_item("IPPortFilterEnable", filter_flag, sizeof(filter_flag));
+
+	if (strlen(filter_flag) == 0 || atoi(filter_flag) == 0) {
+		return;
+	}
+
+	/* set default policy of filter */
+	//zte_router_nvconfig_read("DefaultFirewallPolicy");
+	//strcpy(filter_default_policy, g_router_nvconfig_buf);
+	cfg_get_item("DefaultFirewallPolicy", filter_default_policy, sizeof(filter_default_policy));
+
+	if (strcmp("1", filter_default_policy) == 0) {
+		system_cmd_ex("ip6tables -t filter -P FORWARD DROP");
+	} else {
+		system_cmd_ex("ip6tables -t filter -P FORWARD ACCEPT");
+	}
+
+	for (i = 0; i < RULE_MAX; i++) {
+		sprintf(tmp, "IPPortFilterRulesv6_%d", i);
+		memset(each_rule, 0, sizeof(each_rule));
+		//zte_router_nvconfig_read(tmp);
+		//strcpy(each_rule, g_router_nvconfig_buf);
+		cfg_get_item(tmp, each_rule, sizeof(each_rule));
+
+		/* source ip range "from" */
+		if (getNthValueSafe(0, each_rule, ',', sip_1, sizeof(sip_1)) == -1) {
+			continue;
+		}
+		/* source ip range "to" */
+		if (getNthValueSafe(1, each_rule, ',', sip_2, sizeof(sip_2)) == -1) {
+			continue;
+		}
+		/* source port range "from" */
+		if ((getNthValueSafe(2, each_rule, ',', sprf, sizeof(sprf)) == -1) || atoi(sprf) > 65535) {
+			continue;
+		}
+		/* source port range "to" */
+		if ((getNthValueSafe(3, each_rule, ',', sprt, sizeof(sprt)) == -1) || atoi(sprt) > 65535) {
+			continue;
+		}
+		/* dst ip range "from" */
+		if (getNthValueSafe(4, each_rule, ',', dip_1, sizeof(dip_1)) == -1) {
+			continue;
+		}
+		/* dst ip range "to" */
+		if (getNthValueSafe(5, each_rule, ',', dip_2, sizeof(dip_2)) == -1) {
+			continue;
+		}
+		/* dst port range "from" */
+		if ((getNthValueSafe(6, each_rule, ',', dprf, sizeof(dprf)) == -1) || atoi(dprf) > 65535) {
+			continue;
+		}
+		/* dst port range "to" */
+		if ((getNthValueSafe(7, each_rule, ',', dprt, sizeof(dprt)) == -1) || atoi(dprt) > 65535) {
+			continue;
+		}
+		/* protocol */
+		if (getNthValueSafe(8, each_rule, ',', protocol, sizeof(protocol)) == -1) {
+			continue;
+		}
+		/* action */
+		if (getNthValueSafe(9, each_rule, ',', action, sizeof(action)) == -1) {
+			continue;
+		}
+		/* comment */
+		/* mac_address */
+		//kw 3
+		if (getNthValueSafe(11, each_rule, ',', mac_address, sizeof(mac_address)) == -1) {
+			continue;
+		}
+		if (strlen(mac_address) && !isMacValid(mac_address)) {
+			continue;
+		}
+		
+
+		/* run rules */
+		if (PROTO_TCP_UDP == atoi(protocol)) {
+			zte_iptables_make_filter_rule_v6(cmd, sizeof(cmd), mac_address,
+			                                 sip_1, sip_2, atoi(sprf), atoi(sprt), dip_1, dip_2, atoi(dprf), atoi(dprt), PROTO_TCP, atoi(action));
+			system_cmd_ex(cmd);
+
+			zte_iptables_make_filter_rule_v6(cmd, sizeof(cmd), NULL,
+			                                 sip_1, sip_2, atoi(sprf), atoi(sprt), dip_1, dip_2, atoi(dprf), atoi(dprt), PROTO_UDP, atoi(action));
+			system_cmd_ex(cmd);
+		} else {
+			zte_iptables_make_filter_rule_v6(cmd, sizeof(cmd), mac_address,
+			                                 sip_1, sip_2, atoi(sprf), atoi(sprt), dip_1, dip_2, atoi(dprf), atoi(dprt), atoi(protocol), atoi(action));
+			system_cmd_ex(cmd);
+		}
+	}
+}
+void zte_iptables_Webs_Filter_Run(void)
+{
+	int i = 0;
+	char url_filter[ZTE_ROUTER_URL_FILTER_LEN] = {0};
+	char entry[ROUTER_NV_ITEM_VALUE_MAX_LEN] = {0};
+	char cmd[ROUTER_NV_ITEM_VALUE_MAX_LEN] = {0};
+	char url_hexstring[ZTE_ROUTER_URL_FILTER_LEN] = {0};
+
+	/*
+	 *×¢Ê͵ôÔ­À´µÄ×Ö·û´®Æ¥Å䣬¸ÄΪģºýÆ¥Åä.
+	 *[comlee]:2016Äê 04ÔÂ 08ÈÕ ÐÇÆÚÎå 09:14:07 CST
+	 *
+	*/
+	char sys_cmd_bufer[500] = {0};
+
+	/*flush filter chain*/
+	sprintf(sys_cmd_bufer, "iptables -F %s %s", WEB_FILTER_CHAIN, FMT_ECHO_IPTABLES_CMD);
+	system_cmd_ex(sys_cmd_bufer);
+#if 0
+	for (i = 0; i < old_url_list.count; i ++) {
+		sprintf(cmd, "iptables -D INPUT -m string --hex-string  \"|%s|\" --algo kmp -j DROP", old_url_list.url_list[i]);
+		system_cmd_ex(cmd);
+	}
+	old_url_list.count = 0;
+#endif
+
+	cfg_get_item("websURLFilters", url_filter, sizeof(url_filter));
+
+	i = 0;
+	while ((getNthValueSafe(i++, url_filter, ';', entry, sizeof(entry)) != -1)) {
+		if (strlen(entry)) {
+			if (!strncasecmp(entry, "http://", strlen("http://")))
+				strncpy(entry, entry + strlen("http://"), sizeof(entry)-1);
+
+
+			memset(cmd, 0, sizeof(cmd));
+
+			snprintf(cmd, sizeof(cmd), "iptables -A web_filter -p tcp -m tcp -m webstr --url %s -j REJECT --reject-with tcp-reset", entry);
+			system_cmd_ex(cmd);
+
+			/*
+			 *×¢Ê͵ôÔ­À´µÄ×Ö·û´®Æ¥Å䣬¸ÄΪģºýÆ¥Åä.
+			 *[comlee]:2016Äê 04ÔÂ 08ÈÕ ÐÇÆÚÎå 09:14:07 CST
+			 *
+			*/
+#if 0
+			memset(cmd, 0, sizeof(cmd));
+			memset(url_hexstring, 0, sizeof(url_hexstring));
+			str_vary_dit(entry, url_hexstring);
+			sprintf(cmd, "iptables -I INPUT -m string --hex-string  \"|%s|\" --algo kmp -j DROP ", url_hexstring);
+			if (old_url_list.count < MAX_OLD_URLS_COUNT) {
+				memcpy(old_url_list.url_list[old_url_list.count], url_hexstring, (size_t)ZTE_ROUTER_URL_FILTER_LEN);
+				old_url_list.count ++;
+			}
+			system_cmd_ex(cmd);
+#endif
+		}
+	}
+
+	return;
+}
+static void zte_iptables_all_filter_run(void)
+{
+	zte_iptables_filter_run();
+	zte_iptables_filter_run_v6();
+	/* system filter */
+	zte_iptables_sys_fw_run();
+	/*url filter*/
+	zte_iptables_Webs_Filter_Run();
+
+	//¼Ò³¤Ä£Ê½¹æÔò
+
+	zte_iptables_child_filter_run();
+
+}
+
+void zte_iptables_child_filter_run()
+{
+
+	system_cmd_ex("iptables -t filter -A INPUT -j children_web_filter");
+
+	/* 0:·ÇÏÞÖÆÉÏÍøÊ±¼ä¶Î 1:ÏÞÖÆÉÏÍøÊ±¼ä¶Î*/
+	if (g_limit_time_flag == 1) {
+		zte_children_start_nonet();
+	} else if (g_limit_time_flag == 0) {
+		zte_children_stop_nonet();
+	} else {
+		return;
+	}
+}
+
+static void zte_iptables_all_nat_run(void)
+{
+	/*port forward*/
+	zte_iptables_port_forward_run();
+
+	/* EC: 616000297057, Ô­Òò: ÍøÂç²»Ö§³Ö¶Ë¿ÚÓ³Éä */
+	/*port mapping*/
+	zte_iptables_port_map_all_run();
+
+	/*DMZ*/
+	zte_iptables_DMZ_Run();
+
+}
+
+
+void alg_control_fun()
+{
+	int sip_enable = 0;
+	int ftp_enable = 0;
+	char buf[32];
+	memset(buf, 0x00, sizeof(buf));
+
+	cfg_get_item("alg_sip_enable", buf, sizeof(buf));
+	sip_enable = atoi(buf);
+	memset(buf, 0x00, sizeof(buf));
+	cfg_get_item("alg_ftp_enable", buf, sizeof(buf));
+	ftp_enable = atoi(buf);
+	slog(NET_PRINT, SLOG_NORMAL, "into ***** alg_control_fun");
+	//ALG: sip function control
+	if (1 == sip_enable) {
+		slog(NET_PRINT, SLOG_NORMAL, "insmod sip module");
+		system_cmd_ex("insmod /lib/modules/2.6.21/kernel/net/netfilter/nf_conntrack_sip.ko");
+	} else {
+		slog(NET_PRINT, SLOG_NORMAL, "rmmod sip module");
+		system_cmd_ex("rmmod nf_conntrack_sip");
+	}
+	//ALG: ftp service control
+	system_cmd_ex("iptables -t filter -F ftp_filter");
+	if (0 == ftp_enable) {
+		slog(NET_PRINT, SLOG_NORMAL, "shutdown  ftp service");
+		system_cmd_ex("iptables -t filter -N ftp_filter");
+		system_cmd_ex("iptables -t filter -I FORWARD 2 -j ftp_filter");
+		//system_cmd_ex("iptables -t filter -A ftp_filter -p tcp --dport 20 -j DROP");
+		system_cmd_ex("iptables -t filter -A ftp_filter -p tcp --dport 21 -j DROP");
+	}
+	//ALG: vpn passthr contrl
+	system_cmd_ex("vpn_pthr_contrl.sh");
+	slog(NET_PRINT, SLOG_NORMAL, "end alg_control_fun");
+}
+void zte_router_init(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "===============init firewall=================== \n");
+	/* init firewall and nat*/
+	//system_cmd_ex("nat.sh");
+	//zte_router_MTU_set();
+	system_cmd_ex("firewall_init.sh");
+
+	/* read wan if name */
+	memset(defwan_rel, 0, sizeof(defwan_rel));
+	cfg_get_item("default_wan_rel", defwan_rel, sizeof(defwan_rel));
+
+	//ZTE_LOG(LOG_DEBUG, "zte_router_init -> defwan_rel:[%s]", defwan_rel);
+
+	memset(defwan6_rel, 0, sizeof(defwan6_rel));
+	cfg_get_item("default_wan6_rel", defwan6_rel, sizeof(defwan6_rel));
+	zte_iptables_all_filter_run();
+	zte_iptables_all_nat_run();
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_router_init end \n");
+}
+
+
diff --git a/ap/app/zte_comm/zte_mainctrl/netdev_proc.c b/ap/app/zte_comm/zte_mainctrl/netdev_proc.c
new file mode 100755
index 0000000..003d88b
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/netdev_proc.c
@@ -0,0 +1,2532 @@
+#include "zte_mainctrl.h"
+#include "netapi.h"
+#include <asm/unistd.h>
+
+#define IPV6_RA_FLAG_PD (1<<2)
+#define IPV6_RA_FLAG_MANAGED (1<<1)
+#define IPV6_RA_FLAG_OTHER_CONFIG (1<<0)
+
+char defwan_if_old[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+char defwan6_if_old[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+
+static const char g_dhcp_conf[]="start %s\nend %s\ninterface %s\noption subnet %s\noption dns %s %s\noption router %s\noption lease 86400\npidfile %s\nlease_file %s\n";
+static const char g_dns_conf[]="nameserver %s\r\n";
+static const char g_dhcp6_pd_conf[]="interface %s {\n\tserver-preference 255;\n\trenew-time 6000;\n\trebind-time 9000;\n\tprefer-life-time 1300;\n\tvalid-life-time 2000;\n\tallow rapid-commit;\n\tlink %s {\n\t\tallow unicast;\n\t\tsend unicast;\n\t\tprefix %s:/%d;\n\t};\n\toption dns_servers %s %s;\n};";
+static const char g_dhcp6_state_conf[]="interface %s {\n\tserver-preference 255;\n\trenew-time 6000;\n\trebind-time 9000;\n\tprefer-life-time 1300;\n\tvalid-life-time 2000;\n\tallow rapid-commit;\n\tlink %s {\n\t\tallow unicast;\n\t\tsend unicast;\n\t\tpool {\n\t\t\trange %s to %s/%d;\n\t\t};\n\t};\n\toption dns_servers %s %s;\n};";
+static const char g_dhcp6_stateless_conf[]="interface %s {\n\tlink %s {\n\t};\n\toption dns_servers %s %s;\n};";
+static const char g_radvd_state_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvManagedFlag on;\n};";
+static const char g_radvd_stateless_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvOtherConfigFlag on;\n\tMinRtrAdvInterval 30;\n\tMaxRtrAdvInterval 100;\n\n\tprefix %s/%d\n\t{\n\t\tAdvOnLink on;\n\t\tAdvAutonomous on;\n\t\tAdvRouterAddr off;\n\n\t\tAdvValidLifetime 300;\n\t\tAdvPreferredLifetime 120;\n\t};\n};";
+static const char g_radvd_autocfg_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvOtherConfigFlag off;\n\tMinRtrAdvInterval 30;\n\tMaxRtrAdvInterval 100;\n\n\tprefix %s/%d\n\t{\n\t\tAdvOnLink on;\n\t\tAdvAutonomous on;\n\t\tAdvRouterAddr off;\n\n\t\tAdvValidLifetime 300;\n\t\tAdvPreferredLifetime 120;\n\t};\n\tRDNSS %s %s\n\t{\n\t\tAdvRDNSSPreference 15;\n\t\tAdvRDNSSOpen on;\n\t};\n};";
+
+struct dhcp_conf_info {
+	char *start;
+	char *end;
+	char *interface;
+	char *subnet;
+	char *dns1;
+	char *dns2;
+	char *router;
+	char *pidfile;
+	char *lease_file;
+};
+
+struct dhcp6_conf_info {
+	char *interface;
+	char *link;
+	char *start;
+	char *end;
+	char *prefix;
+	int prefix_len;
+	char *dns1;
+	char *dns2;
+};
+
+struct radvd_conf_info {
+	char *interface;
+	char *prefix;
+	int prefix_len;
+	char *dns1;
+	char *dns2;
+};
+
+struct in6_ifreq {
+	struct in6_addr ifr6_addr;
+	unsigned int ifr6_prefixlen;
+	int ifr6_ifindex;
+};
+
+static void save_interface_id(char *nv_name, char * ip6)
+{
+
+	int i = 0;
+	char * postptr = NULL;
+	int ip6_seg = 0; //ipv6µØÖ·ÖÐðºÅµÄ¸öÊý
+	int ip6_seg_loc = 0;
+	int len;
+
+	len = strlen(ip6);
+
+	for (i = 0; i < len; i++) {
+		if (ip6[i] == ':') {
+			ip6_seg++;
+			if (ip6_seg == 4)
+				ip6_seg_loc = i;
+		}
+	}
+
+	if (ip6_seg == 3) //¼¤»îÐÅϢΪipv6ºó׺£¬²»ÐèÒª½Ø¶Ï
+		postptr = ip6;
+
+	else if (ip6_seg == 7) //¼¤»îÐÅϢΪipv6ǰ׺+ºó׺£¬ÐèÒª½Ø¶Ï´¦Àí
+		postptr = &ip6[ip6_seg_loc + 1];
+	else
+		softap_assert("ipv6 address %s is wrong!", ip6);
+
+	cfg_set(nv_name, postptr);
+}
+
+static inline void zxic_inet_pton(int af, const char *src, void *dst)
+{
+	if(inet_pton(af, src, dst) < 0)
+		slog(NET_PRINT, SLOG_ERR, "inet_pton fail, error:%s src:%s\n", strerror(errno), src);
+}
+
+static inline void zxic_inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
+{
+	if(inet_ntop(af, src, dst, cnt) == NULL)
+		slog(NET_PRINT, SLOG_ERR, "inet_ntop fail, error:%s\n", strerror(errno));
+}
+
+static inline void zxic_remove(char *filename)
+{
+	if(remove(filename) != 0)
+		slog(NET_PRINT, SLOG_ERR, "remove fail, error:%s file:%s\n", strerror(errno), filename);
+}
+
+int net_read_file(const char *path, void *vptr, size_t n)
+{
+	int fd;
+	size_t  nleft;
+	ssize_t nread;
+	char   *ptr;
+	if (path == NULL || vptr == NULL){
+		slog(NET_PRINT, SLOG_ERR, "net_read_file Input err %p %p\n", path, vptr);
+		return -1;
+	}
+	ptr = vptr;
+	nleft = n;
+	fd = open(path, O_RDONLY);
+	if (fd < 0){
+		slog(NET_PRINT, SLOG_ERR, "net_read_file Open fail, error:%s path:%s\n", strerror(errno), path);
+		return -1;
+	}
+	while (nleft > 0) {
+		nread = read(fd, ptr, nleft);
+		if (nread < 0) {
+			if (errno == EINTR){
+				nread = 0;      /* and call read() again */
+			}else{
+				slog(NET_PRINT, SLOG_ERR, "net_read_file fail, error:%s path:%s\n", strerror(errno), path);
+				close(fd);
+				return (-1);
+			}
+		} else if (nread == 0){
+			slog(NET_PRINT, SLOG_ERR, "Read NULL! path:%s\n", path);
+			break;              /* EOF */
+		}else{
+			nleft -= nread;
+			ptr += nread;
+		}
+	}
+	close(fd);
+	return (n - nleft);         /* return >= 0 */
+}
+
+int net_write_file(const char *path, const char *buf, int len)
+{
+	int fd;
+	size_t nleft;
+	ssize_t nwritten;
+	char *ptr;
+	int err_no;
+
+	if (path == NULL || buf == NULL){
+		slog(NET_PRINT, SLOG_ERR, "net_write_file Input err %p %p\n", path, buf);
+		return -1;
+	}
+	ptr = buf;
+	nleft = len;
+	// O_TRUNC:½«Îļþ³¤¶È½Ø¶ÏΪ0£¬×öΪÐÂÎļþдÈë
+	fd = open(path, O_RDWR | O_CREAT | O_TRUNC | O_SYNC, 777);
+	if (fd < 0){
+		slog(NET_PRINT, SLOG_ERR, "net_write_file Open fail, error:%s, path:%s\n", strerror(errno), path);
+		return -1;
+	}
+	while (nleft > 0){
+		if ( (nwritten = write(fd, ptr, nleft)) <= 0){
+			err_no = errno;
+			if (nwritten < 0 && err_no == EINTR){
+				nwritten = 0;	/* and call write() again */
+			}else{
+				slog(NET_PRINT, SLOG_ERR, "net_write_file fail, error:%s, left=%d path:%s\n", strerror(err_no), nleft, path);
+				close(fd);
+				return -1;
+			}
+		}
+		nleft -= nwritten;
+		ptr += nwritten;
+	}
+	if (fsync(fd) < 0) {
+		slog(NET_PRINT, SLOG_ERR, "net_write_file Sync fail:%s, path:%s\n", strerror(errno), path);
+		close(fd);
+		return -1;
+	}
+	close(fd);
+	return len;
+}
+
+static void kill_pid_by_nv(char *nv_name)
+{
+	char pid_s[16] = {0};
+	pid_t pid = 0;
+	
+	cfg_get_item(nv_name, pid_s, sizeof(pid_s));
+	pid = atoi(pid_s);
+	if(pid > 0)
+	{
+		slog(NET_PRINT, SLOG_NORMAL, "kill %s pid=%d \n", nv_name, pid);
+		kill(pid, SIGKILL);
+	}
+	cfg_set(nv_name, "");
+}
+
+static void kill_pid_by_path(char *path)
+{
+	char pid_s[16] = {0};
+	pid_t pid = 0;
+	
+	if(access(path, F_OK))
+		return;
+	if(net_read_file(path, pid_s, sizeof(pid_s)-1) > 0){
+		pid = atoi(pid_s);
+		if(pid > 0)
+		{
+			slog(NET_PRINT, SLOG_NORMAL, "kill udhcpd pid=%d \n", pid);
+			kill(pid, SIGKILL);
+		}
+		zxic_remove(path);
+	}
+}
+
+static void arp_down(int cid)
+{
+	char nv_name[32] = {0};
+	
+	snprintf(nv_name, sizeof(nv_name), "br%d_arp_pid", cid);
+	kill_pid_by_nv(nv_name);
+}
+
+static void dhcp_down(int cid)
+{
+	char path_conf[16] = {0};
+	char path[32] = {0};
+	
+	cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+	snprintf(path, sizeof(path), "%s/udhcpd%d.pid", path_conf, cid);
+	kill_pid_by_path(path);
+}
+
+static void ndp_down(int cid)
+{
+	char nv_name[32] = {0};
+	
+	snprintf(nv_name, sizeof(nv_name), "br%d_ndp_pid", cid);
+	kill_pid_by_nv(nv_name);
+}
+
+static void dhcp6s_down(int cid)
+{
+	char nv_name[32] = {0};
+	
+	snprintf(nv_name, sizeof(nv_name), "br%d_dhcp6s_pid", cid);
+	kill_pid_by_nv(nv_name);
+}
+
+static void radvd_down(int cid)
+{
+	char path_tmp[16] = {0};
+	char path[32] = {0};
+	
+	cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp));
+	snprintf(path, sizeof(path), "%s/radvd%d.pid", path_tmp, cid);
+	kill_pid_by_path(path);
+}
+
+static int config_udhcpd(const char *path, struct dhcp_conf_info *info)
+{
+	char buf[512] = {0};
+	int buf_len = 0;
+
+	if (path == NULL || info == NULL){
+		slog(NET_PRINT, SLOG_ERR, "config_udhcpd Input err %p %p\n", path, info);
+		return -1;
+	}
+	buf_len = snprintf(buf, sizeof(buf), g_dhcp_conf, info->start, info->end, info->interface, 
+		info->subnet, info->dns1, info->dns2, info->router, info->pidfile, info->lease_file);
+	if(buf_len <= 0 || buf_len != strlen(buf)){
+		slog(NET_PRINT, SLOG_ERR, "config_udhcpd snprintf err ret=%d cur=%d\n", buf_len, strlen(buf));
+		return -1;
+	}
+	return net_write_file(path, buf, strlen(buf));
+}
+
+static int config_dns(const char *path, const char *dns1, const char *dns2)
+{
+	char buf[512] = {0};
+	char *pbuf = buf;
+	int ret = 0;
+
+	if (path == NULL || (dns1 == NULL && dns2 == NULL)){
+		slog(NET_PRINT, SLOG_ERR, "config_dns Input err\n");
+		return -1;
+	}
+	ret = net_read_file(path, buf, sizeof(buf)-1);
+	if(ret > 0 && ret < (sizeof(buf) >> 1)){
+		pbuf = pbuf + strlen(pbuf);
+	}
+	else
+		slog(NET_PRINT, SLOG_ERR, "config_dns read err ret=%d\n",ret);
+	if(dns1 != NULL && strlen(dns1) > 6){
+		snprintf(pbuf, sizeof(buf), g_dns_conf, dns1);
+		pbuf = pbuf + strlen(pbuf);
+	}
+	if(dns2 != NULL && strlen(dns2) > 6){
+		snprintf(pbuf, sizeof(buf)-strlen(buf), g_dns_conf, dns2);
+	}
+	if(strlen(buf) > 0)
+		return net_write_file(path, buf, strlen(buf));
+	return 0;
+}
+
+/*¼¤»îIPµÄ×îºóÒ»¸öÊý×ÖµÄ2½øÖƵĺó3λÊÇ010 001 000ʱ+2£¬·ñÔò-2*/
+FILE *pdp_direct_config_quick4(const char *nv_pswan, struct pdp_active_info *actinfo)
+{
+	int i = 0;
+	unsigned int addr = 0;
+	unsigned int dns1 = 0;
+	unsigned int dns2 = 0;
+	unsigned int route_ip = 0;
+	unsigned int wan_ip = 0;
+	unsigned int netmask = 0;
+	char dns1_s[IPV4ADDLEN_MAX] = {0};
+	char dns2_s[IPV4ADDLEN_MAX] = {0};
+	char route_ip_s[IPV4ADDLEN_MAX] = {0};
+	char wan_ip_s[IPV4ADDLEN_MAX] = {0};
+	char netmask_s[IPV4ADDLEN_MAX] = {0};
+	char path_conf[16] = {0};
+	char dev[16] = {0};
+	char pidfile[32] = {0};
+	char lease_file[32] = {0};
+	char path[32] = {0};
+	char cmd[64] = {0};
+	char nv_name[NV_NAME_LEN] = {0};
+	struct dhcp_conf_info info = {0};
+	
+	cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+	snprintf(dev, sizeof(dev), "br%d", actinfo->c_id);
+	snprintf(pidfile, sizeof(pidfile), "%s/udhcpd%d.pid", path_conf, actinfo->c_id);
+	snprintf(lease_file, sizeof(lease_file), "%s/udhcpd%d.leases", path_conf, actinfo->c_id);
+	snprintf(path, sizeof(path), "%s/udhcpd%d.conf", path_conf, actinfo->c_id);
+	zxic_inet_pton(AF_INET, actinfo->act_info.ip, &addr);
+	zxic_inet_pton(AF_INET, actinfo->act_info.pri_dns, &dns1);
+	zxic_inet_pton(AF_INET, actinfo->act_info.sec_dns, &dns2);
+	addr = htonl(addr);
+	if(dns1)
+		snprintf(dns1_s, sizeof(dns1_s), "%s", actinfo->act_info.pri_dns);
+	else
+		snprintf(dns1_s, sizeof(dns1_s), "%s", "114.114.114.114");
+	if(dns2)
+		snprintf(dns2_s, sizeof(dns2_s), "%s", actinfo->act_info.sec_dns);
+	else
+		snprintf(dns2_s, sizeof(dns2_s), "%s", "8.8.8.8");
+
+#if 0 //btrunk
+	netmask = 0xffff0000;
+	if((addr&0xff) <= 1){
+		route_ip = addr+2;
+		wan_ip = addr+1;
+	}
+	else if((addr&0xff) >= 254){
+		route_ip = addr-2;
+		wan_ip = addr-1;
+	}else{
+		route_ip = addr+1;
+		wan_ip = addr-1;
+	}
+#else
+	if((addr&7) < 3){
+		route_ip = addr+2;
+		wan_ip = addr+1;
+	}else{
+		route_ip = addr-2;
+		wan_ip = addr-1;
+	}
+	for(i = 3; i < 32; i++){
+		/*²»ÊÇÁ¬ÐøµÄÈ«0 && ²»ÊÇÁ¬ÐøµÄÈ«1*/
+		if(((addr>>i)<<i) != addr && (((1<<i)-1)|addr) != addr)
+			break;
+	}
+	netmask = 0xfffffff8;
+	if(i > 3 && i < 32)//cov
+		netmask = ((netmask>>i)<<i);
+#endif
+	route_ip = htonl(route_ip);
+	wan_ip = htonl(wan_ip);
+	netmask = htonl(netmask);
+	inet_ntop(AF_INET, (void *)&route_ip, route_ip_s, IPV4ADDLEN_MAX);
+	inet_ntop(AF_INET, (void *)&wan_ip, wan_ip_s, IPV4ADDLEN_MAX);
+	inet_ntop(AF_INET, (void *)&netmask, netmask_s, IPV4ADDLEN_MAX);
+	snprintf(nv_name, sizeof(nv_name), "%s%d_pdp_ip", nv_pswan, actinfo->c_id);
+	cfg_set(nv_name, actinfo->act_info.ip);
+	snprintf(nv_name, sizeof(nv_name), "%s%d_ip", nv_pswan, actinfo->c_id);
+	cfg_set(nv_name, wan_ip_s);
+	snprintf(nv_name, sizeof(nv_name), "br%d_ip", actinfo->c_id);
+	cfg_set(nv_name, route_ip_s);
+	snprintf(nv_name, sizeof(nv_name), "br%d_nm", actinfo->c_id);//for mbim
+	cfg_set(nv_name, netmask_s);
+	snprintf(nv_name, sizeof(nv_name), "%s%d_pridns", nv_pswan, actinfo->c_id);
+	cfg_set(nv_name, dns1_s);
+	snprintf(nv_name, sizeof(nv_name), "%s%d_secdns", nv_pswan, actinfo->c_id);
+	cfg_set(nv_name, dns2_s);
+	
+	info.start = actinfo->act_info.ip;
+	info.end = actinfo->act_info.ip;
+	info.interface = dev;
+	info.subnet = netmask_s;
+	info.dns1 = dns1_s;
+	info.dns2 = dns2_s;
+	info.router = route_ip_s;
+	info.pidfile = pidfile;
+	info.lease_file = lease_file;
+	if(config_udhcpd(path, &info) < 0)
+		return NULL;
+	if(config_dns("/etc/resolv.conf", dns1_s, dns2_s) < 0)
+		return NULL;
+	snprintf(cmd, sizeof(cmd), "psext_up.sh %d", actinfo->c_id);
+	dhcp_down(actinfo->c_id);
+	return popen(cmd, "r");
+}
+
+static int config_dhcp6s(const char *path, struct dhcp6_conf_info *info, int M_O_flag)
+{
+	char buf[1024] = {0};
+	int buf_len = 0;;
+
+	if (path == NULL || info == NULL){
+		slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s Input err %p %p\n", path, info);
+		return -1;
+	}
+	if(M_O_flag & IPV6_RA_FLAG_PD){
+		buf_len = snprintf(buf, sizeof(buf), g_dhcp6_pd_conf, info->interface, info->link, info->prefix, 
+			info->prefix_len, info->dns1, info->dns2);
+	}else if(M_O_flag & IPV6_RA_FLAG_MANAGED){
+		buf_len = snprintf(buf, sizeof(buf), g_dhcp6_state_conf, info->interface, info->link, info->start, 
+			info->end, info->prefix_len, info->dns1, info->dns2);
+	}else if(M_O_flag & IPV6_RA_FLAG_OTHER_CONFIG){
+		buf_len = snprintf(buf, sizeof(buf), g_dhcp6_stateless_conf, info->interface, info->link,
+			info->dns1, info->dns2);
+	}else{
+		slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s err m=0 o=0\n");
+		return 0;
+	}
+	if(buf_len <= 0 || buf_len != strlen(buf)){
+		slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s snprintf err ret=%d cur=%d\n", buf_len, strlen(buf));
+		return -1;
+	}
+	return net_write_file(path, buf, strlen(buf));
+}
+
+static int config_radvd(const char *path, struct radvd_conf_info *info, int M_O_flag)
+{
+	char buf[1024] = {0};
+	int buf_len;
+
+	if (path == NULL || info == NULL){
+		slog(NET_PRINT, SLOG_ERR, "config_radvd Input err %p %p\n", path, info);
+		return -1;
+	}
+	if((M_O_flag & IPV6_RA_FLAG_MANAGED) || (M_O_flag & IPV6_RA_FLAG_PD)){
+		buf_len = snprintf(buf, sizeof(buf), g_radvd_state_conf, info->interface);
+	}else if(M_O_flag & IPV6_RA_FLAG_OTHER_CONFIG){
+		buf_len = snprintf(buf, sizeof(buf), g_radvd_stateless_conf, info->interface, info->prefix, info->prefix_len);
+	}else{
+		buf_len = snprintf(buf, sizeof(buf), g_radvd_autocfg_conf, info->interface, info->prefix, info->prefix_len,
+			info->dns1, info->dns2);
+	}
+	if(buf_len <= 0 || buf_len != strlen(buf)){
+		slog(NET_PRINT, SLOG_ERR, "config_radvd snprintf err ret=%d cur=%d\n", buf_len, strlen(buf));
+		return -1;
+	}
+	return net_write_file(path, buf, strlen(buf));
+}
+
+FILE *pdp_direct_config_quick6(const char *nv_pswan, struct pdp_active_info *actinfo, char *prefix, int prefix_len)
+{
+	char cmd[100] = {0};
+	char nv_pridns6[NV_NAME_LEN] = {0};
+	char nv_secdns6[NV_NAME_LEN] = {0};
+	char nv_ip6[NV_NAME_LEN] = {0};
+	snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", nv_pswan, actinfo->c_id);
+	save_interface_id(nv_ip6, actinfo->act_info.ip6);
+	snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", nv_pswan, actinfo->c_id);
+	cfg_set(nv_pridns6, actinfo->act_info.pri_dns6);
+	snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", nv_pswan, actinfo->c_id);
+	cfg_set(nv_secdns6, actinfo->act_info.sec_dns6);
+	slog(NET_PRINT, SLOG_NORMAL, "pdp_quick6 prefix=%s len=%d \n", prefix, prefix_len);
+	if(prefix_len > 0)
+	{
+		char nv_name[NV_NAME_LEN] = {0};
+		struct in6_addr ipv6_addr = {0};
+		char br_ip6[IPV6ADDLEN_MAX] = {0};
+		char wan_ip6[IPV6ADDLEN_MAX] = {0};
+		char pdp_ip6[IPV6ADDLEN_MAX] = {0};
+		int M_O_flag = 0;
+		char PdFlag[4] = {0};
+		char AdvManagedFlag[4] = {0};
+		char AdvOtherConfigFlag[4] = {0};
+		struct dhcp6_conf_info dhcp6_info = {0};
+		struct radvd_conf_info radvd_info = {0};
+		char path_conf[16] = {0};
+		char dev[16] = {0};
+		char dhcp6_path[32] = {0};
+		char radvd_path[32] = {0};
+		
+		snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_local", nv_pswan, actinfo->c_id);
+		cfg_get_item(nv_ip6, cmd, sizeof(cmd));
+		snprintf(pdp_ip6, sizeof(pdp_ip6), "fe80::%s", cmd);
+		cfg_set(nv_name, pdp_ip6);//actinfo->act_info.ip6
+		memcpy(pdp_ip6, actinfo->act_info.ip6, IPV6ADDLEN_MAX -1);
+		if((prefix_len/16)*5 < IPV6ADDLEN_MAX)//kw
+			memcpy(pdp_ip6, prefix, (prefix_len/16)*5);
+		pdp_ip6[IPV6ADDLEN_MAX-1]='\0';//kw
+		snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_pdp", nv_pswan, actinfo->c_id);
+		cfg_set(nv_name, pdp_ip6);
+		snprintf(nv_name, sizeof(nv_name), "%s%d_dhcpv6_end", nv_pswan, actinfo->c_id);//for mbim
+		cfg_set(nv_name, pdp_ip6);
+		zxic_inet_pton(AF_INET6, pdp_ip6, &ipv6_addr);
+		ipv6_addr.s6_addr[14]++;
+		zxic_inet_ntop(AF_INET6, &ipv6_addr, br_ip6, sizeof(br_ip6));
+		snprintf(nv_name, sizeof(nv_name), "br%d_ipv6_ip", actinfo->c_id);
+		cfg_set(nv_name, br_ip6);
+		ipv6_addr.s6_addr[14]++;
+		zxic_inet_ntop(AF_INET6, &ipv6_addr, wan_ip6, sizeof(wan_ip6));
+		snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_ip", nv_pswan, actinfo->c_id);
+		cfg_set(nv_name, wan_ip6);
+		snprintf(dev, sizeof(dev), "br%d", actinfo->c_id);
+		cfg_get_item("path_conf", path_conf, sizeof(path_conf));
+		snprintf(dhcp6_path, sizeof(dhcp6_path), "%s/dhcp6s%d.conf", path_conf, actinfo->c_id);
+		snprintf(radvd_path, sizeof(radvd_path), "%s/radvd%d.conf", path_conf, actinfo->c_id);
+		cfg_get_item("dhcpv6statePdEnabled", PdFlag, sizeof(PdFlag));
+		cfg_get_item("dhcpv6stateEnabled", AdvManagedFlag, sizeof(AdvManagedFlag));
+		cfg_get_item("dhcpv6statelessEnabled", AdvOtherConfigFlag, sizeof(AdvOtherConfigFlag));
+		if(atoi(PdFlag) == 1)
+			M_O_flag = M_O_flag|IPV6_RA_FLAG_PD;
+		if(atoi(AdvManagedFlag) == 1)
+			M_O_flag = M_O_flag|IPV6_RA_FLAG_MANAGED;
+		if(atoi(AdvOtherConfigFlag) == 1)
+			M_O_flag = M_O_flag|IPV6_RA_FLAG_OTHER_CONFIG;
+		dhcp6_info.interface = dev;
+		dhcp6_info.link = dev;
+		dhcp6_info.start = pdp_ip6;
+		dhcp6_info.end = pdp_ip6;
+		dhcp6_info.prefix = prefix;
+		dhcp6_info.prefix_len = prefix_len;
+		dhcp6_info.dns1 = actinfo->act_info.pri_dns6;
+		dhcp6_info.dns2 = actinfo->act_info.sec_dns6;
+		if(config_dhcp6s(dhcp6_path, &dhcp6_info, M_O_flag) < 0)
+			return NULL;
+		radvd_info.interface = dev;
+		radvd_info.prefix = br_ip6;
+		radvd_info.prefix_len = prefix_len;
+		radvd_info.dns1 = actinfo->act_info.pri_dns6;
+		radvd_info.dns2 = actinfo->act_info.sec_dns6;
+		if(config_radvd(radvd_path, &radvd_info, M_O_flag) < 0)
+			return NULL;
+		if(config_dns("/etc/resolv.conf", actinfo->act_info.pri_dns6, actinfo->act_info.sec_dns6) < 0)
+			return NULL;
+		snprintf(cmd, sizeof(cmd), "psext_up_ipv6.sh %d", actinfo->c_id);
+		dhcp6s_down(actinfo->c_id);
+		return popen(cmd, "r");
+	}else{
+		sprintf(cmd, "psext_updown_ipv6.sh linkup %d", actinfo->c_id);
+		return popen(cmd, "r");
+	}
+}
+
+void pdp_direct_config_quick(struct pdp_active_info *actinfo, char *prefix, int prefix_len)
+{
+	FILE *fpv4 = NULL;
+	FILE *fpv6 = NULL;
+
+	zxic_remove("/etc_rw/resolv.conf");
+	
+	if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		fpv4 = pdp_direct_config_quick4(ps_wan, actinfo);
+		slog(NET_PRINT, SLOG_NORMAL, "psext_up4 popen=%p \n", fpv4);
+	}
+
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		fpv6 = pdp_direct_config_quick6(ps_wan, actinfo, prefix, prefix_len);
+		slog(NET_PRINT, SLOG_NORMAL, "psext_up6 popen=%p \n", fpv6);
+	}
+	if(fpv4 != NULL)
+		pclose(fpv4);
+	if(fpv6 != NULL)
+		pclose(fpv6);
+}
+
+void net_br_deact_quick(int c_id, unsigned char ip46flag)
+{
+	FILE *fpv4 = NULL;
+	FILE *fpv6 = NULL;
+	char cmd[64] = {0};
+	
+	if (ip46flag == V4_VALID || ip46flag == V46_VALID) {
+		sprintf(cmd, "psext_down.sh %d", c_id);
+		fpv4 = popen(cmd, "r");
+		arp_down(c_id);
+		dhcp_down(c_id);
+	}
+	if (ip46flag == V6_VALID || ip46flag == V46_VALID) {
+		memset(cmd, 0, sizeof(cmd));
+		sprintf(cmd, "psext_down_ipv6.sh %d", c_id);
+		fpv6 = popen(cmd, "r");
+		radvd_down(c_id);
+		dhcp6s_down(c_id);
+		ndp_down(c_id);
+	}
+	net_write_file("/etc/resolv.conf", "", 0);
+	if(fpv4 != NULL)
+		pclose(fpv4);
+	if(fpv6 != NULL)
+		pclose(fpv6);
+}
+
+void net_sendmsg_2_atctl(int cid, int iptype, int cmd)
+{
+	int ret = -1;
+	TScriptMSG scriptmsg;
+	memset(&scriptmsg, 0, sizeof(TScriptMSG));
+	scriptmsg.cid = cid;
+	scriptmsg.iptype = iptype;
+	char buffer[128] = {0};
+	
+	slog(NET_PRINT, SLOG_NORMAL, "$$$$$net_sendmsg_2_atctl cid=%d,iptype=%d\n", cid, iptype);
+	ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, cmd, sizeof(TScriptMSG), &scriptmsg, 0); 
+	if (0 != ret) {
+		softap_assert("send msg to at_ctl error");		
+	}
+	snprintf(buffer, sizeof(buffer), "pdp_act_state_%d", cid);
+	if(cmd == MSG_CMD_LINKUP_END)
+		cfg_set(buffer, "act");
+	else if(cmd == MSG_CMD_LINKDOWN_END)
+		cfg_set(buffer, "deact");
+}
+
+void pdp_wan_config_quick(struct pdp_active_info *actinfo, char *prefix, int prefix_len)
+{
+	int flag = 0;
+	struct in6_addr ipv6_addr = {0};
+	char wan_name[NV_NAME_LEN] = {0};
+	char br_ip6[IPV6ADDLEN_MAX] = {0};
+	char pdp_ip6[IPV6ADDLEN_MAX] = {0};
+	char dhcp_ip6_start[IPV6ADDLEN_MAX] = {0};
+	char dhcp_ip6_end[IPV6ADDLEN_MAX] = {0};
+	char tc_enable[4] = {0};
+	char buffer[128] = {0};
+	char mtu[16] = {0};
+	char xlat_enable[4] = {0};
+	
+	cfg_get_item("tc_enable", tc_enable, sizeof(tc_enable));
+	snprintf(wan_name,NV_NAME_LEN,	"%s%d", ps_wan, actinfo->c_id);
+	slog(NET_PRINT, SLOG_NORMAL, "act ifconfig wanname:%s!\n", wan_name);
+
+	//ifconfig wan down
+	snprintf(buffer, sizeof(buffer), "ifconfig %s down", wan_name);
+	system_cmd_ex(buffer);
+	//ifconfig mtu
+	cfg_get_item("mtu", mtu, sizeof(mtu));
+	snprintf(buffer, sizeof(buffer), "ifconfig %s mtu %s", wan_name, mtu);
+	system_cmd_ex(buffer);
+	//ifconfig ip
+	if(actinfo->act_info.ip46flag & V4_VALID){
+		snprintf(buffer, sizeof(buffer), "%s_ip", wan_name);
+		cfg_set(buffer, actinfo->act_info.ip);
+		snprintf(buffer, sizeof(buffer), "%s_gw", wan_name);
+		cfg_set(buffer, actinfo->act_info.ip);
+		snprintf(buffer, sizeof(buffer), "%s_pridns", wan_name);
+		cfg_set(buffer, actinfo->act_info.pri_dns);
+		snprintf(buffer, sizeof(buffer), "%s_secdns", wan_name);
+		cfg_set(buffer, actinfo->act_info.sec_dns);
+		snprintf(buffer, sizeof(buffer), "ifconfig %s %s netmask 255.255.255.0", wan_name, actinfo->act_info.ip);
+		system_cmd_ex(buffer);
+	}
+	//ifconfig up
+	snprintf(buffer, sizeof(buffer), "ifconfig %s up", wan_name);
+	system_cmd_ex(buffer);
+	//ifconfig ipv6
+	if(actinfo->act_info.ip46flag & V6_VALID){
+		snprintf(buffer, sizeof(buffer), "%s_ipv6_interface_id", wan_name);
+		save_interface_id(buffer, actinfo->act_info.ip6);
+		snprintf(buffer, sizeof(buffer), "%s_ipv6_pridns_auto", wan_name);
+		cfg_set(buffer, actinfo->act_info.pri_dns6);
+		snprintf(buffer, sizeof(buffer), "%s_ipv6_secdns_auto", wan_name);
+		cfg_set(buffer, actinfo->act_info.sec_dns6);
+		memcpy(pdp_ip6, actinfo->act_info.ip6, IPV6ADDLEN_MAX -1);
+		if((prefix_len/16)*5 < IPV6ADDLEN_MAX)//kw
+			memcpy(pdp_ip6, prefix, (prefix_len/16)*5);
+		pdp_ip6[IPV6ADDLEN_MAX-1]='\0';//kw
+		snprintf(buffer, sizeof(buffer), "ifconfig %s %s/126", wan_name, pdp_ip6);
+		system_cmd_ex(buffer);
+		snprintf(buffer, sizeof(buffer), "%s_ipv6_ip", wan_name);
+		cfg_set(buffer, pdp_ip6);
+		zxic_inet_pton(AF_INET6, pdp_ip6, &ipv6_addr);
+		ipv6_addr.s6_addr[14]++;
+		zxic_inet_ntop(AF_INET6, &ipv6_addr, br_ip6, sizeof(br_ip6));
+		ipv6_addr.s6_addr[14]++;
+		if (0xFF == ipv6_addr.s6_addr[14]) {
+			ipv6_addr.s6_addr[14] = 0;
+		}
+		zxic_inet_ntop(AF_INET6, &ipv6_addr, dhcp_ip6_start, sizeof(dhcp_ip6_start));
+		ipv6_addr.s6_addr[14]++;
+		zxic_inet_ntop(AF_INET6, &ipv6_addr, dhcp_ip6_end, sizeof(dhcp_ip6_end));
+	}
+	{
+		char path[32] = {0};
+		char path_tmp[32] = {0};
+		char dns_path[64] = {0};
+		char wan_pri[32] = {0};
+		char lan_if[16] = {0};
+		int defwan_pri = 0;
+		int pri = 0;
+		char defwan_if[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+		char defwan_real[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+		char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+		int defwan4_change = 0;
+		int defwan6_change = 0;
+		struct default_dev_info defwan_dev_info = {0};
+		
+		cfg_get_item("lan_name", lan_if, sizeof(lan_if));
+		cfg_get_item("path_conf", path, sizeof(path));
+		cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp));
+		defwan_dev_info.ip46flag = actinfo->act_info.ip46flag;
+		cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri));
+		pri = atoi(wan_pri);
+		if(pri < 0 || pri > 65535)
+			return;
+		if (actinfo->pdp_type == PDP_NORMAL) {
+			if(default_route_check()){
+				cfg_get_item("default_wan_name", defwan_if, sizeof(defwan_if));
+				if(strncmp(defwan_if, wifi_wan, strlen(wifi_wan)) == 0){
+					cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri));
+					defwan_pri = atoi(wan_pri);
+					strcpy(defwan_dev_name, wifi_wan);
+				}
+				else if (strncmp(defwan_if, eth_wan, strlen(eth_wan)) == 0){
+					cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri));
+					defwan_pri = atoi(wan_pri);
+					strcpy(defwan_dev_name, eth_wan);
+				}
+			}
+			if (pri > defwan_pri) {
+				defwan_pri = pri;
+				snprintf(defwan_if, sizeof(defwan_if), "%s%d", ps_wan, actinfo->c_id);
+				strcpy(defwan_real, defwan_if);
+				strcpy(defwan_dev_name, ps_wan);
+				//½«µ±Ç°ÓÐÐ§Íø¿ÚÖÐÓÅÏȼ¶×î¸ßµÄÉèÖÃΪȱʡÍâÍø¿Ú
+				if(actinfo->act_info.ip46flag & V4_VALID){
+					cfg_set("default_wan_name", defwan_if);
+					cfg_set("default_wan_rel", defwan_real);
+				}
+				if(actinfo->act_info.ip46flag & V6_VALID){
+					cfg_set("default_wan6_name", defwan_if);
+					cfg_set("default_wan6_rel", defwan_real);
+				}
+			}
+			defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name);
+			net_default_wan_proc(&defwan_dev_info);
+		} else {
+			int rt_num = pri*10 + actinfo->c_id;
+			if(actinfo->act_info.ip46flag & V4_VALID){
+				snprintf(buffer, sizeof(buffer), "ip rule add from %s table %d", actinfo->act_info.ip, rt_num);
+				system_cmd_ex(buffer);
+				snprintf(buffer, sizeof(buffer), "ip route add default dev %s table %d", wan_name, rt_num);
+				system_cmd_ex(buffer);
+				system_cmd_ex("ip route flush cache");
+			}
+			if(actinfo->act_info.ip46flag & V6_VALID){
+				snprintf(buffer, sizeof(buffer), "ip -6 rule add from %s table %d", pdp_ip6, rt_num);
+				system_cmd_ex(buffer);
+				snprintf(buffer, sizeof(buffer), "ip -6 route add default dev %s table %d", wan_name, rt_num);
+				system_cmd_ex(buffer);
+				system_cmd_ex("ip -6 route flush cache");
+			}
+		}
+		if (0 == strlen(defwan_real)) {
+			slog(NET_PRINT, SLOG_ERR, "pdp_wan_config_quick defwan_if not selected! \n");
+			net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END);
+			return;
+		}
+		if(actinfo->act_info.ip46flag & V4_VALID)
+			defwan4_change = strcmp(defwan_if_old, defwan_real);
+		if(actinfo->act_info.ip46flag & V6_VALID)
+			defwan6_change = strcmp(defwan6_if_old, defwan_real);
+		
+		//Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ
+		if (defwan4_change && (actinfo->act_info.ip46flag & V4_VALID))
+		{
+			char nat_enable[4] = {0};
+			
+			system_cmd_ex("iptables -P INPUT ACCEPT");
+			system_cmd_ex("iptables -P OUTPUT ACCEPT");
+			system_cmd_ex("iptables -P FORWARD ACCEPT");
+			system_cmd_ex("iptables -t nat -F");
+			system_cmd_ex("iptables -t nat -X port_forward");
+			system_cmd_ex("iptables -t nat -X DMZ");
+			system_cmd_ex("iptables -t nat -X port_mapping");
+			system_cmd_ex("iptables -t nat -N port_forward");
+			system_cmd_ex("iptables -t nat -N DMZ");
+			system_cmd_ex("iptables -t nat -N port_mapping");
+			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_forward");
+			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j DMZ");
+			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_mapping");
+			cfg_get_item("natenable", nat_enable, sizeof(nat_enable));
+			
+			if(strcmp(nat_enable, "0") != 0){
+				snprintf(buffer, sizeof(buffer), "iptables -t nat -A POSTROUTING -o %s -j MASQUERADE", defwan_real);
+				system_cmd_ex(buffer);
+			}
+			
+			net_write_file("/etc/resolv.conf", "", 0);
+			snprintf(buffer, sizeof(buffer), g_dns_conf, "127.0.0.1");
+			net_write_file("/etc/resolv.conf", buffer, strlen(buffer));
+		}
+		if(actinfo->act_info.ip46flag & V6_VALID){
+			char dhcp6s_conf[64] = {0};
+			char radvd_conf[64] = {0};
+			char radvd_pidfile[64] = {0};
+			char ndp_log[64] = {0};
+			int M_O_flag = 0;
+			char PdFlag[4] = {0};
+			char AdvManagedFlag[4] = {0};
+			char AdvOtherConfigFlag[4] = {0};
+			struct dhcp6_conf_info dhcp6_info = {0};
+			struct radvd_conf_info radvd_info = {0};
+		
+			snprintf(dhcp6s_conf, sizeof(dhcp6s_conf), "%s/dhcp6s_%s.conf", path, defwan_real); 
+			snprintf(radvd_conf, sizeof(radvd_conf), "%s/radvd_%s.conf", path, defwan_real);
+			snprintf(radvd_pidfile, sizeof(radvd_pidfile), "%s/radvd_%s.pid", path_tmp, defwan_real);
+			snprintf(ndp_log, sizeof(ndp_log), "%s/ndp_%s.log", path, defwan_real);
+		
+			net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "0", 1);
+			snprintf(buffer, sizeof(buffer), "ip -6 route add default dev %s", defwan_real);
+			system_cmd_ex(buffer);
+			snprintf(buffer, sizeof(buffer), "ip -6 addr add %s/64 dev br0", br_ip6);
+			system_cmd_ex(buffer);
+			cfg_set("ipv6_br0_addr", br_ip6);
+			net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", 1);
+			net_write_file("/proc/sys/net/ipv6/conf/all/proxy_ndp", "1", 1);
+			ndp_down(0);
+			snprintf(buffer, sizeof(buffer), "zte_ndp -a -s br0 -d %s -l %s &", defwan_real, ndp_log);
+			system_cmd_ex(buffer);
+			if(actinfo->act_info.ip46flag == V6_VALID){
+				cfg_get_item("xlat_enable", xlat_enable, sizeof(xlat_enable));
+				if(atoi(xlat_enable) && (default_route_check() == 0)){
+					char xlat_prefix[IPV6ADDLEN_MAX] = {0};
+					cfg_get_item("xlat_prefix", xlat_prefix, sizeof(xlat_prefix));
+					system_cmd_ex("chmod 777 /dev/net/tun");
+					if(strlen(xlat_prefix) == 0){
+						snprintf(buffer, sizeof(buffer),"clatd -i %s &", defwan_real);
+					} else {
+						snprintf(buffer, sizeof(buffer),"clatd -i %s -p %s &", defwan_real, xlat_prefix);
+					}
+					system_cmd_ex(buffer);
+					system_cmd_ex("echo 1 > /proc/sys/net/ipv4/ip_forward");
+					snprintf(buffer, sizeof(buffer),"iptables -t nat -A POSTROUTING -o v4-%s -j MASQUERADE", defwan_real);
+					system_cmd_ex(buffer);
+				}
+			}
+			
+			//dhcp set
+			dhcp6s_down(0);
+			zxic_remove(dhcp6s_conf);
+		
+			dhcp6_info.interface = lan_if;
+			dhcp6_info.link = lan_if;
+			dhcp6_info.start = dhcp_ip6_start;
+			dhcp6_info.end= dhcp_ip6_end;
+			dhcp6_info.prefix= prefix;
+			dhcp6_info.dns1 = actinfo->act_info.pri_dns6;
+			dhcp6_info.dns2 = actinfo->act_info.sec_dns6;
+			dhcp6_info.prefix_len= prefix_len;;
+			cfg_get_item("dhcpv6statePdEnabled", PdFlag, sizeof(PdFlag));
+			cfg_get_item("dhcpv6stateEnabled", AdvManagedFlag, sizeof(AdvManagedFlag));
+			cfg_get_item("dhcpv6statelessEnabled", AdvOtherConfigFlag, sizeof(AdvOtherConfigFlag));
+			if(atoi(PdFlag) == 1)
+				M_O_flag = M_O_flag|IPV6_RA_FLAG_PD;
+			if(atoi(AdvManagedFlag) == 1)
+				M_O_flag = M_O_flag|IPV6_RA_FLAG_MANAGED;
+			if(atoi(AdvOtherConfigFlag) == 1)
+				M_O_flag = M_O_flag|IPV6_RA_FLAG_OTHER_CONFIG;
+		
+			memset(buffer, 0, sizeof(buffer));
+			snprintf(buffer, sizeof(buffer), "dhcp6s -dDf -c %s %s &", dhcp6s_conf, lan_if);
+			if(config_dhcp6s(dhcp6s_conf, &dhcp6_info, M_O_flag) < 0)
+				return;
+			system_cmd_ex(buffer);
+			slog(NET_PRINT, SLOG_NORMAL, "start dhcp6s mo=%d:%s\n", M_O_flag, buffer);
+		
+			//radvd set
+			{
+				char path_tmp[16] = {0};
+				char path[32] = {0};
+				
+				cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp));
+				snprintf(path, sizeof(path), "%s/radvd_%s.pid", path_tmp, defwan_real);
+				kill_pid_by_path(path);
+			}
+			zxic_remove(radvd_conf);
+			radvd_info.interface = lan_if;
+			radvd_info.prefix = br_ip6;
+			radvd_info.prefix_len = prefix_len;
+			radvd_info.dns1 = actinfo->act_info.pri_dns6;
+			radvd_info.dns2 = actinfo->act_info.sec_dns6;
+		
+			memset(buffer, 0, sizeof(buffer));
+			snprintf(buffer, sizeof(buffer), "radvd -d 3 -C %s -p %s &", radvd_conf, radvd_pidfile);
+			if(config_radvd(radvd_conf, &radvd_info, M_O_flag) < 0){
+				return;
+			}
+			zxic_remove(radvd_pidfile);
+			system_cmd_ex(buffer);	
+		}
+		system_cmd_ex("killall -9 dnsmasq");
+		snprintf(dns_path, sizeof(dns_path), "%s/dnsmasq.conf", path);	
+		net_write_file(dns_path, "", 0);
+		
+		if(actinfo->act_info.ip46flag & V4_VALID) {
+			unsigned int dns1 = 0;
+			unsigned int dns2 = 0;
+			unsigned int dns_ext = 0;
+			char dns1_s[IPV4ADDLEN_MAX] = {0};
+			char dns2_s[IPV4ADDLEN_MAX] = {0};
+			char ext_dns[IPV4ADDLEN_MAX] = {0};
+			
+			system_cmd_ex("route del default");
+			snprintf(buffer, sizeof(buffer),"route add default dev %s", defwan_real);
+			system_cmd_ex(buffer);
+			zxic_inet_pton(AF_INET, actinfo->act_info.pri_dns, &dns1);
+			zxic_inet_pton(AF_INET, actinfo->act_info.sec_dns, &dns2);
+			if(dns1)
+				snprintf(dns1_s, sizeof(dns1_s), "%s", actinfo->act_info.pri_dns);
+			else
+				snprintf(dns1_s, sizeof(dns1_s), "%s", "114.114.114.114");
+			if(dns2)
+				snprintf(dns2_s, sizeof(dns2_s), "%s", actinfo->act_info.sec_dns);
+			else
+				snprintf(dns2_s, sizeof(dns2_s), "%s", "8.8.8.8");
+			config_dns(dns_path, dns1_s, dns2_s);
+			cfg_get_item("dns_extern", ext_dns, sizeof(ext_dns));
+			zxic_inet_pton(AF_INET, ext_dns, &dns_ext);
+			if(dns_ext){
+				config_dns(dns_path, NULL, ext_dns);
+			}
+			//set ip addr for webui show
+			cfg_set("wan_ipaddr", actinfo->act_info.ip);
+			net_write_file("/proc/sys/net/ipv4/ip_forward", "1", 1);
+		}
+		if(actinfo->act_info.ip46flag & V6_VALID) {
+			char ext_dns_v6[IPV6ADDLEN_MAX] = {0};
+			struct in6_addr ipv6_dns_ext = {0};
+		
+			config_dns(dns_path, actinfo->act_info.pri_dns6, actinfo->act_info.sec_dns6);
+			cfg_get_item("ipv6_dns_extern", ext_dns_v6, sizeof(ext_dns_v6));
+			if(inet_pton(AF_INET6, pdp_ip6, &ipv6_dns_ext) > 0){
+				config_dns(dns_path, NULL, ext_dns_v6);
+			}
+			//set ipv6 addr for webui show
+			cfg_set("ipv6_wan_ipaddr", pdp_ip6);
+		}
+		if(atoi(tc_enable)){
+			snprintf(buffer, sizeof(buffer),"tc_tbf.sh up %d", actinfo->c_id);
+			system_cmd_ex(buffer);
+		}
+		snprintf(buffer, sizeof(buffer),"dnsmasq -i %s -r %s &", lan_if, dns_path);
+		system_cmd_ex(buffer);
+		slog(NET_PRINT, SLOG_NORMAL, "pdp_wan_config_quick defwan_change v4:%d v6:%d \n", defwan4_change, defwan6_change);
+		
+		//ȱʡÍâÍø¿Ú·¢Éú±ä»¯ÔòÖØÉènatºÍfilter
+		if (defwan4_change || defwan6_change) {
+			zte_router_init();
+			if(actinfo->act_info.ip46flag & V4_VALID){
+				memset(defwan_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN);
+				strncpy(defwan_if_old, defwan_real, strlen(defwan_real));
+			}
+			if(actinfo->act_info.ip46flag & V6_VALID){
+				memset(defwan6_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN);
+				strncpy(defwan6_if_old, defwan_real, strlen(defwan_real));
+			}
+		}
+		zte_unpn_set();
+		if(atoi(xlat_enable) && actinfo->act_info.ip46flag == V6_VALID){
+			snprintf(buffer, sizeof(buffer),"ip route add default dev v4-%s", defwan_real);
+			system_cmd_ex(buffer);
+		}
+		net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END);
+	}
+}
+
+void check_wan_change(unsigned char ip46flag)
+{
+	if (ip46flag == V4_VALID || ip46flag == V46_VALID) {
+		char nv_ethwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+		char nv_wifiwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+		char ethwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+		char wifiwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+
+		snprintf(nv_ethwan, sizeof(nv_ethwan), "%s_ip", eth_wan);
+		cfg_get_item(nv_ethwan, ethwan_ip, sizeof(ethwan_ip));
+		snprintf(nv_wifiwan, sizeof(nv_wifiwan), "%s_ip", wifi_wan);
+		cfg_get_item(nv_wifiwan, wifiwan_ip, sizeof(wifiwan_ip));
+		if ((0 != strcmp(ethwan_ip, "0.0.0.0") && (0 != strcmp(ethwan_ip, "")))
+			|| (0 != strcmp(wifiwan_ip, "0.0.0.0") && (0 != strcmp(wifiwan_ip, ""))))
+			proc_wan_change_v4();
+	}
+	if (ip46flag == V6_VALID || ip46flag == V46_VALID) {
+		char nv_ethwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+		char nv_wifiwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+		char ethwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+		char wifiwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+
+		sprintf(nv_ethwan_ipv6, "%s_ipv6_ip", eth_wan);
+		cfg_get_item(nv_ethwan_ipv6, ethwan_ipv6, sizeof(ethwan_ipv6));
+		sprintf(nv_wifiwan_ipv6, "%s_ipv6_ip", wifi_wan);
+		cfg_get_item(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
+		if (((0 != strcmp(ethwan_ipv6, "::")) && (0 != strcmp(ethwan_ipv6, ""))) 
+			|| ((0 != strcmp(wifiwan_ipv6, "::")) && (0 != strcmp(wifiwan_ipv6, ""))))
+			proc_wan_change_v6();
+	}
+}
+
+void net_wan_deact_quick(int c_id, unsigned char ip46flag)
+{
+	char cmd[128] = {0};
+	char wan_name[NV_NAME_LEN] = {0};
+	char default_wan_name[NV_NAME_LEN] = {0};
+	char default_wan6_name[NV_NAME_LEN] = {0};
+	char tc_enable[4] = {0};
+	char wan_pri[32] = {0};
+	char pdp_ip6[IPV6ADDLEN_MAX] = {0};
+	char pdp_ip[IPV4ADDLEN_MAX] = {0};
+	int pri = 0;
+	int rt_num = 0;
+
+	cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri));
+	pri = atoi(wan_pri);
+	if(pri < 0 || pri > 65535)
+		return;
+	rt_num = pri*10 + c_id;
+	cfg_get_item("tc_enable", tc_enable, sizeof(tc_enable));
+	snprintf(wan_name,NV_NAME_LEN,	"%s%d", ps_wan, c_id);
+	slog(NET_PRINT, SLOG_NORMAL, "deact ifconfig wanname:%s!\n", wan_name);
+
+	//ifconfig wan down
+	snprintf(cmd, sizeof(cmd),"ifconfig %s down", wan_name);
+	system_cmd_ex(cmd);
+	//ifconfig ip
+	snprintf(cmd, sizeof(cmd),"ifconfig %s 0.0.0.0 down", wan_name);
+	system_cmd_ex(cmd);
+
+	cfg_get_item("default_wan_name", default_wan_name, sizeof(default_wan_name));
+	cfg_get_item("default_wan6_name", default_wan6_name, sizeof(default_wan6_name));
+	
+	if (ip46flag == V4_VALID || ip46flag == V46_VALID) {
+		snprintf(cmd, sizeof(cmd), "%s_ip", wan_name);
+		cfg_get_item(cmd, pdp_ip, sizeof(pdp_ip));
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_gw", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_pridns", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_secdns", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "ip rule del from %s table %d", pdp_ip, rt_num);
+		system_cmd_ex(cmd);
+		snprintf(cmd, sizeof(cmd), "ip route del default dev %s table %d", wan_name, rt_num);
+		system_cmd_ex(cmd);
+		if(strcmp(default_wan_name, wan_name) == 0){
+			//net_write_file("/proc/sys/net/ipv4/ip_forward", "0", 1);
+			snprintf(cmd, sizeof(cmd),"route del default dev %s", wan_name);
+			system_cmd_ex(cmd);
+			cfg_set("wan_ipaddr", "");
+			cfg_set("default_cid", "");
+			cfg_set("default_wan_name", "");
+			cfg_set("default_wan_rel", "");
+		}
+	}
+	if (ip46flag == V6_VALID || ip46flag == V46_VALID) {
+		snprintf(cmd, sizeof(cmd), "%s_ipv6_ip", wan_name);
+		cfg_get_item(cmd, pdp_ip6, sizeof(pdp_ip6));
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_ipv6_interface_id", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_ipv6_pridns_auto", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "%s_ipv6_secdns_auto", wan_name);
+		cfg_set(cmd, "");
+		snprintf(cmd, sizeof(cmd), "ip -6 rule del from %s table %d", pdp_ip6, rt_num);
+		system_cmd_ex(cmd);
+		snprintf(cmd, sizeof(cmd), "ip -6 route del default dev %s table %d", wan_name, rt_num);
+		system_cmd_ex(cmd);
+		if(strcmp(default_wan6_name, wan_name) == 0){
+			char br_ip6[IPV6ADDLEN_MAX] = {0};
+			
+			cfg_get_item("ipv6_br0_addr", br_ip6, sizeof(br_ip6));
+			net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "0", 1);
+			net_write_file("/proc/sys/net/ipv6/conf/all/proxy_ndp", "0", 1);
+			system_cmd_ex("ip -6 route del default");
+			snprintf(cmd, sizeof(cmd),"ip -6 addr del %s/64 dev br0", br_ip6);
+			system_cmd_ex(cmd);
+			system_cmd_ex("ip route del default");
+			system_cmd_ex("killall clatd");
+			snprintf(cmd, sizeof(cmd),"iptables -t nat -D POSTROUTING -o v4-%s -j MASQUERADE", wan_name);
+			system_cmd_ex(cmd);
+			{
+				char path_tmp[16] = {0};
+				char path[32] = {0};
+				
+				cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp));
+				snprintf(path, sizeof(path), "%s/radvd_%s.pid", path_tmp, wan_name);
+				kill_pid_by_path(path);
+			}
+			dhcp6s_down(0);
+			ndp_down(0);
+			cfg_set("ipv6_br0_addr", "");
+			cfg_set("ipv6_wan_ipaddr", "");
+			cfg_set("default_cid", "");
+			cfg_set("default_wan6_name", "");
+			cfg_set("default_wan6_rel", "");
+		}
+	}
+	if(atoi(tc_enable)){
+		snprintf(cmd, sizeof(cmd),"tc_tbf.sh down %d",c_id);
+		system_cmd_ex(cmd);
+	}
+	{
+		char cid[20] = {0};
+		cfg_get_item("default_cid", cid, sizeof(cid));
+		if(c_id == atoi(cid))
+			cfg_set("default_cid", "");
+	}
+	if(strcmp(default_wan_name, wan_name) == 0 || strcmp(default_wan6_name, wan_name) == 0){
+		net_write_file("/etc/resolv.conf", "", 0);
+		check_wan_change(ip46flag);
+	}
+}
+/**************************************************************************
+* º¯ÊýÃû³Æ£º pdp_act_proc
+* ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸¼¤»î½Ó¿Ú
+* ²ÎÊý˵Ã÷£º pdp_active_info(IN):PDP¼¤»îÐÅÏ¢
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£»
+* ½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸µÄ¼¤»î¼°ÏàÓ¦µÄÍøÂçÅäÖÃ
+**************************************************************************/
+int net_pdp_act_proc(struct pdp_active_info *actinfo)
+{
+	char char_cid[10] = {0};
+	char cmd[100] = {0};
+	char need_jilian[NV_NAME_LEN] = {0};
+	char psext_state[NV_NAME_LEN] = {0};
+	char prefix[IPV6ADDLEN_MAX] = {0};
+	int prefix_len = 0;
+	char quick_flag[4] = {0};
+	
+	cfg_get_item("quick_dial", quick_flag, sizeof(quick_flag));
+	slog(NET_PRINT, SLOG_NORMAL, "net_pdp_act_proc\n");
+	if (!actinfo || actinfo->act_info.ip46flag == V4V6_INVALID) {
+		softap_assert("ip46flag error");//klocwork
+		return 0;
+	}
+
+	if (0 == pdp_act_check(actinfo)) {
+		softap_assert("already act.");
+	}
+	set_pdp_mode(actinfo->c_id, actinfo->pdp_type);
+
+	set_pdp_act_type(actinfo->c_id, actinfo->act_info.ip46flag);
+
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		prefix_len = syscall(__NR_get_ipv6_prefix,(unsigned char)actinfo->c_id, prefix);
+		slog(NET_PRINT, SLOG_NORMAL, "pdp_wan_config prefix=%s len=%d \n", prefix, prefix_len);
+		if(prefix_len > 0)
+		{
+			char nv_name[NV_NAME_LEN] = {0};
+			char len_s[4] = {0};
+
+			snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_prefix_info", ps_wan, actinfo->c_id);
+			cfg_set(nv_name, prefix);
+			snprintf(len_s, sizeof(len_s), "%d", prefix_len);
+			snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_prefix_len", ps_wan, actinfo->c_id);
+			cfg_set(nv_name, len_s);
+		}
+	}
+	//¶ÔÓÚatserver´¥·¢µÄPDP¼¤»î£¬ÊÇÓÃÓÚÆÕͨÉÏÍâÍøÒµÎñµÄ£¬´æÔÚNATת»»
+	if (actinfo->pdp_type == PDP_NORMAL) {
+		snprintf(char_cid, sizeof(char_cid), "%d", actinfo->c_id);
+		cfg_set("default_cid", char_cid);
+		if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0))
+			pdp_wan_config_quick(actinfo, prefix, prefix_len);
+		else
+			pdp_wan_config(actinfo);
+		//cfg_set("ps_state", "working");
+	}
+	//¶ÔÓÚÍâºË´¥·¢µÄPDP¼¤»î£¬½øÐÐÇŽӻò¼¶Áª
+	else if (actinfo->pdp_type == PDP_EXT) {
+		//cp¼¶Áª£¬apÇŽÓ
+		if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0)){
+			pdp_direct_config_quick(actinfo, prefix, prefix_len);
+		}else{
+		cfg_get_item("need_jilian", need_jilian, sizeof(need_jilian));
+		if (0 == strcmp(need_jilian, "1"))
+			pdp_direct_config(actinfo);
+		else if (0 == strcmp(need_jilian, "0")) {
+			//sprintf(cmd, "/sbin/psext_updown.sh \"linkup\" \"%d\"", actinfo->c_id);
+			sprintf(cmd, "/sbin/psext_updown.sh linkup %d", actinfo->c_id);
+			zxic_system(cmd); //kw 3
+		} else
+			softap_assert("need_jilian=%s error", need_jilian);
+		}
+		/*¸ÃÎÊÌâÓÃÓÚUSB ÈȲå°Îʱ״̬±ê¼Ç£¬½öÔÚPDP¼¤»îÖ®ºó£¬
+		²Å¶ÔÈȲå°ÎÏûÏ¢½øÐд¦Àí*/
+		sprintf(psext_state, "ps_ext%d_pdpstate", actinfo->c_id);
+		cfg_set(psext_state, "working");
+
+	}
+	//±¾µØÓ¦ÓÃÉÏÍâÍøµÄPDP¼¤»î£¬ÈçVoLTEµÈ
+	else if (actinfo->pdp_type == PDP_LOCAL) {
+		if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0))
+			pdp_wan_config_quick(actinfo, prefix, prefix_len);
+		else
+			pdp_wan_config(actinfo);
+	} else if (actinfo->pdp_type == PDP_PPP) {
+		//sprintf(char_cid, "%d", actinfo->c_id);
+		//cfg_set("ppp_cid", char_cid);
+		pdp_ppp_config(actinfo);
+
+		cfg_set("ppp_pdpstate", "working");
+	} else {
+		softap_assert("pdp_type=%u error", actinfo->pdp_type);
+		return 0;
+	}
+
+	if (actinfo->pdp_type != PDP_NORMAL) 
+	{
+		net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END);		
+	}
+	
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	slog(NET_PRINT, SLOG_NORMAL, "net_pdp_act_proc success\n");
+	
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º pdp_deact_proc
+* ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸ȥ»î½Ó¿Ú
+* ²ÎÊý˵Ã÷£º c_id(IN):PDP¼¤»îc_id.
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£»
+½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸ȥ»î£»Ö§³Ö46µ¥Õ»È¥»î£¬ËùÒÔÈë²ÎÐèҪָʾ46Çé¿ö
+**************************************************************************/
+int net_pdp_deact_proc(int c_id, unsigned char ip46flag)
+{
+	char cmd[100] = {0};
+	char pdp_mode_nv[NV_NAME_LEN] = {0};
+	char pdp_mode[NV_NAME_LEN] = {0};
+	char psext_state[NV_NAME_LEN] = {0};
+	//char pppd_user_term[NV_NAME_LEN] = {0};
+	char quick_flag[4] = {0};
+	
+	cfg_get_item("quick_dial", quick_flag, sizeof(quick_flag));
+
+	openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON);
+
+	if (ip46flag == V4V6_INVALID) {
+		softap_assert("ip46flag=%u error", ip46flag);
+		return 0;
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc start!cid=%d,ip46flag=%u\n", c_id, ip46flag);
+
+	sprintf(pdp_mode_nv, "pdp_mode%d", c_id);
+	cfg_get_item(pdp_mode_nv, pdp_mode, sizeof(pdp_mode));
+
+	reset_pdp_mode(c_id);
+
+	closelog();
+
+	//ÍâºËpdpÈ¥»î,È¥ÇÅÈ¥¼¶Áª
+	if (0 == strcmp("bridge", pdp_mode)) {
+		if(quick_flag[0] == '1'){
+			net_br_deact_quick(c_id, ip46flag);
+		}else{
+		if (ip46flag == V4_VALID || ip46flag == V46_VALID) {
+			//sprintf(cmd, "/sbin/psext_updown.sh \"linkdown\" \"%d\"", c_id);
+			sprintf(cmd, "/sbin/psext_updown.sh linkdown %d", c_id);
+			zxic_system(cmd); //kw 3
+		}
+
+		if (ip46flag == V6_VALID || ip46flag == V46_VALID) {
+			memset(cmd, 0, sizeof(cmd));
+			//sprintf(cmd, "/sbin/psext_updown_ipv6.sh \"linkdown\" \"%d\"", c_id);
+			sprintf(cmd, "/sbin/psext_updown_ipv6.sh linkdown %d", c_id);
+			zxic_system(cmd);
+		}
+		}
+		sprintf(psext_state, "ps_ext%d_pdpstate", c_id);
+		cfg_set(psext_state, "dead");
+		slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n");
+
+		net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END);	
+		
+		return 1;
+	} else if (0 == strcmp("ppp", pdp_mode)) {
+		//if (ip46flag == V4_VALID || ip46flag == V46_VALID) { for ipv6
+#if 0
+			cfg_get_item("pppd_user_term", pppd_user_term, sizeof(pppd_user_term)); //¼ì²â¸ÃpdpÈ¥¼¤»îÊÇ·ñÊÇÓÉÖն˶ϿªpppÁ´½Ó·¢ÆðµÄ
+			if (strcmp(pppd_user_term,  "terminate") != 0) {
+				cfg_set("ppp_pdpstate", "dead");
+
+			} else {
+				cfg_set("ppp_pdpstate", "user_terminate");
+				cfg_set("pppd_user_term", "");
+			}
+#endif
+			//sprintf(cmd, "/sbin/ppp_updown.sh \"linkdown\" \"%d\"", c_id);
+			sprintf(cmd, "/sbin/ppp_updown.sh linkdown %d", c_id);
+			zxic_system(cmd);
+			cfg_set("ppp_pdpstate", "dead");
+
+		//}
+		slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n");
+
+		net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END);	
+		return 1;
+	}
+	//atserver pdpÈ¥»î ½«default_cidÖÿÕ
+	else if (0 == strcmp("gateway", pdp_mode)) {
+		//cfg_set("default_cid", "");
+		//cfg_set("ps_state", "dead");
+	}
+	if(quick_flag[0] == '1'){
+		net_wan_deact_quick(c_id, ip46flag);
+	}else{
+	if (ip46flag == V4_VALID || ip46flag == V46_VALID) {
+		//sprintf(cmd, "/sbin/wan_ipv4.sh \"linkdown\" \"pswan\" \"%d\"", c_id);
+		sprintf(cmd, "/sbin/wan_ipv4.sh linkdown pswan %d", c_id);
+		zxic_system(cmd);
+	}
+
+	if (ip46flag == V6_VALID || ip46flag == V46_VALID) {
+		memset(cmd, 0, sizeof(cmd));
+		//sprintf(cmd, "/sbin/wan_ipv6.sh \"linkdown\" \"pswan\" \"%d\"", c_id);
+		sprintf(cmd, "/sbin/wan_ipv6.sh linkdown pswan %d", c_id);
+		zxic_system(cmd);
+	}
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n");
+
+	net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END);	
+	return 1;
+}
+
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_connect_internet
+* ¹¦ÄÜÃèÊö£º webui·¢Ë͵ÄÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig up£¬²¢Æô¶¯ÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷Óô˽ӿÚǰ£¬ÐèÒª¼ì²âµ±Ç°É豸ÎïÀíͨ·ÒÑͨ£¬·ñÔò²»Ó¦¸Ãµ÷Óô˽ӿڣ»
+* Ö÷¿ØÄ£¿éÐèÒªÑÏ¿ØÖظ´µÄµ÷Óøýӿڣ¬ÒòΪÿµ÷ÓÃÒ»´Î¸Ã½Ó¿Ú£¬ÄÚ²¿½Ô»áÖØÐÂÖ´ÐÐÒ»´ÎÍêÕûµÄµØÖ··ÖÅäÁ÷³Ì£»
+**************************************************************************/
+int net_netdev_connect_internet(unsigned char netdev_id)
+{
+	char eth_type[NV_NAME_LEN] = {0};
+	char work_state[NV_NAME_LEN] = {0};
+	char eth_dev[NV_NAME_LEN] = {0};
+	char sw_name[NV_NAME_LEN] = {0};
+	char swport[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_connect_internet start! netdev_id=%u\n", netdev_id);
+	if (netdev_id == RJ45_WAN_DEV) {
+		ethwan_id = netdev_id;
+		pppoe_encrypt_code();
+		eth_connect();
+	} else if (netdev_id == WIFI_WAN_DEV) {
+		wifiwan_id = netdev_id;
+		wifi_connect();
+	} else if (netdev_id == RJ45_LAN_DEV) {
+		system("landev_updown.sh \"ethlan\" \"up\"");
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan connect end!\n");
+	} else if (netdev_id == WIFI_LAN_DEV) {
+		system("landev_updown.sh \"wifilan\" \"up\"");
+		slog(NET_PRINT, SLOG_NORMAL, "wifi as lan connect end!\n");
+	} else {
+		softap_assert("netdev_id=%d error", netdev_id);
+		return 0;
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_connect_internet success!\n");
+	closelog();
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_disconnect_internet
+* ¹¦ÄÜÃèÊö£º webui·¢Ë͵ĶϿªÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷Óô˽ӿÚ
+**************************************************************************/
+int net_netdev_disconnect_internet(unsigned char netdev_id)
+{
+	char eth_curtype[NV_NAME_LEN] = {0};
+	char eth_dev[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON);
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_disconnect_internet start! netdev_id=%u\n", netdev_id);
+	if (netdev_id == RJ45_WAN_DEV) {
+		ethwan_id = netdev_id;
+		//msg_timedel();
+		deletetimer(ethwan_id);
+		slog(NET_PRINT, SLOG_NORMAL, "diconnect ..... deletetimer.....");
+		cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype));
+		if (0 == strcmp(eth_curtype, "wan"))
+		{
+			system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+		}
+		else if (0 == strcmp(eth_curtype, "lan")) {
+			system("landev_updown.sh \"ethwan\" \"down\"");
+			slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan disconnect end!\n");
+		} else { //Ϊ·ÀÖ¹eth_curtypeÅжϳö´íËù×öµÄ¼æÈÝ
+			system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+			system("landev_updown.sh \"ethwan\" \"down\"");
+		}
+		vlan_config(RJ45_WAN_DEV, "rem");
+		cfg_set("rj45_state", "idle");
+	} else if (netdev_id == WIFI_WAN_DEV) {
+		wifiwan_id = netdev_id;
+		deletetimer(wifiwan_id);
+		system("wan_ipv4.sh \"linkdown\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"wifiwan\"");
+		cfg_set("wifi_state", "idle");
+	} else if (netdev_id == RJ45_LAN_DEV) {
+		system("landev_updown.sh \"ethlan\" \"down\"");
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan disconnect end!\n");
+	} else if (netdev_id == WIFI_LAN_DEV) {
+		system("landev_updown.sh \"wifilan\" \"down\"");
+		slog(NET_PRINT, SLOG_NORMAL, "wifi as lan disconnect end!\n");
+	} else {
+		softap_assert("netdev_id=%d error", netdev_id);
+		return 0;
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_disconnect_internet success!\n");
+	closelog();
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugin_proc
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸²åÈë,½Ó¿ÚÄÚ²¿¼ì²âÊÇ·ñÐèÒª½øÐÐ×Ô¶¯²¦ºÅ£¬ÈçÐèÒª£¬Ö´ÐеØÖ··ÖÅä¡¢×éÍøµÈÁ÷³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒÑͨ£¬¿ÉÒÔ½øÐÐIPÊý¾Ý°üµÄÊÕ·¢ÁË
+**************************************************************************/
+int net_netdev_plugin_proc(unsigned char netdev_id)
+{
+
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugin_proc start! netdev_id=%u\n", netdev_id);
+	openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON);
+	//USB½ö´æÔÚÓÚÄÚÍøÖÐ
+	if (netdev_id == USB_LAN_DEV) {
+		system("landev_updown.sh \"usblan\" \"up\"");
+		slog(NET_PRINT, SLOG_ERR, "usb as lan plugin end!\n");
+	}
+	//ÈȲå°Î½öÐ迼ÂÇ×Ô¶¯Ä£Ê½£¬²»Ð迼ÂÇÊÖ¹¤²¦ºÅµÄÁ¬½Ó
+	//¸Ã·Ö֧ͬʱ´¦ÀíÁËlan/wan/autoÈýÖÖÇé¿ö£¬RJ45_LAN_DEVÔÝʱÎÞ·¨Ê¹ÓÃ
+	else if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) {
+		ethwan_id = netdev_id;
+		ethwan_plugin();
+	} else if (netdev_id == WIFI_WAN_DEV) {
+		wifiwan_id = netdev_id;
+		wifi_plugin();
+	} else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) {
+		ethlan_plugin();
+	} else if (netdev_id == WIFI_LAN_DEV) {
+		system("landev_updown.sh \"wifilan\" \"up\"");
+		slog(NET_PRINT, SLOG_NORMAL, "wifi as lan plugin end!\n");
+	} else if (netdev_id == PS_EXT_DEV1) {
+		system("landev_updown.sh \"ps_ext1\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV2) {
+		system("landev_updown.sh \"ps_ext2\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV3) {
+		system("landev_updown.sh \"ps_ext3\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV4) {
+		system("landev_updown.sh \"ps_ext4\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV5) {
+		system("landev_updown.sh \"ps_ext5\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV6) {
+		system("landev_updown.sh \"ps_ext6\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV7) {
+		system("landev_updown.sh \"ps_ext7\" \"up\"");
+	} else if (netdev_id == PS_EXT_DEV8) {
+		system("landev_updown.sh \"ps_ext8\" \"up\"");
+	} else
+		slog(NET_PRINT, SLOG_NORMAL, "plugin netdev_id error!!! : netdev_id=%u\n", netdev_id);
+	//assert(0);
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugin_proc success!\n");
+	closelog();
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugout_proc
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸°Î³ö,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒѶϣ¬²»ÒªÔÙ½øÐÐIPÊý¾Ý°üÊÕ·¢
+**************************************************************************/
+int net_netdev_plugout_proc(unsigned char netdev_id)
+{
+	char eth_curtype[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON);
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugout_proc start! netdev_id=%u\n", netdev_id);
+	//ÄÚÍøÇŵãÈ¥³ý
+	if (netdev_id == USB_LAN_DEV) {
+		system("landev_updown.sh \"usblan\" \"down\"");
+		slog(NET_PRINT, SLOG_NORMAL, "usb as lan plugout end!\n");
+		return 1;
+	}
+	//Ðè񻂿·ÖÄÚÍâÍøÄ£Ê½
+	else if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) {
+		ethwan_id = netdev_id;
+		ethwan_plugout();
+	} else if (netdev_id == WIFI_WAN_DEV) {
+		wifiwan_id = netdev_id;
+		deletetimer(wifiwan_id);
+		system("wan_ipv4.sh \"linkdown\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"wifiwan\"");
+		cfg_set("wifi_state", "dead");
+
+	} else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) {
+		ethlan_plugout();
+	} else if (netdev_id == WIFI_LAN_DEV) {
+		system("landev_updown.sh \"wifilan\" \"down\"");
+		slog(NET_PRINT, SLOG_NORMAL, "wifi as lan plugout end!\n");
+	} else if (netdev_id == PS_EXT_DEV1) {
+		system("landev_updown.sh \"ps_ext1\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV2) {
+		system("landev_updown.sh \"ps_ext2\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV3) {
+		system("landev_updown.sh \"ps_ext3\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV4) {
+		system("landev_updown.sh \"ps_ext4\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV5) {
+		system("landev_updown.sh \"ps_ext5\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV6) {
+		system("landev_updown.sh \"ps_ext6\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV7) {
+		system("landev_updown.sh \"ps_ext7\" \"down\"");
+	} else if (netdev_id == PS_EXT_DEV8) {
+		system("landev_updown.sh \"ps_ext8\" \"down\"");
+	} else {
+		slog(NET_PRINT, SLOG_ERR, "plugout netdev_id error!!! : netdev_id=%u\n", netdev_id);
+		//assert(0);
+		return 0;
+	}
+	//wifi ifconfig downÓÉÆäÄ£¿é¸ºÔð£¬rj45 °Î³ýÉ豸Ïûʧ£¬ÓÉÇý¶¯¸ºÔð
+	//memset(cmd, 0, sizeof(cmd));
+	//sprintf(cmd, "ifconfig %s down" , wan_if);
+	//system(cmd);
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugout_proc success!\n");
+	closelog();
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º net_tc_control
+* ¹¦ÄÜÃèÊö£º Á÷Á¿¿ØÖÆ
+* ²ÎÊý˵Ã÷£º ÐèÒªÁ÷Á¿¼à¿ØµÄÉÏÏÂÐÐÁ¿£¬Êý¾Ý¿¨ÐèÒªÓÐcid£¬ufiģʽ²»ÐèÒª
+*            0±íʾ²»ÐèÒªÁ÷¿Ø
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º ¸øÐèÒªÁ÷Á¿¿ØÖƵÄÓ¦Óõ÷Óã¬ÈçÉÏÐÐÐèÒªÁ÷¿Ø£¬ÇëµÈÄÜÉÏÍâÍøºóÔÙµ÷Ó㬷ñÔòÎÞ·¨»ñÈ¡ÍâÍø¿Ú½øÐÐÁ÷¿Ø
+**************************************************************************/
+int net_tc_control(struct tc_control_info *tcinfo, int src_id)
+{
+	int ret = 0;
+	char cmd[100] = {0};
+	char up[NV_NAME_LEN]   = {0};
+	char down[NV_NAME_LEN] = {0};
+	char at_str[32] = {0}; 
+	
+	slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_tc_control start! c_id:%d, down:%u, up:%u\n \n", tcinfo->c_id, tcinfo->tc_downlink, tcinfo->tc_uplink);
+
+	cfg_set("tc_enable", "1");
+
+	/* Á÷Á¿Í³¼ÆÊÇÕë¶ÔByte£¬ËùÒÔÒª³ýÒÔ8 */
+	sprintf(up, "%d", (tcinfo->tc_uplink / 8));
+	cfg_set("tc_uplink", up);
+	sprintf(down, "%d", (tcinfo->tc_downlink) / 8);
+	cfg_set("tc_downlink", down);
+
+	//sprintf(cmd, "/sbin/tc_tbf.sh \"up\" \"%d\"", tcinfo->c_id);
+	sprintf(cmd, "/sbin/tc_tbf.sh up %d", tcinfo->c_id);
+	zxic_system(cmd);
+
+	if(src_id == MODULE_ID_AT_CTL)
+	{
+		sprintf(at_str, "\r\nOK\r\n");
+		send_rsp_str_to_farps(MODULE_ID_MAIN_CTRL, at_str, strlen(at_str));
+	}
+
+	return 1;
+}
+
+/*PPPÐÎ̬µÄPDP¼¤»î£¬ÔÝʱ½öÖ§³ÖIPV4*/
+int pdp_ppp_config(struct pdp_active_info *actinfo)
+{
+
+	char nv_ip[NV_NAME_LEN] = {0};
+	char nv_gw[NV_NAME_LEN] = {0};
+	char nv_pridns[NV_NAME_LEN] = {0};
+	char nv_secdns[NV_NAME_LEN] = {0};
+	char nv_ip6[NV_NAME_LEN] = {0};
+	char nv_pridns6[NV_NAME_LEN] = {0};
+	char nv_secdns6[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+
+	if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id);
+		cfg_set(nv_ip, actinfo->act_info.ip);
+		snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id);
+		cfg_set(nv_gw, actinfo->act_info.ip);
+		snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns, actinfo->act_info.pri_dns);
+		snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns, actinfo->act_info.sec_dns);
+
+		//sprintf(cmd, "/sbin/ppp_updown.sh \"linkup\" \"%d\"", actinfo->c_id);
+		//sprintf(cmd, "/sbin/ppp_updown.sh linkup %d", actinfo->c_id);
+		//zxic_system(cmd);
+	} //else
+		//softap_assert("ip46flag=%u error", actinfo->act_info.ip46flag);
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_pppv6_ip", ps_wan, actinfo->c_id);
+		cfg_set(nv_ip6, actinfo->act_info.ip6);
+		snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id);
+		save_interface_id(nv_ip6, actinfo->act_info.ip6);
+		snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns6, actinfo->act_info.pri_dns6);
+		snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns6, actinfo->act_info.sec_dns6);
+	}
+	sprintf(cmd, "/sbin/ppp_updown.sh linkup %d", actinfo->c_id);
+	zxic_system(cmd);
+	return 1;
+}
+
+/*NORMALÐÎ̬µÄPDP¼¤»îµÄ˫ջµØÖ·±£´æ£¬²¢´¥·¢ÍâÍø¿ÚµØÖ·ÅäÖýű¾*/
+int pdp_wan_config(struct pdp_active_info *actinfo)
+{
+	char nv_ip[NV_NAME_LEN] = {0};
+	char nv_gw[NV_NAME_LEN] = {0};
+	char nv_pridns[NV_NAME_LEN] = {0};
+	char nv_secdns[NV_NAME_LEN] = {0};
+	char nv_ip6[NV_NAME_LEN] = {0};
+	//char nv_gw6[NV_NAME_LEN] = {0};
+	char nv_pridns6[NV_NAME_LEN] = {0};
+	char nv_secdns6[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	FILE *fpv4 = NULL;
+	FILE *fpv6 = NULL;
+	
+	if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id);
+		cfg_set(nv_ip, actinfo->act_info.ip);
+		snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id);
+		cfg_set(nv_gw, actinfo->act_info.ip);
+		snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns, actinfo->act_info.pri_dns);
+		snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns, actinfo->act_info.sec_dns);
+
+		//sprintf(cmd, "/sbin/wan_ipv4.sh \"linkup\" \"pswan\" \"%d\"", actinfo->c_id);
+		sprintf(cmd, "/sbin/wan_ipv4.sh linkup pswan %d", actinfo->c_id);
+		//zxic_system(cmd);
+		fpv4 = popen(cmd, "r");
+	}
+
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id);
+		//cfg_set(nv_ip6, actinfo->act_info.ip6);
+		save_interface_id(nv_ip6, actinfo->act_info.ip6);
+		//snprintf(nv_gw6, sizeof(nv_gw6), "%s%d_ipv6_gw", nv_pswan, actinfo->c_id);
+		//cfg_set(nv_gw6, actinfo->act_info.gateway6);
+		snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns6, actinfo->act_info.pri_dns6);
+		snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns6, actinfo->act_info.sec_dns6);
+		memset(cmd, 0, sizeof(cmd));
+		//sprintf(cmd, "/sbin/wan_ipv6.sh \"linkup\" \"pswan\" \"%d\"", actinfo->c_id);
+		sprintf(cmd, "/sbin/wan_ipv6.sh linkup pswan %d", actinfo->c_id);
+		//zxic_system(cmd);
+		fpv6 = popen(cmd, "r");
+	}
+	if(fpv4 != NULL)
+		pclose(fpv4);
+	if(fpv6 != NULL)
+		pclose(fpv6);
+	return 1;
+}
+
+/*ÇŽÓÀà×éÍøÅäÖã¬CP²àÓÉÓÚPS²»ÊDZê×¢µÄlinuxÒÔÌ«Íø¿ÚÐÎ̬£¬ËùÒÔÐèÒª½øÐж¨ÖÆÂ·ÓÉ£¬ÒÔʵÏÖÍø¿Ú¹ØÁª£»AP²àÖ±½Óbr0¼´¿É*/
+int pdp_direct_config(struct pdp_active_info *actinfo)
+{
+	char nv_ip[NV_NAME_LEN] = {0};
+	char nv_gw[NV_NAME_LEN] = {0};
+	char nv_pridns[NV_NAME_LEN] = {0};
+	char nv_secdns[NV_NAME_LEN] = {0};
+	char nv_pridns6[NV_NAME_LEN] = {0};
+	char nv_secdns6[NV_NAME_LEN] = {0};
+	char nv_ip6[NV_NAME_LEN] = {0};
+	//char nv_gw6[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	FILE *fpv4 = NULL;
+	FILE *fpv6 = NULL;
+	
+	system("rm /etc_rw/resolv.conf");
+	
+	if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip, sizeof(nv_ip), "%s%d_pdp_ip", ps_wan, actinfo->c_id);
+		cfg_set(nv_ip, actinfo->act_info.ip);
+		snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns, actinfo->act_info.pri_dns);
+		snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns, actinfo->act_info.sec_dns);
+		snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id);
+		//Óû§ÅäÖþ²Ì¬gw
+		if (0 != strcmp(actinfo->act_info.gateway, "")) {
+			cfg_set(nv_gw, actinfo->act_info.gateway);
+		}
+		//sprintf(cmd, "/sbin/psext_updown.sh \"linkup\" \"%d\"", actinfo->c_id);
+		sprintf(cmd, "/sbin/psext_updown.sh linkup %d", actinfo->c_id);
+		//zxic_system(cmd);
+		fpv4 = popen(cmd, "r");
+	}
+
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id);
+		//cfg_set(nv_ip6, actinfo->act_info.ip6);
+		save_interface_id(nv_ip6, actinfo->act_info.ip6);
+		//snprintf(nv_gw6, sizeof(nv_gw6), "%s%d_ipv6_gw", nv_pswan, actinfo->c_id);
+		//cfg_set(nv_gw6, actinfo->act_info.gateway6);
+		snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_pridns6, actinfo->act_info.pri_dns6);
+		snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id);
+		cfg_set(nv_secdns6, actinfo->act_info.sec_dns6);
+		memset(cmd, 0, sizeof(cmd));
+		//sprintf(cmd, "/sbin/psext_updown_ipv6.sh \"linkup\" \"%d\"", actinfo->c_id);
+		sprintf(cmd, "/sbin/psext_updown_ipv6.sh linkup %d", actinfo->c_id);
+		//zxic_system(cmd);
+		fpv6 = popen(cmd, "r");
+	}
+	if(fpv4 != NULL)
+		pclose(fpv4);
+	if(fpv6 != NULL)
+		pclose(fpv6);
+	return 1;
+}
+
+//±£´æPDP¼¤»îµÄÓû§Òâͼ£¬ÒÔ±ãPDPÈ¥»îʱÄܹ»×¼È·ÊÍ·ÅÏà¹ØÍøÂç×ÊÔ´
+void set_pdp_mode(int c_id, unsigned char pdp_type)
+{
+	char pdp_mode[NV_NAME_LEN] = {0};
+
+	sprintf(pdp_mode, "pdp_mode%d", c_id);
+	if (pdp_type == PDP_NORMAL)
+		cfg_set(pdp_mode, "gateway");
+	else if (pdp_type == PDP_EXT)
+		cfg_set(pdp_mode, "bridge");
+	else if (pdp_type == PDP_LOCAL)
+		cfg_set(pdp_mode, "local");
+	else if (pdp_type == PDP_PPP)
+		cfg_set(pdp_mode, "ppp");
+	else
+		softap_assert("pdp_type=%u error", pdp_type);
+}
+
+void reset_pdp_mode(int c_id)
+{
+
+	char pdp_mode[NV_NAME_LEN] = {0};
+
+	sprintf(pdp_mode, "pdp_mode%d", c_id);
+
+	cfg_set(pdp_mode, "");
+
+}
+
+//ÉèÖÃPDP¼¤»îµÄ˫ջ֧³ÖÇé¿ö£¬ÒÔ±ãÉèÖÃNORMALÍâÍø¿ÚµÄDNSʱʹÓã»
+void set_pdp_act_type(int c_id, unsigned char ip46flag)
+{
+	char pdp_act_type[NV_NAME_LEN] = { 0 };
+	sprintf(pdp_act_type, "pdp_act_type%d", c_id);
+
+	if (ip46flag == V4_VALID)
+		cfg_set(pdp_act_type, "IPv4");
+	else if (ip46flag == V6_VALID)
+		cfg_set(pdp_act_type, "IPv6");
+	else if (ip46flag == V46_VALID)
+		cfg_set(pdp_act_type, "IPv4v6");
+	else
+		softap_assert("ip46flag=%u error", ip46flag);
+}
+
+void vlan_config(unsigned int sw_type, char* act)
+{
+	char dev_name[NV_NAME_LEN] = {0};
+	char eth_lan[NV_NAME_LEN] = {0};
+	char sw_name[NV_NAME_LEN] = {0};
+	char swport[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	char* str_point = NULL;
+
+	if (sw_type == RJ45_WAN_DEV) {
+		cfg_get_item("ethwan", dev_name, sizeof(dev_name));
+	} else {
+		cfg_get_item("ethlan", dev_name, sizeof(dev_name));
+	}
+	str_point = strchr(dev_name, '.');
+	if (str_point == NULL)
+		return;
+	if (0 == strcmp(act, "add")) {
+		strncpy(swport, str_point + 1, sizeof(swport)-1);
+		strncpy(sw_name, dev_name, str_point - dev_name);
+		sw_name[str_point - dev_name + 1] = '\0';
+		sprintf(cmd, "/sbin/vconfig add %s %s", sw_name, swport);
+		zxic_system(cmd);
+		memset(cmd, 0x00, sizeof(cmd));
+		sprintf(cmd, "/sbin/vconfig set_flag %s 1 1", dev_name);
+		zxic_system(cmd);
+	} else {
+		sprintf(cmd, "/sbin/vconfig rem %s", dev_name);
+		zxic_system(cmd);
+	}
+}
+void ethwan_plugin()
+{
+	char eth_dialmode[NV_NAME_LEN] = {0};
+	char eth_type[NV_NAME_LEN] = {0};
+	char ethwan_name[NV_NAME_LEN] = {0};
+	char rj45_pluginstate[NV_NAME_LEN] = {0};
+	int plugstate = 0;
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	cfg_get_item("ethwan_dialmode", eth_dialmode, sizeof(eth_dialmode));
+	cfg_get_item("eth_type", eth_type, sizeof(eth_type));
+	cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name));
+	
+	if (0 == strcmp(eth_type, "auto") || 0 == strcmp(eth_type, "")) {
+		cfg_set("rj45_state", "idle");
+		cfg_set("eth_curtype", "");
+		vlan_config(RJ45_WAN_DEV, "add");
+		if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+		{//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏÂ
+			creattimer(&ethwan_id);
+		}
+		system("auto_dial.sh \"ethwan\"");
+	} else if (0 == strcmp(eth_type, "wan")) {
+		cfg_set("eth_curtype", "wan");
+		if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+		{
+			set_ethwan_port_mode(1);
+		}
+		
+		vlan_config(RJ45_WAN_DEV, "add");
+		cfg_set("rj45_state", "idle");
+		if (0 == strcmp(eth_dialmode, "auto") || 0 == strcmp(eth_dialmode, "ondemand")) {
+			cfg_set("rj45_state", "connect");
+			if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+			{//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏÂ
+				creattimer(&ethwan_id);
+			}
+			system("wan_ipv4.sh \"linkup\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkup\" \"ethwan\"");
+		}
+	} else if (0 == strcmp(eth_type, "lan")) {
+		cfg_set("eth_curtype", "lan");
+		if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+		{
+			set_ethwan_port_mode(0);
+			cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate));
+			plugstate = atoi(rj45_pluginstate);
+			if((plugstate & RJ45_LAN_IN)  == 0)
+			{
+				vlan_config(RJ45_LAN_DEV, "add");
+				system("landev_updown.sh \"ethlan\" \"up\"");
+				cfg_set("wanport3_in_lan", "1");
+			}
+		}
+		else
+		{
+			system("landev_updown.sh \"ethwan\" \"up\"");
+		}
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugin end!\n");
+	}
+
+}
+void ethlan_plugin()
+{
+	char lanflag[8] = {0};
+	char ethwan_name[NV_NAME_LEN] = {0};
+
+	cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name));
+	cfg_get_item("wanport3_in_lan", lanflag, sizeof(lanflag));
+	if(strchr(ethwan_name, '.') != NULL && strcmp(lanflag, "1") == 0)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+	{//switchÐÎ̬ÇÒwan¿Ú¶ÔÓ¦port3ÒѾ­¼ÓÈëvlan100,¼´eth0.100ÒѾ­´´½¨ÇÒ¹ÒÔÚbr0ÏÂ
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 eth0.100 has been created and mounted to br0!\n");
+		return;
+	}
+	
+	vlan_config(RJ45_LAN_DEV, "add");
+	system("landev_updown.sh \"ethlan\" \"up\"");
+	slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugin end!\n");
+}
+
+void ethwan_plugout()
+{
+	char eth_curtype[NV_NAME_LEN] = {0};
+	char cmd[100] = {0};
+	char ethwan_name[32] = {0};
+	char rj45_pluginstate[NV_NAME_LEN] = {0};
+	int plugstate = 0;
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	//msg_timedel();
+	system("killall eth_auto_connect");
+	deletetimer(ethwan_id);
+	slog(NET_PRINT, SLOG_NORMAL, "plugout ..... deletetimer.....");
+	cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype));
+	cfg_set("eth_curtype", "");
+	
+	cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name));
+
+	if (0 == strcmp(eth_curtype, "wan")) {
+		system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+	} else if (0 == strcmp(eth_curtype, "lan")) {	
+		//switchÐÎ̬´ËʱûÓÐeth0.200Íø¿Ú
+		if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+		{
+			cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate));
+			plugstate = atoi(rj45_pluginstate);
+			if((plugstate & RJ45_LAN_IN)  == 0)
+			{
+				system("landev_updown.sh \"ethlan\" \"down\"");
+				vlan_config(RJ45_LAN_DEV, "rem");
+				cfg_set("wanport3_in_lan", "0");
+			}
+		}
+		else
+		{
+			system("landev_updown.sh \"ethwan\" \"down\"");			
+		}
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugout end!\n");
+	} else {
+		system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+		system("landev_updown.sh \"ethwan\" \"down\"");
+	}
+
+	cfg_set("rj45_state", "dead");
+	vlan_config(RJ45_WAN_DEV, "rem");
+	if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+	{
+		set_ethwan_port_mode(1);	//½«switchµÄwan¿Úport3»¹Ô­³Éwan£¬·ñÔòÏ´βåÈëport3¿ÉÄÜ»¹ÊÇlan¿Ú
+	}
+}
+void ethlan_plugout()
+{
+	char lanflag[8] = {0};
+	char ethwan_name[NV_NAME_LEN] = {0};
+
+	cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name));
+	cfg_get_item("wanport3_in_lan", lanflag, sizeof(lanflag));
+	if(strchr(ethwan_name, '.') != NULL && strcmp(lanflag, "1") == 0)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+	{//switchÐÎ̬ÇÒwan¿Ú¶ÔÓ¦port3ÒѾ­¼ÓÈëvlan100,¼´eth0.100Ï»¹ÓÐport3¶Ë¿Ú£¬ËùÒÔ»¹²»ÄÜɾ³ýeth0.100
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 eth0.100 has been created and mounted to br0!\n");
+		return;
+	}
+	
+	system("landev_updown.sh \"ethlan\" \"down\"");
+	vlan_config(RJ45_LAN_DEV, "rem");
+	slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugout end!\n");
+}
+
+void wifi_plugin()
+{
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	cfg_set("wifi_state", "idle");
+	creattimer(&wifiwan_id);
+	system("wan_ipv4.sh \"linkup\" \"wifiwan\"");
+	if(atoi(wbwanv6_enable) == 1)
+		system("wan_ipv6.sh \"linkup\" \"wifiwan\"");
+}
+
+
+/*rj45 ÍâÍø¿Úʱ£¬¸ù¾Ýµ±Ç°×´Ì¬£¬ÈôΪworking or init or nullÔòÏÈlinkdown£¬É±ËÀÏà¹Ø½ø³Ì£¬È»ºóÆôÓã»ÈôΪdeadÔòÖ±½ÓÆôÓÃ*/
+void eth_connect()
+{
+	char ethwan_name[NV_NAME_LEN] = {0};
+	char eth_curtype[NV_NAME_LEN] = {0};
+	char work_state[NV_NAME_LEN] = {0};
+	//rj45Ö§³Öwan/lan¹¦ÄÜ£¬¿ÉÑ¡Ôñ³ÉΪÍâÍø¿Ú»òÄÚÍø¿Ú
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	vlan_config(RJ45_WAN_DEV, "add");
+	cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype));
+	cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name));
+	if (0 == strcmp(eth_curtype, "lan")) {
+		system("landev_updown.sh \"ethwan\" \"up\"");
+		slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan connect end!\n");
+	} else { // ĬÈÏ×÷Ϊwan¿Ú´¦Àí
+		cfg_get_item("rj45_state", work_state, sizeof(work_state));
+		//work_state=deadÔòµ±Ç°´¦ÓÚ¶Ï¿ª×´Ì¬£¬Ö±½Ólinkup£¬ÆäËû×´¿öÏÈlinkdown
+		if (0 == strcmp(work_state, "connect") || 0 == strcmp(work_state, "working")) {
+			system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+			cfg_set("rj45_state", "connect");
+			if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+			{//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏÂ
+				creattimer(&ethwan_id);
+			}
+			system("wan_ipv4.sh \"linkup\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkup\" \"ethwan\"");
+		} else if (0 == strcmp(work_state, "idle")) {
+			cfg_set("rj45_state", "connect");
+			if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy	
+			{//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏÂ
+				creattimer(&ethwan_id);
+			}
+			system("wan_ipv4.sh \"linkup\" \"ethwan\"");
+			if(atoi(wbwanv6_enable) == 1)
+				system("wan_ipv6.sh \"linkup\" \"ethwan\"");
+		} else if (0 == strcmp(work_state, "dead") || 0 == strcmp(work_state, ""))
+			return;
+		else
+			softap_assert("rj45_state=%s error", work_state);
+
+	}
+
+}
+
+//wifi stationÍâÍø¿ÚµÄµØÖ··ÖÅäÇëÇóÁ÷³Ì£¬Èô֮ǰÒѾ­´¦ÓÚworking̬£¬ÐèÒªÏÈÇå³ýËùÓÐ×ÊÔ´
+void wifi_connect()
+{
+	char work_state[NV_NAME_LEN] = {0};
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	cfg_get_item("wifi_state", work_state, sizeof(work_state));
+	if (0 == strcmp(work_state, "connect") || 0 == strcmp(work_state, "working")) {
+		system("wan_ipv4.sh \"linkdown\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"wifiwan\"");
+		cfg_set("wifi_state", "connect");
+		creattimer(&wifiwan_id);
+		system("wan_ipv4.sh \"linkup\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkup\" \"wifiwan\"");
+	} else {
+		cfg_set("wifi_state", "connect");
+		creattimer(&wifiwan_id);
+		system("wan_ipv4.sh \"linkup\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkup\" \"wifiwan\"");
+	}
+}
+
+int pdp_act_check(struct pdp_active_info *actinfo)
+{
+	char ps_ip[32] = {0};
+	char ps_ip6[64] = {0};
+	char nv_ip[NV_NAME_LEN] = {0};
+	char nv_ip6[NV_NAME_LEN] = {0};
+	if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id);
+		cfg_get_item(nv_ip, ps_ip, sizeof(ps_ip));
+		if (0 != strcmp(ps_ip, "0.0.0.0") && (0 != strcmp(ps_ip, ""))) {
+			slog(NET_PRINT, SLOG_ERR, "pdp_act_init: already act ip=%s", ps_ip); //cov m
+			return 0;
+		}
+	}
+	/*if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID)
+	{
+	    sprintf(nv_ip6,"ps%d_ipv6_ip", actinfo->c_id);
+	    cfg_get_item(nv_ip6, ps_ip6, sizeof(ps_ip6));
+	    if ((0 != strcmp(ps_ip6, "::")) && (0 != strcmp(ps_ip6, "")))
+	    {
+	        return 0;
+	    }
+	}*/
+	return 1;
+}
+
+
+void set_def_wan(char *wanif, char *wantype)
+{
+	char cmd_test[200] = {0};
+
+	cfg_set("default_wan_name", wanif);
+	cfg_set("default_wan_rel", wantype);
+	//if(0 == strncmp(wanif,"ps",2))
+	//    cfg_set("wan_name", wanif);
+
+	slog(NET_PRINT, SLOG_NORMAL, "set default_wan_name = %s \n", wanif);
+	//Èç¹ûĬÈÏÍâÍø¿ÚÊǶÔЭÒéÕ»µÄ£¬ÐèÒª½«Íø¿ÚÃû´«µÝ¸øÄÚºËʵÏÖ¿ìËÙת·¢Æ½Ì¨»°
+	if (strncmp(wanif, ps_wan, strlen(ps_wan)) == 0) {
+		memset(cmd_test, 0, sizeof(cmd_test));
+		sprintf(cmd_test, "echo %s > /proc/net/ps_name", wanif);
+		system_cmd_ex(cmd_test);
+	}
+}
+
+void set_def_wan6(char *wanif, char *wantype)
+{
+	//char cmd_test[200] = {0};
+
+	cfg_set("default_wan6_name", wanif);
+	cfg_set("default_wan6_rel", wantype);
+	//if(0 == strncmp(wanif,"ps",2))
+	//    cfg_set("wan_name6", wanif);
+	slog(NET_PRINT, SLOG_NORMAL, "set default_wan6_name = %s, default_wan6_rel = %s \n", wanif, wantype);
+	//sprintf(cmd_test,"echo test: set default_wan6_name = %s, default_wan6_rel = %s >> /mnt/jffs2/te.log ", wanif, wantype);
+	//system_cmd_ex(cmd_test);
+}
+
+/*set dns in resolv.conf */
+void defwan_set(char *wanif)
+{
+	if (0 == strcmp(wanif, eth_wan))
+		system("defwan_set.sh \"ethwan\"");
+	else if (0 == strcmp(wanif, wifi_wan))
+		system("defwan_set.sh \"wifiwan\"");
+	else
+		system("defwan_set.sh \"pswan\"");
+}
+
+void ddns_set(void)
+{
+	char ddns_enable[NV_NAME_LEN] = {0};
+	char ddns_mode[NV_NAME_LEN] = {0};
+	cfg_get_item("DDNS_Enable", ddns_enable, sizeof(ddns_enable));
+	cfg_get_item("DDNS_Mode", ddns_mode, sizeof(ddns_mode));
+
+	if (0 == strcmp(ddns_enable, "1") && 0 == strcmp(ddns_mode, "auto"))
+		system_cmd_ex("ddns.sh");
+}
+
+/*
+     deal with msg  MSG_CMD_NET_WAN4_CHANGE
+     choose the largest xxxwan_priority in wan who is up
+     set default_wan nv
+     if changed then reset firewall
+*/
+void proc_wan_change_v4(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 start!\n");
+	char wan_pri[32] = {0};
+	char cid[20] = {0};
+	int defwan_pri = 0;
+	int pri = 0;
+	char nv_pswan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char nv_usbwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char nv_ethwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char nv_wifiwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char pswan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	//char usbwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char ethwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char wifiwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char defwan_if[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char defwan_real[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char ethwan_actprotl[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	int defwan_change = 0;
+	struct default_dev_info defwan_dev_info;
+	defwan_dev_info.ip46flag = V4_VALID;
+
+	//sprintf(nv_usbwan,"%s_ip", usb_wan);
+	//cfg_get_item(nv_usbwan, usbwan_ip, sizeof(usbwan_ip));
+	//¶ÔÓÚswÍø¿Ú£¬ethwanµÄÉèÖÃÊÇÔÚÈȲ岥ʱÉèÖõģ¬ÔÚzte_routerÆô¶¯£¬
+	//³õʼ»¯eth_wanʱ£¬ÓпÉÄÜÉÐδÍê³É¸ÃÉèÖã¬Òò´ËÐèÒªÖØÐ»ñÈ¡É豸Ãû
+	cfg_get_item("ethwan", eth_wan, sizeof(eth_wan));
+	snprintf(nv_ethwan, sizeof(nv_ethwan), "%s_ip", eth_wan);
+	cfg_get_item(nv_ethwan, ethwan_ip, sizeof(ethwan_ip));
+	snprintf(nv_wifiwan, sizeof(nv_wifiwan), "%s_ip", wifi_wan);
+	cfg_get_item(nv_wifiwan, wifiwan_ip, sizeof(wifiwan_ip));
+	//cfg_get_item("wlan0_ip", wifiwan_ip, sizeof(wifiwan_ip));//wlan0ÊÊÅä
+
+	cfg_get_item("default_cid", cid, sizeof(cid));
+	if (0 != strcmp(cid, "")) {
+		snprintf(nv_pswan, sizeof(nv_pswan), "%s%s_ip", ps_wan, cid);
+		cfg_get_item(nv_pswan, pswan_ip, sizeof(pswan_ip));
+		if (0 != strcmp(pswan_ip, "0.0.0.0") && (0 != strcmp(pswan_ip, ""))) {
+			memset(wan_pri, 0, sizeof(wan_pri));
+			cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri));
+			pri = atoi(wan_pri);
+			if (pri > defwan_pri) {
+				defwan_pri = pri;
+				snprintf(defwan_if, sizeof(defwan_if), "%s%s", ps_wan, cid);
+				strcpy(defwan_real, defwan_if);
+				strcpy(defwan_dev_name, ps_wan);
+			}
+		}
+	}
+	if (0 != strcmp(ethwan_ip, "0.0.0.0") && (0 != strcmp(ethwan_ip, ""))) {
+		memset(wan_pri, 0, sizeof(wan_pri));
+		cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri));
+		pri = atoi(wan_pri);
+		if (pri > defwan_pri) {
+			defwan_pri = pri;
+			cfg_get_item("eth_curmode", ethwan_actprotl, sizeof(ethwan_actprotl));
+
+			if (0 == strcmp(ethwan_actprotl, "pppoe"))
+				strcpy(defwan_real, "ppp0");
+			else
+				strcpy(defwan_real, eth_wan);
+			strcpy(defwan_if, eth_wan);
+			strcpy(defwan_dev_name, eth_wan);
+		}
+	}
+
+	if (0 != strcmp(wifiwan_ip, "0.0.0.0") && (0 != strcmp(wifiwan_ip, ""))) {
+		memset(wan_pri, 0, sizeof(wan_pri));
+		cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri));
+		pri = atoi(wan_pri);
+		if (pri > defwan_pri) {
+			defwan_pri = pri;
+			strcpy(defwan_if, wifi_wan);
+			strcpy(defwan_real, wifi_wan);
+			strcpy(defwan_dev_name, wifi_wan);
+		}
+	}
+
+	//½«µ±Ç°ÓÐÐ§Íø¿ÚÖÐÓÅÏȼ¶×î¸ßµÄÉèÖÃΪȱʡÍâÍø¿Ú
+	set_def_wan(defwan_if, defwan_real);
+
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 old:%s, now:%s! \n", defwan_if_old, defwan_real);
+
+	//½«È±Ê¡ÍâÍø¿ÚµÄdev_id·¢Ë͸øÖ÷¿Ø
+	//if (strlen(defwan_dev_name) == 0 || 0 != strcmp(defwan_if_old, defwan_real))
+	{
+		defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name);
+
+		net_default_wan_proc(&defwan_dev_info);
+
+		//char tmp_name[20]= {0};
+		//sprintf(tmp_name,"zte_blc");
+	}
+	//dns_set(defwan_if);
+
+	if (0 == strlen(defwan_real)) {
+		slog(NET_PRINT, SLOG_ERR, "proc_wan_change_v4 defwan_if not selected! \n");
+		net_sendmsg_2_atctl(atoi(cid), V4_VALID, MSG_CMD_LINKUP_END);
+		return;
+	}
+
+	if (strcmp(defwan_if_old, defwan_real) != 0)
+		defwan_change = 1;
+
+	//Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ
+	if (defwan_change)
+		system_cmd_ex("nat.sh");
+	defwan_set(defwan_if);
+
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 data ok, defwan_change:%d \n", defwan_change);
+
+	//ȱʡÍâÍø¿Ú·¢Éú±ä»¯ÔòÖØÉènatºÍfilter
+	if (defwan_change) {
+		zte_router_init();
+		//dns_set(defwan_if);
+		memset(defwan_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN);
+		strncpy(defwan_if_old, defwan_real, strlen(defwan_real));
+	}
+	zte_unpn_set();
+	ddns_set();
+
+	net_sendmsg_2_atctl(atoi(cid), V4_VALID, MSG_CMD_LINKUP_END);
+	
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 end \n");
+}
+
+/*
+     deal with msg  MSG_CMD_NET_WAN6_CHANGE
+     choose the largest xxxwan_priority from the up-wans
+     set default_wan nv
+     if changed then reset firewall
+*/
+void proc_wan_change_v6(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 start!\n");
+	char cid[20] = {0};
+	char wan_pri[32] = {0};
+	int defwan_pri = 0;
+	int pri = 0;
+	char nv_pswan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char nv_ethwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char nv_wifiwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char pswan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+	//char usbwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+	char ethwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+	char wifiwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0};
+	char defwan_if_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char defwan_real_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0};
+	char ethwan_actprotl[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+	struct default_dev_info defwan_dev_info;
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	defwan_dev_info.ip46flag = V6_VALID;
+
+	cfg_get_item("ethwan", eth_wan, sizeof(eth_wan));
+	sprintf(nv_ethwan_ipv6, "%s_ipv6_ip", eth_wan);
+	//cfg_get_item("usb0_ipv6_ipaddr", usbwan_ipv6, sizeof(usbwan_ipv6));
+
+	cfg_get_item(nv_ethwan_ipv6, ethwan_ipv6, sizeof(ethwan_ipv6));
+	sprintf(nv_wifiwan_ipv6, "%s_ipv6_ip", wifi_wan);
+	cfg_get_item(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
+
+	cfg_get_item("default_cid", cid, sizeof(cid));
+	if (0 != strcmp(cid, "")) {
+		snprintf(nv_pswan_ipv6, sizeof(nv_pswan_ipv6), "%s%s_ipv6_ip", ps_wan, cid);
+		cfg_get_item(nv_pswan_ipv6, pswan_ipv6, sizeof(pswan_ipv6));
+		if ((0 != strcmp(pswan_ipv6, "::")) && (0 != strcmp(pswan_ipv6, ""))) {
+			memset(wan_pri, 0, sizeof(wan_pri));
+			cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri));
+
+			pri = atoi(wan_pri);
+			if (pri > defwan_pri) {
+				defwan_pri = pri;
+				snprintf(defwan_if_ipv6, sizeof(defwan_if_ipv6), "%s%s", ps_wan, cid);
+				strcpy(defwan_real_ipv6, defwan_if_ipv6);
+				strcpy(defwan_dev_name, ps_wan);
+			}
+		}
+	}
+	if ((0 != strcmp(ethwan_ipv6, "::")) && (0 != strcmp(ethwan_ipv6, ""))) {
+		memset(wan_pri, 0, sizeof(wan_pri));
+		cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri));
+
+		pri = atoi(wan_pri);
+		if (pri > defwan_pri) {
+			defwan_pri = pri;
+			cfg_get_item("eth_curmode", ethwan_actprotl, sizeof(ethwan_actprotl));
+
+			if (0 == strcmp(ethwan_actprotl, "pppoe"))
+				strcpy(defwan_real_ipv6, "ppp0");
+			else
+				strcpy(defwan_real_ipv6, eth_wan);
+			strcpy(defwan_if_ipv6, eth_wan);
+			strcpy(defwan_dev_name, eth_wan);
+			cfg_set("eth_act_type", "IPv4v6");
+		}
+	}
+
+	if ((0 != strcmp(wifiwan_ipv6, "::")) && (0 != strcmp(wifiwan_ipv6, ""))) {
+		memset(wan_pri, 0, sizeof(wan_pri));
+		cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri));
+
+		pri = atoi(wan_pri);
+		if (pri > defwan_pri) {
+			defwan_pri = pri;
+			strcpy(defwan_if_ipv6, wifi_wan);
+			strcpy(defwan_real_ipv6, wifi_wan);
+			strcpy(defwan_dev_name, wifi_wan);
+			cfg_set("wifi_act_type", "IPv4v6");
+		}
+	}
+
+	set_def_wan6(defwan_if_ipv6, defwan_real_ipv6);
+	//½«È±Ê¡ÍâÍø¿ÚµÄdev_id·¢Ë͸øÖ÷¿Ø
+	//if (strlen(defwan_dev_name) == 0 || strcmp(defwan6_if_old, defwan_real_ipv6)!=0)
+	{
+		defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name);
+
+		net_default_wan_proc(&defwan_dev_info);
+
+		//char tmp_name[20]= {0};
+		//sprintf(tmp_name,"zte_blc");
+	}
+
+	if (0 == strlen(defwan_real_ipv6)) {
+		slog(NET_PRINT, SLOG_ERR, "proc_wan_change_v6 defwan_if_ipv6 not selected! \n");
+		net_sendmsg_2_atctl(atoi(cid), V6_VALID, MSG_CMD_LINKUP_END);
+		return;
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 %s -> %s \n", defwan6_if_old, defwan_real_ipv6);
+	if (strcmp(defwan6_if_old, defwan_real_ipv6) != 0) {
+		int ps_wan_len = strlen(ps_wan);
+		if (0 == strcmp(defwan6_if_old, eth_wan) && atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+		else if (0 == strcmp(defwan6_if_old, wifi_wan) && atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"wifi_wan\"");
+		else if (ps_wan_len < strlen(defwan6_if_old) && 0 == strncmp(defwan6_if_old, ps_wan, ps_wan_len)){
+			char cmd[100] = {0};
+			int cid = defwan6_if_old[ps_wan_len] - '0';
+			if(cid > 0 && cid < 9){
+				sprintf(cmd, "/sbin/wan_ipv6.sh linkdown pswan %d", cid);
+				zxic_system(cmd);
+			}
+		}
+	}
+	//Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ
+	if (0 == strcmp(defwan_if_ipv6, eth_wan) && atoi(wbwanv6_enable) == 1)
+		system("wan_ipv6_config.sh \"ethwan\"");
+	else if (0 == strcmp(defwan_if_ipv6, wifi_wan) && atoi(wbwanv6_enable) == 1)
+		system("wan_ipv6_config.sh \"wifiwan\"");
+	else
+		system("wan_ipv6_config.sh \"pswan\"");
+
+	defwan_set(defwan_if_ipv6);
+
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 data ok \n");
+
+	//Èç¹ûĬÈÏwan¿ÚÓб䣬ÐèÒªÖØÐÂÅäÖ÷ÓÉ¡¢·À»ðǽµÈÐÅÏ¢
+	if (strcmp(defwan6_if_old, defwan_real_ipv6) != 0) {
+		zte_router_init();
+		memset(defwan6_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN);
+		strncpy(defwan6_if_old, defwan_real_ipv6, sizeof(defwan6_if_old)-1);
+	}
+	zte_unpn_set();
+
+	net_sendmsg_2_atctl(atoi(cid), V6_VALID, MSG_CMD_LINKUP_END);
+
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 end \n");
+}
+
+void * msg_timeout(void* arg)
+{
+	int ret = 0;
+	unsigned char netdev_id = *(unsigned char*)arg;
+
+	ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TIMER_OUT, sizeof(unsigned char), (UCHAR *)&netdev_id, 0);
+	if (0 != ret) {
+		softap_assert("send msg to zte_mainctrl error");
+		return NULL;//klocwork
+	}
+	return NULL;
+}
+
+void msg_timedel()
+{
+	int ret = 0;
+
+	ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TIMER_DEL, 0, 0, 0);
+	if (0 != ret) {
+		softap_assert("send msg to zte_mainctrl error");
+		return;
+	}
+}
+//µ±³¬Ê±ºó£¬ÍøÂçÄÚ²¿Í£Ö¹µØÖ·ÇëÇóÏà¹Ø¶¯×÷£¬²¢·¢ËÍÏûÏ¢¸øÖ÷¿Ø
+void out_of_time(unsigned char netdev_id)
+{
+	struct dialfail_dev_info dialfail_dev_info = {0};
+	dialfail_dev_info.ip46flag = V4_VALID;
+	dialfail_dev_info.dev_id = netdev_id;
+	dialfail_dev_info.dialfail_reason = TIME_OUT;
+	char tmp_name[20] = {0};
+	char rj45_pluginstate[NV_NAME_LEN] = {0};
+	int plugstate = 0;
+	char wbwanv6_enable[NV_NAME_LEN] = {0};
+	cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
+	if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) {
+		char eth_dev[NV_NAME_LEN] = {0};
+		char cmd[100] = {0};
+		system("wan_ipv4.sh \"linkdown\" \"ethwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"ethwan\"");
+		cfg_set("rj45_state", "idle");
+		cfg_get_item("ethwan", eth_dev, sizeof(eth_dev));
+		if (strchr(eth_dev, '.')) {
+			set_ethwan_port_mode(0);
+			sprintf(cmd, "/sbin/vconfig rem %s", eth_dev);
+			zxic_system(cmd);
+
+			cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate));
+			plugstate = atoi(rj45_pluginstate);
+			if((plugstate & RJ45_LAN_IN) == 0)
+			{
+				system("landev_updown.sh \"ethlan\" \"down\"");
+				vlan_config(RJ45_LAN_DEV, "rem");
+				cfg_set("wanport3_in_lan", "0");
+			}
+		}
+	} else if (netdev_id == WIFI_WAN_DEV) {
+		system("wan_ipv4.sh \"linkdown\" \"wifiwan\"");
+		if(atoi(wbwanv6_enable) == 1)
+			system("wan_ipv6.sh \"linkdown\" \"wifiwan\"");
+		cfg_set("wifi_state", "idle");
+		ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_NET_WAN_DIAL_FAIL, 0, NULL, 0);
+	}
+
+	//Á¬½Ó³¬Ê±Ö®ºó·¢ËÍÏûÏ¢¸øÖ÷¿Ø
+	sprintf(tmp_name, "zte_blc");
+	slog(NET_PRINT, SLOG_ERR, "out_of_time: send MSG_CMD_NET_WAN_DIAL_FAIL msg to mainctl,netdev_id=%u\n", dialfail_dev_info.dev_id);
+
+}
+
+void creattimer(unsigned char *netdev_id)
+{
+	DeleteSoftTimer(TIMER_MainCtrl_NetID + *netdev_id);
+	CreateSoftTimer(TIMER_MainCtrl_NetID + *netdev_id, TIMER_FLAG_ONCE, ConnectWaitTime, msg_timeout, (void*)netdev_id);
+}
+
+
+
+void deletetimer(unsigned char netdev_id)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "deletetimer: netdev_id=%u\n", netdev_id);
+	DeleteSoftTimer(TIMER_MainCtrl_NetID + netdev_id);
+}
+
+
diff --git a/ap/app/zte_comm/zte_mainctrl/router_msg_proxy.c b/ap/app/zte_comm/zte_mainctrl/router_msg_proxy.c
new file mode 100755
index 0000000..0d31e68
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/router_msg_proxy.c
@@ -0,0 +1,40 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/msg.h>
+#include "message.h"
+#include "netapi.h"
+#include "softap_api.h"
+
+
+
+int main(int argc, char* argv[])
+{
+	//char  wan_name[64] = {0};
+	char  wan_opt[64] = {0};
+	char  tmp[64] = {0};
+	if (argc != 2 && argc != 3) {
+		slog(NET_PRINT, SLOG_ERR, "ZTE_wanctl parameter num error ");
+		return -1;
+	}
+	//strcpy(wan_name,argv[1]); //get wan name:pswan;usbwan;ethwan;wifiwan
+	strncpy(wan_opt, argv[1], sizeof(wan_opt)-1); //v4 or v6
+	if (argc == 3) {
+		strncpy(tmp, argv[2], sizeof(tmp)-1);//klocwork
+	}
+
+	if (0 == strcmp(wan_opt, "ipv4"))
+		ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_WAN4_CHANGE, strlen(tmp), (UCHAR *)tmp, 0);
+	else if (0 == strcmp(wan_opt, "ipv6"))
+		ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_WAN6_CHANGE, strlen(tmp), (UCHAR *)tmp, 0);
+	else if (0 == strcmp(wan_opt, "del_timer"))
+		ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TIMER_DEL, strlen(tmp), (UCHAR *)tmp, 0);
+
+	return 0;
+
+}
+
+
+
+
diff --git a/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.c b/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.c
new file mode 100755
index 0000000..9d26012
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.c
@@ -0,0 +1,1616 @@
+#include <sys/syscall.h>
+#include <linux/reboot.h>
+#include <openssl/aes.h>
+
+#include "rtc_timer.h"
+#include "zte_mainctrl.h"
+#include "libcpnv.h"
+/**************************************************************************
+ *                           Global Variables                             *
+ **************************************************************************/
+
+char ps_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+char usb_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+char eth_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+char wifi_wan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0};
+
+unsigned char ethwan_id = 0; //ÓÃÓÚRJ45ÍâÍø¿ÚµÄ³¬Ê±´¦Àí
+unsigned char wifiwan_id = 0;//ÓÃÓÚwifiÍâÍø¿ÚµÄ³¬Ê±´¦Àí
+
+int g_limit_time_flag = 0; //ÓÃÓÚ¼Ò³¤Ä£Ê½ 1£º½ûÖ¹ÉÏÍøÊ±¼ä¶Î 0 £ºÔÊÐíÉÏÍøÊ±¼ä¶Î
+
+//¼Ç¼ÊÇ·ñÕýÔÚ»Ö¸´³ö³§ÉèÖ㬴˽׶β»½øÐÐcfg_saveµÈ²Ù×÷
+int g_mainctrl_factory_reset    = 0;
+int g_mainctrl_reset_ext_cmd    = 0;
+int g_mainctrl_poweroff_ext_cmd = 0;
+int g_mainctrl_restart_ext_cmd  = 0;
+
+struct list_head g_mainctrl_reset_notify;
+struct list_head g_mainctrl_poweroff_notify;
+struct list_head g_mainctrl_restart_notify;
+
+//Èç¹ûreset·¢Æð·½²»ÐèÒªÉ豸×öreboot£¬ÔòÖ÷¿ØÍê³Éresetºó·¢ËÍÏûÏ¢¸øËü£¬±¾Éí²»ÔÙ×öÈÎºÎÆäËû²Ù×÷
+static int g_restart_from = 0;
+static int g_restart_subaction = Operate_By_SOC;
+static int g_poweroff_from = 0;
+
+//¸øAT·¢pdp¼¤»îÏûÏ¢£¬Óöµ½ATµÚÒ»´Îû×öÍêµÚ¶þÌõÓÖÀ´ÁËAT»á¶ÏÑÔËÀ»ú
+static int g_pdpact_reqing = 0;//·¢ËÍpdp¼¤»îÏûÏ¢ÇÒ»¹Î´ÊÕµ½»Ø¸´
+static int g_pdpdeact_reqing = 0;//·¢ËÍpdpÈ¥¼¤»îÏûÏ¢ÇÒ»¹Î´ÊÕµ½»Ø¸´
+int g_poweron_type = 0;
+#define itoa(i,a,b) (((b) == 16) ? sprintf((a), "%x", (i)) : sprintf((a), "%d", (i)))
+
+//bsim
+typedef struct
+{
+	unsigned int pubKeyRsaE[32];
+	unsigned int pubKeyRsaN[32];
+	unsigned int secureFlag;
+	unsigned int pubKeyHash[4];
+	unsigned int secureDevId[3];
+}T_ZDrvEfuse_Secure;
+
+#define EFUSE_IOC_MAGIC 	'E'
+#define EFUSE_GET_DATA 		_IOWR(EFUSE_IOC_MAGIC, 1, char *)
+#define PPPOE_CODE_LEN 		32 //webui limit 30
+
+unsigned char pppoe_aes_key[16] = {0};
+
+static int bs_string2bytes(const char* pSrc, unsigned char* pDst, int nSrcLength)
+{
+    int i=0;
+
+    //УÑé²ÎÊý
+    if(pSrc ==  NULL || pDst == NULL || nSrcLength < 0)
+    {
+        return -1;
+    }
+
+    for(i = 0; i < nSrcLength; i += 2)
+    {
+        // Êä³ö¸ß4λ
+        if(*pSrc >= '0' && *pSrc <= '9')
+        {
+            *pDst = (*pSrc - '0') << 4;
+        }
+        else
+        {
+            *pDst = ((toupper(*pSrc) - 'A') + 10) << 4;
+        }
+
+        pSrc++;
+
+        // Êä³öµÍ4λ
+        if(*pSrc >= '0' && *pSrc <= '9')
+        {
+            *pDst |= *pSrc - '0';
+        }
+        else
+        {
+            *pDst |= (toupper(*pSrc) - 'A') + 10;
+        }
+
+        pSrc++;
+        pDst++;
+    }
+
+    // ·µ»ØÄ¿±êÊý¾Ý³¤¶È
+    return nSrcLength / 2;
+}
+
+static int bs_bytes2string(const unsigned char* pSrc, char* pDst, int nSrcLength)
+{
+    const char tab[]="0123456789ABCDEF";	// 0x0-0xfµÄ×Ö·û²éÕÒ±í
+    int i = 0;
+
+    //УÑé²ÎÊý
+    if(pSrc ==  NULL || pDst == NULL || nSrcLength < 0)
+    {
+        return -1;
+    }
+
+    for(i=0; i<nSrcLength; i++)
+    {
+        *pDst++ = tab[*pSrc >> 4];		// Êä³öµÍ4λ
+        *pDst++ = tab[*pSrc & 0x0f];	// Êä³ö¸ß4λ
+        pSrc++;
+    }
+
+    // ·µ»ØÄ¿±ê×Ö·û´®³¤¶È
+    return nSrcLength * 2;
+}
+
+static int bs_aes_init_key(unsigned char *aes_key, int k_len)
+{
+	int efuse_fd = -1;
+	T_ZDrvEfuse_Secure efuse = {0};
+	
+	memset(&efuse, 0, sizeof(efuse));
+	efuse_fd = open("/dev/efuse", O_RDWR);
+	if (efuse_fd < 0) {
+		printf("wifi_aes_init_key efuse open errno=%d\n", errno);
+		return 0;
+	}
+	if(ioctl(efuse_fd , EFUSE_GET_DATA, &efuse) != 0) {
+		printf("wifi_aes_init_key efuse ioctl errno=%d\n", errno);
+		close(efuse_fd);
+		return 0;
+	}
+	close(efuse_fd);
+	memcpy(aes_key, efuse.pubKeyHash, k_len);
+	
+	return 1;
+}
+
+static int bs_aes_encrypt(char* in, int len, char* out, unsigned char* key, int key_len)
+{
+    if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) {
+		printf("bs_aes_encrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len);
+        return 0;
+    }
+ 
+    AES_KEY aes = {0}; //cov h
+    if (AES_set_encrypt_key(key, key_len*8, &aes) < 0) {
+		printf("bs_aes_encrypt AES_set_encrypt_key err\n");
+        return 0;
+    }
+ 
+    int en_len = 0;
+    while (en_len < len) {
+        AES_encrypt((unsigned char*)in, (unsigned char*)out, &aes);
+        in	+= AES_BLOCK_SIZE;
+        out += AES_BLOCK_SIZE;
+        en_len += AES_BLOCK_SIZE;
+    }
+ 
+    return 1;
+}
+
+static int bs_aes_decrypt(char* in, int len, char* out, char* key, int key_len)
+{
+    if (!in || !out || !key || len <=0 || (len%AES_BLOCK_SIZE)!=0 || (key_len!=16 && key_len!=24 && key_len!=32)) {
+		printf("bs_aes_decrypt err in=%p out=%p key=%p len=%d key_len=%d\n",in,key,out,len,key_len);
+        return 0;
+    }
+ 
+    AES_KEY aes = {0}; //cov h
+    if (AES_set_decrypt_key((unsigned char*)key, key_len*8, &aes) < 0) {
+		printf("bs_aes_decrypt AES_set_decrypt_key err\n");
+        return 0;
+    }
+ 
+    int en_len = 0;
+    while (en_len < len) {
+        AES_decrypt((unsigned char*)in, (unsigned char*)out, &aes);
+        in	+= AES_BLOCK_SIZE;
+        out += AES_BLOCK_SIZE;
+        en_len += AES_BLOCK_SIZE;
+    }
+ 
+    return 1;
+}
+
+int pppoe_encrypt_code(void)
+{
+	char w_code[PPPOE_CODE_LEN + 1]= {0};
+	char b_aes[PPPOE_CODE_LEN + 1] = {0};
+	char s_aes[PPPOE_CODE_LEN*2 + 1] = {0};
+
+	cfg_get_item("pppoe_cc", w_code, sizeof(w_code));
+	bs_aes_encrypt(w_code, PPPOE_CODE_LEN, b_aes, pppoe_aes_key, sizeof(pppoe_aes_key));
+	bs_bytes2string(b_aes, s_aes, PPPOE_CODE_LEN);
+	cfg_set("pppoe_password", s_aes);
+	printf("encrypt pppoe_cc w_code=%s, s_aes=%s\n", w_code, s_aes);
+
+	return 1;
+}
+//2±íʾfota´ÓÀϰ汾ÍùÉÏÉý¼¶£¬pppoe_password´æµÄÊÇÃ÷ÎÄÃÜÂ룬а汾ÊÇÃÜÎÄ
+int pppoe_decrypt_code(void)
+{
+	char w_code[PPPOE_CODE_LEN + 1]= {0};
+	char b_aes[PPPOE_CODE_LEN + 1] = {0};
+	char s_aes[PPPOE_CODE_LEN*2 + 1] = {0};
+	int flag = 0;
+
+	cfg_get_item("pppoe_password", s_aes, sizeof(s_aes));
+	if (strlen(s_aes) == PPPOE_CODE_LEN*2) {
+		bs_string2bytes(s_aes, b_aes, PPPOE_CODE_LEN*2);
+		bs_aes_decrypt(b_aes, PPPOE_CODE_LEN, w_code, pppoe_aes_key, sizeof(pppoe_aes_key));
+		cfg_set("pppoe_cc", w_code);
+//		printf("decrypt pppoe_cc w_code=%s, s_aes=%s\n", w_code, s_aes);
+	} else if (strlen(s_aes) > 0){
+		cfg_set("pppoe_cc", s_aes);
+		return 2;
+	}
+
+	return 1;
+}
+
+int pppoe_aes_init(void)
+{
+	bs_aes_init_key(pppoe_aes_key, sizeof(pppoe_aes_key));
+	if (2 == pppoe_decrypt_code())
+		pppoe_encrypt_code();
+
+	return 1;
+}
+
+/* ¼Ç¼restartÀàÐÍ£¬¼Í¼ÇëÇóÊÇ·ñÀ´×ÔÀ©Õ¹AT ÒÔ¼°ÊÇ·ñÓÉÖ÷¿ØÍê³ÉREBOOT */
+void record_restart_type(MSG_BUF *msg)
+{
+	restart_info *msgData = NULL;
+	
+	//À´×ÔÀ©Õ¹ATºóÃæÐèÒª¸øAT·µ»ØÏûÏ¢£¬subActionΪRestart_By_MCUµÄ²»ÐèÒªÖ÷¿Øreboot
+	if (msg->usMsgCmd == MSG_CMD_RESET_REQUEST || msg->usMsgCmd == MSG_CMD_RESTART_REQUEST) {
+		if (msg->src_id == MODULE_ID_AT_CTL) { //À´×ÔÀ©Õ¹AT
+			g_restart_from = msg->src_id;
+		} else {
+			g_restart_from = 0;
+		}
+		
+		if (msg->usDataLen > 0) {
+			msgData = (restart_info*)msg->aucDataBuf;
+			if (msgData->subaction == Operate_By_MCU) {
+				g_restart_subaction = Operate_By_MCU;
+			} else {
+				g_restart_subaction = Operate_By_SOC;
+			}
+		} else {
+			g_restart_subaction = Operate_By_SOC;
+		}
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "record_restart_type = %d--%d\n", g_restart_from, g_restart_subaction);
+
+}
+
+void record_poweroff_type(MSG_BUF *msg)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "record_poweroff_type msg->src_id = 0x%x, msg->usMsgCmd = 0x%x\n", msg->src_id, msg->usMsgCmd);
+
+	//²»ÐèÒªÖ÷¿Øreboot
+	if (msg->src_id == MODULE_ID_AT_CTL && msg->usMsgCmd == MSG_CMD_POWEROFF_REQUEST) //À´×ÔÀ©Õ¹AT
+		g_poweroff_from = msg->src_id;
+	else
+		g_poweroff_from = 0;
+	slog(NET_PRINT, SLOG_NORMAL, "record_poweroff_type = 0x%x\n", g_poweroff_from);
+}
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:µÃµ½ÊÇ·ñÊÇÓÐÏß¿í´øÄ£Ê½:1:ÊÇ;0:·ñ
+***********************************************************************************/
+static int get_wan_mode()
+{
+	char blc_wan_mode[16] = {0};
+	char blc_wan_auto_mode[16] = {0};
+
+	cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode));
+	cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode));
+	if (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0)) {
+		slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, blc_wan_auto_mode=%s, now is auto or PPP mode\n", blc_wan_mode, blc_wan_auto_mode);
+		return 0;
+	} else {
+		slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, blc_wan_auto_mode=%s, now is not auto or PPP mode \n", blc_wan_mode, blc_wan_auto_mode);
+		return 1;
+	}
+}
+
+
+void set_wan_auto_mode(char * mode)
+{
+	char blc_wan_mode[16] = {0};
+
+	cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode));
+
+	if (strcmp(blc_wan_mode, "AUTO") == 0) {
+		cfg_set("blc_wan_auto_mode", mode);
+		slog(NET_PRINT, SLOG_NORMAL, "blc_set_wan_mode: mode = %s\n", mode);
+	}
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:µÃµ½ÆÕͨģʽ-wifistation ¿ª¹ØµÄÉèÖÃ:1:wifistation¿ªÆô;0:¹Ø±Õ
+***********************************************************************************/
+static int get_wifiwan_onoff()
+{
+	int result = -1;
+	char nv_wifiap_state[32] = {0};
+	char wifi_cur_state[8] = {0};
+
+	cfg_get_item("wifi_cur_state", wifi_cur_state, sizeof(wifi_cur_state));
+	cfg_get_item("wifi_sta_connection", nv_wifiap_state, sizeof(nv_wifiap_state));
+	slog(NET_PRINT, SLOG_NORMAL, "get_wifiwan_onoff wifi_cur_state:%s,nv_wifiap_state:%s\n", wifi_cur_state, nv_wifiap_state);
+	if (!strcmp(nv_wifiap_state, "1") && !strcmp(wifi_cur_state, "1")) {   //£±´ú±íwifistation ÆôÓÃ
+		result = 1;
+	} else {
+		result = 0;
+	}
+
+	slog(NET_PRINT, SLOG_DEBUG, "get_wifiwan_onoff result:%d\n", result);
+	return result;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:µÃµ½ÆÕͨģʽ-wifistation ÓÅÏȵÄÉèÖÃ:1:wifistationÓÅÏÈ;0:modem ÓÅÏÈ
+***********************************************************************************/
+static int get_wifiwan_pre()
+{
+	int result = 0;
+	char nv_wifi_state[32] = {0};
+	char ps_wan_pri[32] = {0};
+	char wifi_wan_pri[32] = {0};
+	int ps_pri = 0;
+	int wifi_pri = 0;
+
+	cfg_get_item("wifi_sta_connection", nv_wifi_state, sizeof(nv_wifi_state));
+	cfg_get_item("pswan_priority", ps_wan_pri, sizeof(ps_wan_pri));
+	cfg_get_item("wifiwan_priority", wifi_wan_pri, sizeof(wifi_wan_pri));
+
+	ps_pri = atoi(ps_wan_pri);
+	wifi_pri = atoi(wifi_wan_pri);
+
+	if (!strcmp(nv_wifi_state, "1")) {  //£±´ú±íwifistation ÆôÓÃ
+		if (wifi_pri > ps_pri) {
+			result = 1;
+		}
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "get_wifiwan_pre result:%d\n", result);
+	return result;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:ÆÕͨģʽ-wifistation ¹Ø±ÕÁ¬½Ó
+***********************************************************************************/
+static int close_wifiwan_access()
+{
+	int ret = 0;
+
+	ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_BLC_CLOSE_WIFISTATION_ACCESS, 0, NULL, 0);
+	if (0 != ret) {
+		return -1;
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "close_wifiwan_access request ok!\n");
+	return 0;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:ÆÕͨģʽ-wifistation ÆôÓÃÁ¬½Ó
+***********************************************************************************/
+static int open_wifiwan_access()
+{
+	char blc_wan_mode[16] = {0};
+	char blc_wan_auto_mode[16] = {0};
+	int ret = 0;
+
+	cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode));
+	cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode));
+
+	/*ÈôÉèÖÃΪÎÞÏß½ÓÈ룬Ôò´ò¿ªwifi*/
+	if (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0)) {
+		slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, can open WifiStation\n", blc_wan_mode);
+
+		ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_BLC_OPEN_WIFISTATION_ACCESS, 0, NULL, 0);
+		if (0 != ret) {
+			return -1;
+		}
+
+		slog(NET_PRINT, SLOG_NORMAL, "open wifiwan request ok!\n");
+		return 0;
+	}
+
+	slog(NET_PRINT, SLOG_ERR, "blc_wan_mode=%s, can not open WifiStation\n", blc_wan_mode);
+	return -1;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:·¢ËÍÆÕͨģʽ-Modem ¹Ø±ÕÁ¬½ÓµÄÖ¸Áî
+***********************************************************************************/
+static int close_pswan_access()
+{
+	int ret = 0;
+	if(g_pdpdeact_reqing != 0){
+		slog(NET_PRINT, SLOG_ERR, "last close pswan request without rsp!\n");
+		return -1;
+	}
+	cfg_set("user_blc_disconnect", "1");	//Ö÷¿ØÖ÷¶¯¶Ï¿ªÁ¬½Ó
+
+	ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_DEACT_REQ, 0, NULL, 0);
+	if (0 != ret) {
+		return -1;
+	}
+	g_pdpdeact_reqing = 1;
+	slog(NET_PRINT, SLOG_NORMAL, "close pswan request ok!\n");
+	return 0;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:·¢ËÍÆÕͨģʽ-Modem ÆôÓÃÁ¬½ÓµÄÖ¸Áî
+***********************************************************************************/
+static int open_pswan_access()
+{
+	char needInit[10] = {0};
+	char blc_wan_mode[16] = {0};
+	char blc_wan_auto_mode[16] = {0};
+	char dial_mode [20] = {0};
+	char user_initiate_disconnect[20] = {0};
+    char sta_ip_status[30] = {0};
+    char work_state[30] = {0};
+    
+	int ret = 0;
+
+	if(g_pdpact_reqing != 0){
+		slog(NET_PRINT, SLOG_ERR, "last open_modem request without rsq!\n");
+		return -1;
+	}
+
+    cfg_get_item ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
+    if (0 == strcmp(sta_ip_status, "connect"))
+    {
+        slog(NET_PRINT, SLOG_ERR, "ap station have connected, can not open modem\n");
+        return -1;
+    }
+    
+    cfg_get_item("rj45_state", work_state, sizeof(work_state));    
+    if (0 == strcmp(work_state, "connect"))
+    {
+        slog(NET_PRINT, SLOG_ERR, "rj45 have connected, can not open modem\n");
+        return -1;
+    }
+    
+	cfg_get_item("need_init_modem", needInit, sizeof(needInit));
+	if (0 != strcmp(needInit, "yes"))
+		return -1;
+
+	cfg_get_item("blc_wan_mode", blc_wan_mode, sizeof(blc_wan_mode));
+	cfg_get_item("blc_wan_auto_mode", blc_wan_auto_mode, sizeof(blc_wan_auto_mode));
+	cfg_get_item("user_initiate_disconnect", user_initiate_disconnect, sizeof(user_initiate_disconnect));
+	cfg_get_item("dial_mode", dial_mode, sizeof(dial_mode));
+
+	if (0 == strcmp(user_initiate_disconnect, "1"))
+		return -1;
+
+	if (0 == strcmp("auto_dial", dial_mode) && (strcmp("PPP", blc_wan_mode) == 0 || (strcmp("AUTO", blc_wan_mode) == 0 && strcmp("AUTO_PPP", blc_wan_auto_mode) == 0))) {
+		slog(NET_PRINT, SLOG_NORMAL, "blc_wan_mode=%s, can open modem\n", blc_wan_mode);
+
+		cfg_set("user_blc_disconnect", "0");	//Ö÷¿ØÍ˳öÖ÷¶¯¶Ï¿ªÁ¬½Ó
+		ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0);
+		if (0 != ret) {
+			return -1;
+		}
+		g_pdpact_reqing = 1;
+
+		slog(NET_PRINT, SLOG_NORMAL, "open_modem request ok!\n");
+		return 0;
+	}
+
+	slog(NET_PRINT, SLOG_ERR, "blc_wan_mode=%s, can not open modem\n", blc_wan_mode);
+	return -1;
+}
+
+static void set_modem_off()
+{
+#if (PRODUCT_TYPE == PRODUCT_PHONE)//¹¦ÄÜ»úÊÇcp×öÍêËùÓвÙ×÷ºóÔÙ֪ͨAP,ËùÒÔ²»ÐèÒª
+	return;
+#else //cov m
+	if(g_poweron_type == 2){//¹Ø»ú³äµçmodem²»ÔÚ²»·¢at+cfun=0
+		return;
+	}
+	int ret = get_modem_info("at+cfun=0\r\n", NULL, NULL);
+	if(ret){
+		slog(NET_PRINT, SLOG_ERR, "at+cfun=0 err =%d, can not close modem\n", ret);
+	}
+#endif
+}
+
+static int pdp_auto_dial()
+{
+	int ret;
+
+	char needInit[10] = {0};//ÅжÏÊÇ·ñÖ§³Ömodem¿ª»ú³õʼ»¯
+	char pppStatus [20] = {0};
+	char blc_wan_mode[20] = {0};
+	char blc_wan_auto_mode[20] = {0};
+	char user_initiate_disconnect[20] = {0};
+	char user_blc_disconnect[20] = {0};
+	char dial_mode [20] = {0};
+
+	cfg_get_item("need_init_modem", needInit, sizeof(needInit));
+	cfg_get_item(NV_BLC_WAN_MODE, blc_wan_mode, sizeof(blc_wan_mode));
+	cfg_get_item(NV_BLC_WAN_AUTO_MODE, blc_wan_auto_mode, sizeof(blc_wan_auto_mode));
+	cfg_get_item(NV_DIAL_MODE, dial_mode, sizeof(dial_mode));
+	cfg_get_item("user_initiate_disconnect", user_initiate_disconnect, sizeof(user_initiate_disconnect));
+	cfg_get_item("user_blc_disconnect", user_blc_disconnect, sizeof(user_blc_disconnect));
+
+	if (0 != strcmp(needInit, "yes")) {
+		return -1;
+	}
+
+	if (0 != strcmp("PPP", blc_wan_mode) && 0 != strcmp("AUTO", blc_wan_mode)) {
+		return -1;
+	}
+
+	if (0 != strcmp("auto_dial", dial_mode)) {
+		return  -1;
+	}
+
+	if (0 == strcmp(user_initiate_disconnect, "1") || 0 == strcmp(user_blc_disconnect, "1")) {
+		return -1;
+	}
+
+	ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, MSG_CMD_PDP_ACT_REQ, 0, NULL, 0);
+	if (0 != ret) {
+		slog(NET_PRINT, SLOG_ERR, "pdp_auto_dial err!\n");
+	}
+	g_pdpact_reqing = 1;
+
+	slog(NET_PRINT, SLOG_NORMAL, "pdp_auto_dial ok!\n");
+	return ret;
+
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:ĬÈÏÍâÍø¿Ú´¦Àí
+***********************************************************************************/
+void net_default_wan_proc(struct default_dev_info *dev)
+{
+	char dev_coexist[32] = {0};
+	char modem_wan_pri[32] = {0};
+	char wifi_wan_pri[32] = {0};
+	char rj45_wan_pri[32] = {0};
+	int modem_pri = 0;
+	int wifi_pri  = 0;
+	int rj45_pri  = 0;
+
+	slog(NET_PRINT, SLOG_NORMAL, "net_default_wan_proc dev_id:%d \n", dev->dev_id);
+
+	cfg_get_item("netdev_coexist", dev_coexist, sizeof(dev_coexist));
+
+	/*ÍâÍø¿Ú¹²´æ*/
+	if (0 == strcmp(dev_coexist, "1")) {
+		/*ÔÚÍø¿Ú¼¤»îʱ£¬wan_ipv4.sh»áΪ¼¤»îÍâÍø¿ÚÅäÖÃÒ»ÌõĬÈÏ·ÓÉ£¬ÔÚ¶àÍâÍø¿Ú¹²´æÊ±£¬
+		  ĬÈÏ·ÓÉÊÇ·ñÓ¦¸ÃÒÔĬÈÏÍâÍø¿Ú·ÓÉ×÷Ϊʵ¼ÊĬÈÏ·ÓÉ???
+		 */
+		slog(NET_PRINT, SLOG_NORMAL, "net device coexist!\n");
+		if (dev->dev_id == RJ45_WAN_DEV || dev->dev_id == SW_WAN_DEV) {
+
+			slog(NET_PRINT, SLOG_DEBUG, "Now rj45 is open!\n");
+
+		} else if (dev->dev_id == WIFI_WAN_DEV) {
+			int ret = -1;
+			slog(NET_PRINT, SLOG_DEBUG, "Now wifi station is open.\n");
+
+			ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_BLC_CONNECTED, 0, NULL, 0);
+			if (0 != ret) {
+				softap_assert("send msg to wlan_server error");
+				return;
+			}
+		} else if (dev->dev_id == PS_NET_DEV) {
+			slog(NET_PRINT, SLOG_DEBUG, "Now ps is open\n");
+		} else if (dev->dev_id == NO_DEV) {
+			if (get_wifiwan_onoff()) {
+				open_wifiwan_access();
+			}
+			open_pswan_access();
+		} else
+			slog(NET_PRINT, SLOG_ERR, "dev_id:%d is unknow!!!\n", dev->dev_id);
+	} else {
+		cfg_get_item("pswan_priority", modem_wan_pri, sizeof(modem_wan_pri));
+		cfg_get_item("wifiwan_priority", wifi_wan_pri, sizeof(wifi_wan_pri));
+		cfg_get_item("ethwan_priority", rj45_wan_pri, sizeof(rj45_wan_pri));
+		modem_pri = atoi(modem_wan_pri);
+		wifi_pri  = atoi(wifi_wan_pri);
+		rj45_pri  = atoi(rj45_wan_pri);
+
+		if (dev->dev_id == RJ45_WAN_DEV || dev->dev_id == SW_WAN_DEV) {
+			slog(NET_PRINT, SLOG_DEBUG, "Now wan is rj45, need close modem or wifi\n");
+			//¹Ø±ÕÆäËüÍøÂç
+			if (rj45_pri > modem_pri) {
+				close_pswan_access();
+			}
+			if (rj45_pri > wifi_pri) {
+				if (get_wifiwan_onoff()) {
+					close_wifiwan_access();
+				}
+			}
+		} else if (dev->dev_id == WIFI_WAN_DEV) {
+
+			int ret = -1;
+			slog(NET_PRINT, SLOG_DEBUG, "Now wan is wifi station.\n");
+
+			ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_BLC_CONNECTED, 0, NULL, 0);
+			if (0 != ret) {
+				softap_assert("send msg to wlan_server error");
+				return;
+			}
+
+			if (wifi_pri > rj45_pri) { // ÔÝʱû¹Ø±Õrj45µÄ³¡¾°
+				int result = -1;
+			}
+			if (wifi_pri > modem_pri) {
+				close_pswan_access();
+			}
+
+
+		} else if (dev->dev_id == PS_NET_DEV) {
+			slog(NET_PRINT, SLOG_DEBUG, "Now wan is ps\n");
+			if (modem_pri > rj45_pri) { // ÔÝʱû¹Ø±Õrj45µÄ³¡¾°
+				int result = -1;
+			} else if (modem_pri > wifi_pri) {
+				if (get_wifiwan_onoff()) {
+					close_wifiwan_access();
+				}
+			}
+		} else if (dev->dev_id == NO_DEV) {
+			slog(NET_PRINT, SLOG_NORMAL, "Now wan is None, need open ps or wifi\n");
+			if (get_wifiwan_onoff()) {
+				open_wifiwan_access();
+			}
+			open_pswan_access();
+		} else
+			slog(NET_PRINT, SLOG_ERR, "dev_id:%d is unknow!!!\n", dev->dev_id);
+	}
+}
+
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:»Ö¸´³ö³§ÉèÖòÎÊýÅäÖÃ
+***********************************************************************************/
+//·¢ËÍÏûÏ¢¸øÄ£¿é£¬ÐèÒª´ËÄ£¿é½øÐлظ´
+void notify_list_add(struct list_head *head, int dst_id)
+{
+	struct mainctrl_notify_queue *tmp = NULL, *notify = NULL;
+
+	slog(NET_PRINT, SLOG_DEBUG, "notify_list_add start, id:0x%x!!!\n", dst_id);
+
+	list_for_each_entry(tmp, head, list) {
+		//·¢Ë͸øtarget_idÄ£¿éµÄÏûÏ¢ÒѾ­¼Ç¼¹ý
+		if (tmp->notify_id == dst_id) {
+			slog(NET_PRINT, SLOG_ERR, "notify_list_add dst_id:0x%x alread existed! \n", dst_id);
+			return;
+		}
+	}
+
+	notify = malloc(sizeof(struct mainctrl_notify_queue));
+	if (notify == NULL) {
+		slog(NET_PRINT, SLOG_ERR, "notify_list_add id:0x%x malloc failed! \n", dst_id);
+		return;
+	}
+
+	INIT_LIST_HEAD(&notify->list);
+	notify->notify_id = dst_id;
+	list_add_tail(&notify->list, head);
+
+	slog(NET_PRINT, SLOG_NORMAL, "notify_list_add id:0x%x success !!!\n", dst_id);
+}
+
+//·¢ËÍÏûÏ¢¸øÄ£¿é£¬ÐèÒª´ËÄ£¿é½øÐлظ´
+void notify_list_del(struct list_head *head, int id)
+{
+	struct mainctrl_notify_queue *tmp = NULL, *notify = NULL;
+
+	slog(NET_PRINT, SLOG_DEBUG, "notify_list_del start, id:0x%x!!!\n", id);
+
+	list_for_each_entry(tmp, head, list) {
+		if (tmp->notify_id == id) {
+			slog(NET_PRINT, SLOG_NORMAL, "notify_list_del id = 0x%x\n", id);
+			list_del(&tmp->list);
+			free(tmp);
+			break;
+		}
+	}
+
+	slog(NET_PRINT, SLOG_DEBUG, "notify_list_del success !!!\n");
+}
+
+static void reset_factory_configure()
+{
+	char port_mode[16] = {0};
+	char time_to_2000[16] = {0};
+	char path_log[32] = {0};
+	char cmd[128] = {0};
+	int ret = -1;
+
+	cfg_get_item("port_stat", port_mode, 16);
+	if (strcmp(port_mode, "port_open") == 0) {
+		system("killall -9 monitor");
+	}
+	//  system("rm -rf /etc_rw/config/sms_db/sms.db"); ÓÉATµ÷Ó㬲»ÔÙ´¦Àí
+	//   system("rm -rf /etc_rw/config/pbm.db");ÓÉATµ÷Ó㬲»ÔÙ´¦Àí
+
+	// Óû§fotaÅäÖÃÊý¾Ý»Ö¸´³ö³§ÉèÖÃ
+	system("rm -rf  /usr/dm/config.ini");
+	system("rm -rf  /usr/dm/zteconfig/userseting_nvconfig.txt");
+
+	cfg_get_item("time_to_2000_when_restore", time_to_2000, 16);
+	if (strcmp(time_to_2000, "yes") == 0) {
+        system("rm -rf /etc_rw/TZ");
+		system("date -s \"2000-01-01 00:00:00\"");
+		system("zte-rtc-clock");
+	}
+
+	//ÍøÂç×é½Ó¿Ú
+	tcpip_reset_configure();
+
+	//add by diaolifang  begin »Ö¸´³ö³§ÉèÖÃʱɾ³ýlogÎļþ
+	system("killall -9 syslogd");
+	cfg_get_item("path_log", path_log, sizeof(path_log));
+	sprintf(cmd, "/bin/rm -rf %s*.*", path_log);
+	zxic_system(cmd);//kw 3
+	//add by diaolifang end
+
+	cfg_reset();
+	ret = cpnv_ResetNVFactory();
+	slog(NET_PRINT, SLOG_NORMAL, "cpnv_ResetNVFactory ret=%d.\n",ret);
+
+	slog(NET_PRINT, SLOG_NORMAL, "reset_factory_configure !\n");
+}
+
+/*¹Ø»ú³äµç*/
+static void poweroff_charging_process()
+{
+	char reboot_cmd[20] = {0};
+
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_charging_process start!!!\n");
+
+	sprintf(reboot_cmd, "mmi_key reboot");
+	syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_cmd);
+
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_charging_process success!!!\n");
+}
+/*  RTCÖØÆô¹Ø»úģʽ*/
+static VOID poweroff_clock_process(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_clock_process start!!!\n");
+	char reboot_cmd[20] = {0};
+	sprintf(reboot_cmd, "mmi_rtc reboot");
+	syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_cmd);
+}
+//mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù
+static int execute_ext_cmd(int cmd)
+{
+	//if (cmd <= Ext_Cmd_Base || cmd >= Ext_Cmd_MAX)
+	//	return 0;
+
+	if (cmd == Ext_Cmd_REBOOT || cmd == Ext_Cmd_POWEROFF)
+		system("app_monitor.sh off");
+
+	if (cmd == Ext_Cmd_REBOOT)
+		system("reboot");
+	else if (cmd == Ext_Cmd_POWEROFF)
+		system("poweroff");
+	else if (cmd == Ext_Cmd_POWEROFF_CHARGING)
+		poweroff_charging_process();
+	else if (cmd == Ext_Cmd_POWEROFF_FAKE) {
+		set_wake_unlock(MAINCTRL_LOCK);
+		cfg_set("doingPowerOff", "0");
+		slog(NET_PRINT, SLOG_NORMAL, "execute_ext_cmd Ext_Cmd_POWEROFF_FAKE!!!\n");
+	} else if (cmd == Ext_Cmd_POWEROFF_CLOCK) {
+		slog(NET_PRINT, SLOG_NORMAL, "execute_ext_cmd Ext_Cmd_POWEROFF_CLOCK!!!\n");
+		poweroff_clock_process();
+	} else {
+		return 0; //kw 3
+	}
+	return 1;
+}
+
+/*´¦ÀíÆäËûÄ£¿éÀ´µÄRESET_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/
+void reset_rsp_process(MSG_BUF *msg)
+{
+	int id;
+	struct mainctrl_notify_queue *temp = NULL;
+
+	slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process start!!!\n");
+
+	if (msg) {
+		id = msg->src_id;
+		slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process id = %x!!!\n", id);
+		//MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬
+		if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) {
+			struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf;
+			g_mainctrl_reset_ext_cmd = ext_data->cmd;
+		}
+		notify_list_del(&g_mainctrl_reset_notify, id);
+	}
+
+	//֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô
+	if (list_empty(&g_mainctrl_reset_notify)) {
+		system("app_monitor.sh off");//±ØÐëÔÚreset NV ֮ǰ
+		slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process success, ext_cmd:%d, from:0x%x  subaction:%d!!!\n", g_mainctrl_reset_ext_cmd, g_restart_from, g_restart_subaction);
+		reset_factory_configure();//µ÷Óûָ´³ö³§ÉèÖÃ
+		set_modem_off();
+
+		/* Èç¹ûÊÇÀ©Õ¹AT·¢ÆðµÄreset£¬ÐèÒª¸øAT»Ø¸´ÏûÏ¢*/
+		if (g_restart_from != 0) {
+			ipc_send_message(MODULE_ID_MAIN_CTRL, g_restart_from, MSG_CMD_RESTART_RSP, 0, NULL, 0);
+			//return;
+		}
+		/* ¸ù¾ÝsubactionÅжÏ×îºóµÄreboot¡¢¶ÏµçµÈ²Ù×÷ÊÇ·ñ½»ÓÉÍⲿMCU¸ºÔð*/
+		if (g_restart_subaction == Operate_By_MCU) {
+			return;
+		}
+		// mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù
+		if (execute_ext_cmd(g_mainctrl_reset_ext_cmd))
+			return;
+
+		system("reboot");
+		return;
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "reset_rsp_process still wait for reply !!!\n");
+}
+
+/*´¦ÀíÆäËûÄ£¿éÀ´µÄRESET_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/
+void poweroff_rsp_process(MSG_BUF *msg)
+{
+	int id;
+	struct mainctrl_notify_queue *temp = NULL;
+
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process start!!!\n");
+
+	if (msg) {
+		id = msg->src_id;
+		//MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬
+		if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) {
+			struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf;
+			g_mainctrl_poweroff_ext_cmd = ext_data->cmd;
+		}
+		notify_list_del(&g_mainctrl_poweroff_notify, id);
+	}
+
+	//֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô
+	if (list_empty(&g_mainctrl_poweroff_notify)) {
+		slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process success, g_poweroff_from:0x%x, ext_cmd:%d!!!\n", g_poweroff_from, g_mainctrl_poweroff_ext_cmd);
+		if (g_mainctrl_factory_reset == 0)
+			cfg_save();
+		if(g_mainctrl_poweroff_ext_cmd != Ext_Cmd_POWEROFF_FAKE){//¿ìËٹػú²»¿ÉÒÔ·¢at_cfun=0
+			set_modem_off();
+		}
+		/* Èç¹ûÊÇÀ©Õ¹AT·¢ÆðµÄreset£¬×îºóµÄreboot¡¢¶ÏµçµÈ²Ù×÷½»ÓÉAT¸ºÔð*/
+		if (g_poweroff_from != 0) {
+			ipc_send_message(MODULE_ID_MAIN_CTRL, g_poweroff_from, MSG_CMD_POWEROFF_RSP, 0, NULL, 0);
+			slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process MSG_CMD_POWEROFF_RSP to AT !!!\n");
+			return;
+		}
+		// mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù
+		if (execute_ext_cmd(g_mainctrl_poweroff_ext_cmd))
+			return;
+		system("app_monitor.sh off");
+		system("poweroff");
+		return;
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_rsp_process still wait for reply !!!\n");
+}
+
+/*´¦ÀíÆäËûÄ£¿éÀ´µÄRESTART_RSPÏûÏ¢£¬ÖØÖÃÆäÓàÄÚÈÝ*/
+void restart_rsp_process(MSG_BUF *msg)
+{
+	int id;
+	struct mainctrl_notify_queue *temp = NULL;
+
+	slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process start!!!\n");
+
+	if (msg) {
+		id = msg->src_id;
+		//MMIÒò¿ìËÙ¿ª¹Ø»úµÄ´æÔÚ£¬×îÖÕ´¦ÀíµÄÃüÁîÓëÉèÖûáÓÐËù²»Í¬
+		if (msg->src_id == MODULE_ID_MMI && msg->usDataLen > 0) {
+			struct ext_msg_data *ext_data = (struct ext_msg_data *) msg->aucDataBuf;
+			g_mainctrl_restart_ext_cmd = ext_data->cmd;
+		}
+		notify_list_del(&g_mainctrl_restart_notify, id);
+	}
+
+	//֪ͨresetµÄÄ£¿é¶¼´¦Àí²¢»Ø¸´ºóÔÙ½øÐÐÖ÷¿ØµÄ»Ö¸´³ö³§ÉèÖò¢ÖØÆô
+	if (list_empty(&g_mainctrl_restart_notify)) {
+		slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process success, ext_cmd:%d, subaction:%d!!!\n", g_mainctrl_restart_ext_cmd, g_restart_subaction);
+		if (g_mainctrl_factory_reset == 0)
+			cfg_save();
+		
+		set_modem_off();
+		
+		// ATÐèÒª»Ø¸´
+		if (g_restart_from != 0) {
+			ipc_send_message(MODULE_ID_MAIN_CTRL, g_restart_from, MSG_CMD_RESTART_RSP, 0, NULL, 0);
+		}
+		if (g_restart_subaction == Operate_By_MCU) {
+			return;
+		}
+		
+		// mmi¸ù¾Ý¿ìËÙ¿ª¹Ø»úµÈʵ¼Ê´¦ÀíÃüÁî»áÓëÔ¤ÆÚ²»Ò»Ñù
+		if (execute_ext_cmd(g_mainctrl_restart_ext_cmd))
+			return;
+
+		system("app_monitor.sh off");
+		system("reboot");
+		return;
+	}
+
+	slog(NET_PRINT, SLOG_NORMAL, "restart_rsp_process still wait for reply !!!\n");
+}
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:»Ö¸´³ö³§ÉèÖÃÏûÏ¢´¦Àíº¯Êý
+***********************************************************************************/
+void reset_msg_process(MSG_BUF *msg)
+{
+	struct mainctrl_notify_queue *notify = NULL;
+	char fota_update_flag[32] = {0};
+
+	slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process start!!!\n");
+
+	//fotaÉý¼¶Ê±²»ÔÊÐí×ö»Ö¸´³ö³§ÉèÖÃ
+	cfg_get_item("fota_update_flag", fota_update_flag, sizeof(fota_update_flag));
+	if (atoi(fota_update_flag) == 1) {
+		slog(NET_PRINT, SLOG_ERR, "reset_msg_process: fota is in upgrading process! can not reset!!!\n");
+		return;
+	}
+
+#if 0
+	//·ÇCPÀ´µÄÏûÏ¢£¬ÐèÒª¸øCP·¢ÏûϢ֪ͨCP reset£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	//if (msg->usMsgCmd != MSG_CMD_SOC_RESET_REQUEST)
+	slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process msg->src_id = %x!!!\n", msg->src_id);
+	if (msg->src_id & MODULE_ID_APBASE) {
+		if (send_soc_msg(NEAR_PS, MODULE_ID_AT_CTL, MSG_CMD_RESET_NOTIFY, 0, NULL) == 0) {
+			slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process: send msg to CP ok!!!\n");
+			//notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_AT_CTL);
+			notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_CP_AT_CTL);
+		}
+	}
+#endif
+
+	//¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_RESET_RSP) == 0) {
+		slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to rtc ok!!!\n");
+		notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_RTC_SERVICE);
+	}
+
+	//¸øSMS·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_SMS, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) {
+		slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to sms ok!!!\n");
+		notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_SMS);
+	}
+
+	//¸øFOTA·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_DM_WEBUI_AT, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) {
+		slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to FOTA ok!!!\n");
+		notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_DM_WEBUI_AT);
+	}
+
+	//¸øPB·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_PB, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) {
+		slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to pb ok!!!\n");
+		notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_PB);
+	}
+
+	//¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´,²»ÐèÒªÖ÷¿Ø×öresetÔò²»¸øMMI
+	if (g_restart_subaction == Operate_By_SOC) {
+		if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_RESET_NOTIFY, 0, NULL, 0) == 0) {
+			slog(NET_PRINT, SLOG_DEBUG, "reset_msg_process: send msg to mmi ok!!!\n");
+			notify_list_add(&g_mainctrl_reset_notify, MODULE_ID_MMI);
+		}
+	}
+
+	//ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì
+	if (list_empty(&g_mainctrl_reset_notify)) {
+		reset_rsp_process(NULL);
+	} else {
+		slog(NET_PRINT, SLOG_NORMAL, "reset_msg_process success!!!\n");
+	}
+}
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:ÊÇ·ñ¼Ù¹Ø»ú
+***********************************************************************************/
+static BOOL blc_is_fakepoweroff()
+{
+	char nv_abnormal_poweroff[2] = {0};
+	char rj45_sta[24] = {0};
+	char nv_poweron_mode[8] = {0};
+	char nv_sim_pin[8] = {0};
+
+	cfg_get_item("abnormal_poweroff_flag", nv_abnormal_poweroff, sizeof(nv_abnormal_poweroff));
+	cfg_get_item("rj45_plug", rj45_sta, sizeof(rj45_sta));
+	cfg_get_item("mgmt_quicken_power_on", nv_poweron_mode, sizeof(nv_poweron_mode));
+	cfg_get_item("need_sim_pin", nv_sim_pin, sizeof(nv_sim_pin));
+	slog(NET_PRINT, SLOG_NORMAL, "blc_is_fakepoweroff nv_abnormal_poweroff= %s,rj45_sta= %s,nv_poweron_mode= %s,nv_sim_pin= %s\n", nv_abnormal_poweroff, rj45_sta, nv_poweron_mode, nv_sim_pin);
+	if ((!strncmp(rj45_sta, "wan_on_lan_off", strlen("wan_on_lan_off")))
+	    || (!strncmp(rj45_sta, "wan_off_lan_on", strlen("wan_off_lan_on")))
+	    || (!strncmp(rj45_sta, "wan_lan_on", strlen("wan_lan_on")))) {
+		return FALSE;
+	}
+	if (strncmp(nv_poweron_mode, "1", sizeof("1"))) {
+		return FALSE;
+	}
+	if (!strncmp(nv_sim_pin, "yes", sizeof("yes"))) {
+		return FALSE;
+	}
+	if (!strncmp(nv_abnormal_poweroff, "1", 1)) {
+		return FALSE;
+	}
+	slog(NET_PRINT, SLOG_NORMAL, "blc_is_fakepoweroff !\n");
+	return TRUE;
+}
+
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:¹Ø»úÏûÏ¢´¦Àíº¯Êý
+***********************************************************************************/
+void poweroff_msg_process(MSG_BUF *msg)
+{
+	struct ext_msg_data *msgData = NULL;
+
+	slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process !\n");
+
+#if (PRODUCT_TYPE == PRODUCT_PHONE)
+	if (g_poweroff_from == 0) { //À©Õ¹AT·¢ÆðµÄ¹Ø»úÇëÇ󣬲»´ø¹Ø»úÔ­Òò£¬²»ÐèÒª×ßÒÔÏÂÁ÷³Ì£»CP·¢ÆðµÄ¹Ø»úÇëÇó×ßÒÔÏÂÁ÷³Ì
+		if (!msg || msg->usDataLen <= 0) {
+			slog(NET_PRINT, SLOG_ERR, "poweroff_msg_process msg is empty \n");
+			return;
+		}
+
+		msgData = (struct ext_msg_data*)msg->aucDataBuf;
+		if (!msgData) {
+			slog(NET_PRINT, SLOG_ERR, "poweroff_msg_process param is NULL \n");
+			return;
+		}
+		g_mainctrl_poweroff_ext_cmd = (T_zUfi_ExtCmd)msgData->cmd;
+	}
+#endif
+
+	//¸ødata·¢ÏûÏ¢£¬²»ÐèÒªÊÕµ½»Ø¸´
+	if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_FLUXSTAT, MSG_CMD_DATA_END, 0, NULL, 0) != 0) {
+		slog(NET_PRINT, SLOG_ERR, "send msg to data fail!!!\n");
+	}
+
+	//·Ç¼Ù¹Ø»úʱ¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (!blc_is_fakepoweroff()) {
+		if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_POWEROFF_RSP) == 0) {
+			slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process: send msg to rtc ok!!!\n");
+			notify_list_add(&g_mainctrl_poweroff_notify, MODULE_ID_RTC_SERVICE);
+		}
+	}
+
+	//¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (g_poweroff_from == 0) {
+		if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_POWEROFF_NOTIFY, 0, NULL, 0) == 0) {
+			slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process: send msg to mmi ok!!!\n");
+			notify_list_add(&g_mainctrl_poweroff_notify, MODULE_ID_MMI);
+		}
+	}
+
+	//ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì
+	if (list_empty(&g_mainctrl_poweroff_notify)) {
+		poweroff_rsp_process(NULL);
+	} else {
+		slog(NET_PRINT, SLOG_NORMAL, "poweroff_msg_process success!!!\n");
+	}
+}
+
+/**********************************************************************************
+º¯Êý×÷ÓÃ:ÖØÆôÏûÏ¢´¦Àíº¯Êý
+***********************************************************************************/
+void restart_msg_process(void)
+{
+	slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process !\n");
+
+	//¸ødata·¢ÏûÏ¢£¬²»ÐèÒªÊÕµ½»Ø¸´
+	if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_FLUXSTAT, MSG_CMD_DATA_END, 0, NULL, 0) != 0) {
+		slog(NET_PRINT, SLOG_ERR, "send msg to data fail!!!\n");
+	}
+
+	//¸øRTC·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (rtc_timer_del_all(MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_RSP) == 0) {
+		slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process: send msg to rtc ok!!!\n");
+		notify_list_add(&g_mainctrl_restart_notify, MODULE_ID_RTC_SERVICE);
+	}
+
+	//¸øMMI·¢ÏûÏ¢£¬ÇÒÐèÒªÊÕµ½»Ø¸´
+	if (g_restart_subaction == Operate_By_SOC) {
+		if (ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_MMI, MSG_CMD_RESTART_NOTIFY, 0, NULL, 0) == 0) {
+			slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process: send msg to mmi ok!!!\n");
+			notify_list_add(&g_mainctrl_restart_notify, MODULE_ID_MMI);
+		}
+	}
+
+	//ÒÔÉÏÓ¦Óò»´æÔÚ£¬Ö÷¿Ø×ßÓ¦´ðÁ÷³Ì
+	if (list_empty(&g_mainctrl_restart_notify)) {
+		restart_rsp_process(NULL);
+	} else {
+		slog(NET_PRINT, SLOG_NORMAL, "restart_msg_process success!!!\n");
+	}
+}
+
+/*rj45×÷ΪÄÚÍø¿Úʱ£¬´ò¿ªwifiºÍpsÖÐÓÅÏȼ¶¸ßµÄ×÷ΪÍâÍø¿Ú*/
+void set_rj45_lan()
+{
+	int result = -1;
+	int wifi_pre = 0;
+
+	set_wan_auto_mode("AUTO_PPP");
+
+	wifi_pre = get_wifiwan_pre();
+	if (wifi_pre == 1) { //½øÐÐwifistation Á¬½Ó
+		open_wifiwan_access();
+	} else if (wifi_pre == 0) { //½øÐÐmodem Á¬½Ó
+		open_pswan_access();
+	}
+}
+
+static void check_limit_time(void)
+{
+	/* 0:·ÇÏÞÖÆÉÏÍøÊ±¼ä¶Î 1:ÏÞÖÆÉÏÍøÊ±¼ä¶Î*/
+	if (g_limit_time_flag == 1) {
+		zte_children_start_nonet();
+	} else if (g_limit_time_flag == 0) {
+		zte_children_stop_nonet();
+	}
+}
+
+static int create_msg_queue(void)
+{
+	return msgget(MODULE_ID_MAIN_CTRL, IPC_CREAT | 0600);
+}
+
+void get_wan_name()
+{
+	cfg_get_item("pswan", ps_wan, sizeof(ps_wan));
+	cfg_get_item("wifiwan", wifi_wan, sizeof(wifi_wan));
+	cfg_get_item("ethwan", eth_wan, sizeof(eth_wan));
+}
+
+void mainctrl_init()
+{
+	INIT_LIST_HEAD(&g_mainctrl_reset_notify);
+	INIT_LIST_HEAD(&g_mainctrl_poweroff_notify);
+	INIT_LIST_HEAD(&g_mainctrl_restart_notify);
+	pppoe_aes_init();
+}
+
+void Router_msg_proc(MSG_BUF *msg)
+{
+	if (NULL == msg) {
+		slog(NET_PRINT, SLOG_ERR, "NULL para input!");
+		return;
+	}
+
+	switch (msg->usMsgCmd) {
+	/*ÍøÂçÏà¹ØµÄÏûÏ¢´¦Àí*/
+	case MSG_CMD_NET_IPPORT_FILTER: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_FILTER \n");
+		zte_iptables_filter_run();
+		zte_iptables_filter_run_v6();
+		break;
+	}
+	case MSG_CMD_NET_IPPORT_FORWARD: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_FORWARD \n");
+		zte_iptables_sys_fw_run();
+		zte_iptables_port_forward_run();
+		break;
+	}
+	case MSG_CMD_NET_DMZ: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DMZ \n");
+		zte_iptables_DMZ_Run();
+		break;
+	}
+	/* EC: 616000297057, Ô­Òò: ÍøÂç²»Ö§³Ö¶Ë¿ÚÓ³Éä */
+	case MSG_CMD_NET_IPPORT_MAPPING: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_IPPORT_MAPPING \n");
+		zte_iptables_port_map_all_run();
+		break;
+	}
+	case MSG_CMD_NET_UPNP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_UPNP \n");
+		zte_unpn_set();
+		break;
+	}
+	case MSG_CMD_NET_URL_FILTER: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_URL_FILTER \n");
+		zte_iptables_Webs_Filter_Run();
+		break;
+	}
+	case MSG_CMD_NET_MTU: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_MTU \n");
+		zte_router_mtu_set_process();
+		break;
+	}
+	case MSG_CMD_NET_WAN4_CHANGE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_WAN4_CHANGE %s\n", msg->aucDataBuf);
+		proc_wan_change_v4();
+		break;
+	}
+	case MSG_CMD_NET_WAN6_CHANGE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_WAN6_CHANGE %s\n", msg->aucDataBuf);
+		proc_wan_change_v6();
+		break;
+	}
+	case MSG_CMD_NET_PLUGIN: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PLUGIN \n");
+		if(g_poweron_type != 2)//¹Ø»ú³äµç²»ÆðÍøÂçÉ豸£¬¹²½ø³Ì°æ±¾¹Ø»ú³äµç»áÆðhotplug£¬»á·¢À´usbplugin
+		net_netdev_plugin_proc(*((unsigned char *)msg->aucDataBuf));
+		break;
+	}
+	case MSG_CMD_NET_PLUGOUT: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PLUGOUT \n");
+		net_netdev_plugout_proc(*((unsigned char *)msg->aucDataBuf));
+		break;
+	}
+	case MSG_CMD_NET_CONNECT: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_CONNECT \n");
+		net_netdev_connect_internet(*((unsigned char *)msg->aucDataBuf));
+		break;
+	}
+	case MSG_CMD_NET_DISCON: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DISCON \n");
+		net_netdev_disconnect_internet(*((unsigned char *)msg->aucDataBuf));
+		break;
+	}
+	case MSG_CMD_NET_PDP_ACT: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PDP_ACT \n");
+		net_pdp_act_proc((struct pdp_active_info *)msg->aucDataBuf);
+		break;
+	}
+	case MSG_CMD_NET_PDP_DEACT: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_PDP_DEACT \n");
+		struct pdp_deactive_info temp = *((struct pdp_deactive_info *)msg->aucDataBuf);
+		net_pdp_deact_proc(temp.c_id, temp.ip46flag);
+		break;
+	}
+	case MSG_CMD_NET_TC_CTRL: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TC_CTRL \n");
+		net_tc_control((struct tc_control_info *)msg->aucDataBuf,msg->src_id);
+		break;
+	}
+	case MSG_CMD_NET_GET_HOSTNAME: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_GET_HOSTNAME \n");
+		get_mac_hostname_pro((struct mac_hostname_info *)msg->aucDataBuf);
+		break;
+	}
+	case MSG_CMD_NET_STATIC_DHCP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_STATIC_DHCP \n");
+		zte_macip_list_run();
+		break;
+	}
+	case MSG_CMD_NET_DHCP_SETTING_REQ: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DHCP_SETTING_REQ \n");
+		zte_router_dhcp_setting_req_process((dhcp_setting_req *)msg->aucDataBuf);
+		break;
+	}
+	case MSG_CMD_NET_TIMER_OUT: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TIMER_OUT \n");
+		out_of_time(*((unsigned char *)msg->aucDataBuf));
+		break;
+	}
+	case MSG_CMD_NET_TIMER_DEL: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_TIMER_DEL \n");
+		char wanname[20] = {0};
+		strncpy(wanname, (char *)msg->aucDataBuf, sizeof(wanname)-1);//klocwork
+		slog(NET_PRINT, SLOG_ERR, "MSG_CMD_NET_TIMER_DEL:%s \n", wanname);
+		if (0 == strcmp("ethwan", wanname))
+			deletetimer(ethwan_id);
+		else if (0 == strcmp("wifiwan", wanname))
+			deletetimer(wifiwan_id);
+		break;
+	}
+	case MSG_CMD_NET_BIND_STATIC_ADDRESS: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS \n");
+		zte_bind_macip_list();
+		break;
+	}
+	case MSG_CMD_NET_BIND_STATIC_ADDRESS_ADD: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS_ADD \n");
+		zte_bind_macip_list_add((struct static_macip_info*)msg->aucDataBuf);
+		break;
+	}
+	case MSG_CMD_NET_BIND_STATIC_ADDRESS_DEL: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_BIND_STATIC_ADDRESS_DEL \n");
+		zte_bind_macip_list_del((char*)msg->aucDataBuf);
+		break;
+	}
+	case MSG_CMD_NET_ADD_CHILDREN_DEVICE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_ADD_CHILDREN_DEVICE \n");
+		children_device_add((struct mac_hostname_info *)msg->aucDataBuf);
+		slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END");
+		check_limit_time();
+		break;
+	}
+	case MSG_CMD_NET_DEL_CHILDREN_DEVICE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_DEL_CHILDREN_DEVICE \n");
+		children_device_del((char *)msg->aucDataBuf);
+		slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END");
+		check_limit_time();
+		break;
+	}
+	case MSG_CMD_NET_ADD_WHITE_SITE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_ADD_WHITE_SITE \n");
+		white_site_add((struct white_site_info *)msg->aucDataBuf);
+		slog(NET_PRINT, SLOG_ERR, "zte_edit_hostname MESSAGE TO MC END");
+		check_limit_time();
+		break;
+	}
+	case MSG_CMD_NET_REMOVE_WHITE_SITE: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_REMOVE_WHITE_SITE \n");
+		white_site_remove((char *)msg->aucDataBuf);
+		slog(NET_PRINT, SLOG_DEBUG, "zte_edit_hostname MESSAGE TO MC END");
+		check_limit_time();
+		break;
+	}
+	case MSG_CMD_NET_START_NONET: {
+		g_limit_time_flag = 1;
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_START_NONET \n");
+		zte_children_start_nonet();
+		break;
+	}
+	case MSG_CMD_NET_STOP_NONET: {
+		g_limit_time_flag = 0;
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_NET_STOP_NONET \n");
+		zte_children_stop_nonet();
+		break;
+	}
+	case MSG_CMD_PDP_ACT_RSP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PDP_ACT_RSP \n");
+		g_pdpact_reqing = 0;
+		break;
+	}
+	case MSG_CMD_PDP_DEACT_RSP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PDP_DEACT_RSP \n");
+		g_pdpdeact_reqing = 0;
+		break;
+	}
+	//case MSG_CMD_SOC_RESET_REQUEST:
+	case MSG_CMD_RESET_REQUEST: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESET_REQUEST, cmd:0x%x \n", msg->usMsgCmd);
+		set_wake_lock(MAINCTRL_LOCK);  //reset¡¢¹Ø»ú¡¢ÖØÆô²»ÔÊÐíÔÙ½øÐÝÃß
+		g_mainctrl_factory_reset = 1;
+		cfg_set("doingPowerOff", "1");
+		record_restart_type(msg);
+		reset_msg_process(msg);
+		break;
+	}
+	case MSG_CMD_POWEROFF_REQUEST: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_POWEROFF_REQUEST \n");
+		set_wake_lock(MAINCTRL_LOCK);
+		cfg_set("doingPowerOff", "1");
+		record_poweroff_type(msg);
+		poweroff_msg_process(msg);
+		break;
+	}
+	//²»´ø²ÎÊýĬÈÏ×ßÖØÆô£¬²ÎÊýaction : 1-RESET,  0 -RESTART ;  subaction:1-Ö÷¿Ø×îÖÕÍê³ÉÖØÆô»ñ»Ö¸´³ö³§ÉèÖÃ,  0-Ö÷¿ØÖ»ÒªÍê³ÉÖØÆô»ñ»Ö¸´³ö³§ÉèÖÃ֮ǰµÄ¶¯×÷¼´¿É
+	case MSG_CMD_RESTART_REQUEST: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESTART_REQUEST \n");
+		set_wake_lock(MAINCTRL_LOCK);
+		cfg_set("doingPowerOff", "1");
+		record_restart_type(msg);
+
+		if (msg->usDataLen > 0) {
+			restart_info *msgData = (restart_info*)msg->aucDataBuf;
+			if (msgData->action == Restart_Action_RESET) {
+				g_mainctrl_factory_reset = 1;
+				reset_msg_process(msg);
+			} else {
+				restart_msg_process();
+			}
+		} else {
+			restart_msg_process();
+		}
+		break;
+	}
+	/*ÆäËûÄ£¿é´¦ÀíÍêresetºó»ØµÄÏûÏ¢*/
+	//case MSG_CMD_SOC_RESET_RSP:
+	case MSG_CMD_RESET_RSP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESET_RSP, cmd:0x%x \n", msg->usMsgCmd);
+		reset_rsp_process(msg);
+		break;
+	}
+	/*ÆäËûÄ£¿é´¦ÀíÍêpoweroffºó»ØµÄÏûÏ¢*/
+	case MSG_CMD_POWEROFF_RSP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_POWEROFF_RSP \n");
+		poweroff_rsp_process(msg);
+		break;
+	}
+	/*ÆäËûÄ£¿é´¦ÀíÍêrestartºó»ØµÄÏûÏ¢*/
+	case MSG_CMD_RESTART_RSP: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_RESTART_RSP \n");
+		restart_rsp_process(msg);
+		break;
+	}
+	case MSG_CMD_NET_SET_RJ45_LAN: {
+		set_rj45_lan();
+		break;
+	}
+	case MSG_CMD_NET_PING_DIAGNOSTICS: {
+		slog(NET_PRINT, SLOG_DEBUG, "recv msg MSG_CMD_PING_DIAGNOSTICS \n");
+		zte_router_ping_diagnostics();
+		break;
+	}
+	default:
+		//assert(0);
+		break;
+	}
+}
+
+static void print_mainctrl_info(void)
+{
+	struct mainctrl_notify_queue *temp = NULL;
+	int ret;
+
+	if (!list_empty(&g_mainctrl_poweroff_notify)) {
+		list_for_each_entry(temp, &g_mainctrl_poweroff_notify, list) {
+			slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_poweroff_notify: module_id = 0x%x\n", temp->notify_id);
+		}
+	} else {
+		slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_poweroff_notify list is empty! \n");
+	}
+
+	if (!list_empty(&g_mainctrl_restart_notify)) {
+		list_for_each_entry(temp, &g_mainctrl_restart_notify, list) {
+			slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_restart_notify: module_id = 0x%x\n", temp->notify_id);
+		}
+	} else {
+		slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_restart_notify list is empty! \n");
+	}
+
+	if (!list_empty(&g_mainctrl_reset_notify)) {
+		list_for_each_entry(temp, &g_mainctrl_reset_notify, list) {
+			slog(NET_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_reset_notify: module_id = 0x%x\n", temp->notify_id);
+		}
+	} else {
+		slog(RTC_PRINT, SLOG_ERR, "zte_mainctrl g_mainctrl_reset_notify list is empty! \n");
+	}
+}
+
+static void mainctrl_sig_usr1(int signo)
+{
+	/*if (signo == SIGUSR1) {
+		slog(NET_PRINT, SLOG_ERR, "zte_mainctrl receive SIGUSR1!\n");
+
+		print_mainctrl_info();
+	} else {
+		slog(NET_PRINT, SLOG_ERR, "zte_mainctrl receive signo %d", signo);
+	}*/
+}
+
+static void nv_save_timeout(void)
+{
+	slog(NET_PRINT, SLOG_DEBUG, "nv_save_timeout factory_reset:%d \n", g_mainctrl_factory_reset);
+
+	if (g_mainctrl_factory_reset == 0)
+		cfg_save();
+}
+
+static void zte_security_log_entry(char *arg)
+{
+	int msg_handle = msgget(MODULE_ID_SECURITY_LOG, IPC_CREAT | 0600);
+	int ret = 0;	
+	MSG_BUF stMsg;
+	LONG msgSize =  sizeof(MSG_BUF) - sizeof(LONG);
+	char seclog[32] = {0};
+
+	cfg_get_item("seclog_switch", seclog, sizeof(seclog));
+	prctl(PR_SET_NAME, "seclog", 0, 0, 0);
+	slog(NET_PRINT, SLOG_ERR, "zte_security_log begin --build date: %s %s \n", __DATE__, __TIME__);
+	if (msg_handle == -1) {
+		slog(NET_PRINT, SLOG_ERR, "can not create msg queue for security_log!\n");
+		return;
+	}
+	for (;;) {
+		memset(&stMsg, 0, sizeof(stMsg));
+		ret = msgrcv(msg_handle, &stMsg, msgSize, 0, 0);
+		if (ret == -1) {
+			if (EINTR == errno) {
+				slog(NET_PRINT, SLOG_ERR, "sl_recev msg EINTR\n");
+				continue;
+			} else {
+				slog(NET_PRINT, SLOG_ERR, "sl_recev msg fail errno = %d \n", errno);
+				break;
+			}
+		}
+		slog(NET_PRINT, SLOG_NORMAL, "sl:%s\n", stMsg.aucDataBuf);
+		if(seclog[0] == '1')
+		{
+			file_write("security",stMsg.aucDataBuf);
+		}
+	}
+}
+
+int zte_mainctrl_main(int argc, char * argv[])
+{
+	int iMsgHandle = 0;
+	int iRet = 0;
+	MSG_BUF stMsg;
+	MSG_BUF send_stMsg;
+	LONG msgSize =  sizeof(MSG_BUF) - sizeof(LONG);
+	int interruptSIG = 0;
+	char nv_save_interval[32] = {0};
+	unsigned int interval_time = 0;
+	int i = 0;
+	prctl(PR_SET_NAME, "mainctrl", 0, 0, 0);
+	//¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
+	loglevel_init();
+
+	slog(NET_PRINT, SLOG_ERR, "zte_mainctrl begin ======= build date: %s %s \n", __DATE__, __TIME__);
+
+	pthread_t zte_security_log_tid;
+	if (pthread_create(&zte_security_log_tid, NULL, (void *)zte_security_log_entry, NULL) != 0) //cov m
+		slog(NET_PRINT, SLOG_ERR, "zte_security_log_entry create fail\n");
+
+	iMsgHandle = create_msg_queue();
+	if (-1 == iMsgHandle) {
+		slog(NET_PRINT, SLOG_ERR, "can not create msg queue for ZTE_router!\n");
+		return -1;
+	}
+
+	if (signal(SIGUSR1, mainctrl_sig_usr1) == SIG_ERR)
+		slog(NET_PRINT, SLOG_ERR, "zte_mainctrl cat not catch SIGUSR1!\n");
+
+	cfg_get_item("nv_save_interval", nv_save_interval, sizeof(nv_save_interval));
+	interval_time = atoi(nv_save_interval);
+	if (interval_time < 0x400000) {//klocwork ΪÁ˲»Òç³ö
+		interval_time = interval_time*1000;
+		CreateSoftTimer(TIMER_MainCtrl_NvSaveID, TIMER_FLAG_RESTART, interval_time, nv_save_timeout, NULL);
+	}
+	
+	/*init the router*/
+	//zte_router_init();
+	get_wan_name();
+
+	//³õʼ»¯È«¾Ö±äÁ¿
+	mainctrl_init();
+	if (argc >= 2) {
+		g_poweron_type = 2;//¹Ø»ú³äµç
+	}
+	if(g_poweron_type != 2)
+	system("internet.sh");
+	//µÈat_ctl×¼±¸ºÃ
+	while (i < 10) {
+		char ppp_status[20] = {0};
+		cfg_get_item("ppp_status", ppp_status, sizeof(ppp_status));
+		if (0 != strcmp("", ppp_status))
+			break;
+		usleep(200000);
+		i++;
+	}
+	pdp_auto_dial();
+
+	for (;;) {
+		if (0 == interruptSIG) {
+			slog(NET_PRINT, SLOG_ERR, "ZTE_router begin to rcv msg from queue %d. \n", iMsgHandle);
+		}
+		memset(&stMsg, '\0', sizeof(stMsg));
+		iRet = 0;
+		iRet = msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0);
+		if (-1 == iRet) {
+			if (EINTR == errno) {
+				slog(NET_PRINT, SLOG_ERR, "received msg EINTR\n");
+				// we use SIGALRM to timer, but the SIG will interrupt mgsrcv, so we should
+				//do this action
+				//DEBUG(LOG_ERR, "msgrcv faild as received a signal EINTR, need continue...\n");
+				//usleep(1000);
+				interruptSIG = 1;
+				continue;
+			} else {
+				//ZTE_LOG(LOG_ERR, "recv msg from the Goahead fail errno=%d!", errno);
+				slog(NET_PRINT, SLOG_ERR, "recv msg fail errno = %d \n", errno);
+				return -1;
+			}
+		} else {
+			interruptSIG = 1;
+		}
+		slog(NET_PRINT, SLOG_NORMAL, "mainctrl received msg usMsgCmd=0x%x, src=0x%x \n", stMsg.usMsgCmd, stMsg.src_id);
+
+		/*set the firewall or router*/
+		Router_msg_proc(&stMsg);
+	}
+	//closelog();
+}
+
+
+
diff --git a/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.h b/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.h
new file mode 100755
index 0000000..81c3730
--- /dev/null
+++ b/ap/app/zte_comm/zte_mainctrl/zte_mainctrl.h
@@ -0,0 +1,198 @@
+#ifndef _ZTE_ROUTER_H_
+#define _ZTE_ROUTER_H_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pthread.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+#include <syslog.h>
+#include <sys/klog.h>
+#include <assert.h>
+#include <ctype.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "soft_timer.h"
+#include "message.h"
+#include "softap_api.h"
+#include "cfg_nv_def.h"
+
+
+/**************************************************************************
+ *                              Types                                     *
+ **************************************************************************/
+
+#define RULE_MAX    10
+#define ZTE_ROUTER_FW_PORT_LEN 6
+#define ZTE_ROUTER_FW_FLAG_LEN 4
+#define ZTE_ROUTER_WAN_IF_NAME_LEN 20
+#define ZTE_ROUTER_IP_ADDR_LEN 32
+#define ZTE_ROUTER_IPV6_ADDR_LEN 64
+
+#define ZTE_FW_IP_ADDR_LEN_V6  45
+
+#define ROUTER_DEFAULT_LEN 64
+#define ZTE_ROUTER_URL_FILTER_LEN     512
+#define MAX_OLD_URLS_COUNT            100
+#define NV_MACIP_LIST_MAX_LEN 500     //zte_mac_list_run
+#define ROUTER_NV_ITEM_VALUE_MAX_LEN 256
+#define ROUTER_NV_FW_RULE_MAX_LEN 300
+#define IPPORT_FILTER_CHAIN      "macipport_filter"
+#define VPN_CHAIN                "vpn_filter"
+#define PORT_FORWARD_CHAIN       "port_forward"
+#define WEB_FILTER_CHAIN         "web_filter"
+#define DMZ_CHAIN                 "DMZ"
+#define PORT_MAPPING_CHAIN       "port_mapping"
+
+#define CLILDREN_MAC_CHAIN       "children_filter"
+#define CLILDREN_WEB_CHAIN       "children_web_filter"
+#define CLILDREN_WEB_PHONE_CHAIN       "children_web_filter_phone"
+
+#define ACTION_DROP 0
+#define ACTION_ACCEPT   1
+
+#define PROTO_UNKNOWN   0
+#define PROTO_TCP   1
+#define PROTO_UDP   2
+#define PROTO_TCP_UDP   3
+#define PROTO_ICMP  4
+#define PROTO_NONE  5
+
+#define CONFIG_DEFAULT_LENGTH  64
+#define NV_QOS_LIST_MAX_LEN 500
+#define NV_STATIC_ROUTE_LIST_MAX_LEN 1500
+
+#define ConnectWaitTime 180000 //1000=1s
+#define StateTimerID 68 //timer ID
+#define WaitTime 10000 //1000=1s
+
+#define FMT_ECHO_IPTABLES_CMD "1>/dev/null 2>&1"
+
+#define MAINCTRL_LOCK "mainctrl_lock"
+
+/**************************************************************************
+ *                            Global Struct                               *
+ **************************************************************************/
+typedef enum {
+	TIMER_MainCtrl_NvSaveID = 60,   /*NvÖÜÆÚsave¶¨Ê±Æ÷ ID*/
+	TIMER_MainCtrl_NetID = 66,      /*Íø¿Ú¶¨Ê±Æ÷ID*/
+	/*ºóÃæ²»ÄÜÔÙÌí¼Óеģ¬Ö»ÄÜÍùǰ¼Ó: ÒòÎªÍø¿Ú¶¨Ê±Æ÷IDÉè¼ÆÊÇ+devIdÖµ£¬Íùºó¼Ó»áÖØ¸´*/
+} T_emMainCtrl_SoftTimerId;
+
+struct url_list {
+	int count;
+	char url_list[MAX_OLD_URLS_COUNT][ZTE_ROUTER_URL_FILTER_LEN];
+};
+
+/*struct mac_hostname{
+    char mac[18];
+    char hostname[500];
+};*/
+
+struct mainctrl_notify_queue {
+	struct list_head list;
+	int notify_id;
+};
+
+extern char ps_wan[ZTE_ROUTER_WAN_IF_NAME_LEN];
+extern char usb_wan[ZTE_ROUTER_WAN_IF_NAME_LEN];
+extern char eth_wan[ZTE_ROUTER_WAN_IF_NAME_LEN];
+extern char wifi_wan[ZTE_ROUTER_WAN_IF_NAME_LEN];
+extern unsigned char ethwan_id; //ÓÃÓÚRJ45ÍâÍø¿ÚµÄ³¬Ê±´¦Àí
+extern unsigned char wifiwan_id;//ÓÃÓÚwifiÍâÍø¿ÚµÄ³¬Ê±´¦Àí
+
+extern char g_router_nvconfig_buf[ROUTER_NV_ITEM_VALUE_MAX_LEN];
+extern char defwan_rel[ZTE_ROUTER_WAN_IF_NAME_LEN];
+
+extern int g_mainctrl_factory_reset;
+extern int g_mainctrl_reset_ext_cmd;
+extern int g_mainctrl_poweroff_ext_cmd;
+extern int g_mainctrl_restart_ext_cmd;
+extern struct list_head g_mainctrl_reset_notify;
+extern struct list_head g_mainctrl_poweroff_notify;
+extern struct list_head g_mainctrl_restart_notify;
+
+/********************netdev_proc.c    start********************************/
+extern int net_pdp_act_proc(struct pdp_active_info *actinfo);
+extern int net_pdp_deact_proc(int c_id, unsigned char ip46flag);
+extern int net_netdev_connect_internet(unsigned char netdev_id);
+extern int net_netdev_disconnect_internet(unsigned char netdev_id);
+extern int net_netdev_plugin_proc(unsigned char netdev_id);
+extern int net_netdev_plugout_proc(unsigned char netdev_id);
+extern int net_tc_control(struct tc_control_info *tcinfo,int src_id);
+extern void proc_wan_change_v4(void);
+extern void proc_wan_change_v6(void);
+extern void out_of_time(unsigned char netdev_id);
+extern void deletetimer(unsigned char netdev_id);
+extern void creattimer(unsigned char* netdev_id);
+extern int pdp_act_check(struct pdp_active_info *actinfo);
+extern void set_pdp_mode(int c_id, unsigned char pdp_type);
+extern void set_pdp_act_type(int c_id, unsigned char ip46flag);
+extern int pdp_wan_config(struct pdp_active_info *actinfo);
+extern int pdp_direct_config(struct pdp_active_info *actinfo);
+extern int pdp_ppp_config(struct pdp_active_info *actinfo);
+extern void reset_pdp_mode(int c_id);
+extern void eth_connect();
+extern void wifi_connect();
+extern void vlan_config(unsigned int sw_type, char* act);
+extern void ethwan_plugin();
+extern void ethlan_plugin();
+extern void ethwan_plugout();
+extern void ethlan_plugout();
+extern void wifi_plugin();
+extern void net_default_wan_proc(struct default_dev_info *dev);
+/********************netdev_proc.c    end********************************/
+
+/********************net_xfrm.c    start********************************/
+extern void zte_router_init(void);
+extern int getNthValueSafe(int index, char *value, char delimit, char *result, int len);
+extern void zte_iptables_Webs_Filter_Run(void);
+extern void zte_iptables_port_map_all_run(void);
+extern void zte_iptables_DMZ_Run(void);
+extern void zte_iptables_sys_fw_run(void);
+extern void zte_iptables_port_forward_run(void);
+extern void zte_iptables_filter_run(void);
+extern void zte_iptables_filter_run_v6(void);
+extern void system_cmd_ex(char * cmd);
+extern void zte_iptables_child_filter_run();
+extern void zte_router_ping_diagnostics(void);
+
+
+/********************net_xfrm.c    end********************************/
+
+/********************net_other.c    start********************************/
+extern void zte_router_MTU_set(void);
+extern void zte_unpn_set(void);
+extern void zte_router_dhcp_set_process(void);
+extern void alg_control_fun();
+extern void zte_router_mtu_set_process(void);
+
+extern void get_mac_hostname_pro(struct mac_hostname_info *mac_hostname_);
+extern void zte_macip_list_run(void);
+extern void zte_bind_macip_list(void);
+extern void zte_bind_macip_list_add(struct static_macip_info *static_macip);
+extern void zte_bind_macip_list_del(char* mac);
+extern void children_device_add(struct mac_hostname_info *mac_hostname);
+extern void children_device_del(char* mac);
+extern void white_site_add(struct white_site_info *white_site);
+extern void white_site_remove(char* ids);
+extern void zte_children_start_nonet(void);
+extern void zte_children_stop_nonet(void);
+extern void zte_router_dhcp_setting_req_process(dhcp_setting_req *pdhcp_setting_req);
+/********************net_other.c    end********************************/
+
+int pppoe_encrypt_code(void);
+int pppoe_decrypt_code(void);
+int pppoe_aes_init(void);
+
+#endif