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