1*916fc46cSflorian /* $OpenBSD: rc.c,v 1.9 2017/07/29 07:18:03 florian Exp $ */
2e08c8b61Smaja
3bff609efSmaja /*
4bff609efSmaja * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
5bff609efSmaja *
6bff609efSmaja * Redistribution and use in source and binary forms, with or without
7bff609efSmaja * modification, are permitted provided that the following conditions
8bff609efSmaja * are met:
9bff609efSmaja * 1. Redistributions of source code must retain the above copyright
10bff609efSmaja * notice, this list of conditions and the following disclaimer.
11bff609efSmaja * 2. Redistributions in binary form must reproduce the above copyright
12bff609efSmaja * notice, this list of conditions and the following disclaimer in the
13bff609efSmaja * documentation and/or other materials provided with the distribution.
14bff609efSmaja *
15bff609efSmaja * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16bff609efSmaja * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17bff609efSmaja * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18bff609efSmaja * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19bff609efSmaja * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20bff609efSmaja * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21bff609efSmaja * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22bff609efSmaja * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23bff609efSmaja * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24bff609efSmaja * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25bff609efSmaja */
26bff609efSmaja
27bff609efSmaja #include "os.h"
28bff609efSmaja #include "common/get.h"
29bff609efSmaja #include "common/print.h"
30bff609efSmaja #include "common/mopdef.h"
31bff609efSmaja
32bff609efSmaja void
mopDumpRC(FILE * fd,u_char * pkt,int trans)3327ce7e35Shenning mopDumpRC(FILE *fd, u_char *pkt, int trans)
34bff609efSmaja {
353cd9cd14Smaja int i, idx = 0;
36bff609efSmaja long tmpl;
37bff609efSmaja u_char tmpc, code, control;
38bff609efSmaja u_short len, tmps, moplen;
39bff609efSmaja
40bff609efSmaja len = mopGetLength(pkt, trans);
41bff609efSmaja
42bff609efSmaja switch (trans) {
43bff609efSmaja case TRANS_8023:
443cd9cd14Smaja idx = 22;
45bff609efSmaja moplen = len - 8;
46bff609efSmaja break;
47bff609efSmaja default:
483cd9cd14Smaja idx = 16;
49bff609efSmaja moplen = len;
50bff609efSmaja }
513cd9cd14Smaja code = mopGetChar(pkt, &idx);
52bff609efSmaja
53bff609efSmaja switch (code) {
54bff609efSmaja case MOP_K_CODE_RID:
55bff609efSmaja
563cd9cd14Smaja tmpc = mopGetChar(pkt, &idx);
5727ce7e35Shenning fprintf(fd, "Reserved : %02x\n", tmpc);
58bff609efSmaja
593cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
6027ce7e35Shenning fprintf(fd, "Receipt Nbr : %04x\n", tmps);
61bff609efSmaja
62bff609efSmaja break;
63bff609efSmaja case MOP_K_CODE_BOT:
64bff609efSmaja
65*916fc46cSflorian if (moplen == 5) {
663cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
6727ce7e35Shenning fprintf(fd, "Verification : %04x\n", tmps);
68bff609efSmaja } else {
69bff609efSmaja
703cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
7127ce7e35Shenning fprintf(fd, "Verification : %08lx\n", tmpl);
72bff609efSmaja
733cd9cd14Smaja tmpc = mopGetChar(pkt, &idx); /* Processor */
7427ce7e35Shenning fprintf(fd, "Processor : %02x ", tmpc);
7527ce7e35Shenning mopPrintBPTY(fd, tmpc); fprintf(fd, "\n");
76bff609efSmaja
773cd9cd14Smaja control = mopGetChar(pkt, &idx); /* Control */
7827ce7e35Shenning fprintf(fd, "Control : %02x ", control);
79eebea325Smaja if ((control & (1<<MOP_K_BOT_CNTL_SERVER)))
8027ce7e35Shenning fprintf(fd, "Bootserver Requesting system ");
8127ce7e35Shenning else
8227ce7e35Shenning fprintf(fd, "Bootserver System default ");
83eebea325Smaja if ((control & (1<<MOP_K_BOT_CNTL_DEVICE)))
8427ce7e35Shenning fprintf(fd, "Bootdevice Specified device");
8527ce7e35Shenning else
8627ce7e35Shenning fprintf(fd, "Bootdevice System default");
8727ce7e35Shenning fprintf(fd, "\n");
88bff609efSmaja
89eebea325Smaja if ((control & (1<<MOP_K_BOT_CNTL_DEVICE))) {
903cd9cd14Smaja tmpc = mopGetChar(pkt, &idx);/* Device ID */
9127ce7e35Shenning fprintf(fd, "Device ID : %02x '", tmpc);
9227ce7e35Shenning for (i = 0; i < ((int) tmpc); i++)
9327ce7e35Shenning fprintf(fd, "%c",
943cd9cd14Smaja mopGetChar(pkt, &idx));
9527ce7e35Shenning fprintf(fd, "'\n");
96bff609efSmaja }
97bff609efSmaja
983cd9cd14Smaja tmpc = mopGetChar(pkt, &idx); /* Software ID */
9927ce7e35Shenning fprintf(fd, "Software ID : %02x ", tmpc);
100*916fc46cSflorian if (tmpc == 0)
10127ce7e35Shenning fprintf(fd, "No software id");
102*916fc46cSflorian if (tmpc == 254) {
10327ce7e35Shenning fprintf(fd, "Maintenance system");
104bff609efSmaja tmpc = 0;
105bff609efSmaja }
106*916fc46cSflorian if (tmpc == 255) {
10727ce7e35Shenning fprintf(fd, "Standard operating system");
108bff609efSmaja tmpc = 0;
109bff609efSmaja }
110*916fc46cSflorian if (tmpc > 0) {
11127ce7e35Shenning fprintf(fd, "'");
11227ce7e35Shenning for (i = 0; i < ((int) tmpc); i++)
11327ce7e35Shenning fprintf(fd, "%c",
1143cd9cd14Smaja mopGetChar(pkt, &idx));
11527ce7e35Shenning fprintf(fd, "'");
116bff609efSmaja }
11727ce7e35Shenning fprintf(fd, "'\n");
118bff609efSmaja
119bff609efSmaja }
120bff609efSmaja break;
121bff609efSmaja case MOP_K_CODE_SID:
122bff609efSmaja
1233cd9cd14Smaja tmpc = mopGetChar(pkt, &idx); /* Reserved */
12427ce7e35Shenning fprintf(fd, "Reserved : %02x\n", tmpc);
125bff609efSmaja
1263cd9cd14Smaja tmps = mopGetShort(pkt, &idx); /* Receipt # */
12727ce7e35Shenning fprintf(fd, "Receipt Nbr : %04x\n", tmpc);
128bff609efSmaja
1293cd9cd14Smaja mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
130bff609efSmaja
131bff609efSmaja break;
132bff609efSmaja case MOP_K_CODE_RQC:
133bff609efSmaja
1343cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
13527ce7e35Shenning fprintf(fd, "Receipt Nbr : %04x\n", tmps);
136bff609efSmaja
137bff609efSmaja break;
138bff609efSmaja case MOP_K_CODE_CNT:
139bff609efSmaja
1403cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
14127ce7e35Shenning fprintf(fd, "Receipt Nbr : %04x %d\n", tmps, tmps);
142bff609efSmaja
1433cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
14427ce7e35Shenning fprintf(fd, "Last Zeroed : %04x %d\n", tmps, tmps);
145bff609efSmaja
1463cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
14727ce7e35Shenning fprintf(fd, "Bytes rec : %08lx %ld\n", tmpl, tmpl);
148bff609efSmaja
1493cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
15027ce7e35Shenning fprintf(fd, "Bytes snd : %08lx %ld\n", tmpl, tmpl);
151bff609efSmaja
1523cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
15327ce7e35Shenning fprintf(fd, "Frames rec : %08lx %ld\n", tmpl, tmpl);
154bff609efSmaja
1553cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
15627ce7e35Shenning fprintf(fd, "Frames snd : %08lx %ld\n", tmpl, tmpl);
157bff609efSmaja
1583cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
15927ce7e35Shenning fprintf(fd, "Mcst Bytes re: %08lx %ld\n", tmpl, tmpl);
160bff609efSmaja
1613cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
16227ce7e35Shenning fprintf(fd, "Mcst Frame re: %08lx %ld\n", tmpl, tmpl);
163bff609efSmaja
1643cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
16527ce7e35Shenning fprintf(fd, "Frame snd, def: %08lx %ld\n", tmpl, tmpl);
166bff609efSmaja
1673cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
16827ce7e35Shenning fprintf(fd, "Frame snd, col: %08lx %ld\n", tmpl, tmpl);
169bff609efSmaja
1703cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
17127ce7e35Shenning fprintf(fd, "Frame snd, mcl: %08lx %ld\n", tmpl, tmpl);
172bff609efSmaja
1733cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
17427ce7e35Shenning fprintf(fd, "Snd failure : %04x %d\n", tmps, tmps);
175bff609efSmaja
1763cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
17727ce7e35Shenning fprintf(fd, "Snd fail reas: %04x ", tmps);
17827ce7e35Shenning if (tmps & 1)
17927ce7e35Shenning fprintf(fd, "Excess col ");
18027ce7e35Shenning if (tmps & 2)
18127ce7e35Shenning fprintf(fd, "Carrier chk fail ");
18227ce7e35Shenning if (tmps & 4)
18327ce7e35Shenning fprintf(fd, "Short circ ");
18427ce7e35Shenning if (tmps & 8)
18527ce7e35Shenning fprintf(fd, "Open circ ");
18627ce7e35Shenning if (tmps & 16)
18727ce7e35Shenning fprintf(fd, "Frm to long ");
18827ce7e35Shenning if (tmps & 32)
18927ce7e35Shenning fprintf(fd, "Rem fail to defer ");
19027ce7e35Shenning fprintf(fd, "\n");
191bff609efSmaja
1923cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
19327ce7e35Shenning fprintf(fd, "Rec failure : %04x %d\n", tmps, tmps);
194bff609efSmaja
1953cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
19627ce7e35Shenning fprintf(fd, "Rec fail reas: %04x ", tmps);
19727ce7e35Shenning if (tmps & 1)
19827ce7e35Shenning fprintf(fd, "Block chk err ");
19927ce7e35Shenning if (tmps & 2)
20027ce7e35Shenning fprintf(fd, "Framing err ");
20127ce7e35Shenning if (tmps & 4)
20227ce7e35Shenning fprintf(fd, "Frm to long ");
20327ce7e35Shenning fprintf(fd, "\n");
204bff609efSmaja
2053cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
20627ce7e35Shenning fprintf(fd, "Unrec frm dst: %04x %d\n", tmps, tmps);
207bff609efSmaja
2083cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
20927ce7e35Shenning fprintf(fd, "Data overrun : %04x %d\n", tmps, tmps);
210bff609efSmaja
2113cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
21227ce7e35Shenning fprintf(fd, "Sys Buf Unava: %04x %d\n", tmps, tmps);
213bff609efSmaja
2143cd9cd14Smaja tmps = mopGetShort(pkt, &idx);
21527ce7e35Shenning fprintf(fd, "Usr Buf Unava: %04x %d\n", tmps, tmps);
216bff609efSmaja
217bff609efSmaja break;
218bff609efSmaja case MOP_K_CODE_RVC:
219bff609efSmaja
2203cd9cd14Smaja tmpl = mopGetLong(pkt, &idx);
22127ce7e35Shenning fprintf(fd, "Verification : %08lx\n", tmpl);
222bff609efSmaja
223bff609efSmaja break;
224bff609efSmaja case MOP_K_CODE_RLC:
225bff609efSmaja
226bff609efSmaja /* Empty message */
227bff609efSmaja
228bff609efSmaja break;
229bff609efSmaja case MOP_K_CODE_CCP:
2303cd9cd14Smaja tmpc = mopGetChar(pkt, &idx);
23127ce7e35Shenning fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
23227ce7e35Shenning if (tmpc & 2)
23327ce7e35Shenning fprintf(fd, "Break");
23427ce7e35Shenning fprintf(fd, "\n");
235bff609efSmaja
236bff609efSmaja if (moplen > 2) {
237bff609efSmaja for (i = 0; i < (moplen - 2); i++) {
238bff609efSmaja if ((i % 16) == 0) {
23927ce7e35Shenning if ((i / 16) == 0)
24027ce7e35Shenning fprintf(fd,
241bff609efSmaja "Image Data : %04x ",
242bff609efSmaja moplen-2);
24327ce7e35Shenning else
24427ce7e35Shenning fprintf(fd,
245bff609efSmaja " ");
246bff609efSmaja }
2473cd9cd14Smaja fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
248bff609efSmaja if ((i % 16) == 15)
24927ce7e35Shenning fprintf(fd, "\n");
250bff609efSmaja }
251bff609efSmaja if ((i % 16) != 15)
25227ce7e35Shenning fprintf(fd, "\n");
253bff609efSmaja }
254bff609efSmaja
255bff609efSmaja break;
256bff609efSmaja case MOP_K_CODE_CRA:
257bff609efSmaja
2583cd9cd14Smaja tmpc = mopGetChar(pkt, &idx);
25927ce7e35Shenning fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
26027ce7e35Shenning if (tmpc & 2)
26127ce7e35Shenning fprintf(fd, "Cmd Data Lost ");
26227ce7e35Shenning if (tmpc & 4)
26327ce7e35Shenning fprintf(fd, "Resp Data Lost ");
26427ce7e35Shenning fprintf(fd, "\n");
265bff609efSmaja
266bff609efSmaja if (moplen > 2) {
267bff609efSmaja for (i = 0; i < (moplen - 2); i++) {
268bff609efSmaja if ((i % 16) == 0) {
26927ce7e35Shenning if ((i / 16) == 0)
27027ce7e35Shenning fprintf(fd,
271bff609efSmaja "Image Data : %04x ",
272bff609efSmaja moplen-2);
27327ce7e35Shenning else
27427ce7e35Shenning fprintf(fd,
275bff609efSmaja " ");
276bff609efSmaja }
2773cd9cd14Smaja fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
278bff609efSmaja if ((i % 16) == 15)
27927ce7e35Shenning fprintf(fd, "\n");
280bff609efSmaja }
281bff609efSmaja if ((i % 16) != 15)
28227ce7e35Shenning fprintf(fd, "\n");
283bff609efSmaja }
284bff609efSmaja
285bff609efSmaja break;
286bff609efSmaja default:
287bff609efSmaja break;
288bff609efSmaja }
289bff609efSmaja }
290