1 /* 2 * Copyright (c) 1988, 1992 The University of Utah and the Center 3 * for Software Science (CSS). 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 * %sccs.include.redist.c% 14 * 15 * @(#)rmp_var.h 8.1 (Berkeley) 06/04/93 16 * 17 * Utah $Hdr: rmp_var.h 3.1 92/07/06$ 18 * Author: Jeff Forys, University of Utah CSS 19 */ 20 21 /* 22 * Possible values for "rmp_type" fields. 23 */ 24 25 #define RMP_BOOT_REQ 1 /* boot request packet */ 26 #define RMP_BOOT_REPL 129 /* boot reply packet */ 27 #define RMP_READ_REQ 2 /* read request packet */ 28 #define RMP_READ_REPL 130 /* read reply packet */ 29 #define RMP_BOOT_DONE 3 /* boot complete packet */ 30 31 /* 32 * Useful constants. 33 */ 34 35 #define RMP_VERSION 2 /* protocol version */ 36 #define RMP_TIMEOUT 600 /* timeout connection after ten minutes */ 37 #define RMP_PROBESID 0xffff /* session ID for probes */ 38 #define RMP_HOSTLEN 13 /* max length of server's name */ 39 #define RMP_MACHLEN 20 /* length of machine type field */ 40 41 /* 42 * RMP error codes 43 */ 44 45 #define RMP_E_OKAY 0 46 #define RMP_E_EOF 2 /* read reply: returned end of file */ 47 #define RMP_E_ABORT 3 /* abort operation */ 48 #define RMP_E_BUSY 4 /* boot reply: server busy */ 49 #define RMP_E_TIMEOUT 5 /* lengthen time out (not implemented) */ 50 #define RMP_E_NOFILE 16 /* boot reply: file does not exist */ 51 #define RMP_E_OPENFILE 17 /* boot reply: file open failed */ 52 #define RMP_E_NODFLT 18 /* boot reply: default file does not exist */ 53 #define RMP_E_OPENDFLT 19 /* boot reply: default file open failed */ 54 #define RMP_E_BADSID 25 /* read reply: bad session ID */ 55 #define RMP_E_BADPACKET 27 /* Bad packet detected */ 56 57 /* 58 * RMPDATALEN is the maximum number of data octets that can be stuffed 59 * into an RMP packet. This excludes the 802.2 LLC w/HP extensions. 60 */ 61 #define RMPDATALEN (RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \ 62 sizeof(struct hp_llc))) 63 64 /* 65 * Define sizes of packets we send. Boot and Read replies are variable 66 * in length depending on the length of `s'. 67 * 68 * Also, define how much space `restofpkt' can take up for outgoing 69 * Boot and Read replies. Boot Request packets are effectively 70 * limited to 255 bytes due to the preceding 1-byte length field. 71 */ 72 73 #define RMPBOOTSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 74 sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt)) 75 #define RMPREADSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 76 sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \ 77 - sizeof(u_char)) 78 #define RMPDONESIZE (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 79 sizeof(struct rmp_boot_done)) 80 #define RMPBOOTDATA 255 81 #define RMPREADDATA (RMPDATALEN - \ 82 (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_word))) 83 84 /* 85 * This protocol defines some field sizes as "rest of ethernet packet". 86 * There is no easy way to specify this in C, so we use a one character 87 * field to denote it, and index past it to the end of the packet. 88 */ 89 90 typedef char restofpkt; 91 92 /* 93 * Due to the RMP packet layout, we'll run into alignment problems 94 * on machines that cant access words on half-word boundaries. If 95 * you know that your machine does not suffer from this problem, 96 * add it to the hp300 #define below. 97 * 98 * The following macros are used to deal with this problem: 99 * WORDZE(w) Return True if u_word `w' is zero, False otherwise. 100 * ZEROWORD(w) Set u_word `w' to zero. 101 * COPYWORD(w1,w2) Copy u_word `w1' to `w2'. 102 * GETWORD(w,i) Copy u_word `w' into int `i'. 103 * PUTWORD(i,w) Copy int `i' into u_word `w'. 104 * 105 * N.B. We do not support little endian alignment-challenged machines. 106 */ 107 #if defined(vax) || defined(tahoe) || defined(hp300) 108 109 typedef u_int u_word; 110 111 #define WORDZE(w) ((w) == 0) 112 #define ZEROWORD(w) (w) = 0 113 #define COPYWORD(w1,w2) (w2) = (w1) 114 #define GETWORD(w, i) (i) = (w) 115 #define PUTWORD(i, w) (w) = (i) 116 117 #else 118 119 #define _WORD_HIGHPART 0 /* XXX: assume Big Endian for now */ 120 #define _WORD_LOWPART 1 121 122 typedef struct _uword { u_short val[2]; } u_word; 123 124 #define WORDZE(w) \ 125 ((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0)) 126 #define ZEROWORD(w) \ 127 (w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0 128 #define COPYWORD(w1, w2) \ 129 { (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \ 130 (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \ 131 } 132 #define GETWORD(w, i) \ 133 (i) = (((u_int)(w).val[_WORD_HIGHPART]) << 16) | (w).val[_WORD_LOWPART] 134 #define PUTWORD(i, w) \ 135 { (w).val[_WORD_HIGHPART] = (u_short) (((i) >> 16) & 0xffff); \ 136 (w).val[_WORD_LOWPART] = (u_short) (i & 0xffff); \ 137 } 138 139 #endif 140 141 /* 142 * Packet structures. 143 */ 144 145 struct rmp_raw { /* generic RMP packet */ 146 u_char rmp_type; /* packet type */ 147 u_char rmp_rawdata[RMPDATALEN-1]; 148 }; 149 150 struct rmp_boot_req { /* boot request */ 151 u_char rmp_type; /* packet type (RMP_BOOT_REQ) */ 152 u_char rmp_retcode; /* return code (0) */ 153 u_word rmp_seqno; /* sequence number (real time clock) */ 154 u_short rmp_session; /* session id (normally 0) */ 155 u_short rmp_version; /* protocol version (RMP_VERSION) */ 156 char rmp_machtype[RMP_MACHLEN]; /* machine type */ 157 u_char rmp_flnmsize; /* length of rmp_flnm */ 158 restofpkt rmp_flnm; /* name of file to be read */ 159 }; 160 161 struct rmp_boot_repl { /* boot reply */ 162 u_char rmp_type; /* packet type (RMP_BOOT_REPL) */ 163 u_char rmp_retcode; /* return code (normally 0) */ 164 u_word rmp_seqno; /* sequence number (from boot req) */ 165 u_short rmp_session; /* session id (generated) */ 166 u_short rmp_version; /* protocol version (RMP_VERSION) */ 167 u_char rmp_flnmsize; /* length of rmp_flnm */ 168 restofpkt rmp_flnm; /* name of file (from boot req) */ 169 }; 170 171 struct rmp_read_req { /* read request */ 172 u_char rmp_type; /* packet type (RMP_READ_REQ) */ 173 u_char rmp_retcode; /* return code (0) */ 174 u_word rmp_offset; /* file relative byte offset */ 175 u_short rmp_session; /* session id (from boot repl) */ 176 u_short rmp_size; /* max no of bytes to send */ 177 }; 178 179 struct rmp_read_repl { /* read reply */ 180 u_char rmp_type; /* packet type (RMP_READ_REPL) */ 181 u_char rmp_retcode; /* return code (normally 0) */ 182 u_word rmp_offset; /* byte offset (from read req) */ 183 u_short rmp_session; /* session id (from read req) */ 184 restofpkt rmp_data; /* data (max size from read req) */ 185 u_char rmp_unused; /* padding to 16-bit boundary */ 186 }; 187 188 struct rmp_boot_done { /* boot complete */ 189 u_char rmp_type; /* packet type (RMP_BOOT_DONE) */ 190 u_char rmp_retcode; /* return code (0) */ 191 u_word rmp_unused; /* not used (0) */ 192 u_short rmp_session; /* session id (from read repl) */ 193 }; 194 195 struct rmp_packet { 196 struct hp_hdr hp_hdr; 197 struct hp_llc hp_llc; 198 union { 199 struct rmp_boot_req rmp_brq; /* boot request */ 200 struct rmp_boot_repl rmp_brpl; /* boot reply */ 201 struct rmp_read_req rmp_rrq; /* read request */ 202 struct rmp_read_repl rmp_rrpl; /* read reply */ 203 struct rmp_boot_done rmp_done; /* boot complete */ 204 struct rmp_raw rmp_raw; /* raw data */ 205 } rmp_proto; 206 }; 207 208 /* 209 * Make life easier... 210 */ 211 212 #define r_type rmp_proto.rmp_raw.rmp_type 213 #define r_data rmp_proto.rmp_raw.rmp_data 214 #define r_brq rmp_proto.rmp_brq 215 #define r_brpl rmp_proto.rmp_brpl 216 #define r_rrq rmp_proto.rmp_rrq 217 #define r_rrpl rmp_proto.rmp_rrpl 218 #define r_done rmp_proto.rmp_done 219