Exemplo n.º 1
0
static void build_wan_lan_mask(int stb)
{
	int i, unit;
	int wanscap_lan = get_wans_dualwan() & WANSCAP_LAN;
	int wans_lanport = nvram_get_int("wans_lanport");
	int sw_mode = nvram_get_int("sw_mode");
	char prefix[8], nvram_ports[20];

	if (sw_mode == SW_MODE_AP || sw_mode == SW_MODE_REPEATER)
		wanscap_lan = 0;

	if (stb == 100 && (sw_mode == SW_MODE_AP || __mediabridge_mode(sw_mode)))
		stb = 7;	/* Don't create WAN port. */

#if 0	/* TODO: no WAN port */
	if ((get_wans_dualwan() & (WANSCAP_LAN | WANSCAP_WAN)) == 0)
		stb = 7; // no WAN?
#endif

	if (wanscap_lan && (wans_lanport < 0 || wans_lanport > 4)) {
		_dprintf("%s: invalid wans_lanport %d!\n", __func__, wans_lanport);
		wanscap_lan = 0;
	}

	lan_mask = wan_mask = wans_lan_mask = 0;
	for (i = 0; i < NR_WANLAN_PORT; ++i) {
		switch (lan_wan_partition[stb][i]) {
		case 0:
			wan_mask |= 1U << lan_id_to_port_nr(i);
			break;
		case 1:
			lan_mask |= 1U << lan_id_to_port_nr(i);
			break;
		default:
			_dprintf("%s: Unknown LAN/WAN port definition. (stb %d i %d val %d)\n",
				__func__, stb, i, lan_wan_partition[stb][i]);
		}
	}

	//DUALWAN
	if (wanscap_lan) {
		wans_lan_mask = 1U << lan_id_to_port_nr(wans_lanport);
		lan_mask &= ~wans_lan_mask;
	}

	for (unit = WAN_UNIT_FIRST; unit < WAN_UNIT_MAX; ++unit) {
		sprintf(prefix, "%d", unit);
		sprintf(nvram_ports, "wan%sports_mask", (unit == WAN_UNIT_FIRST)?"":prefix);

		if (get_dualwan_by_unit(unit) == WANS_DUALWAN_IF_WAN) {
			nvram_set_int(nvram_ports, wan_mask);
		}
		else if (get_dualwan_by_unit(unit) == WANS_DUALWAN_IF_LAN) {
			nvram_set_int(nvram_ports, wans_lan_mask);
		}
		else
			nvram_unset(nvram_ports);
	}
	nvram_set_int("lanports_mask", lan_mask);
}
Exemplo n.º 2
0
static void
nvram_convert_old_params(void)
{
	char *test_value;

	/* convert old params */
	test_value = nvram_get("front_leds");
	if (test_value) {
		int front_leds = atoi(test_value);
		if (front_leds > 2)
			nvram_set_int("front_led_all", 0);
		if (front_leds == 4 || front_leds == 2)
			nvram_set_int("front_led_pwr", 0);
		nvram_unset("front_leds");
	}

	test_value = nvram_get("pppoe_dhcp_route");
	if (test_value) {
		if (strlen(test_value) > 0 && strlen(nvram_safe_get("wan_pppoe_man")) == 0)
			nvram_set("wan_pppoe_man", test_value);
		nvram_unset("pppoe_dhcp_route");
	}

	test_value = nvram_get("wan_heartbeat_x");
	if (test_value) {
		if (strlen(test_value) > 0 && strlen(nvram_safe_get("wan_ppp_peer")) == 0)
			nvram_set("wan_ppp_peer", test_value);
		nvram_unset("wan_heartbeat_x");
	}
	nvram_unset("wan0_heartbeat_x");

	test_value = nvram_get("wan_3g_pin");
	if (test_value) {
		if (strlen(test_value) > 0 && strlen(nvram_safe_get("modem_pin")) == 0)
			nvram_set("modem_pin", test_value);
		nvram_unset("wan_3g_pin");
	}
	nvram_unset("wan0_3g_pin");

	/* remove old unused params */
	nvram_unset("lan_route");
	nvram_unset("wan0_route");
	nvram_unset("wan_route");
	nvram_unset("wan_dns_t");
	nvram_unset("wan_proto_t");
	nvram_unset("wan_ipaddr_t");
	nvram_unset("wan_netmask_t");
	nvram_unset("wan_gateway_t");
	nvram_unset("wan_ifname_t");
	nvram_unset("wan_status_t");
	nvram_unset("wan_subnet_t");
	nvram_unset("lan_subnet_t");
	nvram_unset("link_lan");
	nvram_unset("rt_mcastrate");
	nvram_unset("wl_mcastrate");
}
Exemplo n.º 3
0
static void
ez_action_led_toggle(void)
{
    int front_led_x = (nvram_get_int("front_led_all")) ? 0 : 1;

    nvram_set_int("front_led_all", front_led_x);
    nvram_set_int("front_led_pwr", front_led_x);

    notify_leds_detect_link();
}
Exemplo n.º 4
0
/**
 * Add/Strip GPIO_BLINK_LED flag to specified led_xxx_gpio.
 * @led_gpio:	pointer to name of "led_xxx_gpio"
 * @return:
 *  	0:	success
 *  otherwisze:	fail
 */
static inline int __update_gpio_nv_var(const char *led_gpio, int add)
{
	char *p;

	if (!led_gpio || !(p = nvram_get(led_gpio)))
		return -1;

	if (add)
		nvram_set_int(led_gpio, atoi(p) | GPIO_BLINK_LED);
	else
		nvram_set_int(led_gpio, atoi(p) & ~GPIO_BLINK_LED);
	return 0;
}
Exemplo n.º 5
0
/*
 * Called when interface comes up
 */
int
ippreup_main(int argc, char **argv)
{
	char *wan_ifname = safe_getenv("IFNAME");
	char *wan_linkname = safe_getenv("LINKNAME");
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	_dprintf("%s():: %s\n", __FUNCTION__, argv[0]);

	/* Get unit from LINKNAME: ppp[UNIT] */
	if ((unit = ppp_linkunit(wan_linkname)) < 0)
		return 0;

	_dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname);
	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	/* Set wanX_pppoe_ifname to real interface name */
	nvram_set(strcat_r(prefix, "pppoe_ifname", tmp), wan_ifname);

	/* Start triggering demand connection */
	if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp)))
		nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 2);

	_dprintf("%s:: done\n", __FUNCTION__);
	return 0;
}
Exemplo n.º 6
0
/*
 * Called when link closing with auth fail
 */
int
authfail_main(int argc, char **argv)
{
	char *wan_ifname = safe_getenv("IFNAME");
	char *wan_linkname = safe_getenv("LINKNAME");
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	_dprintf("%s():: %s\n", __FUNCTION__, argv[0]);

	/* Get unit from LINKNAME: ppp[UNIT] */
	if ((unit = ppp_linkunit(wan_linkname)) < 0)
		return 0;

	_dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname);
	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	/* Stop triggering demand connection */
	if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp)))
		nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1);

	// override wan_state
	update_wan_state(prefix, WAN_STATE_STOPPED, WAN_STOPPED_REASON_PPP_AUTH_FAIL);

	_dprintf("%s:: done\n", __FUNCTION__);
	return 0;
}
Exemplo n.º 7
0
/* @return:
 * 	0:	success
 *     -1:	invalid parameter
 *      1:	wait pending rc_service timeout
 */
static int notify_rc_internal(const char *event_name, bool do_wait, int wait)
{
	int i;
	char p2[16];

	if (!event_name || wait < 0)
		return -1;

	psname(getpid(), p2, sizeof(p2));
	_dprintf("%s %d:notify_rc: %s\n", p2, getpid(), event_name);
	logmessage_normal("rc_service", "%s %d:notify_rc %s", p2, getpid(), event_name);

	if (!wait_rc_service(wait)) {
		logmessage_normal("rc_service", "skip the event: %s.", event_name);
		_dprintf("rc_service: skip the event: %s.\n", event_name);
		return 1;
	}

	nvram_set("rc_service", event_name);
	nvram_set_int("rc_service_pid", getpid());
	kill(1, SIGUSR1);

	if(do_wait)
	{
		i = wait;
		while((nvram_match("rc_service", (char *)event_name))&&(i-- > 0)) {
			_dprintf("%s %d: waiting after %d/%d.\n", event_name, getpid(), i, wait);
			sleep(1);
		}
		if(i == 0 && nvram_match("rc_service", (char *)event_name))
			return 2;
	}

	return 0;
}
Exemplo n.º 8
0
void convert_dsl_config_num()
{
	int config_num = 0;
	if(nvram_match("dslx_transmode", "atm")) {
		if (nvram_match("dsl0_enable","1")) config_num++;
		if (nvram_match("dsl1_enable","1")) config_num++;
		if (nvram_match("dsl2_enable","1")) config_num++;
		if (nvram_match("dsl3_enable","1")) config_num++;
		if (nvram_match("dsl4_enable","1")) config_num++;
		if (nvram_match("dsl5_enable","1")) config_num++;
		if (nvram_match("dsl6_enable","1")) config_num++;
		if (nvram_match("dsl7_enable","1")) config_num++;
	}
	else {
		if (nvram_match("dsl8_enable","1")) config_num++;
		if (nvram_match("dsl8.1_enable","1")) config_num++;
		if (nvram_match("dsl8.2_enable","1")) config_num++;
		if (nvram_match("dsl8.3_enable","1")) config_num++;
		if (nvram_match("dsl8.4_enable","1")) config_num++;
		if (nvram_match("dsl8.5_enable","1")) config_num++;
		if (nvram_match("dsl8.6_enable","1")) config_num++;
		if (nvram_match("dsl8.7_enable","1")) config_num++;
		//if (nvram_match("dsl9_enable","1")) config_num++;
	}
	nvram_set_int("dslx_config_num", config_num);
}
Exemplo n.º 9
0
void
nvram_wlan_set_int(int is_aband, const char *param, int value)
{
	char wlan_param[64];
	const char *prefix = (is_aband) ? "wl" : "rt";

	snprintf(wlan_param, sizeof(wlan_param), "%s_%s", prefix, param);
	nvram_set_int(wlan_param, value);
}
Exemplo n.º 10
0
static void 
ez_action_led_toggle(void)
{
	int i_front_leds = nvram_get_int("front_leds");
	if (i_front_leds != LED_FULL_OFF)
		i_front_leds = LED_FULL_OFF;
	else
		i_front_leds = 0;
	nvram_set_int("front_leds", i_front_leds);
	system("killall -SIGALRM detect_link");
}
Exemplo n.º 11
0
void convert_dsl_config_num()
{
	int config_num = 0;
	if (nvram_match("dsl0_enable","1")) config_num++;
	if (nvram_match("dsl1_enable","1")) config_num++;
	if (nvram_match("dsl2_enable","1")) config_num++;
	if (nvram_match("dsl3_enable","1")) config_num++;
	if (nvram_match("dsl4_enable","1")) config_num++;
	if (nvram_match("dsl5_enable","1")) config_num++;
	if (nvram_match("dsl6_enable","1")) config_num++;
	if (nvram_match("dsl7_enable","1")) config_num++;
	nvram_set_int("dslx_config_num", config_num); 
}
Exemplo n.º 12
0
/* @return:
 * 	0:	success
 *     -1:	invalid parameter
 *      1:	wait pending rc_service timeout
 */
static int notify_rc_internal(const char *event_name, bool do_wait, int wait)
{
	int i;
	char p1[16], p2[16];

	if (!event_name || wait < 0)
		return -1;

	psname(nvram_get_int("rc_service_pid"), p1, sizeof(p1));
	psname(getpid(), p2, sizeof(p2));
	_dprintf("%s %d:notify_rc: %s\n", p2, getpid(), event_name);
	logmessage("rc_service", "%s %d:notify_rc %s", p2, getpid(), event_name);

	i=wait;
	int first_try = 1, got_right = 1;
	while ((!nvram_match("rc_service", "")) && (i-- > 0)) {
		if(first_try){
			logmessage("rc_service", "%s is waitting %s...", event_name, nvram_safe_get("rc_service"));
			first_try = 0;
		}

		_dprintf("%d %s: wait for previous script(%d/%d): %s %d %s.\n", getpid(), p2, i, wait, nvram_safe_get("rc_service"), nvram_get_int("rc_service_pid"), p1);
		sleep(1);

		if(i <= 0)
			got_right = 0;
	}

	if(!got_right){
		logmessage("rc_service", "skip the event: %s.", event_name);
		_dprintf("rc_service: skip the event: %s.\n", event_name);
		return 1;
	}

	nvram_set("rc_service", event_name);
	nvram_set_int("rc_service_pid", getpid());
	kill(1, SIGUSR1);

	if(do_wait)
	{
		i = wait;
		while((nvram_match("rc_service", (char *)event_name))&&(i-- > 0)) {
			_dprintf("%s %d: waiting after %d/%d.\n", event_name, getpid(), i, wait);
			sleep(1);
		}
	}

	return 0;
}
Exemplo n.º 13
0
int led_control(int which, int mode)
#ifdef RTCONFIG_INTERNAL_GOBI
{ //save value
	char name[16];

	snprintf(name, sizeof(name), "led%02d", which);
	if(nvram_get_int(name) != mode)
		nvram_set_int(name, mode);

	if (nvram_match(LED_CTRL_HIPRIO, "1"))
		return 0;

	int do_led_control(int which, int mode);
	return do_led_control(which, mode);
}
Exemplo n.º 14
0
int 
watchdog_main(int argc, char *argv[])
{
	FILE *fp;
	sigset_t sigs_to_catch;

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

	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP,  catch_sig);
	signal(SIGTERM, catch_sig);
	signal(SIGUSR1, catch_sig);
	signal(SIGUSR2, catch_sig);
	signal(SIGALRM, watchdog);

	if (daemon(0, 0) < 0) {
		perror("daemon");
		exit(errno);
	}

	nvram_set_int("wd_notify_id", 0);

	/* write pid */
	if ((fp = fopen("/var/run/watchdog.pid", "w")) != NULL)
	{
		fprintf(fp, "%d", getpid());
		fclose(fp);
	}

	/* set timer */
	alarmtimer(NORMAL_PERIOD, 0);

	/* Most of time it goes to sleep */
	while (1)
	{
		pause();
	}

	return 0;
}
Exemplo n.º 15
0
void generate_switch_para(void)
{
	int model;

	// generate nvram nvram according to system setting
	model = get_model();

	switch(model) {
		case MODEL_RTN13U:
			if(!is_routing_enabled()) {
				// override boardflags with no VLAN flag
				nvram_set_int("boardflags", nvram_get_int("boardflags")&(~BFL_ENETVLAN));
				nvram_set("lan_ifnames", "eth2 ra0");
			}
			else if(nvram_match("switch_stb_x", "1")) {
				nvram_set("vlan0ports", "0 1 2 5*");
				nvram_set("vlan1ports", "3 4 5u");
			}
			else if(nvram_match("swtich_stb_x", "2")) {
				nvram_set("vlan0ports", "0 1 3 5*");
				nvram_set("vlan1ports", "2 4 5u");
			}
			else if(nvram_match("switch_stb_x", "3")) {
				nvram_set("vlan0ports", "0 2 3 5*");
				nvram_set("vlan1ports", "1 4 5u");
			}
			else if(nvram_match("switch_stb_x", "4")) {
				nvram_set("vlan0ports", "1 2 3 5*");
				nvram_set("vlan1ports", "0 4 5u");
			}
			else if(nvram_match("switch_stb_x", "5")) {
				nvram_set("vlan0ports", "2 3 5*");
				nvram_set("vlan1ports", "0 1 4 5u");
			}
			else {	// default for 0
				nvram_set("vlan0ports", "0 1 2 3 5*");
				nvram_set("vlan1ports", "4 5u");
			}
			break;
	}
}
Exemplo n.º 16
0
static void 
ez_action_force_toggle_wifi5(void)
{
	int i_radio_state;

	if (get_enabled_radio_wl())
	{
		i_radio_state = 0;
	}
	else
	{
		i_radio_state = 1;
		update_svc_status_wifi5();
	}
	
	nvram_set_int("wl_radio_x", i_radio_state);
	
	logmessage("watchdog", "Perform ez-button force toggle %s radio: %s", "5GHz", (i_radio_state) ? "ON" : "OFF");
	
	control_radio_wl(i_radio_state, 1);
}
Exemplo n.º 17
0
/**
 * Set a VLAN
 * @idx:	VLAN table index
 *  >= 0:	specify VLAN table index.
 *  <  0:	find available VLAN table.
 * @vid:	VLAN ID
 * @prio:	VLAN Priority
 * @mbr:	VLAN members
 * @untag:	VLAN members that need untag
 *
 * @return
 * 	0:	success
 *     -1:	no vlan entry available
 *     -2:	invalid parameter
 */
int qca8337_vlan_set(int idx, int vid, int prio, int mbr, int untag)
{
	char idx_str[8];
	char vid_str[8], prio_str[8];
	char ports[32];
	int vlan_idx;

	if(vid > 4095 || prio > 7)
		return -2;

	vlan_idx = nvram_get_int("vlan_idx");
	if (idx <= 0)
	{
		idx = vlan_idx + 1;
	}

	if(idx >= 128)		//only 128 vlan entry is supported in driver (ar8216.c)
	{
		return -1;
	}
	else if (idx <= vlan_idx)
	{
		_dprintf("%s: out of order. idx(%d) vlan_idx(%d)\n", __func__, idx, vlan_idx);
	}
	else
	{
		nvram_set_int("vlan_idx", idx);
	}

	__mask_to_portnumber_str(mbr, untag, &ports[0]);

	sprintf(idx_str , "%d", idx);
	sprintf(vid_str , "%d", vid);
	sprintf(prio_str, "%d", prio);
	eval("swconfig", "dev", MII_IFNAME, "vlan", idx_str, "set", "vid", vid_str);
	eval("swconfig", "dev", MII_IFNAME, "vlan", idx_str, "set", "vpri", prio_str);
	eval("swconfig", "dev", MII_IFNAME, "vlan", idx_str, "set", "ports", ports);
	return 0;
}
Exemplo n.º 18
0
int init_gpio(void)
{
	char *btn_list[] = { "btn_rst_gpio", "btn_wps_gpio", "fan_gpio", "have_fan_gpio"
#ifdef RTCONFIG_WIRELESS_SWITCH
		, "btn_wifi_gpio"
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
		, "btn_wltog_gpio"
#endif
#ifdef RTCONFIG_SWMODE_SWITCH
#if defined(PLAC66U)
		, "btn_swmode1_gpio"
#else
		, "btn_swmode1_gpio", "btn_swmode2_gpio", "btn_swmode3_gpio"
#endif	/* Mode */
#endif	/* RTCONFIG_SWMODE_SWITCH */
#ifdef RTCONFIG_TURBO
		, "btn_turbo_gpio"
#endif
#ifdef RTCONFIG_LED_BTN
		, "btn_led_gpio"
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
		, "btn_lte_gpio"
#endif
	};
	char *led_list[] = { "led_turbo_gpio", "led_pwr_gpio", "led_usb_gpio", "led_wps_gpio", "fan_gpio", "have_fan_gpio", "led_lan_gpio", "led_wan_gpio", "led_usb3_gpio", "led_2g_gpio", "led_5g_gpio" 
#ifdef RTCONFIG_LAN4WAN_LED
		, "led_lan1_gpio", "led_lan2_gpio", "led_lan3_gpio", "led_lan4_gpio"
#endif  /* LAN4WAN_LED */
#ifdef RTCONFIG_LED_ALL
		, "led_all_gpio"
#endif
		, "led_wan_red_gpio"
#ifdef RTCONFIG_QTN
		, "reset_qtn_gpio"
#endif
#ifdef RTCONFIG_USBRESET
		, "pwr_usb_gpio"
		, "pwr_usb_gpio2"
#endif
#ifdef RTCONFIG_WIFIPWR
		, "pwr_2g_gpio"
		, "pwr_5g_gpio"
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
		, "led_3g_gpio", "led_lte_gpio", "led_sig1_gpio", "led_sig2_gpio", "led_sig3_gpio", "led_sig4_gpio"
#endif
#if (defined(PLN12) || defined(PLAC56))
		, "plc_wake_gpio"
		, "led_pwr_red_gpio"
		, "led_2g_green_gpio", "led_2g_orange_gpio", "led_2g_red_gpio"
		, "led_5g_green_gpio", "led_5g_orange_gpio", "led_5g_red_gpio"
#endif
#ifdef RTCONFIG_MMC_LED
		, "led_mmc_gpio"
#endif
#if defined(RTCONFIG_RTAC5300) || defined(RTCONFIG_RTAC5300R)
		, "rpm_fan_gpio"
#endif
#ifdef RTCONFIG_RESET_SWITCH
		, "reset_switch_gpio"
#endif
			   };
	int use_gpio, gpio_pin;
	int enable, disable;
	int i;

#ifdef RTCONFIG_INTERNAL_GOBI
	void get_gpio_values_once(int);
	get_gpio_values_once(0);		// for filling data to led_gpio_table[]
#endif	/* RTCONFIG_INTERNAL_GOBI */

	/* btn input */
	for(i = 0; i < ASIZE(btn_list); i++)
	{
		if (!nvram_get(btn_list[i]))
			continue;
		use_gpio = nvram_get_int(btn_list[i]);
		if((gpio_pin = use_gpio & 0xff) == 0xff)
			continue;
		gpio_dir(gpio_pin, GPIO_DIR_IN);
	}

	/* led output */
	for(i = 0; i < ASIZE(led_list); i++)
	{
		if (!nvram_get(led_list[i]))
			continue;
#if defined(RTCONFIG_ETRON_XHCI_USB3_LED)
		if (!strcmp(led_list[i], "led_usb3_gpio") && nvram_match("led_usb3_gpio", "etron")) {
			led_control(LED_USB3, LED_OFF);
			continue;
		}
#endif
		use_gpio = nvram_get_int(led_list[i]);

		if((gpio_pin = use_gpio & 0xff) == 0xff)
			continue;

#if defined(RTCONFIG_RALINK_MT7620)
		if(gpio_pin == 72)	//skip 2g wifi led NOT to be gpio LED
			continue;
#endif

		disable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 0: 1;
		gpio_dir(gpio_pin, GPIO_DIR_OUT);

		/* If WAN RED LED is defined, keep it on until Internet connection ready in router mode. */
		if (!strcmp(led_list[i], "led_wan_red_gpio") && nvram_get_int("sw_mode") == SW_MODE_ROUTER)
			disable = !disable;

		set_gpio(gpio_pin, disable);
#ifdef RTCONFIG_INTERNAL_GOBI	// save setting value
		{ int i; char led[16]; for(i=0; i<LED_ID_MAX; i++) if(gpio_pin == (led_gpio_table[i]&0xff)){snprintf(led, sizeof(led), "led%02d", i); nvram_set_int(led, LED_OFF); break;}}
#endif	/* RTCONFIG_INTERNAL_GOBI */
	}

#if (defined(PLN12) || defined(PLAC56))
	if((gpio_pin = (use_gpio = nvram_get_int("led_pwr_red_gpio")) & 0xff) != 0xff)
#else
	if((gpio_pin = (use_gpio = nvram_get_int("led_pwr_gpio")) & 0xff) != 0xff)
#endif
	{
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
#ifdef RTCONFIG_INTERNAL_GOBI	// save setting value
		{ int i; char led[16]; for(i=0; i<LED_ID_MAX; i++) if(gpio_pin == (led_gpio_table[i]&0xff)){snprintf(led, sizeof(led), "led%02d", i); nvram_set_int(led, LED_ON); break;}}
#endif	/* RTCONFIG_INTERNAL_GOBI */
	}

	// Power of USB.
	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}
	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio2")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}

#if defined(RTCONFIG_RTAC5300) || defined(RTCONFIG_RTAC5300R)
	// RPM of FAN
	if((gpio_pin = (use_gpio = nvram_get_int("rpm_fan_gpio")) & 0xff) != 0xff){
	enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
	set_gpio(gpio_pin, enable);
	}
#endif

#ifdef PLAC56
	if((gpio_pin = (use_gpio = nvram_get_int("plc_wake_gpio")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}
#endif

	// TODO: system dependent initialization
	return 0;
}
Exemplo n.º 19
0
/*
 * set plc_flag nvram for save_plc_setting() function
 *
 * because of plc-utils/plc/plchost.c cannot include bcmnvram.h
 * 	error: conflicting types for 'bool' from
 * 		src-qca/include/typedefs.h
 * 		plc-utils/tools/types.h
 */
void set_plc_flag(int flag)
{
	nvram_set_int("plc_flag", flag);
}
Exemplo n.º 20
0
void start_dsl()
{
	// todo: is it necessary? 
	init_dsl_before_start_wan();
	char *argv_tp_init[] = {"tp_init", NULL};	
	int pid;

	// if setting cfg file is from annex a, annex b will has invalid values
	if(nvram_match("productid", "DSL-N55U-B"))
	{
		if (nvram_get_int("dslx_annex") != 0)
		{
			nvram_set_int("dslx_config_num", 0);
		}
	}
	
	eval("mkdir", "/tmp/adsl");

	// disable out-of-memory process killer
	// this command could not use eval because redirection
	system("echo 2 > /proc/sys/vm/overcommit_memory");
	

#ifdef RTCONFIG_DUALWAN
	if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE)
	{
		if (get_dualwan_primary()!=WANS_DUALWAN_IF_DSL)
		{
			// it does not need to start dsl driver when using other modes
			// but it still need to run tp_init to have firmware version info
			printf("get modem info\n");
			eval("tp_init", "eth_wan_mode_only");			
			return;
		}
	}
#endif

	int config_num = nvram_get_int("dslx_config_num");
	_eval(argv_tp_init, NULL, 0, &pid);
	// IPTV
	if (nvram_match("x_Setting", "1") && config_num > 1)
	{
		int x;
		char wan_if[9];
		char wan_num[2];		
		char buf_ip[32];
		eval("brctl", "addbr", "br1");
		for(x=2; x<=config_num; x++) {
			sprintf(wan_if, "eth2.1.%d", x);
			sprintf(wan_num, "%d", x);
			eval("vconfig", "add", "eth2.1", wan_num);
			eval("ifconfig", wan_if, "up");				
			eval("brctl", "addif", "br1", wan_if);
		}	
		eval("brctl", "addif", "br1", "eth2.3");
		// it needs assign a IPv4 address to enable packet forwarding
		pick_a_random_ipv4(buf_ip);
		eval("ifconfig", "br1", "up");
		eval("ifconfig", "br1", buf_ip);		
	}

	// auto detection
	if (nvram_match("x_Setting", "0") && config_num == 0)
	{
		int x;
		char wan_if[9];
		char wan_num[2];		
		char country_value[8];
		char cmd_buf[64];
		char *argv_auto_det[] = {"auto_det", country_value, NULL};		
		int pid;		
		for(x=2; x<=8; x++) {
			sprintf(wan_if, "eth2.1.%d", x);
			sprintf(wan_num, "%d", x);
			eval("vconfig", "add", "eth2.1", wan_num);
			eval("ifconfig", wan_if, "up");				
		}
		//
		nvram_set("dsltmp_autodet_state", "Detecting");
		// call auto detection with country code
		get_country_code_from_rc(country_value);
		_eval(argv_auto_det, NULL, 0, &pid);
	}
}
Exemplo n.º 21
0
Arquivo: rc.c Projeto: ff94315/rt-n56u
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;
#if defined (BOARD_GPIO_BTN_ROUTER)
	int i_router_switch = BTN_PRESSED;

	if (cpu_gpio_get_pin(BOARD_GPIO_BTN_ROUTER, &i_router_switch) >= 0) {
		if (i_router_switch != BTN_PRESSED)
			nvram_set_int("sw_mode", 3);
	}
#endif

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		sw_mode = 1;
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

#if defined (BOARD_GPIO_LED_ROUTER)
	if (sw_mode != 3)
		LED_CONTROL(BOARD_GPIO_LED_ROUTER, LED_ON);
#endif

#if BOARD_HAS_5G_RADIO
	if (strlen(nvram_wlan_get(1, "ssid")) < 1)
		nvram_wlan_set(1, "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(1, "ssid"));
	nvram_wlan_set(1, "ssid2", buff);

	if (strlen(nvram_wlan_get(1, "wpa_mode")) < 1)
		nvram_wlan_set_int(1, "wpa_mode", 0);

#if BOARD_HAS_5G_11AC
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 4); // a/n/ac Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 2)
		nvram_wlan_set_int(1, "HT_BW", 2);
#else
	if (strlen(nvram_wlan_get(1, "gmode")) < 1)
		nvram_wlan_set_int(1, "gmode", 2); // a/n Mixed

	if (nvram_wlan_get_int(1, "HT_BW") > 1)
		nvram_wlan_set_int(1, "HT_BW", 1);
#endif

	if (nvram_wlan_get_int(1, "stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_wlan_set_int(1, "stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_wlan_get_int(1, "stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_wlan_set_int(1, "stream_rx", BOARD_NUM_ANT_5G_RX);
#endif

	if (strlen(nvram_wlan_get(0, "ssid")) < 1)
		nvram_wlan_set(0, "ssid", DEF_WLAN_2G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get(0, "ssid"));
	nvram_wlan_set(0, "ssid2", buff);

	if (strlen(nvram_wlan_get(0, "gmode")) < 1)
		nvram_wlan_set_int(0, "gmode", 2); // b/g/n Mixed

	if (nvram_wlan_get_int(0, "HT_BW") > 1)
		nvram_wlan_set_int(0, "HT_BW", 1);

	if (nvram_wlan_get_int(0, "stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_wlan_set_int(0, "stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_wlan_get_int(0, "stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_wlan_set_int(0, "stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("vpnc_dom_t", "");
	nvram_set_temp("viptv_ifname", "");

	nvram_set_temp(RSTATS_NVKEY_24, (sw_mode != 3) ? IFDESC_WAN : IFDESC_LAN);
	nvram_set_temp(RSTATS_NVKEY_DM, IFDESC_WAN);

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
Exemplo n.º 22
0
void
start_httpd(int restart_fw)
{
	int http_proto, argv_index, http_port, restart_fw_need;
	char http_port_s[8];
#if defined (SUPPORT_HTTPS)
	char https_port_s[8];
#endif
	char *httpd_argv[] = {
		"/usr/sbin/httpd",
		NULL, NULL,
		NULL, NULL,
		NULL,
	};

	argv_index = 1;
	http_port = 0;
	restart_fw_need = 0;

#if defined (SUPPORT_HTTPS)
	http_proto = nvram_get_int("http_proto");
#else
	http_proto = 0;
#endif
	if (http_proto == 0 || http_proto == 2) {

		http_port = nvram_get_int("http_lanport");
		if (http_port < 80 || http_port > 65535) {
			http_port = 80;
			nvram_set_int("http_lanport", http_port);
		}
		
		sprintf(http_port_s, "%d", http_port);
		
		httpd_argv[argv_index++] = "-p";
		httpd_argv[argv_index++] = http_port_s;
		
		restart_fw_need |= nvram_get_int("misc_http_x");
	}

#if defined (SUPPORT_HTTPS)
	if (http_proto == 1 || http_proto == 2) {
		int https_port = nvram_get_int("https_lport");
		if (https_port < 81 || https_port > 65535 || https_port == http_port) {
			https_port = 443;
			nvram_set_int("https_lport", https_port);
		}
		
		sprintf(https_port_s, "%d", https_port);
		
		httpd_argv[argv_index++] = "-s";
		httpd_argv[argv_index++] = https_port_s;
		
		restart_fw_need |= nvram_get_int("https_wopen");
	}
#endif

	_eval(httpd_argv, NULL, 0, NULL);

	if (restart_fw && restart_fw_need && nvram_match("fw_enable_x", "1"))
		restart_firewall();
}
Exemplo n.º 23
0
void
erase_nvram(void)
{
	nvram_set_int("restore_defaults", 1);
	nvram_commit();
}
Exemplo n.º 24
0
static void
nvram_convert_misc_values(void)
{
	char buff[64];
	int sw_mode;

	/* check router mode */
	sw_mode = nvram_get_int("sw_mode");
	if (sw_mode == 1) {
		/* Internet gateway mode */
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 4) {
		/* Pure router mode */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Routed");
	} else if (sw_mode == 3) {
		/* AP mode (Ethernet convertor) */
		nvram_set_int("wan_nat_x", 0);
		nvram_set("wan_route_x", "IP_Bridged");
	} else {
		nvram_set_int("sw_mode", 1);
		nvram_set_int("wan_nat_x", 1);
		nvram_set("wan_route_x", "IP_Routed");
	}

	if (strlen(nvram_wlan_get("wl", "ssid")) < 1)
		nvram_wlan_set("wl", "ssid", DEF_WLAN_5G_SSID);

	if (strlen(nvram_wlan_get("rt", "ssid")) < 1)
		nvram_wlan_set("rt", "ssid", DEF_WLAN_5G_SSID);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("wl", "ssid"));
	nvram_wlan_set("wl", "ssid2", buff);

	memset(buff, 0, sizeof(buff));
	char_to_ascii(buff, nvram_wlan_get("rt", "ssid"));
	nvram_wlan_set("rt", "ssid2", buff);

	if (strlen(nvram_safe_get("wl_wpa_mode")) < 1)
		nvram_set_int("wl_wpa_mode", 0);

	if (strlen(nvram_safe_get("wl_gmode")) < 1)
		nvram_set_int("wl_gmode", 2); // a/n Mixed

	if (strlen(nvram_safe_get("rt_gmode")) < 1)
		nvram_set_int("rt_gmode", 2); // b/g/n Mixed

	if (nvram_get_int("wl_HT_BW") > 1)
		nvram_set_int("wl_HT_BW", 1);

	if (nvram_get_int("rt_HT_BW") > 1)
		nvram_set_int("rt_HT_BW", 1);

	if (nvram_get_int("wl_stream_tx") > BOARD_NUM_ANT_5G_TX)
		nvram_set_int("wl_stream_tx", BOARD_NUM_ANT_5G_TX);

	if (nvram_get_int("wl_stream_rx") > BOARD_NUM_ANT_5G_RX)
		nvram_set_int("wl_stream_rx", BOARD_NUM_ANT_5G_RX);

	if (nvram_get_int("rt_stream_tx") > BOARD_NUM_ANT_2G_TX)
		nvram_set_int("rt_stream_tx", BOARD_NUM_ANT_2G_TX);

	if (nvram_get_int("rt_stream_rx") > BOARD_NUM_ANT_2G_RX)
		nvram_set_int("rt_stream_rx", BOARD_NUM_ANT_2G_RX);

	nvram_set_temp("ntpc_counter", "0000000000");
	nvram_set_temp("login_timestamp", "0000000000");

	nvram_set_int_temp("networkmap_fullscan", 0);
	nvram_set_int_temp("link_internet", 2);
	nvram_set_int_temp("link_wan", 0);

	nvram_set_int_temp("reload_svc_wl", 0);
	nvram_set_int_temp("reload_svc_rt", 0);

	nvram_set_int_temp("usb_hotplug_ms", 0);
	nvram_set_int_temp("usb_hotplug_lp", 0);
	nvram_set_int_temp("usb_hotplug_md", 0);
	nvram_set_int_temp("usb_unplug_lp", 0);
	nvram_set_int_temp("usb_unplug_md", 0);
	nvram_set_int_temp("usb_opt_start", 0);

	nvram_set_int_temp("l2tp_wan_t", 0);
	nvram_set_int_temp("l2tp_cli_t", 0);
	nvram_set_int_temp("l2tp_srv_t", 0);
	nvram_set_int_temp("vpnc_state_t", 0);
	nvram_set_temp("deferred_wanup_t", "0000000000");
	nvram_set_temp("vpnc_dns_t", "");
	nvram_set_temp("viptv_ifname", "");

	/* setup wan0 variables */
	set_wan0_vars();
	set_wan_unit_value(0, "uptime", "0000000000");
	set_wan_unit_value(0, "dltime", "0000000000");
	set_wan_unit_value(0, "bytes_rx", "00000000000000000000");
	set_wan_unit_value(0, "bytes_tx", "00000000000000000000");
	set_wan_unit_value(0, "ifname_t", "");
	set_usb_modem_dev_wan(0, 0);
	reset_wan_vars();

	/* setup lan variables */
	reset_lan_vars();
	reset_lan_temp();

	time_zone_x_mapping();
}
Exemplo n.º 25
0
void notify_watchdog_wifi(int is_5ghz)
{
	int wd_notify_id = (is_5ghz) ? WD_NOTIFY_ID_WIFI5 : WD_NOTIFY_ID_WIFI2;
	nvram_set_int("wd_notify_id", wd_notify_id);
	doSystem("killall %s %s", "-SIGUSR1", "watchdog");
}
Exemplo n.º 26
0
/*
 * Called when link comes up
 */
int
ipup_main(int argc, char **argv)
{
	FILE *fp;
	char *wan_ifname = safe_getenv("IFNAME");
	char *wan_linkname = safe_getenv("LINKNAME");
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	char buf[256], *value;
	int unit;

	_dprintf("%s():: %s\n", __FUNCTION__, argv[0]);

	/* Get unit from LINKNAME: ppp[UNIT] */
	if ((unit = ppp_linkunit(wan_linkname)) < 0)
		return 0;

	_dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname);
	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	/* Stop triggering demand connection */
	if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp)))
		nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1);

#ifdef RTCONFIG_USB_MODEM
	// wanX_ifname is used for device for USB Modem
	if ((value = getenv("DEVICE")) &&
	    (isSerialNode(value) || isACMNode(value)))
		nvram_set(strcat_r(prefix, "ifname", tmp), value);
#endif

	/* Touch connection file */
	if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) {
		perror(tmp);
		return errno;
	}
	fclose(fp);

	if ((value = getenv("IPLOCAL"))) {
		if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value))
			ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
		_ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE"));
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
		nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255");
	}

	if ((value = getenv("IPREMOTE")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);

	strcpy(buf, "");
	if ((value = getenv("DNS1")))
		sprintf(buf, "%s", value);
	if ((value = getenv("DNS2")))
		sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value);

	/* empty DNS means they either were not requested or peer refused to send them.
	 * lift up underlying xdns value instead, keeping "dns" filled */
	if (strlen(buf) == 0)
		sprintf(buf, "%s", nvram_safe_get(strcat_r(prefix, "xdns", tmp)));

	nvram_set(strcat_r(prefix, "dns", tmp), buf);

	wan_up(wan_ifname);

	_dprintf("%s:: done\n", __FUNCTION__);
	return 0;
}
Exemplo n.º 27
0
int del_account(const char *const account) {
	disk_info_t *disk_list, *follow_disk;
	partition_info_t *follow_partition;
	int acc_num = 0, target;
	char **account_list = NULL;
	int result, i;
	char nvram_name[16], nvram_value[128];
	char var_file[256];
	
	if (account == NULL || strlen(account) <= 0) {
		return -1;
	}
	
	// 1. check if can create the account
	get_account_list(&acc_num, &account_list);
	if (acc_num <= 0)
		return -1;
	
	result = 0;
	for (i = 0; i < acc_num; ++i)
		if (!strcmp(account_list[i], account)) {
			result = 1;
			target = i;
			break;
		}
	if (result == 0) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	// 2. delete the nvram value about the deleted account
	--acc_num;
	nvram_set_int("acc_num", acc_num);
	
	for (i = target; i < acc_num; ++i) {
		sprintf(nvram_name, "acc_username%d", i);
		nvram_set(nvram_name, account_list[i+1]);
		
		sprintf(nvram_value, "acc_password%d", i+1);
		
		sprintf(nvram_name, "acc_password%d", i);
		nvram_set(nvram_name, nvram_safe_get(nvram_value));
	}
	
	// 3. change to the share mode when no account
	if (acc_num < 1) {
		int i_mode;
		
		i_mode = nvram_get_int("st_samba_mode");
		if (i_mode != 1 && i_mode != 3)
			nvram_set_int("st_samba_mode", 1);
		
		i_mode = nvram_get_int("st_ftp_mode");
		if (i_mode != 1 && i_mode != 3)
			nvram_set_int("st_ftp_mode", 1);
	}
	
	nvram_commit_safe();
	
	free_2_dimension_list(&acc_num, &account_list);
	
	// 4. find every pool
	disk_list = read_disk_data();
	if (!disk_list)
		return 0;
	
	for (follow_disk = disk_list; follow_disk != NULL; follow_disk = follow_disk->next) {
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			if (follow_partition->mount_point == NULL)
				continue;
			
			// 5. delete the var file of the deleted account
			snprintf(var_file, sizeof(var_file), "%s/.__%s_var.txt", follow_partition->mount_point, account);
			
			unlink(var_file);
		}
	}
	free_disk_data(disk_list);
	
	// 6. re-run ftp and samba
	system("/sbin/run_ftpsamba");
	
	return 0;
}
Exemplo n.º 28
0
void start_dsl()
{
	// todo: is it necessary? 
	init_dsl_before_start_wan();
	char *argv_tp_init[] = {"tp_init", NULL};	
	int pid;

	// if setting cfg file is from annex a, annex b will has invalid values
	if(nvram_match("productid", "DSL-N55U-B"))
	{
		if (nvram_get_int("dslx_annex") != 0)
		{
			nvram_set_int("dslx_annex", 0); //Paul add 2012/8/22, for Annex B model should always be 0
			nvram_set_int("dslx_config_num", 0);
		}
	}
	
	eval("mkdir", "/tmp/adsl");

	/* Paul comment 2012/7/25, the "never overcommit" policy would cause Ralink WiFi driver kernel panic when configure DUT through external registrar. *
	 * So let this value be the default which is 0, the kernel will estimate the amount of free memory left when userspace requests more memory. */
	//system("echo 2 > /proc/sys/vm/overcommit_memory");
	

#ifdef RTCONFIG_DUALWAN
	if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE)
	{
		if (get_dualwan_primary()!=WANS_DUALWAN_IF_DSL)
		{
			// it does not need to start dsl driver when using other modes
			// but it still need to run tp_init to have firmware version info
			printf("get modem info\n");
			eval("tp_init", "eth_wan_mode_only");			
			return;
		}
	}
#endif

	int config_num = nvram_get_int("dslx_config_num");
	_eval(argv_tp_init, NULL, 0, &pid);
	// IPTV
	if (nvram_match("x_Setting", "1") && config_num > 1)
	{
		int x;
		char wan_if[9];
		char wan_num[2];		
		char buf_ip[32];
		eval("brctl", "addbr", "br1");
		for(x=2; x<=config_num; x++) {
			sprintf(wan_if, "eth2.1.%d", x);
			sprintf(wan_num, "%d", x);
			eval("vconfig", "add", "eth2.1", wan_num);
			eval("ifconfig", wan_if, "up");				
			eval("brctl", "addif", "br1", wan_if);
		}	
		eval("brctl", "addif", "br1", "eth2.3");
		// it needs assign a IPv4 address to enable packet forwarding
		pick_a_random_ipv4(buf_ip);
		eval("ifconfig", "br1", "up");
		eval("ifconfig", "br1", buf_ip);		
	}

	// auto detection
	if (nvram_match("x_Setting", "0") && config_num == 0)
	{
		int x;
		char wan_if[9];
		char wan_num[2];		
		char country_value[8];
		char cmd_buf[64];
		char *argv_auto_det[] = {"auto_det", country_value, NULL};		
		int pid;		
		for(x=2; x<=8; x++) {
			sprintf(wan_if, "eth2.1.%d", x);
			sprintf(wan_num, "%d", x);
			eval("vconfig", "add", "eth2.1", wan_num);
			eval("ifconfig", wan_if, "up");				
		}
		//
		nvram_set("dsltmp_autodet_state", "Detecting");
		// call auto detection with country code
		get_country_code_from_rc(country_value);
		_eval(argv_auto_det, NULL, 0, &pid);
	}
}
Exemplo n.º 29
0
void convert_dsl_wan()
{
	int conv_dsl_to_wan0 = 0;
	int conv_dsl_to_wan1 = 0;

#ifdef RTCONFIG_DUALWAN
	if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL)
	{
		conv_dsl_to_wan0 = 1;
	}

	if (get_dualwan_secondary()==WANS_DUALWAN_IF_DSL)
	{
		conv_dsl_to_wan1 = 1;
	}	
#else
	conv_dsl_to_wan0 = 1;
#endif

	if (conv_dsl_to_wan0)
	{
		nvram_set("wan_nat_x",nvram_safe_get("dslx_nat"));
		nvram_set("wan_upnp_enable",nvram_safe_get("dslx_upnp_enable"));	
		nvram_set("wan_enable",nvram_safe_get("dslx_link_enable")); 
		nvram_set("wan_dhcpenable_x",nvram_safe_get("dslx_DHCPClient"));	
		nvram_set("wan_ipaddr_x",nvram_safe_get("dslx_ipaddr"));	
		nvram_set("wan_upnp_enable",nvram_safe_get("dslx_upnp_enable"));		
		nvram_set("wan_netmask_x",nvram_safe_get("dslx_netmask"));		
		nvram_set("wan_gateway_x",nvram_safe_get("dslx_gateway"));		
		nvram_set("wan_dnsenable_x",nvram_safe_get("dslx_dnsenable"));		
		nvram_set("wan_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan_dns2_x",nvram_safe_get("dslx_dns2"));			
		nvram_set("wan_pppoe_username",nvram_safe_get("dslx_pppoe_username"));			
		nvram_set("wan_pppoe_passwd",nvram_safe_get("dslx_pppoe_passwd"));				
		nvram_set("wan_pppoe_idletime",nvram_safe_get("dslx_pppoe_idletime"));			
		nvram_set("wan_pppoe_mtu",nvram_safe_get("dslx_pppoe_mtu"));				
		nvram_set("wan_pppoe_mru",nvram_safe_get("dslx_pppoe_mtu"));			
		nvram_set("wan_pppoe_service",nvram_safe_get("dslx_pppoe_service"));				
		nvram_set("wan_pppoe_ac",nvram_safe_get("dslx_pppoe_ac"));				
		nvram_set("wan_pppoe_options_x",nvram_safe_get("dslx_pppoe_options"));			
//		nvram_set("wan_pppoe_relay",nvram_safe_get("dslx_pppoe_relay"));				
		nvram_set("wan_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan_dns1_x",nvram_safe_get("dslx_dns1"));				
	}

	if (conv_dsl_to_wan0)
	{
		nvram_set("wan0_nat_x",nvram_safe_get("dslx_nat"));
		nvram_set("wan0_upnp_enable",nvram_safe_get("dslx_upnp_enable"));	
		nvram_set("wan0_enable",nvram_safe_get("dslx_link_enable"));	
		nvram_set("wan0_dhcpenable_x",nvram_safe_get("dslx_DHCPClient"));	
		nvram_set("wan0_ipaddr_x",nvram_safe_get("dslx_ipaddr"));	
		nvram_set("wan0_upnp_enable",nvram_safe_get("dslx_upnp_enable"));		
		nvram_set("wan0_netmask_x",nvram_safe_get("dslx_netmask")); 	
		nvram_set("wan0_gateway_x",nvram_safe_get("dslx_gateway")); 	
		nvram_set("wan0_dnsenable_x",nvram_safe_get("dslx_dnsenable")); 	
		nvram_set("wan0_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan0_dns2_x",nvram_safe_get("dslx_dns2"));			
		nvram_set("wan0_pppoe_username",nvram_safe_get("dslx_pppoe_username")); 		
		nvram_set("wan0_pppoe_passwd",nvram_safe_get("dslx_pppoe_passwd")); 			
		nvram_set("wan0_pppoe_idletime",nvram_safe_get("dslx_pppoe_idletime")); 		
		nvram_set("wan0_pppoe_mtu",nvram_safe_get("dslx_pppoe_mtu"));				
		nvram_set("wan0_pppoe_mru",nvram_safe_get("dslx_pppoe_mtu"));			
		nvram_set("wan0_pppoe_service",nvram_safe_get("dslx_pppoe_service"));				
		nvram_set("wan0_pppoe_ac",nvram_safe_get("dslx_pppoe_ac")); 			
		nvram_set("wan0_pppoe_options_x",nvram_safe_get("dslx_pppoe_options")); 		
//		nvram_set("wan0_pppoe_relay",nvram_safe_get("dslx_pppoe_relay"));				
		nvram_set("wan0_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan0_dns1_x",nvram_safe_get("dslx_dns1"));				
		nvram_set("wan0_hwaddr_x",nvram_safe_get("dslx_hwaddr"));					
	}

	if (conv_dsl_to_wan1)
	{
		nvram_set("wan1_nat_x",nvram_safe_get("dslx_nat"));
		nvram_set("wan1_upnp_enable",nvram_safe_get("dslx_upnp_enable"));	
		nvram_set("wan1_enable",nvram_safe_get("dslx_link_enable"));	
		nvram_set("wan1_dhcpenable_x",nvram_safe_get("dslx_DHCPClient"));	
		nvram_set("wan1_ipaddr_x",nvram_safe_get("dslx_ipaddr"));	
		nvram_set("wan1_upnp_enable",nvram_safe_get("dslx_upnp_enable"));		
		nvram_set("wan1_netmask_x",nvram_safe_get("dslx_netmask")); 	
		nvram_set("wan1_gateway_x",nvram_safe_get("dslx_gateway")); 	
		nvram_set("wan1_dnsenable_x",nvram_safe_get("dslx_dnsenable")); 	
		nvram_set("wan1_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan1_dns2_x",nvram_safe_get("dslx_dns2"));			
		nvram_set("wan1_pppoe_username",nvram_safe_get("dslx_pppoe_username")); 		
		nvram_set("wan1_pppoe_passwd",nvram_safe_get("dslx_pppoe_passwd")); 			
		nvram_set("wan1_pppoe_idletime",nvram_safe_get("dslx_pppoe_idletime")); 		
		nvram_set("wan1_pppoe_mtu",nvram_safe_get("dslx_pppoe_mtu"));				
		nvram_set("wan1_pppoe_mru",nvram_safe_get("dslx_pppoe_mtu"));			
		nvram_set("wan1_pppoe_service",nvram_safe_get("dslx_pppoe_service"));				
		nvram_set("wan1_pppoe_ac",nvram_safe_get("dslx_pppoe_ac")); 			
		nvram_set("wan1_pppoe_options_x",nvram_safe_get("dslx_pppoe_options")); 		
//		nvram_set("wan1_pppoe_relay",nvram_safe_get("dslx_pppoe_relay"));				
		nvram_set("wan1_dns1_x",nvram_safe_get("dslx_dns1"));			
		nvram_set("wan1_dns1_x",nvram_safe_get("dslx_dns1"));				
		nvram_set("wan1_hwaddr_x",nvram_safe_get("dslx_hwaddr"));					
	}
	

	if (conv_dsl_to_wan0)
	{
		if (nvram_match("dsl0_proto","pppoe") || nvram_match("dsl0_proto","pppoa")) {
			nvram_set("wan0_proto","pppoe");
			/* Turn off DHCP on MAN interface */
			nvram_set_int("wan0_dhcpenable_x", 2);
		}
		else if (nvram_match("dsl0_proto","ipoa")) {
			nvram_set("wan0_proto","static");
		}
		else if (nvram_match("dsl0_proto","bridge")) {
			// disable nat
			nvram_set("wan0_nat_x","0");

			/* Paul add 2012/7/13, for Bridge connection type wan0_proto set to dhcp, and dsl_proto set as bridge */
			nvram_set("wan0_proto","dhcp");
			nvram_set("dsl_proto","bridge");
		}
		else if (nvram_match("dsl0_proto","mer")) {
			if (nvram_match("dslx_DHCPClient","1")) {
				nvram_set("wan0_proto","dhcp");
			}
			else {
				nvram_set("wan0_proto","static");		
			}
		}
	}

	if (conv_dsl_to_wan1)
	{
		if (nvram_match("dsl0_proto","pppoe") || nvram_match("dsl0_proto","pppoa")) {
			nvram_set("wan1_proto","pppoe");
			/* Turn off DHCP on MAN interface */
			nvram_set_int("wan1_dhcpenable_x", 2);
		}
		else if (nvram_match("dsl0_proto","ipoa")) {
			nvram_set("wan1_proto","static");
		}
		else if (nvram_match("dsl0_proto","bridge")) {
			// disable nat
			nvram_set("wan1_nat_x","0");		

			/* Paul add 2012/7/13, for Bridge connection type wan0_proto set to dhcp, and dsl_proto set as bridge */
			nvram_set("wan1_proto","dhcp");
			nvram_set("dsl_proto","bridge");
		}
		else if (nvram_match("dsl0_proto","mer")) {
			if (nvram_match("dslx_DHCPClient","1")) {
				nvram_set("wan1_proto","dhcp");
			}
			else {
				nvram_set("wan1_proto","static");		
			}
		}
	}
	

	if (conv_dsl_to_wan0)
	{
		nvram_set("wan_proto",nvram_safe_get("wan0_proto"));
	}	

}
Exemplo n.º 30
0
int add_account(const char *const account, const char *const password) {
	disk_info_t *disk_list, *follow_disk;
	partition_info_t *follow_partition;
	int i, acc_num = 0;
	char **account_list = NULL;
	char nvram_name[32];
	
	if (account == NULL || strlen(account) <= 0) {
		return -1;
	}
	if (password == NULL || strlen(password) <= 0) {
		return -1;
	}
	
	// 1. check if can create the account
	get_account_list(&acc_num, &account_list);
	if (acc_num >= MAX_ACCOUNT_NUM) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	for (i = 0; i < acc_num; ++i)
		if (!strcmp(account, account_list[i])) {
			free_2_dimension_list(&acc_num, &account_list);
			return -1;
		}
	
	if (!strcmp(account, FTP_ANONYMOUS_USER)) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	// 2. create nvram value about the new account
	nvram_set_int("acc_num", acc_num+1);
	
	sprintf(nvram_name, "acc_username%d", acc_num);
	nvram_set(nvram_name, account);
	
	sprintf(nvram_name, "acc_password%d", acc_num);
	nvram_set(nvram_name, password);
	
	nvram_commit_safe();
	
	free_2_dimension_list(&acc_num, &account_list);
	
	// 3. find every pool
	disk_list = read_disk_data();
	if (!disk_list)
		return 0;
	
	for (follow_disk = disk_list; follow_disk != NULL; follow_disk = follow_disk->next) {			
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			if (follow_partition->mount_point == NULL)
				continue;
			
			// 4. initial the var file of the account
			initial_one_var_file_in_mount_path(account, follow_partition->mount_point);
		}
	}
	free_disk_data(disk_list);
	
	// 6. re-run samba
	system("/sbin/run_samba");
	
	return 0;
}