1 /* $NetBSD: dev_net.c,v 1.14 2009/03/14 21:04:10 dsl Exp $ */
4 * Copyright (c) 1995 Gordon W. Ross
7 * Matthias Drochner. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * network device for libsa
32 * supports BOOTP, RARP and BOOTPARAM
35 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
41 #include <lib/libsa/stand.h>
42 #include <lib/libsa/net.h>
43 #include <lib/libsa/bootparam.h>
44 #include <machine/stdarg.h>
46 #include <netif/netif_small.h>
48 #include <lib/libkern/libkern.h>
56 static int netdev_sock
= -1;
59 * Called by devopen after it sets f->f_dev to our devsw entry.
60 * This opens the low-level device and sets f->f_devdata.
63 net_open(struct open_file
*f
, ...)
68 if (netdev_sock
!= -1)
72 /* Find network interface. */
73 if ((netdev_sock
= netif_open()) < 0)
77 printf("configure network...trying bootp\n");
78 /* Get boot info using BOOTP way. (RFC951, RFC1048) */
82 if (myip
.s_addr
!= INADDR_ANY
) { /* got bootp reply or
87 /* XXX (some) tftp servers don't like leading "/" */
88 for (num
= 0; bootfile
[num
] == '/'; num
++);
89 for (i
= 0; (bootfile
[i
] = bootfile
[i
+ num
]) != 0; i
++);
92 printf("boot: client IP address: %s\n",
94 printf("boot: client name: %s\n", hostname
);
99 * no answer, Get boot info using RARP and Sun
102 printf("configure network...trying rarp\n");
104 /* Get our IP address. (rarp.c) */
105 if (rarp_getipaddress(netdev_sock
)) {
109 printf("boot: client IP address: %s\n",
112 #ifdef SUPPORT_BOOTPARAM
113 /* Get our hostname, server IP address. */
114 if (!bp_whoami(netdev_sock
)) {
115 printf("boot: client name: %s\n", hostname
);
117 /* Get the root pathname. */
118 bp_getfile(netdev_sock
, "root", &rootip
,
123 * else fallback: use rarp server address
127 #else /* no SUPPORT_RARP */
133 printf("boot: server: %s, rootpath: %s, bootfile: %s\n",
134 inet_ntoa(rootip
), rootpath
, bootfile
);
136 f
->f_devdata
= &netdev_sock
;
140 printf("net_open failed\n");
141 netif_close(netdev_sock
);
146 net_close(struct open_file
*f
)
149 if (netdev_sock
== -1)
153 netif_close(netdev_sock
);
162 net_ioctl(struct open_file
*f
, u_long c
, void *d
)
168 net_strategy(void *d
, int f
, daddr_t b
, size_t s
, void *buf
, size_t *r
)