xref: /openbsd-src/usr.sbin/mopd/common/rc.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: rc.c,v 1.7 2006/11/10 23:02:08 maja 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 #ifndef lint
28 static const char rcsid[] =
29     "$OpenBSD: rc.c,v 1.7 2006/11/10 23:02:08 maja Exp $";
30 #endif
31 
32 #include "os.h"
33 #include "common/get.h"
34 #include "common/print.h"
35 #include "common/mopdef.h"
36 
37 void
38 mopDumpRC(FILE *fd, u_char *pkt, int trans)
39 {
40 	int	i, idx = 0;
41 	long	tmpl;
42 	u_char	tmpc, code, control;
43 	u_short	len, tmps, moplen;
44 
45 	len = mopGetLength(pkt, trans);
46 
47 	switch (trans) {
48 	case TRANS_8023:
49 		idx = 22;
50 		moplen = len - 8;
51 		break;
52 	default:
53 		idx = 16;
54 		moplen = len;
55 	}
56 	code = mopGetChar(pkt, &idx);
57 
58 	switch (code) {
59 	case MOP_K_CODE_RID:
60 
61 		tmpc = mopGetChar(pkt, &idx);
62 		fprintf(fd, "Reserved     :   %02x\n", tmpc);
63 
64 		tmps = mopGetShort(pkt, &idx);
65 		fprintf(fd, "Receipt Nbr  : %04x\n", tmps);
66 
67 		break;
68 	case MOP_K_CODE_BOT:
69 
70 		if ((moplen == 5)) {
71 			tmps = mopGetShort(pkt, &idx);
72 			fprintf(fd, "Verification : %04x\n", tmps);
73 		} else {
74 
75 			tmpl = mopGetLong(pkt, &idx);
76 			fprintf(fd, "Verification : %08lx\n", tmpl);
77 
78 			tmpc = mopGetChar(pkt, &idx);	/* Processor */
79 			fprintf(fd, "Processor    :   %02x ", tmpc);
80 			mopPrintBPTY(fd, tmpc);  fprintf(fd, "\n");
81 
82 			control = mopGetChar(pkt, &idx);	/* Control */
83 			fprintf(fd, "Control    :   %02x ", control);
84 			if ((control & (1<<MOP_K_BOT_CNTL_SERVER)))
85 				fprintf(fd, "Bootserver Requesting system ");
86 			else
87 				fprintf(fd, "Bootserver System default ");
88 			if ((control & (1<<MOP_K_BOT_CNTL_DEVICE)))
89 				fprintf(fd, "Bootdevice Specified device");
90 			else
91 				fprintf(fd, "Bootdevice System default");
92 			fprintf(fd, "\n");
93 
94 			if ((control & (1<<MOP_K_BOT_CNTL_DEVICE))) {
95 				tmpc = mopGetChar(pkt, &idx);/* Device ID */
96 				fprintf(fd, "Device ID    :   %02x '", tmpc);
97 				for (i = 0; i < ((int) tmpc); i++)
98 					fprintf(fd, "%c",
99 					    mopGetChar(pkt, &idx));
100 				fprintf(fd, "'\n");
101 			}
102 
103 			tmpc = mopGetChar(pkt, &idx);      /* Software ID */
104 			fprintf(fd, "Software ID  :   %02x ", tmpc);
105 			if ((tmpc == 0))
106 				fprintf(fd, "No software id");
107 			if ((tmpc == 254)) {
108 				fprintf(fd, "Maintenance system");
109 				tmpc = 0;
110 			}
111 			if ((tmpc == 255)) {
112 				fprintf(fd, "Standard operating system");
113 				tmpc = 0;
114 			}
115 			if ((tmpc > 0)) {
116 				fprintf(fd, "'");
117 				for (i = 0; i < ((int) tmpc); i++)
118 					fprintf(fd, "%c",
119 					    mopGetChar(pkt, &idx));
120 				fprintf(fd, "'");
121 			}
122 			fprintf(fd, "'\n");
123 
124 		}
125 		break;
126 	case MOP_K_CODE_SID:
127 
128 		tmpc = mopGetChar(pkt, &idx);		/* Reserved */
129 		fprintf(fd, "Reserved     :   %02x\n", tmpc);
130 
131 		tmps = mopGetShort(pkt, &idx);		/* Receipt # */
132 		fprintf(fd, "Receipt Nbr  : %04x\n", tmpc);
133 
134 		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
135 
136 		break;
137 	case MOP_K_CODE_RQC:
138 
139 		tmps = mopGetShort(pkt, &idx);
140 		fprintf(fd, "Receipt Nbr  : %04x\n", tmps);
141 
142 		break;
143 	case MOP_K_CODE_CNT:
144 
145 		tmps = mopGetShort(pkt, &idx);
146 		fprintf(fd, "Receipt Nbr  : %04x %d\n", tmps, tmps);
147 
148 		tmps = mopGetShort(pkt, &idx);
149 		fprintf(fd, "Last Zeroed  : %04x %d\n", tmps, tmps);
150 
151 		tmpl = mopGetLong(pkt, &idx);
152 		fprintf(fd, "Bytes rec    : %08lx %ld\n", tmpl, tmpl);
153 
154 		tmpl = mopGetLong(pkt, &idx);
155 		fprintf(fd, "Bytes snd    : %08lx %ld\n", tmpl, tmpl);
156 
157 		tmpl = mopGetLong(pkt, &idx);
158 		fprintf(fd, "Frames rec   : %08lx %ld\n", tmpl, tmpl);
159 
160 		tmpl = mopGetLong(pkt, &idx);
161 		fprintf(fd, "Frames snd   : %08lx %ld\n", tmpl, tmpl);
162 
163 		tmpl = mopGetLong(pkt, &idx);
164 		fprintf(fd, "Mcst Bytes re: %08lx %ld\n", tmpl, tmpl);
165 
166 		tmpl = mopGetLong(pkt, &idx);
167 		fprintf(fd, "Mcst Frame re: %08lx %ld\n", tmpl, tmpl);
168 
169 		tmpl = mopGetLong(pkt, &idx);
170 		fprintf(fd, "Frame snd, def: %08lx %ld\n", tmpl, tmpl);
171 
172 		tmpl = mopGetLong(pkt, &idx);
173 		fprintf(fd, "Frame snd, col: %08lx %ld\n", tmpl, tmpl);
174 
175 		tmpl = mopGetLong(pkt, &idx);
176 		fprintf(fd, "Frame snd, mcl: %08lx %ld\n", tmpl, tmpl);
177 
178 		tmps = mopGetShort(pkt, &idx);
179 		fprintf(fd, "Snd failure  : %04x %d\n", tmps, tmps);
180 
181 		tmps = mopGetShort(pkt, &idx);
182 		fprintf(fd, "Snd fail reas: %04x ", tmps);
183 		if (tmps & 1)
184 			fprintf(fd, "Excess col  ");
185 		if (tmps & 2)
186 			fprintf(fd, "Carrier chk fail  ");
187 		if (tmps & 4)
188 			fprintf(fd, "Short circ  ");
189 		if (tmps & 8)
190 			fprintf(fd, "Open circ  ");
191 		if (tmps & 16)
192 			fprintf(fd, "Frm to long  ");
193 		if (tmps & 32)
194 			fprintf(fd, "Rem fail to defer  ");
195 		fprintf(fd, "\n");
196 
197 		tmps = mopGetShort(pkt, &idx);
198 		fprintf(fd, "Rec failure  : %04x %d\n", tmps, tmps);
199 
200 		tmps = mopGetShort(pkt, &idx);
201 		fprintf(fd, "Rec fail reas: %04x ", tmps);
202 		if (tmps & 1)
203 			fprintf(fd, "Block chk err  ");
204 		if (tmps & 2)
205 			fprintf(fd, "Framing err  ");
206 		if (tmps & 4)
207 			fprintf(fd, "Frm to long  ");
208 		fprintf(fd, "\n");
209 
210 		tmps = mopGetShort(pkt, &idx);
211 		fprintf(fd, "Unrec frm dst: %04x %d\n", tmps, tmps);
212 
213 		tmps = mopGetShort(pkt, &idx);
214 		fprintf(fd, "Data overrun : %04x %d\n", tmps, tmps);
215 
216 		tmps = mopGetShort(pkt, &idx);
217 		fprintf(fd, "Sys Buf Unava: %04x %d\n", tmps, tmps);
218 
219 		tmps = mopGetShort(pkt, &idx);
220 		fprintf(fd, "Usr Buf Unava: %04x %d\n", tmps, tmps);
221 
222 		break;
223 	case MOP_K_CODE_RVC:
224 
225 		tmpl = mopGetLong(pkt, &idx);
226 		fprintf(fd, "Verification : %08lx\n", tmpl);
227 
228 		break;
229 	case MOP_K_CODE_RLC:
230 
231 		/* Empty message */
232 
233 		break;
234 	case MOP_K_CODE_CCP:
235 		tmpc = mopGetChar(pkt, &idx);
236 		fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
237 		if (tmpc & 2)
238 			fprintf(fd, "Break");
239 		fprintf(fd, "\n");
240 
241 		if (moplen > 2) {
242 			for (i = 0; i < (moplen - 2); i++) {
243 				if ((i % 16) == 0) {
244 					if ((i / 16) == 0)
245 						fprintf(fd,
246 						    "Image Data   : %04x ",
247 						    moplen-2);
248 					else
249 						fprintf(fd,
250 						    "                    ");
251 				}
252 				fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
253 				if ((i % 16) == 15)
254 					fprintf(fd, "\n");
255 			}
256 			if ((i % 16) != 15)
257 				fprintf(fd, "\n");
258 		}
259 
260 		break;
261 	case MOP_K_CODE_CRA:
262 
263 		tmpc = mopGetChar(pkt, &idx);
264 		fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
265 		if (tmpc & 2)
266 			fprintf(fd, "Cmd Data Lost ");
267 		if (tmpc & 4)
268 			fprintf(fd, "Resp Data Lost ");
269 		fprintf(fd, "\n");
270 
271 		if (moplen > 2) {
272 			for (i = 0; i < (moplen - 2); i++) {
273 				if ((i % 16) == 0) {
274 					if ((i / 16) == 0)
275 						fprintf(fd,
276 						    "Image Data   : %04x ",
277 						    moplen-2);
278 					else
279 						fprintf(fd,
280 						    "                    ");
281 				}
282 				fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
283 				if ((i % 16) == 15)
284 					fprintf(fd, "\n");
285 			}
286 			if ((i % 16) != 15)
287 				fprintf(fd, "\n");
288 		}
289 
290 		break;
291 	default:
292 		break;
293 	}
294 }
295