summaryrefslogtreecommitdiff
path: root/usr.sbin/mopd/common/print.c
blob: f6d0cf13dcdd1ab7519755ff5ac43f13fd1fbc58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*	$OpenBSD: print.c,v 1.11 2006/04/20 08:52:52 maja Exp $ */

/*
 * Copyright (c) 1993-96 Mats O Jansson.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef lint
static const char rcsid[] =
    "$OpenBSD: print.c,v 1.11 2006/04/20 08:52:52 maja Exp $";
#endif

#include <sys/types.h>
#include <stdio.h>

#include "os.h"
#include "common/mopdef.h"
#include "common/nmadef.h"
#include "common/nma.h"
#include "common/cmp.h"
#include "common/get.h"

#define SHORT_PRINT

void
mopPrintHWA(FILE *fd, u_char *ap)
{
	fprintf(fd, "%x:%x:%x:%x:%x:%x", ap[0], ap[1], ap[2], ap[3], ap[4],
	    ap[5]);
	if (ap[0] < 16) fprintf(fd, " ");
	if (ap[1] < 16) fprintf(fd, " ");
	if (ap[2] < 16) fprintf(fd, " ");
	if (ap[3] < 16) fprintf(fd, " ");
	if (ap[4] < 16) fprintf(fd, " ");
	if (ap[5] < 16) fprintf(fd, " ");
}

void
mopPrintBPTY(FILE *fd, u_char bpty)
{
	switch (bpty) {
	case MOP_K_BPTY_SYS:
		fprintf(fd, "System Processor");
		break;
	case MOP_K_BPTY_COM:
		fprintf(fd, "Communication Processor");
		break;
	default:
		fprintf(fd, "Unknown");
		break;
	};
}

void
mopPrintPGTY(FILE *fd, u_char pgty)
{
	switch (pgty) {
	case MOP_K_PGTY_SECLDR:
		fprintf(fd, "Secondary Loader");
		break;
	case MOP_K_PGTY_TERLDR:
		fprintf(fd, "Tertiary Loader");
		break;
	case MOP_K_PGTY_OPRSYS:
		fprintf(fd, "Operating System");
		break;
	case MOP_K_PGTY_MGNTFL:
		fprintf(fd, "Management File");
		break;
	default:
		fprintf(fd, "Unknown");
		break;
	};
}

void
mopPrintOneline(FILE *fd, u_char *pkt, int trans)
{
	int	 idx = 0;
	u_char	*dst, *src, code;
	u_short	 proto;
	int	 len;

	trans = mopGetTrans(pkt, trans);
	mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);
	code = mopGetChar(pkt, &idx);

	switch (proto) {
	case MOP_K_PROTO_DL:
		fprintf(fd, "MOP DL ");
		break;
	case MOP_K_PROTO_RC:
		fprintf(fd, "MOP RC ");
		break;
	case MOP_K_PROTO_LP:
		fprintf(fd, "MOP LP ");
		break;
	default:
		switch ((proto % 256) * 256 + (proto / 256)) {
		case MOP_K_PROTO_DL:
			fprintf(fd, "MOP DL ");
			proto = MOP_K_PROTO_DL;
			break;
		case MOP_K_PROTO_RC:
			fprintf(fd, "MOP RC ");
			proto = MOP_K_PROTO_RC;
			break;
		case MOP_K_PROTO_LP:
			fprintf(fd, "MOP LP ");
			proto = MOP_K_PROTO_LP;
			break;
		default:
			fprintf(fd, "MOP ?? ");
			break;
		}
	}

	if (trans == TRANS_8023)
		fprintf(fd, "802.3 ");

	mopPrintHWA(fd, src); fprintf(fd, " > ");
	mopPrintHWA(fd, dst);
	if (len < 1600)
	fprintf(fd, " len %4d code %02x ", len, code);
	else
		fprintf(fd, " len %4d code %02x ",
		    (len % 256)*256 + (len /256), code);

	switch (proto) {
	case MOP_K_PROTO_DL:
	switch (code) {
		case MOP_K_CODE_MLT:
			fprintf(fd, "MLT ");
			break;
		case MOP_K_CODE_DCM:
			fprintf(fd, "DCM ");
			break;
		case MOP_K_CODE_MLD:
			fprintf(fd, "MLD ");
			break;
		case MOP_K_CODE_ASV:
			fprintf(fd, "ASV ");
			break;
		case MOP_K_CODE_RMD:
			fprintf(fd, "RMD ");
			break;
		case MOP_K_CODE_RPR:
			fprintf(fd, "RPR ");
			break;
		case MOP_K_CODE_RML:
			fprintf(fd, "RML ");
			break;
		case MOP_K_CODE_RDS:
			fprintf(fd, "RDS ");
			break;
		case MOP_K_CODE_MDD:
			fprintf(fd, "MDD ");
			break;
		case MOP_K_CODE_PLT:
			fprintf(fd, "PLT ");
			break;
		default:
			fprintf(fd, "??? ");
			break;
		}
		break;
	case MOP_K_PROTO_RC:
		switch (code) {
		case MOP_K_CODE_RID:
			fprintf(fd, "RID ");
			break;
		case MOP_K_CODE_BOT:
			fprintf(fd, "BOT ");
			break;
		case MOP_K_CODE_SID:
			fprintf(fd, "SID ");
			break;
		case MOP_K_CODE_RQC:
			fprintf(fd, "RQC ");
			break;
		case MOP_K_CODE_CNT:
			fprintf(fd, "CNT ");
			break;
		case MOP_K_CODE_RVC:
			fprintf(fd, "RVC ");
			break;
		case MOP_K_CODE_RLC:
			fprintf(fd, "RLC ");
			break;
		case MOP_K_CODE_CCP:
			fprintf(fd, "CCP ");
			break;
		case MOP_K_CODE_CRA:
			fprintf(fd, "CRA ");
			break;
		default:
			fprintf(fd, "??? ");
			break;
		}
		break;
	case MOP_K_PROTO_LP:
		switch (code) {
		case MOP_K_CODE_ALD:
			fprintf(fd, "ALD ");
			break;
		case MOP_K_CODE_PLD:
			fprintf(fd, "PLD ");
			break;
		default:
			fprintf(fd, "??? ");
			break;
		}
		break;
	default:
		fprintf(fd, "??? ");
		break;
	}
	fprintf(fd, "\n");
}

void
mopPrintHeader(FILE *fd, u_char *pkt, int trans)
{
	u_char	*dst, *src;
	u_short	 proto;
	int	 len, idx = 0;

	trans = mopGetTrans(pkt, trans);
	mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);

	fprintf(fd, "\nDst          : ");
	mopPrintHWA(fd, dst);
	if (mopCmpEAddr(dl_mcst, dst) == 0)
		fprintf(fd, " MOP Dump/Load Multicast");
	if (mopCmpEAddr(rc_mcst, dst) == 0)
		fprintf(fd, " MOP Remote Console Multicast");
	fprintf(fd, "\n");

	fprintf(fd, "Src          : ");
	mopPrintHWA(fd, src);
	fprintf(fd, "\n");
	fprintf(fd, "Proto        : %04x ", proto);

	switch (proto) {
	case MOP_K_PROTO_DL:
		switch (trans) {
		case TRANS_8023:
			fprintf(fd, "MOP Dump/Load (802.3)\n");
			break;
		default:
			fprintf(fd, "MOP Dump/Load\n");
		}
		break;
	case MOP_K_PROTO_RC:
		switch (trans) {
		case TRANS_8023:
			fprintf(fd, "MOP Remote Console (802.3)\n");
			break;
		default:
			fprintf(fd, "MOP Remote Console\n");
		}
		break;
	case MOP_K_PROTO_LP:
		switch (trans) {
		case TRANS_8023:
			fprintf(fd, "MOP Loopback (802.3)\n");
			break;
		default:
			fprintf(fd, "MOP Loopback\n");
		}
		break;
	default:
		fprintf(fd, "\n");
		break;
	}

	fprintf(fd, "Length       : %04x (%d)\n", len, len);
}

void
mopPrintMopHeader(FILE *fd, u_char *pkt, int trans)
{
	u_char	*dst, *src;
	u_short	 proto;
	int	 len, idx = 0;
	u_char   code;

	trans = mopGetTrans(pkt, trans);
	mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);

	code = mopGetChar(pkt, &idx);

	fprintf(fd, "Code         :   %02x ", code);

	switch (proto) {
	case MOP_K_PROTO_DL:
		switch (code) {
		case MOP_K_CODE_MLT:
			fprintf(fd, "Memory Load with transfer address\n");
			break;
		case MOP_K_CODE_DCM:
			fprintf(fd, "Dump Complete\n");
			break;
		case MOP_K_CODE_MLD:
			fprintf(fd, "Memory Load\n");
			break;
		case MOP_K_CODE_ASV:
			fprintf(fd, "Assistance volunteer\n");
			break;
		case MOP_K_CODE_RMD:
			fprintf(fd, "Request memory dump\n");
			break;
		case MOP_K_CODE_RPR:
			fprintf(fd, "Request program\n");
			break;
		case MOP_K_CODE_RML:
			fprintf(fd, "Request memory load\n");
			break;
		case MOP_K_CODE_RDS:
			fprintf(fd, "Request Dump Service\n");
			break;
		case MOP_K_CODE_MDD:
			fprintf(fd, "Memory dump data\n");
			break;
		case MOP_K_CODE_PLT:
			fprintf(fd, "Parameter load with transfer address\n");
			break;
		default:
			fprintf(fd, "(unknown)\n");
			break;
		}
		break;
	case MOP_K_PROTO_RC:
		switch (code) {
		case MOP_K_CODE_RID:
			fprintf(fd, "Request ID\n");
			break;
		case MOP_K_CODE_BOT:
			fprintf(fd, "Boot\n");
			break;
		case MOP_K_CODE_SID:
			fprintf(fd, "System ID\n");
			break;
		case MOP_K_CODE_RQC:
			fprintf(fd, "Request Counters\n");
			break;
		case MOP_K_CODE_CNT:
			fprintf(fd, "Counters\n");
			break;
		case MOP_K_CODE_RVC:
			fprintf(fd, "Reserve Console\n");
			break;
		case MOP_K_CODE_RLC:
			fprintf(fd, "Release Console\n");
			break;
		case MOP_K_CODE_CCP:
			fprintf(fd, "Console Command and Poll\n");
			break;
		case MOP_K_CODE_CRA:
			fprintf(fd, "Console Response and Acknnowledge\n");
			break;
		default:
			fprintf(fd, "(unknown)\n");
			break;
		}
		break;
	case MOP_K_PROTO_LP:
		switch (code) {
		case MOP_K_CODE_ALD:
			fprintf(fd, "Active loop data\n");
			break;
		case MOP_K_CODE_PLD:
			fprintf(fd, "Passive looped data\n");
			break;
		default:
			fprintf(fd, "(unknown)\n");
			break;
		}
		break;
	default:
		fprintf(fd, "(unknown)\n");
		break;
	}
}

void
mopPrintDevice(FILE *fd, u_char device)
{
	char	*sname, *name;

	sname = nmaGetShort((int) device);
	name = nmaGetDevice((int) device);

	fprintf(fd, "%s '%s'", sname, name);
}

void
mopPrintTime(FILE *fd, u_char *ap)
{
	fprintf(fd, "%04d-%02d-%02d %02d:%02d:%02d.%02d %d:%02d",
	    ap[0] * 100 + ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7],
	    ap[8], ap[9]);
}

void
mopPrintInfo(FILE *fd, u_char *pkt, int *idx, u_short moplen, u_char mopcode,
    int trans)
{
	u_short itype, tmps;
	u_char  ilen, tmpc, device;
	u_char  uc1, uc2, uc3, *ucp;
	int     i;

	device = 0;

	switch (trans) {
	case TRANS_ETHER:
		moplen = moplen + 16;
		break;
	case TRANS_8023:
		moplen = moplen + 14;
		break;
	}

	itype = mopGetShort(pkt, idx);

	while (*idx < (moplen + 2)) {
		ilen = mopGetChar(pkt, idx);
		switch (itype) {
		case 0:
			tmpc  = mopGetChar(pkt, idx);
			*idx = *idx + tmpc;
			break;
		case MOP_K_INFO_VER:
			uc1 = mopGetChar(pkt, idx);
			uc2 = mopGetChar(pkt, idx);
			uc3 = mopGetChar(pkt, idx);
			fprintf(fd, "Maint Version: %d.%d.%d\n", uc1, uc2, uc3);
			break;
		case MOP_K_INFO_MFCT:
			tmps = mopGetShort(pkt, idx);
			fprintf(fd, "Maint Funcion: %04x ( ", tmps);
			if (tmps &   1) fprintf(fd, "Loop ");
			if (tmps &   2) fprintf(fd, "Dump ");
			if (tmps &   4) fprintf(fd, "Pldr ");
			if (tmps &   8) fprintf(fd, "MLdr ");
			if (tmps &  16) fprintf(fd, "Boot ");
			if (tmps &  32) fprintf(fd, "CC ");
			if (tmps &  64) fprintf(fd, "DLC ");
			if (tmps & 128) fprintf(fd, "CCR ");
			fprintf(fd, ")\n");
			break;
		case MOP_K_INFO_CNU:
			ucp = pkt + *idx;
			*idx = *idx + 6;
			fprintf(fd, "Console User : ");
			mopPrintHWA(fd, ucp);
			fprintf(fd, "\n");
			break;
		case MOP_K_INFO_RTM:
			tmps = mopGetShort(pkt, idx);
			fprintf(fd, "Reserv Timer : %04x (%d)\n", tmps, tmps);
			break;
		case MOP_K_INFO_CSZ:
			tmps = mopGetShort(pkt, idx);
			fprintf(fd, "Cons Cmd Size: %04x (%d)\n", tmps, tmps);
			break;
		case MOP_K_INFO_RSZ:
			tmps = mopGetShort(pkt, idx);
			fprintf(fd, "Cons Res Size: %04x (%d)\n", tmps, tmps);
			break;
		case MOP_K_INFO_HWA:
			ucp = pkt + *idx;
			*idx = *idx + 6;
			fprintf(fd, "Hardware Addr: ");
			mopPrintHWA(fd, ucp);
			fprintf(fd, "\n");
			break;
		case MOP_K_INFO_TIME:
			ucp = pkt + *idx;
			*idx = *idx + 10;
			fprintf(fd, "System Time: ");
			mopPrintTime(fd, ucp);
			fprintf(fd, "\n");
			break;
		case MOP_K_INFO_SOFD:
			device = mopGetChar(pkt, idx);
			fprintf(fd, "Comm Device  :   %02x ", device);
			mopPrintDevice(fd, device);
			fprintf(fd, "\n");
			break;
		case MOP_K_INFO_SFID:
			tmpc = mopGetChar(pkt, idx);
			fprintf(fd, "Software ID  :   %02x ", tmpc);
			if ((tmpc == 0))
				fprintf(fd, "No software id");
			if ((tmpc == 254)) {
				fprintf(fd, "Maintenance system");
				tmpc = 0;
			}
			if ((tmpc == 255)) {
				fprintf(fd, "Standard operating system");
				tmpc = 0;
			}
			if ((tmpc > 0)) {
				fprintf(fd, "'");
				for (i = 0; i < ((int) tmpc); i++)
					fprintf(fd, "%c",
					    mopGetChar(pkt, idx));
				fprintf(fd, "'");
			}
			fprintf(fd, "\n");
			break;
		case MOP_K_INFO_PRTY:
			tmpc = mopGetChar(pkt, idx);
			fprintf(fd, "System Proc  :   %02x ", tmpc);
			switch (tmpc) {
			case MOP_K_PRTY_11:
				fprintf(fd, "PDP-11\n");
				break;
			case MOP_K_PRTY_CMSV:
				fprintf(fd, "Communication Server\n");
				break;
			case MOP_K_PRTY_PRO:
				fprintf(fd, "Professional\n");
				break;
			case MOP_K_PRTY_SCO:
				fprintf(fd, "Scorpio\n");
				break;
			case MOP_K_PRTY_AMB:
				fprintf(fd, "Amber\n");
				break;
			case MOP_K_PRTY_BRI:
				fprintf(fd, "XLII Bridge\n");
				break;
			default:
				fprintf(fd, "Unknown\n");
				break;
			};
			break;
		case MOP_K_INFO_DLTY:
			tmpc = mopGetChar(pkt, idx);
			fprintf(fd, "DLnk Type    :   %02x ", tmpc);
			switch (tmpc) {
			case MOP_K_DLTY_NI:
				fprintf(fd, "Ethernet\n");
				break;
			case MOP_K_DLTY_DDCMP:
				fprintf(fd, "DDCMP\n");
				break;
			case MOP_K_DLTY_LAPB:
				fprintf(fd, "LAPB (X.25)\n");
				break;
			default:
				fprintf(fd, "Unknown\n");
				break;
			};
			break;
		case MOP_K_INFO_DLBSZ:
			tmps = mopGetShort(pkt, idx);
			fprintf(fd, "DLnk Buf Size: %04x (%d)\n", tmps, tmps);
			break;
		default:
			if (((device == NMA_C_SOFD_LCS) ||  /* DECserver 100 */
			     (device == NMA_C_SOFD_DS2) ||  /* DECserver 200 */
			     (device == NMA_C_SOFD_DP2) ||  /* DECserver 250 */
			     (device == NMA_C_SOFD_DS3)) && /* DECserver 300 */
			    ((itype > 101) && (itype < 107)))
			{
			switch (itype) {
				case 102:
					ucp = pkt + *idx;
					*idx = *idx + ilen;
					fprintf(fd, "ROM SW Ver   :   %02x '",
					    ilen);
					for (i = 0; i < ilen; i++)
						fprintf(fd, "%c", ucp[i]);
					fprintf(fd, "'\n");
					break;
				case 103:
					ucp = pkt + *idx;
					*idx = *idx + ilen;
					fprintf(fd, "Loaded SW Ver:   %02x '",
					    ilen);
					for (i = 0; i < ilen; i++)
						fprintf(fd, "%c", ucp[i]);
					fprintf(fd, "'\n");
					break;
				case 104:
					tmps = mopGetShort(pkt, idx);
					fprintf(fd,
					    "DECnet Addr  : %d.%d (%d)\n",
					    tmps / 1024, tmps % 1024, tmps);
					break;
				case 105:
					ucp = pkt + *idx;
					*idx = *idx + ilen;
					fprintf(fd, "Node Name    :   %02x '",
					    ilen);
					for (i = 0; i < ilen; i++)
						fprintf(fd, "%c", ucp[i]);
					fprintf(fd, "'\n");
					break;
				case 106:
					ucp = pkt + *idx;
					*idx = *idx + ilen;
					fprintf(fd, "Node Ident   :   %02x '",
					    ilen);
					for (i = 0; i < ilen; i++)
						fprintf(fd, "%c", ucp[i]);
					fprintf(fd, "'\n");
					break;
				}
			} else {
				ucp = pkt + *idx;
				*idx = *idx + ilen;
				fprintf(fd, "Info Type    : %04x (%d)\n",
				    itype, itype);
				fprintf(fd, "Info Data    :   %02x ", ilen);
				for (i = 0; i < ilen; i++) {
					if ((i % 16) == 0)
						if ((i / 16) != 0)
							fprintf(fd,
						     "\n                    ");
					fprintf(fd, "%02x ", ucp[i]);
				}
				fprintf(fd, "\n");
			}
		}
		itype = mopGetShort(pkt, idx);
	}
}