Exemplo n.º 1
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 3) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{	
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on) 
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (is_module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				}
#endif
				add_iQosRules(get_wan_ifname(0));
				start_iQos();
			}
			else 
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
//					!((nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") || nvram_get_int("wl0_mrate_x") || nvram_get_int("wl1_mrate_x"))) &&
					!is_module_loaded("hw_nat"))
				{
#if 0
					system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
					modprobe("hw_nat");
					sleep(1);
				}
#endif
				del_iQosRules();
				stop_iQos();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			_dprintf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch(on);
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}	
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Exemplo n.º 2
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 2) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on)
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "wan_port") == 0) {
			if(on) start_wan_port();
			else stop_wan_port();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
#ifdef RTCONFIG_IPERF
		else if (strcmp(argv[1], "monitor") == 0) {
			if(on) start_monitor();
			else stop_monitor();
		}
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				}
#endif
#ifdef RTCONFIG_TMOBILE_QOS
			add_EbtablesRules();
#else
			add_iQosRules(get_wan_ifname(0));
#endif
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1)
					start_dpi_engine_service();
				else
#endif
				start_iQos();
			}
			else
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif

#if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN54U)
					if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", "")))
#endif
					{
						modprobe("hw_nat");
						sleep(1);
					}
				}
#endif
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1){
					stop_dpi_engine_service();
				}
				else
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			_dprintf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch(on);
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
#ifdef RTCONFIG_BCMFA
		else if (strcmp(argv[1], "fa_rev") == 0) {
			_dprintf("(%d) done.\n", get_fa_rev());
		}
		else if (strcmp(argv[1], "fa_dump") == 0) {
			_dprintf("(%d) done.\n", get_fa_dump());
		}
#endif
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Exemplo n.º 3
0
void period_check(int sig)
{
	FILE *fp;
	unsigned int val = 0;

#ifdef HAVE_RADIOOFF
	if (initses == 1 && nvram_match("radiooff_boot_off", "1")
	    && nvram_match("radiooff_button", "1")) {
		ses_mode = 1;
		initses = 0;
	}
#endif

	// time_t t;

	// time(&t);
	// DEBUG("resetbutton: now time=%d\n", t);

#if defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600)  || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_WDR4900) || defined(HAVE_VENTANA)
	val = getbuttonstate();
#ifdef HAVE_WRK54G
	if (val)
		val = 0;
	else
		val = 1;
#endif
#ifndef HAVE_ALPHA
#ifdef HAVE_USR5453
	if (val)
		val = 0;
	else
		val = 1;
#endif
#endif

#else
	if (brand == ROUTER_BOARD_WCRGN) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_WHRG300N) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_HAMEA15) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_ECB9750) {
		val = get_gpio(11) << 11;
	} else if (brand == ROUTER_BOARD_NEPTUNE) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_RT3352) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_WR5422) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_DIR600B) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_F5D8235) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_ASUS_RTN10PLUS) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_RT15N) {
		val = get_gpio(12) << 12;
	} else if (brand == ROUTER_BOARD_DIR615D) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_ESR6650) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_EAP9550) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_ESR9752) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_AR670W) {
		val = get_gpio(9) << 9;
	} else if (brand == ROUTER_BOARD_AR690W) {
		val = get_gpio(9) << 9;
	} else if (brand == ROUTER_BOARD_BR6574N) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_ACXNR22) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_TECHNAXX3G) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_WHR300HP2) {
		val = get_gpio(52) << 1;
	} else if (brand == ROUTER_BOARD_W502U) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_GW2380) {
		val = get_gpio(240);
	} else if (brand == ROUTER_BOARD_GW2388) {
		val = get_gpio(240);
	} else {

		if ((fp = fopen(GPIO_FILE, "r"))) {
#ifdef HAVE_XSCALE
			fscanf(fp, "%d", &val);
#else			
			if (brand == ROUTER_NETGEAR_WGR614L)	//gpio 7 power led shared with reset button
			{
				set_gpio(7, 1);	//disable power led
				val = get_gpio(7) << 7;	//read and shift value
				set_gpio(7, 0);	//enable power led
			} else {
				fread(&val, 4, 1, fp);
			}

#endif
			fclose(fp);
		} else
			perror(GPIO_FILE);
	}
#endif
	DEBUG("resetbutton: GPIO = 0x%x\n", val);

	int gpio = 0;

	int state = 0;

#if defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600)  || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_UNIWIP) || defined(HAVE_VENTANA)
	state = val;
	int sesgpio = 0xfff;
	int wifigpio = 0xfff;
	int push;
	int pushwifi;
#ifdef HAVE_WZRG300NH
	sesgpio = 0x117;
	val |= get_gpio(23) << 23;	//aoss pushbutton
#elif defined(HAVE_WHR300HP2)
	sesgpio = 0x102;
	val |= get_gpio(53) << 2;	//aoss pushbutton
#elif defined(HAVE_NEPTUNE)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_HAMEA15)
//      sesgpio = 0x100;
//      val |= get_gpio(0);     //aoss pushbutton
#elif defined(HAVE_WCRGN)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_RT3352)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WZRG300NH2)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WMBR_G300NH)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WZRG450)
	sesgpio = 0x108;
	val |= get_gpio(8) << 8;	//aoss pushbutton
#elif defined(HAVE_DIR632)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WZRHPAG300NH)
	sesgpio = 0x105;
	val |= get_gpio(5) << 5;	//aoss pushbutton
#elif defined(HAVE_CARAMBOLA)
	sesgpio = 0xfff;

#elif defined(HAVE_HORNET)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_RB2011)
//      sesgpio = 0x110;
//      val |= get_gpio(16) << 16;      //aoss pushbutton
#elif defined(HAVE_WDR4300)
//      sesgpio = 0x110;
//      val |= get_gpio(16) << 16;      //aoss pushbutton
#elif defined(HAVE_WNDR3700V4)
	sesgpio = 0x10f;
	val |= get_gpio(15) << 15;	//aoss pushbutton
#elif defined(HAVE_DIR825C1)
	sesgpio = 0x110;
	val |= get_gpio(16) << 16;	//aoss pushbutton
#elif defined(HAVE_WASP)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_WNR2200)
//      sesgpio = 0x00b; //not yet supported
//      val |= get_gpio(37) << 37;      //aoss pushbutton
#elif defined(HAVE_WNR2000)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_WDR2543)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WHRHPGN)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_RT10N)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_RT15N)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_F5D8235)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WR5422)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_DIR600)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_DIR615I)
	sesgpio = 0x110;
	val |= get_gpio(16) << 16;	//aoss pushbutton
#elif defined(HAVE_DIR615E)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WR1043)
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//aoss pushbutton
#elif defined(HAVE_WR941)
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//aoss pushbutton
#elif defined(HAVE_MR3020)
	sesgpio = 0xfff;
#elif defined(HAVE_WR741V4)
	sesgpio = 0x01a;
	val |= get_gpio(26) << 26;	//aoss pushbutton
#elif defined(HAVE_WR741)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WRT400)
	sesgpio = 0x103;
	val |= get_gpio(3) << 3;	//aoss pushbutton
#elif defined(HAVE_WNDR3700)
	sesgpio = 0x103;
	val |= get_gpio(3) << 3;	//aoss pushbutton
#elif defined(HAVE_DIR825)
	sesgpio = 0x108;
	val |= get_gpio(8) << 8;	//aoss pushbutton
#elif defined(HAVE_TG2521)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_OPENRISC)
	sesgpio = 0x005;
	val |= get_gpio(5) << 5;	//aoss pushbutton
#endif
#ifdef HAVE_WRT160NL
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//wps/ses pushbutton
#endif
#ifdef HAVE_TEW632BRP
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//wps/ses pushbutton
#endif
#else
	if (brand > 0xffff) {
		if ((brand & 0x000ff) != 0x000ff)
			gpio = 1 << (brand & 0x000ff);	// calculate gpio value.

		if ((brand & 0x00100) == 0)	// check reset button polarity: 0
			// normal, 1 inversed
			state = (val & gpio);
		else
			state = !(val & gpio);
	} else {

		if ((brand & 0x000f) != 0x000f)
			gpio = 1 << (brand & 0x000f);	// calculate gpio value.

		if ((brand & 0x0010) == 0)	// check reset button polarity: 0
			// normal, 1 inversed
			state = (val & gpio);
		else
			state = !(val & gpio);
	}
	/* 
	 * 1 byte router's SES (AOSS) button gpio number and polarity; Eko
	 * 25.nov.06
	 * 
	 * R R R P N N N N = 0xXX ----- - ------- | | gpio num | | | |--- SES -
	 * AOSS button polarity (0: normal, 1 inversed) | |-------- reserved for
	 * future use
	 * 
	 * 0xff = button disabled / not available 
	 */
	int push;
	int pushwifi;
	int sesgpio;
	int wifigpio = 0xfff;

	switch (brand) {
	case ROUTER_BUFFALO_WHRG54S:
	case ROUTER_BUFFALO_WZRRSG54:
	case ROUTER_BUFFALO_WLI_TX4_G54HP:
		sesgpio = 0x100;	// gpio 0, inversed
		break;
	case ROUTER_BUFFALO_WLA2G54C:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_BUFFALO_WBR2G54S:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_BUFFALO_WZR600DHP2:
	case ROUTER_BUFFALO_WZR900DHP:
		sesgpio = 0x109;	// gpio 9, inversed
		break;
	case ROUTER_BUFFALO_WZR1750:
		sesgpio = 0x10c;	// gpio 12, inversed
		break;
	case ROUTER_D1800H:
		sesgpio = 0x10a;	// gpio 10, inversed
		break;
#ifndef HAVE_BUFFALO
	case ROUTER_ASUS_WL700GE:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_ASUS_RTN10PLUSD1:
		sesgpio = 0x114;	// gpio 20, inversed
		break;
	case ROUTER_ASUS_RTN10:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_ASUS_RTN12:
	case ROUTER_NETGEAR_WNR2000V2:
		sesgpio = 0x100;	// gpio 0, inversed
		break;
	case ROUTER_LINKSYS_WTR54GS:
	case ROUTER_NETGEAR_WNDR4000:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_WRT54G:
	case ROUTER_WRT54G_V8:
	case ROUTER_WRTSL54GS:
	case ROUTER_WRT150N:
	case ROUTER_WRT160N:
	case ROUTER_WRT300N:
	case ROUTER_WRT300NV11:
	case ROUTER_WRT610NV2:
	case ROUTER_ASKEY_RT220XD:	// not soldered
	case ROUTER_DYNEX_DX_NRUTER:
	case ROUTER_LINKSYS_E4200:
	case ROUTER_ASUS_RTN66:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
	case ROUTER_ASUS_AC66U:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
	case ROUTER_DLINK_DIR868:
	case ROUTER_ASUS_AC67U:
		wifigpio = 0x10f;
		sesgpio = 0x107;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_AC56U:
		wifigpio = 0x107;	// gpio 7, inversed
		sesgpio = 0x10f;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_WL500G_PRE:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_ASUS_WL550GE:
		sesgpio = 0x00f;	// gpio 15, normal
		break;
	case ROUTER_WRT310N:
	case ROUTER_WRT350N:
	case ROUTER_WRT610N:
	case ROUTER_ASUS_RTN16:
	case ROUTER_BELKIN_F7D3301:
	case ROUTER_BELKIN_F7D3302:
	case ROUTER_BELKIN_F7D4301:
	case ROUTER_BELKIN_F7D4302:
	case ROUTER_BELKIN_F5D8235V3:
	case ROUTER_LINKSYS_E3200:
		sesgpio = 0x108;	// gpio 8, inversed
		break;
	case ROUTER_ASUS_WL500W:
		sesgpio = 0x007;	// gpio 7, normal
		break;
	case ROUTER_DLINK_DIR330:
		sesgpio = 0x107;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_WL520GUGC:
	case ROUTER_ASUS_WL500G_PRE_V2:
		sesgpio = 0x103;	// gpio 3, inversed
		break;
	case ROUTER_WAP54G_V3:
		sesgpio = 0x10e;	// gpio 14, inversed
		break;
	case ROUTER_NETGEAR_WNDR3300:
		sesgpio = 0x101;	// gpio 1, inversed
		break;
	case ROUTER_WRT54G_V81:
	case ROUTER_DLINK_DIR320:
	case ROUTER_WRT600N:
	case ROUTER_NETGEAR_WNDR3400:
	case ROUTER_NETGEAR_WNR3500L:
		sesgpio = 0x106;	// gpio 6, inversed
		break;
	case ROUTER_WRT320N:
	case ROUTER_WRT160NV3:
	case ROUTER_NETGEAR_WNDR4500:
	case ROUTER_NETGEAR_WNDR4500V2:
	case ROUTER_NETGEAR_R6300:
		sesgpio = 0x104;
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R6250:
		sesgpio = 0x104;	
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R6300V2:
		sesgpio = 0x104;	
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R7000:
		sesgpio = 0x104;
		wifigpio = 0x105;
		break;
	case ROUTER_WRT310NV2:
		sesgpio = 0x105;	// gpio 5, inversed
		break;
	case ROUTER_LINKSYS_E800:
	case ROUTER_LINKSYS_E900:
	case ROUTER_LINKSYS_E1000V2:
	case ROUTER_LINKSYS_E1500:
	case ROUTER_LINKSYS_E1550:
	case ROUTER_LINKSYS_E2500:
		sesgpio = 0x109;	// gpio 9, inversed
		break;
	case ROUTER_LINKSYS_EA6500:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
#endif
	default:
		sesgpio = 0xfff;	// gpio unknown, disabled
		wifigpio = 0xfff;	// gpio unknown, disabled
	}
#endif

	push = 1 << (sesgpio & 0x0ff);	// calculate push value from ses gpio 
	pushwifi = 1 << (wifigpio & 0x0ff);	// calculate push value from ses gpio 
	// 
	// 
	// 
	// pin no.

	/* 
	 * The value is zero during button-pushed. 
	 */
	if (state && nvram_match("resetbutton_enable", "1")) {
		DEBUG("resetbutton: mode=%d, count=%d\n", mode, count);

		if (mode == 0) {
			/* 
			 * We detect button pushed first time 
			 */
			alarmtimer(0, URGENT_INTERVAL);
			mode = 1;
		}
		{		/* Whenever it is pushed steady */
			if (++count > RESET_WAIT_COUNT) {
				if (check_action() != ACT_IDLE) {	// Don't execute during upgrading
					fprintf(stderr, "resetbutton: nothing to do...\n");
					alarmtimer(0, 0);	/* Stop the timer alarm */
					return;
				}
				if ((brand & 0x000f) != 0x000f) {
					printf("resetbutton: factory default.\n");
					dd_syslog(LOG_DEBUG, "Reset button: restoring factory defaults now!\n");
#if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51)
					led_control(LED_DIAG, LED_ON);
#elif defined(HAVE_WHRHPGN)  || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450)
					led_control(LED_DIAG, LED_ON);
#endif
					ACTION("ACT_HW_RESTORE");
					alarmtimer(0, 0);	/* Stop the timer alarm */
#ifdef HAVE_X86
					eval("mount", "/usr/local", "-o", "remount,rw");
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("rm", "-f", "/usr/local/nvram/*");	// delete
					// nvram
					// database
					eval("mount", "/usr/local", "-o", "remount,ro");
#elif HAVE_RB500
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("rm", "-f", "/etc/nvram/*");	// delete nvram
					// database
#elif HAVE_MAGICBOX
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("erase", "nvram");
#else
#ifdef HAVE_BUFFALO_SA
					int region_sa = 0;
					if (nvram_default_match("region", "SA", ""))
						region_sa = 1;
#endif
					nvram_set("sv_restore_defaults", "1");
					nvram_commit();
					eval("killall", "ledtool");	// stop blinking on
					// nvram_commit
#if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51)
					led_control(LED_DIAG, LED_ON);	// turn diag led on,
					// so we know reset
					// was pressed and
					// we're restoring
					// defaults.
#elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450)
					led_control(LED_DIAG, LED_ON);
#endif
#ifdef HAVE_BUFFALO_SA
					nvram_set("sv_restore_defaults", "1");
					if (region_sa)
						nvram_set("region", "SA");
					nvram_commit();
#endif
#endif

					// nvram_set ("sv_restore_defaults", "1");
					// nvram_commit ();

					kill(1, SIGTERM);
				}
			}
		}
	} else if ((sesgpio != 0xfff)
		   && (((sesgpio & 0x100) == 0 && (val & push))
		       || ((sesgpio & 0x100) == 0x100 && !(val & push)))) {
		runStartup("/etc/config", ".sesbutton");
		runStartup("/jffs/etc/config", ".sesbutton");	// if available
		runStartup("/mmc/etc/config", ".sesbutton");	// if available
		runStartup("/tmp/etc/config", ".sesbutton");	// if available
		if (nvram_match("radiooff_button", "1")) {
			led_control(LED_SES, LED_FLASH);	// when pressed, blink white
			switch (ses_mode) {

			case 1:
				// SES (AOSS) led
#ifdef HAVE_RADIOOFF
#ifndef HAVE_BUFFALO
				dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) on\n");
#else
				dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) on\n");
#endif
#ifndef HAVE_ERC
				sysprintf("startservice radio_on");
#endif
#endif

				ses_mode = 0;
				break;
			case 2:

				// (AOSS) led
#ifdef HAVE_RADIOOFF
#ifndef HAVE_BUFFALO
				dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) off\n");
#else
				dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) off\n");
#endif
#ifndef HAVE_ERC
				sysprintf("startservice radio_off");
#endif
#endif

				ses_mode = 1;
				break;
			}

		}
#ifdef HAVE_AOSS
		else if (nvram_match("radiooff_button", "2")) {
			sysprintf("startservice aoss");
		}
#else
#endif

	} else if ((wifigpio != 0xfff)
		   && (((wifigpio & 0x100) == 0 && (val & pushwifi))
		       || ((wifigpio & 0x100) == 0x100 && !(val & pushwifi)))) {
		led_control(LED_WLAN, LED_FLASH);	// when pressed, blink white
		switch (wifi_mode) {
		case 1:
			dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) on\n");
			sysprintf("startservice radio_on");
			wifi_mode = 0;
			break;
		case 0:
			// (AOSS) led
			dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) off\n");
			sysprintf("startservice radio_off");
			wifi_mode = 1;
			break;
		}

	} else {

		/* 
		 * Although it's unpushed now, it had ever been pushed 
		 */
		if (mode == 1) {
			if (check_action() != ACT_IDLE) {	// Don't execute during upgrading
				fprintf(stderr, "resetbutton: nothing to do...\n");
				alarmtimer(0, 0);	/* Stop the timer alarm */
				return;
			}
			service_restart();
		}
	}
}
Exemplo n.º 4
0
static int fn(lua_State * L) {
    check_action(L, 1, { action_kind::LuaExt });
    return push_string(L, to_notation_action(L, 1).get_lua_fn().c_str());
}
Exemplo n.º 5
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 2) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on)
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "wan_port") == 0) {
			if(on) start_wan_port();
			else stop_wan_port();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#if ! (defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK))
		else if (strcmp(argv[1], "watchdog02") == 0) {
			if(on) start_watchdog02();
			else stop_watchdog02();
		}
#endif  /* ! (RTCONFIG_QCA || RTCONFIG_RALINK) */
		else if (strcmp(argv[1], "sw_devled") == 0) {
			if(on) start_sw_devled();
			else stop_sw_devled();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
#ifdef RTCONFIG_IPERF
		else if (strcmp(argv[1], "monitor") == 0) {
			if(on) start_monitor();
			else stop_monitor();
		}
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "0", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "0", 0, 0);
#endif
				}
#endif
			add_iQosRules(get_wan_ifname(wan_primary_ifunit()));
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1) {
					start_dpi_engine_service();
					// force to rebuild firewall to avoid some loopback issue
					if (nvram_match("fw_nat_loopback", "2"))
						start_firewall(wan_primary_ifunit(), 0);
				}
				else
#endif
				start_iQos();
			}
			else
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "2", 0, 0);
					f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "2", 0, 0);
#endif

#if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN300) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTAC54U) || defined(RTN56UB2)
					if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", "")))
#endif
					{
						modprobe("hw_nat");
						sleep(1);
					}
				}
#endif
#ifdef RTCONFIG_BWDPI
				if(nvram_get_int("qos_type") == 1){
					stop_dpi_engine_service(1);
				}
				else
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
#ifdef RTCONFIG_TUNNEL
		else if (strcmp(argv[1], "mastiff") == 0) {
			if(on)
				start_mastiff();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			printf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch();
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else if (strcmp(argv[1], "enc_chk") == 0) {
        		unsigned char enc_buf[ENC_WORDS_LEN];
        		unsigned char dec_buf[DATA_WORDS_LEN + 1];

			_dprintf("get enc str:[%s]\n", enc_str(argv[2], (char *) enc_buf));
			_dprintf("get dec str:[%s]\n", dec_str((char *) enc_buf, (char *) dec_buf));

			_dprintf("done(%d)\n", strcmp(argv[2], (const char *) dec_buf));
		}
#ifdef RTCONFIG_BCMFA
		else if (strcmp(argv[1], "fa_rev") == 0) {
			_dprintf("(%d) done.\n", get_fa_rev());
		}
		else if (strcmp(argv[1], "fa_dump") == 0) {
			_dprintf("(%d) done.\n", get_fa_dump());
		}
#endif
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Exemplo n.º 6
0
static int is_fold_right(lua_State * L) {
    check_action(L, 1, { action_kind::Exprs });
    return push_boolean(L, to_notation_action(L, 1).is_fold_right());
}
Exemplo n.º 7
0
static int use_lambda_abstraction(lua_State * L) {
    check_action(L, 1, { action_kind::ScopedExpr });
    return push_boolean(L, to_notation_action(L, 1).use_lambda_abstraction());
}
Exemplo n.º 8
0
static int rec(lua_State * L) {
    check_action(L, 1, { action_kind::Exprs, action_kind::ScopedExpr });
    return push_expr(L, to_notation_action(L, 1).get_rec());
}
Exemplo n.º 9
0
static int initial(lua_State * L) {
    check_action(L, 1, { action_kind::Exprs });
    return push_optional_expr(L, to_notation_action(L, 1).get_initial());
}
Exemplo n.º 10
0
static int rbp(lua_State * L) {
    check_action(L, 1, { action_kind::Expr, action_kind::Exprs, action_kind::ScopedExpr });
    return push_integer(L, to_notation_action(L, 1).rbp());
}
Exemplo n.º 11
0
static int sep(lua_State * L) {
    check_action(L, 1, { action_kind::Exprs });
    return push_name(L, to_notation_action(L, 1).get_sep());
}
Exemplo n.º 12
0
static void sigaction_handler(int sig, siginfo_t *si, void *context) {
	static siginfo_t empty_siginfo;
	UNUSED(context);
	
	if (!si) si = &empty_siginfo;

	switch (sig) {
	case SIGTERM:{
		#if EMBEDDED_EANBLE	

		int i, act;
		for (i = 30; i > 0; --i) {
        		if (((act = check_action()) == ACT_IDLE) || (act == ACT_REBOOT)) break;
        		fprintf(stderr, "Busy with %d. Waiting before shutdown... %d", act, i);
        		sleep(1);
    		}
		
		nvram_do_commit();
		#endif
		
		is_shutdown = 1;
		break;
	}
	case SIGINT:
		break;
	case SIGALRM:
		break;
	case SIGHUP:
		break;
	case SIGCHLD:
		break;
	case SIGUSR1:{
		
		//- Remove all
		smb_srv_info_t *c;
		smb_srv_info_t *tmp = NULL;
		
		c = smb_srv_info_list;
		if( c != NULL ){
			while(1){

				int end = (c->next==NULL) ? 1 : 0;
				

				if(end==0){
					tmp = c->next;
					Cdbg(DBE, "next, ip=%s", tmp->ip->ptr);
				}
				else
					tmp = NULL;
				
				if(c){
					Cdbg(DBE, "remove , ip=[%s]", c->ip->ptr);
					DLIST_REMOVE(smb_srv_info_list,c);			
					free(c);
				}
				else
					break;

				if(end==1)
					break;
				
				c = tmp;
			}
		}

		//free(smb_srv_info_list);
		g_threadIndex = 0;
		
		Cdbg(DBE, "222222222222222222222222222222222222222222222222222");
		break;
		
		break;
	}
	}
}
Exemplo n.º 13
0
Boolean
check_key_settings (	XmlContent		*keylist_element,
			int			index,
			XmlElementType		*key_type,
			XmlElementType		*keyname_type,
			XmlElementType		*keycode_type,
			XmlElementType		*scancode_type,
			XmlElementType		*acpi_event_descr_type,
			XmlElementType		*default_action_type,
			XmlElementType		*pluginname_type,
			XmlElementType		*pluginfunction_type,
			XmlAttributeName	*action_type_attrname,
			XmlAttributeName	*key_type_attrname,
			unsigned int		*num_keys,
			char			*key_names[MAX_NUM_KEYS],
			Boolean			keycode_used[NUM_KEYCODES],
			Boolean			*valid )
/*
Input:
	keylist_element		- The parent of the element to check.
	index			- Read the index'th key element
	key_type		- The XmlElementType for the key element
	keyname_type		- The XmlElementType for the key-name element
	keycode_type		- The XmlElementType for the keycode element
	scancode_type		- The XmlElementType for the scancode element
	acpi_event_descr_type	- The XmlElementType for the event-descr element
	default_action_type	- The XmlElementType for the default-action element
	pluginname_type		- The XmlElementType for the plugin-name element
	pluginfunction_type	- The XmlElementType for the plugin-function element
	action_type_attrname	- The XmlElementName for the action-type attribute
	key_type_attrname	- The XmlElementName for the key-type attribute
	num_keys		- The number of elements used in 'key_names'
	key_names		- Array of pointers to key names that are in the
				  keyboard file.
	keycode_used		- For keycode i, keycode_used[i] indicates if it is
				  used already in the keyboard file.
Output:
	valid			- Will be TRUE if the index'th element of 'key_type'
				  in 'keylist_element', is valid (otherwise FALSE).
	num_keys		- If '*valid' is TRUE then 'num_keys' will be
				  increased with 1 if it is smaller than
				  MAX_NUM_KEYS-1.
	key_names		- If '*valid' is TRUE then the (*num_key-1)'th (if
				  *num_keys < MAX_NUM_KEYS) element of this array,
				  will point to the key name of the checked key
				  setting. The memory of this name is allocated and
				  should be freed if it is no longer needed.
	keycode_used		- For keycode i, keycode_used[i] indicates if it is
				  used already in the keyboard file.
Returns:
	TRUE if the index'th element of 'key_type' in 'keylist_element' exist.
Desciption:
	This function checks if the key_name and default_action member, of the
	index'th key element of 'keylist_element', are valid.
*/
{
	XmlContent	*key_element,
			*event_descr_element,
			*keyname_element,
			*keycode_element,
			*scancode_element,
			*default_action_element;
	unsigned int	i, keycode;
	char		*key_name,
			*key_type_str,
			*end_pointer,
			*keycode_string,
			*scancode_string;
	Boolean		is_acpi_hotkey;
	
	*valid = TRUE;
	key_element = XmlGetElementOfType(XmlElementContentList(keylist_element), key_type, index);
	if (key_element)
	{
		key_type_str = XmlGetAttributeValue (key_type_attrname, key_element);
		is_acpi_hotkey = (key_type_str && !strcmp(key_type_str, ATTR_VAL_ACPIHOTKEY));
		if ((keyname_element = XmlGetElementOfType(XmlElementContentList(key_element), keyname_type, 0)) == NULL ||
		    (default_action_element = XmlGetElementOfType(XmlElementContentList(key_element), default_action_type, 0)) == NULL ||
		    (keycode_element = XmlGetElementOfType(XmlElementContentList(key_element), keycode_type, 0)) == NULL ||
		    (is_acpi_hotkey ?
		       (event_descr_element = XmlGetElementOfType(XmlElementContentList(key_element), acpi_event_descr_type, 0)) == NULL :
		       (scancode_element = XmlGetElementOfType(XmlElementContentList(key_element), scancode_type, 0)) == NULL) )
		{
			KTSetErrorMsg (_("The keyboard file contains an incomplete key element."), "");
			*valid = FALSE;
		}
		else
		{
			key_name = XmlGetElementString (keyname_element, "");
			if (*key_name == '\0')
			{
				KTSetErrorMsg (_("The keyboard file contains an empty key-name element."), "");
				*valid = FALSE;
			}
			else
			{
				for (i = 0; i < *num_keys && strcmp (key_name, key_names[i]) != 0; i++)
					; /* NULL Statement */
				if (i < *num_keys)
				{
					KTSetErrorMsg (_("The keyboard file contains more than once a key named '%s'."), key_name);
					*valid = FALSE;
				}
				else if ( !check_action (default_action_element, pluginname_type,
					                 pluginfunction_type, action_type_attrname) )
				{
					*valid = FALSE;
				}
				
			}
			if (*valid)
			{
				if (!is_acpi_hotkey)
				{
					/** Check the scancode **/
					scancode_string = XmlGetElementString(scancode_element, "");
					/* Convert the string of the scancode to a integer */
					strtol (scancode_string, &end_pointer, 0);
					/* If the scancode string is not a vallid scancode */
					if (*end_pointer != '\0')
					{
						KTSetErrorMsg (_("'%s' is an invalid scancode."), scancode_string);
						*valid = FALSE;
					}
					XmlFree (scancode_string);
				}
				
				if (*valid)
				{
					/** Check the keycode **/
					keycode_string = XmlGetElementString (keycode_element, "");
					keycode = string_to_kernel_keycode (keycode_string);
					if (keycode)
					{
						if (keycode_used[keycode])
						{
							KTSetErrorMsg (_("Keycode %s is used more than once."), keycode_string);
							*valid = FALSE;
						}
						else
						{
							keycode_used[keycode] = TRUE;
						}
					}
					else
					{
						if (keycode_string[0] == '\0')
						{
							KTSetErrorMsg (_("The keyboard file contains an empty keycode."), "");
						}
						else
						{
							KTSetErrorMsg (_("'%s' is an invalid keycode."), keycode_string);
						}
						*valid = FALSE;
					}
					XmlFree (keycode_string);
					
					if (*valid && *num_keys < MAX_NUM_KEYS-1)
					{
						key_names[*num_keys] = key_name;
						(*num_keys)++;
					}
					else
					{
						XmlFree (key_name);
					}
				}
			}
		}
	}
	
	return (key_element != NULL);
}
Exemplo n.º 14
0
int main(int argc, char **argv) {

    UNUSED(argc);

    //- Check if same process is running.
    FILE *fp = fopen(LIGHTTPD_MONITOR_PID_FILE_PATH, "r");
    if (fp) {
        fclose(fp);
        return 0;
    }

    //- Write PID file
    pid_t pid = getpid();
    fp = fopen(LIGHTTPD_MONITOR_PID_FILE_PATH, "w");
    if (!fp) {
        exit(EXIT_FAILURE);
    }
    fprintf(fp, "%d\n", pid);
    fclose(fp);

#if EMBEDDED_EANBLE
    sigset_t sigs_to_catch;

    /* set the signal handler */
    sigemptyset(&sigs_to_catch);
    sigaddset(&sigs_to_catch, SIGTERM);
    sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL);

    signal(SIGTERM, sigaction_handler);
#else
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &act, NULL);
    sigaction(SIGUSR1, &act, NULL);

    act.sa_sigaction = sigaction_handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_SIGINFO;

    sigaction(SIGINT,  &act, NULL);
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGHUP,  &act, NULL);
    sigaction(SIGALRM, &act, NULL);
    sigaction(SIGCHLD, &act, NULL);
#endif

    time_t prv_ts = time(NULL);

    int stop_arp_count = 0;
    int commit_count = 0;

    while (!is_shutdown) {

        sleep(10);

        int start_lighttpd = 0;
        int start_lighttpd_arp = 0;

        time_t cur_ts = time(NULL);

#if EMBEDDED_EANBLE
        if (!pids("lighttpd")) {
            start_lighttpd = 1;
        }

        if (!pids("lighttpd-arpping")) {
            start_lighttpd_arp = 1;
        }
#else
        if (!system("pidof lighttpd")) {
            start_lighttpd = 1;
        }

        if (!system("pidof lighttpd-arpping")) {
            start_lighttpd_arp = 1;
        }
#endif

        //-every 30 sec
        if(cur_ts - prv_ts >= 30) {

            if(start_lighttpd) {
#if EMBEDDED_EANBLE
                system("/usr/sbin/lighttpd -f /tmp/lighttpd.conf -D &");
#else
                system("./_inst/sbin/lighttpd -f lighttpd.conf &");
#endif
            }

            if(start_lighttpd_arp) {
#if EMBEDDED_EANBLE
                system("/usr/sbin/lighttpd-arpping -f br0 &");
#else
                system("./_inst/sbin/lighttpd-arpping -f eth0 &");
#endif
            }

            //-every 2 hour
            if(stop_arp_count>=240) {
                stop_arpping_process();
                stop_arp_count=0;
            }

            //-every 12 hour
            if(commit_count>=1440) {

#if EMBEDDED_EANBLE
                int i, act;
                for (i = 30; i > 0; --i) {
                    if (((act = check_action()) == ACT_IDLE) || (act == ACT_REBOOT)) break;
                    fprintf(stderr, "Busy with %d. Waiting before shutdown... %d", act, i);
                    sleep(1);
                }

                nvram_do_commit();
#endif

                commit_count=0;
            }

            prv_ts = cur_ts;
            stop_arp_count++;
            commit_count++;
        }
    }

    Cdbg(DBE, "Success to terminate lighttpd-monitor.....");

    exit(EXIT_SUCCESS);

    return 0;
}
Exemplo n.º 15
0
/*
 * Called when link comes up
 */
int ipup_main(int argc, char **argv)
{
	FILE *fp;
	char *wan_ifname = safe_getenv("IFNAME");

	// char *wan_proto = nvram_safe_get("wan_proto");
	char *value;
	char buf[256];

	cprintf("%s\n", argv[0]);

	stop_process("listen", "activity listener");
	nvram_set("wan_iface", wan_ifname);
	if (check_action() != ACT_IDLE)
		return -1;

	/*
	 * ipup will receive bellow six arguments 
	 */
	/*
	 * interface-name tty-device speed local-IP-address remote-IP-address
	 * ipparam 
	 */

	/*
	 * Touch connection file 
	 */
	if (!(fp = fopen("/tmp/ppp/link", "a"))) {
		perror("/tmp/ppp/link");
		return errno;
	}
	fprintf(fp, "%s", argv[1]);
	fclose(fp);

	nvram_set("pppd_pppifname", wan_ifname);

	if (nvram_match("wan_proto", "pppoe"))
		nvram_set("pppoe_ifname", wan_ifname);

	if (getenv("IPLOCAL")) {
		value = getenvs("IPLOCAL");
		ifconfig(wan_ifname, IFUP, value, "255.255.255.255");
		if (nvram_match("wan_proto", "pppoe")) {
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));	// Store 
			nvram_set("wan_ipaddr", value);
			nvram_set("wan_netmask", "255.255.255.255");
#ifdef HAVE_PPPOATM
		} else if (nvram_match("wan_proto", "pppoa")) {
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));	// Store 
			nvram_set("wan_ipaddr", value);
			nvram_set("wan_netmask", "255.255.255.255");
#endif
#ifdef HAVE_PPTP
		} else if (nvram_match("wan_proto", "pptp")) {
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));	// Store 
			nvram_set("pptp_get_ip", value);
#endif
#ifdef HAVE_L2TP
		} else if (nvram_match("wan_proto", "l2tp")) {
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));	// Store 
			nvram_set("l2tp_get_ip", value);
#endif
		}
#ifdef HAVE_3G
		else if (nvram_match("wan_proto", "3g")) {
			nvram_set("wan_ipaddr_buf", nvram_safe_get("wan_ipaddr"));	// Store 
			nvram_set("wan_ipaddr", value);
			nvram_set("wan_netmask", "255.255.255.255");
			// reset 3gnetmodetoggle for mode 5
			nvram_unset("3gnetmodetoggle");
#if defined(HAVE_TMK) || defined(HAVE_BKM)
			char *gpio3g = nvram_get("gpio3g");
			if (gpio3g != NULL)
				set_gpio(atoi(gpio3g), 1);
#endif
		}
#endif
	}

	if (getenv("IPREMOTE")) {
		value = getenvs("IPREMOTE");

		if (nvram_match("wan_proto", "pptp")) {
			nvram_set("wan_gateway", value);
			eval("route", "del", "default");
			route_add(wan_ifname, 0, "0.0.0.0", value, "0.0.0.0");
		} else {
			nvram_set("wan_gateway", value);

		}
	}
	strcpy(buf, "");
	if (getenv("DNS1"))
		sprintf(buf, "%s", getenvs("DNS1"));
	if (getenv("DNS2"))
		sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", getenvs("DNS2"));
	nvram_set("wan_get_dns", buf);

	if ((value = getenv("AC_NAME")))
		nvram_set("ppp_get_ac", value);
	if ((value = getenv("SRV_NAME")))
		nvram_set("ppp_get_srv", value);
	if ((value = getenv("MTU")))
		nvram_set("wan_run_mtu", value);
	start_wan_done(wan_ifname);
	cprintf("done\n");
	return 0;
}
Exemplo n.º 16
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;
}