コード例 #1
0
static void watchdog(void)
{
	int brand = getRouterBrand();
	int registered = -1;
	int radiostate0 = -1;
	int oldstate0 = -1;
	int radiostate1 = -1;
	int oldstate1 = -1;
	int counter = 0;
	int radioledinitcount = 0;
	int fd = open("/dev/misc/watchdog", O_WRONLY);
	if (fd == -1)
		fd = open("/dev/watchdog", O_WRONLY);

	if (fd == -1) {
		return;
	}
#ifdef HAVE_MADWIFI
	int cnt = getdevicecount();
#else
	int cnt = get_wl_instances();
#endif

	while (1) {
		write(fd, "\0", 1);
		fsync(fd);

#ifdef HAVE_REGISTER
		if (!nvram_match("flash_active", "1")) {
			if (registered == -1)
				registered = isregistered_real();
			if (!registered)
				isregistered();	//to poll
		}
#endif
		/* 
		 * software wlan led control 
		 */
		if (radioledinitcount < 5) {
			radioledinitcount++;
			oldstate0 = -1;
			oldstate1 = -1;
		}
#ifdef HAVE_MADWIFI
		if (!nvram_match("flash_active", "1")) {
			radiostate0 = get_radiostate("ath0");
			if (cnt == 2)
				radiostate1 = get_radiostate("ath1");
		}
#else
		wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int));
		if (cnt == 2)
			wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int));
#endif

		if (radiostate0 != oldstate0) {
#ifdef HAVE_MADWIFI
			if (radiostate0 == 1)
#else
			if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN0, LED_ON);
			else {
				led_control(LED_WLAN0, LED_OFF);
#ifndef HAVE_MADWIFI
				/* 
				 * Disable wireless will cause diag led blink, so we want to
				 * stop it. 
				 */
				if (brand == ROUTER_WRT54G)
					diag_led(DIAG, STOP_LED);
				/* 
				 * Disable wireless will cause power led off, so we want to
				 * turn it on. 
				 */
				if (brand == ROUTER_WRT54G_V8)
					led_control(LED_POWER, LED_ON);
#endif
			}

			oldstate0 = radiostate0;
		}

		if (radiostate1 != oldstate1) {
#ifdef HAVE_MADWIFI
			if (radiostate1 == 1)
#else
			if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN1, LED_ON);
			else {
				led_control(LED_WLAN1, LED_OFF);
			}

			oldstate1 = radiostate1;
		}
		/* 
		 * end software wlan led control 
		 */

		sleep(10);
		if (nvram_match("warn_enabled", "1")) {
			counter++;
			if (!(counter % 60))
				system("notifier&");	// 
		}
	}
}
コード例 #2
0
ファイル: lib.c プロジェクト: rogerhu/dd-wrt
void ej_get_firmware_version(webs_t wp, int argc, char_t ** argv)
{
#if defined(HAVE_ESPOD) || defined(HAVE_ONNET) || defined(HAVE_IMMERSIVE)
    char *p;
    char string[32], date[16];
    sprintf(string, CYBERTAN_VERSION);
    p = strtok(string, "(");
    if (p != NULL) {
        p = strtok(NULL, ")");
        if (p != NULL) {
            sprintf(date, "%s", p);
        }
    }
#endif
#ifdef HAVE_BUFFALO
    websWrite(wp, "%s%s %s%s", CYBERTAN_VERSION, MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT);
#else

#ifdef HAVE_REGISTER
    if (isregistered() && !isregistered_real()) {
        websWrite(wp, "Click here to ACTIVATE %d Hour Trial", getTrialCount());
    } else {
#ifdef HAVE_WIKINGS
#ifdef HAVE_SUB3
#define V "ExcelMed"
#elif HAVE_SUB6
#define V "ExcelMin"
#else
#define V "Excellent"
#endif
        websWrite(wp, "Excel Networks (%s series) V 2.10", V);
#undef V
#elif HAVE_ESPOD
#ifdef HAVE_SUB3
#define V "A600"
#elif HAVE_SUB6
#define V "A1000"
#else
#define V "MIMO"
#endif
        if (argc == 2) {
            websWrite(wp, "ESPOD v1.0611 (%s) / ESPOD %s Series", date, V);
        } else {
            websWrite(wp, "ESPOD v1.0611 (%s)</a><div>\");document.write(\"<div class=\\\"info\\\">Device: ESPOD %s Series<a>", date, V);
        }
#undef V
#elif HAVE_CARLSONWIRELESS
        websWrite(wp, "Carlson Wireless v5.3 (%s)", SVN_REVISION);
#elif HAVE_IMMERSIVE
        if (argc == 2) {
            websWrite(wp, "Build date %s", date);
        } else {
            websWrite(wp, "SUPPORT %s (%s)", SVN_REVISION, date);
        }
#elif HAVE_IPR
        websWrite(wp, "IPR-CP v1.0 (%s)", SVN_REVISION);
#elif HAVE_ONNET_BLANK
        websWrite(wp, "Enterprise AP (%s)", date);
#elif HAVE_ONNET
        if (nvram_match("DD_BOARD", "Atheros Hornet")) {
            websWrite(wp, "OTAi 9331 (%s)", date);
        } else if (nvram_match("DD_BOARD", "Compex WPE72")) {
            websWrite(wp, "OTAi 724 (%s)", date);
        } else if (nvram_match("DD_BOARD", "ACCTON AC622")) {
            if (iscpe()) {
                websWrite(wp, "OTAi 724S (%s)", date);
            } else {
                websWrite(wp, "OTAi 724AP (%s)", date);
            }
        } else if (nvram_match("DD_BOARD", "ACCTON AC722")) {
            if (iscpe()) {
                websWrite(wp, "OTAi 724S (%s)", date);
            } else {
                websWrite(wp, "OTAi 724AP (%s)", date);
            }
        } else if (nvram_match("DD_BOARD", "Compex WP546")) {
            websWrite(wp, "OTAi 724S (%s)", date);
        } else {
            websWrite(wp, "OTAi %s (%s)", nvram_get("DD_BOARD"), date);
        }
#elif HAVE_KORENRON
        websWrite(wp, "KORENRON %s %s%s", MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT);
#elif HAVE_SANSFIL
        websWrite(wp, "SANSFIL %s %s%s", MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT);
#else
        websWrite(wp, "%s%s %s%s", CYBERTAN_VERSION, MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT);
#endif
    }

#else
#ifdef HAVE_WIKINGS
#ifdef HAVE_SUB3
#define V "ExcelMed"
#elif HAVE_SUB6
#define V "ExcelMin"
#else
#define V "Excellent"
#endif
    websWrite(wp, "Excel Networks (%s series) V 2.10", V);
#undef V
#elif HAVE_ESPOD
#ifdef HAVE_SUB3
#define V "A600"
#elif HAVE_SUB6
#define V "A1000"
#else
#define V "MIMO"
#endif
    if (argc == 2) {
        websWrite(wp, "ESPOD v1.0611 (%s) / ESPOD %s Series", date, V);
    } else {
        websWrite(wp, "ESPOD v1.0611 (%s)</a><div>\");document.write(\"<div class=\\\"info\\\">Device: ESPOD %s Series<a>", date, V);
    }
#undef V
#elif HAVE_CARLSONWIRELESS
    websWrite(wp, "Carlson Wireless v1.0 (%s)", SVN_REVISION);
#elif HAVE_IMMERSIVE
    if (argc == 2) {
        websWrite(wp, "Build date %s", date);
    } else {
        websWrite(wp, "SUPPORT %s (%s)", SVN_REVISION, date);
    }
#else

    websWrite(wp, "%s%s %s%s", CYBERTAN_VERSION, MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT);
#endif
#endif
#endif
}
コード例 #3
0
void start_sysinit(void)
{
	time_t tm = 0;

	char dev[64];
	char *disk = getdisc();

	if (disk == NULL) {
		fprintf(stderr, "no valid dd-wrt partition found, calling shell");
		eval("/bin/sh");
		exit(0);
	}

	FILE *in = fopen("/usr/local/nvram/nvram.db", "rb");

	if (in != NULL) {
		fclose(in);
		mkdir("/tmp/nvram", 0700);
		eval("cp", "/etc/nvram/nvram.db", "/tmp/nvram");
		eval("cp", "/etc/nvram/offsets.db", "/tmp/nvram");
		eval("/usr/sbin/convertnvram");
		nvram_commit();
		eval("rm", "-f", "/etc/nvram/nvram.db");
		eval("rm", "-f", "/etc/nvram/offsets.db");
	}
	//recover nvram if available
	in = fopen("/usr/local/nvram/nvram.bin", "rb");
	if (in == NULL) {
		fprintf(stderr, "recover broken nvram\n");
		sprintf(dev, "/dev/%s", disk);
		in = fopen(dev, "rb");
		fseeko(in, 0, SEEK_END);
		off_t mtdlen = ftello(in);
		fseeko(in, mtdlen - (65536 * 2), SEEK_SET);
		unsigned char *mem = malloc(65536);
		fread(mem, 65536, 1, in);
		fclose(in);
		if (mem[0] == 0x46 && mem[1] == 0x4c && mem[2] == 0x53 && mem[3] == 0x48) {
			fprintf(stderr, "found recovery\n");
			in = fopen("/usr/local/nvram/nvram.bin", "wb");
			if (in != NULL) {
				fwrite(mem, 65536, 1, in);
				fclose(in);
				free(mem);
				eval("sync");
				sleep(5);
				eval("event", "5", "1", "15");
			}
		}
		free(mem);
	} else {
		fclose(in);
	}

	if (!nvram_match("disable_watchdog", "1"))
		eval("watchdog");	// system watchdog
#ifdef HAVE_ERC
	if (isregistered_real() && nvram_match("ree_resetme", "1")) {
		fprintf(stderr, "Restoring REE default nvram\n");
		eval("nvram", "restore", "/etc/defaults/x86ree.backup");
		eval("reboot");
		eval("event", "5", "1", "15");
	}
#endif

	cprintf("sysinit() setup console\n");

	/*
	 * Setup console 
	 */

	cprintf("sysinit() klogctl\n");
	klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
	cprintf("sysinit() get router\n");

	/*
	 * eval("insmod","md5"); eval("insmod","aes"); eval("insmod","blowfish");
	 * eval("insmod","deflate"); eval("insmod","des");
	 * eval("insmod","michael_mic"); eval("insmod","cast5");
	 * eval("insmod","crypto_null"); 
	 */

	detect_ethernet_devices();
	eval("ifconfig", "eth0", "0.0.0.0", "up");
	eval("ifconfig", "eth1", "0.0.0.0", "up");
	eval("ifconfig", "eth2", "0.0.0.0", "up");
	eval("ifconfig", "eth3", "0.0.0.0", "up");

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}
	detect_wireless_devices();

	mknod("/dev/rtc", S_IFCHR | 0644, makedev(253, 0));
#ifdef HAVE_CPUTEMP
	// insmod("nsc_gpio");
	// insmod("scx200_gpio");
	// insmod("scx200_i2c");
	// insmod("scx200_acb");
	// insmod("lm77");
#endif

	nvram_set("wl0_ifname", "ath0");
	mknod("/dev/crypto", S_IFCHR | 0644, makedev(10, 70));
	/*
	 * Set a sane date 
	 */
	stime(&tm);
	cprintf("done\n");
	return;
}
コード例 #4
0
/*
 * Called when link goes down
 */
int ipdown_main(int argc, char **argv)
{
	if (check_action() != ACT_IDLE)
		return -1;
	runStartup("/etc/config", ".ipdown");
#ifdef HAVE_REGISTER
	if (isregistered_real())
#endif
	{
#ifdef HAVE_RB500
		runStartup("/usr/local/etc/config", ".ipdown");
#else
		runStartup("/jffs/etc/config", ".ipdown");
		runStartup("/mmc/etc/config", ".ipdown");
		runStartup("/tmp/etc/config", ".ipdown");
#endif
	}
	stop_ddns();
	stop_ntpc();

	unlink("/tmp/ppp/link");

	if (nvram_match("wan_proto", "l2tp")) {
		/*
		 * clear dns from the resolv.conf 
		 */
		nvram_set("wan_get_dns", "");
		dns_to_resolv();

		// todo
		route_del(nvram_safe_get("wan_ifname"), 0, nvram_safe_get("l2tp_server_ip"), nvram_safe_get("wan_gateway_buf"), "255.255.255.255");
		/*
		 * Restore the default gateway for WAN interface 
		 */
		nvram_set("wan_gateway", nvram_safe_get("wan_gateway_buf"));

		/*
		 * Set default route to gateway if specified 
		 */
		route_add(nvram_safe_get("wan_ifname"), 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");
	}
	if (nvram_match("wan_proto", "pptp")) {
		eval("route", "del", "default");
		nvram_set("wan_gateway", nvram_safe_get("wan_gateway_buf"));
		eval("route", "add", "default", "gw", nvram_safe_get("wan_gateway"));
		sysprintf("iptables -t nat -A POSTROUTING -o %s -j MASQUERADE\n", nvram_safe_get("pptp_ifname"));
	}
#ifdef HAVE_3G
#if defined(HAVE_TMK) || defined(HAVE_BKM)
	else if (nvram_match("wan_proto", "3g")) {
		char *gpio3g = nvram_get("gpio3g");
		if (gpio3g != NULL)
			set_gpio(atoi(gpio3g), 0);
	}
#endif
#endif

	nvram_set("pppoe_ifname", "");
	nvram_set("pppd_pppifname", "");

	// write PPP traffic statistics to nvram if wanted
	if (nvram_match("ppp_traffic", "1")) {
		char buffer[64];
		long long old_in, old_out;
		long long in, out;
		char *pin;
		char *pout;
		time_t stamp;

		old_in = atol(nvram_safe_get("ppp_byte_in"));
		old_out = atol(nvram_safe_get("ppp_byte_out"));

		if ((pin = getenv("BYTES_RCVD")))
			in = atol(pin);
		else
			in = 0;

		if ((pout = getenv("BYTES_SENT")))
			out = atol(pout);
		else
			out = 0;

		in += old_in;
		out += old_out;
		snprintf(buffer, 63, "%lld", in);
		nvram_set("ppp_byte_in", buffer);
		snprintf(buffer, 63, "%lld", out);
		nvram_set("ppp_byte_out", buffer);
		if ((stamp = time(NULL)) < 1087818160)	// clock is not set
			// properly
			stamp = 0;
		snprintf(buffer, 63, "%ld", stamp);
		nvram_set("ppp_byte_stamp", buffer);
		nvram_commit();
	}

	if (nvram_match("ppp_demand", "1")
	    && (nvram_match("wan_proto", "pptp")
		|| nvram_match("wan_proto", "l2tp")
		|| nvram_match("wan_proto", "pppoe"))) {
		stop_process("listen", "activity listener");
		eval("listen", nvram_safe_get("lan_ifname"));
	}

	return 1;
}