11592Srgrimes/*
21592Srgrimes * Copyright (c) 1988, 1992 The University of Utah and the Center
31592Srgrimes *	for Software Science (CSS).
41592Srgrimes * Copyright (c) 1992, 1993
51592Srgrimes *	The Regents of the University of California.  All rights reserved.
61592Srgrimes *
71592Srgrimes * This code is derived from software contributed to Berkeley by
81592Srgrimes * the Center for Software Science of the University of Utah Computer
91592Srgrimes * Science Department.  CSS requests users of this software to return
101592Srgrimes * to css-dist@cs.utah.edu any improvements that they make and grant
111592Srgrimes * CSS redistribution rights.
121592Srgrimes *
131592Srgrimes * Redistribution and use in source and binary forms, with or without
141592Srgrimes * modification, are permitted provided that the following conditions
151592Srgrimes * are met:
161592Srgrimes * 1. Redistributions of source code must retain the above copyright
171592Srgrimes *    notice, this list of conditions and the following disclaimer.
181592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
191592Srgrimes *    notice, this list of conditions and the following disclaimer in the
201592Srgrimes *    documentation and/or other materials provided with the distribution.
21262435Sbrueffer * 3. Neither the name of the University nor the names of its contributors
221592Srgrimes *    may be used to endorse or promote products derived from this software
231592Srgrimes *    without specific prior written permission.
241592Srgrimes *
251592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281592Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351592Srgrimes * SUCH DAMAGE.
361592Srgrimes *
3727074Ssteve *	from: @(#)rmp_var.h	8.1 (Berkeley) 6/4/93
381592Srgrimes *
3927074Ssteve * from: Utah Hdr: rmp_var.h 3.1 92/07/06
401592Srgrimes * Author: Jeff Forys, University of Utah CSS
41262434Sbrueffer *
42262434Sbrueffer * $FreeBSD$
431592Srgrimes */
441592Srgrimes
451592Srgrimes/*
461592Srgrimes *  Possible values for "rmp_type" fields.
471592Srgrimes */
481592Srgrimes
491592Srgrimes#define	RMP_BOOT_REQ	1	/* boot request packet */
501592Srgrimes#define	RMP_BOOT_REPL	129	/* boot reply packet */
511592Srgrimes#define	RMP_READ_REQ	2	/* read request packet */
521592Srgrimes#define	RMP_READ_REPL	130	/* read reply packet */
531592Srgrimes#define	RMP_BOOT_DONE	3	/* boot complete packet */
541592Srgrimes
551592Srgrimes/*
561592Srgrimes *  Useful constants.
571592Srgrimes */
581592Srgrimes
591592Srgrimes#define RMP_VERSION	2	/* protocol version */
601592Srgrimes#define RMP_TIMEOUT	600	/* timeout connection after ten minutes */
611592Srgrimes#define	RMP_PROBESID	0xffff	/* session ID for probes */
621592Srgrimes#define	RMP_HOSTLEN	13	/* max length of server's name */
631592Srgrimes#define	RMP_MACHLEN	20	/* length of machine type field */
641592Srgrimes
651592Srgrimes/*
661592Srgrimes *  RMP error codes
671592Srgrimes */
681592Srgrimes
691592Srgrimes#define	RMP_E_OKAY	0
701592Srgrimes#define	RMP_E_EOF	2	/* read reply: returned end of file */
711592Srgrimes#define	RMP_E_ABORT	3	/* abort operation */
721592Srgrimes#define	RMP_E_BUSY	4	/* boot reply: server busy */
731592Srgrimes#define	RMP_E_TIMEOUT	5	/* lengthen time out (not implemented) */
741592Srgrimes#define	RMP_E_NOFILE	16	/* boot reply: file does not exist */
751592Srgrimes#define RMP_E_OPENFILE	17	/* boot reply: file open failed */
761592Srgrimes#define	RMP_E_NODFLT	18	/* boot reply: default file does not exist */
771592Srgrimes#define RMP_E_OPENDFLT	19	/* boot reply: default file open failed */
781592Srgrimes#define	RMP_E_BADSID	25	/* read reply: bad session ID */
791592Srgrimes#define RMP_E_BADPACKET	27 	/* Bad packet detected */
801592Srgrimes
811592Srgrimes/*
821592Srgrimes *  RMPDATALEN is the maximum number of data octets that can be stuffed
831592Srgrimes *  into an RMP packet.  This excludes the 802.2 LLC w/HP extensions.
841592Srgrimes */
851592Srgrimes#define RMPDATALEN	(RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \
861592Srgrimes			                   sizeof(struct hp_llc)))
871592Srgrimes
881592Srgrimes/*
891592Srgrimes *  Define sizes of packets we send.  Boot and Read replies are variable
901592Srgrimes *  in length depending on the length of `s'.
911592Srgrimes *
921592Srgrimes *  Also, define how much space `restofpkt' can take up for outgoing
931592Srgrimes *  Boot and Read replies.  Boot Request packets are effectively
941592Srgrimes *  limited to 255 bytes due to the preceding 1-byte length field.
951592Srgrimes */
961592Srgrimes
971592Srgrimes#define	RMPBOOTSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
981592Srgrimes			 sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt))
991592Srgrimes#define	RMPREADSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
1001592Srgrimes			 sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \
10127074Ssteve			 - sizeof(u_int8_t))
1021592Srgrimes#define	RMPDONESIZE	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
1031592Srgrimes			 sizeof(struct rmp_boot_done))
1041592Srgrimes#define	RMPBOOTDATA	255
1051592Srgrimes#define	RMPREADDATA	(RMPDATALEN - \
10627074Ssteve			 (2*sizeof(u_int8_t)+sizeof(u_int16_t)+sizeof(u_word)))
1071592Srgrimes
1081592Srgrimes/*
1091592Srgrimes * This protocol defines some field sizes as "rest of ethernet packet".
1101592Srgrimes * There is no easy way to specify this in C, so we use a one character
1111592Srgrimes * field to denote it, and index past it to the end of the packet.
1121592Srgrimes */
1131592Srgrimes
1141592Srgrimestypedef char	restofpkt;
1151592Srgrimes
1161592Srgrimes/*
1171592Srgrimes * Due to the RMP packet layout, we'll run into alignment problems
11827074Ssteve * on machines that can't access (or don't, by default, align) words
11927074Ssteve * on half-word boundaries.  If you know that your machine does not suffer
12027074Ssteve * from this problem, add it to the vax/tahoe/m68k #define below.
1211592Srgrimes *
1221592Srgrimes * The following macros are used to deal with this problem:
1231592Srgrimes *	WORDZE(w)	Return True if u_word `w' is zero, False otherwise.
1241592Srgrimes *	ZEROWORD(w)	Set u_word `w' to zero.
1251592Srgrimes *	COPYWORD(w1,w2)	Copy u_word `w1' to `w2'.
1261592Srgrimes *	GETWORD(w,i)	Copy u_word `w' into int `i'.
1271592Srgrimes *	PUTWORD(i,w)	Copy int `i' into u_word `w'.
12827079Ssteve *
12927074Ssteve * N.B. Endianness is handled by use of ntohl/htonl
1301592Srgrimes */
13127074Ssteve#if defined(__vax__) || defined(__tahoe__) || defined(__m68k__)
1321592Srgrimes
13327074Sstevetypedef	u_int32_t	u_word;
1341592Srgrimes
1351592Srgrimes#define	WORDZE(w)	((w) == 0)
1361592Srgrimes#define	ZEROWORD(w)	(w) = 0
1371592Srgrimes#define	COPYWORD(w1,w2)	(w2) = (w1)
13827074Ssteve#define	GETWORD(w, i)	(i) = ntohl(w)
13927074Ssteve#define	PUTWORD(i, w)	(w) = htonl(i)
1401592Srgrimes
1411592Srgrimes#else
1421592Srgrimes
14327074Ssteve#define	_WORD_HIGHPART	0
1441592Srgrimes#define	_WORD_LOWPART	1
1451592Srgrimes
14627074Sstevetypedef	struct _uword { u_int16_t val[2]; }	u_word;
1471592Srgrimes
1481592Srgrimes#define	WORDZE(w) \
1491592Srgrimes	((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0))
1501592Srgrimes#define	ZEROWORD(w) \
1511592Srgrimes	(w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0
1521592Srgrimes#define	COPYWORD(w1, w2) \
1531592Srgrimes	{ (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \
1541592Srgrimes	  (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \
1551592Srgrimes	}
1561592Srgrimes#define	GETWORD(w, i) \
15727074Ssteve	(i) = (((u_int32_t)ntohs((w).val[_WORD_HIGHPART])) << 16) | ntohs((w).val[_WORD_LOWPART])
1581592Srgrimes#define	PUTWORD(i, w) \
15927074Ssteve	{ (w).val[_WORD_HIGHPART] = htons((u_int16_t) ((i >> 16) & 0xffff)); \
16027074Ssteve	  (w).val[_WORD_LOWPART] = htons((u_int16_t) (i & 0xffff)); \
1611592Srgrimes	}
1621592Srgrimes
1631592Srgrimes#endif
1641592Srgrimes
1651592Srgrimes/*
1661592Srgrimes * Packet structures.
1671592Srgrimes */
1681592Srgrimes
1691592Srgrimesstruct rmp_raw {		/* generic RMP packet */
17027074Ssteve	u_int8_t  rmp_type;		/* packet type */
17127074Ssteve	u_int8_t  rmp_rawdata[RMPDATALEN-1];
1721592Srgrimes};
1731592Srgrimes
1741592Srgrimesstruct rmp_boot_req {		/* boot request */
17527074Ssteve	u_int8_t  rmp_type;		/* packet type (RMP_BOOT_REQ) */
17627074Ssteve	u_int8_t  rmp_retcode;		/* return code (0) */
17727074Ssteve	u_word	  rmp_seqno;		/* sequence number (real time clock) */
17827074Ssteve	u_int16_t rmp_session;		/* session id (normally 0) */
17927074Ssteve	u_int16_t rmp_version;		/* protocol version (RMP_VERSION) */
18027074Ssteve	char	  rmp_machtype[RMP_MACHLEN];	/* machine type */
18127074Ssteve	u_int8_t  rmp_flnmsize;		/* length of rmp_flnm */
1821592Srgrimes	restofpkt rmp_flnm;		/* name of file to be read */
1831592Srgrimes};
1841592Srgrimes
1851592Srgrimesstruct rmp_boot_repl {		/* boot reply */
18627074Ssteve	u_int8_t  rmp_type;		/* packet type (RMP_BOOT_REPL) */
18727074Ssteve	u_int8_t  rmp_retcode;		/* return code (normally 0) */
18827074Ssteve	u_word	  rmp_seqno;		/* sequence number (from boot req) */
18927074Ssteve	u_int16_t rmp_session;		/* session id (generated) */
19027074Ssteve	u_int16_t rmp_version;		/* protocol version (RMP_VERSION) */
19127074Ssteve	u_int8_t  rmp_flnmsize;		/* length of rmp_flnm */
1921592Srgrimes	restofpkt rmp_flnm;		/* name of file (from boot req) */
1931592Srgrimes};
1941592Srgrimes
1951592Srgrimesstruct rmp_read_req {		/* read request */
19627074Ssteve	u_int8_t  rmp_type;		/* packet type (RMP_READ_REQ) */
19727074Ssteve	u_int8_t  rmp_retcode;		/* return code (0) */
19827074Ssteve	u_word	  rmp_offset;		/* file relative byte offset */
19927074Ssteve	u_int16_t rmp_session;		/* session id (from boot repl) */
20027074Ssteve	u_int16_t rmp_size;		/* max no of bytes to send */
2011592Srgrimes};
2021592Srgrimes
2031592Srgrimesstruct rmp_read_repl {		/* read reply */
20427074Ssteve	u_int8_t  rmp_type;		/* packet type (RMP_READ_REPL) */
20527074Ssteve	u_int8_t  rmp_retcode;		/* return code (normally 0) */
20627074Ssteve	u_word	  rmp_offset;		/* byte offset (from read req) */
20727074Ssteve	u_int16_t rmp_session;		/* session id (from read req) */
2081592Srgrimes	restofpkt rmp_data;		/* data (max size from read req) */
20927074Ssteve	u_int8_t  rmp_unused;		/* padding to 16-bit boundary */
2101592Srgrimes};
2111592Srgrimes
2121592Srgrimesstruct rmp_boot_done {		/* boot complete */
21327074Ssteve	u_int8_t  rmp_type;		/* packet type (RMP_BOOT_DONE) */
21427074Ssteve	u_int8_t  rmp_retcode;		/* return code (0) */
21527074Ssteve	u_word	  rmp_unused;		/* not used (0) */
21627074Ssteve	u_int16_t rmp_session;		/* session id (from read repl) */
2171592Srgrimes};
2181592Srgrimes
2191592Srgrimesstruct rmp_packet {
2201592Srgrimes	struct hp_hdr hp_hdr;
2211592Srgrimes	struct hp_llc hp_llc;
2221592Srgrimes	union {
2231592Srgrimes		struct rmp_boot_req	rmp_brq;	/* boot request */
2241592Srgrimes		struct rmp_boot_repl	rmp_brpl;	/* boot reply */
2251592Srgrimes		struct rmp_read_req	rmp_rrq;	/* read request */
2261592Srgrimes		struct rmp_read_repl	rmp_rrpl;	/* read reply */
2271592Srgrimes		struct rmp_boot_done	rmp_done;	/* boot complete */
2281592Srgrimes		struct rmp_raw		rmp_raw;	/* raw data */
2291592Srgrimes	} rmp_proto;
2301592Srgrimes};
2311592Srgrimes
2321592Srgrimes/*
2331592Srgrimes *  Make life easier...
2341592Srgrimes */
2351592Srgrimes
2361592Srgrimes#define	r_type	rmp_proto.rmp_raw.rmp_type
23727074Ssteve#define	r_data	rmp_proto.rmp_raw.rmp_rawdata
2381592Srgrimes#define	r_brq	rmp_proto.rmp_brq
2391592Srgrimes#define	r_brpl	rmp_proto.rmp_brpl
2401592Srgrimes#define	r_rrq	rmp_proto.rmp_rrq
2411592Srgrimes#define	r_rrpl	rmp_proto.rmp_rrpl
2421592Srgrimes#define	r_done	rmp_proto.rmp_done
243