示例#1
0
文件: cmd_nvedit.c 项目: qgp/armboot
int do_saveenv  (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
{
    return (board_env_save(bd, bd->bi_env, sizeof(env_t))) ? 1 : 0;
}
示例#2
0
m_STATUS
save_environment(
	PADSL_ENV	p_env
)
{
#ifdef	__KERNEL__
#else
	FILE		*fw = NULL;
#endif
	char				flash_buf[BUF_SIZE] = {};
	ENCAP_MODE		encap = ENCAP_NOT_SUPPORTED;
	m_STATUS		status = ST_OK;

#if 1	//	I need more time!
	encap = check_encap_mode(p_env->encap);

	if (encap == ENCAP_NOT_SUPPORTED)
	{
	#ifdef	DBG
		m_print("Not supported encapsulation mode...%s\n", p_env->encap);
	#endif
		return	ST_ENCAP_MODE_ERROR;		
	}
#else
	if (!strncmp((const char *)(p_env->encap), "PPPOE", 5))
	{
		encap = ENCAP_PPPOE;	
	}
	else if (!strncmp((const char *)(p_env->encap), "PPPOA", 5))
	{
		encap = ENCAP_PPPOA;
	}
	else if (!strncmp((const char *)(p_env->encap), "RFC1483br", 9))
	{
		encap = ENCAP_RFC1483BR;
	}
	else if (!strncmp((const char *)(p_env->encap), "RFC1483rt", 9))
	{
		encap = ENCAP_RFC1483RT;
	}
	else
	{
		encap = ENCAP_NOT_SUPPORTED;
	#ifdef	DBG
		m_print("Not supported encapsulation mode...%s\n", p_env->encap);
	#endif
		return	ST_ENCAP_MODE_ERROR;
	}
#endif

/////////////////////////////////////////////////
//	samsung_adsl
//	adsl_start
#ifdef	__KERNEL__
#else
	if ((fw = fopen("/var/samsung_adsl", "w")) == NULL)
	{
	#ifdef	DBG
		m_print("Cannot make /var/samsung_adsl file!\n");
	#endif
		return	ST_FILE_ERROR;
	}
#endif

	sprintf(flash_buf, "adsl_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	if (p_env->dmt_reset)
	{
		sprintf(flash_buf, "adsldmt r m 0");
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
		
		sprintf(flash_buf, "adsldmt r y");
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	}
	
#if 1
	switch(encap)
	{
		case	ENCAP_PPPOE:	//	Fall through...
		case	ENCAP_PPPOA:	//	I don't know how to set PPPoA case..., but I'll suppose both will be same at this time.
	#ifdef	__KERNEL__
			status = flash_setting_pppoe(p_env, flash_buf);
	#else
			status = flash_setting_pppoe(p_env, flash_buf, fw);
	#endif
			break;

		case	ENCAP_RFC1483BR:	//	Fall through...
		case	ENCAP_RFC1483RT:	//	I don't know how to set RFC1483rt case..., but I'll suppose both will be same at this time.
	#ifdef	__KERNEL__
			status = flash_setting_rfc1483br(p_env, flash_buf);
	#else
			status = flash_setting_rfc1483br(p_env, flash_buf, fw);
	#endif
			break;

		case	ENCAP_NOT_SUPPORTED:	//	Fall through...
		default:
			status = ST_ENCAP_MODE_ERROR;
			break;
	}
#else
	if (!strncmp((const char *)(p_env->encap), "PPP", 3))	//	If truth, that's PPP mode.
	{
		sprintf(flash_buf, "br2684ctl -c %d -a %d.%d &",	p_env->if_index,
													p_env->vpi,
													p_env->vci		);
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

		if (p_env->mtu)
		{
			sprintf(flash_buf, "ifconfig nas%d mtu %d",		p_env->if_index,
													p_env->mtu			);	//	I'll not touch nas MTU at this time.
			sys_env(flash_buf);
#ifdef	__KERNEL__
#else
			fprintf(fw, "%s\n", flash_buf);
#endif
			memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
		}
		else
		{
		}

#if	0	//	Why did you run nas up twice times?
		sprintf(flash_buf,"ifconfig nas%d up",				p_env->if_index);
		sys_env(flash_buf);
#ifdef	__KERNEL__		
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
#endif
		
		sprintf(flash_buf, "ifconfig eth0 %s netmask %s",	p_env->ip_addr,
													p_env->netmask	);	//	I'll not touch eth index at this time.
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	{
		char		subnet[20];
		get_subnet(subnet, p_env->ip_addr, p_env->netmask);
		sprintf(flash_buf, "iptables -t nat -A POSTROUTING -s %s/%d -j MASQUERADE",
													(char *)subnet,
													get_subnet_bit(p_env->netmask)	);	//	Should be imported these functions
	}
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

		sprintf(flash_buf, "ifconfig nas%d up",				p_env->if_index);
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

		sprintf(flash_buf,"start_pppoe&");
		sys_env(flash_buf);
#ifdef	__KERNEL__
#else
		fprintf(fw, "%s\n", flash_buf);
#endif
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	}
	else			//	I'll not touch not_ppp case at this time
	{
	}

	sprintf(flash_buf, "udhcpd&");
	sys_env(flash_buf);
#ifdef	__KERNEL__
#else
	fprintf(fw, "%s\n", flash_buf);
#endif
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
#endif

	sprintf(flash_buf, "adsl_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

#ifdef	__KERNEL__
#else
	if (fw)
	{
		fclose(fw);
		fw = NULL;
	}
#endif

#ifdef	__KERNEL__
#else
	system("chmod 755 /var/samsung_adsl");
#endif
//
//	adsl_end
/////////////////////////////////////////////////

/////////////////////////////////////////////////
//	
//	aal5_x_start
	sprintf(flash_buf, "aal5_0_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	sprintf(flash_buf, "%s %d %d %s %s %s %s %d",	p_env->encap,
													p_env->vpi,
													p_env->vci,
													p_env->ip_addr,
													p_env->netmask,
													p_env->ppp_id,
													p_env->ppp_pw,
													p_env->ppp_default_route);	
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	sprintf(flash_buf, "%d %d %d %d %d %d %d %d",	p_env->dhcp_use,
													1,1,1,1,1,1,1);
			
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_0_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_1_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_1_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_2_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_2_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	sprintf(flash_buf, "aal5_3_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_3_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_4_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_4_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_5_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_5_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_6_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_6_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "aal5_7_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf, "aal5_7_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
//
//	aal5_x_end
/////////////////////////////////////////////////	

/////////////////////////////////////////////////
//
//	nat_rule_start

	sprintf(flash_buf, "nat_rule_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	{
	char subnet_from[20], subnet_to[20];
	get_subnet(subnet_from, p_env->ip_addr, p_env->netmask);
	get_subnet_end(subnet_to, subnet_from, p_env->netmask);
    sprintf(flash_buf, "%s %s %s %s %s %s %s %s %s %s %s %s",	"NAPT",
																"1",
																"-",
																"-",
																(char *)subnet_from,	//"192.168.1.0",
																(char *)subnet_to,		//"192.168.1.255",
																"-",
                                                        		"anywhere",
																"-",
																"-",
																"-",
																"-"			);
	}
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "nat_rule_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
//
//	nat_rule_end
/////////////////////////////////////////////////	

/////////////////////////////////////////////////
//
//	chap_start & pap_start
	sprintf(flash_buf, "chap_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	sprintf(flash_buf,"%s  *   %s",			p_env->ppp_id,
										p_env->ppp_pw	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	
	sprintf(flash_buf, "chap_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "pap_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	sprintf(flash_buf,"%s  *   %s ",			p_env->ppp_id,
										p_env->ppp_pw	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	
	sprintf(flash_buf, "pap_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
//
//	chap_end & pap_end
/////////////////////////////////////////////////

/////////////////////////////////////////////////
//
//	ppp_option_start
	sprintf(flash_buf, "ppp_option_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);


	if (p_env->ppp_default_route)
	{
		sprintf(flash_buf, "defaultroute");
		sys_env(flash_buf);
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	}
	else
	{
	}

	sprintf(flash_buf, "asyncmap 0");					//	I'll not touch asyncmap at this time.
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	if (p_env->ppp_mru)
	{
		sprintf(flash_buf, "mru %d",			p_env->ppp_mru	);
		sys_env(flash_buf);
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	}
	else
	{
	}

	if (p_env->ppp_mtu)
	{
		sprintf(flash_buf, "mtu %d",			p_env->ppp_mtu	);
		sys_env(flash_buf);
		memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	}
	else
	{
	}

	sprintf(flash_buf,"user %s",				p_env->ppp_id	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf,"plugin pppoe");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf,"nas%d",				p_env->if_index	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
	
	sprintf(flash_buf, "usepeerdns");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "ppp_option_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	
//
//	ppp_option_end
/////////////////////////////////////////////////

/////////////////////////////////////////////////
//
//	webpassword_start
	sprintf(flash_buf, "webpassword_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "USERNAME=%s",			p_env->user_id	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "PASSWORD=%s",			p_env->user_pw	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "ADMINNAME=%s",			p_env->root_id	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "PASSWORD1=%s",			p_env->root_pw	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "webpassword_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	
//
//	webpassword_end
/////////////////////////////////////////////////

	if (p_env->dhcp_use)
	{
/////////////////////////////////////////////////
//
//	dhcp_start
	sprintf(flash_buf, "dhcp_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "%s %s %s %s %s %s",		"dhcp_server",
											p_env->dhcp_ip_from,
											p_env->dhcp_ip_to,
											"--",
											p_env->ip_addr,
											p_env->dhcp_netmask		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);

	sprintf(flash_buf, "dhcp_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);
//
//	dhcp_end
/////////////////////////////////////////////////
#if 1
/////////////////////////////////////////////////
//
//	udhcp_start
	sprintf(flash_buf, "udhcp_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "start\t %s",			p_env->dhcp_ip_from		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "end\t %s",				p_env->dhcp_ip_to		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	
	
	sprintf(flash_buf, "interface %s",			p_env->dhcp_interface	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "option\t subnet %s",		p_env->dhcp_netmask		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "option\t router %s",		p_env->dhcp_gateway		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "option\t lease %d", 		p_env->dhcp_lease_time	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);	

	sprintf(flash_buf, "udhcp_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);		
//
//	udhcp_end
/////////////////////////////////////////////////
#endif
	}	//	if (p_env->dhcp_use)
	else
	{
	}

/////////////////////////////////////////////////
//
//	dns_start
	sprintf(flash_buf, "dns_start");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);		

	sprintf(flash_buf, "nameserver %s",		p_env->dns_primary		);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);		

	sprintf(flash_buf, "nameserver %s ",		p_env->dns_secondary	);
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);		

	sprintf(flash_buf, "dns_end");
	sys_env(flash_buf);
	memset(flash_buf, 0, sizeof(char) * BUF_SIZE);		
//
//	dns_end
/////////////////////////////////////////////////

#ifdef	__KERNEL__
	board_env_save(bd, bd->bi_env, sizeof(env_t));
#else
	system("saveenvm");
#endif

	return	status;
}