Beispiel #1
0
// only ralink solution can reload it dynamically
void reinit_hwnat()
{
	// only happened when hwnat=1
	// only loaded when unloaded, and unloaded when loaded
	// in restart_firewall for fw_pt_l2tp/fw_pt_ipsec
	// in restart_qos for qos_enable
	// in restart_wireless for wlx_mrate_x
	
	if (nvram_get_int("hwnat")) {
		if (is_nat_enabled() && !nvram_get_int("qos_enable") /*&&*/
			/* TODO: consider RTCONFIG_DUALWAN case */
//			!nvram_match("wan0_proto", "l2tp") &&
//			!nvram_match("wan0_proto", "pptp") &&
			/*(nvram_match("wl0_radio", "0") || !nvram_get_int("wl0_mrate_x")) &&
			(nvram_match("wl1_radio", "0") || !nvram_get_int("wl1_mrate_x"))*/) {
			if (!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);
			}
		}	
		else 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
		}
	}
}
Beispiel #2
0
void init_wl(void)
{
	if (!is_module_loaded("rt2860v2_ap"))
		modprobe("rt2860v2_ap");
#if defined (RTCONFIG_WLMODULE_RT3090_AP)
	if (!is_module_loaded("RTPCI_ap"))
	{
		modprobe("RTPCI_ap");
	}
#endif
#if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII)
	if (!is_module_loaded("iNIC_mii"))
		modprobe("iNIC_mii", "mode=ap", "bridge=1", "miimaster=eth2", "syncmiimac=0");	// set iNIC mac address from eeprom need insmod with "syncmiimac=0"
#endif

	sleep(1);
}
Beispiel #3
0
int scsi_add(void)
{
	char scsi_file[256];
	char scsi_type[50];
	int type;
	char *devpath;
	char *module = NULL;
	int i;
	int fd;
	int len;
	int retval = 1;
	
	devpath = getenv("DEVPATH");
	if (!devpath) {
		dbg("missing DEVPATH environment variable, aborting.");
		goto exit;
	}

	snprintf(scsi_file, sizeof(scsi_file), "/sys%s/type", devpath);
	for (i = 0; i < 10; ++i) {
		struct stat stats;
		if (stat(scsi_file, &stats) == 0)
			break;
		sleep(1);
	}
	fd = open(scsi_file, O_RDONLY);
	if (fd < 0) {
		dbg("can't open file '%s'", scsi_file);
		goto exit;
	}
	len = read(fd, scsi_type, sizeof(scsi_type));
	if (len < 0) {
		dbg("can't open file '%s'", scsi_file);
		goto exit_close;
	}

	dbg("read '%s' from '%s'", scsi_type, scsi_file);
	type = atoi(scsi_type);
	dbg("type = %d", type);
	switch (type) {
	case 0:
	case 7: module = "sd_mod";	break;
	case 1: module = "st";		break;
	case 4:
	case 5: module = "sr_mod";	break;
	}

	if (module)
		retval = modprobe(module, true);
	else
		retval = 0;
	
exit_close:
	close(fd);
exit:
	return retval;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	const char *src, *node, *opts;
	char *rsrc = NULL;
	char *popts = NULL;
	int flags = 0;
	int retval = 0;

	retval = parse_arguments(argc, argv, &src, &node, &opts);
	if (retval) {
		usage(argv[0]);
		exit((retval > 0) ? EXIT_SUCCESS : EXIT_FAILURE);
	}

	rsrc = mount_resolve_src(src);
	if (!rsrc) {
		printf("failed to resolve source\n");
		exit(1);
	}

	modprobe();

	popts = parse_options(opts, &flags);
	if (!popts) {
		printf("failed to parse ceph_options\n");
		exit(1);
	}

	block_signals(SIG_BLOCK);

	if (mount(rsrc, node, "ceph", flags, popts)) {
		retval = errno;
		switch (errno) {
		case ENODEV:
			printf("mount error: ceph filesystem not supported by the system\n");
			break;
		default:
			printf("mount error %d = %s\n",errno,strerror(errno));
		}
	} else {
		if (!skip_mtab_flag) {
			update_mtab_entry(rsrc, node, "ceph", popts, flags, 0, 0);
		}
	}

	block_signals(SIG_UNBLOCK);

	free(popts);
	free(rsrc);
	exit(retval);
}
Beispiel #5
0
void format_mount_2nd_jffs2(void)
{
        int format = 0;
        char s[256];
        int size;
        int part;
        const char *p;

        if (!wait_action_idle(10)) return;

        if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) return;
	_dprintf("Format 2nd jffs2: %d, %d\n", part, size);

	if(!check_in_rootfs(SECOND_JFFS2_PATH, "2nd_jffs", format))
		return;

        if (!mtd_unlock(SECOND_JFFS2_PARTITION)) {
                error("unlocking");
                return;
        }

        modprobe(JFFS_NAME);
        sprintf(s, MTD_BLKDEV(%d), part);
        if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) {
		if( (get_model()==MODEL_RTAC56U || get_model()==MODEL_RTAC56S || get_model()==MODEL_RTAC3200 || get_model()==MODEL_RTAC68U || get_model()==MODEL_RPAC68U || get_model()==MODEL_DSLAC68U || get_model()==MODEL_RTAC87U || get_model()==MODEL_RTAC88U || get_model()==MODEL_RTAC3100 || get_model()==MODEL_RTAC5300 || get_model==MODEL_RTAC5300R || get_model()==MODEL_RTN18U || get_model()==MODEL_RTAC1200G || get_model()==MODEL_RTAC1200GP) ^ (mtd_erase(SECOND_JFFS2_PARTITION)) ){
                        error("formatting");
                        return;
                }

                format = 1;
                if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) {
                        _dprintf("*** jffs2 2-nd mount error\n");
                        //modprobe_r(JFFS_NAME);
                        error("mounting");
                        return;
                }
        }

	sprintf(s, "rm -rf %s/*", SECOND_JFFS2_PATH);
        system(s);

        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");

        if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) {
                chdir(SECOND_JFFS2_PATH);
                system(p);
                chdir("/");
        }
        run_userfile(SECOND_JFFS2_PATH, ".asusrouter", SECOND_JFFS2_PATH, 3);

}
Beispiel #6
0
/*
 * The kernel expects the DLM control daemon (in this case FakeDLM) to keep
 * DLM_MONITOR_PATH open while it is running.  This allows to detect when the
 * control daemon dies unexpectedly.
 */
static void
monitor_kernel(void)
{
	kernel_monitor_fd = open_udev_device(DLM_MONITOR_PATH, O_RDONLY, 0);
	if (kernel_monitor_fd != -1)
		return;
	if (access(CONFIG_DLM, X_OK) == -1) {
		modprobe("dlm");
		if (access(CONFIG_DLM, X_OK) == -1)
			fail(CONFIG_DLM);
	}
	kernel_monitor_fd = open_udev_device(DLM_MONITOR_PATH, O_RDONLY, 5000000);
	if (kernel_monitor_fd == -1)
		fail(DLM_MONITOR_PATH);
}
Beispiel #7
0
// only ralink solution can reload it dynamically
void reinit_hwnat()
{
	// only happened when hwnat=1
	// only loaded when unloaded, and unloaded when loaded
	// in restart_firewall for fw_pt_l2tp/fw_pt_ipsec
	// in restart_qos for qos_enable
	// in restart_wireless for wlx_mrate_x
	
	if (nvram_get_int("hwnat")) {
		if (is_nat_enabled() && !nvram_get_int("qos_enable") /*&&*/
			/* TODO: consider RTCONFIG_DUALWAN case */
//			!nvram_match("wan0_proto", "l2tp") &&
//			!nvram_match("wan0_proto", "pptp") &&
			/*(nvram_match("wl0_radio", "0") || !nvram_get_int("wl0_mrate_x")) &&
			(nvram_match("wl1_radio", "0") || !nvram_get_int("wl1_mrate_x"))*/) {

#if !defined(RTCONFIG_DUALWAN)
#if defined(RTN65U) || defined(RTN56U)
			char primary[] = "wan1_primaryXXXXXX";

			sprintf(primary, "wan%d_primary", WAN_UNIT_SECOND);
			if (nvram_match(primary, "1")) {
				_dprintf("%s: don't install hardware NAT driver if 3G is enabled!\n", __func__);
				return;
			}
#endif
#endif

			if (!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);
			}
		}	
		else 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
		}
	}
}
Beispiel #8
0
void mount_2nd_jffs2(void)
{
        int format = 0;
        char s[256];
        int size;
        int part;
	int i = 0;

	_dprintf("Mount 2nd jffs2...\n");
	while(1) {
        	if (wait_action_idle(10)) break;
		else i++;

		if(i>=10) {
			_dprintf("Mount 2nd jffs2 failed!");
			return;
		}
	}

        if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) {
		_dprintf("Can not get 2nd jffs2 information!");
		return;
	}
	_dprintf("2nd jffs2: %d, %d\n", part, size);

	if(!check_in_rootfs(SECOND_JFFS2_PATH, "2nd_jffs", format))
		return;

        modprobe(JFFS_NAME);
        sprintf(s, MTD_BLKDEV(%d), part);

	i = 0;
        while(mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_RDONLY, "") != 0) {
		_dprintf("Mount 2nd jffs failed! Try again...\n");
		if(i >= 10) {
			_dprintf("Mount 2nd jffs 10 times failed, stop mount!");
			break;
		}
		i++;
        }

	return;
}
Beispiel #9
0
void init_devs(void)
{
#define MKNOD(name,mode,dev)	if(mknod(name,mode,dev)) perror("## mknod " name)

#if defined(LINUX30) && !defined(RTN14U) && !defined(RTAC52U)
	/* Below device node are used by proprietary driver.
	 * Thus, we cannot use GPL-only symbol to create/remove device node dynamically.
	 */
	MKNOD("/dev/swnat0", S_IFCHR | 0x666, makedev(210, 0));
	MKNOD("/dev/hwnat0", S_IFCHR | 0x666, makedev(220, 0));
	MKNOD("/dev/acl0", S_IFCHR | 0x666, makedev(230, 0));
	MKNOD("/dev/ac0", S_IFCHR | 0x666, makedev(240, 0));
	MKNOD("/dev/mtr0", S_IFCHR | 0x666, makedev(250, 0));
	MKNOD("/dev/rtkswitch", S_IFCHR | 0x666, makedev(206, 0));
	MKNOD("/dev/nvram", S_IFCHR | 0x666, makedev(228, 0));
#else
	MKNOD("/dev/video0", S_IFCHR | 0x666, makedev(81, 0));
#if !defined(RTN14U) && !defined(RTAC52U)
	MKNOD("/dev/rtkswitch", S_IFCHR | 0x666, makedev(206, 0));
#endif
	MKNOD("/dev/spiS0", S_IFCHR | 0x666, makedev(217, 0));
	MKNOD("/dev/i2cM0", S_IFCHR | 0x666, makedev(218, 0));
#if defined(RTN14U) || defined(RTAC52U)
#else
	MKNOD("/dev/rdm0", S_IFCHR | 0x666, makedev(254, 0));
#endif
	MKNOD("/dev/flash0", S_IFCHR | 0x666, makedev(200, 0));
	MKNOD("/dev/swnat0", S_IFCHR | 0x666, makedev(210, 0));
	MKNOD("/dev/hwnat0", S_IFCHR | 0x666, makedev(220, 0));
	MKNOD("/dev/acl0", S_IFCHR | 0x666, makedev(230, 0));
	MKNOD("/dev/ac0", S_IFCHR | 0x666, makedev(240, 0));
	MKNOD("/dev/mtr0", S_IFCHR | 0x666, makedev(250, 0));
	MKNOD("/dev/gpio0", S_IFCHR | 0x666, makedev(252, 0));
	MKNOD("/dev/nvram", S_IFCHR | 0x666, makedev(228, 0));
	MKNOD("/dev/PCM", S_IFCHR | 0x666, makedev(233, 0));
	MKNOD("/dev/I2S", S_IFCHR | 0x666, makedev(234, 0));
#endif
	{
		int status;
		if((status = WEXITSTATUS(modprobe("nvram_linux"))))	printf("## modprove(nvram_linux) fail status(%d)\n", status);
	}
}
Beispiel #10
0
/* Internal function for testing if a filesystem is available.  Note
 * this must not call reply_with_error functions.
 */
int
filesystem_available (const char *filesystem)
{
  int r;

  r = test_proc_filesystems (filesystem);
  if (r == -1 || r > 0)
    return r;

  /* Not found: try to modprobe the module, then test again. */
  if (optgroup_linuxmodules_available ()) {
    modprobe (filesystem);

    r = test_proc_filesystems (filesystem);
    if (r == -1)
      return -1;
  }

  return r;
}
Beispiel #11
0
int ieee1394_add(void)
{
	char ieee1394_string[256];
	char *vendor_env;
	char *model_env;
	char *specifier_env;
	char *version_env;
	int error;
	unsigned long vendor;
	unsigned long model;
	unsigned long specifier;
	unsigned long version;

	vendor_env = getenv("VENDOR_ID");
	model_env = getenv("MODEL_ID");
	specifier_env = getenv("SPECIFIER_ID");
	version_env = getenv("VERSION");
	dbg("VENDOR_ID='%s', MODEL_ID='%s' SPECIFIER_ID='%s' VERSION='%s'", vendor_env, model_env, specifier_env, version_env);
	if ((vendor_env == NULL) ||
	    (model_env == NULL) ||
	    (specifier_env == NULL) ||
	    (version_env == NULL)) {
		dbg("missing an environment variable, aborting.");
		return 1;
	}

	vendor    = strtoul(vendor_env, NULL, 16);
	model     = strtoul(model_env, NULL, 16);
	specifier = strtoul(specifier_env, NULL, 16);
	version   = strtoul(version_env, NULL, 16);

	strcpy(ieee1394_string, "ieee1394:");
	sprintf(ieee1394_string + strlen(ieee1394_string), "ven%08lX", vendor);
	sprintf(ieee1394_string + strlen(ieee1394_string), "mo%08lX", model);
	sprintf(ieee1394_string + strlen(ieee1394_string), "sp%08lX", specifier);
	sprintf(ieee1394_string + strlen(ieee1394_string), "ver%08lX", version);

	return modprobe(ieee1394_string, true);
}
Beispiel #12
0
int nodeup_postmove(int argc, char *argv[]) {
    int c, i;
    struct module_t *mod;
    const char *krev;
    struct utsname utsbuf;

    /* We're really just skipping over options here */
    while ((c=getopt(argc, argv, "r:f")) != -1) {
        switch (c) {
        case 'r':
            break;
        case 'f':
            break;
        default:
            log_print(LOG_ERROR, "Unrecognized flag: %c\n", (char) optopt);
            return -1;
        }
    }

    if (uname(&utsbuf) != 0) {
        log_print(LOG_ERROR, "Failed to get kernel revision: %s\n",
                  strerror(errno));
        return -1;
    }
    krev = utsbuf.release;

    for (i=optind; i < argc; i++) {
        mod = module_get(krev, argv[i]);
        if (!mod || !mod->map) continue;

        log_print(LOG_INFO, "Loading module %s\n", argv[i]);
        if (modprobe(mod, 0))
            log_print(LOG_ERROR, "  Insmod failed: %s\n", mod_strerror(errno));

    }
    return 0;
}
Beispiel #13
0
int init_network (void)
{
    long arg;
    struct sockaddr_in server;
    unsigned int length = sizeof (server);

    gethostname (hostname, sizeof (hostname));

    /* create server socket only has lns */
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = gconfig.listenaddr; 
    server.sin_port = htons (gconfig.port);

    if ((server_socket = socket (PF_INET, SOCK_DGRAM, 0)) < 0)
    {
        l2tp_log (LOG_CRIT, "%s: Unable to allocate socket. Terminating.\n", __FUNCTION__);
        return -EINVAL;
    }

    arg=1;
    setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg));

    if (bind (server_socket, (struct sockaddr *) &server, sizeof (server)))
    {
        close (server_socket);
        l2tp_log (LOG_CRIT, "%s: Unable to bind socket: %s. Terminating.\n", __FUNCTION__, strerror(errno), errno);
        return -EINVAL;
    }

    if (getsockname (server_socket, (struct sockaddr *) &server, &length))
    {
        close (server_socket);
        l2tp_log (LOG_CRIT, "%s: Unable to read socket name.Terminating.\n", __FUNCTION__);
        return -EINVAL;
    }

#ifdef LINUX
    /*
     * For L2TP/IPsec with KLIPSng, set the socket to receive IPsec REFINFO
     * values.
     */
    arg=1;
    if(setsockopt(server_socket, IPPROTO_IP, gconfig.sarefnum, &arg, sizeof(arg)) != 0) {
#ifdef DEBUG_MORE
        l2tp_log(LOG_CRIT, "setsockopt recvref[%d]: %s\n", gconfig.sarefnum, strerror(errno));
#endif
        gconfig.ipsecsaref=0;
    }
    
    arg=1;
    if(setsockopt(server_socket, IPPROTO_IP, IP_PKTINFO, (char*)&arg, sizeof(arg)) != 0) {
	    l2tp_log(LOG_CRIT, "setsockopt IP_PKTINFO: %s\n", strerror(errno));
    }
#else
    l2tp_log(LOG_INFO, "No attempt being made to use IPsec SAref's since we're not on a Linux machine.\n");
#endif

    /* turn off UDP checksums */
    arg=1;
    if (setsockopt(server_socket, SOL_SOCKET, SO_NO_CHECK , (void*)&arg,
                   sizeof(arg)) ==-1) {
        l2tp_log(LOG_INFO, "unable to turn off UDP checksums");
    }

#ifdef USE_KERNEL
    if (gconfig.forceuserspace)
    {
        l2tp_log (LOG_INFO, "Not looking for kernel support.\n");
        kernel_support = 0;
    }
    else
    {
#if defined(USE_KERNEL) && defined(MODULE_AUTO)
        modprobe();
#endif
        int kernel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
        if (kernel_fd < 0)
        {
            l2tp_log (LOG_INFO, "L2TP kernel support not detected.\n");
            kernel_support = 0;
        }
        else
        {
            close(kernel_fd);
            l2tp_log (LOG_INFO, "Using l2tp kernel support.\n");
            kernel_support = -1;
        }
    }
#else
    l2tp_log (LOG_INFO, "This binary does not support kernel L2TP.\n");
#endif

    arg = fcntl (server_socket, F_GETFL);
    arg |= O_NONBLOCK;
    fcntl (server_socket, F_SETFL, arg);
    gconfig.port = ntohs (server.sin_port);

    return 0;
}
Beispiel #14
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;
}
Beispiel #15
0
/*
 * Listen on IPv4 and/or IPv6 depending on how the local node is configured.
 */
static void
listen_to_peers(void)
{
	struct addrinfo hints = {
		.ai_family = AF_UNSPEC,
		.ai_socktype = SOCK_STREAM,
		.ai_flags = AI_PASSIVE | AI_ADDRCONFIG,
	};
	const int yes = 1;
	struct addrinfo *res, *addr;
	char *port_str;
	int g;

	if (asprintf(&port_str, "%u", fakedlm_port) == -1)
		fail(NULL);
	g = getaddrinfo(NULL, port_str, &hints, &res);
	if (g) {
		fprintf(stderr, "%s\n", gai_strerror(g));
		exit(1);
	}
	free(port_str);
	for (addr = res; addr; addr = addr->ai_next) {
		int fd;

		fd = socket(addr->ai_family, addr->ai_socktype | SOCK_NONBLOCK,
			    addr->ai_protocol);
		if (fd == -1)
			fail(NULL);
		if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes,
			       sizeof(yes)) == -1)
			fail(NULL);
		if (addr->ai_family == AF_INET6) {
			/* Prevent IPv6 sockets from conflicting with IPv4. */
			if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
				       (void *)&yes, sizeof(yes)) == -1)
				fail(NULL);
		}
		if (bind(fd, addr->ai_addr, addr->ai_addrlen) == -1)
			fail(NULL);
		if (listen(fd, MAX_NODES - 1) == -1)
			fail(NULL);
		add_poll_callback(&cbs, fd, POLLIN, incoming_connection,
				  LISTENING_SOCKET_MARKER);
	}
	freeaddrinfo(res);
}

/*
 * Tell DLM about a new node's ID, address, and whether the node is local.
 */
static void
configure_node(struct node *node)
{
	struct sockaddr_storage ss;

	mkdirf(0777, "%scomms/%d", CONFIG_DLM_CLUSTER, node->nodeid);
	printf_pathf("%d", "%scomms/%d/nodeid", node->nodeid, CONFIG_DLM_CLUSTER,
		     node->nodeid);
	if (node == local_node) {
		printf_pathf("1", "%scomms/%d/local", CONFIG_DLM_CLUSTER,
			     node->nodeid);
	}
	memset(&ss, 0, sizeof(ss));
	memcpy(&ss, node->addr->sa, node->addr->sa_len);
	write_pathf(&ss, sizeof(ss), "%scomms/%d/addr",
		    CONFIG_DLM_CLUSTER, node->nodeid);
}

/*
 * Load and configure the DLM kernel module.  This does not start any
 * lockspaces, yet.
 */
static void
configure_dlm(void)
{
	struct node *node;

	if (mkdir(CONFIG_DLM_CLUSTER, 0777) == -1 && errno != EEXIST) {
		modprobe("dlm");
		if (mkdir(CONFIG_DLM_CLUSTER, 0777) == -1 && errno != EEXIST)
			fail(CONFIG_DLM_CLUSTER);
	}
	if (cluster_name)
		printf_pathf("%s", "%s", cluster_name,
			     CONFIG_DLM_CLUSTER "cluster_name");
	if (dlm_port != DLM_PORT) {
		printf_pathf("%d", "%s", DLM_PORT,
			     CONFIG_DLM_CLUSTER "tcp_port");
	}
	if (dlm_protocol != PROTO_TCP) {
		printf_pathf("%d", "%s", dlm_protocol,
			     CONFIG_DLM_CLUSTER "protocol");
	}
	for (node = nodes; node; node = node->next) {
		configure_node(node);
	}
}

/*
 * Remove the DLM configuration so that the kernel module can be removed and/or
 * a different configuration can be created.
 */
static void
remove_dlm(void)
{
	struct node *node;

	for (node = nodes; node; node = node->next)
		rmdirf("%scomms/%d", CONFIG_DLM_CLUSTER, node->nodeid);
	rmdirf("%s", CONFIG_DLM_CLUSTER);

	if (control_fd != -1)
		close(control_fd);
	close(kernel_monitor_fd);
	rmmod("dlm");
}

/*
 * Print a uevent and its parameters (mostly for debugging purposes).
 */
static void
print_uevent(const char *buf, int len)
{
	printf("Uevent '%s'", buf);
	if (verbose) {
		const char *end = buf + len;
		bool first = true;

		for (buf = strchr(buf, 0) + 1;
		     buf < end;
		     buf = strchr(buf, 0) + 1) {
			if (first) {
				printf(" (%s", buf);
				first = false;
			} else {
				printf(", %s", buf);
			}
		}
		if (!first)
			 printf(")");
	}
	printf("\n");
	fflush(stdout);
}
int
main(void)
{
    int i, state = 0, ret;
    int (*states[])() = {
        partition_menu,
        filesystem,
        mountpoint,
        mountpoint_manual,
        fixup, // never does an INPUT, just handles the manual mountpoint result
        NULL
    };

    /* FIXME: How can we tell which file system modules to load?  */
    char *file_system_modules[] = {"ext2", "ext3", "reiserfs", "jfs", "xfs", NULL};

    debconf = debconfclient_new();
    debconf_capb(debconf, "backup");
    ped_exception_set_handler(my_exception_handler);

    for (i = 0; file_system_modules[i]; i++)
	modprobe(file_system_modules[i]);

    if (check_proc_mounts("")) {
        // Chicken out if /target is already mounted
        debconf_set(debconf,"partconf/already-mounted", "no");
        debconf_input(debconf, "critical", "partconf/already-mounted");
        debconf_go(debconf);
        debconf_get(debconf,"partconf/already-mounted");
        if (strcmp(debconf->value, "false") == 0)
            return 0;
    }
    if (!umount_target()) {
        debconf_input(debconf, "critical", "partconf/umount-failed");
        debconf_go(debconf);
        return 1;
    }
    if ((part_count = get_all_partitions(parts, MAX_PARTS, false, 0)) <= 0) {
        debconf_input(debconf, "critical", "partconf/no-partitions");
        debconf_go(debconf);
        return 1;
    }
    if (get_all_filesystems() <= 0) {
        debconf_input(debconf, "critical", "partconf/no-filesystems");
        debconf_go(debconf);
        return 1;
    }
    fschoices = build_fs_choices();
    while (state >= 0) {
        ret = states[state]();
        if (ret < 0)
	    return 10;
        else if (ret == 0 && debconf_go(debconf) == 0)
            state++;
        else
            state--;
        if (states[state] == NULL)
            state = 0;
    }
    return ret;
}
Beispiel #17
0
void start_jffs2(void)
{
	if (!nvram_match("jffs2_enable", "1")) {
		notice_set("jffs", "");
		return;
	}

	int format = 0;
	char s[256];
	int size;
	int part;
	const char *p;
	int model = 0;
	int i = 0;

        while(1) {
		if (wait_action_idle(10)) break;
		else i++;

		if(i>=10) {
			_dprintf("Mount jffs2 failed!");
			return;
		}
	}

	if (!mtd_getinfo(JFFS2_PARTITION, &part, &size)) return;

	model = get_model();
	_dprintf("start jffs2: %d, %d\n", part, size);
	if (nvram_match("jffs2_format", "1")) {
		nvram_set("jffs2_format", "0");
		nvram_commit_x();
		if (mtd_erase(JFFS2_MTD_NAME)) {
			error("formatting");
			return;
		}
		format = 1;
	}

	sprintf(s, "%d", size);
	p = nvram_get("jffs2_size");
	if ((p == NULL) || (strcmp(p, s) != 0)) {
		if (format) {
			nvram_set("jffs2_size", s);
			nvram_commit_x();
		}
		else if ((p != NULL) && (*p != 0)) {
			error("verifying known size of");
			return;
		}
	}

	if(!check_in_rootfs("/jffs", "jffs", format))
		return;

	if (nvram_get_int("jffs2_clean_fs")) {
		if (!mtd_unlock(JFFS2_PARTITION)) {
			error("unlocking");
			return;
		}
	}
	modprobe(JFFS_NAME);
	sprintf(s, MTD_BLKDEV(%d), part);

	if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) {
		if (mtd_erase(JFFS2_MTD_NAME)) {
			jffs2_fail = 1;
                        error("formatting");
                        return;
                }

		format = 1;
		if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) {
			_dprintf("*** jffs2 2-nd mount error\n");
			//modprobe_r(JFFS_NAME);
			error("mounting");
			jffs2_fail = 1;
			return;
		}
	}

	if(nvram_match("force_erase_jffs2", "1")) {
		_dprintf("\n*** force erase jffs2 ***\n");
		mtd_erase(JFFS2_MTD_NAME);
		nvram_set("jffs2_clean_fs", "1");
		nvram_commit();
		reboot(RB_AUTOBOOT);
	}
#ifdef TEST_INTEGRITY
	int test;

	if (format) {
		if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) {
			stop_jffs2(0);
			error("setting integrity test for");
			return;
		}
	}
	if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) {
		stop_jffs2(0);
		error("testing integrity of");
		return;
	}
#endif

	if (nvram_get_int("jffs2_clean_fs")) {
		_dprintf("Clean /jffs/*\n");
		system("rm -fr /jffs/*");
		nvram_unset("jffs2_clean_fs");
		nvram_commit_x();
	}

	notice_set("jffs", format ? "Formatted" : "Loaded");
	jffs2_fail = 0;

	if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) {
		chdir("/jffs");
		system(p);
		chdir("/");
	}
	run_userfile("/jffs", ".asusrouter", "/jffs", 3);

	if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755);
	if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755);
}
Beispiel #18
0
void setup_conntrack(void)
{
	unsigned int v[10];
	const char *p;
	int i;
	
	p = nvram_safe_get("ct_tcp_timeout");
	if (sscanf(p, "%u%u%u%u%u%u%u%u%u%u",
		&v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9]) == 10) {	// lightly verify
		f_write_string("/proc/sys/net/ipv4/ip_conntrack_tcp_timeouts", p, 0, 0);
	}
	
	p = nvram_safe_get("ct_udp_timeout");
	if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) {
		f_write_string("/proc/sys/net/ipv4/ip_conntrack_udp_timeouts", p, 0, 0);
	}
	
	p = nvram_safe_get("ct_max");
	i = atoi(p);
	if ((i >= 128) && (i <= 65535)) {
		f_write_string("/proc/sys/net/ipv4/ip_conntrack_max", p, 0, 0);
	}

	if (!nvram_match("nf_pptp", "0")) {
		modprobe("ip_conntrack_proto_gre");
		modprobe("ip_nat_proto_gre");
		modprobe("ip_conntrack_pptp");
		modprobe("ip_nat_pptp");
	}
	else {
		modprobe_r("ip_nat_pptp");
		modprobe_r("ip_conntrack_pptp");
		modprobe_r("ip_nat_proto_gre");
		modprobe_r("ip_conntrack_proto_gre");
	}

	if (!nvram_match("nf_h323", "0")) {
		modprobe("ip_conntrack_h323");
		modprobe("ip_nat_h323");
	}
	else {
		modprobe_r("ip_nat_h323");
		modprobe_r("ip_conntrack_h323");
	}
	
	if (!nvram_match("nf_rtsp", "0")) {
		modprobe("ip_conntrack_rtsp");
		modprobe("ip_nat_rtsp");
	}
	else {
		modprobe_r("ip_nat_rtsp");
		modprobe_r("ip_conntrack_rtsp");
	}

	if (!nvram_match("nf_ftp", "0")) {
		modprobe("ip_conntrack_ftp");
		modprobe("ip_nat_ftp");
	}
	else {
		modprobe_r("ip_nat_ftp");
		modprobe_r("ip_conntrack_ftp");
	}

}
Beispiel #19
0
int asus_ate_command(const char *command, const char *value, const char *value2)
{
	_dprintf("===[ATE %s %s]===\n", command, value);
#ifdef RTCONFIG_QTN
	if(!nvram_match("qtn_ready", "1")){
		_dprintf("ATE Error: wireless 5G not ready\n");
		return 0;
	}
#endif
	/*** ATE Set function ***/
	if(!strcmp(command, "Set_StartATEMode")) {
		nvram_set("asus_mfg", "1");
		if(nvram_match("asus_mfg", "1")) {
			puts("1");
#ifdef RTCONFIG_FANCTRL
			stop_phy_tempsense();
#endif
			stop_wpsaide();
			stop_wps();
#ifdef RTCONFIG_BCMWL6
			stop_igmp_proxy();
#ifdef RTCONFIG_HSPOT
			stop_hspotap();
#endif
			stop_acsd();
#ifdef BCM_BSD
			stop_bsd();
#endif
#ifdef BCM_SSD
			stop_ssd();
#endif
#endif
			stop_upnp();
			stop_lltd();
			stop_rstats();
			stop_wanduck();
			stop_logger();
			stop_wanduck();
			stop_dnsmasq(0);
			stop_ots();
			stop_networkmap();
#ifdef RTCONFIG_USB
			stop_usbled();
#ifdef RTCONFIG_USB_PRINTER
			stop_lpd();
			stop_u2ec();
#endif
#endif
			platform_start_ate_mode();
		}
		else
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Set_AllLedOn")) {
		return setAllLedOn();
	}
	else if (!strcmp(command, "Set_AllLedOn2")) {
		return setAllLedOn2();
	}
	else if (!strcmp(command, "Set_AllLedOff")) {
		return setAllLedOff();
	}
	else if (!strcmp(command, "Set_AllLedOn_Half")) {
		puts("ATE_ERROR"); //Need to implement for EA-N66U
		return EINVAL;
	}
#ifdef RTCONFIG_BCMARM
	else if (!strcmp(command, "Set_AteModeLedOn")) {
		return setATEModeLedOn();
	}
#endif
	else if (!strcmp(command, "Set_MacAddr_2G")) {
		if( !setMAC_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		if( !setMAC_5G_qtn(value))
#else
		if( !setMAC_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Set_MacAddr_5G_2")) {
		if( !setMAC_5G_2(value))
                {
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                        return EINVAL;
                }
                return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTN14U)
	else if (!strcmp(command, "eeprom")) {
		if ( !eeprom_upgrade(value, 1))
			return EINVAL;
		return 0;
	}
	else if (!strcmp(command, "eeover")) {
		if ( !eeprom_upgrade(value, 0))
			return EINVAL;
		return 0;
	}
#endif
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Set_RegSpec")) {
		if (setRegSpec(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if (setRegDomain_2G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
		if (setRegDomain_5G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if ( !setCountryCode_2G(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
#ifdef RTCONFIG_QCA
		if ((value2==NULL) || strcmp(value2,"noctl"))
			setCTL(value);
#endif
		return 0;
	}
#endif /* RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		if ( !setCountryCode_5G_qtn(value))
#else
		if ( !setCountryCode_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_2G")) {
		if( !setRegrev_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		if( !setRegrev_5G_qtn(value))
#else
		if( !setRegrev_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Commit")) {
		setCommit();
		return 0;
	}
#endif
#if defined(RTN14U)
	else if (!strcmp(command, "pkt_flood")) {
		if (nvram_invmatch("asus_mfg", "0"))
		{
#if 0 // TBD
			struct sockaddr_ll dev,dev2;
			int fd,fd2,do_flag=3;
			unsigned char buffer[1514];
			fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev.sll_family = AF_PACKET;
			dev.sll_protocol = htons(ETH_P_ALL);
			dev.sll_ifindex = 4; // LAN
			bind( fd, (struct sockaddr *) &dev, sizeof(dev));

			fd2 = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev2.sll_family = AF_PACKET;
			dev2.sll_protocol = htons(ETH_P_ALL);
			dev2.sll_ifindex = 5; // WAN
			bind( fd2, (struct sockaddr *) &dev2, sizeof(dev2));

			if (value) {
				if(strcmp(value,"WAN")==0)
					do_flag = 2;
				else if(strcmp(value,"LAN")==0)
					do_flag = 1;
			}
			memset(buffer,0xff,6);
			FRead(buffer+6, OFFSET_MAC_ADDR_2G, 6);
			memset(buffer+12,0x55,1502);
			while(1)
			{
				if (do_flag & 1)
					send( fd, buffer, 1514, 0);
				if (do_flag & 2)
					send( fd2, buffer, 1514, 0);
			}
#endif
		}
		return 0;
 	}
#endif
	else if (!strcmp(command, "Set_SerialNumber")) {
		if(!setSN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
 	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Set_ModelName")) {
		if(!setMN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif
	else if (!strcmp(command, "Set_PINCode")) {
		if (!setPIN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_40M_Channel_2G")) {
		if(!set40M_Channel_2G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_40M_Channel_5G")) {
		if(!set40M_Channel_5G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_RestoreDefault")) {
		nvram_set("restore_defaults", "1");
		ResetDefault();
		nvram_set(ASUS_STOP_COMMIT, "1");
		return 0;
	}
	else if (!strcmp(command, "Set_Eject")) {
		if( !Ej_device(value)) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTCONFIG_FANCTRL
	else if (!strcmp(command, "Set_FanOn")) {
		setFanOn();
		return 0;
	}
	else if (!strcmp(command, "Set_FanOff")) {
		setFanOff();
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_WaitTime")) {
		if( !setWaitTime(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WiFi_2G")) {
		if( !setWiFi2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFi_5G")) {
		if( !setWiFi5G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Set_DevFlags")) {
		if( Set_Device_Flags(value) < 0 )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WanToLan")) {
	   	set_wantolan();
		modprobe_r("hw_nat");
		modprobe("hw_nat");
		system("killall -9 wanduck");
		system("killall -9 udhcpc");
		return 0;
	}
#if defined(RTAC1200HP) || defined(RTN56UB1)
        else if (!strcmp(command, "Set_FixChannel")) {
	   	 FWrite("1", OFFSET_FIX_CHANNEL, 1);	
                 puts("1");
                 return 0;
         }
        else if (!strcmp(command, "Set_FreeChannel")) {
	   	 FWrite("0", OFFSET_FIX_CHANNEL, 1);	
		 nvram_set("wl0_channel","0");
		 nvram_set("wl1_channel","0");
		 nvram_set("lan_stp","1");
		 nvram_commit();
                 puts("1");
                 return 0;
         }
#endif
#endif
	else if (!strcmp(command, "Set_XSetting")) {
		if(value == NULL || strcmp(value, "1")) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		else {
			nvram_set("x_Setting", "1");
			puts(nvram_get("x_Setting"));
		}
		return 0;
	}
	/*** ATE Get functions ***/
	else if (!strcmp(command, "Get_FWVersion")) {
		char fwver[12];
		sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno"));
		puts(fwver);
		return 0;
	}
	else if (!strcmp(command, "Get_BootLoaderVersion")) {
		getBootVer();
		return 0;
	}
	else if (!strcmp(command, "Get_ResetButtonStatus")) {
		puts(nvram_safe_get("btn_rst"));
		return 0;
	}
	else if (!strcmp(command, "Get_WpsButtonStatus")) {
		puts(nvram_safe_get("btn_ez"));
		return 0;
	}
#ifdef RT4GAC55U
	else if (!strcmp(command, "Get_LteButtonStatus")) {
		puts(nvram_safe_get("btn_lte"));
		return 0;
	}
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WirelessButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_SWMode")) {
		puts(nvram_safe_get("sw_mode"));
		return 0;
	}
	else if (!strcmp(command, "Get_MacAddr_2G")) {
		getMAC_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		getMAC_5G_qtn();
#else
		getMAC_5G();
#endif
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_MacAddr_5G_2")) {
		getMAC_5G_2();
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) {
		Get_USB_Port_Info("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) {
		Get_USB_Port_Folder("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) {
		Get_USB_Port_Info("2");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) {
		Get_USB_Port_Folder("2");
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Infor")) {
		Get_SD_Card_Info();
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Folder")) {
		Get_SD_Card_Folder();
		return 0;
	}
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Get_RegSpec")) {
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getCountryCode_2G();
		return 0;
	}
#endif	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		getCountryCode_5G_qtn();
#else
	   	getCountryCode_5G();
#endif
		return 0;
	}
	else if (!strcmp(command, "Get_Regrev_2G")) {
		getRegrev_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		getRegrev_5G_qtn();
#else
		getRegrev_5G();
#endif
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_SerialNumber")) {
		getSN();
		return 0;
	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Get_ModelName")) {
		getMN();
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_PINCode")) {
		getPIN();
		return 0;
	}
	else if (!strcmp(command, "Get_WanLanStatus")) {
		if( !GetPhyStatus())
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_FwReadyStatus")) {
		puts(nvram_safe_get("success_start_service"));
		return 0;
	}
	else if (!strcmp(command, "Get_Build_Info")) {
		puts(nvram_safe_get("buildinfo"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_RSSI_2G")) {
		getrssi(0);
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RSSI_5G")) {
		getrssi(1);
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_ChannelList_2G")) {
		if(!Get_ChannelList_2G())
			puts("ATE_ERROR");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_ChannelList_5G")) {
#ifdef RTCONFIG_QTN
		if (!Get_ChannelList_5G_qtn())
#else
		if (!Get_ChannelList_5G())
#endif
			puts("ATE_ERROR");
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_ChannelList_5G_2")) {
		if (!Get_ChannelList_5G_2())
			puts("ATE_ERROR");
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTCONFIG_USB_XHCI)
	else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) {
		if (!Get_USB3_Port_Info("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) {
		if (!Get_USB3_Port_Info("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) {
		puts("ATE_ERROR"); //Need to implement
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) {
		if (!Get_USB3_Port_Folder("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) {
		if (!Get_USB3_Port_Folder("2"))
			puts("ATE_ERROR");
		return 0;
	}
 	else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) {
		if (!Get_USB3_Port_DataRate("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) {
		if (!Get_USB3_Port_DataRate("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
#endif	/* RTCONFIG_USB_XHCI */
	else if (!strcmp(command, "Get_fail_ret")) {
		Get_fail_ret();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_reboot_log")) {
		Get_fail_reboot_log();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_dev_log")) {
		Get_fail_dev_log();
		return 0;
	}
#ifdef RTCONFIG_RALINK
#if !defined(RTN14U) && !defined(RTAC52U) && !defined(RTAC51U) && !defined(RTN11P) && !defined(RTN54U) && !defined(RTAC1200HP) && !defined(RTN56UB1) && !defined(RTAC54U)
	else if (!strcmp(command, "Ra_FWRITE")) {
		return FWRITE(value, value2);
	}
	else if (!strcmp(command, "Ra_Asuscfe_2G")) {
		return asuscfe(value, WIF_2G);
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Ra_Asuscfe_5G")) {
		return asuscfe(value, WIF_5G);
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_SwitchPort_LEDs")) {
		if(Set_SwitchPort_LEDs(value, value2) < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#endif
#ifdef RTCONFIG_WIRELESS_SWITCH
	else if (!strcmp(command, "Get_WifiSwStatus")) {
		puts(nvram_safe_get("btn_wifi_sw"));
		return 0;
	}
#endif

#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WifiButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
#ifdef RTCONFIG_TURBO
	else if (!strcmp(command, "Get_Turbo")) {
		puts(nvram_safe_get("btn_turbo"));
		return 0;
	}
#endif
#ifdef RTCONFIG_LED_BTN
	else if (!strcmp(command, "Get_LedButtonStatus")) {
		puts(nvram_safe_get("btn_led"));
		return 0;
	}
#endif
#ifdef RTCONFIG_QTN
	else if (!strcmp(command, "Enable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(1);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Disable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(0);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Qtn_TelnetSrv_Status")) {
		getstatus_qtn_telnetsrv();
		return 0;
	}
	else if (!strcmp(command, "Del_Qtn_Cal_Files")) {
		del_qtn_cal_files();
		puts("1");
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(!getWiFiStatus("2G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(!getWiFiStatus("5G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
#else
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(get_radio(0, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(get_radio(1, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Set_WiFiStatus_2G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 0, 0);

		if(get_radio(0, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFiStatus_5G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 1, 0);

		if(get_radio(1, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_ATEVersion")) {
		puts(nvram_safe_get("Ate_version"));
		return 0;
	}
	else if (!strcmp(command, "Get_XSetting")) {
		puts(nvram_safe_get("x_Setting"));
		return 0;
	}
	else if (!strcmp(command, "Get_WaitTime")) {
		puts(nvram_safe_get("wait_time"));
		return 0;
	}
	else if (!strcmp(command, "Get_ExtendNo")) {
		puts(nvram_safe_get("extendno"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_DevFlags")) {
		if( Get_Device_Flags() < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#ifdef RTCONFIG_QCA
/*
	else if (!strcmp(command, "Set_ART2")) {
		// temp solution
		system("killall rstats");
		system("killall udhcpc");
		system("killall wanduck");
		system("killall networkmap");
		system("killall -9 hostapd");
		system("ifconfig ath0 down");
		system("ifconfig ath1 down");
		system("killall -9 hostapd");
		system("brctl delif br0 ath0");
		system("brctl delif br0 ath1");
		system("wlanconfig ath0 destroy");
		system("wlanconfig ath1 destroy");
		system("ifconfig wifi0 down");
		system("ifconfig wifi1 down");
		modprobe_r("umac");
		modprobe_r("ath_dfs");
		modprobe_r("ath_dev");
		modprobe_r("ath_rate_atheros");
		modprobe_r("ath_spectral");
		modprobe_r("ath_hal");
		modprobe_r("adf");
		modprobe_r("asf");
		modprobe("art");
		system("nart.out -port 2390 -console &");
		system("nart.out -port 2391 -console &");
		return 0;
	}
*/
	else if (!strncmp(command, "Get_EEPROM_", 11)) {
		unsigned char buffer[2560];
		unsigned short len;
		int lret;
		char *pt;
		len=sizeof(buffer);
		pt = (char*) command + 11;
		if (!strcmp(pt, "2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else {
			puts("ATE_UNSUPPORT");
			return EINVAL;
		}
		if ( !lret )
			hexdump(&buffer[0], len);
		return 0;
	}
	else if (!strcmp(command, "Get_CalCompare")) {
		unsigned char buffer[2560], buffer2[2560];
		unsigned short len, len2;
		int lret=0, cret=0;
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "2G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_2G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("2G EEPROM different!");
			cret++;
		}
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "5G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_5G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("5G EEPROM different!");
			cret++;
		}
		if (!cret)
			puts("1");
		else
			puts("0");
		return 0;
	}
#ifdef RTCONFIG_ATEUSB3_FORCE
	else if (!strcmp(command, "Set_ForceUSB3")) {
		if (setForceU3(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getForceU3();
		return 0;
	}
	else if (!strcmp(command, "Get_ForceUSB3")) {
		getForceU3();
		return 0;
	}
#endif
#endif	/* RTCONFIG_QCA */
#ifdef RT4GAC55U
	else if(!strcmp(command, "Get_GobiSimCard")) {
		char line[128];
		if (!Gobi_SimCardReady(Gobi_SimCard(line, sizeof(line))))
		{
			puts("FAIL");
			return EINVAL;
		}
		puts("PASS");
	}
	else if(!strcmp(command, "Get_GobiIMEI")) {
		char line[128];
		const char *IMEI = Gobi_IMEI(line, sizeof(line));
		if (IMEI == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(IMEI);
	}
	else if(!strcmp(command, "Get_GobiConnectISP")) {
		char line[128];
		const char *ISP = Gobi_ConnectISP(line, sizeof(line));
		if (ISP == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(ISP);
	}
	else if(!strcmp(command, "Get_GobiConnectStatus")) {
		const char *status = Gobi_ConnectStatus_Str(Gobi_ConnectStatus_Int());
		if (status == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(status);
	}
	else if(!strcmp(command, "Get_GobiSignal_Percent")) {
		int percent = Gobi_SignalQuality_Percent(Gobi_SignalQuality_Int());
		if (percent < 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d\n", percent);
	}
	else if(!strcmp(command, "Get_GobiSignal_dbm")) {
		int dbm = Gobi_SignalLevel_Int();
		if (dbm >= 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d dBm\n", dbm);
	}
	else if(!strcmp(command, "Get_GobiVersion")) {
		char line[128];
		if (Gobi_Version(line, sizeof(line)) == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%s\n", line);
	}
#endif	/* RT4GAC55U */
	else
	{
		puts("ATE_UNSUPPORT");
		return EINVAL;
	}

	return 0;
}
Beispiel #20
0
void start_qos(void)
{
	int i;
	char *buf, *g, *p, *qos;
	unsigned int rate;
	unsigned int ceil;
	unsigned int bw;
	unsigned int incomingBandwidthInKilobitsPerSecond;
	unsigned int mtu;
	unsigned int r2q;
	unsigned int qosDefaultClassId;
	unsigned int overhead;
	FILE *f;
	int x;
	int inuse;
	char s[256];
	int first;
	char burst_root[32];
	char burst_leaf[32];

	qosDefaultClassId = (nvram_get_int("qos_default") + 1) * 10;
	incomingBandwidthInKilobitsPerSecond = strtoul(nvram_safe_get("qos_ibw"), NULL, 10);
	
	// move me?
	x = nvram_get_int("ne_vegas");
#ifdef LINUX26
	if (x) {
		char alpha[10], beta[10], gamma[10];
		sprintf(alpha, "alpha=%d", nvram_get_int("ne_valpha"));
		sprintf(beta, "beta=%d", nvram_get_int("ne_vbeta"));
		sprintf(gamma, "gamma=%d", nvram_get_int("ne_vgamma"));
		modprobe("tcp_vegas", alpha, beta, gamma);
		f_write_string("/proc/sys/net/ipv4/tcp_congestion_control", "vegas", 0, 0);
	}
	else {
		modprobe_r("tcp_vegas");
		f_write_string("/proc/sys/net/ipv4/tcp_congestion_control", "cubic", FW_NEWLINE, 0);
	}
#else
	f_write_string("/proc/sys/net/ipv4/tcp_vegas_cong_avoid", x ? "1" : "0", 0, 0);
	if (x) {
		f_write_string("/proc/sys/net/ipv4/tcp_vegas_alpha", nvram_safe_get("ne_valpha"), 0, 0);
		f_write_string("/proc/sys/net/ipv4/tcp_vegas_beta", nvram_safe_get("ne_vbeta"), 0, 0);
		f_write_string("/proc/sys/net/ipv4/tcp_vegas_gamma", nvram_safe_get("ne_vgamma"), 0, 0);
	}
#endif

	if (!nvram_get_int("qos_enable")) return;

	if ((f = fopen(qosfn, "w")) == NULL) return;

	i = nvram_get_int("qos_burst0");
	if (i > 0) sprintf(burst_root, "burst %dk", i);
		else burst_root[0] = 0;
	i = nvram_get_int("qos_burst1");
	if (i > 0) sprintf(burst_leaf, "burst %dk", i);
		else burst_leaf[0] = 0;

	mtu = strtoul(nvram_safe_get("wan_mtu"), NULL, 10);
	bw = strtoul(nvram_safe_get("qos_obw"), NULL, 10);
	overhead = strtoul(nvram_safe_get("atm_overhead"), NULL, 10);
	r2q = 10;

	if ((bw * 1000) / (8 * r2q) < mtu) {
		r2q = (bw * 1000) / (8 * mtu);
		if (r2q < 1) r2q = 1;
	} else if ((bw * 1000) / (8 * r2q) > 60000) {
		r2q = (bw * 1000) / (8 * 60000) + 1;
	}

	x = nvram_get_int("qos_pfifo");
	if (x == 1) {
		qos = "pfifo limit 256";
	} else if (x == 2) {
		qos = "codel";
	} else if (x == 3) {
		qos = "fq_codel";
	} else {
		qos = "sfq perturb 10";
	}
	if (overhead == 0) {
		fprintf(f,
			"#!/bin/sh\n"
			"WAN_DEV=%s\n"
			"IMQ_DEV=%s\n"
			"TQA=\"tc qdisc add dev $WAN_DEV\"\n"
			"TCA=\"tc class add dev $WAN_DEV\"\n"
			"TFA=\"tc filter add dev $WAN_DEV\"\n"
			"TQA_IMQ=\"tc qdisc add dev $IMQ_DEV\"\n"
			"TCA_IMQ=\"tc class add dev $IMQ_DEV\"\n"
			"TFA_IMQ=\"tc filter add dev $IMQ_DEV\"\n"
			"Q=\"%s\"\n"
			"\n"
			"case \"$1\" in\n"
			"start)\n"
			"\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n"
			"\t$TQA root handle 1: htb default %u r2q %u\n"
			"\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s\n",
				get_wanface(),
				qosImqDeviceString,
				qos,
				qosDefaultClassId, r2q,
				bw, bw, burst_root);
	} else {
		fprintf(f,
			"#!/bin/sh\n"
			"WAN_DEV=%s\n"
			"IMQ_DEV=%s\n"
			"TQA=\"tc qdisc add dev $WAN_DEV\"\n"
			"TCA=\"tc class add dev $WAN_DEV\"\n"
			"TFA=\"tc filter add dev $WAN_DEV\"\n"
			"TQA_IMQ=\"tc qdisc add dev $IMQ_DEV\"\n"
			"TCA_IMQ=\"tc class add dev $IMQ_DEV\"\n"
			"TFA_IMQ=\"tc filter add dev $IMQ_DEV\"\n"
			"Q=\"%s\"\n"
			"\n"
			"case \"$1\" in\n"
			"start)\n"
			"\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n"
			"\t$TQA root handle 1: htb default %u r2q %u\n"
			"\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s overhead %u linklayer atm\n",
				get_wanface(),
				qosImqDeviceString,
				qos,
				qosDefaultClassId, r2q,
				bw, bw, burst_root, overhead);
		}

	inuse = nvram_get_int("qos_inuse");

	g = buf = strdup(nvram_safe_get("qos_orates"));
	for (i = 0; i < 10; ++i) {
		if ((!g) || ((p = strsep(&g, ",")) == NULL)) break;

		if ((inuse & (1 << i)) == 0) continue;

		// check if we've got a percentage definition in the form of "rate-ceiling"
		if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1)) continue;	// 0=off

		if (ceil > 0) sprintf(s, "ceil %ukbit ", calc(bw, ceil));
			else s[0] = 0;
		x = (i + 1) * 10;

		if (overhead == 0) {
			fprintf(f,
				"# egress %d: %u-%u%%\n"
				"\t$TCA parent 1:1 classid 1:%d htb rate %ukbit %s %s prio %d quantum %u\n"
				"\t$TQA parent 1:%d handle %d: $Q\n"
				"\t$TFA parent 1: prio %d handle %d fw flowid 1:%d\n",
					i, rate, ceil,
					x, calc(bw, rate), s, burst_leaf, i+1, mtu,
					x, x,
					x, i + 1, x);
		} else {
			fprintf(f,
				"# egress %d: %u-%u%%\n"
				"\t$TCA parent 1:1 classid 1:%d htb rate %ukbit %s %s prio %d quantum %u overhead %u linklayer atm\n"
				"\t$TQA parent 1:%d handle %d: $Q\n"
				"\t$TFA parent 1: prio %d handle %d fw flowid 1:%d\n",
					i, rate, ceil,
					x, calc(bw, rate), s, burst_leaf, i+1, mtu, overhead,
					x, x,
					x, i + 1, x);
		}
	}
	free(buf);

//		"\t$TFA parent 1: prio 10 protocol ip u32 match ip tos 0x10 0xff flowid :10\n"	// TOS EF -> Highest


/*
		if (nvram_match("qos_ack", "1")) {
			fprintf(f,
				"\n"
				"\t$TFA parent 1: prio 15 protocol ip u32 "
				"match ip protocol 6 0xff "		// TCP
				"match u8 0x05 0x0f at 0 "		// IP header length
				"match u16 0x0000 0xffc0 at 2 "	// total length (0-63)
				"match u8 0x10 0xff at 33 "		// ACK only
				"flowid 1:10\n");
		}
		if (nvram_match("qos_icmp", "1")) {
			fputs("\n\t$TFA parent 1: prio 14 protocol ip u32 match ip protocol 1 0xff flowid 1:10\n", f);
		}
*/

/*
	if (nvram_get_int("qos_ack")) {
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 14 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xff80 at 2 "		// total length (0-127)
			"match u8 0x10 0xff at 33 "			// ACK only
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_syn")) {
		//	10000 = ACK
		//	00010 = SYN

		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 15 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xff80 at 2 "		// total length (0-127)
			"match u8 0x02 0xff at 33 "			// SYN only
			"flowid 1:10\n"
			"\n"
			"\t$TFA parent 1: prio 16 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xff80 at 2 "		// total length (0-127)
			"match u8 0x12 0xff at 33 "			// SYN,ACK
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_fin")) {
		//	10000 = ACK
		//	00001 = FIN

		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 17 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u8 0x11 0xff at 33 "			// ACK,FIN
			"flowid 1:10\n"
			"\n"
			"\t$TFA parent 1: prio 18 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u8 0x01 0xff at 33 "			// FIN
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_rst")) {
		//	10000 = ACK
		//	00100 = RST
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 19 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u8 0x14 0xff at 33 "			// ACK,RST
			"flowid 1:10\n"
			"\n"
			"\t$TFA parent 1: prio 20 protocol ip u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u8 0x04 0xff at 33 "			// RST
			"flowid 1:10\n");
	}


	if (nvram_get_int("qos_icmp")) {
		fputs("\n\t$TFA parent 1: prio 13 protocol ip u32 match ip protocol 1 0xff flowid 1:10\n", f);
	}
*/

	/*
		10000 = ACK
		00100 = RST
		00010 = SYN
		00001 = FIN
	*/

	if (nvram_get_int("qos_ack")) {
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 14 u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
//			"match u16 0x0000 0xff80 at 2 "		// total length (0-127)
			"match u16 0x0000 0xffc0 at 2 "		// total length (0-63)
			"match u8 0x10 0xff at 33 "			// ACK only
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_syn")) {
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 15 u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xffc0 at 2 "		// total length (0-63)
			"match u8 0x02 0x02 at 33 "			// SYN,*
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_fin")) {
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 17 u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xffc0 at 2 "		// total length (0-63)
			"match u8 0x01 0x01 at 33 "			// FIN,*
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_rst")) {
		fprintf(f,
			"\n"
			"\t$TFA parent 1: prio 19 u32 "
			"match ip protocol 6 0xff "			// TCP
			"match u8 0x05 0x0f at 0 "			// IP header length
			"match u16 0x0000 0xffc0 at 2 "		// total length (0-63)
			"match u8 0x04 0x04 at 33 "			// RST,*
			"flowid 1:10\n");
	}

	if (nvram_get_int("qos_icmp")) {
		fputs("\n\t$TFA parent 1: prio 13 u32 match ip protocol 1 0xff flowid 1:10\n", f);
	}


	////
	//// INCOMING TRAFFIC SHAPING
	////
	
	first = 1;
	overhead = strtoul(nvram_safe_get("atm_overhead"), NULL, 10);

	g = buf = strdup(nvram_safe_get("qos_irates"));
	
	for (i = 0; i < 10; ++i)
	{	
		if ((!g) || ((p = strsep(&g, ",")) == NULL))
		{
			break;
		}
		
		if ((inuse & (1 << i)) == 0)
		{
			continue;
		}

		// check if we've got a percentage definition in the form of "rate-ceiling"
		if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1))
		{
			continue;	// 0=off
		}
		
		// class ID
		unsigned int classid = ((unsigned int)i + 1) * 10;
		
		// priority
		unsigned int priority = (unsigned int)i + 1;			//prios 1-10 - Toastman
		
		// rate in kb/s
		unsigned int rateInKilobitsPerSecond =
			calc(incomingBandwidthInKilobitsPerSecond, rate);
		
		// ceiling in kb/s
		unsigned int ceilingInKilobitsPerSecond =
			calc(incomingBandwidthInKilobitsPerSecond, ceil);

		// burst rate (2% of the classes' rate) - don't know if we should use this
//Commented out KDB 20130531 - produces compiler warning about being unused!
//		unsigned int burstRateInBitsPerSecond =
//			(rateInKilobitsPerSecond * 1000) / 50;

		r2q = 10;
		if ((incomingBandwidthInKilobitsPerSecond * 1000) / (8 * r2q) < mtu) 
		{
			r2q = (incomingBandwidthInKilobitsPerSecond * 1000) / (8 * mtu);
			if (r2q < 1) r2q = 1;
		} 
		else if ((incomingBandwidthInKilobitsPerSecond * 1000) / (8 * r2q) > 60000) 
		{
			r2q = (incomingBandwidthInKilobitsPerSecond * 1000) / (8 * 60000) + 1;
		}

		if (first)
		{
			first = 0;
			fprintf(f,
				"\n"
				"\ttc qdisc del dev $I ingress 2>/dev/null\n"
				"\t$TQA handle ffff: ingress\n");
			if (overhead == 0) {
				fprintf(f,
				"\n"
				"\tip link set $IMQ_DEV up\n"
				"\ttc qdisc del dev $IMQ_DEV 2>/dev/null\n"
				"\t$TQA_IMQ handle 1: root htb default %u r2q %u\n"
				"\t$TCA_IMQ parent 1: classid 1:1 htb rate %ukbit ceil %ukbit\n",
				qosDefaultClassId, r2q,
				incomingBandwidthInKilobitsPerSecond,
				incomingBandwidthInKilobitsPerSecond);
			} else {
				fprintf(f,
					"\n"
					"\tip link set $IMQ_DEV up\n"
					"\ttc qdisc del dev $IMQ_DEV 2>/dev/null\n"
					"\t$TQA_IMQ handle 1: root htb default %u r2q %u\n"
					"\t$TCA_IMQ parent 1: classid 1:1 htb rate %ukbit ceil %ukbit overhead %u linklayer atm\n",
					qosDefaultClassId, r2q,
					incomingBandwidthInKilobitsPerSecond,
					incomingBandwidthInKilobitsPerSecond, overhead);
				}

			fprintf(f,
			"\n"
			"\t$TFA parent ffff: prio 10 u32 match ip %s action mirred egress redirect dev $IMQ_DEV\n", (nvram_get_int("qos_udp") == 1) ? "protocol 6 0xff" : "dst 0.0.0.0/0");
		}
		
		fprintf(
			f,
			"\n"
			"\t# class id %u: rate %ukbit ceil %ukbit\n",
			classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond);

		if (overhead == 0) {
			fprintf(
				f,
				"\t$TCA_IMQ parent 1:1 classid 1:%u htb rate %ukbit ceil %ukbit prio %u quantum %u\n",
				classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond, priority, mtu);
		} else {
			fprintf(
				f,
				"\t$TCA_IMQ parent 1:1 classid 1:%u htb rate %ukbit ceil %ukbit prio %u quantum %u overhead %u linklayer atm\n",
				classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond, priority, mtu, overhead);
			}

		fprintf(
			f,
			"\t$TQA_IMQ parent 1:%u handle %u: $Q\n",
			classid, classid);

		fprintf(
			f,
			"\t$TFA_IMQ parent 1: prio %u handle %u fw flowid 1:%u \n",           
			classid, priority, classid);
	}

	free(buf);

	//// write commands which adds rule to forward traffic to IMQ device
	fputs(
		"\n"
		"\t# set up the IMQ device (otherwise this won't work) to limit the incoming data\n"
		"\tip link set $IMQ_DEV up\n",
		f);

	fprintf(f,
		"\t;;\n"
		"stop)\n"
		"\tip link set $IMQ_DEV down\n"
		"\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n"
		"\ttc qdisc del dev $IMQ_DEV root 2>/dev/null\n"
		"\ttc filter del dev $WAN_DEV parent ffff: prio 10 u32 match ip %s action mirred egress redirect dev $IMQ_DEV 2>/dev/null\n"
		"\t;;\n"
		"*)\n"
		"\techo \"...\"\n"
		"\techo \"... OUTGOING QDISCS AND CLASSES FOR $WAN_DEV\"\n"
		"\techo \"...\"\n"
		"\ttc -s -d qdisc ls dev $WAN_DEV\n"
		"\techo\n"
		"\ttc -s -d class ls dev $WAN_DEV\n"
		"\techo\n"
		"\techo \"...\"\n"
		"\techo \"... INCOMING QDISCS AND CLASSES FOR $WAN_DEV (routed through $IMQ_DEV)\"\n"
		"\techo \"...\"\n"
		"\ttc -s -d qdisc ls dev $IMQ_DEV\n"
		"\techo\n"
		"\ttc -s -d class ls dev $IMQ_DEV\n"
		"\techo\n"
		"esac\n",
		(nvram_get_int("qos_udp") == 1) ? "protocol 6 0xff" : "dst 0.0.0.0/0");

	fclose(f);
	chmod(qosfn, 0700);
	eval((char *)qosfn, "start");
}
Beispiel #21
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 (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") &&
					/* 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
					modprobe("hw_nat");
					sleep(1);
				}
#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");
		}
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Beispiel #22
0
void mount_2nd_jffs2(void)
{
        int format = 0;
        char s[256];
        int size;
        int part;
        struct statfs sf;
        int model = 0;
	int i = 0;

	_dprintf("Mount 2nd jffs2...\n");
	while(1) {
        	if (wait_action_idle(10)) break;
		else i++;

		if(i>=10) {
			_dprintf("Mount 2nd jffs2 failed!");
			return;
		}
	}

        if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) {
		_dprintf("Can not get 2nd jffs2 information!");
		return;
	}
	_dprintf("2nd jffs2: %d, %d\n", part, size);

        model = get_model();

        if (statfs(SECOND_JFFS2_PATH, &sf) == 0) {
                switch(model) {
                        case MODEL_RTAC56S:
                        case MODEL_RTAC56U:
			case MODEL_RTAC3200:
                        case MODEL_DSLAC68U:
                        case MODEL_RPAC68U:
                        case MODEL_RTAC68U:
                        case MODEL_RTAC87U:
			case MODEL_RTN18U:
                        case MODEL_RTN65U:
                        case MODEL_RTN14U: // it should be better to use LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36)
                        {
                                if (sf.f_type != 0x73717368 /* squashfs */) {
                                        // already mounted
                                        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");
                                        return;
                                }
                                break;
                        }
                        default:
                        {
                                if (sf.f_type != 0x71736873 /* squashfs */) {
                                        // already mounted
                                        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");
                                        return;
                                }
                                break;
                        }
                }
        }

        modprobe(JFFS_NAME);
        sprintf(s, MTD_BLKDEV(%d), part);

	i = 0;
        while(mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_RDONLY, "") != 0) {
		_dprintf("Mount 2nd jffs failed! Try again...\n");
		if(i >= 10) {
			_dprintf("Mount 2nd jffs 10 times failed, stop mount!");
			break;
		}
		i++;
        }

	return;
}
Beispiel #23
0
void start_jffs2(void)
{
	if (!nvram_match("jffs2_on", "1")) {
		notice_set("jffs", "");
		return;
	}

	int format = 0;
	char s[256];
	int size;
	int part;
	const char *p;
	struct statfs sf;
	int model = 0;
	int i = 0;

        while(1) {
		if (wait_action_idle(10)) break;
		else i++;

		if(i>=10) {
			_dprintf("Mount jffs2 failed!");
			return;
		}
	}

	if (!mtd_getinfo(JFFS2_PARTITION, &part, &size)) return;

	model = get_model();
	_dprintf("start jffs2: %d, %d\n", part, size);
	if (nvram_match("jffs2_format", "1")) {
		nvram_set("jffs2_format", "0");
		nvram_commit_x();
		if (!mtd_erase(JFFS_NAME)) {
			error("formatting");
			return;
		}
		format = 1;
	}

	sprintf(s, "%d", size);
	p = nvram_get("jffs2_size");
	if ((p == NULL) || (strcmp(p, s) != 0)) {
		if (format) {
			nvram_set("jffs2_size", s);
			nvram_commit_x();
		}
		else if ((p != NULL) && (*p != 0)) {
			error("verifying known size of");
			return;
		}
	}

	if (statfs("/jffs", &sf) == 0) { 
		switch(model) {
			case MODEL_RTAC56S: 
			case MODEL_RTAC56U: 
			case MODEL_RTAC3200:
			case MODEL_DSLAC68U:
			case MODEL_RPAC68U: 
			case MODEL_RTAC68U: 
			case MODEL_RTAC87U:
			case MODEL_RTN18U: 
			case MODEL_RTN65U:
			case MODEL_RTN14U: // it should be better to use LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36)
			{
				if (sf.f_type != 0x73717368 /* squashfs */) {
					// already mounted
					notice_set("jffs", format ? "Formatted" : "Loaded");
					return;
				}
				break;
			}
			default:
			{
	                        if (sf.f_type != 0x71736873 /* squashfs */) {
        	                        // already mounted
                	                notice_set("jffs", format ? "Formatted" : "Loaded");
                        	        return;
				}
				break;
			}
		}
	}

	if (nvram_get_int("jffs2_clean_fs")) {
		if (!mtd_unlock(JFFS2_PARTITION)) {
			error("unlocking");
			return;
		}
	}
	modprobe(JFFS_NAME);
	sprintf(s, MTD_BLKDEV(%d), part);

	if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) {
		if (!mtd_erase(JFFS_NAME)) {
                        error("formatting");
                        return;
                }

		format = 1;
		if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) {
			_dprintf("*** jffs2 2-nd mount error\n");
			//modprobe_r(JFFS_NAME);
			error("mounting");
			return;
		}
	}

#ifdef TEST_INTEGRITY
	int test;

	if (format) {
		if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) {
			stop_jffs2(0);
			error("setting integrity test for");
			return;
		}
	}
	if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) {
		stop_jffs2(0);
		error("testing integrity of");
		return;
	}
#endif

	if (nvram_get_int("jffs2_clean_fs")) {
		_dprintf("Clean /jffs/*\n");
		system("rm -fr /jffs/*");
		nvram_unset("jffs2_clean_fs");
		nvram_commit_x();
	}

	notice_set("jffs", format ? "Formatted" : "Loaded");

	if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) {
		chdir("/jffs");
		system(p);
		chdir("/");
	}
	run_userfile("/jffs", ".asusrouter", "/jffs", 3);

	if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755);
	if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755);
}
Beispiel #24
0
void format_mount_2nd_jffs2(void)
{
        int format = 0;
        char s[256];
        int size;
        int part;
        const char *p;
        struct statfs sf;
        int model = 0;

        if (!wait_action_idle(10)) return;

        if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) return;
	_dprintf("Format 2nd jffs2: %d, %d\n", part, size);

        model = get_model();

        sprintf(s, "%d", size);
        if (statfs(SECOND_JFFS2_PATH, &sf) == 0) {
                switch(model) {
                        case MODEL_RTAC56S:
                        case MODEL_RTAC56U:
			case MODEL_RTAC3200:
                        case MODEL_DSLAC68U:
                        case MODEL_RPAC68U:
                        case MODEL_RTAC68U:
                        case MODEL_RTAC87U:
			case MODEL_RTN18U:
                        case MODEL_RTN65U:
                        case MODEL_RTN14U: // it should be better to use LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36)
                        {
                                if (sf.f_type != 0x73717368 /* squashfs */) {
                                        // already mounted
                                        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");
                                        return;
                                }
                                break;
                        }
                        default:
                        {
                                if (sf.f_type != 0x71736873 /* squashfs */) {
                                        // already mounted
                                        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");
                                        return;
                                }
                                break;
                        }
                }
        }

        if (!mtd_unlock(SECOND_JFFS2_PARTITION)) {
                error("unlocking");
                return;
        }

        modprobe(JFFS_NAME);
        sprintf(s, MTD_BLKDEV(%d), part);
        if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) {
		if( (get_model()==MODEL_RTAC56U || get_model()==MODEL_RTAC56S || get_model()==MODEL_RTAC3200 || get_model()==MODEL_RTAC68U || get_model()==MODEL_RPAC68U || get_model()==MODEL_DSLAC68U || get_model()==MODEL_RTAC87U || get_model()==MODEL_RTN18U) ^ (!mtd_erase(JFFS_NAME)) ){
                        error("formatting");
                        return;
                }

                format = 1;
                if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) {
                        _dprintf("*** jffs2 2-nd mount error\n");
                        //modprobe_r(JFFS_NAME);
                        error("mounting");
                        return;
                }
        }

	sprintf(s, "rm -rf %s/*", SECOND_JFFS2_PATH);
        system(s);

        notice_set("2nd_jffs", format ? "Formatted" : "Loaded");

        if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) {
                chdir(SECOND_JFFS2_PATH);
                system(p);
                chdir("/");
        }
        run_userfile(SECOND_JFFS2_PATH, ".asusrouter", SECOND_JFFS2_PATH, 3);

}
Beispiel #25
0
void ipt_restrictions(void)
{
	char buf[8192];
	char *p, *q;
	int n;
	char *comps, *matches, *http;
	int nrule;
	int blockall;
	char reschain[32];
	char devchain[32];
	char nextchain[32];
	int need_web;
	char *pproto;
	char *dir;
	char *pport;
	int proto;
	char *ipp2p;
	char *layer7;
	char *addr_type, *addr;
	char app[256];
	char ports[256];
	char iptaddr[192];
	int http_file;
	int ex;
	int first;
	int v4v6_ok;

	need_web = 0;
	first = 1;
	nvram_unset("rrules_timewarn");
	nvram_set("rrules_radio", "-1");
	unsched_restrictions();

	for (nrule = 0; nrule < MAX_NRULES; ++nrule) {
		sprintf(buf, "rrule%d", nrule);
		if ((p = nvram_get(buf)) == NULL) continue;
		if (strlen(p) >= sizeof(buf)) continue;
		strcpy(buf, p);

		if ((vstrsep(buf, "|",
			&q,		// 0/1
			&p, &p, &p,	// time (ignored)
			&comps,		//
			&matches,	//
			&http,		//
			&p		// http file match
			) != 8) || (*q != '1')) continue;
		http_file = atoi(p);

		if (comps[0] == '~') {
			// a wireless disable rule, skip
			continue;
		}

		if (first) {
			first = 0;

			ip46t_write(":restrict - [0:0]\n");
#ifdef TCONFIG_IPV6
			if (*wan6face)
				ip6t_write("-A FORWARD -o %s -j restrict\n",
					  wan6face);
#endif
			for (n = 0; n < wanfaces.count; ++n) {
				if (*(wanfaces.iface[n].name)) {
					ipt_write("-A FORWARD -o %s -j restrict\n",
						  wanfaces.iface[n].name);
				}
			}
		// Only mess with DNS requests that are coming in on INPUT
		ip46t_write("-I INPUT 1 ! -i lo -p udp --dport 53 -j restrict\n");
	}

		sprintf(reschain, "rres%02d", nrule);
		ip46t_write(":%s - [0:0]\n", reschain);

		blockall = 1;

		while ((q = strsep(&matches, ">")) != NULL) {
			n = vstrsep(q, "<", &pproto, &dir, &pport, &ipp2p, &layer7, &addr_type, &addr);
			if (n == 5) {
				// fixup for backward compatibility
				addr_type = "0";
			}
			else if (n != 7) continue;

			if ((*dir != 'a') && (*dir != 's') && (*dir != 'd') && (*dir != 'x')) continue;

			// p2p, layer7
			if (!ipt_ipp2p(ipp2p, app)) {
				if (ipt_layer7(layer7, app) == -1) continue;
			}
#ifdef TCONFIG_IPV6
			v4v6_ok = ((*app) ? 0 : IPT_V6) | IPT_V4;
#else
			v4v6_ok = IPT_V4;
#endif

			// dest ip/domain address
			if ((*addr_type == '1') || (*addr_type == '2')) {
				v4v6_ok = ipt_addr(iptaddr, sizeof(iptaddr), addr, (*addr_type == '1') ? "dst" : "src", v4v6_ok, (v4v6_ok == IPT_V4), "restrictions", NULL);
				if (!v4v6_ok)
					continue;
			}
			else {
				iptaddr[0] = 0;
			}

			blockall = 0;

			// proto & ports
			proto = atoi(pproto);
			if (proto <= -2) {
				// shortcut if any proto+any port
				ip46t_flagged_write(v4v6_ok, "-A %s %s %s -j %s\n", reschain, iptaddr, app, chain_out_drop);
				continue;
			}
			else if ((proto == 6) || (proto == 17) || (proto == -1)) {
				if ((*dir != 'a') && (*pport)) {
					if ((*dir == 'x') || (strchr(pport, ','))) {
						// use multiport for multiple ports or src-or-dst type matches
						snprintf(ports, sizeof(ports), "-m multiport --%sports %s", (*dir == 'x') ? "" : dir, pport);
					}
					else {
						// else, use built-in
						snprintf(ports, sizeof(ports), "--%sport %s", dir, pport);
					}
				}
				else {
					ports[0] = 0;
				}
				if (proto != 17)
					ip46t_flagged_write(v4v6_ok, "-A %s -p tcp %s %s %s -j %s\n", reschain, ports, iptaddr, app, chain_out_drop);
				if (proto != 6)
					ip46t_flagged_write(v4v6_ok, "-A %s -p udp %s %s %s -j %s\n", reschain, ports, iptaddr, app, chain_out_drop);
			}
			else {
				ip46t_flagged_write(v4v6_ok, "-A %s -p %d %s %s -j %s\n", reschain, proto, iptaddr, app, chain_out_drop);
			}
		}

		//

		p = http;
		while (*p) {
			if ((*p == '\t') || (*p == '\r') || (*p == '\n') || (*p == '"')) *p = ' ';
			++p;
		}
		while ((n = strlen(http)) > 0) {
			if (n >= 511) {
				p = http + 510;
				while ((p > http) && (*p != ' ')) --p;
				if (p <= http) {
					// too long
					break;
				}
				*p = 0;
			}
			else p = NULL;
			ip46t_write("-A %s -p tcp -m web --hore \"%s\" -j %s\n", reschain, http, chain_out_reject);
			need_web = 1;
			blockall = 0;
			if (p == NULL) break;
			http = p + 1;
		}


		//
		app[0] = 0;
		if (http_file & 1) strcat(app, ".ocx$ .cab$ ");
		if (http_file & 2) strcpy(app, ".swf$ ");
		if (http_file & 4) strcat(app, ".class$ .jar$");
		if (app[0]) {
			ip46t_write("-A %s -p tcp -m multiport --dports %s -m web --path \"%s\" -j %s\n",
				reschain, nvram_safe_get("rrulewp"), app, chain_out_reject);
			need_web = 1;
			blockall = 0;
		}

		if (*comps) {
			if (blockall) {
				ip46t_write("-X %s\n", reschain);	// chain not needed
				sprintf(nextchain, "-j %s", chain_out_drop);
			}
			else {
				sprintf(nextchain, "-g %s", reschain);
			}

			ex = 0;
			sprintf(devchain, "rdev%02d", nrule);
			ip46t_write(":%s - [0:0]\n", devchain);
			while ((q = strsep(&comps, ">")) != NULL) {
				if (*q == 0) continue;
				if (*q == '!') {
					ex = 1;
					continue;
				}
#ifdef TCONFIG_IPV6
				v4v6_ok = IPT_V6 | IPT_V4;
#else
				v4v6_ok = IPT_V4;
#endif
				if (sscanf(q, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
					   iptaddr, iptaddr, iptaddr, iptaddr, iptaddr, iptaddr) == 6) {
					snprintf(iptaddr, sizeof(iptaddr), "-m mac --mac-source %s", q);
				}
				else {
					v4v6_ok = ipt_addr(iptaddr, sizeof(iptaddr), q, "src", v4v6_ok, (v4v6_ok == IPT_V4), "restrictions", "filtering");
					if (!v4v6_ok)
						continue;
				}
				ip46t_flagged_write(v4v6_ok,
					"-A %s %s %s\n", devchain, iptaddr, ex ? "-j RETURN" : nextchain);
			}

			if (ex) {
				ip46t_write("-A %s %s\n", devchain, nextchain);
			}
		}
		else if (blockall) {
			ip46t_write("-A %s -j %s\n", reschain, chain_out_drop);
		}
	}

	nvram_set("rrules_activated", "0");

	if (need_web)
		modprobe("ipt_web");
}
Beispiel #26
0
void start_jffs2(void)
{
	if (!nvram_match("jffs2_on", "1")) {
		notice_set("jffs", "");
		return;
	}

	int format = 0;
	char s[256];
	int size;
	int part;
	const char *p;
	struct statfs sf;

	if (!wait_action_idle(10)) return;

	if (!mtd_getinfo("jffs2", &part, &size)) return;

_dprintf("*** jffs2: %d, %d\n", part, size);
	if (nvram_match("jffs2_format", "1")) {
		nvram_set("jffs2_format", "0");

		if (!mtd_erase("jffs2")) {
			error("formatting");
			return;
		}

		format = 1;
	}

	sprintf(s, "%d", size);
	p = nvram_get("jffs2_size");
	if ((p == NULL) || (strcmp(p, s) != 0)) {
		if (format) {
			nvram_set("jffs2_size", s);
			nvram_commit_x();
		}
		else if ((p != NULL) && (*p != 0)) {
			error("verifying known size of");
			return;
		}
	}

	if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x71736873 /* squashfs */)) {
		// already mounted
		notice_set("jffs", format ? "Formatted" : "Loaded");
		return;
	}
	if (!mtd_unlock("jffs2")) {
		error("unlocking");
		return;
	}
	modprobe(JFFS_NAME);
	sprintf(s, MTD_BLKDEV(%d), part);
	if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) {
_dprintf("*** jffs2 mount error\n");
		//modprobe_r(JFFS_NAME);
		error("mounting");
		return;
	}
#ifdef TEST_INTEGRITY
	int test;

	if (format) {
		if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) {
			stop_jffs2();
			error("setting integrity test for");
			return;
		}
	}
	if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) {
		stop_jffs2();
		error("testing integrity of");
		return;
	}
#endif

	notice_set("jffs", format ? "Formatted" : "Loaded");

	if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) {
		chdir("/jffs");
		system(p);
		chdir("/");
	}
	run_userfile("/jffs", ".asusrouter", "/jffs", 3);

	if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755);
	if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755);

}