Home | History | Annotate | Line # | Download | only in lcboot
      1  1.4  joerg /* $NetBSD: dev_net.c,v 1.4 2011/07/17 20:54:41 joerg Exp $ */
      2  1.1    igy 
      3  1.1    igy /*
      4  1.1    igy  * Copyright (c) 2003 Naoto Shimazaki.
      5  1.1    igy  * All rights reserved.
      6  1.1    igy  *
      7  1.1    igy  * Redistribution and use in source and binary forms, with or without
      8  1.1    igy  * modification, are permitted provided that the following conditions
      9  1.1    igy  * are met:
     10  1.1    igy  * 1. Redistributions of source code must retain the above copyright
     11  1.1    igy  *    notice, this list of conditions and the following disclaimer.
     12  1.1    igy  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1    igy  *    notice, this list of conditions and the following disclaimer in the
     14  1.1    igy  *    documentation and/or other materials provided with the distribution.
     15  1.1    igy  *
     16  1.1    igy  * THIS SOFTWARE IS PROVIDED BY NAOTO SHIMAZAKI AND CONTRIBUTORS ``AS IS''
     17  1.1    igy  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     18  1.1    igy  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1    igy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE NAOTO OR CONTRIBUTORS BE
     20  1.1    igy  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1    igy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1    igy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1    igy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1    igy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1    igy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     26  1.1    igy  * THE POSSIBILITY OF SUCH DAMAGE.
     27  1.1    igy  */
     28  1.1    igy #include <sys/cdefs.h>
     29  1.4  joerg __KERNEL_RCSID(0, "$NetBSD: dev_net.c,v 1.4 2011/07/17 20:54:41 joerg Exp $");
     30  1.1    igy 
     31  1.1    igy #include <sys/param.h>
     32  1.2    igy #include <sys/types.h>
     33  1.2    igy #include <netinet/in.h>
     34  1.2    igy 
     35  1.1    igy #include <lib/libsa/stand.h>
     36  1.2    igy #include <lib/libsa/bootp.h>
     37  1.1    igy #include <lib/libkern/libkern.h>
     38  1.1    igy 
     39  1.1    igy #include "extern.h"
     40  1.1    igy 
     41  1.1    igy extern struct in_addr	servip;
     42  1.1    igy 
     43  1.1    igy static int	netdev_sock = -1;
     44  1.1    igy 
     45  1.1    igy int
     46  1.1    igy net_strategy(void *devdata, int rw, daddr_t blk,
     47  1.1    igy 	     size_t size, void *buf , size_t *rsize)
     48  1.1    igy {
     49  1.1    igy 	return EIO;
     50  1.1    igy }
     51  1.1    igy 
     52  1.1    igy int
     53  1.1    igy net_open(struct open_file *f, ...)
     54  1.1    igy {
     55  1.1    igy 	char		*fname;
     56  1.1    igy 	char		**file;
     57  1.1    igy 	struct iodesc	*s;
     58  1.1    igy 	va_list		ap;
     59  1.1    igy 
     60  1.1    igy 	va_start(ap, f);
     61  1.1    igy 	fname = va_arg(ap, char *);
     62  1.1    igy 	file = va_arg(ap, char **);
     63  1.1    igy 	va_end(ap);
     64  1.1    igy 
     65  1.1    igy 	f->f_devdata = &netdev_sock;
     66  1.1    igy 	netdev_sock = netif_open(NULL);
     67  1.1    igy 
     68  1.1    igy 	bootfile[0] = '\0';
     69  1.1    igy 	if (bootopts.b_flags & B_F_USE_BOOTP) {
     70  1.2    igy 		s = socktodesc(netdev_sock);
     71  1.2    igy 		bootp(netdev_sock);
     72  1.2    igy 		if (fname[0] != '\0')
     73  1.2    igy 			strlcpy(bootfile, fname, sizeof bootfile);
     74  1.1    igy 	} else {
     75  1.1    igy 		s = socktodesc(netdev_sock);
     76  1.1    igy 
     77  1.1    igy 		servip = s->destip = bootopts.b_remote_ip;
     78  1.1    igy 		myip = s->myip = bootopts.b_local_ip;
     79  1.1    igy 		netmask = bootopts.b_netmask;
     80  1.1    igy 		gateip = bootopts.b_gate_ip;
     81  1.1    igy 
     82  1.1    igy 		if (fname[0] == '\0') {
     83  1.1    igy 			printf("no boot filename\n");
     84  1.1    igy 			netif_close(netdev_sock);
     85  1.1    igy 			return EIO;
     86  1.1    igy 		}
     87  1.1    igy 		strlcpy(bootfile, fname, sizeof bootfile);
     88  1.1    igy 	}
     89  1.2    igy 
     90  1.2    igy 	*file = bootfile;
     91  1.1    igy 
     92  1.1    igy 	return 0;
     93  1.1    igy }
     94  1.1    igy 
     95  1.1    igy int
     96  1.1    igy net_close(struct open_file *f)
     97  1.1    igy {
     98  1.1    igy 	int	sock;
     99  1.1    igy 
    100  1.1    igy 	sock = *((int *) f->f_devdata);
    101  1.1    igy 	netif_close(sock);
    102  1.1    igy 	f->f_devdata = NULL;
    103  1.1    igy 	return 0;
    104  1.1    igy }
    105  1.1    igy 
    106  1.1    igy int
    107  1.1    igy net_ioctl(struct open_file *f, u_long cmd, void *data)
    108  1.1    igy {
    109  1.1    igy 	return EIO;
    110  1.1    igy }
    111