[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/lib/libsoftap/Makefile b/ap/lib/libsoftap/Makefile
new file mode 100755
index 0000000..51326eb
--- /dev/null
+++ b/ap/lib/libsoftap/Makefile
@@ -0,0 +1,38 @@
+#*******************************************************************************
+# include ZTE library makefile
+#*******************************************************************************
+include $(COMMON_MK)
+
+##############USER COMIZE BEGIN################
+
+LIB_STATIC = libsoftap.a
+LIB_SHARED = libsoftap.so
+
+OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
+
+#CFLAGS += -I$(zte_app_path)/at_ctl/inc
+#CFLAGS += -I$(zte_lib_path)/libatutils
+CFLAGS += -I$(LINUX_DIR)/include
+CFLAGS += -g
+
+
+##############USER COMIZE END##################
+
+CFLAGS += -I$(zte_app_path)/include
+CFLAGS += -fPIC
+LDFLAGS += -shared
+
+all: $(LIB_STATIC) $(LIB_SHARED)
+
+$(LIB_STATIC) : $(OBJS)
+	$(AR) rcs $(LIB_STATIC) $(OBJS)
+
+$(LIB_SHARED): $(OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^
+
+romfs:
+	$(ROMFSINST) $(LIB_SHARED) /lib/$(LIB_SHARED)
+
+clean:
+	-$(RM) *.a *.o *.so $(LIB_SHARED) $(LIB_STATIC) $(OBJS)
+
diff --git a/ap/lib/libsoftap/audio_res_request_api.c b/ap/lib/libsoftap/audio_res_request_api.c
new file mode 100755
index 0000000..fa800a3
--- /dev/null
+++ b/ap/lib/libsoftap/audio_res_request_api.c
@@ -0,0 +1,115 @@
+/**
+* @File: codec_res_request_api.c
+* @Brief: Implementation of Device Manager in Sanechips
+*
+* Copyright (C) 2017 Sanechips Technology Co., Ltd.
+* @Author: chen.tianming@zte.com.cn
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+* */
+
+/*******************************************************************************
+ *						    Í·Îļþ   	          					        *
+******************************************************************************/
+#include<stdio.h>
+#include<stdlib.h>
+#include<sys/msg.h>
+#include<errno.h>
+#include<pthread.h>
+#include<string.h>
+#include"softap_api.h"
+	
+/*******************************************************************************
+ *							   ºê¶¨Òå								   *
+ ******************************************************************************/
+
+/*******************************************************************************
+ *							   Êý¾ÝÀàÐͶ¨Òå 							   *
+ ******************************************************************************/
+ 
+/*******************************************************************************
+ *							   ½Ó¿Ú¶¨Òå 								   *
+ ******************************************************************************/
+
+/**
+ *º¯Êý˵Ã÷£ºÇëÇóʹÓÃaudio×ÊÔ´½Ó¿Ú
+ *²ÎÊý˵Ã÷: @	reqParam Èë²ÎÊý£¬°üÀ¨ÇëÇóµÄÒµÎñ£¬Ä£¿éºÅ£»
+ 		   @spData ³ö²Î,·´Ó³µ±Ç°µÄÖ÷¿ØµÄ״̬¡£
+ *·µ»ØÖµ£º  true ÉêÇë³É¹¦£»
+ 		   false ÉêÇëʧ°Ü(¶ÔÓÚ»ìÒôµÈÏà¹Ø²Ù×÷£¬ÅäºÏ³ö²Î)	  
+ *±¸×¢£º    
+ */
+BOOL audio_resource_request(T_audio_Res_Request *reqParam, T_audio_UseRsp *RspData)
+{
+	int tempQueueId = -1;
+	MSG_BUF msg = {0};
+	long msgSize = 0;
+	T_audio_UseReq useReqData = {0}; 
+	int moduleIdTmp = MODULE_ID_AP_AUDIODYNAMIC_BASE;//ÄÚ²¿¶¯Ì¬»ñȡԴģ¿éID£¬³õʼֵΪMODULE_ID_AP_AUDIODYNAMIC_BASE
+	
+	if(!reqParam || !RspData) {
+		softap_assert("audio_resource_request function: input param is null \n");
+		return FALSE;
+	}
+	/* ´´½¨ÏûÏ¢¶ÓÁУ¬´ËÏûÏ¢¶ÓÁÐÁÙʱÐÔ£¬Ê¹ÓÃÍêºóɾ³ý */
+//	if(-1 == (tempQueueId = msgget(reqParam->tempMouduleId, IPC_CREAT | IPC_EXCL))) 
+//		softap_assert("audio_resource_request function: create Message queue Error£º%s", strerror(errno));
+
+	/* ´´½¨ÏûÏ¢¶ÓÁУ¬´ËÏûÏ¢¶ÓÁÐÁÙʱÐÔ£¬Ê¹ÓÃÍêºóɾ³ý */
+	while((tempQueueId = msgget(moduleIdTmp,IPC_CREAT | IPC_EXCL| 0600)) < 0)
+	{
+	    moduleIdTmp++;
+		if (moduleIdTmp > MODULE_ID_AP_AUDIODYNAMIC_END) {
+			//µ±module_id´óÓÚMODULE_ID_AP_AUDIODYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ
+			softap_assert("audio dynamatic msg queue too many now !!!!!!!!");
+		}
+	}
+
+	/* ×é×°ÏûÏ¢·¢Ë͸øaudio Ö÷¿Ø, ²¢µÈ´ýÖ÷¿Ø¸ø³öÃ÷È·´ð¸´ */
+	useReqData.type = reqParam->audioType;
+	useReqData.moduleId = reqParam->moduleId;
+	useReqData.tempModuleId = moduleIdTmp;
+	if(0 > platform_send_msg(moduleIdTmp, MODULE_ID_CODEC, USE_AUDIO_REQ, sizeof(T_audio_UseReq), (unsigned char *)&useReqData)) 	
+		softap_assert("audio_resource_request function: Send USE_AUDIO_REQ msg Error: %s", strerror(errno));
+ 
+	/*µÈ´ýaudioÖ÷¿Ø»Ø¸´ */
+	while(1)
+	{
+		/*»ñÈ¡ÏûÏ¢½øÐд¦Àí*/
+		memset(&msg,0, sizeof(MSG_BUF));
+		msgSize = sizeof(MSG_BUF) - sizeof(long);
+		if(0 > msgrcv(tempQueueId, &msg, msgSize, 0, 0))
+			softap_assert("audio_resource_request function: Rec msg Error %s\n", strerror(errno));
+
+		slog(RTC_PRINT, SLOG_NORMAL, "audio_resource_request function: Rec msg now:tempModuleId(%x), srcId(%x), dstId(%x), msgCmd(%d)\n", moduleIdTmp,msg.src_id, msg.dst_id, msg.usMsgCmd);
+		/*ÏûÏ¢´¦Àí */
+		if(USE_AUDIO_RSP == msg.usMsgCmd)
+		{
+			T_audio_UseRsp *serverResData =(T_audio_UseRsp *) msg.aucDataBuf;
+			RspData->result = serverResData->result;
+			RspData->type = serverResData->type;
+			RspData->using_type = serverResData->using_type;
+			slog(RTC_PRINT, SLOG_NORMAL, "audio_resource_request function: get debug info:  RspData->resul(%d), using_type(%d)\n ", RspData->result, serverResData->using_type);
+
+			/* ɾ³ýÏûÏ¢¶ÓÁÐ */
+			if(0 > msgctl(tempQueueId, IPC_RMID, 0))
+			{
+				slog(RTC_PRINT, SLOG_NORMAL,"error num(%d): error case:%s",errno,strerror(errno));
+			}
+			if(0 == serverResData->result)	// success	
+			{					
+				return TRUE;
+			} 
+			else  
+			{  
+				slog(RTC_PRINT, SLOG_NORMAL, "audio res request fail now:  using_type(%d)\n",serverResData->using_type);
+				return FALSE;
+			}
+
+		}
+		
+	}
+
+}
diff --git a/ap/lib/libsoftap/ipsec_api.c b/ap/lib/libsoftap/ipsec_api.c
new file mode 100644
index 0000000..377ac46
--- /dev/null
+++ b/ap/lib/libsoftap/ipsec_api.c
@@ -0,0 +1,646 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include <unistd.h>

+#include <string.h>

+#include <errno.h>

+#include <arpa/inet.h>

+#include <linux/netlink.h>

+#include <linux/socket.h>

+#include <sys/socket.h>

+#include <syslog.h>

+#include <sys/klog.h>

+#include <stdarg.h>

+#include "ipsec_api.h"

+#include <assert.h>

+

+static void LOG_PRINT(int priority, const char* fmt, ...)

+{

+    va_list args = {0};

+	char buff[512];

+	memset(buff, 0x00, sizeof(buff));

+    va_start(args, fmt); 

+	vsnprintf(buff, sizeof(buff), fmt, args);

+	va_end(args);  

+	syslog(priority,"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%s", buff); 

+	printf("%s\n", buff);

+	

+}

+

+//ÓÉÓÚiprouteÖв»´æÔÚ½«¡°udp¡±¡¢¡°tcp¡±×Ô¶¯×ª»»ÎªÏàÓ¦´«Êä²ãЭÒéºÅµÄ¹¦ÄÜ£¬Òò´ËÔÚÅäÖÃipsecʱ£¬Ö±½ÓʹÓô«Êä²ãЭÒéºÅÅäÖÃproto²ÎÊý

+int ipsec_set(int s, void *data, int datalen)

+{

+

+	ipsec_set_msg *set_msg = (ipsec_set_msg *)data;

+	unsigned short client_port, server_port;

+	int spi;

+	char * source_addr, *dest_addr, *auth_key, *crypto_key, *xfrmproto, *mode, *ealg, *alg, *dir;

+	char cmd[512];

+	

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set:socket s is not legal");

+		return -1;		

+	}

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set:data is not legal");

+		return -1;

+	}

+	

+	if(datalen != sizeof(ipsec_set_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set:The length of msg is not legal");

+		return -1;

+	}

+

+	crypto_key = set_msg->Ckey;

+	xfrmproto = set_msg->Prot;

+	mode = set_msg->Mod;

+	ealg = set_msg->Ealg;

+	alg = set_msg->Alg;

+	dir = set_msg->dir;

+	auth_key = set_msg->Ikey;

+	client_port = set_msg->PortC;

+	server_port = set_msg->PortS;

+	spi = set_msg->Spi;

+	

+	if (1 == set_msg->IsIpv4)

+	{

+		source_addr = set_msg->SrcIpv4;

+		dest_addr = set_msg->DestIpv4;

+	}

+	else

+	{

+		source_addr = set_msg->SrcIpv6;

+		dest_addr = set_msg->DestIpv6;

+	}

+	

+	if(0 == strcmp(alg,"hmac-md5-96"))

+	{

+		memset(alg,0x00,strlen(alg));

+		sprintf(alg,"md5");

+	}

+	else if (0 == strcmp(alg,"hmac-sha-1-96"))

+	{

+		memset(alg,0x00,strlen(alg));

+		sprintf(alg,"sha1");

+	}

+	else

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set:ONLY support md5 and sha1 algorithm now, alg %s is not valid",alg);

+		return -1;

+	}

+	

+	if(0 == strcmp(ealg,"aes-cbc"))

+	{

+		memset(ealg,0x00,strlen(ealg));

+		sprintf(ealg,"aes");

+	}

+	else if(0 == strcmp(ealg,"des-ede3-cbc"))

+	{

+		memset(ealg,0x00,strlen(ealg));

+		sprintf(ealg,"des3_ede");

+	}

+	else if(0 == strcmp(ealg,"null"))

+	{

+		memset(ealg,0x00,strlen(ealg));

+		sprintf(ealg,"cipher_null");

+		memset(crypto_key,0x00,strlen(crypto_key));

+		sprintf(crypto_key,"\"\"");

+	}

+	else

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set:ONLY support aes-cbc£¬des-ede3-cbc and null three crypto algorithm, the alg %s is not valid", ealg);

+		return -1;

+	}

+	

+	memset(cmd, 0x00, sizeof(cmd)); 

+	if(0 != strcmp(ealg,"cipher_null"))

+	{

+		sprintf(cmd, "ip xfrm state add src %s dst %s proto %s spi 0x%x  auth %s 0x%s enc %s 0x%s mode %s", 

+								source_addr, dest_addr, xfrmproto, spi, alg,auth_key, ealg,crypto_key, mode);

+	}

+	else

+	{

+		sprintf(cmd, "ip xfrm state add src %s dst %s proto %s spi 0x%x  auth %s 0x%s enc %s %s mode %s", 

+								source_addr, dest_addr, xfrmproto, spi, alg,auth_key, ealg,crypto_key, mode);

+	}

+	soft_system(cmd);

+

+	LOG_PRINT(LOG_ALERT,"ipsec_set:%s\n", cmd);

+	

+	memset(cmd, 0x00, sizeof(cmd)); 

+	//ÅäÖÃudpЭÒéipsec²ÎÊý£¬udp´«Êä²ãЭÒéºÅΪ17

+	sprintf(cmd, "ip xfrm policy add dir %s src %s dst %s proto 17 sport %d dport %d ptype main tmpl src %s dst %s proto esp spi %d mode transport",

+		                                dir, source_addr, dest_addr, client_port, server_port, source_addr, dest_addr, spi);

+	soft_system(cmd);

+	LOG_PRINT(LOG_ALERT,"ipsec_set:%s\n", cmd);

+	

+	memset(cmd, 0x00, sizeof(cmd)); 

+	//ÅäÖÃtcpЭÒéipsec²ÎÊý£¬tcp´«Êä²ãЭÒéºÅΪ6

+	sprintf(cmd, "ip xfrm policy add dir %s src %s dst %s proto 6 sport %d dport %d ptype main tmpl src %s dst %s proto esp spi %d mode transport",

+		                                dir, source_addr, dest_addr, client_port, server_port, source_addr, dest_addr, spi);

+	soft_system(cmd);

+	

+	LOG_PRINT(LOG_ALERT,"ipsec_set:%s\n", cmd);

+	

+	

+	return 0;

+}

+

+

+int ipsec_del(int s, void *data, int datalen)

+{

+	ipsec_del_msg * p_del_msg = (ipsec_del_msg *)data;

+	ipsec_del_msg * del_msg = NULL;

+	unsigned short client_port, server_port;

+	int spi, i;

+	char * source_addr, *dest_addr, *auth_key, *crypto_key, *xfrmproto, *mode, *ealg, *alg, *dir;

+	char cmd[512];

+	

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del:socket s is not legal");

+		return -1;		

+	}

+	

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del:data is not legal");

+		return -1;

+	}

+	

+	if( 0!= datalen%sizeof(ipsec_del_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del:The length of msg is not legal");

+		return -1;

+	}

+	

+

+	for(i = 0;i<datalen/sizeof(ipsec_del_msg);i++)

+	{

+		del_msg = p_del_msg+i;

+

+		crypto_key = del_msg->Ckey;

+		xfrmproto = del_msg->Prot;

+		mode = del_msg->Mod;

+		ealg = del_msg->Ealg;

+		alg = del_msg->Alg;

+		dir = del_msg->dir;

+		auth_key = del_msg->Ikey;

+		client_port = del_msg->PortC;

+		server_port = del_msg->PortS;

+		spi = del_msg->Spi;

+		

+		if (1 == del_msg->IsIpv4)

+		{

+			source_addr = del_msg->SrcIpv4;

+			dest_addr = del_msg->DestIpv4;

+		}

+		else

+		{

+			source_addr = del_msg->SrcIpv6;

+			dest_addr = del_msg->DestIpv6;

+		}

+		

+		memset(cmd, 0x00, sizeof(cmd)); 

+		

+		sprintf(cmd,"ip xfrm state delall spi 0x%x",spi);

+		soft_system(cmd);

+

+		LOG_PRINT(LOG_ALERT,"ipsec_del:%s\n", cmd);

+		

+		memset(cmd, 0x00, sizeof(cmd)); 

+		//ɾ³ýudpЭÒéipsecÅäÖÃ

+		sprintf(cmd, "ip xfrm policy delall dir %s src %s dst %s proto 17 sport %d dport %d",dir, source_addr, dest_addr, client_port, server_port);

+		soft_system(cmd);

+		LOG_PRINT(LOG_ALERT,"ipsec_del:%s\n", cmd);

+		

+		memset(cmd, 0x00, sizeof(cmd)); 

+		//ɾ³ýtcpЭÒéipsecÅäÖÃ

+		sprintf(cmd, "ip xfrm policy delall dir %s src %s dst %s proto 6 sport %d dport %d ",dir, source_addr, dest_addr, client_port, server_port);

+		soft_system(cmd);

+		

+		LOG_PRINT(LOG_ALERT,"ipsec_del:%s\n", cmd);

+	}

+	return 0;

+}

+

+#if 0

+int ipsec_set_sa(int s, void *data, int datalen)

+{

+	

+	ipsec_set_sa_msg * set_sa_msg = (ipsec_set_sa_msg *)data;

+	int spi;

+	char * source_addr, *dest_addr, *auth_key, *crypto_key, *xfrmproto, *mode, *ealg, *alg;

+	char cmd[512];

+	

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sa:socket s is not legal");

+		return -1;		

+	}

+	

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sa:data is not legal");

+		return -1;

+	}

+	

+	if(datalen != sizeof(ipsec_set_sa_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sa:The length of msg is not legal");

+		return -1;

+	}

+	

+	crypto_key = set_sa_msg->Ckey;

+	xfrmproto = set_sa_msg->XfrmProt;

+	mode = set_sa_msg->Mod;

+	ealg = set_sa_msg->Ealg;

+	alg = set_sa_msg->Alg;

+	auth_key = set_sa_msg->Ikey;

+	spi = set_sa_msg->Spi;

+	

+	if (1 == set_sa_msg->IsIpv4)

+	{

+		source_addr = set_sa_msg->SrcIpv4;

+		dest_addr = set_sa_msg->DestIpv4;

+	}

+	else

+	{

+		source_addr = set_sa_msg->SrcIpv6;

+		dest_addr = set_sa_msg->DestIpv6;

+	}

+	

+	if(0 == strcmp(alg,"hmac-md5-96"))

+	{

+		memset(alg,0x00,sizeof(alg));

+		sprintf(alg,"md5");

+	}

+	else if (0 == strcmp(alg,"hmac-sha-1-96"))

+	{

+		memset(alg,0x00,sizeof(alg));

+		sprintf(alg,"sha1");

+	}

+	else

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sa:ONLY support md5 and sha1 algorithm now, alg %s is not valid",alg);

+		return -1;

+	}

+	

+	if(0 == strcmp(ealg,"aes-cbc"))

+	{

+		memset(ealg,0x00,sizeof(ealg));

+		sprintf(ealg,"aes");

+	}

+	else if(0 == strcmp(ealg,"des-ede3-cbc"))

+	{

+		memset(ealg,0x00,sizeof(ealg));

+		sprintf(ealg,"des3_ede");

+	}

+	else if(0 == strcmp(ealg,"null"))

+	{

+		memset(ealg,0x00,sizeof(ealg));

+		sprintf(ealg,"cipher_null");

+		memset(crypto_key,0x00,sizeof(crypto_key));

+		sprintf(crypto_key,"\"\"");

+	}

+	else

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sa:ONLY support aes-cbc£¬des-ede3-cbc and null three crypto algorithm, the alg %s is not valid", ealg);

+		return -1;

+	}

+	

+	memset(cmd, 0x00, sizeof(cmd)); 

+	if(0 != strcmp(ealg,"cipher_null"))

+	{

+		sprintf(cmd, "ip xfrm state add src %s dst %s proto %s spi 0x%x auth %s 0x%s enc %s 0x%s mode %s", 

+								source_addr, dest_addr, xfrmproto, spi, alg,auth_key, ealg,crypto_key, mode);

+	}

+	else

+	{

+		sprintf(cmd, "ip xfrm state add src %s dst %s proto %s spi 0x%x  auth %s 0x%s enc %s %s mode %s", 

+								source_addr, dest_addr, xfrmproto, spi, alg,auth_key, ealg, crypto_key, mode);

+	}

+	system(cmd);

+

+	LOG_PRINT(LOG_ALERT,"ipsec_set_sa:%s\n", cmd);

+	return 0;

+}

+

+

+int ipsec_set_sp(int s, void *data, int datalen)

+{

+	ipsec_set_sp_msg * set_sp_msg = (ipsec_set_sp_msg *)data;

+	unsigned short client_port, server_port;

+	int  proto;

+	char * source_addr, *dest_addr, *dir;

+	char cmd[512], cmd_tcp[512];

+	int offset = 0, offset_tcp = 0;

+

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sp:socket s is not legal");

+		return -1;		

+	}

+	

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sp:data is not legal");

+		return -1;

+	}

+	

+	if(datalen != sizeof(ipsec_set_sp_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:The length of msg is not legal");

+		return -1;

+	}

+	

+	proto = set_sp_msg->Prot;

+	dir = set_sp_msg->dir;

+	client_port = set_sp_msg->PortC;

+	server_port = set_sp_msg->PortS;

+	if (1 == set_sp_msg->IsIpv4)

+	{

+		source_addr = set_sp_msg->SrcIpv4;

+		dest_addr = set_sp_msg->DestIpv4;

+	}

+	else

+	{

+		source_addr = set_sp_msg->SrcIpv6;

+		dest_addr = set_sp_msg->DestIpv6;

+	}

+	

+

+	if( proto < IPSEC_PROTO_BASE || proto > IPSEC_PROTO_MAX)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sp:ipsec protocol only support tcp and udp now!\n");

+		return -1;

+	}

+	

+	memset(cmd, 0x00, sizeof(cmd));

+

+	offset += sprintf(cmd + offset, "ip xfrm policy add ");

+	

+	if( 0 != strlen(dir))

+	{

+		offset += sprintf(cmd + offset,"dir %s ", dir);

+	}

+

+	if( 0 != strlen(source_addr))

+	{

+			offset += sprintf(cmd + offset, "src %s ", source_addr);

+	}

+

+	if( 0 != strlen(dest_addr))

+	{

+			offset += sprintf(cmd + offset, "dst %s ", dest_addr);

+	}

+

+	if( (IPSEC_PROTO_UNKOWN == proto) && (client_port || server_port))

+	{

+

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sp:ipsec_del_sp : msg must have protocol messages when port is not equal to zero!\n");

+		return -1;

+		

+	}

+	else if( IPSEC_PROTO_UNKOWN == proto)

+	{

+		system(cmd);

+		LOG_PRINT(LOG_ALERT,"ipsec_set_sp:%s\n", cmd);

+	}

+	else

+	{

+		offset_tcp += sprintf(cmd_tcp + offset_tcp, "%s",cmd);

+		

+		if( proto&IPSEC_PROTO_UDP)

+		{

+			offset += sprintf(cmd + offset, "proto 17 ");

+			if(client_port)

+			{

+				offset += sprintf(cmd + offset,"sport %d ", client_port);

+			}

+			if(server_port)

+			{

+				offset += sprintf(cmd + offset,"dport %d ", server_port);

+			}

+			system(cmd);

+			LOG_PRINT(LOG_ALERT,"ipsec_set_sp:%s\n", cmd);

+		}

+

+		if(proto&IPSEC_PROTO_TCP)

+		{

+			offset_tcp += sprintf(cmd_tcp + offset_tcp, "proto 6 ");

+			if(client_port)

+			{

+				offset_tcp += sprintf(cmd_tcp + offset_tcp,"sport %d ", client_port);

+			}

+			if(server_port)

+			{

+				offset_tcp += sprintf(cmd_tcp + offset_tcp,"dport %d ", server_port);

+			}

+			system(cmd_tcp);

+			LOG_PRINT(LOG_ALERT,"ipsec_set_sp:%s\n", cmd_tcp);

+		}

+	}

+	return 0;

+}

+

+int ipsec_del_sa(int s, void *data, int datalen)

+{

+	ipsec_del_sa_msg * del_sa_msg = (ipsec_del_sa_msg *)data;

+	int spi;

+	char * source_addr, *dest_addr,  *xfrmproto, *mode;

+	int offset = 0;

+	char cmd[512];

+	

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sa:socket s is not legal");

+		return -1;		

+	}

+	

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sa:data is not legal");

+		return -1;

+	}

+	

+	if(datalen != sizeof(ipsec_del_sa_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sa:The length of msg is not legal");

+		return -1;

+	}

+	

+	xfrmproto = del_sa_msg->XfrmProt;

+	mode = del_sa_msg->Mod;

+	spi = del_sa_msg->Spi;

+	

+	if (1 == del_sa_msg->IsIpv4)

+	{

+		source_addr = del_sa_msg->SrcIpv4;

+		dest_addr = del_sa_msg->DestIpv4;

+	}

+	else

+	{

+		source_addr = del_sa_msg->SrcIpv6;

+		dest_addr = del_sa_msg->DestIpv6;

+	}

+

+

+	memset(cmd, 0x00, sizeof(cmd));

+

+

+	offset += sprintf(cmd + offset, "ip xfrm state delall ");

+

+	if( 0 != strlen(source_addr))

+	{

+		offset += sprintf(cmd + offset, "src %s ",source_addr);

+	}

+

+	if( 0 != strlen(dest_addr))

+	{

+		offset += sprintf(cmd + offset, "dst %s ",dest_addr);

+	}

+

+	if( 0 != strlen(xfrmproto))

+	{

+		offset += sprintf(cmd + offset, "proto %s ", xfrmproto);

+	}

+

+	if( 0 != spi)

+	{

+		offset += sprintf(cmd + offset, "spi 0x%x ",spi);

+	}

+

+	if( 0 != strlen(mode))

+	{

+		offset += sprintf(cmd + offset, "mode %s ", mode);

+	}

+	

+	system(cmd);

+

+	LOG_PRINT(LOG_ALERT,"ipsec_del_sa:%s\n", cmd);

+	

+	return 0;

+

+}

+

+

+int ipsec_del_sp(int s, void *data, int datalen)

+{

+	ipsec_del_sp_msg * del_sp_msg = (ipsec_del_sp_msg *)data;

+	unsigned short client_port, server_port;

+	int  proto;

+	char * source_addr, *dest_addr, *dir;

+	char cmd[512], cmd_tcp[512];

+	int offset = 0, offset_tcp = 0;

+

+	if(s < 0)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:socket s is not legal");

+		return -1;		

+	}

+	

+	if (data == NULL)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:data is not legal");

+		return -1;

+	}

+	

+	if(datalen != sizeof(ipsec_del_sp_msg))

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:The length of msg is not legal");

+		return -1;

+	}

+	

+	proto = del_sp_msg->Prot;

+	dir = del_sp_msg->dir;

+	client_port = del_sp_msg->PortC;

+	server_port = del_sp_msg->PortS;

+	if (1 == del_sp_msg->IsIpv4)

+	{

+		source_addr = del_sp_msg->SrcIpv4;

+		dest_addr = del_sp_msg->DestIpv4;

+	}

+	else

+	{

+		source_addr = del_sp_msg->SrcIpv6;

+		dest_addr = del_sp_msg->DestIpv6;

+	}

+	

+

+	if( proto < IPSEC_PROTO_BASE || proto > IPSEC_PROTO_MAX)

+	{

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:ipsec protocol only support tcp and udp now!\n");

+		return -1;

+	}

+	

+	memset(cmd, 0x00, sizeof(cmd));

+

+	offset += sprintf(cmd + offset, "ip xfrm policy delall ");

+	

+	if( 0 != strlen(dir))

+	{

+		offset += sprintf(cmd + offset,"dir %s ", dir);

+	}

+

+	if( 0 != strlen(source_addr))

+	{

+			offset += sprintf(cmd + offset, "src %s ", source_addr);

+	}

+

+	if( 0 != strlen(dest_addr))

+	{

+			offset += sprintf(cmd + offset, "dst %s ", dest_addr);

+	}

+

+	if( (IPSEC_PROTO_UNKOWN == proto) && (client_port || server_port))

+	{

+

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:ipsec_del_sp : msg must have protocol messages when port is not equal to zero!\n");

+		return -1;

+		

+	}

+	else if( IPSEC_PROTO_UNKOWN == proto)

+	{

+		system(cmd);

+		LOG_PRINT(LOG_ALERT,"ipsec_del_sp:%s\n", cmd);

+	}

+	else

+	{

+		offset_tcp += sprintf(cmd_tcp + offset_tcp, "%s",cmd);

+		

+		if( proto&IPSEC_PROTO_UDP)

+		{

+			offset += sprintf(cmd + offset, "proto 17 ");

+			if(client_port)

+			{

+				offset += sprintf(cmd + offset,"sport %d ", client_port);

+			}

+			if(server_port)

+			{

+				offset += sprintf(cmd + offset,"dport %d ", server_port);

+			}

+			system(cmd);

+			LOG_PRINT(LOG_ALERT,"ipsec_del_sp:%s\n", cmd);

+		}

+

+		if(proto&IPSEC_PROTO_TCP)

+		{

+			offset_tcp += sprintf(cmd_tcp + offset_tcp, "proto 6 ");

+			if(client_port)

+			{

+				offset_tcp += sprintf(cmd_tcp + offset_tcp,"sport %d ", client_port);

+			}

+			if(server_port)

+			{

+				offset_tcp += sprintf(cmd_tcp + offset_tcp,"dport %d ", server_port);

+			}

+			system(cmd_tcp);

+			LOG_PRINT(LOG_ALERT,"ipsec_del_sp:%s\n", cmd_tcp);

+		}

+	}

+	return 0;

+}

+#endif

diff --git a/ap/lib/libsoftap/netapi.c b/ap/lib/libsoftap/netapi.c
new file mode 100755
index 0000000..7b47c06
--- /dev/null
+++ b/ap/lib/libsoftap/netapi.c
@@ -0,0 +1,593 @@
+/**
+ * @file Netapi.c
+ * @brief Implementation of Sanechips
+ *
+ * Copyright (C) 2017 Sanechips Technology Co., Ltd.
+ * @author linxu Gebin
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <syslog.h>
+#include <sys/klog.h>
+#include <sys/msg.h>
+#include <sys/socket.h>
+#include <linux/sockios.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "softap_api.h"
+#include <net/if.h>
+
+/************************ ÍøÂç½Ó¿Ú ************************/
+
+
+
+//¸ù¾ÝÍøÂçÉ豸Ãû»ñÈ¡¶ÔÓ¦µÄÉ豸ID,°´ÕÕÓÅÏȼ¶ÓëNVÖеÄÉ豸Ãû½øÐÐÆ¥Å䣬ʧ°Ü·µ»Ø-1
+int getDevId_byname(char *dev_name)
+{
+	char ps_wan[NETIF_NAME_LEN] = {0};
+	char psext_wan1[NETIF_NAME_LEN] = {0};
+	char psext_wan2[NETIF_NAME_LEN] = {0};
+	char psext_wan3[NETIF_NAME_LEN] = {0};
+	char psext_wan4[NETIF_NAME_LEN] = {0};
+	char psext_wan5[NETIF_NAME_LEN] = {0};
+	char psext_wan6[NETIF_NAME_LEN] = {0};
+	char psext_wan7[NETIF_NAME_LEN] = {0};
+	char psext_wan8[NETIF_NAME_LEN] = {0};
+	char swwanstr[NETIF_NAME_LEN] = {0};
+	char swlanstr[NETIF_NAME_LEN] = {0};
+	char eth_wan[NETIF_NAME_LEN] = {0};
+	char wifi_wan[NETIF_NAME_LEN] = {0};
+	char eth_lan[NETIF_NAME_LEN] = {0};
+	char wifi_lan[NETIF_NAME_LEN] = {0};
+	char usb_lan[NETIF_NAME_LEN] = {0};
+	char sw_name[NV_NAME_LEN] = {0};
+	char lan_enable[NV_NAME_LEN] = {0};
+	printf("netapi:getDevId_byname start!dev_name=%s\n", dev_name);
+
+	//ȱʡÍâÍø¿ÚΪ¿ÕʱºòÒ²¸øÖ÷¿Ø·¢ÏûÏ¢£¬add by zpm 20160628 begin
+	if (strlen(dev_name) == 0) {
+		return NO_DEV;
+	}
+	//ȱʡÍâÍø¿ÚΪ¿ÕʱºòÒ²¸øÖ÷¿Ø·¢ÏûÏ¢£¬add by zpm 20160628 end
+
+	sc_cfg_get("pswan", ps_wan, sizeof(ps_wan));
+	sc_cfg_get("ps_ext1", psext_wan1, sizeof(psext_wan1));
+	sc_cfg_get("ps_ext2", psext_wan2, sizeof(psext_wan2));
+	sc_cfg_get("ps_ext3", psext_wan3, sizeof(psext_wan3));
+	sc_cfg_get("ps_ext4", psext_wan4, sizeof(psext_wan4));
+	sc_cfg_get("ps_ext5", psext_wan5, sizeof(psext_wan1));
+	sc_cfg_get("ps_ext6", psext_wan6, sizeof(psext_wan2));
+	sc_cfg_get("ps_ext7", psext_wan7, sizeof(psext_wan3));
+	sc_cfg_get("ps_ext8", psext_wan8, sizeof(psext_wan4));
+	sc_cfg_get("wifiwan", wifi_wan, sizeof(wifi_wan));
+	sc_cfg_get("swwanstr", swwanstr, sizeof(swwanstr));
+	sc_cfg_get("swlanstr", swlanstr, sizeof(swlanstr));
+	sc_cfg_get("ethwan", eth_wan, sizeof(eth_wan));
+	sc_cfg_get("ethlan", eth_lan, sizeof(eth_lan));
+	sc_cfg_get("wifilan", wifi_lan, sizeof(wifi_lan));
+	sc_cfg_get("usblan", usb_lan, sizeof(usb_lan));
+	sc_cfg_get("sw", sw_name, sizeof(sw_name));
+	sc_cfg_get("LanEnable", lan_enable, sizeof(lan_enable));
+
+	if (!strncmp(dev_name, ps_wan, strlen(dev_name)))
+		return PS_NET_DEV;
+	if ((0 != strcmp(lan_enable, "0")) && !strncmp(dev_name, usb_lan, strlen(dev_name)))
+		return USB_LAN_DEV;
+	if (!strncmp(dev_name, psext_wan1, strlen(dev_name)))
+		return PS_EXT_DEV1;
+	if (!strncmp(dev_name, psext_wan2, strlen(dev_name)))
+		return PS_EXT_DEV2;
+	if (!strncmp(dev_name, psext_wan3, strlen(dev_name)))
+		return PS_EXT_DEV3;
+	if (!strncmp(dev_name, psext_wan4, strlen(dev_name)))
+		return PS_EXT_DEV4;
+	if (!strncmp(dev_name, psext_wan5, strlen(dev_name)))
+		return PS_EXT_DEV5;
+	if (!strncmp(dev_name, psext_wan6, strlen(dev_name)))
+		return PS_EXT_DEV6;
+	if (!strncmp(dev_name, psext_wan7, strlen(dev_name)))
+		return PS_EXT_DEV7;
+	if (!strncmp(dev_name, psext_wan8, strlen(dev_name)))
+		return PS_EXT_DEV8;
+	//µ±½öÒ»¸öRJ45Íø¿Úʱ£¬Ê¼ÖÕµ±ÍâÍø¿ÚÓã¬ÔÙ¼ÓÉÏeth_type£¬¿ÉÒÔʵÏÖÄÚÍø¹¦ÄÜ
+	if (!strncmp(dev_name, eth_wan, strlen(dev_name)) || !strncmp(dev_name, swwanstr, strlen(dev_name)))
+		return RJ45_WAN_DEV;
+	//µ±´æÔÚÁ½¸öRJ45Íø¿Úʱ£¬ÔÚ´ËÉèÖÃÒ»¸ö¹Ì¶¨µÄÄÚÍøRJ45Íø¿Ú
+	if (!strncmp(dev_name, eth_lan, strlen(dev_name)) || !strncmp(dev_name, swlanstr, strlen(dev_name)))
+		return RJ45_LAN_DEV;
+	if (!strncmp(dev_name, wifi_wan, strlen(dev_name)))
+		return WIFI_WAN_DEV;
+	if (!strncmp(dev_name, wifi_lan, strlen(dev_name)))
+		return WIFI_LAN_DEV;
+
+	return -1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º set_pswanstate
+* ¹¦ÄÜÃèÊö£º ÉèÖÃpsÍøÂçÉ豸IPv6״̬NVÖµ
+* ²ÎÊý˵Ã÷£º c_id(IN) :PDP¼¤»îµÄc_id
+*            state(IN):ÍøÂçÉ豸״̬
+* ·µ »Ø Öµ£º
+* ÆäËü˵Ã÷£º
+**************************************************************************/
+
+static void set_pswan_v6state(int c_id, int state)
+{
+	char ps_wan[NV_NAME_LEN] = {0};
+	char pswan_state[NETIF_NAME_LEN] = {0};
+
+	sc_cfg_get("pswan", ps_wan, sizeof(ps_wan));
+
+	snprintf(pswan_state, sizeof(pswan_state), "%s%d_ipv6_state", ps_wan, c_id);
+
+	if (state == DEV_STATE_WORKING) {
+		sc_cfg_set(pswan_state, "working");
+		return;
+	}
+
+	if (state == DEV_STATE_CONNECT) {
+		sc_cfg_set(pswan_state, "connect");
+		return;
+	}
+	if (state == DEV_STATE_DEAD) {
+		sc_cfg_set(pswan_state, "dead");
+		return;
+	}
+}
+
+static int pdp_state_check(struct pdp_active_info *actinfo)
+{
+	char pdp_act_state[NV_NAME_LEN] = {0};
+	char nv_pdp_state[NV_NAME_LEN] = {0};
+	sprintf(nv_pdp_state, "pdp_act_state_%d", actinfo->c_id);
+	sc_cfg_get(nv_pdp_state, pdp_act_state, sizeof(pdp_act_state));
+	if (0 != strcmp(pdp_act_state, "act")) {
+		sc_cfg_set(nv_pdp_state, "acting");
+		return 0;
+	}
+	return 1;
+}
+
+static void plugin_state_set(unsigned char netdev_id)
+{
+	int plugstate;
+	char rj45_pluginstate[NV_NAME_LEN] = {0};
+	char temp[NV_NAME_LEN] = {0};
+	sc_cfg_get("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate));
+
+	plugstate = atoi(rj45_pluginstate);
+	if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) {
+		plugstate |= RJ45_WAN_IN;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("rj45_pluginstate", temp);
+	} else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) {
+		plugstate |= RJ45_LAN_IN;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("rj45_pluginstate", temp);
+	} else if (netdev_id == USB_LAN_DEV) {
+		plugstate = USB_LAN_IN;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("usb_pluginstate", temp);
+	} else if (netdev_id >= PS_EXT_DEV1 && netdev_id <= PS_EXT_DEV8) {
+		sprintf(temp, "psext%d_pluginstate", netdev_id);
+		sc_cfg_set(temp, "1");
+	}
+}
+
+static void plugout_state_set(unsigned char netdev_id)
+{
+	int plugstate;
+	char rj45_pluginstate[NV_NAME_LEN] = {0};
+	char temp[NV_NAME_LEN] = {0};
+
+	sc_cfg_get("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate));
+	plugstate = atoi(rj45_pluginstate);
+
+	if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) {
+		plugstate &= ~RJ45_WAN_IN;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("rj45_pluginstate", temp);
+	} else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) {
+		plugstate &= ~RJ45_LAN_IN;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("rj45_pluginstate", temp);
+	} else if (netdev_id == USB_LAN_DEV) {
+		plugstate = USB_LAN_OUT;
+		sprintf(temp, "%d", plugstate);
+		sc_cfg_set("usb_pluginstate", temp);
+	} else if (netdev_id >= PS_EXT_DEV1 && netdev_id <= PS_EXT_DEV8) {
+		sprintf(temp, "psext%d_pluginstate", netdev_id);
+		sc_cfg_set(temp, "0");
+	}
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º pdp_act_proc
+* ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸¼¤»î½Ó¿Ú
+* ²ÎÊý˵Ã÷£º pdp_active_info(IN):PDP¼¤»îÐÅÏ¢
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£»
+* ½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸µÄ¼¤»î¼°ÏàÓ¦µÄÍøÂçÅäÖÃ
+**************************************************************************/
+int ppp_act_proc(char *ttyname)
+{
+	char cmd[200] = {0};
+	char path_sh[50] = {0};
+
+	slog(NET_PRINT, SLOG_ERR, "netapi:calling ppp_act_proc, %s\n", ttyname);
+	sc_cfg_set("ppp_pdpstate", "");
+	sc_cfg_get("path_sh", path_sh, sizeof(path_sh));
+	if (!ttyname)
+		return -1;
+	sprintf(cmd, "%s/pppd_up.sh %s", path_sh, ttyname);
+	slog(NET_PRINT, SLOG_ERR, "cmd is %s\n", cmd);
+	soft_system(cmd);
+	return 0;
+}
+
+int pdp_act_proc(struct pdp_active_info *actinfo, int src_id)
+{
+	int ret = 0;
+	//klocwork
+	//int c_id = actinfo->c_id;
+	//unsigned char ip46flag = actinfo->act_info.ip46flag;
+
+	system("cat /proc/uptime 1>dev/console 2>&1");
+	
+	if (!actinfo || actinfo->act_info.ip46flag == V4V6_INVALID) {
+		slog(NET_PRINT, SLOG_ERR, "pdp_act_proc, src_id = %d, actinfo->act_info.ip46flag == V4V6_INVALID\n", src_id);
+
+		softap_assert("ip46flag error"); //klocwork
+		return -1;
+	}
+	slog(NET_PRINT, SLOG_ERR, "netapi:pdp_act_proc: src_id=0x%x, cid=%d pdp_type=%u ip46flag=%u\n", src_id, actinfo->c_id, actinfo->pdp_type, actinfo->act_info.ip46flag);
+
+#if 1  // cov M  actinfo->pdp_type is unsigned, could not compare with 0
+    if (PDP_PPP < actinfo->pdp_type) {
+#else
+	if (PDP_PPP < actinfo->pdp_type || PDP_LOCAL > actinfo->pdp_type) {
+#endif        
+
+		slog(NET_PRINT, SLOG_ERR, "pdp_act_proc, src_id = %d, pdp_type is error: cid=%d pdp_type=%u ip46flag=%u\n", src_id, actinfo->c_id, actinfo->pdp_type, actinfo->act_info.ip46flag);
+		softap_assert("pdp_type=%u error", actinfo->pdp_type);
+		return -1;
+	}
+
+	if (1 == pdp_state_check(actinfo)) {
+
+		slog(NET_PRINT, SLOG_ERR, "pdp_act_init: already act c_id = %d, src_id = %d\n", actinfo->c_id, src_id);
+		//softap_assert("already act");
+		return -1;
+	}
+
+	if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) {
+		set_pswan_v6state(actinfo->c_id, DEV_STATE_CONNECT);
+	}
+
+	ret = ipc_send_message(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_PDP_ACT, sizeof(struct pdp_active_info), (UCHAR *)actinfo, 0);  /*lint !e26 !e55*/
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return -1;
+	}
+
+	slog(NET_PRINT, SLOG_ERR, "pdp_act_proc: success!\n");
+	return 0;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º pdp_deact_proc
+* ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸ȥ»î½Ó¿Ú
+* ²ÎÊý˵Ã÷£º c_id(IN):PDP¼¤»îc_id.
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£»
+½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸ȥ»î£»Ö§³Ö46µ¥Õ»È¥»î£¬ËùÒÔÈë²ÎÐèҪָʾ46Çé¿ö
+**************************************************************************/
+int pdp_deact_proc(int c_id, unsigned char ip46flag, int src_id)
+{
+	int ret = 0;
+	struct pdp_deactive_info temp;
+	char nv_pdp_state[NV_NAME_LEN] = {0};
+
+	slog(NET_PRINT, SLOG_ERR, "netapi:pdp_deact_proc: src_id=%d, cid=%d ip46flag=%u\n", src_id, c_id, ip46flag);
+
+	sprintf(nv_pdp_state, "pdp_act_state_%d", c_id);
+
+	temp.c_id = c_id;
+	temp.ip46flag = ip46flag;
+
+	if (ip46flag == V4V6_INVALID) {
+		slog(NET_PRINT, SLOG_ERR, "pdp_deact_proc,src_id = %d, ip46flag is error: cid=%d ip46flag=%u\n", src_id, c_id, ip46flag);
+		softap_assert("ip46flag=%u error", ip46flag);
+		return -1;
+	}
+
+	sc_cfg_set(nv_pdp_state, "deacting");
+	ret = ipc_send_message(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_PDP_DEACT, sizeof(struct pdp_deactive_info), (UCHAR *)&temp, 0); /*lint !e26 !e55*/
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return -1;
+	}
+	slog(NET_PRINT, SLOG_ERR, "pdp_deact_proc: success!\n");
+	return 0;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_connect_internet
+* ¹¦ÄÜÃèÊö£º webui·¢Ë͵ÄÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig up£¬²¢Æô¶¯ÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷Óô˽ӿÚǰ£¬ÐèÒª¼ì²âµ±Ç°É豸ÎïÀíͨ·ÒÑͨ£¬·ñÔò²»Ó¦¸Ãµ÷Óô˽ӿڣ»
+* Ö÷¿ØÄ£¿éÐèÒªÑÏ¿ØÖظ´µÄµ÷Óøýӿڣ¬ÒòΪÿµ÷ÓÃÒ»´Î¸Ã½Ó¿Ú£¬ÄÚ²¿½Ô»áÖØÐÂÖ´ÐÐÒ»´ÎÍêÕûµÄµØÖ··ÖÅäÁ÷³Ì£»
+**************************************************************************/
+int netdev_connect_internet(unsigned char netdev_id, int src_id)
+{
+	int ret = 0;
+
+	slog(NET_PRINT, SLOG_ERR, "netapi:netdev_connect_internet: netdev_id=%u\n", netdev_id);
+
+	if (netdev_id != RJ45_WAN_DEV && netdev_id != WIFI_WAN_DEV && netdev_id != RJ45_LAN_DEV && netdev_id != WIFI_LAN_DEV) {
+		slog(NET_PRINT, SLOG_ERR, "connect_internet:%u don't support connect op!\n", netdev_id);
+		softap_assert("netdev_id=%d error", netdev_id);
+		return 0;
+	}
+
+	ret = ipc_send_message(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_CONNECT, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); /*lint !e26 !e55*/
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return 0;
+	}
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_disconnect_internet
+* ¹¦ÄÜÃèÊö£º webui·¢Ë͵ĶϿªÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷Óô˽ӿÚ
+**************************************************************************/
+int netdev_disconnect_internet(unsigned char netdev_id, int src_id)
+{
+	int ret = 0;
+
+	printf("netapi:netdev_disconnect_internet start!netdev_id=%u\n", netdev_id);
+	slog(NET_PRINT, SLOG_ERR, "netapi:netdev_disconnect_internet: netdev_id=%u\n", netdev_id);
+
+	if (netdev_id != RJ45_WAN_DEV && netdev_id != WIFI_WAN_DEV && netdev_id != RJ45_LAN_DEV && netdev_id != WIFI_LAN_DEV) {
+		slog(NET_PRINT, SLOG_ERR, "disconnect_internet:%u don't support disconnect op!\n", netdev_id);
+		softap_assert("netdev_id=%d error", netdev_id);
+
+		return 0;
+	}
+
+	ret = ipc_send_message(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_DISCON, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); /*lint !e26 !e55*/
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return 0;
+	}
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugin_proc_byname
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸²åÈë,½Ó¿ÚÄÚ²¿¼ì²âÊÇ·ñÐèÒª½øÐÐ×Ô¶¯²¦ºÅ£¬ÈçÐèÒª£¬Ö´ÐеØÖ··ÖÅä¡¢×éÍøµÈÁ÷³Ì
+* ²ÎÊý˵Ã÷£º netdev_name£ºÍøÂçÉ豸Ãû£¬source_id plug¼ì²âÄ£¿éID
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒÑͨ£¬¿ÉÒÔ½øÐÐIPÊý¾Ý°üµÄÊÕ·¢ÁË
+**************************************************************************/
+int netdev_plugin_proc_byname(char *netdev_name, int src_id)
+{
+	int netdev_id = 0;
+	slog(NET_PRINT, SLOG_ERR, "netdev_plugin_byname, netdev %s is plugin, src_id = %d\n", netdev_name, src_id);
+	netdev_id = getDevId_byname(netdev_name);
+
+	if (netdev_id == -1) {
+		slog(NET_PRINT, SLOG_ERR, "netdev_plugin_proc_byname,netdev_name is error,please connect main control");
+		return -1;
+	} else {
+		return netdev_plugin_proc(netdev_id, src_id);
+	}
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugout_proc
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸°Î³ö,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_name£ºÍøÂçÉ豸Ãû£¬source_id plug¼ì²âÄ£¿éID
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒѶϣ¬²»ÒªÔÙ½øÐÐIPÊý¾Ý°üÊÕ·¢
+**************************************************************************/
+int netdev_plugout_proc_byname(char *netdev_name, int src_id)
+{
+	int netdev_id = 0;
+	slog(NET_PRINT, SLOG_ERR, "netdev_plugout_byname, netdev %s is plugout, src_id = %d\n", netdev_name, src_id);
+	netdev_id = getDevId_byname(netdev_name);
+
+	if (netdev_id == -1) {
+		slog(NET_PRINT, SLOG_ERR, "netdev_plugout_proc_byname,netdev_name is error,please connect main control");
+		return -1;
+	} else {
+		return netdev_plugout_proc(netdev_id, src_id);
+	}
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugin_proc
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸²åÈë,½Ó¿ÚÄÚ²¿¼ì²âÊÇ·ñÐèÒª½øÐÐ×Ô¶¯²¦ºÅ£¬ÈçÐèÒª£¬Ö´ÐеØÖ··ÖÅä¡¢×éÍøµÈÁ÷³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒÑͨ£¬¿ÉÒÔ½øÐÐIPÊý¾Ý°üµÄÊÕ·¢ÁË
+**************************************************************************/
+int netdev_plugin_proc(unsigned char netdev_id, int src_id)
+{
+	int ret = 0;
+
+	printf("netapi:netdev_plugin_proc start!netdev_id=%u\n", netdev_id);
+	slog(NET_PRINT, SLOG_ERR, "netapi:netdev_plugin_proc: netdev_id=%u\n", netdev_id);
+	plugin_state_set(netdev_id);
+	ret = ipc_send_message2(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_PLUGIN, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); /*lint !e26 !e55*/
+
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return 0;
+	}
+#ifdef _USE_MBIM	
+	slog(NET_PRINT, SLOG_ERR, "netapi:netdev_plugin_proc: send MSG_CMD_NET_PLUGIN to MBIM\n");
+	ipc_send_message2(src_id, MODULE_ID_MBIM, MSG_CMD_NET_PLUGIN, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); 
+#endif
+	return 1;
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º netdev_plugout_proc
+* ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸°Î³ö,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì
+* ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒѶϣ¬²»ÒªÔÙ½øÐÐIPÊý¾Ý°üÊÕ·¢
+**************************************************************************/
+int netdev_plugout_proc(unsigned char netdev_id, int src_id)
+{
+	int ret = 0;
+
+	printf("netapi:netdev_plugout_proc start!netdev_id=%u\n", netdev_id);
+	slog(NET_PRINT, SLOG_ERR, "netapi:netdev_plugout_proc: netdev_id=%u\n", netdev_id);
+	plugout_state_set(netdev_id);
+	slog(NET_PRINT, SLOG_ERR, "netdev_plugout_proc: netdev_id=%u\n", netdev_id);
+	ret = ipc_send_message2(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_PLUGOUT, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); /*lint !e26 !e55*/
+
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return 0;
+	}
+#ifdef _USE_MBIM
+	ipc_send_message2(src_id, MODULE_ID_MBIM, MSG_CMD_NET_PLUGOUT, sizeof(unsigned char), (UCHAR *)&netdev_id, 0);
+#endif
+	return 1;
+}
+/********************************************************************
+* º¯ÊýÃû³Æ£º tcpip_reset_configure
+* ¹¦ÄÜÃèÊö£º »Ö¸´³ö³§ÉèÖÃʱÓÉååzte_blc½ø³Ìµ÷Óã¬É¾³ý³ÌÐòÔËÐÐÖÐÉú³ÉµÄÎļþ
+* ²ÎÊý˵Ã÷£º ÎÞ
+* ·µ »Ø Öµ£º ÎÞ
+* ÆäËü˵Ã÷£º
+**********************************************************************/
+void tcpip_reset_configure()
+{
+	char cmd[200] = {0};
+	char path_script[50] = {0};
+	char path_conf[50] = {0};
+	char path_file[200] = {0};
+	printf("netapi:tcpip_reset_configure start!\n");
+	sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/hostname_mac_file", path_conf);
+
+
+	//»Ö¸´³ö³§ÉèÖÃʱɾ³ýhostname_mac_fileÎļþ
+	sprintf(cmd, "/bin/rm -rf %s", path_file);
+	zxic_system(cmd);
+	//»Ö¸´³ö³§ÉèÖÃʱɾ³ýstatic_macip_file  Îļþ
+	memset(path_file, 0, sizeof(path_file));
+	sprintf(path_file, "%s/static_macip_file", path_conf);
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "/bin/rm -rf %s", path_file);
+	zxic_system(cmd);
+
+	memset(path_file, 0, sizeof(path_file));
+	sprintf(path_file, "%s/children_device_file", path_conf);
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "/bin/rm -rf %s", path_file);
+	zxic_system(cmd);
+
+	memset(path_file, 0, sizeof(path_file));
+	sprintf(path_file, "%s/white_site_file", path_conf);
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "/bin/rm -rf %s", path_file);
+	zxic_system(cmd);
+
+	/*reset DDNS status file*/
+	memset(path_file, 0, sizeof(path_file));
+	sprintf(path_file, "%s/inadyn.status", path_conf);
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "/bin/rm -rf %s", path_file);
+	zxic_system(cmd);
+
+	//»Ö¸´³ö³§ÉèÖÃʱ½«MAC-IP°ó¶¨¹æÔòÇå¿Õ
+	sc_cfg_get("path_sh", path_script, sizeof(path_script));
+	memset(cmd, 0, sizeof(cmd));
+	sprintf(cmd, "%s/config-udhcpd.sh \"lan\" -S", path_script);
+	soft_system(cmd);
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º tc_control
+* ¹¦ÄÜÃèÊö£º Á÷Á¿¿ØÖÆ
+* ²ÎÊý˵Ã÷£º ÐèÒªÁ÷Á¿¼à¿ØµÄÉÏÏÂÐÐÁ¿£¬Êý¾Ý¿¨ÐèÒªÓÐcid£¬ufiģʽ²»ÐèÒª
+*            0±íʾ²»ÐèÒªÁ÷¿Ø£¬µ¥Î»:bit£¬Òòlinux±ê×¼ÃüÁîÊǶÔ×Ö½Ú´¦Àí£¬ËùÒÔ×îÖÕÅäÖÃÖµ»áÕû³ý8
+* ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1.
+* ÆäËü˵Ã÷£º ¸øÐèÒªÁ÷Á¿¿ØÖƵÄÓ¦Óõ÷Óã¬ÈçÉÏÐÐÐèÒªÁ÷¿Ø£¬ÇëµÈÄÜÉÏÍâÍøºóÔÙµ÷Ó㬷ñÔòÎÞ·¨»ñÈ¡ÍâÍø¿Ú½øÐÐÁ÷¿Ø
+*                 Õý³£¹Ø»úÖØÐ¿ª»ú£¬Ö®Ç°ÉèÖõÄÁ÷¿ØÒÀÈ»ÓÐЧ
+**************************************************************************/
+int tc_control(struct tc_control_info *tcinfo, int src_id)
+{
+	int ret = 0;
+
+	printf("netapi:tc_control start! c_id:%d, down:%u, up:%u\n, src:%d \n", tcinfo->c_id, tcinfo->tc_downlink, tcinfo->tc_uplink, src_id);
+
+	ret = ipc_send_message(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TC_CTRL, sizeof(struct tc_control_info), (UCHAR *)tcinfo, 0);
+	if (0 != ret) {
+		softap_assert("send msg to zte_router error");
+		return 0;
+	}
+	return 1;
+}
+
+#define SIOCDEVPRIVATE 0X89F0
+#define SIOCVLAN		SIOCDEVPRIVATE+0x0	
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º set_ethwan_mode
+* ¹¦ÄÜÃèÊö£º ÉèÖÃswitchÉ豸eth0.200Íø¿Ú¶ÔÓ¦µÄport3Ϊwan¿Ú»¹ÊÇlan¿Ú
+* ²ÎÊý˵Ã÷£º mode:1 => wan¿Ú£¬0 => lan¿Ú
+* ·µ »Ø Öµ£º ÎÞ.
+* ÆäËü˵Ã÷£º 
+**************************************************************************/
+void set_ethwan_port_mode(int mode)
+{
+	struct ifreq ifr;
+	int fd;
+	char eth_name[IFNAMSIZ] = {'e','t','h','0'};
+	
+	if(mode != 0 && mode != 1)
+	{
+		return;
+	}
+	slog(NET_PRINT, SLOG_ERR, "set_ethwan_port_mode() mode=%d\n", mode);	
+	if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+		slog(NET_PRINT, SLOG_ERR, "set_eth200_mode() socket(AF_INET,SOCK_STREAM) fail");
+		return;
+	}
+	memset(&ifr, 0, sizeof(ifr));
+	memcpy((void*)ifr.ifr_name, (void*)eth_name, strlen("eth0"));//gmacÍø¿ÚÃû³Æeth0£¬ºóÐø¿¼ÂÇÊÇ·ñͨ¹ýÐÂÔönvÏî»ñÈ¡
+	ifr.ifr_data = (void*)&mode;
+
+	if (ioctl(fd, SIOCVLAN, &ifr) < 0 && errno != EINVAL) {
+		slog(NET_PRINT, SLOG_ERR, "set_eth200_mode() ioctl fail");		
+		close(fd);
+		return;
+	}
+
+	close(fd);
+
+}
+
+
diff --git a/ap/lib/libsoftap/netioctl.c b/ap/lib/libsoftap/netioctl.c
new file mode 100755
index 0000000..ac23daf
--- /dev/null
+++ b/ap/lib/libsoftap/netioctl.c
@@ -0,0 +1,44 @@
+/************************************************************************
+*¹¦ÄܽéÉÜ£ºlinuxÖÐ×ÔÑÐÌṩӦÓÃappsʹÓõÄioctl½Ó¿Ú
+*¸ºÔðÈË£º
+*±¸·ÝÈË£º
+*ÐÞ¸ÄÈÕ£º
+*ÐÞ¸ÄÄÚÈÝ£º
+*°æ±¾ºÅ£º
+************************************************************************/
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <linux/if.h>
+#include <arpa/inet.h>
+#include <net/if_arp.h>
+#include <linux/sockios.h>
+#include <assert.h>
+#include "message.h"
+
+
+//ͨ¹ýÀ©Õ¹ioctl£¬ÊµÏÖÓ¦ÓÃÓëÄں˵ÄÍøÂçÏà¹Ø²Ù×÷½»»¥
+int netioctl_handle(int cmd, void *val)
+{
+	int fd = -1;
+	int ret = 0;
+	fd = open("/dev/myioctl", O_RDWR);
+	if (fd < 0)
+		return -1;
+	ret = ioctl(fd, cmd, val);
+	if (ret < 0)
+		printf("ioctl can not get info,%d\n", ret);
+	//assert(0);
+	close(fd);
+	return ret;
+}
+
+
diff --git a/ap/lib/libsoftap/netotherapi.c b/ap/lib/libsoftap/netotherapi.c
new file mode 100755
index 0000000..c1d73ce
--- /dev/null
+++ b/ap/lib/libsoftap/netotherapi.c
@@ -0,0 +1,1520 @@
+/**
+* @file netotherapi.c
+* @brief Public APIs of Sanechips
+*
+* Copyright (C) 2017 Sanechips Technology Co., Ltd.
+* @author  Linxu Gebin
+* @defgroup si_id Sanechips
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*************************************************************************
+*/
+
+/*******************************************************************************
+ *							 Include header files							   *
+ ******************************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <syslog.h>
+#include <sys/klog.h>
+#include <sys/msg.h>
+#include "message.h"
+#include <sys/time.h>
+#include <asm/types.h>
+#include <netinet/ether.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include "softap_api.h"
+#include <netotherapi.h>
+#include <dirent.h>
+#include <limits.h>
+
+/*******************************************************************************
+ *                             Type definitions                                *
+ ******************************************************************************/
+/**
+* @brief route information
+* @param dstAddr destination address
+* @param srcAddr source address
+* @param gateWay gateWay
+* @param ifName NIC name
+*/
+struct route_info {
+	u_int dstAddr;
+	u_int srcAddr;
+	u_int gateWay;
+	char ifName[IF_NAMESIZE];
+};
+
+#define BUFSIZE 8192
+
+#define SPINLOCK_IOC_MAGIC	'S'
+
+#define SPINLOCK_GET_STATUS  _IOWR(SPINLOCK_IOC_MAGIC,1,char *)
+
+#define READ_BUF_SIZE 56
+/*******************************************************************************
+ *                      Inline function implementations                        *
+ ******************************************************************************/
+inline char *strip_space(char *str)
+{
+	while (*str == ' ')
+		str++;
+	return str;
+}
+/*******************************************************************************
+ *                      Local function implementations                         *
+ ******************************************************************************/
+/* дÎļþ²Ù×÷º¯Êý */
+int write_file(const char *filepath, int flags, const char *buf, int size)
+{
+	int fd = 0;
+	int ret = 0;
+
+	fd = open(filepath, flags, 0644);
+	if (fd < 0) {
+		slog(MISC_PRINT, SLOG_ERR, "write_to_file open %s fail, error:%s! \n", filepath, strerror(errno));
+		ret = -1;
+		goto out;
+	}
+
+    ret = TEMP_FAILURE_RETRY(write(fd, buf, size));
+	if (ret != size) {
+		slog(MISC_PRINT, SLOG_ERR, "write_to_file write %s fail, error:%s! \n", filepath, strerror(errno));
+		ret = -1;
+		goto out;
+	}
+	if(fsync(fd) < 0)
+    {
+        // todo: cov m
+    }  
+    
+	ret = 0;
+
+out:
+	if (fd >= 0)
+		close(fd);
+	return ret;
+}
+
+/* дÎļþ: ¸²¸Çд */
+int write_to_file(const char *filepath, const char *buf, int size)
+{
+	return write_file(filepath, O_WRONLY | O_CREAT | O_TRUNC, buf, size);
+}
+
+/* дÎļþ: β²¿×·¼Óд  */
+int append_to_file(const char *filepath, const char *buf, int size)
+{
+	return write_file(filepath, O_WRONLY | O_APPEND | O_CREAT, buf, size);
+}
+
+//¿â½Ó¿Úctime¡¢asctime»á»»ÐУ¬Ôì³ÉÿÌõlog±»·ÖÐÐÏÔʾ£¬²»·½±ã¿´£¬ËùÒÔ½«ctimeÔ´ÂëÉÔ΢¸ÄÔìÏÂ
+static char *str_ctime(const struct tm *timeptr)
+{
+	/*static const char wday_name[][4] = {
+	  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+	};*/
+
+	static const char mon_name[][4] = {
+		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+	};
+
+	static char result[26];
+
+	/*sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d",
+	  wday_name[timeptr->tm_wday],
+	  mon_name[timeptr->tm_mon],
+	  timeptr->tm_mday, timeptr->tm_hour,
+	  timeptr->tm_min, timeptr->tm_sec,
+	  1900 + timeptr->tm_year);*/
+	snprintf(result, sizeof(result), "%.3s%3d %.2d:%.2d:%.2d %d",
+	        mon_name[timeptr->tm_mon],
+	        timeptr->tm_mday, timeptr->tm_hour,
+	        timeptr->tm_min, timeptr->tm_sec,
+	        1900 + timeptr->tm_year);
+	return result;
+}
+
+/*******************************************************************************
+ *                      Global function implementations                        *
+ ******************************************************************************/
+
+/****************************************/
+//input:  nv_str:nvÄÚÈÝÖ¸Õë    * nv_param ½âÎöºó²ÎÊýµÄÖ¸Õë
+//output:   param_num     nv_param
+//ʾÀý:
+//   int num;
+//   char** nv_param;
+//   num = nv_analyze(nv_str,&nv_param)
+//   strcmp(nv_param[0],"aaa") ...
+//   strcmp(nv_param[1],"bbb") ...
+//   ...
+//   free(nv_param);
+//
+/****************************************/
+
+int nv_analyze(char* nv_str, char*** nv_param)
+{
+	int param_num = 1;
+	int i = 0;
+	char* str_ptr;
+	char** mem_ptr;
+	char* tmp_ptr;
+	for (str_ptr = nv_str; *str_ptr != '\0'; str_ptr++) {
+		if (*str_ptr == '+')
+			param_num++;
+	}
+	mem_ptr = (char**)malloc((1 + sizeof(char*)) * param_num + strlen(nv_str));
+	if (mem_ptr == NULL) {//klocwork
+		return -1;
+	}
+	memset(mem_ptr, 0, (1 + sizeof(char*)) * param_num + strlen(nv_str));
+	* nv_param = mem_ptr;
+	str_ptr = strtok(nv_str, "+");
+	tmp_ptr = (char*)(mem_ptr + param_num);
+	while (str_ptr != NULL) {
+		memcpy((mem_ptr + i), &tmp_ptr, sizeof(char*));
+		strcpy(tmp_ptr, str_ptr);
+		tmp_ptr = (char*)((long)tmp_ptr + strlen(str_ptr) + 1);
+		i ++;
+		str_ptr = strtok(NULL, "+");
+	}
+	return param_num;
+}
+
+
+char* getField(char *a_line, char *delim, int count)
+{
+	int i = 0;
+	char *tok = NULL;
+	char *save = NULL;
+	tok = strtok_r(a_line, delim, &save);
+	while (tok) {
+		if (i == count)
+			break;
+		i++;
+		tok = strtok_r(NULL, delim, &save);
+	}
+	if (tok)
+		return tok;
+
+	return NULL;
+}
+
+void  free_dhcp_list(struct list_head *dhcp_info_list)
+{
+	DHCPOFFERADDR_LIST_t *dhcp_info_temp  = NULL;
+	DHCPOFFERADDR_LIST_t *dhcp_info_temp1 = NULL;
+
+	list_for_each_entry_safe(dhcp_info_temp, dhcp_info_temp1, dhcp_info_list, list) {
+		list_del(&dhcp_info_temp->list);
+		free(dhcp_info_temp);
+	}
+}
+
+void  free_laninfo_list(struct list_head *file_info_list)
+{
+	LAN_INFO_LIST_t *lan_info_list_tmp  = NULL;
+	LAN_INFO_LIST_t *lan_info_list_tmp1 = NULL;
+
+	list_for_each_entry_safe(lan_info_list_tmp, lan_info_list_tmp1, file_info_list, list) {
+		list_del(&lan_info_list_tmp->list);
+		free(lan_info_list_tmp);
+	}
+
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º getIfStatistic
+* ¹¦ÄÜÃèÊö£º »ñÈ¡ÍøÂçÉ豸µ±Ç°Á÷Á¿
+* ²ÎÊý˵Ã÷£º interface:     Íø¿ÚÉ豸Ãû³Æ
+*            type:          Á÷Á¿ÀàÐÍ£¬ÉÏÐС¢ÏÂÐбÈÌØ»ò°ü¸öÊý
+*            result_data:   ±£´æÁ÷Á¿Öµ
+* ·µ »Ø Öµ£º ʧ°Ü·µ»Ø-1£¬³É¹¦·µ»Ø0
+**************************************************************************/
+int getIfStatistic(char *interface, int type, unsigned long long *result_data)
+{
+	int found_flag = 0;
+	int skip_line = 2;
+	char temp_rcv[64] = {0};
+	char buf[1024], *field, *semiColon = NULL;
+	long long result_data_num = 0;
+	FILE *fp = fopen(PROC_IF_STATISTIC, "r");
+	if (!fp) {
+		slog(MISC_PRINT, SLOG_ERR, "no proc?\n");
+		return -1;
+	}
+
+	while (fgets(buf, 1024, fp)) {
+		char *ifname;
+		if (skip_line != 0) {
+			skip_line--;
+			continue;
+		}
+		if (!(semiColon = strchr(buf, ':')))
+			continue;
+		*semiColon = '\0';
+		ifname = buf;
+		ifname = strip_space(ifname);
+
+		if (!strcmp(ifname, interface)) {
+			found_flag = 1;
+			break;
+		}
+	}
+	fclose(fp);
+
+	if (found_flag == 0) {
+		slog(MISC_PRINT, SLOG_DEBUG, "[fluxstat]getIfStatistic no found data======\n");
+		return -1;
+	}
+
+	semiColon++;
+
+	switch (type) {
+	case TXBYTE:
+		if ((field = getField(semiColon, " ", 8))) {
+			errno = 0;
+			result_data_num = strtoull(field, NULL, 10);
+			if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
+			{
+				printf("strtoull errno %d: %s\n", errno, strerror(errno));
+			}
+			if (result_data_num < 0 || result_data_num > LLONG_MAX-1)
+				result_data_num = 0;
+			*result_data = result_data_num;
+			
+			slog(MISC_PRINT, SLOG_DEBUG, "[getIfStatistic]TXBYTE field:%s, result_data:%llu\n", field, *result_data);
+			return 0; //kw 3
+		}
+		break;
+	case TXPACKET:
+		if ((field = getField(semiColon, " ", 9))) {
+			errno = 0;
+			result_data_num = strtoull(field, NULL, 10);
+			if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
+			{
+				printf("strtoull errno %d: %s\n", errno, strerror(errno));
+			}
+			if (result_data_num < 0 || result_data_num > LLONG_MAX-1)
+				result_data_num = 0;
+			*result_data = result_data_num;
+			return 0;
+		}
+		break;
+	case RXBYTE:
+		if ((field = getField(semiColon, " ", 0))) {
+			errno = 0;
+			result_data_num = strtoull(field, NULL, 10);
+			if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
+			{
+				printf("strtoull errno %d: %s\n", errno, strerror(errno));
+			}
+			if (result_data_num < 0 || result_data_num > LLONG_MAX-1)
+				result_data_num = 0;
+			*result_data = result_data_num;
+			slog(MISC_PRINT, SLOG_DEBUG, "[getIfStatistic]RXBYTE field:%s, result_data:%llu\n", field, *result_data);
+			return 0;
+		}
+		break;
+	case RXPACKET:
+		if ((field = getField(semiColon, " ", 1))) {
+			errno = 0;
+			result_data_num = strtoull(field, NULL, 10);
+			if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
+			{
+				printf("strtoull errno %d: %s\n", errno, strerror(errno));
+			}
+			if (result_data_num < 0 || result_data_num > LLONG_MAX-1)
+				result_data_num = 0;
+			*result_data = result_data_num;
+			return 0;
+		}
+		break;
+	}
+	return -1;
+}
+
+void *safe_malloc(int size, BOOL is_assert)
+{
+	void *ret = malloc(size);
+
+	if (ret == NULL) {
+		if (is_assert == TRUE) {
+			assert(ret);
+		} else {
+			printf("[%s][%s] ----can not get memory", __FILE__, __FUNCTION__);
+		}
+	} else {
+		memset(ret, 0, size);
+	}
+
+	return ret;
+}
+
+//ÊäÈësize±ØÐëÊÇdestµÄ³¤¶È
+void safe_strcpy(char *dest, char *source, int size)
+{
+	if (dest == NULL || source == NULL || size < 1) {
+		return;
+	}
+
+	strncpy(dest, source, size - 1);
+	dest[size - 1] = '\0';
+}
+
+int get_dev_list(struct pc_node* mypc_node)
+{
+	int ret = 0;
+
+	ret = netioctl_handle(NIOCGPCINFO, mypc_node);
+	if (-1 == ret) {
+		slog(NET_PRINT, SLOG_ERR, "NIOCGPCINFO err");
+		return -1;
+	}
+	return 0;
+}
+
+int  zte_get_mac_list_from_lease(struct list_head *dhcp_list_info)
+{
+	FILE *leaseFile    = NULL;
+	int64_t leaseFirst = 0;
+	char buf[32];
+
+	DHCPOFFERADDRNET dhcpInfo = {0};
+
+	char path_conf[50] = {0};
+	char path_file[100] = {0};
+
+	if (!list_empty(dhcp_list_info))
+		return -1;
+
+	sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/udhcpd.leases", path_conf);
+
+	leaseFile = fopen(path_file, "r");
+	if (leaseFile == NULL) {
+		fprintf(stderr, "can not open file udhcpd.leases.");
+		return -1 ;
+	}
+
+	if (fread(&leaseFirst, 1, sizeof(leaseFirst), leaseFile) != sizeof(leaseFirst)) {
+		fprintf(stderr, "read the first part of udhcpd.leases fail!");
+		fclose(leaseFile);
+		return -1 ;
+	}
+
+	memset(buf, 0x00, sizeof(buf));
+	sc_cfg_get("dhcpEnabled", buf, sizeof(buf));
+	if (strcmp(buf, "0") == 0) {
+		fclose(leaseFile);
+		return -1 ;
+	}
+
+	while ((fread(&dhcpInfo, 1, sizeof(dhcpInfo), leaseFile) == sizeof(dhcpInfo))) {
+		DHCPOFFERADDR_LIST_t *dhcpInfo_ptr = (DHCPOFFERADDR_LIST_t *)safe_malloc(sizeof(DHCPOFFERADDR_LIST_t), TRUE);
+		if (!dhcpInfo_ptr) {
+			slog(NET_PRINT, SLOG_ERR, "get_lan_info_list safe_malloc dhcpInfo_ptr fail \n");
+			return -1;
+		}
+		memcpy(&(dhcpInfo_ptr->dhcp_info), &dhcpInfo, sizeof(DHCPOFFERADDRNET));
+		list_add_tail(&dhcpInfo_ptr->list, dhcp_list_info);
+	}
+
+	fclose(leaseFile);
+	return 0;
+}
+
+void flash_file(char *file, char *file_num)
+{
+	char newFile[128] = {0};
+	char oldFile[128] = {0};
+	int i = 0;//klocwork
+	int i_file_num = atoi(file_num);
+
+    if(i_file_num < 0 || i_file_num > INT_MAX-1)
+    {
+        return ;
+    }
+    
+	for (i = i_file_num - 2; i > 0 && i < 1000; i--) {
+		sprintf(newFile, "%s_bk%d", file, i);
+		sprintf(oldFile, "%s_bk%d", file, i + 1);
+		if ((access(newFile, F_OK)) == 0) {
+			if(rename(newFile, oldFile) < 0){
+                // cov M 
+            }
+		}
+	}
+	sprintf(newFile, "%s_bk1", file);
+
+    if(rename(file, newFile) < 0)
+    {
+        // cov M
+    }
+}
+
+void file_write(char *filename, char *info)
+{
+	FILE *fp;
+	char logpath[128]  = {0};
+	char logname[128] = {0};
+	char filesize[32]	= {0};
+	char temp[64]	= {0};
+	int flag = 0;
+	time_t now;
+	struct tm *timenow;
+
+	time(&now);
+	timenow = localtime(&now);
+	if (!timenow) {//klocwork
+		printf("localtime get err.\n");
+		return;
+	}
+
+	if (!filename || 0 == strcmp(filename, "")) {
+		printf("filename is err.\n");
+		return;
+	}
+
+	//Ö¸¶¨logÎļþ´óС£¬Èç¹ûδָ¶¨¾ÍÓÃĬÈÏcomm_logsize
+	sprintf(temp, "%s_logsize", filename);
+	sc_cfg_get(temp, filesize, sizeof(filesize));
+	if (0 == strcmp(filesize, "0")) {
+		return ;
+	} else if (0 == strcmp(filesize, "")) {
+		sc_cfg_get("comm_logsize", filesize, sizeof(filesize));
+		if (0 == strcmp(filesize, "0") || 0 == strcmp(filesize, "")) {
+			printf("filesize is not set.\n");
+			return;
+		}
+	}
+
+	sc_cfg_get("path_log", logpath, sizeof(logpath));
+	snprintf(logname, sizeof(logname), "%s%s.log", logpath, filename);
+
+	fp = fopen(logname, "a");
+	if (!fp) {
+		printf("fopen %s failed \n", logname);
+		return;
+	}
+	//flock»úÖÆ²¢²»ÄÜÕæµÄÆðµ½lock×÷Ó㬷µ»Ø»áÔì³Éunlock²»µô
+	/*
+	else if (flock(fileno(fp), LOCK_EX) != 0)
+	{
+	    perror("flock");
+		fclose(fp);
+	    return;
+	}*/
+
+	fprintf(fp, "%s:%s\n", str_ctime(timenow), info);
+	//fprintf(fp, "%s %s %s[%d]: %s", ctime(timenow), asctime(timenow), filename, getpid(), info);
+	fflush(fp);
+	fseek(fp, 0L, SEEK_END);
+
+	if (ftell(fp) > atoi(filesize))
+		flag = 1;
+
+	//flock(fileno(fp), LOCK_UN);
+	fclose(fp);
+
+	if (flag == 1) {
+		flash_file(logname, "2");
+	}
+}
+
+int echo_file(char *filename, char*info)
+{
+	int len;
+	int ret;
+	int fd;
+	if (!filename || 0 == strcmp(filename, "") || !info) {
+		printf("echo filename is err.\n");
+		return -1;
+	}
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 777);
+	if (fd < 0) {
+		printf("%s open failed!\n", filename);
+		return -1;
+	}
+	len = strlen(info);
+	ret = write(fd, info, len);
+
+	close(fd);
+
+	return ret;
+}
+
+void save_file(char *filename, char* info)
+{
+	FILE* fp;
+	char filepath[128]  = {0};
+	char filesize[32]	= {0};
+	char filenum[32]	= {0};
+	char temp[64]	= {0};
+	int flag = 0;
+	time_t now;
+	struct tm *timenow;
+	time(&now);
+	timenow = localtime(&now);
+	if (!timenow) {//klocwork
+		printf("localtime get err.\n");
+		return;
+	}
+
+	if (!filename || 0 == strcmp(filename, "")) {
+		printf("filename is err.\n");
+		return;
+	}
+	sprintf(temp, "%sfile", filename);
+	sc_cfg_get(temp, filepath, sizeof(filepath));
+	sprintf(temp, "%sfileSize", filename);
+	sc_cfg_get(temp, filesize, sizeof(filesize));
+	if (0 == strcmp(filesize, "0") || 0 == strcmp(filesize, "")) {
+		printf("filesize is not set.\n");
+		return;
+	}
+
+	sprintf(temp, "%sNum", filename);
+	sc_cfg_get(temp, filenum, sizeof(filenum));
+	fp = fopen(filepath, "a");
+	if (!fp) {
+		printf("fopen %s failed \n", filepath);
+		return;
+	} else if (flock(fileno(fp), LOCK_EX) != 0) {
+		perror("flock");
+		fclose(fp);
+		return;
+	}
+
+	fprintf(fp, "%s %s\n", str_ctime(timenow), info);
+	fflush(fp);
+	fseek(fp, 0L, SEEK_END);
+	if (ftell(fp) > atoi(filesize))
+		flag = 1;
+
+	flock(fileno(fp), LOCK_UN);
+	fclose(fp);
+
+	if (flag == 1) {
+		flash_file(filepath, "2");
+	}
+}
+
+struct timeval timeget(void)
+{
+	struct timeval now;
+	unsigned char  timestr[60] = {0};
+	unsigned char  uptimestr[30] = {0};
+	unsigned char * dotaddr = NULL;
+	unsigned long second;
+	char error = 0;
+	FILE * timefile = NULL;
+    int read_len = 0;
+
+	timefile = fopen("/proc/uptime", "r");
+	if (!timefile) {
+		printf("[%s:line:%d] error opening '/proc/uptime'", __FILE__, __LINE__);
+		error = 1;
+		goto out;
+	}
+	//klocwork  cov M
+	read_len = fread(timestr, sizeof(char), sizeof(timestr)-1, timefile);
+	if (read_len == 0 ) {
+		printf("[%s:line:%d] read '/proc/uptime' error", __FILE__, __LINE__);
+		error = 1;
+		goto out;
+	}
+	timestr[sizeof(timestr)-1] = '\0';//cov
+	dotaddr = strchr(timestr, '.');
+	if (dotaddr != NULL && (dotaddr - timestr) < (30 - 2))//cov
+		memcpy(uptimestr, timestr, dotaddr - timestr + 2);
+	else {
+		printf("[%s:line:%d] uptime string is too long", __FILE__, __LINE__);
+		error = 1;
+		goto out;
+	}
+	uptimestr[dotaddr - timestr + 2] = '\0';
+
+out:
+	if (error) {
+		now.tv_sec  = 0;
+		now.tv_usec = 0;
+	} else {
+		now.tv_sec  = atol(uptimestr);
+		now.tv_usec = 0;
+	}
+	if (timefile) {//klocwork
+		fclose(timefile);
+	}
+	return now;
+}
+
+unsigned long time_sec()
+{
+	struct timeval uptime;
+
+	uptime = timeget();
+	//printf("uptime = %lu \n",(unsigned long)uptime.tv_sec);
+	return uptime.tv_sec;
+}
+
+int get_lan_info_list(struct list_head *file_list_info)
+{
+	FILE *lanFile    = NULL;
+	char buf[32];
+
+	LAN_INFO_t lanInfo = {0};
+	char path_conf[50] = {0};
+	char path_file[100] = {0};
+
+	if (!list_empty(file_list_info)) {
+		return -1;
+	}
+
+	sc_cfg_get("path_conf", path_conf, sizeof(path_conf));
+	sprintf(path_file, "%s/laninfo.tmp", path_conf);
+
+	lanFile = fopen(path_file, "r");
+	if (lanFile == NULL) {
+		slog(NET_PRINT, SLOG_ERR, "fopen laninfo.tmp fail \n");
+		return 0;
+	}
+
+	while (fread(&lanInfo, sizeof(LAN_INFO_t), 1, lanFile) == 1) {
+		LAN_INFO_LIST_t *lanInfo_ptr = (LAN_INFO_LIST_t *)safe_malloc(sizeof(LAN_INFO_LIST_t), TRUE);
+		if (!lanInfo_ptr) {
+			slog(NET_PRINT, SLOG_ERR, "get_lan_info_list safe_malloc lanInfo_ptr fail \n");
+			return -1;
+		}
+		memcpy(&(lanInfo_ptr->lan_info), &lanInfo, sizeof(LAN_INFO_t));
+		list_add_tail(&lanInfo_ptr->list, file_list_info);
+	}
+
+	fclose(lanFile);
+	return 0;
+
+}
+
+/* ÉèÖó¬Ê±Ëø£¬ ³¬Ê±0±íʾÓÀ¾ÃËø - Ôݲ»¶ÔÍ⣬ÐèÒªms¼¶±ðʱ¿ª·Å */
+int set_wake_lock_timeout_ms(const char *lockid, unsigned long interval_ms)
+{
+	char *p = NULL;
+	int ret = -1;
+
+	if ((lockid == NULL) || (*lockid == '\0')) 
+		return -1;
+
+	if (interval_ms == 0) {
+		ret = asprintf(&p, "%s", lockid);
+	} else {
+		ret = asprintf(&p, "%s %lu000000", lockid, interval_ms);
+	}
+	if (ret < 0) {
+		ret = -1;
+		goto out;
+	}
+	ret = write_to_file(WAKE_LOCK_PATH, p, strlen(p));
+	
+out:
+	safe_free(p);
+	return ret;
+}
+
+/* »ñÈ¡wakelockËø */
+int set_wake_lock(const char *lockId)
+{
+	return set_wake_lock_timeout_ms(lockId, 0);
+}
+
+/* ÉèÖó¬Ê±Ëø */
+int set_wake_lock_timeout(const char *lockId, unsigned long seconds)
+{
+	return set_wake_lock_timeout_ms(lockId, seconds * 1000);
+}
+
+/* ÊÍ·ÅwakelockËø */
+int set_wake_unlock(const char *lockId)
+{
+	if ((lockId == NULL) || (*lockId == '\0'))
+		return -1;
+	
+	return write_to_file(WAKE_UNLOCK_PATH, lockId, strlen(lockId));
+}
+
+int readNlSock(int sockFd, char *bufPtr, int seqNum, int pId)
+{
+	struct nlmsghdr *nlHdr;
+	int readLen = 0, msgLen = 0;
+	do {
+		//ÊÕµ½Äں˵ÄÓ¦´ð
+		if ((readLen = recv(sockFd, bufPtr, BUFSIZE - msgLen, 0)) < 0) {
+			perror("SOCK READ: ");
+			return -1;
+		}
+
+
+		nlHdr = (struct nlmsghdr *)bufPtr;
+		//¼ì²éheaderÊÇ·ñÓÐЧ
+		if ((NLMSG_OK(nlHdr, readLen) == 0) || (nlHdr->nlmsg_type == NLMSG_ERROR)) {
+			perror("Error in recieved packet");
+			return -1;
+		}
+
+
+
+
+		if (nlHdr->nlmsg_type == NLMSG_DONE) {
+			break;
+		} else {
+			bufPtr += readLen;
+			msgLen += readLen;
+		}
+
+		if ((nlHdr->nlmsg_flags & NLM_F_MULTI) == 0) {
+			break;
+		}
+	} while ((nlHdr->nlmsg_seq != seqNum) || (nlHdr->nlmsg_pid != pId));
+	return msgLen;
+}
+
+//coverity
+static int net_RTA_OK(struct rtattr *rta, unsigned int len)
+{
+	return RTA_OK(rta, len);
+}
+
+//·ÖÎö·µ»ØµÄ·ÓÉÐÅÏ¢
+void parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
+{
+	struct rtmsg *rtMsg;
+	struct rtattr *rtAttr;
+	int rtLen, dstLen;
+	//char *tempBuf = NULL;
+	struct in_addr dst;
+	struct in_addr gate;
+	char cmd[128];
+	char dstaddr[32], srcaddr[32];
+
+
+	//tempBuf = (char *)malloc(100);
+	rtMsg = (struct rtmsg *)NLMSG_DATA(nlHdr);
+	// If the route is not for AF_INET or does not belong to main routing table
+	//then return.
+	if ((rtMsg->rtm_family != AF_INET) || (rtMsg->rtm_table != RT_TABLE_MAIN))
+		return;
+	//printf("rtmsg srclen:%d,dstlen:%d\n",rtMsg->rtm_src_len,rtMsg->rtm_dst_len);
+	dstLen = rtMsg->rtm_dst_len; //·ÓɱíÖÐÄ¿µÄµØÖ·µÄÑÚÂ볤¶È
+
+
+	rtAttr = (struct rtattr *)RTM_RTA(rtMsg);
+	rtLen = RTM_PAYLOAD(nlHdr);
+	for (; net_RTA_OK(rtAttr, rtLen); rtAttr = RTA_NEXT(rtAttr, rtLen)) {
+		switch (rtAttr->rta_type) {
+		case RTA_OIF:
+			if_indextoname(*(int *)RTA_DATA(rtAttr), rtInfo->ifName);       //Íø¿¨Ãû³Æ
+			break;
+		case RTA_GATEWAY:
+			rtInfo->gateWay = *(u_int *)RTA_DATA(rtAttr);                       //´ËÌõ·ÓÉÏîµÄÍø¹Ø
+			break;
+		case RTA_PREFSRC:
+			rtInfo->srcAddr = *(u_int *)RTA_DATA(rtAttr);                       //·ÓÉÏîµÄÔ´µØÖ·
+			break;
+		case RTA_DST:
+			rtInfo->dstAddr = *(u_int *)RTA_DATA(rtAttr);                       //·ÓÉÏîÖеÄÄ¿µÄµØÖ·
+			break;
+		}
+	}
+	dst.s_addr = rtInfo->dstAddr;
+
+	printf("oif:%s\t", rtInfo->ifName);
+	gate.s_addr = rtInfo->gateWay;
+	printf("%s\n", (char *)inet_ntoa(gate));
+
+	printf("src:%s\n", (char *)inet_ntoa(gate));
+	snprintf(srcaddr, sizeof(srcaddr), "%s", (char *)inet_ntoa(gate));//klocwork
+	gate.s_addr = rtInfo->dstAddr;
+	printf("dst:%s\n", (char *)inet_ntoa(gate));
+
+	//free(tempBuf);
+	return;
+}
+
+/****************************************/
+//½Ó¿Ú¹¦ÄÜ£º ¼ì²âÊÇ·ñÅäÖÃÁËȱʡ·ÓÉ£¬ÐèÒªÁ¬ÍâÍøµÄÓ¦ÓÿÉÒÔµ÷Óñ¾½Ó¿ÚÅжÏÍøÂçÊÇ·ñ¾ÍÐ÷
+//return:
+//    -1: error;
+//     0: ÍøÂçδ¾ÍÐ÷
+//     1: ÍøÂçÒѾÍÐ÷
+/****************************************/
+int default_route_check()
+{
+	struct nlmsghdr *nlMsg;
+	struct rtmsg *rtMsg;
+	struct route_info *rtInfo;
+	char *msgBuf = malloc(BUFSIZE);
+
+
+	int sock, len, msgSeq = 0;
+
+    if(NULL == msgBuf) {
+        softap_assert("");
+		return -1;//klocwork
+    }
+
+	if ((sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) {
+		perror("Socket Creation: ");
+		free(msgBuf);
+		return -1;
+	}
+
+	memset(msgBuf, 0, BUFSIZE);
+
+	nlMsg = (struct nlmsghdr *)msgBuf;
+	rtMsg = (struct rtmsg *)NLMSG_DATA(nlMsg);
+	nlMsg->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); // Length of message.
+	nlMsg->nlmsg_type = RTM_GETROUTE; // Get the routes from kernel routing table .
+	nlMsg->nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; // The message is a request for dump.
+	nlMsg->nlmsg_seq = msgSeq++; // Sequence of the message packet.
+	nlMsg->nlmsg_pid = getpid(); // PID of process sending the request.
+
+	if (send(sock, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
+		printf("Write To Socket Failed¡­\n");
+		free(msgBuf);
+		close(sock);
+		return -1;
+	}
+
+	if ((len = readNlSock(sock, msgBuf, msgSeq, getpid())) < 0) {
+		printf("Read From Socket Failed¡­\n");
+		free(msgBuf);
+		close(sock);
+		return -1;
+	}
+
+
+	rtInfo = (struct route_info *)malloc(sizeof(struct route_info));
+	if (NULL == rtInfo) { //klocwork
+		printf("Malloc route_info Failed¡­\n");
+		free(msgBuf);
+		close(sock);
+		return -1;
+	}
+	for (; NLMSG_OK(nlMsg, len); nlMsg = NLMSG_NEXT(nlMsg, len)) {
+		memset(rtInfo, 0, sizeof(struct route_info));
+		parseRoutes(nlMsg, rtInfo);
+		if (rtInfo->dstAddr == 0 && strlen(rtInfo->ifName)) {
+			printf("default wan :%s \n", rtInfo->ifName);
+			free(rtInfo);
+			close(sock);
+			free(msgBuf);
+			return 1;
+		}
+	}
+	free(rtInfo);
+	close(sock);
+	free(msgBuf);
+	return 0;
+}
+
+
+
+/**************************************/
+//½Ó¿Ú¹¦ÄÜ:   ¼ì²âflashÊÇ·ñ±»ÆäËûºËÕ¼ÓÃ
+//return:
+//             0   -----  flashûÓб»Õ¼ÓÃ
+//		   1   -----  flashÕý±»ÆäËûºËÕ¼ÓÃ
+//		  -1  -----  open½Úµãʧ°Ü
+//		  -2  -----  ioctlʧ°Ü
+/**************************************/
+
+int flash_mutex_check()
+{
+	int fd, ret;
+	char arg = 3;
+	fd = open("/dev/softspinlock", O_RDWR);
+	//printf("fd = %d \n",fd);
+	if (fd < 0)
+		return -1;
+
+	ret = ioctl(fd, SPINLOCK_GET_STATUS, &arg);
+	//printf("ret = %d  arg = %d \n",ret,arg);
+	if (ret < 0) {
+		close(fd);
+		return -2;
+	}
+	close(fd);
+	return arg;
+
+}
+
+//»ñȡָ¶¨Ïß³ÌÃûµÄpidºÅ£¬×¢Ò⣺µ÷Óøú¯Êý»ñÈ¡·µ»ØÖµ£¬Ê¹ÓúóÒ»¶¨ÒªÊͷŸÃÄÚ´æ¿Õ¼ä
+pid_t* find_pid_by_name(char *pidName)
+{
+	DIR *dir;
+	struct dirent *next;
+	pid_t* pidList = NULL;
+	pid_t* tmpList = NULL;
+	int i = 0;
+	
+	//procÖаüÀ¨µ±Ç°µÄ½ø³ÌÐÅÏ¢£¬¶ÁÈ¡¸ÃĿ¼
+	dir = opendir("/proc");
+	if(!dir)
+	{
+		perror("Cannot open /proc");
+		return pidList;
+	}
+	//±éÀú/procÏÂĿ¼
+	while((next = readdir(dir)) != NULL)
+	{
+		FILE *status;
+		char filename[READ_BUF_SIZE] = {0};//klocwork
+		char filename1[READ_BUF_SIZE] = {0};//klocwork
+		char name[READ_BUF_SIZE] = {0};
+		//skip ".." since that is outside /proc
+		if(0 == strcmp(next->d_name,".."))
+			continue;
+		//if it isn't a number,we skip it
+		if(!isdigit(*next->d_name))
+			continue;
+		
+		snprintf(filename,sizeof(filename),"/proc/%s/status",next->d_name);
+
+		if(!(status = fopen(filename,"r")))
+		{
+			continue;
+		}
+		if(NULL == fgets(filename1,READ_BUF_SIZE-1,status))
+		{
+			fclose(status);
+			continue;
+		}
+		fclose(status);
+		
+		//»ñÈ¡½ø³Ìpid£¬Í¬Ê±Ò²»áÓжà¸öÏàͬ½ø³ÌÃûµÄÇé¿ö
+		sscanf(filename1, "%*s %s", name);
+		if(0 == strcmp(name,pidName))
+		{
+			//pidList = realloc(pidList,sizeof(pid_t)*(i+2));
+			//klocwork
+			tmpList = realloc(pidList,sizeof(pid_t)*(i+2));
+			if (NULL == tmpList) {
+				continue;
+			}
+			pidList = tmpList;
+			errno = 0;
+			pidList[i++] = strtol(next->d_name,NULL,0);
+			if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
+			{
+				printf("strtol errno %d: %s\n", errno, strerror(errno));
+			}
+		}
+	}
+	if(pidList)
+	{
+		pidList[i] = 0;
+	}
+	closedir(dir);
+	return pidList;
+}
+
+void handle_quit(int signo)
+{
+    pthread_exit(NULL);
+}
+
+/* gethostbyname¹¦ÄÜÖж¨Ê±Æ÷³¬Ê±´¦Àíº¯Êý */
+void gethostbyname_timeout(int msg_id)
+{
+	slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_timeout begin,msg_id=%d\n",msg_id);
+	if(ipc_send_message(msg_id, msg_id, MSG_GET_HOST_BY_NAME_TIMEOUT,0, 0, 0) < 0)
+    {
+        // todo: for cov M
+    }        
+}
+
+/**
+* gethostbyname¹¦ÄÜÖд´½¨¶¨Ê±Æ÷
+* second_time: ³¬Ê±Ê±³¤
+* msg_id:         Ïß³Ìid
+*/
+void gethostbyname_creattimer(int second_time, int msg_id)
+{
+	slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_creattimer begin\n");
+	sc_timer_delete(TIMER_GETHOSTBYNAME_ID);
+	sc_timer_create(TIMER_GETHOSTBYNAME_ID, TIMER_FLAG_ONCE, second_time*1000, gethostbyname_timeout, (void *)msg_id);
+}
+
+/* gethostbyname¹¦ÄÜÖÐɾ³ý¶¨Ê±Æ÷ */
+void gethostbyname_deletetimer()
+{
+	slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_deletetimer begin\n");
+	sc_timer_delete(TIMER_GETHOSTBYNAME_ID);
+}
+
+void *gethostbyname_timer(void *arg)
+{
+	int time = 0;
+	char *name = NULL;
+	int msg_id;
+	struct hostent* hptr = NULL;
+	
+	time =((struct gethostbyname_info *)arg)->time;
+	name = ((struct gethostbyname_info *)arg)->name;
+	msg_id = ((struct gethostbyname_info *)arg)->msg_id;
+
+	slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_timer time=%d,name=%s,msg_id=%d\n", time, name, msg_id);
+	
+	signal(SIGQUIT, handle_quit);
+	
+	gethostbyname_creattimer(time, msg_id); //Æð¶¨Ê±Æ÷
+	
+	hptr = gethostbyname(name);
+	if(NULL != hptr) //»ñÈ¡µ½hostÐÅÏ¢
+	{
+		slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_timer get info\n");
+		gethostbyname_deletetimer(); //ɾ³ý¶¨Ê±Æ÷
+		slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_timer result hostname=%s\n",hptr->h_name);
+		//¸øÖ÷½ø³Ì·¢ÏûÏ¢
+		if(ipc_send_message(msg_id, msg_id, MSG_GET_HOST_BY_NAME_SUCCESS, sizeof(void *), (UCHAR *)&hptr, 0) < 0)
+        {
+            // todo: for cov M
+        }      
+		pthread_exit(NULL);
+	}
+	return NULL;
+}
+
+//·â×°gethostbynameº¯Êý£¬Ôö¼ÓÒ»¸ö³¬Ê±Ê±¼äµÄÈë²Î£¬timeµ¥Î»ÎªÃë
+//Èç¹û³¬¹ý³¬Ê±Ê±¼äÈÔÈ»»ñÈ¡²»µ½hostÐÅÏ¢£¬Ôòº¯Êý·µ»Ø²»¼ÌÐø×èÈû
+//¶¨Ê±Æ÷IDÏß³ÌÄÚ¹²Ïí£¬Ò»¸ö½ø³Ì²»ÒªÍ¬Ê±µ÷ÓøýӿÚ
+struct hostent *gethostbyname_t(const char *name, int time)
+{
+	slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t begin\n");
+	pthread_t pthread;
+	int my_handle = 0;
+	int module_id = MODULE_ID_AP_GETHOSTBYNAME_BASE;
+	int ret = 0;
+	int msg_ret = 0;
+	struct hostent* hostresultinfo = NULL;
+	struct gethostbyname_info myhostinfo = {0};
+	MSG_BUF rsp_msg = {0};
+	LONG msgSize =  sizeof(MSG_BUF) - sizeof(LONG);
+	if(0 == time)
+	{
+		slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t time =0\n");
+		return gethostbyname(name);
+	}
+	else
+	{
+		slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t time = %d\n",time);
+
+        //¶¯Ì¬´´½¨ÁÙʱµÄÏûÏ¢¶ÓÁйܵÀ
+        //msggetʹÓòÎÊýIPC_CREAT | IPC_EXCL| 0600£¬Åжϵ±Ç°module_idµÄÏûÏ¢¶ÓÁÐÊÇ·ñ
+        //´æÔÚ£¬Èç¹û²»´æÔÚ£¬Ö±½Ó´´½¨ÐµÄÏûÏ¢¶ÓÁУ»Èç¹û´æÔÚ£¬·µ»ØÖµÎ´-1£¬È»ºómodule_id
+        //Öµ¼Ó1£¬²»¶ÏÑ­»·Ö±µ½ÕÒµ½Ã»ÓÐʹÓõÄmodule_idÖµ
+		while((my_handle = msgget(module_id,IPC_CREAT | IPC_EXCL| 0600)) == -1) 
+		{
+        	module_id++;
+			//µ±module_id´óÓÚMODULE_ID_ATDYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ
+			if (module_id > MODULE_ID_AP_GETHOSTBYNAME_END) 
+			{
+				softap_assert("MODULE_ID_AP_GETHOSTBYNAME_END!!!!!!!!!!!\n");
+			}
+		}
+		myhostinfo.time = time;
+		strncpy(myhostinfo.name, name, sizeof(myhostinfo.name)-1);
+		myhostinfo.msg_id = module_id;
+		//Æð×ÓỊ̈߳¬ÔÚ×ÓÏß³ÌÀï´´½¨¶¨Ê±Æ÷
+		ret = pthread_create(&pthread, NULL, (void *)gethostbyname_timer, (void *)&myhostinfo);
+		if (ret < 0 || pthread == NULL) {
+			slog(NET_PRINT, SLOG_DEBUG, "creat thread fail\n");
+			return NULL;
+		}
+		while(1)
+		{
+			msg_ret = 0;
+			memset(&rsp_msg, 0x00, sizeof(MSG_BUF));
+			msg_ret = msgrcv(my_handle, &rsp_msg, msgSize, 0, 0);
+			if (msg_ret < 0)
+        	{
+        		continue;
+			}
+
+			if(rsp_msg.usMsgCmd == MSG_GET_HOST_BY_NAME_SUCCESS)
+			{
+				slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t success\n");
+				hostresultinfo = (struct hostent*)(*(int *)rsp_msg.aucDataBuf);
+				slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t result:name=%s\n",hostresultinfo->h_name);
+				return hostresultinfo;
+			}
+			else if(rsp_msg.usMsgCmd == MSG_GET_HOST_BY_NAME_TIMEOUT)
+			{
+				slog(NET_PRINT, SLOG_DEBUG, "gethostbyname_t fail\n");
+				pthread_kill(pthread, SIGQUIT);
+				return NULL;
+			}
+			else
+			{
+				slog(NET_PRINT, SLOG_ERR, "gethostbyname_t fail\n");
+			}
+		}
+	}
+}
+
+/******************************************************************************/
+
+#define DNS_SERVER_NUM 2
+
+#define T_A 1 //Ipv4 address
+#define T_NS 2 //Nameserver
+#define T_CNAME 5 // canonical name
+#define T_SOA 6 /* start of authority zone */
+#define T_PTR 12 /* domain name pointer */
+#define T_MX 15 //Mail server
+
+
+
+//DNS header structure
+struct DNS_HEADER {
+	unsigned short id; // identification number
+
+	unsigned char rd :1; // recursion desired
+	unsigned char tc :1; // truncated message
+	unsigned char aa :1; // authoritive answer
+	unsigned char opcode :4; // purpose of message
+	unsigned char qr :1; // query/response flag
+
+	unsigned char rcode :4; // response code
+	unsigned char cd :1; // checking disabled
+	unsigned char ad :1; // authenticated data
+	unsigned char z :1; // its z! reserved
+	unsigned char ra :1; // recursion available
+
+	unsigned short q_count; // number of question entries
+	unsigned short ans_count; // number of answer entries
+	unsigned short auth_count; // number of authority entries
+	unsigned short add_count; // number of resource entries
+};
+
+//Constant sized fields of query structure
+struct QUESTION {
+	unsigned short qtype;
+	unsigned short qclass;
+};
+
+//Constant sized fields of the resource record structure
+#pragma pack(push, 1)
+struct R_DATA {
+	unsigned short type;
+	unsigned short _class;
+	unsigned int ttl;
+	unsigned short data_len;
+};
+#pragma pack(pop)
+
+//Pointers to resource record contents
+struct RES_RECORD {
+	unsigned char *name;
+	struct R_DATA *resource;
+	unsigned char *rdata;
+};
+
+//Structure of a Query
+typedef struct {
+	unsigned char *name;
+	struct QUESTION *ques;
+} QUERY;
+
+
+void ChangetoDnsNameFormat(unsigned char* dns, unsigned char* host) {
+	int lock = 0, i;
+	strcat((char*) host, ".");
+
+	for (i = 0; i < strlen((char*) host); i++) {
+		if (host[i] == '.') {
+			*dns++ = i - lock;
+			for (; lock < i; lock++) {
+				*dns++ = host[lock];
+			}
+			lock++; //or lock=i+1;
+		}
+	}
+	*dns++ = '\0';
+}
+
+u_char* ReadName(unsigned char* reader, unsigned char* buffer, int* count) {
+	unsigned char *name;
+	unsigned int p = 0, jumped = 0, offset;
+	int i, j;
+
+	*count = 1;
+	name = (unsigned char*) malloc(256);
+	if (!name)
+		return NULL;//klocwork
+
+	name[0] = '\0';
+
+	//read the names in 3www6google3com format
+	while (*reader != 0) {
+		if (*reader >= 192) {
+			offset = (*reader) * 256 + *(reader + 1) - 49152; //49152 = 11000000 00000000 ;)
+			reader = buffer + offset - 1;
+			jumped = 1; //we have jumped to another location so counting wont go up!
+		} else {
+			name[p++] = *reader;
+		}
+
+		reader = reader + 1;
+
+		if (jumped == 0) {
+			*count = *count + 1; //if we havent jumped to another location then we can count up
+		}
+	}
+
+	name[p] = '\0'; //string complete
+	if (jumped == 1) {
+		*count = *count + 1; //number of steps we actually moved forward in the packet
+	}
+
+	//now convert 3www6google3com0 to www.google.com
+	for (i = 0; i < (int) strlen((const char*) name); i++) {
+		p = name[i];
+		for (j = 0; j < (int) p; j++) {
+			name[i] = name[i + 1];
+			i = i + 1;
+		}
+		name[i] = '.';
+	}
+	name[i - 1] = '\0'; //remove the last dot
+	return name;
+}
+
+unsigned long my_gethostbyname(unsigned char *host, char *dev_name,char* dns_server, int query_type) {
+	unsigned char buf[1025], *qname, *reader;
+	int i, j, stop, s, ans_max;
+	struct timeval tv;
+	unsigned long ret = 0;
+	struct ifreq ifr;
+	
+	struct sockaddr_in a;
+
+	struct RES_RECORD answers[20], auth[20], addit[20]; //the replies from the DNS server
+	struct sockaddr_in dest;
+
+	struct DNS_HEADER *dns = NULL;
+	struct QUESTION *qinfo = NULL;
+
+	printf("Resolving %s", host);
+
+	s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); //UDP packet for DNS queries
+	if(s < 0)
+    {
+        printf("socket return fail \n");
+        return ret;
+    }   
+	
+	memset(&ifr,0,sizeof(ifr));    
+	strncpy(ifr.ifr_name, dev_name, sizeof(ifr.ifr_name)-1);
+	if(setsockopt(s,SOL_SOCKET,SO_BINDTODEVICE,(char*)&ifr,sizeof(ifr)) < 0){
+		printf("SO_BINDTODEVICE fail \n");
+		goto out;
+	}
+	tv.tv_sec = 5;
+	tv.tv_usec = 0;
+	if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+		printf("socket option  SO_RCVTIMEO not support\n");
+		goto out;
+	}
+	dest.sin_family = AF_INET;
+	dest.sin_port = htons(53);
+	dest.sin_addr.s_addr = inet_addr(dns_server); //dns servers
+
+	//Set the DNS structure to standard queries
+	dns = (struct DNS_HEADER *) &buf;
+
+	dns->id = (unsigned short) htons(getpid());
+	dns->qr = 0; //This is a query
+	dns->opcode = 0; //This is a standard query
+	dns->aa = 0; //Not Authoritative
+	dns->tc = 0; //This message is not truncated
+	dns->rd = 1; //Recursion Desired
+	dns->ra = 0; //Recursion not available! hey we dont have it (lol)
+	dns->z = 0;
+	dns->ad = 0;
+	dns->cd = 0;
+	dns->rcode = 0;
+	dns->q_count = htons(1); //we have only 1 question
+	dns->ans_count = 0;
+	dns->auth_count = 0;
+	dns->add_count = 0;
+
+	//point to the query portion
+	qname = (unsigned char*) &buf[sizeof(struct DNS_HEADER)];
+
+	ChangetoDnsNameFormat(qname, host);
+	qinfo = (struct QUESTION*) &buf[sizeof(struct DNS_HEADER)
+			+ (strlen((const char*) qname) + 1)]; //fill it
+
+	qinfo->qtype = htons(query_type); //type of the query , A , MX , CNAME , NS etc
+	qinfo->qclass = htons(1); //its internet (lol)
+
+	printf("\nSending Packet...");
+	if (sendto(s, (char*) buf,
+			sizeof(struct DNS_HEADER) + (strlen((const char*) qname) + 1)
+					+ sizeof(struct QUESTION), 0, (struct sockaddr*) &dest,
+			sizeof(dest)) < 0) {
+		perror("sendto failed");
+	}
+	printf("Done");
+
+	//Receive the answer
+	i = sizeof dest;
+	printf("\nReceiving answer...");
+	if (recvfrom(s, (char*) buf, sizeof(buf)-1, 0, (struct sockaddr*) &dest,
+			(socklen_t*) &i) < 0) {
+		perror("recvfrom failed");
+	}
+	*(buf+sizeof(buf)-1) = 0;
+	printf("Done");
+
+	dns = (struct DNS_HEADER*) buf;
+	if((sizeof(struct DNS_HEADER) + 
+		(strlen((const char*) qname) + 1)+ 
+		sizeof(struct QUESTION)) >= sizeof(buf))
+	{
+		perror("my_gethostbyname error");
+		goto out;
+	}
+	
+	//move ahead of the dns header and the query field
+	reader = &buf[sizeof(struct DNS_HEADER) + (strlen((const char*) qname) + 1)
+			+ sizeof(struct QUESTION)];
+
+	//printf("\nThe response contains : ");
+	//printf("\n %d Questions.", ntohs(dns->q_count));
+	//printf("\n %d Answers.", ntohs(dns->ans_count));
+	//printf("\n %d Authoritative Servers.", ntohs(dns->auth_count));
+	//printf("\n %d Additional records.\n\n", ntohs(dns->add_count));
+
+	//Start reading answers
+	stop = 0;
+	//klocwork
+	//ans_max = ((ntohs(dns->ans_count) <= (sizeof(answers)/sizeof(answers[0]))) ? ntohs(dns->ans_count) : (sizeof(answers)/sizeof(answers[0])));
+	ans_max = ntohs(dns->ans_count);
+	if (ans_max > (sizeof(answers)/sizeof(answers[0])))
+		ans_max = (sizeof(answers)/sizeof(answers[0]));
+	for (i = 0; i < ans_max; i++) 
+	{
+		answers[i].name = ReadName(reader, buf, &stop);
+		reader = reader + stop;
+
+		answers[i].resource = (struct R_DATA*) (reader);
+		reader = reader + sizeof(struct R_DATA);
+
+		if (ntohs(answers[i].resource->type) == 1) //if its an ipv4 address
+				{
+			answers[i].rdata = (unsigned char*) malloc(
+					ntohs(answers[i].resource->data_len));
+
+			for (j = 0; j < ntohs(answers[i].resource->data_len); j++) {
+				answers[i].rdata[j] = reader[j];
+			}
+
+			answers[i].rdata[ntohs(answers[i].resource->data_len)] = '\0';
+
+			reader = reader + ntohs(answers[i].resource->data_len);
+		} else {
+			answers[i].rdata = ReadName(reader, buf, &stop);
+			reader = reader + stop;
+		}
+	}
+
+	//print answers
+	printf("\nAnswer Records : %d \n", ntohs(dns->ans_count));
+	for (i = 0; i < ans_max; i++) {
+		printf("Name : %s ", answers[i].name);
+
+		if (ntohs(answers[i].resource->type) == T_A) //IPv4 address
+		{
+			long *p;
+			p = (long*) answers[i].rdata;
+			a.sin_addr.s_addr = (*p); //working without ntohl
+#if 1       // cov M
+			char * s_addr = inet_ntoa(a.sin_addr);
+			printf("has IPv4 address : %s", s_addr);
+#else
+            printf("has IPv4 address : %s", inet_ntoa(a.sin_addr));
+#endif
+			ret = (unsigned long)a.sin_addr.s_addr;
+		}
+
+		if (ntohs(answers[i].resource->type) == 5) {
+			//Canonical name for an alias
+			printf("has alias name : %s", answers[i].rdata);
+		}
+
+		printf("\n");
+	}
+out:
+	close(s);
+	return ret;
+}
+
+
+unsigned long gethostbyname_l(char *hostname,char* dev_name) 
+{
+	int i = 0;
+	unsigned long ret = 0;
+	char dns_servers[DNS_SERVER_NUM][32] = {0};
+
+	//Get the DNS servers from the resolv.conf file
+	char nv_dns[32]	= {0};
+	char ip_dns[32]	= {0};
+	
+    sprintf(nv_dns, "%s_pridns", dev_name);
+	sc_cfg_get(nv_dns, ip_dns, sizeof(ip_dns));
+	strcpy(dns_servers[0], ip_dns);
+
+	memset(nv_dns,0,sizeof(nv_dns));
+	memset(ip_dns,0,sizeof(ip_dns));
+	sprintf(nv_dns, "%s_secdns", dev_name);
+	sc_cfg_get(nv_dns, ip_dns, sizeof(ip_dns));
+	strcpy(dns_servers[1], ip_dns);
+
+	
+	//Now get the ip of this hostname , A record
+	for(i=0;i<DNS_SERVER_NUM;i++)
+	{
+		ret = my_gethostbyname(hostname, dev_name , dns_servers[i], T_A);
+		if(ret > 0)
+			break;
+	}
+ 
+	return ret;
+}
+
+
+
+
+/******************************************************************************/
+
+
diff --git a/ap/lib/libsoftap/readme.txt b/ap/lib/libsoftap/readme.txt
new file mode 100755
index 0000000..458ab9a
--- /dev/null
+++ b/ap/lib/libsoftap/readme.txt
@@ -0,0 +1,4 @@
+¸ºÔðÈýÖÖ¹«¹²½Ó¿Ú£º
+1¡¢ÓëÄں˵Ĺ«¹²½Ó¿Ú£¬Èçnetioc£¬½ö¸ºÔð½á¹¹ÌåÐÅÏ¢µÄ»ñÈ¡Óëset£¬²»×¼½øÐÐifÅжϣ¬ËùÓеÄifÅжϼ°´òÓ¡£¬·Åµ½¸÷¸öÓ¦Óýø³ÌµÄcaseÀïÃæ£»
+2¡¢ÍøÂç½ø³Ì¼äµÄ½»»¥ÐÅÏ¢£¬ÈçnetdogÓënet_monitor½ø³Ì¼äµÄÐÅÏ¢½Ó¿Ú£»
+3¡¢ÍøÂç½ø³ÌÓëÍⲿµÄ½»»¥ÐÅÏ¢£¬ÈçnetapiÖеĽӿڣ»
\ No newline at end of file
diff --git a/ap/lib/libsoftap/rtc_timer.c b/ap/lib/libsoftap/rtc_timer.c
new file mode 100755
index 0000000..c17d668
--- /dev/null
+++ b/ap/lib/libsoftap/rtc_timer.c
@@ -0,0 +1,155 @@
+
+/**************************************************************************
+* #includeÇø
+**************************************************************************/
+#include  <stdio.h>
+#include  <stdlib.h>
+#include  <signal.h>
+#include  <sys/time.h>
+#include  <syslog.h>
+#include  <fcntl.h>
+#include  <pthread.h>
+#include  <stdlib.h>
+#include  <string.h>
+#include  <errno.h>
+#include  <sys/types.h>
+#include  <sys/prctl.h>
+#include  <unistd.h>
+#include  <linux/rtc.h>
+#include  <time.h>
+#include  <sys/ipc.h>
+#include  <sys/msg.h>
+#include  "softap_api.h"
+#include  "message.h"
+#include  "rtc_timer.h"
+
+/**************************************************************************
+* Êý¾Ý½á¹¹¶¨ÒåÇø
+**************************************************************************/
+/**************************************************************************
+* Íⲿ±äÁ¿ÉùÃ÷Çø
+**************************************************************************/
+/**************************************************************************
+* ºê¶¨ÒåÇø
+**************************************************************************/
+
+/**************************************************************************/
+int rtc_timer_add(ULONG ulSec, RTC_ID  rtc_id, int src_id)//add_rtc_timer
+{
+	int ret = -1;
+	int data_len = 0;
+	RTC_DATA_BUF  buf = {0};
+	char rtc_cpu[16] = {0};
+	char rtc_cp_ready[8] = {0};
+
+	//¼à¿ØÓÐÄÄЩӦÓÃÉèÖÃÁ˶Ìʱ¼äµÄrtc
+	if (ulSec < 59)
+		slog(MISC_PRINT, SLOG_ERR,   "rtc time is %d, less than 60. src:0x%x, id:0x%x \n", ulSec, src_id, rtc_id);
+
+	buf.srcModule = src_id;
+	buf.module = rtc_id;
+	buf.ulSec = ulSec;
+	buf.wakeup = 0;
+	buf.is_utc = 0;
+	data_len = sizeof(RTC_DATA_BUF);
+	buf.time_val = time(0);
+	buf.cpu = RTC_CPU_AP;
+
+	ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_ADD_ALARM, data_len, (unsigned char *)&buf, 0);
+	if (ret != 0) {
+		slog(MISC_PRINT, SLOG_ERR,   "rtc: set rtc timer send msg failed \n");
+		return -1;
+	}
+
+	return ret;
+}
+
+int rtc_timer_add_utc(struct tm *sec, RTC_ID rtc_id, int src_id, int wakeup)//add_rtc_timer
+{
+	int ret = -1;
+	time_t cur_sec = time(0);
+	time_t set_sec = mktime(sec);
+	char sntp_result[20] = {0};
+	char rtc_cpu[16] = {0};
+	char rtc_cp_ready[8] = {0};
+
+	slog(MISC_PRINT, SLOG_ERR,   "rtc_timer_add_utc enter \n");
+
+#if 0
+	// ÉèÖÃÊÀ½çʱÖÓ¶¨Ê±Æ÷£¬±ØÐëµÈsntp³É¹¦ºó
+	sc_cfg_get("sntp_process_result", sntp_result, sizeof(sntp_result));
+	if (strcmp("success", sntp_result) != 0) {
+		slog(MISC_PRINT, SLOG_ERR,   "rtc: set utc timer should be after sntp success\n");
+		return ret;
+	}
+#endif
+	// ÉèÖö¨Ê±Æ÷ʱ¼ä±ØÐëÍíÓÚµ±Ç°Ê±¼ä
+	if (cur_sec >= set_sec) {
+		slog(MISC_PRINT, SLOG_ERR,   "rtc: set time-%ld should be after then currnet time-%ld\n", set_sec, cur_sec);
+		return ret;
+	}
+
+	int data_len = 0;
+	RTC_DATA_BUF buf = {0};
+
+	buf.srcModule = src_id;
+	buf.module = rtc_id;
+	buf.ulSec = set_sec - cur_sec;
+	buf.time_val = cur_sec;
+	buf.wakeup = wakeup;
+	buf.is_utc = 1;
+	buf.cpu = RTC_CPU_AP;
+	data_len = sizeof(RTC_DATA_BUF);
+
+	slog(MISC_PRINT, SLOG_ERR,   "rtc add utc timer, cur:%ld, set:%ld, ulSec:%d; year:%d, mon:%d, day:%d, hour:%d, min:%d, sec:%d, wday:%d, yday:%d \n", buf.time_val, set_sec, buf.ulSec, sec->tm_year, sec->tm_mon, sec->tm_mday, sec->tm_hour, sec->tm_min, sec->tm_sec, sec->tm_wday, sec->tm_yday);
+	ret =  ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_ADD_ALARM, data_len, (unsigned char *)&buf, 0);
+	if (ret != 0) {
+		slog(MISC_PRINT, SLOG_ERR,   "rtc: set rtc utc timer send msg failed \n");
+		return -1;
+	}
+
+	return ret;
+}
+
+int rtc_timer_del(RTC_ID rtc_id, int src_id)
+{
+	int ret = -1;
+	int data_len = 0;
+	RTC_DATA_BUF  buf = {0};
+
+	buf.srcModule = src_id;
+	buf.module = rtc_id;
+	buf.cpu = RTC_CPU_AP;
+	data_len = sizeof(RTC_DATA_BUF);
+
+	ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_DEL_ALARM, data_len, (unsigned char *) &buf, 0);
+	if (ret == 0)
+		return 0;
+	else
+		return -1;
+}
+
+int rtc_timer_del_all(int src_id, unsigned short req_cmd)
+{
+	int ret = -1;
+
+	ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_DEL_ALL, sizeof(unsigned short), &req_cmd, 0);
+	if (ret == 0)
+		return 0;
+	else
+		return -1;
+}
+
+int  rtc_set_time(int src_id)
+{
+	int ret = -1;
+	time_t cur_time = time(0);
+
+	ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_SET_TIME, sizeof(time_t), &cur_time, 0);
+	if (ret == 0)
+		return 0;
+	else
+		return -1;
+}
+
+
diff --git a/ap/lib/libsoftap/softap_api.c b/ap/lib/libsoftap/softap_api.c
new file mode 100755
index 0000000..d76371c
--- /dev/null
+++ b/ap/lib/libsoftap/softap_api.c
@@ -0,0 +1,496 @@
+/**
+ * @file softap_api.c
+ * @brief Implementation of Sanechips
+ *
+ * Copyright (C) 2017 Sanechips Technology Co., Ltd.
+ * @author linxu Gebin
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <syslog.h>
+#include <sys/klog.h>
+#include <sys/msg.h>
+#include <sys/socket.h>
+#include <linux/sockios.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <limits.h>
+#include "softap_api.h"
+
+
+/* ƽ̨»ù´¡Ó¦Ó㬼´: ËùÓÐÐͺŻú¶¼ÐèÒªÆô¶¯µÄÓ¦Óà */
+static int basic_apps[] = {
+	MODULE_ID_AT_CTL,			// AT
+	MODULE_ID_MAIN_CTRL,		// Ö÷¿Ø
+	MODULE_ID_RTC_SERVICE,		// rtc
+	MODULE_ID_CODEC				// audio ctrl
+};
+
+static int is_basic_app(int module_id)
+{
+	int i = 0;
+
+	for (i = 0; i < sizeof(basic_apps) / sizeof(basic_apps[0]); i++) {
+		if (module_id == basic_apps[i]) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
+//»ñÈ¡¶àºË»ù׼ʱ¼ä
+long long int get_time_us()
+{
+	int fd;
+	char buf[128] = {0};
+	
+	fd = open("/proc/persistent_time", O_RDWR);
+	if (fd < 0) {
+		printf("fail to open\n");
+		return -1;
+	}
+#if 1
+    int len = read(fd, buf, sizeof(buf)-1);
+    long long time = 0;
+
+    if(len < 0 ){
+		close(fd);
+		return -1;
+    }else{
+		close(fd);
+		time =  atoll(buf); 
+        if(time < 0 || time > LLONG_MAX-1)
+        {
+            time  = 0;
+        }
+
+        return time;
+    }
+#else
+	if (read(fd, buf, 127) > 0) {
+		close(fd);
+		return  atoll(buf);
+	} else {
+		close(fd);
+		return -1;
+	}
+#endif    
+}
+
+/**************************************************************************
+* º¯ÊýÃû³Æ£º soc_send_condition_check
+* ¹¦ÄÜÃèÊö£º ¼ì²âÊÇ·ñÂú×ãSOCÏûÏ¢·¢ËÍÌõ¼þ£¬Èç¹ûÊÇ´ÓAP·¢Ë͵½CP£¬Ôòsrc_id±ØÐëΪAP²àµÄmoduleid£¬dst_id±ØÐëΪ
+*                           moduleid;  Èç¹ûÊÇ´ÓCP·¢Ë͵½AP£¬Ôòsrc_id±ØÐëΪCP²àµÄmoduleid£¬dst_id±ØÐëΪAP²àµÄmoduleid.
+* ²ÎÊý˵Ã÷£ºsrc_id:ÏûÏ¢·¢ËÍÄ£¿éID   dest_id:ÏûÏ¢½ÓÊÕÄ£¿éID
+* ·µ »Ø Öµ£º 1:·ûºÏÌõ¼þ0:²»·ûºÏÌõ¼þ
+* ÆäËü˵Ã÷£º
+**************************************************************************/
+static int soc_send_condition_check(int src_id, int dst_id)
+{
+#if (APP_OS_TYPE == APP_OS_TOS)
+	if ((src_id <= MODULE_ID_CPBASE) || (src_id >= MODULE_ID_MAX)) { //¼ì²âsrc_idÊÇ·ñΪCPºËÄ£¿éºÅ
+		return 0;
+	} else if ((dst_id <= MODULE_ID_APBASE) || (dst_id >= MODULE_ID_CPBASE)) { //¼ì²âdst_idÊÇ·ñΪAPºËÄ£¿éºÅ
+		return 0;
+	}
+
+	return 1;
+#endif
+
+#if (APP_OS_TYPE == APP_OS_LINUX)
+	if ((src_id <= MODULE_ID_APBASE) || (src_id >= MODULE_ID_CPBASE)) { //¼ì²âsrc_idÊÇ·ñΪAPºËÄ£¿éºÅ
+		return 0;
+	} else if ((dst_id <= MODULE_ID_CPBASE) || (dst_id >= MODULE_ID_MAX)) { //¼ì²âdst_idÊÇ·ñΪCPºËÄ£¿éºÅ
+		return 0;
+	}
+
+	return 1;
+
+#endif
+}
+
+/************************ Ó¦Óü乫¹²º¯ÊýʵÏÖ ************************/
+/*·µ»ØÖµ 0 ³É¹¦  ·Ç0ʧ°Ü£¬
+Èç¹û·µ»ØÖµµÈÓÚENOENT£¬±íʾ½ÓÊÕ¶ÓÁв»´æÔÚ£¬Ó¦ÓÃ×ÔÐÐÅжϽÓÊÕÄ£¿éÊÇ·ñÒ»¶¨Æô¶¯£¬Èç¹ûÊÇ£¬µ÷ÓÃipc_send_message2·¢ËÍ*/
+int ipc_send_message(int src_id, int dst_id, unsigned short Msg_cmd, unsigned short us_DataLen, unsigned char *pData, int msgflag)
+{
+	MSG_BUF stMsg;
+	int lRet = 0;
+	int lTgtMsgID = 0;
+	LONG msgSize = offsetof(MSG_BUF, aucDataBuf) - sizeof(LONG) + us_DataLen;
+	int errNo = 0;
+
+	memset(&stMsg, 0, sizeof(MSG_BUF));
+
+	lTgtMsgID = msgget(dst_id, 0);
+	if (-1 == lTgtMsgID) {
+		errNo = errno;
+		slog(NET_PRINT, SLOG_ERR, "send_message failed:can not get target msg id, src:0x%x, target:0x%x, cmd:0x%x, errNo:%d! \n", src_id, dst_id, Msg_cmd, errNo); /*lint !e26*/
+
+		/* »ù´¡Ó¦ÓñØÐë·¢Ëͳɹ¦£¬Èç¹ûÓ¦Óû¹Ã»Æð¾ÍÖ±½ÓÏÈ´´½¨ÏûÏ¢½ÓÊÕ¶ÓÁУ¬Æô¶¯ºóÔÙ´¦Àí */
+		if (is_basic_app(dst_id)) {
+			slog(NET_PRINT, SLOG_ERR, "send_message failed, basic app \n");
+			return ipc_send_message2(src_id, dst_id, Msg_cmd, us_DataLen, pData, msgflag);
+		}
+		return errNo;
+	}
+
+	if (us_DataLen >= MSG_DATA_MAX_LEN) {
+		slog(NET_PRINT, SLOG_ERR, "send_message failed:us_DataLen %d is too big, src:0x%x, target:0x%x, cmd:0x%x! \n", us_DataLen, src_id, dst_id, Msg_cmd); /*lint !e26*/
+		softap_assert("send_message failed:us_DataLen %d is too big!", us_DataLen);
+		return EINVAL;
+	}
+
+	if ((us_DataLen > 0) && (NULL == pData)) {
+		slog(NET_PRINT, SLOG_ERR, "send_message failed:us_DataLen is %d, but pData is NULL! \n", us_DataLen); /*lint !e26*/
+		softap_assert("send_message failed:us_DataLen is %d, but pData is NULL!", us_DataLen);
+		return EINVAL;
+	}
+
+	stMsg.ulMagic = MSG_MAGIC_WORD;
+	stMsg.lMsgType = MSG_TYPE_DEFAULT;
+	stMsg.src_id = src_id;
+	stMsg.dst_id = dst_id;
+	stMsg.usMsgCmd = Msg_cmd;
+	stMsg.usDataLen = us_DataLen;
+
+	if (us_DataLen > 0) {
+		memcpy(stMsg.aucDataBuf, pData, us_DataLen);
+	}
+
+AGAIN:
+	lRet = msgsnd(lTgtMsgID, &stMsg, msgSize, msgflag);
+	if (lRet < 0) {
+		if (errno == EINTR) {
+			goto AGAIN;
+		}
+		errNo = errno;
+		slog(NET_PRINT, SLOG_ERR, "send_message failed: msgsnd error code %d!, errNo:%d \n", lRet, errNo); /*lint !e26*/
+		if (msgflag != IPC_NOWAIT) {
+			softap_assert("send_message failed: msgsnd error code errNo:%d! \n", errNo);
+		}
+		return errNo;
+	}
+	return 0;
+}
+
+int ipc_send_message2(int src_id, int dst_id, unsigned short Msg_cmd, unsigned short us_DataLen, unsigned char *pData, int msgflag)
+{
+	MSG_BUF stMsg;
+	int lRet = 0;
+	int lTgtMsgID = 0;
+	LONG msgSize = offsetof(MSG_BUF, aucDataBuf) - sizeof(LONG) + us_DataLen;
+	int errNo = 0;
+
+	memset(&stMsg, 0, sizeof(MSG_BUF));
+
+	lTgtMsgID = msgget(dst_id, IPC_CREAT | 0600);
+	if (-1 == lTgtMsgID) {
+		errNo = errno;
+		slog(NET_PRINT, SLOG_ERR, "send_message2 failed:can not get target id, src:0x%x, target:0x%x, cmd:0x%x, errNo:%d!", src_id, dst_id, Msg_cmd, errNo); /*lint !e26*/
+		softap_assert("send_message2 failed:can not get target msg id 0x%04x!", dst_id);
+		return errNo;
+	}
+
+	if (us_DataLen >= MSG_DATA_MAX_LEN) {
+		slog(NET_PRINT, SLOG_ERR, "send_message2 failed:us_DataLen %d is too big, src:0x%x, target:0x%x, cmd:0x%x!", us_DataLen, src_id, dst_id, Msg_cmd); /*lint !e26*/
+		softap_assert("send_message2 failed:us_DataLen %d is too big!", us_DataLen);
+		return EINVAL;
+	}
+
+	if ((us_DataLen > 0) && (NULL == pData)) {
+		slog(NET_PRINT, SLOG_ERR, "send_message2 failed:us_DataLen is %d, but pData is NULL!", us_DataLen); /*lint !e26*/
+		softap_assert("send_message2 failed:us_DataLen is %d, but pData is NULL!", us_DataLen);
+		return EINVAL;
+	}
+
+	stMsg.ulMagic = MSG_MAGIC_WORD;
+	stMsg.lMsgType = MSG_TYPE_DEFAULT;
+	stMsg.src_id = src_id;
+	stMsg.dst_id = dst_id;
+	stMsg.usMsgCmd = Msg_cmd;
+	stMsg.usDataLen = us_DataLen;
+
+	if (us_DataLen > 0) {
+		memcpy(stMsg.aucDataBuf, pData, us_DataLen);
+	}
+
+AGAIN:
+	lRet = msgsnd(lTgtMsgID, &stMsg, msgSize, msgflag);
+	if (lRet < 0) {
+		errNo = errno;
+		if (errNo == EINTR) {
+			goto AGAIN;
+		}
+		if (errNo == EAGAIN) {
+			slog(NET_PRINT, SLOG_ERR, "send_message2 EAGAIN! src=0x%x dst=0x%x msg=0x%x\n",src_id,dst_id,Msg_cmd);
+			goto AGAIN;
+		}
+		slog(NET_PRINT, SLOG_ERR, "send_message failed: msgsnd error code %d, errNo:%d!", lRet, errNo); /*lint !e26*/
+		if (msgflag != IPC_NOWAIT) {
+			softap_assert("send_message failed: msgsnd error code errNo:%d!", errNo);
+		}
+		return errNo;
+	}
+	return 0;
+}
+
+int send_soc_msg(unsigned short position, int dst_id, unsigned short msg_cmd, unsigned short len, void *msg)
+{
+	T_Soc_Msg socMsgInfo = {0};
+	int Msgsize = offsetof(T_Soc_Msg, msg) + len;
+	int ret = -1;
+
+	if ((len > 0) && (NULL == msg)) {
+		assert(0);
+		return EINVAL;
+	}
+
+	if (len >= SOC_MSG_MAX_LEN) {
+		assert(0);
+		return EINVAL;
+	}
+	
+	//¿çºË·¢Ë͵½at_ctlµÄÏûÏ¢£¬ÄÚ²¿½øÐÐÈÝ´í
+	switch (dst_id) {
+	case MODULE_ID_AT_CTL:
+		dst_id = MODULE_ID_EXTERNAL_AT_CTL;
+		break;
+	case MODULE_ID_RTC_SERVICE:
+		dst_id = MODULE_ID_EXTERNAL_RTC_SERVICE;
+		break;
+	default:
+		break;
+	}
+
+	socMsgInfo.position = position;
+	socMsgInfo.targetId = dst_id;
+	socMsgInfo.msg_cmd = msg_cmd;
+	socMsgInfo.len = len;
+	if (len > 0) {
+		memcpy(socMsgInfo.msg, msg, len);
+	}
+	
+	//´Ë´¦½«Ô´Ä£¿éÉèÖÃΪMODULE_ID_AT_CTL£¬socÊÇAT·â×°´¦Àí½Ó¿Ú
+	ret = ipc_send_message(MODULE_ID_AT_CTL, MODULE_ID_AT_CTL, MSG_CMD_SOC_MSG_REQ, Msgsize, &socMsgInfo, 0);
+	if (ret != 0)
+		assert(0);
+
+	return ret;
+}
+
+/*ƽ̨¼¶ÏûÏ¢·¢Ëͽӿڣ¬ÄÚ²¿Ò»Í³ipc_send_messageºÍsend_soc_msg½Ó¿Ú¡£µ±Ä¿±êÄ£¿éºÍÔ´Ä£¿é²»ÔÚÒ»¸öºËʱ£¬½øÐк˼äÏûÏ¢·¢ËÍ*/
+int platform_send_msg(int src_id, int dst_id, unsigned short msg_cmd, unsigned short datalen, unsigned char *pData)
+{
+	int  position;
+
+	if (datalen >= SOC_MSG_MAX_LEN) {
+		softap_assert("platform_send_msg failed:datalen %d is too big!", datalen);
+		return EINVAL;
+	}
+
+	if ((datalen > 0) && (NULL == pData)) {
+		softap_assert("platform_send_msg failed:datalen is %d, but pData is NULL!", datalen);
+		return EINVAL;
+	}
+
+	//䶨ÒåÔ´Ä£¿éID£¬Ôò·Ö±ð¸³¶ÔÓ¦ºËµÄĬÈÏÖµ
+	if (src_id == 0) {
+#if (APP_OS_TYPE == APP_OS_LINUX)
+		src_id = MODULE_ID_APBASE;
+#else
+		src_id = MODULE_ID_CPBASE;
+#endif
+	}
+	
+	if (dst_id == 0)
+		softap_assert("platform_send_msg failed:src_id = %d, dst_id = %d!", src_id, dst_id);
+
+	//Ô´Ä£¿éIDÓëÄ¿±êÄ£¿éID²»ÔÚÒ»¸öºËÄÚ£¬Ôò×é×°²¢·¢Ëͺ˼äÏûÏ¢
+	if (((src_id & MODULE_ID_APBASE) != (dst_id & MODULE_ID_APBASE)) && ((src_id & MODULE_ID_CPBASE) != (dst_id & MODULE_ID_CPBASE))) {
+		int msglen = offsetof(T_Soc_Msg, msg) + datalen;
+		int ret = -1;
+		T_Soc_Msg socMsgInfo = {0};
+		
+		//¼ì²âsrc_id,dst_idÊÇ·ñÂú×ãºË¼äͨѶµÄÌõ¼þ
+		if (0 == soc_send_condition_check(src_id, dst_id))
+			softap_assert("platform_send_msg failed: confition check failed, src_id = %d, dst_id = %d!", src_id, dst_id);
+
+		position = (dst_id & MODULE_ID_APBASE) ? FAR_PS : NEAR_PS;
+
+		socMsgInfo.position = position;
+		socMsgInfo.srcId = src_id;
+		socMsgInfo.targetId = dst_id;
+		socMsgInfo.msg_cmd = msg_cmd;
+		socMsgInfo.len = datalen;
+		if (datalen > 0) {
+			memcpy(socMsgInfo.msg, pData, datalen);
+		}
+		
+		ret = ipc_send_message(src_id, MODULE_ID_AT_CTL, MSG_CMD_SOC_MSG_REQ, msglen, &socMsgInfo, 0);
+		if (ret != 0) //·¢Ë͵½at_ctlµÄÏûÏ¢²»ÔÊÐí·¢ËÍʧ°Ü
+			softap_assert("platform_send_msg failed: ipc_send_message MSG_CMD_SOC_MSG_REQ errNo:%d!", errno);
+		return ret;
+	} else {
+		//ºËÄÚÏûÏ¢´æÔÚÒòÄ¿±êÏûÏ¢¶ÓÁл¹Î´´´½¨µ¼Ö·¢ËÍʧ°ÜµÄÇé¿ö£¬¹Ê¸Ã´¦²»¶ÏÑÔ
+		return ipc_send_message(src_id, dst_id, msg_cmd, datalen, pData, 0);
+	}
+}
+
+int poweroff_request(int src_id)
+{
+	return platform_send_msg(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_POWEROFF_REQUEST, 0, NULL);
+}
+
+int restart_request(int src_id)
+{
+	return platform_send_msg(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_RESTART_REQUEST, 0, NULL);
+}
+
+int reset_request(int src_id)
+{
+	return platform_send_msg(src_id, MODULE_ID_MAIN_CTRL, MSG_CMD_RESET_REQUEST, 0, NULL);
+}
+
+typedef struct system_cmd_proc
+{
+	const char * str;
+	int (* proc)(const char * cmd, const char * str);
+}
+system_cmd_proc_t;
+
+//awkÌ«¸´ÔÓ£¬¾ßÌåÎÊÌâ¾ßÌå·ÖÎö
+//·Ö¸ô·û|ºóÃæ¿ÉÒÔ´æÔÚµÄÃüÁ´ýÍêÉÆ
+const static const char * separator_whitelist[]={
+	"grep ","sort ","head "
+};
+
+//·µ»Ø×Ö·û´®¼°ÒÔǰµÄ³¤¶È£¬Ã»ÓÐÕÒµ½·µ»Ø0
+static int system_cmd_used_curr(const char * cmd, const char * str)
+{
+	char *tmp_str = NULL;
+	tmp_str = strstr(cmd, str);
+	if(tmp_str)
+	{
+		int len = tmp_str - cmd + strlen(str);
+		tmp_str = tmp_str + strlen(str);
+		while((*tmp_str)!='\0' && (*tmp_str)==' ')
+		{
+			tmp_str++;
+		}
+		if((*tmp_str) == '\0' || (*(tmp_str+1)) == '\0')
+		{//¹æ±Ü2>&1 
+			return 0;
+		}
+		return len;
+	}
+	else
+		return 0;
+}
+
+//·µ»Ø³ý×Ö·û´®ÒÔǰµÄ³¤¶È£¬Ã»ÓÐÕÒµ½·µ»Ø0
+static int system_cmd_used_before(const char * cmd, const char * str)
+{
+	char *tmp_str = NULL;
+	tmp_str = strstr(cmd, str);
+	if(tmp_str)
+		return tmp_str -cmd;
+	else
+		return 0;
+}
+
+//¶Ô·Ö¸ô·û|µÄÌØÊâ´¦Àí£¬Ã»ÓÐÕÒµ½»òÔÊÐíÖ´Ðзµ»Ø0
+static int system_cmd_separator_proc(const char * cmd, const char * str)
+{
+	char *tmp_str = NULL;
+	tmp_str = strstr(cmd, str);
+	if(tmp_str)
+	{
+		int i = 0;
+		int len = tmp_str -cmd;
+		tmp_str = tmp_str + strlen(str);
+		while((*tmp_str)!='\0' && (*tmp_str)==' ')
+		{
+			tmp_str++;
+		}
+		for(i = 0; i < sizeof(separator_whitelist) / sizeof(const char *); i++)
+		{
+			if(strncmp(tmp_str, separator_whitelist[i], strlen(separator_whitelist[i])) == 0)
+			{
+				return 0;
+			}
+		}
+		return len;
+	}
+	else
+		return 0;
+}
+
+const static system_cmd_proc_t system_chack[]={
+	{"&",system_cmd_used_curr},
+	{"|",system_cmd_separator_proc},
+	{";",system_cmd_used_before},
+	{"\r",system_cmd_used_before},
+	{"\n",system_cmd_used_before}
+};
+
+int soft_system(const char *command)
+{
+	int i = 0;
+	int flag = 0;
+	int len = strlen(command);
+	
+	for(i = 0; i < sizeof(system_chack) / sizeof(system_cmd_proc_t); i++)
+	{	
+		int offset = system_chack[i].proc(command,system_chack[i].str);
+		if(offset != 0 && offset < len)
+		{
+			len = offset;
+			flag = 1;
+		}
+	}
+	if(flag && len > 0 && len < strlen(command))
+	{
+		char *cmd = (char *)malloc(len+1);
+		int ret = 0;
+		if(cmd == NULL)
+		{
+			slog(NET_PRINT, SLOG_ERR, "@system@ malloc fail!\n");
+			return -1;
+		}
+		memset(cmd, 0, len+1);
+		strncpy(cmd, command, len);
+		slog(NET_PRINT, SLOG_ERR, "@system@ %s is inject!\n",command);
+		ret = system(cmd);
+		slog(NET_PRINT, SLOG_ERR, "@system@ %s is now,ret=%d!\n",cmd,ret);
+		free(cmd);
+		return ret;
+	}
+	else
+		return system(command);
+}
+
+long get_sys_uptime()
+{
+	struct sysinfo info;
+	if(sysinfo(&info))
+	{
+		printf("Failed to get sysinfo failed\n");
+		return -1;
+	}
+
+	return info.uptime;
+}
+
+
diff --git a/ap/lib/libsoftap/softap_log.c b/ap/lib/libsoftap/softap_log.c
new file mode 100755
index 0000000..442770b
--- /dev/null
+++ b/ap/lib/libsoftap/softap_log.c
@@ -0,0 +1,216 @@
+#define _POSIX_C_SOURCE 199309
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <time.h>
+#include <syslog.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include "softap_log.h"
+#include "softap_api.h"
+
+#define ON 1
+#define OFF -1
+
+int slog_printlevel  = SLOG_ERR;
+int slog_sysloglevel = SLOG_OFF;
+int soctime_sw       = SLOG_SOCTIME_OFF;
+
+int log_switch = LOG_ON;
+long long time_us;
+
+void log_sig_hdl(int sig, siginfo_t *siginfo, void *ptr)
+{
+	int level = 0;
+	int printlog = 0, syslog = 0, soctime = 0;
+
+	if (sig == SIGUSR2) {
+		slog(NET_PRINT, SLOG_ERR, "prelevels(printlog:%d,syslog:%d,soctime:%d), setlevel:%d \n",
+		     slog_printlevel, slog_sysloglevel, soctime_sw, siginfo->si_value.sival_int);
+
+		level = siginfo->si_value.sival_int;
+
+		soctime  = (level % 1000) / 100;         //È¡°Ùλ£¬Ç§Î»ÒÔÉϲ»Ö§³Ö
+		syslog   = (level - soctime * 100) / 10; //ȡʮλ
+		printlog = level - soctime * 100 - syslog * 10; //È¡¸öλ
+
+		slog(NET_PRINT, SLOG_ERR, "printlog:%d, syslog:%d, soctime:%d \n", printlog, syslog, soctime);
+
+		if (printlog > 0 && printlog <= SLOG_OFF)
+			slog_printlevel = printlog;
+		else
+			slog(NET_PRINT, SLOG_ERR, "slog_printlevel only support %d~%d \n", SLOG_DEBUG, SLOG_OFF);
+
+		if (syslog > 0 && syslog <= SLOG_OFF)
+			slog_sysloglevel = syslog;
+		else
+			slog(NET_PRINT, SLOG_ERR, "slog_sysloglevel only support %d~%d \n", SLOG_DEBUG, SLOG_OFF);
+
+		if (soctime == 0 || soctime == 1)
+			soctime_sw = soctime;
+		else
+			slog(NET_PRINT, SLOG_ERR, "soctime_sw only support 0~1 \n");
+	}
+}
+
+//×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
+void register_sig_logswitch(void)
+{
+	struct sigaction st;
+
+	memset(&st, 0, sizeof(st));
+	st.sa_flags = SA_SIGINFO;
+	st.sa_sigaction = log_sig_hdl;
+	sigaction(SIGUSR2, &st, NULL);
+}
+
+//¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð
+void loglevel_init(void)
+{
+	char nv_print_level[32]    = {0};
+	char nv_syslog_level[32]   = {0};
+	char nv_soctime_switch[32] = {0};
+
+	sc_cfg_get("print_level", nv_print_level, sizeof(nv_print_level));
+	sc_cfg_get("syslog_level", nv_syslog_level, sizeof(nv_syslog_level));
+	sc_cfg_get("soctime_switch", nv_soctime_switch, sizeof(nv_soctime_switch));
+
+	//loglevel·ÇÓÐЧֵʱ£¬½«Ä¬ÈÏ´òÓ¡¼¶±ðÉèÖÃΪoff£¬¼´¹Ø±Õ´òÓ¡
+	slog_printlevel = atoi(nv_print_level);
+	if((slog_printlevel < SLOG_DEBUG) || (slog_printlevel > SLOG_OFF)) { 
+		slog_printlevel = SLOG_OFF;
+	}	
+
+	slog_sysloglevel = atoi(nv_syslog_level);
+	if((slog_sysloglevel < SLOG_DEBUG) || (slog_sysloglevel > SLOG_OFF)) { 
+		slog_sysloglevel = SLOG_OFF;
+	}
+
+	soctime_sw = atoi(nv_soctime_switch);
+	if((soctime_sw > SLOG_SOCTIME_ON) || (soctime_sw < SLOG_SOCTIME_OFF)) { 
+		soctime_sw = SLOG_SOCTIME_OFF;
+	}	
+
+	register_sig_logswitch();
+
+	slog(NET_PRINT, SLOG_DEBUG, "loglevel_init, print:%d, syslog:%d, soctime:%d \n",
+	     slog_printlevel, slog_sysloglevel, soctime_sw);
+}
+
+int sys_log(char *ident, int prio, const char * fmt, va_list arg)
+{
+	vsyslog(prio, fmt, arg);
+	return 0;
+}
+
+inline void output_syslog_time(char *mod, int prio)
+{
+	if (SLOG_SOCTIME_ON == soctime_sw)
+		syslog(prio, "[%lld.%llds]: ", time_us / 1000000, time_us % 1000000);
+}
+
+#define put_to_console(mod, fmt, arg) do {\
+	char buf[1024] = {0}; \
+	if(SLOG_SOCTIME_ON == soctime_sw) \
+		snprintf(buf, 1023, "%s[%d][%lld.%llds]: ", mod, syscall(SYS_gettid), time_us/1000000, time_us%1000000); \
+	else \
+		snprintf(buf, 1023, "%s[%d]: ", mod, syscall(SYS_gettid)); \
+	int n = strlen(buf); \
+	va_start(arg, fmt); \
+	vsnprintf(buf+n, 1023-n, fmt, arg); \
+	va_end(arg); \
+	printf("%s",buf); \
+}while(0)
+
+
+//output_syslog_time(mod, LOG_##LEVEL, &t);
+#define put_to_syslog(LEVEL) do { \
+	openlog(mod, LOG_PID, LOG_MAIL); \
+	output_syslog_time(mod, LOG_##LEVEL); \
+	va_start(arg, fmt); \
+	ret = sys_log(mod, LOG_##LEVEL, fmt, arg); \
+	va_end(arg); \
+	closelog(); \
+}while(0)
+
+#define SYSLOG_LVL_PATH "/proc/sys/slog/syslog_level"
+#define PRINT_LVL_PATH "/proc/sys/slog/print_level"
+#define LOG_SOC_TIME_SWITCH "/proc/sys/slog/soctime_sw"
+static void set_log_level(int* loglevel, char* filepath)
+{
+	int fd;
+	char buf[4] = {0};
+    int len  = 0;
+	fd = open(filepath, O_RDWR);
+	if (fd < 0) {
+		printf("fail to open\n");
+		return;
+	}
+
+    len = read(fd, buf, 3);
+
+	if (len > 0 )
+		*loglevel = atoi(buf);
+	else {
+		close(fd);
+		return;
+	}
+	close(fd);
+}
+
+int slog(char *mod, int prio, const char *fmt, ...)
+{
+	va_list arg = {0};
+	int ret = 0;
+
+	if (SLOG_SOCTIME_ON == soctime_sw)
+		time_us = get_time_us();
+
+	if (slog_sysloglevel > 0 && slog_sysloglevel <= prio) {
+		switch (prio) {
+		case SLOG_NORMAL: {
+			put_to_syslog(NOTICE);
+		}
+		break;
+
+		case SLOG_DEBUG: {
+			put_to_syslog(DEBUG);
+		}
+		break;
+
+		case SLOG_ERR: {
+			put_to_syslog(ERR);
+		}
+		break;
+
+		default:
+			break;
+		}
+	}
+
+	if (slog_printlevel > 0 && slog_printlevel <= prio) {
+		put_to_console(mod, fmt, arg);
+	}
+
+	return ret;
+}
+
+void security_log(int mod,const char *fmt, ...)
+{
+	char buf[512] = {0};
+	va_list arg = {0};
+	int n = 0;
+
+	snprintf(buf, sizeof(buf), "[%X][%d]", mod, syscall(SYS_gettid));
+	n = strlen(buf);
+	va_start(arg, fmt);
+	vsnprintf(buf+n, sizeof(buf)-n, fmt, arg); 
+	va_end(arg);
+	ipc_send_message(mod, MODULE_ID_SECURITY_LOG, MSG_CMD_SECURITY_LOG_SAVE, sizeof(buf), (unsigned char *)buf, IPC_NOWAIT);
+}
+