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