Beispiel #1
0
static int do_ifup(int argc, char *argv[])
{
	int opt;
	unsigned flags = 0;
	int all = 0;

	while ((opt = getopt(argc, argv, "af")) > 0) {
		switch (opt) {
		case 'f':
			flags |= IFUP_FLAG_FORCE;
			break;
		case 'a':
			all = 1;
			break;
		}
	}

	if (all)
		return ifup_all(flags);

	if (argc == optind)
		return COMMAND_ERROR_USAGE;

	return ifup(argv[optind], flags);
}
Beispiel #2
0
int ifup_all(unsigned flags)
{
	DIR *dir;
	struct dirent *d;

	dir = opendir("/env/network");
	if (!dir)
		return -ENOENT;

	while ((d = readdir(dir))) {
		if (*d->d_name == '.')
			continue;
		/*
		 * Skip xxx-discover files since these are no
		 * network configuration files, but scripts to bring
		 * up network interface xxx.
		 */
		if (strstr(d->d_name, "-discover"))
			continue;
		ifup(d->d_name, flags);
	}

	closedir(dir);

	return 0;
}
Beispiel #3
0
int main(int argc, char **argv) {
    int fd;
    uint8_t msg[2048];
    ssize_t msg_size;
    struct ipv6_mreq mreq;
    struct sockaddr_in6 addr;
    const int zero = 0;

    if (!ifup())
	return 1;

    fd = socket(AF_INET6, SOCK_DGRAM, 0);
    if (fd < 0) {
	perror("socket");
	return 1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sin6_family = AF_INET6;
    addr.sin6_addr = in6addr_any;
    addr.sin6_port = htons(NETKEYSCRIPT_PORT);

    if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
	perror("bind");
	return 1;
    }

    memset(&mreq, 0, sizeof(mreq));
    if (!inet_pton(AF_INET6, "ff02::1", &mreq.ipv6mr_multiaddr)) {
	perror("inet_pton");
	return 1;
    }
    if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
		   sizeof(mreq)) < 0) {
	perror("setsockopt");
	return 1;
    }
    if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &zero,
		   sizeof(zero))) {
	perror("setsockopt");
	return 1;
    }

    fputs("netkeyscript: waiting for passphrase\n", stderr);
    msg_size = read_passphrase(fd, msg, sizeof(msg));
    if (msg_size < 0) {
	return 1;
    }
    /* +1/-1 to skip the command prefix code */
    if (fwrite(msg+1, msg_size-1, 1, stdout) < 1) {
	fputs("fwrite: error\n", stderr);
	return 1;
    }
    ifdown();
    return 0;
}
Beispiel #4
0
int StartTap(char *name) {
	int tapfd;
	if((tapfd = tun_alloc(name)) <= 0) {
		printf("Failed to allocate tap %s\n", name);
		return -1;
	}
	if(ifup(name) != 0) {
		printf("Failed to bring up interface %s\n", name);
		return -1;
	}
	return tapfd;
}
Beispiel #5
0
int CreateBridge(char* bridge) {
	int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
	int br = -1;
	if(sock <= 0) {
		return -1;
	}
	br = ioctl(sock, SIOCBRADDBR, bridge);
	close(sock);
	if(br < 0 ) {
		return -1;
	}
	return ifup(bridge);
}
Beispiel #6
0
int CheckBridge(char* bridge) {
	char buff[256];
	struct stat s;
	snprintf(buff, sizeof(buff), "/sys/class/net/%s/bridge", bridge);
	
	if(stat(buff, &s) != 0) {
		return -1;
	}
	if(!S_ISDIR(s.st_mode)) {
		return -1;
	} else {
		return ifup(bridge);
	}
}
/****************************************************************************
	main

	Print out a menu, wait for keypresses, while calling tcp_tick.

****************************************************************************/
void main(void)
{
	int val0, val1,i, level;
   mac_addr mac;
   char c;
   word waitms, pingit;
   longword pingid;
   wifi_status status;
   int len;
   int printmenu;
   unsigned long int end;

	// Initialize the scan_complete variable
	scan_complete = 0;

	sock_init();

	waitms = _SET_SHORT_TIMEOUT(300);
	pingit = 0;
   printmenu = 1;
   for (;;) {
   	if (printmenu) {
      	printmenu = 0;
	      printf("\nMenu:\n");
	      printf("   Press s to scan available access points\n");
	      printf("   Press a to scan access points and associate\n");
	      printf("   Press m to print WIFI MAC status\n");
	      printf("\n");
      }
		tcp_tick(NULL);
		if (kbhit()) {
      	switch (getchar()) {
         	case 'm':
            case 'M':
	            ifconfig (IF_WIFI0, IFG_WIFI_STATUS, &status, IFS_END);
	            print_status(&status);
	            printmenu = 1;
					break;

            case 's':
            case 'S':
	            // Bring the interface down before starting a scan
	            ifdown(IF_WIFI0);
	            while (ifpending(IF_WIFI0) != IF_DOWN)
	               tcp_tick(NULL);
	            // Set the callback before requesting scan
	            ifconfig(IF_WIFI0, IFS_WIFI_SCAN, scan_callback, IFS_END);
	            printf("Starting scan...\n");
					break;

            case 'a':
            case 'A':
	            // Bring the interface down before starting a scan
	            ifdown(IF_WIFI0);
	            while (ifpending(IF_WIFI0) != IF_DOWN)
	               tcp_tick(NULL);
	            ifconfig(IF_WIFI0, IFS_WIFI_SCAN, scan_assoc_callback, IFS_END);
	            printf("Starting scan...\n");
					break;
			}
		}
		// Check to see if a scan has completed.  If so, then bring the
		// interface back up.
		if (scan_complete) {
			ifup(IF_WIFI0);
			scan_complete = 0;
         printmenu = 1;
		}
   }
}
Beispiel #8
0
main()
{
	int state;
	word tmo;


	brdInit();				//initialize board for this demo

	// Bring up interface first time (also prints our address)
	sock_init_or_exit(1);

	// First initialization OK, turn on both LEDs
	if_led(LEDON);
	xcvr_led(LEDON);

	state = 0;
	tmo = _SET_SHORT_TIMEOUT(UPTIME);

	for(;;) {
		switch (state) {
		case 0:	// Up, timing out
			tcp_tick(NULL);
			if (_CHK_SHORT_TIMEOUT(tmo)) {
				printf("Bringing interface down...\n");
				state = 1;
				ifdown(IF_WIFI0);
			}
			break;
		case 1:	// bringing down
			tcp_tick(NULL);
			if (ifpending(IF_WIFI0) == IF_DOWN) {
				printf("Powering down...\n");
	         if_led(LEDOFF);
	         xcvr_led(LEDOFF);

            // Set flag for MAC to power down when tcp_tick function is called!
            pd_powerdown(IF_WIFI0);
	         tmo =_SET_SHORT_TIMEOUT(DOWNTIME);
	         state = 2;
	      }
	      break;
	   case 2:	// down, waiting
      	tcp_tick(NULL);
	   	if (_CHK_SHORT_TIMEOUT(tmo)) {
				printf("Powering up...\n");

            // Set flag for MAC to power-up when tcp_tick function is called!
	         pd_powerup(IF_WIFI0);
            xcvr_led(LEDON);
	         tmo =_SET_SHORT_TIMEOUT(500);	// settle for 1/2 sec
	         state = 3;
			}
			break;
		case 3: // let power stabilize
      	tcp_tick(NULL);
			if (_CHK_SHORT_TIMEOUT(tmo)) {
				printf("Bringing interface up...\n");
				ifup(IF_WIFI0);
	         state = 4;
			}
			break;
		case 4:	// waiting for up
			tcp_tick(NULL);
			if (ifpending(IF_WIFI0) != IF_COMING_UP) {
				if (ifpending(IF_WIFI0) == IF_DOWN) {
					printf("!!!!! Failed to come back up!!!!!\n");
					return -1;
				}
				printf("Up again!\n");
				if_led(LEDON);
	         tmo =_SET_SHORT_TIMEOUT(UPTIME);
				state = 0;
			}
			break;
		}
	}
}
main()
{
	longword seq,ping_who,tmp_seq,time_out;
	char	buffer[100];
   auto wifi_region region_info;
   auto char index[10];
   auto int option;
   auto char tmpbuf[64];
   auto int updateRegion;
   auto int country;
   auto int configured;


	brdInit();				//initialize board for this demo

	seq=0;

	sock_init();			// Initial wifi interface

   // Make sure wifi IF is down to do ifconfig's functions
	printf("\nBringing interface down (disassociate)...\n");
   ifdown(IF_WIFI0);
   while (ifpending(IF_WIFI0) != IF_DOWN) {
     	printf(".");
     	tcp_tick(NULL);
   }
	printf("...Done.\n");

   configured = FALSE;
   updateRegion = FALSE;
   do
   {
   	country = get_stored_region(&region_info);
   	// Check if the region has been previously set.
 		if(country < 0 || updateRegion)
   	{
      	// Populate structure with region info, then display
   		ifconfig (IF_WIFI0, IFG_WIFI_REGION_INFO, &region_info, IFS_END);
   		printf("\nCurrent region setting:\n");
   		display_info(&region_info);

         // Select Region and write value to userblock
    		country = wifi_config_region(&region_info);
         updateRegion = FALSE;

   	}
   	else
   	{
      	// Set Region from previously saved value read from the userblock, this
      	// will set the runtime limits to be used by the wifi driver.

   		ifconfig (IF_WIFI0, IFS_WIFI_REGION, country,
         	IFG_WIFI_REGION_INFO, &region_info, IFS_END);

   		printf("\nRuntime region setting now being used by wifi driver:\n");
         display_info(&region_info);

      	// Region has already been set at runtime, check if it needs to
         // be changed due to country to country roaming.
    		printf("\nRegion already set, select option to continue");
         printf("\n1. Continue.");
         printf("\n2. Select new region.");
         printf("\nSelect > ");
			do
			{
				option = atoi(gets(tmpbuf));
	  		} while (!((option >= 1) && (option <= 2)));
         if(option == 2)
         	updateRegion = TRUE;
         else
         	configured = TRUE;
      }
	}while(!configured);

   // If you are not going to use the defaulted channel and/or power level,
   // then you can use the following functions to set channel and/or the
   // power level. This needs to be done after setting the region/country
   // to meet wifi driver requirements.

   //ifconfig (IF_WIFI0, IFS_WIFI_CHANNEL, 0, IFS_END); // Scan all channels
   //ifconfig (IF_WIFI0, IFS_WIFI_TX_POWER, 8, IFS_END); // Set to Pwr level 8


   // Startup the  wireless interface here...
	printf("Bringing interface back up (associate)...\n");
   ifup(IF_WIFI0);
   while (ifpending(IF_WIFI0) == IF_COMING_UP) {
      tcp_tick(NULL);
   }
	printf("...Done.\n");
	if (ifpending(IF_WIFI0) != IF_UP) {
		printf("Unfortunately, it failed to associate :-(\n");
		exit(1);
	}
   // End of regional setting section, from this point on do standard tcp/ip
   // protocol.


   /*
   // Here is where we gather the statistics...
	// Note that if you get a compile error here, it is because you are not running
	// this sample on a Wifi-equipped board.

	/* Print who we are... */
	printf( "My IP address is %s\n\n", inet_ntoa(buffer, gethostid()) );

	/*
	 *		Get the binary ip address for the target of our
	 *		pinging.
	 */

#ifdef PING_WHO
	/* Ping a specific IP addr: */
	ping_who=resolve(PING_WHO);
	if(ping_who==0) {
		printf("ERROR: unable to resolve %s\n",PING_WHO);
		exit(2);
	}
#else
	/* Examine our configuration, and ping the default router: */
	tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END );
	if( tmp_seq != 0 ) {
		printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq );
		exit(2);
	}
	if(ping_who==0) {
		printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n");
		exit(2);
	}
#endif

	for(;;) {
		/*
		 *		It is important to call tcp_tick here because
		 *		ping packets will not get processed otherwise.
		 *
		 */

		tcp_tick(NULL);

		/*
		 *		Send one ping every PING_DELAY ms.
		 */

		costate {
			waitfor(DelayMs(PING_DELAY));
			_ping(ping_who,seq++);
			pingoutled(LEDON);					// flash transmit LED
			waitfor(DelayMs(50));
			pingoutled(LEDOFF);
		}

		/*
		 *		Has a ping come in?  time_out!=0xfffffff->yes.
		 */

		costate {
			time_out=_chk_ping(ping_who,&tmp_seq);
			if(time_out!=0xffffffff) {

#ifdef VERBOSE
				printf("received ping:  %ld\n", tmp_seq);
#endif

				pinginled(LEDON);					// flash receive LED
				waitfor(DelayMs(50));
				pinginled(LEDOFF);
			}
		}
	}
}
main()
{
	longword seq,ping_who,tmp_seq,time_out;
	char	buffer[100];


	brdInit();				//initialize board for this demo
	seq=0;

	sock_init();			// Initialize wifi interface

   // Make sure wifi IF is down to do ifconfig's functions
	printf("\nBringing interface down (disassociate)...\n");
   ifdown(IF_WIFI0);
   while (ifpending(IF_WIFI0) != IF_DOWN) {
     	printf(".");
     	tcp_tick(NULL);
   }
	printf("...Done.\n");

   // Enable 802.11d country information capability
   // Note: Access Point must have 802.11d enabled with proper country selected
   ifconfig(IF_WIFI0, IFS_WIFI_MULTI_DOMAIN, 1, IFS_END);

   // Startup the  wireless interface here...
	printf("Bringing interface back up (associate)...\n");
   ifup(IF_WIFI0);
   while (ifpending(IF_WIFI0) == IF_COMING_UP) {
      tcp_tick(NULL);
   }
	printf("...Done.\n");
	if (ifpending(IF_WIFI0) != IF_UP) {
		printf("Unfortunately, it failed to associate :-(\n");
		exit(1);
	}
   // End of regional setting section, from this point on do standard tcp/ip
   // protocol.


   /*
   // Here is where we gather the statistics...
	// Note that if you get a compile error here, it is because you are not running
	// this sample on a Wifi-equipped board.

	/* Print who we are... */
	printf( "My IP address is %s\n\n", inet_ntoa(buffer, gethostid()) );

	/*
	 *		Get the binary ip address for the target of our
	 *		pinging.
	 */

#ifdef PING_WHO
	/* Ping a specific IP addr: */
	ping_who=resolve(PING_WHO);
	if(ping_who==0) {
		printf("ERROR: unable to resolve %s\n",PING_WHO);
		exit(2);
	}
#else
	/* Examine our configuration, and ping the default router: */
	tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END );
	if( tmp_seq != 0 ) {
		printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq );
		exit(2);
	}
	if(ping_who==0) {
		printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n");
		exit(2);
	}
#endif

	for(;;) {
		/*
		 *		It is important to call tcp_tick here because
		 *		ping packets will not get processed otherwise.
		 *
		 */

		tcp_tick(NULL);

		/*
		 *		Send one ping every PING_DELAY ms.
		 */

		costate {
			waitfor(DelayMs(PING_DELAY));
			pingoutled(LEDON);					// flash transmit LED
			waitfor(DelayMs(50));
			pingoutled(LEDOFF);
			_ping(ping_who,seq++);
		}

		/*
		 *		Has a ping come in?  time_out!=0xfffffff->yes.
		 */

		costate {
			time_out=_chk_ping(ping_who,&tmp_seq);
			if(time_out!=0xffffffff) {

#ifdef VERBOSE
				printf("received ping:  %ld\n", tmp_seq);
#endif

				pinginled(LEDON);					// flash receive LED
				waitfor(DelayMs(50));
				pinginled(LEDOFF);
#if RCM5600W_SERIES
				waitfor(DelayMs(250));
				pinginled(LEDON);					// flash receive LED again
				waitfor(DelayMs(50));
				pinginled(LEDOFF);
#endif
			}
		}
	}
}