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

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/zte_cpe/zte_cpe.c b/ap/app/zte_cpe/zte_cpe.c
new file mode 100755
index 0000000..7afa751
--- /dev/null
+++ b/ap/app/zte_cpe/zte_cpe.c
@@ -0,0 +1,305 @@
+#define _GNU_SOURCE /**/
+
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <time.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/sysctl.h>
+#include <net/if.h>
+#include <poll.h>
+#include <stddef.h>
+#include <linux/if_packet.h>
+#include <netinet/ether.h>
+#include <netinet/if_ether.h>
+#include <arpa/inet.h>
+#include <pthread.h>
+#include <zte_cpe.h>
+#include "softap_api.h"
+
+void nvserver_entry(void)
+{
+	nvserver_main(0,NULL);
+	return;
+}
+
+void at_ctl_entry(char *arg)
+{
+	//printf("at_ctl_entry boot:%s\n", arg);
+	char *argv[2];
+	argv[0] = NULL;
+	argv[1] = arg;
+
+	at_ctl_main(2, argv);
+	return;
+}
+
+void rtc_service_entry(char *arg)
+{
+	rtc_service_main(0,NULL);
+	return;
+}
+
+void zte_mainctrl_entry(char *arg)
+{
+	if (0 == strcmp(arg, "2")) {
+		char *argv[2];
+		argv[0] = NULL;
+		argv[1] = "poweroff_charger";
+
+		zte_mainctrl_main(2, argv);
+	} else {
+		zte_mainctrl_main(0,NULL);
+	}
+
+	return;
+}
+
+void zte_hotplug_entry(char *arg)
+{
+	zte_hotplug_main(0,NULL);
+	return;
+}
+
+void zte_audio_res_ctrl_entry(char *arg)
+{
+	zte_audio_res_ctrl_main(0,NULL);
+	return;
+}
+
+void zte_drv_serial_ctrl_entry(char *arg)
+{
+	zte_drv_serial_ctrl_main();
+	return;
+}
+
+void zte_drv_usb_ctrl_entry(char *arg)
+{
+	if(arg)
+		zte_drv_usb_ctrl_main(3,NULL);
+	else
+		zte_drv_usb_ctrl_main(0,NULL);
+	return;
+}
+
+void zte_mmi_entry(char *arg)
+{
+	//printf("zte_mmi_entry boot:%s\n", arg);
+	if (0 == strcmp(arg, "2")) {
+		char *argv[2];
+		argv[0] = NULL;
+		argv[1] = "poweroff_charger";
+
+		zte_mmi_main(2, argv);
+	} else {
+		zte_mmi_main(0,NULL);
+	}
+	return;
+}
+
+void zte_locknet_entry(char *arg)
+{
+	zte_locknet_main(0,NULL);
+	//return; //klocwork
+}
+
+void zte_watchdog_entry(char *arg)
+{
+	zte_watchdog_main(0,NULL);
+	return;
+}
+
+void fluxstat_entry(char *arg)
+{
+	fluxstat_main(0,NULL);
+	return;
+}
+
+void sntp_entry(char *arg)
+{
+	sntp_main(0,NULL);
+	return;
+}
+
+void sd_hotplug_entry(char *arg)
+{
+	sd_hotplug_main(0,NULL);
+	return;
+}
+
+void sms_entry(char *arg)
+{
+	sms_main(0,NULL);
+}
+
+void phonebook_entry(char *arg)
+{
+	phonebook_main(0,NULL);
+	return;
+}
+
+void wlan_entry(char *arg)
+{
+	wlan_main(0,NULL);
+	return;
+}
+
+void fota_dm_entry(char *arg)
+{
+	fota_dm_main(0,NULL);
+}
+
+
+int main(int argc, char *argv[])
+{
+	int ret = 0;
+	/* nvserver */
+    pthread_t nvserver_thread_tid;
+    pthread_create(&nvserver_thread_tid, NULL, (void *)nvserver_entry, NULL);
+	
+	/* zte_hotplug */
+	pthread_t zte_hotplug_thread_tid;
+	pthread_create(&zte_hotplug_thread_tid, NULL, (void *)zte_hotplug_entry, NULL);
+	
+    /* zte_drv_serial_ctrl */
+	pthread_t zte_drv_serial_ctrl_thread_tid;
+	pthread_create(&zte_drv_serial_ctrl_thread_tid, NULL, (void *)zte_drv_serial_ctrl_entry, NULL);
+	/* zte_drv_usb_ctrl */
+	pthread_t zte_drv_usb_ctrl_thread_tid;
+#ifdef WEBS_SECURITY
+	{
+		char rstr[24] = {0};
+		
+		sc_cfg_get("dbinfo", rstr, sizeof(rstr));
+		if(strlen(rstr) == 0)
+		{
+			unsigned int rnum = 0;
+			
+			system("rm -rf /etc_rw/pbm.*");
+			system("rm -rf /etc_rw/sms.*");
+			srand( (unsigned)time( NULL ) );
+			rnum = (rand()|0xf000000);
+			snprintf((char *)rstr, sizeof(rstr), "%ld", rnum);		
+			sc_cfg_set("dbinfo", rstr);
+			sc_cfg_save();
+		}
+		{
+			unsigned char i = 0;
+			char nstr[24] = {0};
+			for(i = 0; i < 22; i++)
+			{
+				if(rstr[i] >= 0x30)
+				{
+					nstr[i] = rstr[i] + (((i&0x7)|0x18)+1)*(2>>(i%3));
+				}
+				else
+				{
+					nstr[i] = (i%10) + 0x30 + (((i&0x7)|0x18)+1)*(2>>(i%3));
+				}
+			}
+			sc_cfg_set("rnum_at", nstr);
+		}
+	}
+#endif	
+	if (0 == strcmp(argv[2], "amt")) {
+		ret = sc_cfg_set("ver_mode", "0");
+		if(ret < 0)
+			printf("zte_cpe set vermode fail\n");
+		else		
+		sc_cfg_save();
+		printf("---set ver mode to 0\n");
+	}
+
+	if (0 != strcmp(argv[2], "amt")) { //³äµç»òÕý³£¿ª»úģʽ
+		char LanEnable[10] = {0};
+		/* at_ctl */
+		pthread_t at_ctl_thread_tid;
+		pthread_create(&at_ctl_thread_tid, NULL, (void *)at_ctl_entry, argv[1]);
+		/* rtc_service */
+		pthread_t rtc_service_thread_tid;
+		pthread_create(&rtc_service_thread_tid, NULL, (void *)rtc_service_entry, NULL);
+		/* zte_mainctrl */
+		pthread_t zte_mainctrl_thread_tid;
+		pthread_create(&zte_mainctrl_thread_tid, NULL, (void *)zte_mainctrl_entry, argv[1]);
+			
+		/* zte_audio_res_ctrl */
+		pthread_t zte_audio_res_ctrl_thread_tid;
+		pthread_create(&zte_audio_res_ctrl_thread_tid, NULL, (void *)zte_audio_res_ctrl_entry, NULL);
+	
+		sc_cfg_get("LanEnable", LanEnable, sizeof(LanEnable));
+		if(atoi(LanEnable) == 1) { //mifiÐÎ̬
+			/* zte_mmi */
+			pthread_t zte_mmi_thread_tid;
+			pthread_create(&zte_mmi_thread_tid, NULL, (void *)zte_mmi_entry, argv[1]);
+		}	
+		if (0 != strcmp(argv[1], "2")) { //·Ç³äµçģʽ
+
+			pthread_create(&zte_drv_usb_ctrl_thread_tid, NULL, (void *)zte_drv_usb_ctrl_entry, NULL);	
+			if(atoi(LanEnable) == 1) { //mifiÐÎ̬				
+				/* zte_locknet */
+				pthread_t zte_locknet_thread_tid;
+				pthread_create(&zte_locknet_thread_tid, NULL, (void *)zte_locknet_entry, NULL);
+				/* fluxstat */
+
+				pthread_t fluxstat_thread_tid;
+				pthread_create(&fluxstat_thread_tid, NULL, (void *)fluxstat_entry, NULL);
+				/* sntp */
+				pthread_t sntp_thread_tid;
+				pthread_create(&sntp_thread_tid, NULL, (void *)sntp_entry, NULL);
+				/* sd_hotplug */
+				//pthread_t sd_hotplug_thread_tid;
+				//pthread_create(&sd_hotplug_thread_tid, NULL, (void *)sd_hotplug_entry, NULL);
+				sd_hotplug_init();
+				/* sms */
+				pthread_t sms_thread_tid;
+				pthread_create(&sms_thread_tid, NULL, (void *)sms_entry, NULL);
+				/* phonebook */
+				pthread_t phonebook_thread_tid;
+				pthread_create(&phonebook_thread_tid, NULL, (void *)phonebook_entry, NULL);
+				/* wifi_manager */
+				pthread_t wlan_thread_tid;
+				pthread_create(&wlan_thread_tid, NULL, (void *)wlan_entry, NULL);
+			}
+
+			/* fota_dm */
+			pthread_t fota_dm_thread_tid;
+			pthread_create(&fota_dm_thread_tid, NULL, (void *)fota_dm_entry, NULL);				
+		}else{
+			
+			pthread_create(&zte_drv_usb_ctrl_thread_tid, NULL, (void *)zte_drv_usb_ctrl_entry, "poweroff_charger");
+
+		}
+			
+		
+		/* zte_watchdog */
+		pthread_t zte_watchdog_thread_tid;
+		pthread_create(&zte_watchdog_thread_tid, NULL, (void *)zte_watchdog_entry, NULL);
+
+	}
+	else
+	{
+		pthread_create(&zte_drv_usb_ctrl_thread_tid, NULL, (void *)zte_drv_usb_ctrl_entry, NULL);
+	}
+
+
+	while(1)
+	{
+		sleep(20);
+		//printf("zte app test -1 \n");
+	}
+
+	return 0;
+}
+