[BACK]Return to netio.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / stand / uboot

Annotation of sys/arch/hp300/stand/uboot/netio.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: netio.c,v 1.3 2006/08/17 06:31:10 miod Exp $  */
        !             2: /*     $NetBSD: netio.c,v 1.5 1997/01/30 10:32:56 thorpej Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1995, 1996 Jason R. Thorpe
        !             6:  * Copyright (c) 1995 Gordon W. Ross
        !             7:  * All rights reserved.
        !             8:  *
        !             9:  * Redistribution and use in source and binary forms, with or without
        !            10:  * modification, are permitted provided that the following conditions
        !            11:  * are met:
        !            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.
        !            17:  * 3. The name of the author may not be used to endorse or promote products
        !            18:  *    derived from this software without specific prior written permission.
        !            19:  * 4. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *      This product includes software developed by Gordon W. Ross
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            24:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            25:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            26:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            27:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            28:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            29:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            30:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            31:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            32:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            33:  */
        !            34:
        !            35: /*
        !            36:  * This module implements a "raw device" interface suitable for
        !            37:  * use by the stand-alone I/O library NFS code.  This interface
        !            38:  * does not support any "block" access, and exists only for the
        !            39:  * purpose of initializing the network interface, getting boot
        !            40:  * parameters, and performing the NFS mount.
        !            41:  *
        !            42:  * At open time, this does:
        !            43:  *
        !            44:  * find interface      - netif_open()
        !            45:  * RARP for IP address - rarp_getipaddress()
        !            46:  * RPC/bootparams      - callrpc(d, RPC_BOOTPARAMS, ...)
        !            47:  * RPC/mountd          - nfs_mount(sock, ip, path)
        !            48:  *
        !            49:  * the root file handle from mountd is saved in a global
        !            50:  * for use by the NFS open code (NFS/lookup).
        !            51:  */
        !            52:
        !            53: #include <sys/param.h>
        !            54: #include <sys/socket.h>
        !            55: #include <net/if.h>
        !            56: #include <netinet/in.h>
        !            57: #include <netinet/if_ether.h>
        !            58: #include <netinet/in_systm.h>
        !            59:
        !            60: #include <lib/libsa/stand.h>
        !            61:
        !            62: #include "samachdep.h"
        !            63:
        !            64: #include <lib/libsa/net.h>
        !            65: #include <lib/libsa/netif.h>
        !            66: #include <lib/libsa/bootparam.h>
        !            67: #include <lib/libsa/nfs.h>
        !            68:
        !            69: extern int nfs_root_node[];    /* XXX - get from nfs_mount() */
        !            70:
        !            71: struct in_addr myip, rootip, gateip;
        !            72: n_long netmask;
        !            73: char rootpath[FNAME_SIZE];
        !            74:
        !            75: int netdev_sock = -1;
        !            76: static int open_count;
        !            77:
        !            78: int netio_ask = 0;             /* default to bootparam, can override */
        !            79:
        !            80: static char input_line[100];
        !            81:
        !            82: /* Why be any different? */
        !            83: #define SUN_BOOTPARAMS
        !            84:
        !            85: int    netclose(struct open_file *);
        !            86: int    netmountroot(struct open_file *, char *);
        !            87: int    netopen(struct open_file *, char *);
        !            88: int    netstrategy(void *, int, daddr_t, size_t, void *, size_t *);
        !            89:
        !            90: /*
        !            91:  * Called by devopen after it sets f->f_dev to our devsw entry.
        !            92:  * This opens the low-level device and sets f->f_devdata.
        !            93:  */
        !            94: int
        !            95: netopen(struct open_file *f, char *devname)
        !            96: {
        !            97:        int error = 0;
        !            98:
        !            99:        /* On first open, do netif open, mount, etc. */
        !           100:        if (open_count == 0) {
        !           101:                /* Find network interface. */
        !           102:                if ((netdev_sock = netif_open(devname)) < 0)
        !           103:                        return (error=ENXIO);
        !           104:                if ((error = netmountroot(f, devname)) != 0)
        !           105:                        return (error);
        !           106:        }
        !           107:        open_count++;
        !           108:        f->f_devdata = nfs_root_node;
        !           109:        return (error);
        !           110: }
        !           111:
        !           112: int
        !           113: netclose(struct open_file *f)
        !           114: {
        !           115:        /* On last close, do netif close, etc. */
        !           116:        if (open_count > 0)
        !           117:                if (--open_count == 0)
        !           118:                        netif_close(netdev_sock);
        !           119:        f->f_devdata = NULL;
        !           120:        return (0);
        !           121: }
        !           122:
        !           123: int
        !           124: netstrategy(void *devdata, int func, daddr_t dblk, size_t size, void *v_buf,
        !           125:     size_t *rsize)
        !           126: {
        !           127:
        !           128:        *rsize = size;
        !           129:        return EIO;
        !           130: }
        !           131:
        !           132: int
        !           133: netmountroot(struct open_file *f, char *devname)
        !           134: {
        !           135:        int error;
        !           136:        struct iodesc *d;
        !           137:
        !           138: #ifdef DEBUG
        !           139:        printf("netmountroot: %s\n", devname);
        !           140: #endif
        !           141:
        !           142:        if (netio_ask) {
        !           143:  get_my_ip:
        !           144:                printf("My IP address? ");
        !           145:                bzero(input_line, sizeof(input_line));
        !           146:                gets(input_line);
        !           147:                if ((myip.s_addr = inet_addr(input_line)) ==
        !           148:                    htonl(INADDR_NONE)) {
        !           149:                        printf("invalid IP address: %s\n", input_line);
        !           150:                        goto get_my_ip;
        !           151:                }
        !           152:
        !           153:  get_my_netmask:
        !           154:                printf("My netmask? ");
        !           155:                bzero(input_line, sizeof(input_line));
        !           156:                gets(input_line);
        !           157:                if ((netmask = inet_addr(input_line)) ==
        !           158:                    htonl(INADDR_NONE)) {
        !           159:                        printf("invalid netmask: %s\n", input_line);
        !           160:                        goto get_my_netmask;
        !           161:                }
        !           162:
        !           163:  get_my_gateway:
        !           164:                printf("My gateway? ");
        !           165:                bzero(input_line, sizeof(input_line));
        !           166:                gets(input_line);
        !           167:                if ((gateip.s_addr = inet_addr(input_line)) ==
        !           168:                    htonl(INADDR_NONE)) {
        !           169:                        printf("invalid IP address: %s\n", input_line);
        !           170:                        goto get_my_gateway;
        !           171:                }
        !           172:
        !           173:  get_server_ip:
        !           174:                printf("Server IP address? ");
        !           175:                bzero(input_line, sizeof(input_line));
        !           176:                gets(input_line);
        !           177:                if ((rootip.s_addr = inet_addr(input_line)) ==
        !           178:                    htonl(INADDR_NONE)) {
        !           179:                        printf("invalid IP address: %s\n", input_line);
        !           180:                        goto get_server_ip;
        !           181:                }
        !           182:
        !           183:  get_server_path:
        !           184:                printf("Server path? ");
        !           185:                bzero(rootpath, sizeof(rootpath));
        !           186:                gets(rootpath);
        !           187:                if (rootpath[0] == '\0' || rootpath[0] == '\n')
        !           188:                        goto get_server_path;
        !           189:
        !           190:                if ((d = socktodesc(netdev_sock)) == NULL)
        !           191:                        return (EMFILE);
        !           192:
        !           193:                d->myip = myip;
        !           194:
        !           195:                goto do_nfs_mount;
        !           196:        }
        !           197:
        !           198:        /*
        !           199:         * Get info for NFS boot: our IP address, our hostname,
        !           200:         * server IP address, and our root path on the server.
        !           201:         * There are two ways to do this:  The old, Sun way,
        !           202:         * and the more modern, BOOTP way. (RFC951, RFC1048)
        !           203:         */
        !           204:
        !           205: #ifdef SUN_BOOTPARAMS
        !           206:        /* Get boot info using RARP and Sun bootparams. */
        !           207:
        !           208:        /* Get our IP address.  (rarp.c) */
        !           209:        if (rarp_getipaddress(netdev_sock) == -1)
        !           210:                return (errno);
        !           211:
        !           212:        printf("boot: client IP address: %s\n", inet_ntoa(myip));
        !           213:
        !           214:        /* Get our hostname, server IP address. */
        !           215:        if (bp_whoami(netdev_sock))
        !           216:                return (errno);
        !           217:
        !           218:        printf("boot: client name: %s\n", hostname);
        !           219:
        !           220:        /* Get the root pathname. */
        !           221:        if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
        !           222:                return (errno);
        !           223:
        !           224: #else
        !           225:
        !           226:        /* Get boot info using BOOTP way. (RFC951, RFC1048) */
        !           227:        bootp(netdev_sock);
        !           228:
        !           229:        printf("Using IP address: %s\n", inet_ntoa(myip));
        !           230:
        !           231:        printf("myip: %s (%s)", hostname, inet_ntoa(myip));
        !           232:        if (gateip)
        !           233:                printf(", gateip: %s", inet_ntoa(gateip));
        !           234:        if (mask)
        !           235:                printf(", mask: %s", intoa(netmask));
        !           236:        printf("\n");
        !           237:
        !           238: #endif /* SUN_BOOTPARAMS */
        !           239:
        !           240:        printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
        !           241:
        !           242:  do_nfs_mount:
        !           243:        /* Get the NFS file handle (mount). */
        !           244:        error = nfs_mount(netdev_sock, rootip, rootpath);
        !           245:
        !           246:        return (error);
        !           247: }

CVSweb