Esempio n. 1
0
int asus_ate_command(const char *command, const char *value, const char *value2){
	_dprintf("===[ATE %s %s]===\n", command, value);
	if(!strcmp(command, "Set_StartATEMode")) {
                nvram_set("asus_mfg", "1");
                if(nvram_match("asus_mfg", "1")) {
			puts("1");
#ifdef RTCONFIG_FANCTRL
			stop_phy_tempsense();
#endif
#ifdef TODO
	                stop_wsc();
#endif
        	        stop_lltd();    
                	stop_wanduck();
	                stop_logger();
        	        stop_wanduck();
#ifdef RTCONFIG_DNSMASQ
                	stop_dnsmasq();
#else
	                stop_dns();
	                stop_dhcpd();
#endif
        	        stop_ots();
                	stop_networkmap();
#ifdef RTCONFIG_USB
	                stop_usbled();
#endif
		}
		else
			puts("ATE_ERROR");
                return 0;
        }
        else if (!strcmp(command, "Set_AllLedOn")) {
                return setAllLedOn();
        }
        else if (!strcmp(command, "Set_AllLedOff")) {
                return setAllLedOff();
        }
        else if (!strcmp(command, "Set_AllLedOn_Half")) {
                puts("Not support"); //Need to implement for EA-N66U
                return 0;
        }
        else if (!strcmp(command, "Set_MacAddr_2G")) {
                if( !setMAC_2G(value) )
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
        }
        else if (!strcmp(command, "Set_MacAddr_5G")) {
                if( !setMAC_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_RegulationDomain_2G")) {
                if ( !setCountryCode_2G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Set_RegulationDomain_5G")) {
                if ( !setCountryCode_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_Regrev_2G")) {
                if( !setRegrev_2G(value) )
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_Regrev_5G")) {
                if( !setRegrev_5G(value))
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#endif
        else if (!strcmp(command, "Set_PINCode")) {
                if (!setPIN(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_40M_Channel_2G")) {
                if(!set40M_Channel_2G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
        else if (!strcmp(command, "Set_40M_Channel_5G")) {
                if(!set40M_Channel_5G(value))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
                return 0;
        }
#ifdef RTCONFIG_FANCTRL
        else if (!strcmp(command, "Set_FanOn")) {
                setFanOn();
                return 0;
        }
        else if (!strcmp(command, "Set_FanOff")) {
                setFanOff();
                return 0;
        }
#endif
	else if (!strcmp(command, "Set_RestoreDefault")) {
		ResetDefault();
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Set_Commit")) {
                setCommit();
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_FWVersion")) {
	        char fwver[12];
        	sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno"));
	        puts(fwver);
                return 0;
        }
        else if (!strcmp(command, "Get_BootLoaderVersion")) {
                getBootVer();
                return 0;
        }
        else if (!strcmp(command, "Get_ResetButtonStatus")) {
                puts(nvram_safe_get("btn_rst"));
                return 0;
        }
        else if (!strcmp(command, "Get_WpsButtonStatus")) {
                puts(nvram_safe_get("btn_ez"));
                return 0;
        }
        else if (!strcmp(command, "Get_SWMode")) {
                puts(nvram_safe_get("sw_mode"));
                return 0;
        }
        else if (!strcmp(command, "Get_MacAddr_2G")) {
                getMAC_2G();
                return 0;
        }
        else if (!strcmp(command, "Get_MacAddr_5G")) {
                getMAC_5G();
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) {
		Get_USB_Port_Info(1);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) {
                Get_USB_Port_Folder(1);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) {
                Get_USB_Port_Info(2);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) {
                Get_USB_Port_Folder(2);
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_SD_Infor")) {
		Get_SD_Card_Info();
                return 0;
        }
        else if (!strcmp(command, "Get_SD_Folder")) {
                Get_SD_Card_Folder();
                return 0;
        }
        else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getCountryCode_2G();
                return 0;
        }
#ifdef CONFIG_BCMWL5
        else if (!strcmp(command, "Get_RegulationDomain_5G")) {
           	getCountryCode_5G();
                return 0;
        }
	else if (!strcmp(command, "Get_Regrev_2G")) {
		getRegrev_2G();
		return 0;
	}
        else if (!strcmp(command, "Get_Regrev_5G")) {
		getRegrev_5G();
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_PINCode")) {
                getPIN();
                return 0;
        }
        else if (!strcmp(command, "Get_WanLanStatus")) {
                if( !GetPhyStatus())
			puts("ATE_ERROR");
		return 0;
        }
        else if (!strcmp(command, "Get_FwReadyStatus")) {
                puts(nvram_safe_get("success_start_service"));
                return 0;
        }
	else if (!strcmp(command, "Get_Build_Info")) {
		puts(nvram_safe_get("buildinfo"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
        else if (!strcmp(command, "Get_RSSI_2G")) {
                getrssi(0);
                return 0;
        }
        else if (!strcmp(command, "Get_RSSI_5G")) {
                getrssi(1);
                return 0;
        }
#endif
        else if (!strcmp(command, "Get_ChannelList_2G")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_ChannelList_5G")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
        else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) {
                puts("Not support"); //Need to implement
                return 0;
        }
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Ra_FWRITE")) {
		return FWRITE(value, value2);
	}
        else if (!strcmp(command, "Ra_Asuscfe_2G")) {
                return asuscfe(value, WIF_2G);
        }
        else if (!strcmp(command, "Ra_Asuscfe_5G")) {
		return asuscfe(value, WIF_5G);
        }

#endif
        else 
	{
		puts("ATE_ERROR");
                return EINVAL;
	}
}
Esempio n. 2
0
/* wathchdog is runned in NORMAL_PERIOD, 1 seconds
 * check in each NORMAL_PERIOD
 *	1. button
 *
 * check in each NORAML_PERIOD*10
 *
 *      1. ntptime 
 *      2. time-dependent service
 *      3. http-process
 *      4. usb hotplug status
 */
void watchdog(void)
{
	/* handle button */
	btn_check();

	/* if timer is set to less than 1 sec, then bypass the following */
	if (itv.it_value.tv_sec == 0) return;

	if (nvram_match("asus_mfg", "1"))
	{
		system("rmmod hw_nat");
		if (pids("ntp"))
			system("killall -SIGTERM ntp");
		if (pids("ntpclient"))
			system("killall ntpclient");
		if (pids("udhcpc"))
			system("killall -SIGTERM udhcpc");
#if (!defined(W7_LOGO) && !defined(WIFI_LOGO))
		if (pids("ots"))
			system("killall ots");
#endif
		stop_wanduck();
		stop_logger();
		stop_upnp();	// it may cause upnp cannot run
		stop_dhcpd();
		stop_dns();
#if (!defined(W7_LOGO) && !defined(WIFI_LOGO))
		stop_pspfix();
#endif
		stop_wsc();
		stop_wsc_2g();
		stop_lltd();
		stop_networkmap();
		stop_httpd();
		stop_lpd();
		stop_u2ec();
		kill_pidfile_s("/var/run/linkstatus_monitor.pid", SIGTERM);
		if (pids("detectWan"))
			system("killall detectWan");
#if (!defined(W7_LOGO) && !defined(WIFI_LOGO))
		stop_rstats();
		kill_pidfile_s("/var/run/detect_internet.pid", SIGTERM);
#endif
		if (pids("tcpcheck"))
			system("killall -SIGTERM tcpcheck");
#ifdef HTTPD_CHECK
		if (pids("httpdcheck"))
			system("killall -SIGTERM httpdcheck");
#endif
		if (pids("traceroute"))
			system("killall traceroute");
		if (pids("usbled"))
			system("killall -SIGTERM usbled");

		nvram_set("asus_mfg", "2");
	}

#if 0
	// reboot signal checking
	if (nvram_match("reboot", "1"))
	{
		printf("[watchdog] nvram match reboot\n");

		reboot_count++;
		if (reboot_count >= 2) 
		{
//			kill(1, SIGTERM);
			sys_exit();
		}

		return;
	}
#else
	if (nvram_match("reboot", "1")) return;
#endif

	if (stop_service_type_99) return;

	if (!nvram_match("asus_mfg", "0")) return;

	watchdog_period = (watchdog_period + 1) % 10;

	if (watchdog_period) return;

#ifdef BTN_SETUP
	if (btn_pressed_setup >= BTNSETUP_START) return;
#endif

#if (!defined(W7_LOGO) && !defined(WIFI_LOGO))
	if (count_to_stop_wps > 0)
	{
		count_to_stop_wps--;

		if (!count_to_stop_wps)
		{
//			if (nvram_match("wl_radio_x", "1"))
			stop_wsc();			// psp fix
//			if (nvram_match("rt_radio_x", "1"))
			stop_wsc_2g();			// psp fix
			nvram_set("wps_enable", "0");	// psp fix
		}
	}
#endif

	ddns_timer = (ddns_timer + 1) % 4320;

	if (nvram_match("asus_debug", "1"))
		mem_timer = (mem_timer + 1) % 60;

	if (!watchdog_count)
		watchdog_count++;
	else if (watchdog_count++ == 1)
	{
#if 0
		if (!strcmp(nvram_safe_get("rc_service"), "restart_upnp"))
			service_handle();
		else
#endif
		if (	nvram_match("router_disable", "0") &&
			nvram_match("upnp_enable", "1") &&
			nvram_match("upnp_started", "0")	)
		{
//			if (has_wan_ip())
			{
				dbg("[watchdog] starting upnp...\n");
				stop_upnp();
				start_upnp();
			}
		}
	}

	/* check for time-dependent services */
	svc_timecheck();

	/* http server check */
	httpd_processcheck();

	u2ec_processcheck();

	media_processcheck();
#if 0
	samba_processcheck();
#endif
	pppd_processcheck();

	if (nvram_match("wan_route_x", "IP_Routed"))
		nm_processcheck();

	cpu_usage_minotor();

	dm_block_chk();

	if (nvram_match("asus_debug", "1") && !mem_timer)
	{
		print_num_of_connections();
		dbg("Hardware NAT: %s\n", is_hwnat_loaded() ? "Enabled": "Disabled");
		dbg("Software QoS: %s\n", nvram_match("qos_enable", "1") ? "Enabled": "Disabled");
		dbg("pppd running: %s\n", pids("pppd") ? "Yes": "No");
#if 0
		dbg("CPU usage: %d%%\n", get_cpu_usage());
#else
		dbg("CPU usage: %d%%\n", cpu_main(0, NULL, 0));
#endif
		system("free");
		system("date");
		print_uptime();
	}

#ifdef CDMA
	/* CDMA_DOWN = 99, none
	 * CDMA_DOWN = 1, currently down
	 * CDMA_DOWN = 2, currently up
	 * CDMA_DOWN = 0, currently trying to connect
	 */
	if (nvram_match("cdma_down", "1"))
	{
		logmessage("CDMA client", "cdma is down(%d)!", cdma_down);

		cdma_down++;
		cdma_connec t = 0;

		if (cdma_down == 2)
		{
			printf("[watchdog] stop wan\n");
			stop_wan();
			start_wan();
		}
		else if (cdma_down >= 12) /* 2 minutes timeout for retry */
		{
			cdma_down = 0;
		}
	}
	else if (nvram_match("cdma_down", "0"))
	{
		logmessage("CDMA client", "cdma try connect(%d)!", cdma_connect);
		cdma_down = 0;
		cdma_connect++;

		if (cdma_connect > 12) /* 2 minitues timeout for connecting */
		{
			nvram_set("cdma_down", "1");
		}
	}
	else
	{
		cdma_down = 0;
		cdma_connect = 0;
	}
#endif

	if (nvram_match("wan_route_x", "IP_Routed"))
	{
		if (!is_phyconnected() || !has_wan_ip())
			return;

		/* sync time to ntp server if necessary */
		if (!nvram_match("wan_dns_t", "") && !nvram_match("wan_gateway_t", ""))
		{
			ntp_timesync();
		}

		if (	nvram_match("ddns_enable_x", "1") && 
			(!nvram_match("ddns_updated", "1") || !ddns_timer)
		)
		{
			logmessage("RT-N56U", "[start ddns] watchdog");
			start_ddns();
		}

		if (!ddns_timer)
		{
			stop_networkmap();
			start_networkmap();
		}
	}
	else
	{
		if (/*!nvram_match("lan_dns_t", "") && */!nvram_match("lan_gateway_t", ""))
			ntp_timesync();
	}
}