Exemplo n.º 1
0
static int
#else
static long
#endif
dev_nvram_ioctl(
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
	struct inode *inode, 
#endif
	struct file *file, 
	unsigned int cmd, 
	unsigned long arg)
{
	if (cmd != NVRAM_MAGIC)
		return -EINVAL;

#ifndef NLS_XFR
        return nvram_commit();
#else
        if(arg == 0)
                return nvram_commit();
        else {
                if(nvram_xfr((char *)arg)==NULL) return -EFAULT;
                else return 0;
        }
#endif  // NLS_XFR
}
Exemplo n.º 2
0
static int
dev_nvram_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	if (cmd != NVRAM_MAGIC)
		return -EINVAL;

#ifndef NLS_XFR
	return nvram_commit();
#else
	if(arg == 0)
		return nvram_commit();
	else
		return nvram_xfr((char *)arg);
#endif	// NLS_XFR
}
Exemplo n.º 3
0
static void QoSDeleteRules(webs_t wp, char_t *path, char_t *query, char *which_rule)
{
    int i, j, rule_count;
    char_t name_buf[16];
    char_t *value;
    int *deleArray;

    char *new_rules;
    const char *rules = nvram_bufget(RT2860_NVRAM, which_rule);
    if(!rules || !strlen(rules) )
        return;

    rule_count = getRuleNums(rules);
    if(!rule_count)
        return;

    deleArray = (int *)malloc(rule_count * sizeof(int));
    if(!deleArray)
        return;

    new_rules = strdup(rules);
    if(!new_rules) {
        free(deleArray);
        return;
    }

    for(i=0, j=0; i< rule_count; i++) {
        snprintf(name_buf, 16, "del_qos_%d", i);
        value = websGetVar(wp, name_buf, NULL);
        if(value) {
            deleArray[j++] = i;
        }
    }
    if(!j) {
        free(deleArray);
        free(new_rules);
        websHeader(wp);
        websWrite(wp, T("You didn't select any rules to delete.<br>\n"));
        websFooter(wp);
        websDone(wp, 200);
        return;
    }

    deleteNthValueMulti(deleArray, j, new_rules, ';');

    nvram_set(RT2860_NVRAM, which_rule, new_rules);
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

    websHeader(wp);
    websWrite(wp, T("Delete Rules:\n") );
    for(i=0; i<j; i++)
        websWrite(wp, "%d ", (deleArray[i] + 1) );

    websFooter(wp);
    websDone(wp, 200);
    free(deleArray);
    free(new_rules);
}
Exemplo n.º 4
0
static void nvram_commit_safe()
{
	if (nvram_get_int("nvram_manual") == 1)
		return;
	
	nvram_commit();
}
Exemplo n.º 5
0
int gen_config(int mode)
{
	FILE *fp;
	int  i, ssid_num = 1;
	char tx_rate[16], wmm_enable[16];

	nvram_init(mode);

	/*
	nvram_bufset(mode, "SystemName", "RalinkAP");
	nvram_bufset(mode, "ModuleName", "RT2860");
	nvram_commit(mode);
	*/
	if (mode == RT2860_NVRAM) {
		unsigned char temp[2], buf[4];
		flash_read_NicConf(buf);
		sprintf(temp, "%x", buf[1]);
		nvram_bufset(mode, "RFICType", temp);
		sprintf(temp, "%x", buf[0]&0xf0>>4);
		if (atoi(temp) < atoi(nvram_bufget(mode, "HT_TxStream")))
			nvram_bufset(mode, "HT_TxStream", temp);
		nvram_bufset(mode, "TXPath", temp);
		sprintf(temp, "%x", buf[0]&0x0f);
		if (atoi(temp) < atoi(nvram_bufget(mode, "HT_RxStream")))
			nvram_bufset(mode, "HT_RxStream", temp);
		nvram_bufset(mode, "RXPath", temp);
		nvram_commit(mode);
	}
Exemplo n.º 6
0
int nvram_import(char *FileName)
{
	char *value,*name;
	char line[409600];
    FILE *fp_ptr;

	if(exists(FileName)){
		fp_ptr=fopen(FileName,"r+");
		while(fgets(line,sizeof(line),fp_ptr))
		{
			value=line;
			name=line;
			strsep(&value,"=");
			if (value)
			{
				clear_end(value);
				if(name)
				{
					nvram_set(name,value);
					printf("%s = %s\n", name, value);
				}
			}
		}
		fclose(fp_ptr);
		nvram_commit();
		return 0;
	}
	else{
		printf("\nFile \"%s\" does not exist !!!\n", FileName);
		return -1;
	}
}
Exemplo n.º 7
0
ssize_t nvramdrv_ioctl(struct inode * inode, struct file * file,
	unsigned int cmd, unsigned long buf)
#endif
{
	int index, len;
	const char *p;
	nvram_ioctl_t *nvr;
	char *value;


	switch (cmd) {
		case NVRAM_IOCTL_GET:
			nvr = (nvram_ioctl_t __user *)buf;
			p = nvram_get(nvr->index, nvr->name);
			if (p == NULL)
				p = "";

			if (copy_to_user(nvr->value, p, strlen(p) + 1))
				return -EFAULT;
			break;

		case NVRAM_IOCTL_GETALL:
			nvr = (nvram_ioctl_t __user *)buf;
			//index = nvr->index;
			index = 0;
			len = fb[index].flash_max_len - sizeof(fb[index].env.crc);

			if (nvram_getall(index, fb[index].env.data) == 0) {
				if (copy_to_user(nvr->value, fb[index].env.data, len))
					return -EFAULT;
			}
			break;
		case NVRAM_IOCTL_SET:
			nvr = (nvram_ioctl_t *)buf;		
			value = (char *)kmalloc(MAX_VALUE_LEN, GFP_KERNEL);
			if (!value)
				return -ENOMEM;

			if (copy_from_user(value, nvr->value, strlen(nvr->value) + 1)) {
				kfree(value);
				return -EFAULT;
			}

			nvram_set(nvr->index, nvr->name, value);
			kfree(value);
			break;

		case NVRAM_IOCTL_COMMIT:
			nvr = (nvram_ioctl_t __user *)buf;
			nvr->useFile = nvram_commit(nvr->index);
			break;
		case NVRAM_IOCTL_CLEAR:
			nvr = (nvram_ioctl_t __user *)buf;
			nvram_clear(nvr->index);
		default:
			printk(KERN_CRIT "Unsupported ioctl(%d) on nvram\n", cmd);
			break;
	}
	return 0;
}
Exemplo n.º 8
0
static void iTunesSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *enable, *dir_path, *name;

	// fetch from web input
	enable = websGetVar(wp, T("enabled"), T("0"));
	dir_path = websGetVar(wp, T("dir_path"), T(""));
	name = websGetVar(wp, T("srv_name"), T(""));
	// set to nvram
	nvram_bufset(RT2860_NVRAM, "iTunesEnable", enable);
	nvram_bufset(RT2860_NVRAM, "iTunesDir", dir_path);
	nvram_bufset(RT2860_NVRAM, "iTunesSrvName", name);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("killall mt-daapd; killall mDNSResponder");
	if (strcmp(enable, "1") == 0)
		doSystem("config-iTunes.sh \"%s\" \"%s\" \"%s\"", 
				 name,
				 nvram_bufget(RT2860_NVRAM, "Password"),
				 dir_path);

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>iTunes Server Settings</h2><br>\n"));
	websWrite(wp, T("capability: %s<br>\n"), enable);
	websWrite(wp, T("srv_name: %s<br>\n"), name);
	websWrite(wp, T("media library: %s<br>\n"), dir_path);
	websFooter(wp);
	websDone(wp, 200);
}
Exemplo n.º 9
0
/* goform/storageAdm */
static void storageAdm(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit = websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		char_t *user_select;
		char feild[20];

		feild[0] = '\0';
		user_select = websGetVar(wp, T("storage_user_select"), T(""));
		sprintf(feild, "User%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		doSystem("rm -rf \"%s/home/%s\"", first_part, nvram_bufget(RT2860_NVRAM, feild));
		sprintf(feild, "User%sPasswd", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		sprintf(feild, "FtpUser%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		sprintf(feild, "SmbUser%s", user_select);
		nvram_bufset(RT2860_NVRAM, feild, "");
		nvram_commit(RT2860_NVRAM);
		doSystem("storage.sh admin");
	}
	else if (0 == strcmp(submit, "apply"))
	{
		initUSB();
	}
	websRedirect(wp, "usb/STORAGEuser_admin.asp");
}
Exemplo n.º 10
0
/* goform/webcamra */
static void webcamra(webs_t wp, char_t *path, char_t *query)
{
	char_t *enable, *resolution, *fps, *port;

	// fetch from web input
	enable = websGetVar(wp, T("enabled"), T(""));
	resolution = websGetVar(wp, T("resolution"), T(""));
	fps = websGetVar(wp, T("fps"), T(""));
	port = websGetVar(wp, T("port"), T(""));

	// set to nvram
	nvram_bufset(RT2860_NVRAM, "WebCamEnabled", enable);
	nvram_bufset(RT2860_NVRAM, "WebCamResolution", resolution);
	nvram_bufset(RT2860_NVRAM, "WebCamFPS", fps);
	nvram_bufset(RT2860_NVRAM, "WebCamPort", port);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("killall uvc_stream");
	if (0 == strcmp(enable, "1"))
	{
		doSystem("uvc_stream -r %s -f %s -p %s -b", 
				  resolution, fps, port);
	}

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>Web Camera Settings</h2><br>\n"));
	websWrite(wp, T("enabled: %s<br>\n"), enable);
	websWrite(wp, T("resolution: %s<br>\n"), resolution);
	websWrite(wp, T("fps: %s<br>\n"), fps);
	websWrite(wp, T("port: %s<br>\n"), port);
	websFooter(wp);
	websDone(wp, 200);
}
Exemplo n.º 11
0
int32_t nvram_set(char * section, char * key, char * value)
{
    API();
    if (OK == _nvram_buf_set(section, key, value))
        return nvram_commit(0);
    return NG;
}
Exemplo n.º 12
0
/*
 * Set the ip configuration index given the eth name
 * Updates both wlXX_ipconfig_index and lanYY_ifname.
 *
 * @param	eth_ifname 	pointer to eth interface name
 * @return	0 if successful -1 if not.
 */
int
set_ipconfig_index(char *eth_ifname, int index)
{
	char varname[255];
	char varval[16];
	char wl_ifname[NVRAM_MAX_PARAM_LEN];

	/* Bail if we get a NULL or empty string */

	if (!eth_ifname) return -1;
	if (!*eth_ifname) return -1;

	if (index >= MAX_NVPARSE) return -1;

	/* Look up wl name from the eth name only if the name contains
	   eth
	*/

	if (osifname_to_nvifname(eth_ifname, wl_ifname, sizeof(wl_ifname)) != 0)
		return -1;

	snprintf(varname, sizeof(varname), "%s_ipconfig_index", wl_ifname);
	snprintf(varval, sizeof(varval), "%d", index);
	nvram_set(varname, varval);

	snprintf(varname, sizeof(varname), "lan%d_ifname", index);
	nvram_set(varname, wl_ifname);

	nvram_commit();

	return 0;
}
Exemplo n.º 13
0
/* goform/StorageEditUser */
static void StorageEditUser(webs_t wp, char_t *path, char_t *query)
{
	char_t *index, *password; 
	char_t *user_ftp_enable, *user_smb_enable;
	char feild[20];

	feild[0] = '\0';
	// fetch from web input
	index = websGetVar(wp, T("hiddenIndex"), T(""));
	password = websGetVar(wp, T("edituser_pw"), T(""));
	user_ftp_enable = websGetVar(wp, T("edituser_ftp"), T(""));
	user_smb_enable = websGetVar(wp, T("edituser_smb"), T(""));
	/*
	DEBUG(index);
	DEBUG(password);
	DEBUG(user_ftp_enable);
	DEBUG(user_smb_enable);
	*/

	// set to nvram
	sprintf(feild, "User%sPasswd", index);
	nvram_bufset(RT2860_NVRAM, feild, password);
	sprintf(feild, "FtpUser%s", index);
	// DEBUG(feild);
	nvram_bufset(RT2860_NVRAM, feild, user_ftp_enable);
	sprintf(feild, "SmbUser%s", index);
	// DEBUG(feild);
	nvram_bufset(RT2860_NVRAM, feild, user_smb_enable);
	nvram_commit(RT2860_NVRAM);
	doSystem("storage.sh admin");
		
	websRedirect(wp, "usb/STORAGEuser_admin.asp");
}
Exemplo n.º 14
0
static int
speedtest(int dl_enable, int ul_enable)
{
	int i;
	client_config_t client;
	server_config_t servers[CLOSEST_SERVERS_NUM];
	server_config_t best_server;

	for (i = 0; i < CLOSEST_SERVERS_NUM; i++) {
		init_server(&servers[i]);
	}
	init_server(&best_server);
	init_client(&client);

	if (get_speedtest_config(&client)) {
		fprintf(stderr, "get_speedtest_config error!\n");
		nvram_set("speedtest_running", "2");
		return -1;
	}

	if (get_nearest_servers(&client, servers)) {
		fprintf(stderr, "get_nearest_servers error!\n");
		nvram_set("speedtest_running", "2");
		return -1;
	}

	client_free(&client);

	if (get_lowest_latency_server(servers, &best_server)) {
		fprintf(stderr, "get_lowest_latency_server error!\n");
		nvram_set("speedtest_running", "2");
		return -1;
	}

	if (dl_enable == 1) {
		if (test_download_speed(&best_server)) {
			fprintf(stderr, "test_download_speed error!\n");
			nvram_set("speedtest_running", "2");
			return -1;
		}
	}

	if (ul_enable == 1) {
		finished = (double)0;
		if (test_upload_speed(&best_server)) {
			fprintf(stderr, "test_upload_speed error!\n");
			nvram_set("speedtest_running", "2");
			return -1;
		}
	}

	for (i = 0; i < CLOSEST_SERVERS_NUM; i++) {
		server_free(&servers[i]);
	}

	nvram_set("speedtest_running", "1");
	nvram_commit();
	return 0;
}
Exemplo n.º 15
0
int main(int argc, char **argv)
{
	/* 
	 * Run it in the background 
	 */
	switch (fork()) {
	case -1:
		// can't fork
		exit(0);
		break;
	case 0:
		/* 
		 * child process 
		 */
		// fork ok
		(void)setsid();
		break;
	default:
		/* 
		 * parent process should just die 
		 */
		_exit(0);
	}
	int timeout = atoi(argv[1]);
	while (timeout) {
		FILE *fp = fopen("/tmp/.wpsdone", "rb");
		if (fp) {
			killall("ledtool", SIGKILL);
			nvram_set("wps_status", "1");
			nvram_commit();
			sysprintf("rm -f /tmp/.wpsdone");
			fclose(fp);
			led_control(LED_SES, LED_ON);
			break;
		}
		timeout--;
		sleep(1);
	}
	if (!timeout) {
		killall("ledtool", SIGKILL);
		nvram_set("wps_status", "1");
		nvram_commit();
		system("ledtool 1800 3");
	}
	return 0;
}				// end main
Exemplo n.º 16
0
int32_t nvram_del(char * section, char * key)
{
    API();

    if (OK == _nvram_buf_del(section, key))
        return nvram_commit(0);
    return NG;
}
Exemplo n.º 17
0
/* sync nvram hash table with devinfo nvram hash table, and commit nvram */
int
BCMINITFN(devinfo_nvram_sync)(void)
{
	_nvram_hash_sync();
	nvram_commit();

	return (0);
}
Exemplo n.º 18
0
static int
dev_nvram_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	if (cmd != NVRAM_MAGIC)
		return -EINVAL;

	return nvram_commit();
}
Exemplo n.º 19
0
/* goform/storageSmbSrv */
static void storageSmbSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit =  websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		int index;
		FILE *fp;
		char smb_config_file[25];

		// strcpy(smb_config_file, "/var/.smb_config");
		sprintf(smb_config_file, "%s/.smb_config", first_part);
		fp = fopen(smb_config_file, "w");

		if (NULL == fp) {
			perror(__FUNCTION__);
			return;
		}

		index = atoi(websGetVar(wp, T("selectIndex"), T("")));
		// fprintf(stderr, "before set bitmap: %x%x%x\n", smb_conf.bitmap[2], smb_conf.bitmap[1], smb_conf.bitmap[0]);
		smb_conf.bitmap[index/32] &= ~(1<<(index%32));
		// fprintf(stderr, "after set bitmap: %x%x%x\n", smb_conf.bitmap[2], smb_conf.bitmap[1], smb_conf.bitmap[0]);
		smb_conf.count--;
		// fprintf(stderr, "smb dir count: %d\n", smb_conf.count);
		fwrite(&smb_conf, sizeof(struct smb_dir_config), 1, fp);
		fclose(fp);
		websRedirect(wp, "usb/SAMBAsmbsrv.asp");
	} 
	else if (0 == strcmp(submit, "apply"))
	{
		char_t *smb_enable, *wg, *netbios;
		
		// fetch from web input
		smb_enable = websGetVar(wp, T("smb_enabled"), T(""));
		wg = websGetVar(wp, T("smb_workgroup"), T(""));
		netbios = websGetVar(wp, T("smb_netbios"), T(""));

		// set to nvram
		nvram_bufset(RT2860_NVRAM, "SmbEnabled", smb_enable);
		nvram_bufset(RT2860_NVRAM, "HostName", wg);
		nvram_bufset(RT2860_NVRAM, "SmbNetBIOS", netbios);
		nvram_commit(RT2860_NVRAM);

		// setup device
		SetSambaSrv();

		// debug print
		websHeader(wp);
		websWrite(wp, T("<h2>smb_enabled: %s</h2><br>\n"), smb_enable);
		websWrite(wp, T("smb_workgroup: %s<br>\n"), wg);
		websWrite(wp, T("smb_netbios: %s<br>\n"), netbios);
		websFooter(wp);
		websDone(wp, 200);
	}
}
Exemplo n.º 20
0
int ralink_nvram_ioctl(struct inode *inode, struct file *file, unsigned int req,
		unsigned long arg)
#endif
{
	int index, len;
	const char *p;
	nvram_ioctl_t *nvr;
	char *value;


	switch (req) {
	case RALINK_NVRAM_IOCTL_GET:
		nvr = (nvram_ioctl_t __user *)arg;
		p = nvram_get(nvr->index, nvr->name);
		if (p == NULL)
			p = "";

		if (copy_to_user(nvr->value, p, strlen(p) + 1))
			return -EFAULT;
		break;
	case RALINK_NVRAM_IOCTL_GETALL:
		nvr = (nvram_ioctl_t __user *)arg;
		index = nvr->index;
		len = fb[index].flash_max_len - sizeof(fb[index].env.crc);
			
		if (nvram_getall(index, fb[index].env.data) == 0) {
			if (copy_to_user(nvr->value, fb[index].env.data, len))
				return -EFAULT;
		}
		break;
	case RALINK_NVRAM_IOCTL_SET:
		nvr = (nvram_ioctl_t *)arg;		
		value = (char *)kmalloc(MAX_VALUE_LEN, GFP_KERNEL);
		if (!value)
			return -ENOMEM;

		if (copy_from_user(value, nvr->value, strlen(nvr->value) + 1)) {
			kfree(value);
			return -EFAULT;
		}

		nvram_set(nvr->index, nvr->name, value);
		kfree(value);
		break;

	case RALINK_NVRAM_IOCTL_COMMIT:
		nvr = (nvram_ioctl_t __user *)arg;
		nvram_commit(nvr->index);
		break;
	case RALINK_NVRAM_IOCTL_CLEAR:
		nvr = (nvram_ioctl_t __user *)arg;
		nvram_clear(nvr->index);
	default:
		break;
	}

	return 0;
}
Exemplo n.º 21
0
int nvram_set(int index, char *name, char *value)
{
    //LIBNV_PRINT("--> nvram_set\n");

    if (-1 == nvram_bufset(index, name, value))

        return -1;
    return nvram_commit(index);
}
Exemplo n.º 22
0
/* NVRAM utility */
int
main(int argc, char **argv)
{
	char *name, *value;

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

	if (!*argv) 
		usage();

	/* Process the remaining arguments. */
	for (; *argv; argv++) {
		if (!strncmp(*argv, "get", 3)) {
			if (*++argv) {
				if ((value = nvram_get(*argv)))
					puts(value);
			}
		}
		else if (!strncmp(*argv, "set", 3)) {
			if (*++argv) {
				char buf[1024];
				strncpy(value = buf, *argv, sizeof(buf)-1);
				name = strsep(&value, "=");
				nvram_set(name, value);
			}
		}
		else if (!strncmp(*argv, "unset", 5)) {
			if (*++argv)
				nvram_unset(*argv);
		}
		else if (!strncmp(*argv, "commit", 6)) {
			nvram_commit();
		}
		else if (!strncmp(*argv, "clear", 5)) {
			nvram_clear();
		}
		else if (!strncmp(*argv, "save", 4)) 
		{
			if (*++argv) 
				nvram_save_new(*argv);
		}
		else if (!strncmp(*argv, "restore", 7)) 
		{
			if (*++argv) 
				nvram_restore_new(*argv);
		}
		else if (!strncmp(*argv, "show", 4) || !strncmp(*argv, "getall", 6)) {
			nvram_show_new();
		}
		if (!*argv)
			break;
	}

	return 0;
}
Exemplo n.º 23
0
static void storageMediaSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *submit;

	submit =  websGetVar(wp, T("hiddenButton"), T(""));

	if (0 == strcmp(submit, "delete"))
	{
		int index;
		FILE *fp;
		char media_config_file[25];

		// strcpy(smb_config, "/var/.smb_config");
		sprintf(media_config_file, "%s/.media_config", first_part);
		fp = fopen(media_config_file, "w");

		if (NULL == fp) {
			perror(__FUNCTION__);
			return;
		}

		index = atoi(websGetVar(wp, T("media_dir"), T("")));
		memset(&media_conf[index].path, 0, sizeof(media_conf[index].path));	
		fwrite(media_conf, sizeof(media_conf), 1, fp);
		fclose(fp);
		websRedirect(wp, "usb/USHAREmediasrv.asp");
	} 
	else if (0 == strcmp(submit, "apply"))
	{
		char_t *media_enabled, *media_name;
		int i;
		
		// fetch from web input
		media_enabled = websGetVar(wp, T("media_enabled"), T(""));
		media_name = websGetVar(wp, T("media_name"), T(""));

		// set to nvram
		nvram_bufset(RT2860_NVRAM, "mediaSrvEnabled", media_enabled);
		nvram_bufset(RT2860_NVRAM, "mediaSrvName", media_name);
		nvram_commit(RT2860_NVRAM);

		// setup device
		if (0 == strcmp(media_enabled, "0"))
			memset(media_conf, 0, sizeof(media_conf));
		RunMediaSrv();

		// debug print
		websHeader(wp);
		websWrite(wp, T("<h2>Media Server Settings</h2><br>\n"));
		websWrite(wp, T("media_enabled: %s<br>\n"), media_enabled);
		websWrite(wp, T("media_name: %s<br>\n"), media_name);
		for(i=0;i<4;i++)
			websWrite(wp, T("media dir%d path: %s<br>\n"), i, media_conf[i].path);
		websFooter(wp);
		websDone(wp, 200);
	}
}
Exemplo n.º 24
0
int32_t nvram_reset(char * section, char * defile)
{
    API();

    if (OK == nvram_parse(section, defile))
        return nvram_commit(1);

    return NG;
}
Exemplo n.º 25
0
void start_jffs2(void)
{
	char *rwpart = "ddwrt";
	int itworked = 0;

	if (nvram_match("sys_enable_jffs2", "1")) {
		if (nvram_match("sys_clean_jffs2", "1")) {
			nvram_set("sys_clean_jffs2", "0");
			nvram_commit();
#ifdef HAVE_WNDR3700V4
			itworked = eval("erase", rwpart);
			itworked = eval("mkfs.jffs2", "-o", "/dev/mtdblock3", "-n", "-b", "-e", "131072", "-p");
#else
			itworked = eval("mtd", "erase", rwpart);
#endif
			insmod("crc32");
			insmod("lzma_compress");
			insmod("lzma_decompress");
			insmod("lzo_compress");
			insmod("lzo_decompress");
			insmod("jffs2");

			char dev[64];

			sprintf(dev, "/dev/mtdblock/%d", getMTD("ddwrt"));
			itworked +=
			    mount(dev, "/jffs", "jffs2", MS_MGC_VAL, NULL);
			if (itworked) {
				nvram_set("jffs_mounted", "0");
			} else {
				nvram_set("jffs_mounted", "1");
			}

		} else {
			itworked = eval("mtd", "unlock", rwpart);
			insmod("crc32");
			insmod("lzma_compress");
			insmod("lzma_decompress");
			insmod("lzo_compress");
			insmod("lzo_decompress");
			insmod("jffs2");
			char dev[64];

			sprintf(dev, "/dev/mtdblock/%d", getMTD("ddwrt"));
			itworked +=
			    mount(dev, "/jffs", "jffs2", MS_MGC_VAL, NULL);
			if (itworked) {
				nvram_set("jffs_mounted", "0");
			} else {
				nvram_set("jffs_mounted", "1");
			}

		}
	}

}
Exemplo n.º 26
0
void
reset_db() {
NMP_DEBUG("RESET DB!!!\n");
	commit_no = 0;
	nvram_set("nmp_client_list", "");
	nvram_commit();
	*nmp_client_list = NULL;
	nmp_client_list = strdup(nvram_get("nmp_client_list"));
	refresh_sig();
}
Exemplo n.º 27
0
static int commit_main(int argc, char **argv)
{
	int r;

	printf("Commit... ");
	fflush(stdout);
	r = nvram_commit();
	printf("done.\n");
	return r ? 1 : 0;
}
Exemplo n.º 28
0
/* goform/storageFtpSrv */
static void storageFtpSrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *ftp, *name, *anonymous, *port, *max_sessions;
	char_t *adddir, *rename, *remove, *read, *write, *download, *upload;

	// fetch from web input
	ftp = websGetVar(wp, T("ftp_enabled"), T("0"));
	name = websGetVar(wp, T("ftp_name"), T("0"));
	anonymous = websGetVar(wp, T("ftp_anonymous"), T("0"));
	port = websGetVar(wp, T("ftp_port"), T(""));
	max_sessions = websGetVar(wp, T("ftp_max_sessions"), T(""));
	adddir = websGetVar(wp, T("ftp_adddir"), T("0"));
	rename = websGetVar(wp, T("ftp_rename"), T("0"));
	remove = websGetVar(wp, T("ftp_remove"), T("0"));
	read = websGetVar(wp, T("ftp_read"), T("0"));
	write = websGetVar(wp, T("ftp_write"), T("0"));
	download = websGetVar(wp, T("ftp_download"), T("0"));
	upload = websGetVar(wp, T("ftp_upload"), T("0"));

	// set to nvram
	nvram_bufset(RT2860_NVRAM, "FtpEnabled", ftp);
	nvram_bufset(RT2860_NVRAM, "FtpName", name);
	nvram_bufset(RT2860_NVRAM, "FtpAnonymous", anonymous);
	nvram_bufset(RT2860_NVRAM, "FtpPort", port);
	nvram_bufset(RT2860_NVRAM, "FtpMaxSessions", max_sessions);
	nvram_bufset(RT2860_NVRAM, "FtpAddDir", adddir);
	nvram_bufset(RT2860_NVRAM, "FtpRename", rename);
	nvram_bufset(RT2860_NVRAM, "FtpRemove", remove);
	nvram_bufset(RT2860_NVRAM, "FtpRead", read);
	nvram_bufset(RT2860_NVRAM, "FtpWrite", write);
	nvram_bufset(RT2860_NVRAM, "FtpDownload", download);
	nvram_bufset(RT2860_NVRAM, "FtpUpload", upload);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("storage.sh ftp");

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>ftp_enabled: %s</h2><br>\n"), ftp);
	websWrite(wp, T("ftp_anonymous: %s<br>\n"), anonymous);
	websWrite(wp, T("ftp_name: %s<br>\n"), name);
	websWrite(wp, T("ftp_port: %s<br>\n"), port);
	websWrite(wp, T("ftp_max_sessions: %s<br>\n"), max_sessions);
	websWrite(wp, T("ftp_adddir: %s<br>\n"), adddir);
	websWrite(wp, T("ftp_rename: %s<br>\n"), rename);
	websWrite(wp, T("ftp_remove: %s<br>\n"), remove);
	websWrite(wp, T("ftp_read: %s<br>\n"), read);
	websWrite(wp, T("ftp_write: %s<br>\n"), write);
	websWrite(wp, T("ftp_download: %s<br>\n"), download);
	websWrite(wp, T("ftp_upload: %s<br>\n"), upload);
	websFooter(wp);
	websDone(wp, 200);
}
Exemplo n.º 29
0
void start_sysinit(void)
{
	char buf[PATH_MAX];
	struct stat tmp_stat;
	time_t tm = 0;

	eval("/bin/tar", "-xzf", "/dev/mtdblock/2", "-C", "/");
	FILE *in = fopen("/tmp/nvram/nvram.db", "rb");

	if (in != NULL) {
		fclose(in);
		eval("/usr/sbin/convertnvram");
		eval("/sbin/mtd", "erase", "nvram");
		nvram_commit();
	}
	if (!nvram_match("disable_watchdog", "1"))
		eval("watchdog");
	/*
	 * Setup console 
	 */

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

	int brand = getRouterBrand();

	/*
	 * network drivers 
	 */
	detect_wireless_devices();

	struct ifreq ifr;
	int s;

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

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

	/*
	 * Set a sane date 
	 */
	stime(&tm);
	nvram_set("wl0_ifname", "ath0");

	return;
}
Exemplo n.º 30
0
void aoss_save(webs_t wp)
{
	char buf[32];
	nvram_set("aoss_enable", websGetVar(wp, "aoss_enable", "0"));
	nvram_set("aoss_aes", websGetVar(wp, "aoss_aes", "0"));
	nvram_set("aoss_tkip", websGetVar(wp, "aoss_tkip", "0"));
	nvram_set("aoss_wep", websGetVar(wp, "aoss_wep", "0"));
#ifdef HAVE_WPS
	nvram_set("wps_enabled", websGetVar(wp, "wps_enabled", "0"));
	char *pin = websGetVar(wp, "wps_ap_pin", NULL);
	if (pin)
		nvram_set("pincode", pin);
#endif
	// check if at least one value was set
	if (nvram_match("aoss_aes", "0")
	    && nvram_match("aoss_tkip", "0")
	    && nvram_match("aoss_wep", "0")) {
		nvram_set("aoss_aes", "1");
	}
	if (strlen(nvram_safe_get("aoss_vifs"))) {
		nvram_unset("ath0_vifs");
		nvram_unset("aoss_vifs");
		nvram_commit();
	}
	if (strlen(nvram_safe_get("aossa_vifs"))) {
		nvram_unset("ath1_vifs");
		nvram_unset("aossa_vifs");
		nvram_commit();
	}
	char *registrar = websGetVar(wp, "wps_registrar", NULL);
	if (registrar && nvram_invmatch("wps_registrar", registrar)) {
		nvram_set("wps_registrar", registrar);
		addAction("wireless");
		nvram_set("nowebaction", "1");
		service_restart();
	}
	// all other vars
	//validate_cgi(wp);
}