xref: /csrg-svn/libexec/rbootd/rmp_var.h (revision 61443)
155577Sbostic /*
255577Sbostic  * Copyright (c) 1988, 1992 The University of Utah and the Center
355577Sbostic  *	for Software Science (CSS).
4*61443Sbostic  * Copyright (c) 1992, 1993
5*61443Sbostic  *	The Regents of the University of California.  All rights reserved.
655577Sbostic  *
755577Sbostic  * This code is derived from software contributed to Berkeley by
855577Sbostic  * the Center for Software Science of the University of Utah Computer
955577Sbostic  * Science Department.  CSS requests users of this software to return
1055577Sbostic  * to css-dist@cs.utah.edu any improvements that they make and grant
1155577Sbostic  * CSS redistribution rights.
1255577Sbostic  *
1355577Sbostic  * %sccs.include.redist.c%
1455577Sbostic  *
15*61443Sbostic  *	@(#)rmp_var.h	8.1 (Berkeley) 06/04/93
1655577Sbostic  *
1755577Sbostic  * Utah $Hdr: rmp_var.h 3.1 92/07/06$
1855577Sbostic  * Author: Jeff Forys, University of Utah CSS
1955577Sbostic  */
2055577Sbostic 
2155577Sbostic /*
2255577Sbostic  *  Possible values for "rmp_type" fields.
2355577Sbostic  */
2455577Sbostic 
2555577Sbostic #define	RMP_BOOT_REQ	1	/* boot request packet */
2655577Sbostic #define	RMP_BOOT_REPL	129	/* boot reply packet */
2755577Sbostic #define	RMP_READ_REQ	2	/* read request packet */
2855577Sbostic #define	RMP_READ_REPL	130	/* read reply packet */
2955577Sbostic #define	RMP_BOOT_DONE	3	/* boot complete packet */
3055577Sbostic 
3155577Sbostic /*
3255577Sbostic  *  Useful constants.
3355577Sbostic  */
3455577Sbostic 
3555577Sbostic #define RMP_VERSION	2	/* protocol version */
3655577Sbostic #define RMP_TIMEOUT	600	/* timeout connection after ten minutes */
3755577Sbostic #define	RMP_PROBESID	0xffff	/* session ID for probes */
3855577Sbostic #define	RMP_HOSTLEN	13	/* max length of server's name */
3955577Sbostic #define	RMP_MACHLEN	20	/* length of machine type field */
4055577Sbostic 
4155577Sbostic /*
4255577Sbostic  *  RMP error codes
4355577Sbostic  */
4455577Sbostic 
4555577Sbostic #define	RMP_E_OKAY	0
4655577Sbostic #define	RMP_E_EOF	2	/* read reply: returned end of file */
4755577Sbostic #define	RMP_E_ABORT	3	/* abort operation */
4855577Sbostic #define	RMP_E_BUSY	4	/* boot reply: server busy */
4955577Sbostic #define	RMP_E_TIMEOUT	5	/* lengthen time out (not implemented) */
5055577Sbostic #define	RMP_E_NOFILE	16	/* boot reply: file does not exist */
5155577Sbostic #define RMP_E_OPENFILE	17	/* boot reply: file open failed */
5255577Sbostic #define	RMP_E_NODFLT	18	/* boot reply: default file does not exist */
5355577Sbostic #define RMP_E_OPENDFLT	19	/* boot reply: default file open failed */
5455577Sbostic #define	RMP_E_BADSID	25	/* read reply: bad session ID */
5555577Sbostic #define RMP_E_BADPACKET	27 	/* Bad packet detected */
5655577Sbostic 
5755577Sbostic /*
5855577Sbostic  *  RMPDATALEN is the maximum number of data octets that can be stuffed
5955577Sbostic  *  into an RMP packet.  This excludes the 802.2 LLC w/HP extensions.
6055577Sbostic  */
6155577Sbostic #define RMPDATALEN	(RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \
6255577Sbostic 			                   sizeof(struct hp_llc)))
6355577Sbostic 
6455577Sbostic /*
6555577Sbostic  *  Define sizes of packets we send.  Boot and Read replies are variable
6655577Sbostic  *  in length depending on the length of `s'.
6755577Sbostic  *
6855577Sbostic  *  Also, define how much space `restofpkt' can take up for outgoing
6955577Sbostic  *  Boot and Read replies.  Boot Request packets are effectively
7055577Sbostic  *  limited to 255 bytes due to the preceding 1-byte length field.
7155577Sbostic  */
7255577Sbostic 
7355577Sbostic #define	RMPBOOTSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
7455577Sbostic 			 sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt))
7555577Sbostic #define	RMPREADSIZE(s)	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
7655577Sbostic 			 sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \
7755577Sbostic 			 - sizeof(u_char))
7855577Sbostic #define	RMPDONESIZE	(sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \
7955577Sbostic 			 sizeof(struct rmp_boot_done))
8055577Sbostic #define	RMPBOOTDATA	255
8155577Sbostic #define	RMPREADDATA	(RMPDATALEN - \
8255577Sbostic 			 (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_word)))
8355577Sbostic 
8455577Sbostic /*
8555577Sbostic  * This protocol defines some field sizes as "rest of ethernet packet".
8655577Sbostic  * There is no easy way to specify this in C, so we use a one character
8755577Sbostic  * field to denote it, and index past it to the end of the packet.
8855577Sbostic  */
8955577Sbostic 
9055577Sbostic typedef char	restofpkt;
9155577Sbostic 
9255577Sbostic /*
9355577Sbostic  * Due to the RMP packet layout, we'll run into alignment problems
9455577Sbostic  * on machines that cant access words on half-word boundaries.  If
9555577Sbostic  * you know that your machine does not suffer from this problem,
9655577Sbostic  * add it to the hp300 #define below.
9755577Sbostic  *
9855577Sbostic  * The following macros are used to deal with this problem:
9955577Sbostic  *	WORDZE(w)	Return True if u_word `w' is zero, False otherwise.
10055577Sbostic  *	ZEROWORD(w)	Set u_word `w' to zero.
10155577Sbostic  *	COPYWORD(w1,w2)	Copy u_word `w1' to `w2'.
10255577Sbostic  *	GETWORD(w,i)	Copy u_word `w' into int `i'.
10355577Sbostic  *	PUTWORD(i,w)	Copy int `i' into u_word `w'.
10455577Sbostic  *
10555577Sbostic  * N.B. We do not support little endian alignment-challenged machines.
10655577Sbostic  */
10755577Sbostic #if defined(vax) || defined(tahoe) || defined(hp300)
10855577Sbostic 
10955577Sbostic typedef	u_int		u_word;
11055577Sbostic 
11155577Sbostic #define	WORDZE(w)	((w) == 0)
11255577Sbostic #define	ZEROWORD(w)	(w) = 0
11355577Sbostic #define	COPYWORD(w1,w2)	(w2) = (w1)
11455577Sbostic #define	GETWORD(w, i)	(i) = (w)
11555577Sbostic #define	PUTWORD(i, w)	(w) = (i)
11655577Sbostic 
11755577Sbostic #else
11855577Sbostic 
11955577Sbostic #define	_WORD_HIGHPART	0	/* XXX: assume Big Endian for now */
12055577Sbostic #define	_WORD_LOWPART	1
12155577Sbostic 
12255577Sbostic typedef	struct _uword { u_short val[2]; }	u_word;
12355577Sbostic 
12455577Sbostic #define	WORDZE(w) \
12555577Sbostic 	((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0))
12655577Sbostic #define	ZEROWORD(w) \
12755577Sbostic 	(w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0
12855577Sbostic #define	COPYWORD(w1, w2) \
12955577Sbostic 	{ (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \
13055577Sbostic 	  (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \
13155577Sbostic 	}
13255577Sbostic #define	GETWORD(w, i) \
13355577Sbostic 	(i) = (((u_int)(w).val[_WORD_HIGHPART]) << 16) | (w).val[_WORD_LOWPART]
13455577Sbostic #define	PUTWORD(i, w) \
13555577Sbostic 	{ (w).val[_WORD_HIGHPART] = (u_short) (((i) >> 16) & 0xffff); \
13655577Sbostic 	  (w).val[_WORD_LOWPART] = (u_short) (i & 0xffff); \
13755577Sbostic 	}
13855577Sbostic 
13955577Sbostic #endif
14055577Sbostic 
14155577Sbostic /*
14255577Sbostic  * Packet structures.
14355577Sbostic  */
14455577Sbostic 
14555577Sbostic struct rmp_raw {		/* generic RMP packet */
14655577Sbostic 	u_char	rmp_type;		/* packet type */
14755577Sbostic 	u_char	rmp_rawdata[RMPDATALEN-1];
14855577Sbostic };
14955577Sbostic 
15055577Sbostic struct rmp_boot_req {		/* boot request */
15155577Sbostic 	u_char	rmp_type;		/* packet type (RMP_BOOT_REQ) */
15255577Sbostic 	u_char	rmp_retcode;		/* return code (0) */
15355577Sbostic 	u_word	rmp_seqno;		/* sequence number (real time clock) */
15455577Sbostic 	u_short	rmp_session;		/* session id (normally 0) */
15555577Sbostic 	u_short	rmp_version;		/* protocol version (RMP_VERSION) */
15655577Sbostic 	char	rmp_machtype[RMP_MACHLEN];	/* machine type */
15755577Sbostic 	u_char	rmp_flnmsize;		/* length of rmp_flnm */
15855577Sbostic 	restofpkt rmp_flnm;		/* name of file to be read */
15955577Sbostic };
16055577Sbostic 
16155577Sbostic struct rmp_boot_repl {		/* boot reply */
16255577Sbostic 	u_char	rmp_type;		/* packet type (RMP_BOOT_REPL) */
16355577Sbostic 	u_char	rmp_retcode;		/* return code (normally 0) */
16455577Sbostic 	u_word	rmp_seqno;		/* sequence number (from boot req) */
16555577Sbostic 	u_short	rmp_session;		/* session id (generated) */
16655577Sbostic 	u_short	rmp_version;		/* protocol version (RMP_VERSION) */
16755577Sbostic 	u_char	rmp_flnmsize;		/* length of rmp_flnm */
16855577Sbostic 	restofpkt rmp_flnm;		/* name of file (from boot req) */
16955577Sbostic };
17055577Sbostic 
17155577Sbostic struct rmp_read_req {		/* read request */
17255577Sbostic 	u_char	rmp_type;		/* packet type (RMP_READ_REQ) */
17355577Sbostic 	u_char	rmp_retcode;		/* return code (0) */
17455577Sbostic 	u_word	rmp_offset;		/* file relative byte offset */
17555577Sbostic 	u_short	rmp_session;		/* session id (from boot repl) */
17655577Sbostic 	u_short	rmp_size;		/* max no of bytes to send */
17755577Sbostic };
17855577Sbostic 
17955577Sbostic struct rmp_read_repl {		/* read reply */
18055577Sbostic 	u_char	rmp_type;		/* packet type (RMP_READ_REPL) */
18155577Sbostic 	u_char	rmp_retcode;		/* return code (normally 0) */
18255577Sbostic 	u_word	rmp_offset;		/* byte offset (from read req) */
18355577Sbostic 	u_short	rmp_session;		/* session id (from read req) */
18455577Sbostic 	restofpkt rmp_data;		/* data (max size from read req) */
18555577Sbostic 	u_char	rmp_unused;		/* padding to 16-bit boundary */
18655577Sbostic };
18755577Sbostic 
18855577Sbostic struct rmp_boot_done {		/* boot complete */
18955577Sbostic 	u_char	rmp_type;		/* packet type (RMP_BOOT_DONE) */
19055577Sbostic 	u_char	rmp_retcode;		/* return code (0) */
19155577Sbostic 	u_word	rmp_unused;		/* not used (0) */
19255577Sbostic 	u_short	rmp_session;		/* session id (from read repl) */
19355577Sbostic };
19455577Sbostic 
19555577Sbostic struct rmp_packet {
19655577Sbostic 	struct hp_hdr hp_hdr;
19755577Sbostic 	struct hp_llc hp_llc;
19855577Sbostic 	union {
19955577Sbostic 		struct rmp_boot_req	rmp_brq;	/* boot request */
20055577Sbostic 		struct rmp_boot_repl	rmp_brpl;	/* boot reply */
20155577Sbostic 		struct rmp_read_req	rmp_rrq;	/* read request */
20255577Sbostic 		struct rmp_read_repl	rmp_rrpl;	/* read reply */
20355577Sbostic 		struct rmp_boot_done	rmp_done;	/* boot complete */
20455577Sbostic 		struct rmp_raw		rmp_raw;	/* raw data */
20555577Sbostic 	} rmp_proto;
20655577Sbostic };
20755577Sbostic 
20855577Sbostic /*
20955577Sbostic  *  Make life easier...
21055577Sbostic  */
21155577Sbostic 
21255577Sbostic #define	r_type	rmp_proto.rmp_raw.rmp_type
21355577Sbostic #define	r_data	rmp_proto.rmp_raw.rmp_data
21455577Sbostic #define	r_brq	rmp_proto.rmp_brq
21555577Sbostic #define	r_brpl	rmp_proto.rmp_brpl
21655577Sbostic #define	r_rrq	rmp_proto.rmp_rrq
21755577Sbostic #define	r_rrpl	rmp_proto.rmp_rrpl
21855577Sbostic #define	r_done	rmp_proto.rmp_done
219