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