예제 #1
0
int32_t main(int32_t argc, char ** argv)
{
    int32_t i = 0;

    for(i=0; i<argc; i++)
        DEBUG("argv[%d]:%s\n", i, argv[i]);


    if (argc < 2)
        return usage(OK);

    nvram_mtd_size = mtd_size(NVRAM_MTD_NAME);
    DEBUG("nvram_mtd_size = %u\n", nvram_mtd_size);
    if (nvram_mtd_size <= 0)
        return NG;

    if (nvram_filecache(NVRAM_CACHE_FILE) != OK)
        return NG;

    if (nvram_parse(NULL, NVRAM_CACHE_FILE) != OK)
        return NG;

    if (0 == strcasecmp(argv[1], "commit"))
    {
        return nvram_commit(1);
    }
    else if (0 == strcasecmp(argv[1], "set"))
    {
        if (argc == 5)
            return nvram_set(argv[2], argv[3], argv[4]);
        else
            return usage(NG);
    }
    else if (0 == strcasecmp(argv[1], "get"))
    {
        if (argc < 4)
            return usage(NG);
        else
            nvram_get(argv[2], argv[3]);
    }
    else if (0 == strcasecmp(argv[1], "del"))
    {
        if (argc < 4)
            return usage(NG);
        else
            nvram_del(argv[2], argv[3]);
    }
    else if (0 == strcasecmp(argv[1], "show"))
    {
        if (argc < 3)
            return nvram_show(NULL);
        else
            return nvram_show(argv[2]);
    }
    else if (0 == strcasecmp(argv[1], "clear"))
    {
        return nvram_clear(argv[2]);
    }
    else if (0 == strcasecmp(argv[1], "reset"))
    {
        if (argc < 4)
            return usage(NG);
        else
            return nvram_reset(argv[2], argv[3]);
    }
    else
        return usage(NG);

    return OK;
}
예제 #2
0
파일: nvram.c 프로젝트: jing-git/rt-n56u
/* NVRAM utility */
int
main(int argc, char **argv)
{
	char *name, *value;
	int ret = 0;

	/* Skip program name */
	--argc;
	++argv;

	if (!*argv)
		usage();

	/* Process the remaining arguments. */
	for (; *argv; argv++) {
		if (!strcmp(*argv, "get")) {
			if (*++argv) {
				if ((value = nvram_get(*argv)))
					puts(value);
			}
		}
		else if (!strcmp(*argv, "settmp")) {
			if (*++argv) {
				char buf[1024];
				strncpy(value = buf, *argv, sizeof(buf)-1);
				name = strsep(&value, "=");
				nvram_set_temp(name, value);
			}
		}
		else if (!strcmp(*argv, "set")) {
			if (*++argv) {
				char buf[1024];
				strncpy(value = buf, *argv, sizeof(buf)-1);
				name = strsep(&value, "=");
				nvram_set(name, value);
			}
		}
		else if (!strcmp(*argv, "unset")) {
			if (*++argv)
				nvram_unset(*argv);
		}
		else if (!strcmp(*argv, "clear")) {
			nvram_clear();
		}
		else if (!strcmp(*argv, "commit")) {
			nvram_commit();
			break;
		}
		else if (!strcmp(*argv, "save")) {
			if (*++argv)
				ret |= nvram_save(*argv);
			break;
		}
		else if (!strcmp(*argv, "restore")) {
			if (*++argv)
				ret |= nvram_restore(*argv);
			break;
		}
		else if (!strcmp(*argv, "show")) {
			ret |= nvram_show(0);
			break;
		}
		else if (!strcmp(*argv, "showall")) {
			ret |= nvram_show(1);
			break;
		}
		if (!*argv)
			break;
	}

	return ret;
}
예제 #3
0
int32_t main(int32_t argc, char ** argv)
{
#if 0
    int32_t i = 0;

    for(i=0; i<argc; i++)
        DEBUG("argv[%d]:%s\n", i, argv[i]);
#endif

    if (argc < 2)
        return usage(OK);

    if (nvram_filecache(NVRAM_CACHE_FILE) != OK)
        return NG;

    if (nvram_parse(NULL, NVRAM_CACHE_FILE) != OK)
        return NG;

    if (0 == strcasecmp(argv[1], "commit"))
    {
        return nvram_commit(1);
    }
    else if (0 == strcasecmp(argv[1], "set"))
    {
        if (argc == 5)
            return nvram_set(argv[2], argv[3], argv[4]);
        else
            return usage(NG);
    }
    else if (0 == strcasecmp(argv[1], "get"))
    {
        if (argc < 4)
            return usage(NG);
        else
            nvram_get(argv[2], argv[3]);
    }
    else if (0 == strcasecmp(argv[1], "del"))
    {
        if (argc < 4)
            return usage(NG);
        else
            nvram_del(argv[2], argv[3]);
    }
    else if (0 == strcasecmp(argv[1], "show"))
    {
        if (argc < 3)
            return nvram_show(NULL);
        else
            return nvram_show(argv[2]);
    }
    else if (0 == strcasecmp(argv[1], "clear"))
    {
        return nvram_clear(argv[2]);
    }
    else if (0 == strcasecmp(argv[1], "layout"))
    {
        return nvram_layout();
    }
    else if (0 == strcasecmp(argv[1], "loadfile"))
    {
        if (argc < 4)
            return usage(NG);
        else
            return nvram_loadfile(argv[2], argv[3]);
    }
    else
        return usage(NG);

    return OK;
}
예제 #4
0
int main(int argc, char *argv[])
{
	char *cmd;

	if (argc < 2)
		usage(argv[0]);

	//call nvram_get or nvram_set
	if ((cmd = strrchr(argv[0], '/')) != NULL)
		cmd++;
	else
		cmd = argv[0];
	if (!strncmp(cmd, "nvram_get", 10))
		return ra_nv_get(argc, argv);
	else if (!strncmp(cmd, "nvram_set", 10))
		return ra_nv_set(argc, argv);

	if (argc == 2) {
		if (!strncmp(argv[1], "rt2860_nvram_show", 18))
			nvram_show(RT2860_NVRAM);
#if defined (CONFIG_RTDEV_MII) || defined (CONFIG_RTDEV_USB) || defined (CONFIG_RTDEV_PCI)|| \
	defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
		else if (!strncmp(argv[1], "rtdev_nvram_show", 17))
			nvram_show(RTDEV_NVRAM);
#endif
#ifdef CONFIG_DUAL_IMAGE
		else if (!strncmp(argv[1], "uboot_nvram_show", 17))
			nvram_show(UBOOT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_STA_WPA_SUPPLICANT
		else if (!strncmp(argv[1], "cert_nvram_show", 16))
			nvram_show(CERT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_AP_WAPI
		else if (!strncmp(argv[1], "wapi_nvram_show", 16))
			nvram_show(WAPI_NVRAM);
#endif
		else
			usage(argv[0]);
	} else if (argc == 3) {
		/* TODO: <cmd> gen 2860ap */
		if (!strncasecmp(argv[1], "gen", 4) ||
		    !strncasecmp(argv[1], "make_wireless_config", 21)) {
			if (!strncmp(argv[2], "2860", 5) ||
			    !strncasecmp(argv[2], "rt2860", 7)) //b-compatible
				gen_config(RT2860_NVRAM);
#if defined (CONFIG_RTDEV_MII) || defined (CONFIG_RTDEV_USB) || defined (CONFIG_RTDEV_PCI) || \
	defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
			else if (!strncasecmp(argv[2], "rtdev", 6))
				gen_config(RTDEV_NVRAM);
#endif
#ifdef CONFIG_DUAL_IMAGE
			else if (!strncasecmp(argv[2], "uboot", 6))
				printf("No support of gen command of uboot parameter.\n");
#endif
#ifdef CONFIG_RT2860V2_STA_WPA_SUPPLICANT
			else if (!strncmp(argv[2], "cert", 5))
				gen_cert(CERT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_AP_WAPI
			else if (!strncmp(argv[2], "wapi", 5))
				gen_cert(WAPI_NVRAM);
#endif
			else
				usage(argv[0]);
		} else if (!strncasecmp(argv[1], "show", 5)) {
			if (!strncmp(argv[2], "2860", 5) ||
			    !strncasecmp(argv[2], "rt2860", 7)) //b-compatible
				nvram_show(RT2860_NVRAM);
#if defined (CONFIG_RTDEV_MII) || defined (CONFIG_RTDEV_USB) || defined (CONFIG_RTDEV_PCI) || \
	defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
			else if (!strncasecmp(argv[2], "rtdev", 6))
				nvram_show(RTDEV_NVRAM);
#endif
#ifdef CONFIG_DUAL_IMAGE
			else if (!strncasecmp(argv[2], "uboot", 6))
				nvram_show(UBOOT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_STA_WPA_SUPPLICANT
			else if (!strncasecmp(argv[2], "cert", 5))
				nvram_show(CERT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_AP_WAPI
			else if (!strncasecmp(argv[2], "wapi", 5))
				nvram_show(WAPI_NVRAM);
#endif
			else
				usage(argv[0]);
		} else if(!strncasecmp(argv[1], "clear", 6)) {
			if (!strncmp(argv[2], "2860", 5) || 
			    !strncasecmp(argv[2], "rt2860", 7)) //b-compatible
				nvram_clear(RT2860_NVRAM);
#if defined (CONFIG_RTDEV_MII) || defined (CONFIG_RTDEV_USB) || defined (CONFIG_RTDEV_PCI) || \
	defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
			else if (!strncasecmp(argv[2], "rtdev", 6))
				nvram_clear(RTDEV_NVRAM);
#endif
#ifdef CONFIG_DUAL_IMAGE
			else if (!strncasecmp(argv[2], "uboot", 6))
				nvram_clear(UBOOT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_STA_WPA_SUPPLICANT
			else if (!strncasecmp(argv[2], "cert", 5))
				nvram_clear(CERT_NVRAM);
#endif
#ifdef CONFIG_RT2860V2_AP_WAPI
			else if (!strncasecmp(argv[2], "wapi", 5))
				nvram_clear(WAPI_NVRAM);
#endif
			else
				usage(argv[0]);
		} else
			usage(argv[0]);
	} else if (argc == 4) {
		if (!strncasecmp(argv[1], "renew", 6)) {
			if (!strncmp(argv[2], "2860", 5) ||
			    !strncasecmp(argv[2], "rt2860", 7)) //b-compatible
				renew_nvram(RT2860_NVRAM, argv[3]);
#if defined (CONFIG_RTDEV_MII) || defined (CONFIG_RTDEV_USB) || defined (CONFIG_RTDEV_PCI) || \
	defined (CONFIG_RT2561_AP) || defined (CONFIG_RT2561_AP_MODULE)
			else if (!strncasecmp(argv[2], "rtdev", 6))
				renew_nvram(RTDEV_NVRAM, argv[3]);
#endif
#ifdef CONFIG_DUAL_IMAGE
			else if (!strncasecmp(argv[2], "uboot", 6))
				printf("No support of renew command of uboot parameter.\n");
#endif
		} else
			usage(argv[0]);
	} else
		usage(argv[0]);
	return 0;
}