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. 211592Srgrimes * 3. All advertising materials mentioning features or use of this software 221592Srgrimes * must display the following acknowledgement: 231592Srgrimes * This product includes software developed by the University of 241592Srgrimes * California, Berkeley and its contributors. 251592Srgrimes * 4. Neither the name of the University nor the names of its contributors 261592Srgrimes * may be used to endorse or promote products derived from this software 271592Srgrimes * without specific prior written permission. 281592Srgrimes * 291592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 381592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 391592Srgrimes * SUCH DAMAGE. 401592Srgrimes * 4127074Ssteve * from: @(#)rmp_var.h 8.1 (Berkeley) 6/4/93 421592Srgrimes * 4327074Ssteve * from: Utah Hdr: rmp_var.h 3.1 92/07/06 441592Srgrimes * Author: Jeff Forys, University of Utah CSS 451592Srgrimes */ 461592Srgrimes 471592Srgrimes/* 481592Srgrimes * Possible values for "rmp_type" fields. 491592Srgrimes */ 501592Srgrimes 511592Srgrimes#define RMP_BOOT_REQ 1 /* boot request packet */ 521592Srgrimes#define RMP_BOOT_REPL 129 /* boot reply packet */ 531592Srgrimes#define RMP_READ_REQ 2 /* read request packet */ 541592Srgrimes#define RMP_READ_REPL 130 /* read reply packet */ 551592Srgrimes#define RMP_BOOT_DONE 3 /* boot complete packet */ 561592Srgrimes 571592Srgrimes/* 581592Srgrimes * Useful constants. 591592Srgrimes */ 601592Srgrimes 611592Srgrimes#define RMP_VERSION 2 /* protocol version */ 621592Srgrimes#define RMP_TIMEOUT 600 /* timeout connection after ten minutes */ 631592Srgrimes#define RMP_PROBESID 0xffff /* session ID for probes */ 641592Srgrimes#define RMP_HOSTLEN 13 /* max length of server's name */ 651592Srgrimes#define RMP_MACHLEN 20 /* length of machine type field */ 661592Srgrimes 671592Srgrimes/* 681592Srgrimes * RMP error codes 691592Srgrimes */ 701592Srgrimes 711592Srgrimes#define RMP_E_OKAY 0 721592Srgrimes#define RMP_E_EOF 2 /* read reply: returned end of file */ 731592Srgrimes#define RMP_E_ABORT 3 /* abort operation */ 741592Srgrimes#define RMP_E_BUSY 4 /* boot reply: server busy */ 751592Srgrimes#define RMP_E_TIMEOUT 5 /* lengthen time out (not implemented) */ 761592Srgrimes#define RMP_E_NOFILE 16 /* boot reply: file does not exist */ 771592Srgrimes#define RMP_E_OPENFILE 17 /* boot reply: file open failed */ 781592Srgrimes#define RMP_E_NODFLT 18 /* boot reply: default file does not exist */ 791592Srgrimes#define RMP_E_OPENDFLT 19 /* boot reply: default file open failed */ 801592Srgrimes#define RMP_E_BADSID 25 /* read reply: bad session ID */ 811592Srgrimes#define RMP_E_BADPACKET 27 /* Bad packet detected */ 821592Srgrimes 831592Srgrimes/* 841592Srgrimes * RMPDATALEN is the maximum number of data octets that can be stuffed 851592Srgrimes * into an RMP packet. This excludes the 802.2 LLC w/HP extensions. 861592Srgrimes */ 871592Srgrimes#define RMPDATALEN (RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \ 881592Srgrimes sizeof(struct hp_llc))) 891592Srgrimes 901592Srgrimes/* 911592Srgrimes * Define sizes of packets we send. Boot and Read replies are variable 921592Srgrimes * in length depending on the length of `s'. 931592Srgrimes * 941592Srgrimes * Also, define how much space `restofpkt' can take up for outgoing 951592Srgrimes * Boot and Read replies. Boot Request packets are effectively 961592Srgrimes * limited to 255 bytes due to the preceding 1-byte length field. 971592Srgrimes */ 981592Srgrimes 991592Srgrimes#define RMPBOOTSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 1001592Srgrimes sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt)) 1011592Srgrimes#define RMPREADSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 1021592Srgrimes sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \ 10327074Ssteve - sizeof(u_int8_t)) 1041592Srgrimes#define RMPDONESIZE (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ 1051592Srgrimes sizeof(struct rmp_boot_done)) 1061592Srgrimes#define RMPBOOTDATA 255 1071592Srgrimes#define RMPREADDATA (RMPDATALEN - \ 10827074Ssteve (2*sizeof(u_int8_t)+sizeof(u_int16_t)+sizeof(u_word))) 1091592Srgrimes 1101592Srgrimes/* 1111592Srgrimes * This protocol defines some field sizes as "rest of ethernet packet". 1121592Srgrimes * There is no easy way to specify this in C, so we use a one character 1131592Srgrimes * field to denote it, and index past it to the end of the packet. 1141592Srgrimes */ 1151592Srgrimes 1161592Srgrimestypedef char restofpkt; 1171592Srgrimes 1181592Srgrimes/* 1191592Srgrimes * Due to the RMP packet layout, we'll run into alignment problems 12027074Ssteve * on machines that can't access (or don't, by default, align) words 12127074Ssteve * on half-word boundaries. If you know that your machine does not suffer 12227074Ssteve * from this problem, add it to the vax/tahoe/m68k #define below. 1231592Srgrimes * 1241592Srgrimes * The following macros are used to deal with this problem: 1251592Srgrimes * WORDZE(w) Return True if u_word `w' is zero, False otherwise. 1261592Srgrimes * ZEROWORD(w) Set u_word `w' to zero. 1271592Srgrimes * COPYWORD(w1,w2) Copy u_word `w1' to `w2'. 1281592Srgrimes * GETWORD(w,i) Copy u_word `w' into int `i'. 1291592Srgrimes * PUTWORD(i,w) Copy int `i' into u_word `w'. 13027079Ssteve * 13127074Ssteve * N.B. Endianness is handled by use of ntohl/htonl 1321592Srgrimes */ 13327074Ssteve#if defined(__vax__) || defined(__tahoe__) || defined(__m68k__) 1341592Srgrimes 13527074Sstevetypedef u_int32_t u_word; 1361592Srgrimes 1371592Srgrimes#define WORDZE(w) ((w) == 0) 1381592Srgrimes#define ZEROWORD(w) (w) = 0 1391592Srgrimes#define COPYWORD(w1,w2) (w2) = (w1) 14027074Ssteve#define GETWORD(w, i) (i) = ntohl(w) 14127074Ssteve#define PUTWORD(i, w) (w) = htonl(i) 1421592Srgrimes 1431592Srgrimes#else 1441592Srgrimes 14527074Ssteve#define _WORD_HIGHPART 0 1461592Srgrimes#define _WORD_LOWPART 1 1471592Srgrimes 14827074Sstevetypedef struct _uword { u_int16_t val[2]; } u_word; 1491592Srgrimes 1501592Srgrimes#define WORDZE(w) \ 1511592Srgrimes ((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0)) 1521592Srgrimes#define ZEROWORD(w) \ 1531592Srgrimes (w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0 1541592Srgrimes#define COPYWORD(w1, w2) \ 1551592Srgrimes { (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \ 1561592Srgrimes (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \ 1571592Srgrimes } 1581592Srgrimes#define GETWORD(w, i) \ 15927074Ssteve (i) = (((u_int32_t)ntohs((w).val[_WORD_HIGHPART])) << 16) | ntohs((w).val[_WORD_LOWPART]) 1601592Srgrimes#define PUTWORD(i, w) \ 16127074Ssteve { (w).val[_WORD_HIGHPART] = htons((u_int16_t) ((i >> 16) & 0xffff)); \ 16227074Ssteve (w).val[_WORD_LOWPART] = htons((u_int16_t) (i & 0xffff)); \ 1631592Srgrimes } 1641592Srgrimes 1651592Srgrimes#endif 1661592Srgrimes 1671592Srgrimes/* 1681592Srgrimes * Packet structures. 1691592Srgrimes */ 1701592Srgrimes 1711592Srgrimesstruct rmp_raw { /* generic RMP packet */ 17227074Ssteve u_int8_t rmp_type; /* packet type */ 17327074Ssteve u_int8_t rmp_rawdata[RMPDATALEN-1]; 1741592Srgrimes}; 1751592Srgrimes 1761592Srgrimesstruct rmp_boot_req { /* boot request */ 17727074Ssteve u_int8_t rmp_type; /* packet type (RMP_BOOT_REQ) */ 17827074Ssteve u_int8_t rmp_retcode; /* return code (0) */ 17927074Ssteve u_word rmp_seqno; /* sequence number (real time clock) */ 18027074Ssteve u_int16_t rmp_session; /* session id (normally 0) */ 18127074Ssteve u_int16_t rmp_version; /* protocol version (RMP_VERSION) */ 18227074Ssteve char rmp_machtype[RMP_MACHLEN]; /* machine type */ 18327074Ssteve u_int8_t rmp_flnmsize; /* length of rmp_flnm */ 1841592Srgrimes restofpkt rmp_flnm; /* name of file to be read */ 1851592Srgrimes}; 1861592Srgrimes 1871592Srgrimesstruct rmp_boot_repl { /* boot reply */ 18827074Ssteve u_int8_t rmp_type; /* packet type (RMP_BOOT_REPL) */ 18927074Ssteve u_int8_t rmp_retcode; /* return code (normally 0) */ 19027074Ssteve u_word rmp_seqno; /* sequence number (from boot req) */ 19127074Ssteve u_int16_t rmp_session; /* session id (generated) */ 19227074Ssteve u_int16_t rmp_version; /* protocol version (RMP_VERSION) */ 19327074Ssteve u_int8_t rmp_flnmsize; /* length of rmp_flnm */ 1941592Srgrimes restofpkt rmp_flnm; /* name of file (from boot req) */ 1951592Srgrimes}; 1961592Srgrimes 1971592Srgrimesstruct rmp_read_req { /* read request */ 19827074Ssteve u_int8_t rmp_type; /* packet type (RMP_READ_REQ) */ 19927074Ssteve u_int8_t rmp_retcode; /* return code (0) */ 20027074Ssteve u_word rmp_offset; /* file relative byte offset */ 20127074Ssteve u_int16_t rmp_session; /* session id (from boot repl) */ 20227074Ssteve u_int16_t rmp_size; /* max no of bytes to send */ 2031592Srgrimes}; 2041592Srgrimes 2051592Srgrimesstruct rmp_read_repl { /* read reply */ 20627074Ssteve u_int8_t rmp_type; /* packet type (RMP_READ_REPL) */ 20727074Ssteve u_int8_t rmp_retcode; /* return code (normally 0) */ 20827074Ssteve u_word rmp_offset; /* byte offset (from read req) */ 20927074Ssteve u_int16_t rmp_session; /* session id (from read req) */ 2101592Srgrimes restofpkt rmp_data; /* data (max size from read req) */ 21127074Ssteve u_int8_t rmp_unused; /* padding to 16-bit boundary */ 2121592Srgrimes}; 2131592Srgrimes 2141592Srgrimesstruct rmp_boot_done { /* boot complete */ 21527074Ssteve u_int8_t rmp_type; /* packet type (RMP_BOOT_DONE) */ 21627074Ssteve u_int8_t rmp_retcode; /* return code (0) */ 21727074Ssteve u_word rmp_unused; /* not used (0) */ 21827074Ssteve u_int16_t rmp_session; /* session id (from read repl) */ 2191592Srgrimes}; 2201592Srgrimes 2211592Srgrimesstruct rmp_packet { 2221592Srgrimes struct hp_hdr hp_hdr; 2231592Srgrimes struct hp_llc hp_llc; 2241592Srgrimes union { 2251592Srgrimes struct rmp_boot_req rmp_brq; /* boot request */ 2261592Srgrimes struct rmp_boot_repl rmp_brpl; /* boot reply */ 2271592Srgrimes struct rmp_read_req rmp_rrq; /* read request */ 2281592Srgrimes struct rmp_read_repl rmp_rrpl; /* read reply */ 2291592Srgrimes struct rmp_boot_done rmp_done; /* boot complete */ 2301592Srgrimes struct rmp_raw rmp_raw; /* raw data */ 2311592Srgrimes } rmp_proto; 2321592Srgrimes}; 2331592Srgrimes 2341592Srgrimes/* 2351592Srgrimes * Make life easier... 2361592Srgrimes */ 2371592Srgrimes 2381592Srgrimes#define r_type rmp_proto.rmp_raw.rmp_type 23927074Ssteve#define r_data rmp_proto.rmp_raw.rmp_rawdata 2401592Srgrimes#define r_brq rmp_proto.rmp_brq 2411592Srgrimes#define r_brpl rmp_proto.rmp_brpl 2421592Srgrimes#define r_rrq rmp_proto.rmp_rrq 2431592Srgrimes#define r_rrpl rmp_proto.rmp_rrpl 2441592Srgrimes#define r_done rmp_proto.rmp_done 245