xref: /netbsd-src/share/examples/rump/wirelessconf/wirelessconf.c (revision c2492298bf53609688034a182149de067b8a088b)
1*c2492298Spooka /*	$NetBSD: wirelessconf.c,v 1.3 2009/11/03 18:24:21 pooka Exp $	*/
278869832Spooka 
378869832Spooka /*
478869832Spooka  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
578869832Spooka  *
678869832Spooka  * Redistribution and use in source and binary forms, with or without
778869832Spooka  * modification, are permitted provided that the following conditions
878869832Spooka  * are met:
978869832Spooka  * 1. Redistributions of source code must retain the above copyright
1078869832Spooka  *    notice, this list of conditions and the following disclaimer.
1178869832Spooka  * 2. Redistributions in binary form must reproduce the above copyright
1278869832Spooka  *    notice, this list of conditions and the following disclaimer in the
1378869832Spooka  *    documentation and/or other materials provided with the distribution.
1478869832Spooka  *
1578869832Spooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1678869832Spooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1778869832Spooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1878869832Spooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1978869832Spooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2078869832Spooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2178869832Spooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2278869832Spooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2378869832Spooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2478869832Spooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2578869832Spooka  * SUCH DAMAGE.
2678869832Spooka  */
2778869832Spooka 
2878869832Spooka #include <sys/types.h>
2978869832Spooka #include <sys/ioctl.h>
3078869832Spooka #include <sys/reboot.h>
3178869832Spooka #include <sys/socket.h>
3278869832Spooka 
3378869832Spooka #include <net/if.h>
3478869832Spooka 
3578869832Spooka #include <rump/rump.h>
3678869832Spooka #include <rump/rump_syscalls.h>
3778869832Spooka 
3878869832Spooka #include <err.h>
39*c2492298Spooka #include <errno.h>
4078869832Spooka #include <stdio.h>
41*c2492298Spooka #include <stdlib.h>
4278869832Spooka #include <string.h>
4378869832Spooka 
4478869832Spooka /*
4578869832Spooka  * Example program for raising rum0 interface under rump.  This
4678869832Spooka  * requires a rum-compatible usb device attached as ugen.
4778869832Spooka  */
4878869832Spooka 
4978869832Spooka #define RUMFW "/libdata/firmware/rum/rum-rt2573"
5078869832Spooka int
main(void)518a435a04Spooka main(void)
5278869832Spooka {
5378869832Spooka 	struct ifreq ifr;
5478869832Spooka 	int s;
5578869832Spooka 
56*c2492298Spooka 	rump_boot_sethowto(RUMP_AB_VERBOSE);
5778869832Spooka 	rump_init();
58*c2492298Spooka 
59*c2492298Spooka 	/* rum?  shouldn't that be marsala? */
60*c2492298Spooka 	s = rump_sys_socket(AF_INET, SOCK_DGRAM, 0);
61*c2492298Spooka 	if (s == -1)
62*c2492298Spooka 		err(1, "socket");
63*c2492298Spooka 	strcpy(ifr.ifr_name, "rum0");
64*c2492298Spooka 	if (rump_sys_ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
65*c2492298Spooka 		if (errno == ENXIO) {
66*c2492298Spooka 			printf("rum@usb not found!\n");
67*c2492298Spooka 			exit(0);
68*c2492298Spooka 		}
69*c2492298Spooka 		err(1, "get if flags");
70*c2492298Spooka 	}
7178869832Spooka 	printf("\ndevice autoconfiguration finished\n");
7278869832Spooka 
7378869832Spooka 	printf("tira-if-su ...\n");
748a435a04Spooka 	if (rump_pub_etfs_register(RUMFW, RUMFW, RUMP_ETFS_REG) != 0)
7578869832Spooka 		errx(1, "firmware etfs registration failed");
7678869832Spooka 
7778869832Spooka 	strcpy(ifr.ifr_name, "rum0");
7878869832Spooka 	ifr.ifr_flags = IFF_UP;
7978869832Spooka 	if (rump_sys_ioctl(s, SIOCSIFFLAGS, &ifr) == -1)
8078869832Spooka 		err(1, "ioctl");
8178869832Spooka 	printf("... done\n");
8278869832Spooka 
8378869832Spooka 	return 0;
8478869832Spooka }
85