#include "msw.h"
#include "am335x.h"

#define VERSION "1.0"

void usage(void)
{
        printf("Command : ipv4set\n");
        printf("Set Ethernet(eth0) network setting\n");
        printf("Usage: ipv4set [type] [ip] [netmask] [gateway]\n");
        printf("Example 1:ipv4set dhcp\n");
        printf("Set Ethernet(eth0) DHCP\n");
        printf("Example 2:ipv4set static 10.1.0.107 255.255.0.0 10.1.0.254\n");
        printf("Set Ethernet(eth0) static network setting\n");
}

int main(int argc, char *argv[])
{
	int rs = 0;
	int c;

	int option = 0;

	while((c=getopt(argc, argv, "v")) != -1)
        {
                switch(c)
                {
                        case 'v':
                                printf("ipv4set : %s\n", VERSION);
                                return SUCCESS;

                        case '?':
                                printf("wrong command\n");
                                return SUCCESS;
                }
        }

	if (argc == 5) 
	{
        	/* Static */
		if(!strcmp(argv[1], "static"))	
		{
			rs = angstrom_ip_static(argv[2], argv[3], argv[4]);

			if(rs == SUCCESS)
                                printf("ipv4set static ... OK\n");
                        else
                                printf("ipv4set static ... Fail\n");

		}
		else
		{
			usage();
			return FAILURE;

		}
	}
        else if (argc == 2) 
	{
		/* DHCP */
		if(!strcmp(argv[1], "dhcp"))
		{
			rs = angstrom_ip_dhcp();

			if(rs == SUCCESS)
				printf("ipv4set dhcp ... OK\n");
			else
				printf("ipv4set dhcp ... Fail\n");
		}
		else
		{
			usage();
			return FAILURE;
		}
        }
        else 
	{
                usage();
		return FAILURE;
        }

	return SUCCESS;
}


