Home | History | Annotate | Line # | Download | only in rbootd
rmp_var.h revision 1.4
      1 /*	$NetBSD: rmp_var.h,v 1.4 1995/09/12 07:13:10 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1992 The University of Utah and the Center
      5  *	for Software Science (CSS).
      6  * Copyright (c) 1992, 1993
      7  *	The Regents of the University of California.  All rights reserved.
      8  *
      9  * This code is derived from software contributed to Berkeley by
     10  * the Center for Software Science of the University of Utah Computer
     11  * Science Department.  CSS requests users of this software to return
     12  * to css-dist (at) cs.utah.edu any improvements that they make and grant
     13  * CSS redistribution rights.
     14  *
     15  * Redistribution and use in source and binary forms, with or without
     16  * modification, are permitted provided that the following conditions
     17  * are met:
     18  * 1. Redistributions of source code must retain the above copyright
     19  *    notice, this list of conditions and the following disclaimer.
     20  * 2. Redistributions in binary form must reproduce the above copyright
     21  *    notice, this list of conditions and the following disclaimer in the
     22  *    documentation and/or other materials provided with the distribution.
     23  * 3. All advertising materials mentioning features or use of this software
     24  *    must display the following acknowledgement:
     25  *	This product includes software developed by the University of
     26  *	California, Berkeley and its contributors.
     27  * 4. Neither the name of the University nor the names of its contributors
     28  *    may be used to endorse or promote products derived from this software
     29  *    without specific prior written permission.
     30  *
     31  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     41  * SUCH DAMAGE.
     42  *
     43  *	from: @(#)rmp_var.h	8.1 (Berkeley) 6/4/93
     44  *
     45  * from: Utah Hdr: rmp_var.h 3.1 92/07/06
     46  * Author: Jeff Forys, University of Utah CSS
     47  */
     48 
     49 /*
     50  *  Possible values for "rmp_type" fields.
     51  */
     52 
     53 #define	RMP_BOOT_REQ	1	/* boot request packet */
     54 #define	RMP_BOOT_REPL	129	/* boot reply packet */
     55 #define	RMP_READ_REQ	2	/* read request packet */
     56 #define	RMP_READ_REPL	130	/* read reply packet */
     57 #define	RMP_BOOT_DONE	3	/* boot complete packet */
     58 
     59 /*
     60  *  Useful constants.
     61  */
     62 
     63 #define RMP_VERSION	2	/* protocol version */
     64 #define RMP_TIMEOUT	600	/* timeout connection after ten minutes */
     65 #define	RMP_PROBESID	0xffff	/* session ID for probes */
     66 #define	RMP_HOSTLEN	13	/* max length of server's name */
     67 #define	RMP_MACHLEN	20	/* length of machine type field */
     68 
     69 /*
     70  *  RMP error codes
     71  */
     72 
     73 #define	RMP_E_OKAY	0
     74 #define	RMP_E_EOF	2	/* read reply: returned end of file */
     75 #define	RMP_E_ABORT	3	/* abort operation */
     76 #define	RMP_E_BUSY	4	/* boot reply: server busy */
     77 #define	RMP_E_TIMEOUT	5	/* lengthen time out (not implemented) */
     78 #define	RMP_E_NOFILE	16	/* boot reply: file does not exist */
     79 #define RMP_E_OPENFILE	17	/* boot reply: file open failed */
     80 #define	RMP_E_NODFLT	18	/* boot reply: default file does not exist */
     81 #define RMP_E_OPENDFLT	19	/* boot reply: default file open failed */
     82 #define	RMP_E_BADSID	25	/* read reply: bad session ID */
     83 #define RMP_E_BADPACKET	27 	/* Bad packet detected */
     84 
     85 /*
     86  *  RMPDATALEN is the maximum number of data octets that can be stuffed
     87  *  into an RMP packet.  This excludes the 802.2 LLC w/HP extensions.
     88  */
     89 #define RMPDATALEN	(RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \
     90 			                   sizeof(struct hp_llc)))
     91 
     92 /*
     93  *  Define sizes of packets we send.  Boot and Read replies are variable
     94  *  in length depending on the length of `s'.
     95  *
     96  *  Also, define how much space `restofpkt' can take up for outgoing
     97  *  Boot and Read replies.  Boot Request packets are effectively
     98  *  limited to 255 bytes due to the preceding 1-byte length field.
     99  */
    100 
    101 #define	RMPBOOTSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
    102 			 sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt))
    103 #define	RMPREADSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
    104 			 sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \
    105 			 - sizeof(u_char))
    106 #define	RMPDONESIZE	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
    107 			 sizeof(struct rmp_boot_done))
    108 #define	RMPBOOTDATA	255
    109 #define	RMPREADDATA	(RMPDATALEN - \
    110 			 (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_word)))
    111 
    112 /*
    113  * This protocol defines some field sizes as "rest of ethernet packet".
    114  * There is no easy way to specify this in C, so we use a one character
    115  * field to denote it, and index past it to the end of the packet.
    116  */
    117 
    118 typedef char	restofpkt;
    119 
    120 /*
    121  * Due to the RMP packet layout, we'll run into alignment problems
    122  * on machines that can't access (or don't, by default, align) words
    123  * on half-word boundaries.  If you know that your machine does not suffer
    124  * from this problem, add it to the vax/tahoe/m68k #define below.
    125  *
    126  * The following macros are used to deal with this problem:
    127  *	WORDZE(w)	Return True if u_word `w' is zero, False otherwise.
    128  *	ZEROWORD(w)	Set u_word `w' to zero.
    129  *	COPYWORD(w1,w2)	Copy u_word `w1' to `w2'.
    130  *	GETWORD(w,i)	Copy u_word `w' into int `i'.
    131  *	PUTWORD(i,w)	Copy int `i' into u_word `w'.
    132  *
    133  * N.B. Endianness is handled by use of ntohl/htonl
    134  */
    135 #if defined(__vax__) || defined(__tahoe__) || defined(__m68k__)
    136 
    137 typedef	u_int		u_word;
    138 
    139 #define	WORDZE(w)	((w) == 0)
    140 #define	ZEROWORD(w)	(w) = 0
    141 #define	COPYWORD(w1,w2)	(w2) = (w1)
    142 #define	GETWORD(w, i)	(i) = ntohl(w)
    143 #define	PUTWORD(i, w)	(w) = htonl(i)
    144 
    145 #else
    146 
    147 #define	_WORD_HIGHPART	0
    148 #define	_WORD_LOWPART	1
    149 
    150 typedef	struct _uword { u_short val[2]; }	u_word;
    151 
    152 #define	WORDZE(w) \
    153 	((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0))
    154 #define	ZEROWORD(w) \
    155 	(w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0
    156 #define	COPYWORD(w1, w2) \
    157 	{ (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \
    158 	  (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \
    159 	}
    160 #define	GETWORD(w, i) \
    161 	(i) = ntohl((((u_int)(w).val[_WORD_HIGHPART]) << 16) | (w).val[_WORD_LOWPART])
    162 #define	PUTWORD(i, w) \
    163 	{ int xx = htonl(i); \
    164 	  (w).val[_WORD_HIGHPART] = (u_short) ((xx >> 16) & 0xffff); \
    165 	  (w).val[_WORD_LOWPART] = (u_short) (xx & 0xffff); \
    166 	}
    167 
    168 #endif
    169 
    170 /*
    171  * Packet structures.
    172  */
    173 
    174 struct rmp_raw {		/* generic RMP packet */
    175 	u_char	rmp_type;		/* packet type */
    176 	u_char	rmp_rawdata[RMPDATALEN-1];
    177 };
    178 
    179 struct rmp_boot_req {		/* boot request */
    180 	u_char	rmp_type;		/* packet type (RMP_BOOT_REQ) */
    181 	u_char	rmp_retcode;		/* return code (0) */
    182 	u_word	rmp_seqno;		/* sequence number (real time clock) */
    183 	u_short	rmp_session;		/* session id (normally 0) */
    184 	u_short	rmp_version;		/* protocol version (RMP_VERSION) */
    185 	char	rmp_machtype[RMP_MACHLEN];	/* machine type */
    186 	u_char	rmp_flnmsize;		/* length of rmp_flnm */
    187 	restofpkt rmp_flnm;		/* name of file to be read */
    188 };
    189 
    190 struct rmp_boot_repl {		/* boot reply */
    191 	u_char	rmp_type;		/* packet type (RMP_BOOT_REPL) */
    192 	u_char	rmp_retcode;		/* return code (normally 0) */
    193 	u_word	rmp_seqno;		/* sequence number (from boot req) */
    194 	u_short	rmp_session;		/* session id (generated) */
    195 	u_short	rmp_version;		/* protocol version (RMP_VERSION) */
    196 	u_char	rmp_flnmsize;		/* length of rmp_flnm */
    197 	restofpkt rmp_flnm;		/* name of file (from boot req) */
    198 };
    199 
    200 struct rmp_read_req {		/* read request */
    201 	u_char	rmp_type;		/* packet type (RMP_READ_REQ) */
    202 	u_char	rmp_retcode;		/* return code (0) */
    203 	u_word	rmp_offset;		/* file relative byte offset */
    204 	u_short	rmp_session;		/* session id (from boot repl) */
    205 	u_short	rmp_size;		/* max no of bytes to send */
    206 };
    207 
    208 struct rmp_read_repl {		/* read reply */
    209 	u_char	rmp_type;		/* packet type (RMP_READ_REPL) */
    210 	u_char	rmp_retcode;		/* return code (normally 0) */
    211 	u_word	rmp_offset;		/* byte offset (from read req) */
    212 	u_short	rmp_session;		/* session id (from read req) */
    213 	restofpkt rmp_data;		/* data (max size from read req) */
    214 	u_char	rmp_unused;		/* padding to 16-bit boundary */
    215 };
    216 
    217 struct rmp_boot_done {		/* boot complete */
    218 	u_char	rmp_type;		/* packet type (RMP_BOOT_DONE) */
    219 	u_char	rmp_retcode;		/* return code (0) */
    220 	u_word	rmp_unused;		/* not used (0) */
    221 	u_short	rmp_session;		/* session id (from read repl) */
    222 };
    223 
    224 struct rmp_packet {
    225 	struct hp_hdr hp_hdr;
    226 	struct hp_llc hp_llc;
    227 	union {
    228 		struct rmp_boot_req	rmp_brq;	/* boot request */
    229 		struct rmp_boot_repl	rmp_brpl;	/* boot reply */
    230 		struct rmp_read_req	rmp_rrq;	/* read request */
    231 		struct rmp_read_repl	rmp_rrpl;	/* read reply */
    232 		struct rmp_boot_done	rmp_done;	/* boot complete */
    233 		struct rmp_raw		rmp_raw;	/* raw data */
    234 	} rmp_proto;
    235 };
    236 
    237 /*
    238  *  Make life easier...
    239  */
    240 
    241 #define	r_type	rmp_proto.rmp_raw.rmp_type
    242 #define	r_data	rmp_proto.rmp_raw.rmp_data
    243 #define	r_brq	rmp_proto.rmp_brq
    244 #define	r_brpl	rmp_proto.rmp_brpl
    245 #define	r_rrq	rmp_proto.rmp_rrq
    246 #define	r_rrpl	rmp_proto.rmp_rrpl
    247 #define	r_done	rmp_proto.rmp_done
    248