Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / mopd / common / rc.c
blob8890109df8f352a0fc1842fa025baa83d3bb3f7c
1 /* $NetBSD: rc.c,v 1.5 2009/10/20 00:51:13 snj Exp $ */
3 /*
4 * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
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.
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.
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
32 #include "os.h"
33 #include "get.h"
34 #include "mopdef.h"
35 #include "print.h"
36 #include "rc.h"
38 void
39 mopDumpRC(FILE *fd, const u_char *pkt, int trans)
41 int i,idx = 0;
42 int32_t tmpl;
43 u_char tmpc,code,control;
44 u_short len,tmps,moplen;
46 len = mopGetLength(pkt, trans);
48 switch (trans) {
49 case TRANS_8023:
50 idx = 22;
51 moplen = len - 8;
52 break;
53 default:
54 idx = 16;
55 moplen = len;
57 code = mopGetChar(pkt,&idx);
59 switch (code) {
60 case MOP_K_CODE_RID:
62 tmpc = mopGetChar(pkt,&idx);
63 (void)fprintf(fd,"Reserved : %02x\n",tmpc);
65 tmps = mopGetShort(pkt,&idx);
66 (void)fprintf(fd,"Receipt Nbr : %04x\n",tmps);
68 break;
69 case MOP_K_CODE_BOT:
71 if ((moplen == 5)) {
72 tmps = mopGetShort(pkt,&idx);
73 (void)fprintf(fd,"Verification : %04x\n",tmps);
74 } else {
76 tmpl = mopGetLong(pkt,&idx);
77 (void)fprintf(fd,"Verification : %08x\n",tmpl);
79 tmpc = mopGetChar(pkt,&idx); /* Processor */
80 (void)fprintf(fd,"Processor : %02x ",tmpc);
81 mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n");
83 control = mopGetChar(pkt,&idx); /* Control */
84 (void)fprintf(fd,"Control : %02x ",control);
85 if ((control & (1>>MOP_K_BOT_CNTL_SERVER))) {
86 (void)fprintf(fd,
87 "Bootserver Requesting system ");
88 } else {
89 (void)fprintf(fd,
90 "Bootserver System default ");
92 if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
93 (void)fprintf(fd,
94 "Bootdevice Specified device");
95 } else {
96 (void)fprintf(fd,
97 "Bootdevice System default");
99 (void)fprintf(fd,"\n");
101 if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
102 tmpc = mopGetChar(pkt,&idx);/* Device ID */
103 (void)fprintf(fd,
104 "Device ID : %02x '",tmpc);
105 for (i = 0; i < ((int) tmpc); i++) {
106 (void)fprintf(fd,"%c",
107 mopGetChar(pkt,&idx));
109 (void)fprintf(fd,"'\n");
112 tmpc = mopGetChar(pkt,&idx); /* Software ID */
113 (void)fprintf(fd,"Software ID : %02x ",tmpc);
114 if ((tmpc == 0)) {
115 (void)fprintf(fd,"No software id");
117 if ((tmpc == 254)) {
118 (void)fprintf(fd,"Maintenance system");
119 tmpc = 0;
121 if ((tmpc == 255)) {
122 (void)fprintf(fd,"Standard operating system");
123 tmpc = 0;
125 if ((tmpc > 0)) {
126 (void)fprintf(fd,"'");
127 for (i = 0; i < ((int) tmpc); i++) {
128 (void)fprintf(fd,"%c",
129 mopGetChar(pkt,&idx));
131 (void)fprintf(fd,"'");
133 (void)fprintf(fd,"'\n");
136 break;
137 case MOP_K_CODE_SID:
139 tmpc = mopGetChar(pkt,&idx); /* Reserved */
140 (void)fprintf(fd, "Reserved : %02x\n",tmpc);
142 tmps = mopGetShort(pkt,&idx); /* Receipt # */
143 (void)fprintf(fd, "Receipt Nbr : %04x\n",tmpc);
145 mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
147 break;
148 case MOP_K_CODE_RQC:
150 tmps = mopGetShort(pkt,&idx);
151 (void)fprintf(fd,"Receipt Nbr : %04x\n",tmps);
153 break;
154 case MOP_K_CODE_CNT:
156 tmps = mopGetShort(pkt,&idx);
157 (void)fprintf(fd,"Receipt Nbr : %04x %d\n",tmps,tmps);
159 tmps = mopGetShort(pkt,&idx);
160 (void)fprintf(fd,"Last Zeroed : %04x %d\n",tmps,tmps);
162 tmpl = mopGetLong(pkt,&idx);
163 (void)fprintf(fd,"Bytes rec : %08x %d\n",tmpl,tmpl);
165 tmpl = mopGetLong(pkt,&idx);
166 (void)fprintf(fd,"Bytes snd : %08x %d\n",tmpl,tmpl);
168 tmpl = mopGetLong(pkt,&idx);
169 (void)fprintf(fd,"Frames rec : %08x %d\n",tmpl,tmpl);
171 tmpl = mopGetLong(pkt,&idx);
172 (void)fprintf(fd,"Frames snd : %08x %d\n",tmpl,tmpl);
174 tmpl = mopGetLong(pkt,&idx);
175 (void)fprintf(fd,"Mcst Bytes re: %08x %d\n",tmpl,tmpl);
177 tmpl = mopGetLong(pkt,&idx);
178 (void)fprintf(fd,"Mcst Frame re: %08x %d\n",tmpl,tmpl);
180 tmpl = mopGetLong(pkt,&idx);
181 (void)fprintf(fd,"Frame snd,def: %08x %d\n",tmpl,tmpl);
183 tmpl = mopGetLong(pkt,&idx);
184 (void)fprintf(fd,"Frame snd,col: %08x %d\n",tmpl,tmpl);
186 tmpl = mopGetLong(pkt,&idx);
187 (void)fprintf(fd,"Frame snd,mcl: %08x %d\n",tmpl,tmpl);
189 tmps = mopGetShort(pkt,&idx);
190 (void)fprintf(fd,"Snd failure : %04x %d\n",tmps,tmps);
192 tmps = mopGetShort(pkt,&idx);
193 (void)fprintf(fd,"Snd fail reas: %04x ",tmps);
194 if ((tmps & 1)) (void)fprintf(fd,"Excess col ");
195 if ((tmps & 2)) (void)fprintf(fd,"Carrier chk fail ");
196 if ((tmps & 4)) (void)fprintf(fd,"Short circ ");
197 if ((tmps & 8)) (void)fprintf(fd,"Open circ ");
198 if ((tmps & 16)) (void)fprintf(fd,"Frm to long ");
199 if ((tmps & 32)) (void)fprintf(fd,"Rem fail to defer ");
200 (void)fprintf(fd,"\n");
202 tmps = mopGetShort(pkt,&idx);
203 (void)fprintf(fd,"Rec failure : %04x %d\n",tmps,tmps);
205 tmps = mopGetShort(pkt,&idx);
206 (void)fprintf(fd,"Rec fail reas: %04x ",tmps);
207 if ((tmps & 1)) (void)fprintf(fd,"Block chk err ");
208 if ((tmps & 2)) (void)fprintf(fd,"Framing err ");
209 if ((tmps & 4)) (void)fprintf(fd,"Frm to long ");
210 (void)fprintf(fd,"\n");
212 tmps = mopGetShort(pkt,&idx);
213 (void)fprintf(fd,"Unrec frm dst: %04x %d\n",tmps,tmps);
215 tmps = mopGetShort(pkt,&idx);
216 (void)fprintf(fd,"Data overrun : %04x %d\n",tmps,tmps);
218 tmps = mopGetShort(pkt,&idx);
219 (void)fprintf(fd,"Sys Buf Unava: %04x %d\n",tmps,tmps);
221 tmps = mopGetShort(pkt,&idx);
222 (void)fprintf(fd,"Usr Buf Unava: %04x %d\n",tmps,tmps);
224 break;
225 case MOP_K_CODE_RVC:
227 tmpl = mopGetLong(pkt,&idx);
228 (void)fprintf(fd,"Verification : %08x\n",tmpl);
230 break;
231 case MOP_K_CODE_RLC:
233 /* Empty message */
235 break;
236 case MOP_K_CODE_CCP:
238 tmpc = mopGetChar(pkt,&idx);
239 (void)fprintf(fd,
240 "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
241 if ((tmpc & 2))
242 (void)fprintf(fd,"Break");
243 (void)fprintf(fd,"\n");
245 if (moplen > 2) {
246 #ifndef SHORT_PRINT
247 for (i = 0; i < (moplen - 2); i++) {
248 if ((i % 16) == 0) {
249 if ((i / 16) == 0) {
250 (void)fprintf(fd,
251 "Image Data : %04x ",
252 moplen-2);
253 } else {
254 (void)fprintf(fd,
255 " ");
258 (void)fprintf(fd,"%02x ",
259 mopGetChar(pkt,&idx));
260 if ((i % 16) == 15)
261 (void)fprintf(fd,"\n");
263 if ((i % 16) != 15)
264 (void)fprintf(fd,"\n");
265 #else
266 idx = idx + moplen - 2;
267 #endif
270 break;
271 case MOP_K_CODE_CRA:
273 tmpc = mopGetChar(pkt,&idx);
274 (void)fprintf(fd,
275 "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
276 if ((tmpc & 2))
277 (void)fprintf(fd,"Cmd Data Lost ");
278 if ((tmpc & 4))
279 (void)fprintf(fd,"Resp Data Lost ");
280 (void)fprintf(fd,"\n");
282 if (moplen > 2) {
283 #ifndef SHORT_PRINT
284 for (i = 0; i < (moplen - 2); i++) {
285 if ((i % 16) == 0) {
286 if ((i / 16) == 0) {
287 (void)fprintf(fd,
288 "Image Data : %04x ",
289 moplen-2);
290 } else {
291 (void)fprintf(fd,
292 " ");
295 (void)fprintf(fd,"%02x ",
296 mopGetChar(pkt,&idx));
297 if ((i % 16) == 15)
298 (void)fprintf(fd,"\n");
300 if ((i % 16) != 15)
301 (void)fprintf(fd,"\n");
302 #else
303 idx = idx + moplen - 2;
304 #endif
307 break;
308 default:
309 break;