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