rc.c revision 1.5
1/*	$NetBSD: rc.c,v 1.5 2009/10/20 00:51:13 snj Exp $	*/
2
3/*
4 * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28#ifndef lint
29__RCSID("$NetBSD: rc.c,v 1.5 2009/10/20 00:51:13 snj Exp $");
30#endif
31
32#include "os.h"
33#include "get.h"
34#include "mopdef.h"
35#include "print.h"
36#include "rc.h"
37
38void
39mopDumpRC(fd, pkt, trans)
40	FILE	*fd;
41	u_char 	*pkt;
42	int	 trans;
43{
44	int	i,idx = 0;
45	int32_t	tmpl;
46	u_char	tmpc,code,control;
47	u_short	len,tmps,moplen;
48
49	len = mopGetLength(pkt, trans);
50
51	switch (trans) {
52	case TRANS_8023:
53		idx = 22;
54		moplen = len - 8;
55		break;
56	default:
57		idx = 16;
58		moplen = len;
59	}
60	code = mopGetChar(pkt,&idx);
61
62	switch (code) {
63	case MOP_K_CODE_RID:
64
65		tmpc = mopGetChar(pkt,&idx);
66		(void)fprintf(fd,"Reserved     :   %02x\n",tmpc);
67
68		tmps = mopGetShort(pkt,&idx);
69		(void)fprintf(fd,"Receipt Nbr  : %04x\n",tmps);
70
71		break;
72	case MOP_K_CODE_BOT:
73
74		if ((moplen == 5)) {
75			tmps = mopGetShort(pkt,&idx);
76			(void)fprintf(fd,"Verification : %04x\n",tmps);
77		} else {
78
79			tmpl = mopGetLong(pkt,&idx);
80			(void)fprintf(fd,"Verification : %08x\n",tmpl);
81
82			tmpc = mopGetChar(pkt,&idx);	/* Processor */
83			(void)fprintf(fd,"Processor    :   %02x ",tmpc);
84			mopPrintBPTY(fd, tmpc);  (void)fprintf(fd, "\n");
85
86			control = mopGetChar(pkt,&idx);	/* Control */
87			(void)fprintf(fd,"Control    :   %02x ",control);
88			if ((control & (1>>MOP_K_BOT_CNTL_SERVER))) {
89				(void)fprintf(fd,
90					      "Bootserver Requesting system ");
91			} else {
92				(void)fprintf(fd,
93					      "Bootserver System default ");
94			}
95			if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
96				(void)fprintf(fd,
97					      "Bootdevice Specified device");
98			} else {
99				(void)fprintf(fd,
100					      "Bootdevice System default");
101			}
102			(void)fprintf(fd,"\n");
103
104			if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
105				tmpc = mopGetChar(pkt,&idx);/* Device ID */
106				(void)fprintf(fd,
107					      "Device ID    :   %02x '",tmpc);
108				for (i = 0; i < ((int) tmpc); i++) {
109				  (void)fprintf(fd,"%c",
110						mopGetChar(pkt,&idx));
111				}
112				(void)fprintf(fd,"'\n");
113			}
114
115			tmpc = mopGetChar(pkt,&idx);      /* Software ID */
116			(void)fprintf(fd,"Software ID  :   %02x ",tmpc);
117			if ((tmpc == 0)) {
118				(void)fprintf(fd,"No software id");
119			}
120			if ((tmpc == 254)) {
121				(void)fprintf(fd,"Maintenance system");
122				tmpc = 0;
123			}
124			if ((tmpc == 255)) {
125				(void)fprintf(fd,"Standard operating system");
126				tmpc = 0;
127			}
128			if ((tmpc > 0)) {
129				(void)fprintf(fd,"'");
130				for (i = 0; i < ((int) tmpc); i++) {
131					(void)fprintf(fd,"%c",
132						     mopGetChar(pkt,&idx));
133				}
134				(void)fprintf(fd,"'");
135			}
136			(void)fprintf(fd,"'\n");
137
138		}
139		break;
140	case MOP_K_CODE_SID:
141
142		tmpc = mopGetChar(pkt,&idx);		/* Reserved */
143		(void)fprintf(fd, "Reserved     :   %02x\n",tmpc);
144
145		tmps = mopGetShort(pkt,&idx);		/* Receipt # */
146		(void)fprintf(fd, "Receipt Nbr  : %04x\n",tmpc);
147
148		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
149
150		break;
151	case MOP_K_CODE_RQC:
152
153		tmps = mopGetShort(pkt,&idx);
154		(void)fprintf(fd,"Receipt Nbr  : %04x\n",tmps);
155
156		break;
157	case MOP_K_CODE_CNT:
158
159		tmps = mopGetShort(pkt,&idx);
160		(void)fprintf(fd,"Receipt Nbr  : %04x %d\n",tmps,tmps);
161
162		tmps = mopGetShort(pkt,&idx);
163		(void)fprintf(fd,"Last Zeroed  : %04x %d\n",tmps,tmps);
164
165		tmpl = mopGetLong(pkt,&idx);
166		(void)fprintf(fd,"Bytes rec    : %08x %d\n",tmpl,tmpl);
167
168		tmpl = mopGetLong(pkt,&idx);
169		(void)fprintf(fd,"Bytes snd    : %08x %d\n",tmpl,tmpl);
170
171		tmpl = mopGetLong(pkt,&idx);
172		(void)fprintf(fd,"Frames rec   : %08x %d\n",tmpl,tmpl);
173
174		tmpl = mopGetLong(pkt,&idx);
175		(void)fprintf(fd,"Frames snd   : %08x %d\n",tmpl,tmpl);
176
177		tmpl = mopGetLong(pkt,&idx);
178		(void)fprintf(fd,"Mcst Bytes re: %08x %d\n",tmpl,tmpl);
179
180		tmpl = mopGetLong(pkt,&idx);
181		(void)fprintf(fd,"Mcst Frame re: %08x %d\n",tmpl,tmpl);
182
183		tmpl = mopGetLong(pkt,&idx);
184		(void)fprintf(fd,"Frame snd,def: %08x %d\n",tmpl,tmpl);
185
186		tmpl = mopGetLong(pkt,&idx);
187		(void)fprintf(fd,"Frame snd,col: %08x %d\n",tmpl,tmpl);
188
189		tmpl = mopGetLong(pkt,&idx);
190		(void)fprintf(fd,"Frame snd,mcl: %08x %d\n",tmpl,tmpl);
191
192		tmps = mopGetShort(pkt,&idx);
193		(void)fprintf(fd,"Snd failure  : %04x %d\n",tmps,tmps);
194
195		tmps = mopGetShort(pkt,&idx);
196		(void)fprintf(fd,"Snd fail reas: %04x ",tmps);
197		if ((tmps &  1)) (void)fprintf(fd,"Excess col  ");
198		if ((tmps &  2)) (void)fprintf(fd,"Carrier chk fail  ");
199		if ((tmps &  4)) (void)fprintf(fd,"Short circ  ");
200		if ((tmps &  8)) (void)fprintf(fd,"Open circ  ");
201		if ((tmps & 16)) (void)fprintf(fd,"Frm to long  ");
202		if ((tmps & 32)) (void)fprintf(fd,"Rem fail to defer  ");
203		(void)fprintf(fd,"\n");
204
205		tmps = mopGetShort(pkt,&idx);
206		(void)fprintf(fd,"Rec failure  : %04x %d\n",tmps,tmps);
207
208		tmps = mopGetShort(pkt,&idx);
209		(void)fprintf(fd,"Rec fail reas: %04x ",tmps);
210		if ((tmps &  1)) (void)fprintf(fd,"Block chk err  ");
211		if ((tmps &  2)) (void)fprintf(fd,"Framing err  ");
212		if ((tmps &  4)) (void)fprintf(fd,"Frm to long  ");
213		(void)fprintf(fd,"\n");
214
215		tmps = mopGetShort(pkt,&idx);
216		(void)fprintf(fd,"Unrec frm dst: %04x %d\n",tmps,tmps);
217
218		tmps = mopGetShort(pkt,&idx);
219		(void)fprintf(fd,"Data overrun : %04x %d\n",tmps,tmps);
220
221		tmps = mopGetShort(pkt,&idx);
222		(void)fprintf(fd,"Sys Buf Unava: %04x %d\n",tmps,tmps);
223
224		tmps = mopGetShort(pkt,&idx);
225		(void)fprintf(fd,"Usr Buf Unava: %04x %d\n",tmps,tmps);
226
227		break;
228	case MOP_K_CODE_RVC:
229
230		tmpl = mopGetLong(pkt,&idx);
231		(void)fprintf(fd,"Verification : %08x\n",tmpl);
232
233		break;
234	case MOP_K_CODE_RLC:
235
236		/* Empty message */
237
238		break;
239	case MOP_K_CODE_CCP:
240
241		tmpc = mopGetChar(pkt,&idx);
242		(void)fprintf(fd,
243			      "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
244		if ((tmpc & 2))
245			(void)fprintf(fd,"Break");
246		(void)fprintf(fd,"\n");
247
248		if (moplen > 2) {
249#ifndef SHORT_PRINT
250			for (i = 0; i < (moplen - 2); i++) {
251		  		if ((i % 16) == 0) {
252					if ((i / 16) == 0) {
253						(void)fprintf(fd,
254							"Image Data   : %04x ",
255							      moplen-2);
256					} else {
257						(void)fprintf(fd,
258						       "                    ");
259				        }
260				}
261				(void)fprintf(fd,"%02x ",
262					      mopGetChar(pkt,&idx));
263				if ((i % 16) == 15)
264					(void)fprintf(fd,"\n");
265			}
266			if ((i % 16) != 15)
267				(void)fprintf(fd,"\n");
268#else
269			idx = idx + moplen - 2;
270#endif
271		}
272
273		break;
274	case MOP_K_CODE_CRA:
275
276		tmpc = mopGetChar(pkt,&idx);
277		(void)fprintf(fd,
278			      "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
279		if ((tmpc & 2))
280			(void)fprintf(fd,"Cmd Data Lost ");
281		if ((tmpc & 4))
282			(void)fprintf(fd,"Resp Data Lost ");
283		(void)fprintf(fd,"\n");
284
285		if (moplen > 2) {
286#ifndef SHORT_PRINT
287			for (i = 0; i < (moplen - 2); i++) {
288				if ((i % 16) == 0) {
289					if ((i / 16) == 0) {
290						(void)fprintf(fd,
291							"Image Data   : %04x ",
292							      moplen-2);
293					} else {
294						(void)fprintf(fd,
295						       "                    ");
296					}
297				}
298				(void)fprintf(fd,"%02x ",
299					      mopGetChar(pkt,&idx));
300				if ((i % 16) == 15)
301					(void)fprintf(fd,"\n");
302			}
303			if ((i % 16) != 15)
304				(void)fprintf(fd,"\n");
305#else
306			idx = idx + moplen - 2;
307#endif
308		}
309
310		break;
311	default:
312		break;
313	}
314}
315
316