print.c revision 1.1
1/*
2 * Copyright (c) 1993-96 Mats O Jansson.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 *    must display the following acknowledgement:
14 *	This product includes software developed by Mats O Jansson.
15 * 4. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef LINT
31static char rcsid[] = "$Id: print.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
32#endif
33
34#include <sys/types.h>
35#include <stdio.h>
36
37#include "os.h"
38#include "common/mopdef.h"
39#include "common/nmadef.h"
40#include "common/nma.h"
41#include "common/cmp.h"
42#include "common/get.h"
43
44#define SHORT_PRINT
45
46void
47mopPrintHWA(fd, ap)
48	FILE	*fd;
49        u_char *ap;
50{
51	(void)fprintf(fd, "%x:%x:%x:%x:%x:%x",
52		      ap[0],ap[1],ap[2],ap[3],ap[4],ap[5]);
53	if (ap[0] < 10) (void)fprintf(fd, " ");
54	if (ap[1] < 10) (void)fprintf(fd, " ");
55	if (ap[2] < 10) (void)fprintf(fd, " ");
56	if (ap[3] < 10) (void)fprintf(fd, " ");
57	if (ap[4] < 10) (void)fprintf(fd, " ");
58	if (ap[5] < 10) (void)fprintf(fd, " ");
59}
60
61void
62mopPrintBPTY(fd, bpty)
63	FILE	*fd;
64	u_char 	bpty;
65{
66	switch(bpty) {
67	case MOP_K_BPTY_SYS:
68		(void)fprintf(fd, "System Processor");
69		break;
70	case MOP_K_BPTY_COM:
71		(void)fprintf(fd, "Communication Processor");
72		break;
73	default:
74		(void)fprintf(fd, "Unknown");
75		break;
76	};
77};
78
79void
80mopPrintPGTY(fd, pgty)
81	FILE	*fd;
82	u_char 	pgty;
83{
84	switch(pgty) {
85	case MOP_K_PGTY_SECLDR:
86		(void)fprintf(fd, "Secondary Loader");
87		break;
88	case MOP_K_PGTY_TERLDR:
89		(void)fprintf(fd, "Tertiary Loader");
90		break;
91	case MOP_K_PGTY_OPRSYS:
92		(void)fprintf(fd, "Operating System");
93		break;
94	case MOP_K_PGTY_MGNTFL:
95		(void)fprintf(fd, "Management File");
96		break;
97	default:
98		(void)fprintf(fd, "Unknown");
99		break;
100	};
101}
102
103void
104mopPrintOneline(fd, pkt, trans)
105	FILE	*fd;
106	u_char	*pkt;
107	int	 trans;
108{
109	int	 index = 0;
110	u_char	*dst, *src, code;
111	u_short	 proto;
112	int	 len;
113
114	trans = mopGetTrans(pkt, trans);
115	mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans);
116	code = mopGetChar(pkt, &index);
117
118	switch (proto) {
119	case MOP_K_PROTO_DL:
120		(void)fprintf(fd, "MOP DL ");
121		break;
122	case MOP_K_PROTO_RC:
123		(void)fprintf(fd, "MOP RC ");
124		break;
125	case MOP_K_PROTO_LP:
126		(void)fprintf(fd, "MOP LP ");
127		break;
128	default:
129		switch((proto % 256)*256 + (proto / 256)) {
130		case MOP_K_PROTO_DL:
131			(void)fprintf(fd, "MOP DL ");
132			proto = MOP_K_PROTO_DL;
133			break;
134		case MOP_K_PROTO_RC:
135			(void)fprintf(fd, "MOP RC ");
136			proto = MOP_K_PROTO_RC;
137			break;
138		case MOP_K_PROTO_LP:
139			(void)fprintf(fd, "MOP LP ");
140			proto = MOP_K_PROTO_LP;
141			break;
142		default:
143			(void)fprintf(fd, "MOP ?? ");
144			break;
145		}
146	}
147
148	if (trans == TRANS_8023) {
149		(void)fprintf(fd, "802.3 ");
150	}
151
152	mopPrintHWA(fd, src); (void)fprintf(fd," > ");
153	mopPrintHWA(fd, dst);
154	if (len < 1600) {
155        	(void)fprintf(fd, " len %4d code %02x ",len,code);
156	} else {
157		(void)fprintf(fd, " len %4d code %02x ",
158			      (len % 256)*256 + (len /256), code);
159	}
160
161	switch (proto) {
162	case MOP_K_PROTO_DL:
163        	switch (code) {
164		case MOP_K_CODE_MLT:
165			(void)fprintf(fd, "MLT ");
166			break;
167		case MOP_K_CODE_DCM:
168			(void)fprintf(fd, "DCM ");
169			break;
170		case MOP_K_CODE_MLD:
171			(void)fprintf(fd, "MLD ");
172			break;
173		case MOP_K_CODE_ASV:
174			(void)fprintf(fd, "ASV ");
175			break;
176		case MOP_K_CODE_RMD:
177			(void)fprintf(fd, "RMD ");
178			break;
179		case MOP_K_CODE_RPR:
180			(void)fprintf(fd, "RPR ");
181			break;
182		case MOP_K_CODE_RML:
183			(void)fprintf(fd, "RML ");
184			break;
185	        case MOP_K_CODE_RDS:
186			(void)fprintf(fd, "RDS ");
187			break;
188		case MOP_K_CODE_MDD:
189			(void)fprintf(fd, "MDD ");
190			break;
191		case MOP_K_CODE_PLT:
192			(void)fprintf(fd, "PLT ");
193			break;
194	        default:
195			(void)fprintf(fd, "??? ");
196			break;
197		}
198		break;
199	case MOP_K_PROTO_RC:
200		switch (code) {
201		case MOP_K_CODE_RID:
202			(void)fprintf(fd, "RID ");
203			break;
204		case MOP_K_CODE_BOT:
205			(void)fprintf(fd, "BOT ");
206			break;
207		case MOP_K_CODE_SID:
208			(void)fprintf(fd, "SID ");
209			break;
210		case MOP_K_CODE_RQC:
211			(void)fprintf(fd, "RQC ");
212			break;
213		case MOP_K_CODE_CNT:
214			(void)fprintf(fd, "CNT ");
215			break;
216		case MOP_K_CODE_RVC:
217			(void)fprintf(fd, "RVC ");
218			break;
219		case MOP_K_CODE_RLC:
220			(void)fprintf(fd, "RLC ");
221			break;
222		case MOP_K_CODE_CCP:
223			(void)fprintf(fd, "CCP ");
224			break;
225		case MOP_K_CODE_CRA:
226			(void)fprintf(fd, "CRA ");
227			break;
228		default:
229			(void)fprintf(fd, "??? ");
230			break;
231		}
232		break;
233	case MOP_K_PROTO_LP:
234		switch (code) {
235		case MOP_K_CODE_ALD:
236			(void)fprintf(fd, "ALD ");
237			break;
238		case MOP_K_CODE_PLD:
239			(void)fprintf(fd, "PLD ");
240			break;
241		default:
242			(void)fprintf(fd, "??? ");
243			break;
244		}
245		break;
246	default:
247		(void)fprintf(fd, "??? ");
248		break;
249	}
250	(void)fprintf(fd, "\n");
251}
252
253void
254mopPrintHeader(fd, pkt, trans)
255	FILE	*fd;
256	u_char	*pkt;
257	int	 trans;
258{
259	u_char	*dst, *src;
260	u_short	 proto;
261	int	 len, index = 0;
262
263	trans = mopGetTrans(pkt, trans);
264	mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans);
265
266	(void)fprintf(fd,"\nDst          : ");
267	mopPrintHWA(fd, dst);
268	if (mopCmpEAddr(dl_mcst,dst) == 0) {
269		(void)fprintf(fd," MOP Dump/Load Multicast");
270	};
271	if (mopCmpEAddr(rc_mcst,dst) == 0) {
272		(void)fprintf(fd," MOP Remote Console Multicast");
273	};
274	(void)fprintf(fd,"\n");
275
276	(void)fprintf(fd,"Src          : ");
277	mopPrintHWA(fd, src);
278	(void)fprintf(fd,"\n");
279	(void)fprintf(fd,"Proto        : %04x ",proto);
280	switch (proto) {
281	case MOP_K_PROTO_DL:
282		switch (trans) {
283		case TRANS_8023:
284			(void)fprintf(fd, "MOP Dump/Load (802.3)\n");
285			break;
286		default:
287			(void)fprintf(fd, "MOP Dump/Load\n");
288		}
289		break;
290	case MOP_K_PROTO_RC:
291		switch (trans) {
292		case TRANS_8023:
293			(void)fprintf(fd, "MOP Remote Console (802.3)\n");
294			break;
295		default:
296			(void)fprintf(fd, "MOP Remote Console\n");
297		}
298		break;
299	case MOP_K_PROTO_LP:
300		switch (trans) {
301		case TRANS_8023:
302			(void)fprintf(fd, "MOP Loopback (802.3)\n");
303			break;
304		default:
305			(void)fprintf(fd, "MOP Loopback\n");
306		}
307		break;
308	default:
309		(void)fprintf(fd, "\n");
310		break;
311	}
312
313
314        (void)fprintf(fd,"Length       : %04x (%d)\n",len,len);
315}
316
317void
318mopPrintMopHeader(fd, pkt, trans)
319	FILE	*fd;
320	u_char	*pkt;
321	int	 trans;
322{
323	u_char	*dst, *src;
324	u_short	 proto;
325	int	 len, index = 0;
326	u_char   code;
327
328	trans = mopGetTrans(pkt, trans);
329	mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans);
330
331	code = mopGetChar(pkt, &index);
332
333	(void)fprintf(fd, "Code         :   %02x ",code);
334
335	switch (proto) {
336	case MOP_K_PROTO_DL:
337		switch (code) {
338		case MOP_K_CODE_MLT:
339			(void)fprintf(fd,
340				      "Memory Load with transfer address\n");
341			break;
342		case MOP_K_CODE_DCM:
343			(void)fprintf(fd, "Dump Complete\n");
344			break;
345		case MOP_K_CODE_MLD:
346			(void)fprintf(fd, "Memory Load\n");
347			break;
348		case MOP_K_CODE_ASV:
349			(void)fprintf(fd, "Assistance volunteer\n");
350			break;
351		case MOP_K_CODE_RMD:
352			(void)fprintf(fd, "Request memory dump\n");
353			break;
354		case MOP_K_CODE_RPR:
355			(void)fprintf(fd, "Request program\n");
356			break;
357		case MOP_K_CODE_RML:
358			(void)fprintf(fd, "Request memory load\n");
359			break;
360		case MOP_K_CODE_RDS:
361			(void)fprintf(fd, "Request Dump Service\n");
362			break;
363		case MOP_K_CODE_MDD:
364			(void)fprintf(fd, "Memory dump data\n");
365			break;
366		case MOP_K_CODE_PLT:
367			(void)fprintf(fd,
368				      "Parameter load with transfer addres\n");
369			break;
370		default:
371			(void)fprintf(fd, "(unknown)\n");
372			break;
373		}
374		break;
375	case MOP_K_PROTO_RC:
376		switch (code) {
377		case MOP_K_CODE_RID:
378			(void)fprintf(fd, "Request ID\n");
379			break;
380		case MOP_K_CODE_BOT:
381			(void)fprintf(fd, "Boot\n");
382			break;
383		case MOP_K_CODE_SID:
384			(void)fprintf(fd, "System ID\n");
385			break;
386		case MOP_K_CODE_RQC:
387			(void)fprintf(fd, "Request Counters\n");
388			break;
389		case MOP_K_CODE_CNT:
390			(void)fprintf(fd, "Counters\n");
391			break;
392		case MOP_K_CODE_RVC:
393			(void)fprintf(fd, "Reserve Console\n");
394			break;
395		case MOP_K_CODE_RLC:
396			(void)fprintf(fd, "Release Console\n");
397			break;
398		case MOP_K_CODE_CCP:
399			(void)fprintf(fd, "Console Command and Poll\n");
400			break;
401		case MOP_K_CODE_CRA:
402			(void)fprintf(fd,
403				      "Console Response and Acknnowledge\n");
404			break;
405		default:
406			(void)fprintf(fd, "(unknown)\n");
407			break;
408		}
409		break;
410	case MOP_K_PROTO_LP:
411		switch (code) {
412		case MOP_K_CODE_ALD:
413			(void)fprintf(fd, "Active loop data\n");
414			break;
415		case MOP_K_CODE_PLD:
416			(void)fprintf(fd, "Passive looped data\n");
417			break;
418		default:
419			(void)fprintf(fd, "(unknown)\n");
420			break;
421		}
422		break;
423	default:
424		(void)fprintf(fd, "(unknown)\n");
425		break;
426	}
427}
428
429void
430mopPrintDevice(fd, device)
431	FILE	*fd;
432        u_char device;
433{
434	char	*sname, *name;
435
436	sname = nmaGetShort((int) device);
437	name  = nmaGetDevice((int) device);
438
439        (void)fprintf(fd, "%s '%s'",sname,name);
440}
441
442void
443mopPrintTime(fd, ap)
444	FILE	*fd;
445        u_char *ap;
446{
447	(void)fprintf(fd,
448		      "%04d-%02d-%02d %02d:%02d:%02d.%02d %d:%02d",
449		      ap[0]*100 + ap[1],
450		      ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]);
451}
452
453void
454mopPrintInfo(fd, pkt, index, moplen, mopcode, trans)
455	FILE	*fd;
456	u_char  *pkt, mopcode;
457	int     *index, trans;
458	u_short moplen;
459{
460        u_short itype,tmps;
461	u_char  ilen ,tmpc,device;
462	u_char  uc1,uc2,uc3,*ucp;
463	int     i;
464
465	device = 0;
466
467	switch(trans) {
468	case TRANS_ETHER:
469		moplen = moplen + 16;
470		break;
471	case TRANS_8023:
472		moplen = moplen + 14;
473		break;
474	}
475
476	itype = mopGetShort(pkt,index);
477
478	while (*index < (int)(moplen + 2)) {
479		ilen  = mopGetChar(pkt,index);
480		switch (itype) {
481		case 0:
482			tmpc  = mopGetChar(pkt,index);
483			*index = *index + tmpc;
484			break;
485		case MOP_K_INFO_VER:
486			uc1 = mopGetChar(pkt,index);
487			uc2 = mopGetChar(pkt,index);
488			uc3 = mopGetChar(pkt,index);
489			(void)fprintf(fd,"Maint Version: %d.%d.%d\n",
490				      uc1,uc2,uc3);
491			break;
492		case MOP_K_INFO_MFCT:
493			tmps = mopGetShort(pkt,index);
494			(void)fprintf(fd,"Maint Funcion: %04x ( ",tmps);
495			if (tmps &   1) (void)fprintf(fd, "Loop ");
496			if (tmps &   2) (void)fprintf(fd, "Dump ");
497			if (tmps &   4) (void)fprintf(fd, "Pldr ");
498			if (tmps &   8) (void)fprintf(fd, "MLdr ");
499			if (tmps &  16) (void)fprintf(fd, "Boot ");
500			if (tmps &  32) (void)fprintf(fd, "CC ");
501			if (tmps &  64) (void)fprintf(fd, "DLC ");
502			if (tmps & 128) (void)fprintf(fd, "CCR ");
503			(void)fprintf(fd, ")\n");
504			break;
505		case MOP_K_INFO_CNU:
506			ucp = pkt + *index; *index = *index + 6;
507			(void)fprintf(fd,"Console User : ");
508			mopPrintHWA(fd, ucp);
509			(void)fprintf(fd, "\n");
510			break;
511		case MOP_K_INFO_RTM:
512			tmps = mopGetShort(pkt,index);
513			(void)fprintf(fd,"Reserv Timer : %04x (%d)\n",
514				      tmps,tmps);
515			break;
516		case MOP_K_INFO_CSZ:
517			tmps = mopGetShort(pkt,index);
518			(void)fprintf(fd,"Cons Cmd Size: %04x (%d)\n",
519				      tmps,tmps);
520			break;
521		case MOP_K_INFO_RSZ:
522			tmps = mopGetShort(pkt,index);
523			(void)fprintf(fd,"Cons Res Size: %04x (%d)\n",
524				      tmps,tmps);
525			break;
526		case MOP_K_INFO_HWA:
527			ucp = pkt + *index; *index = *index + 6;
528			(void)fprintf(fd,"Hardware Addr: ");
529			mopPrintHWA(fd, ucp);
530			(void)fprintf(fd, "\n");
531			break;
532		case MOP_K_INFO_TIME:
533			ucp = pkt + *index; *index = *index + 10;
534			(void)fprintf(fd,"System Time: ");
535			mopPrintTime(fd, ucp);
536			(void)fprintf(fd,"\n");
537			break;
538		case MOP_K_INFO_SOFD:
539			device = mopGetChar(pkt,index);
540			(void)fprintf(fd,"Comm Device  :   %02x ",device);
541			mopPrintDevice(fd, device);
542			(void)fprintf(fd, "\n");
543			break;
544		case MOP_K_INFO_SFID:
545			tmpc = mopGetChar(pkt,index);
546			(void)fprintf(fd,"Software ID  :   %02x ",tmpc);
547			if ((tmpc == 0)) {
548				(void)fprintf(fd,"No software id");
549			}
550			if ((tmpc == 254)) {
551				(void)fprintf(fd,"Maintenance system");
552				tmpc = 0;
553			}
554			if ((tmpc == 255)) {
555				(void)fprintf(fd,"Standard operating system");
556				tmpc = 0;
557			}
558			if ((tmpc > 0)) {
559				(void)fprintf(fd,"'");
560				for (i = 0; i < ((int) tmpc); i++) {
561					(void)fprintf(fd,"%c",
562						     mopGetChar(pkt,index));
563				}
564				(void)fprintf(fd,"'");
565			}
566			(void)fprintf(fd,"\n");
567			break;
568		case MOP_K_INFO_PRTY:
569			tmpc = mopGetChar(pkt,index);
570			(void)fprintf(fd,"System Proc  :   %02x ",tmpc);
571			switch (tmpc) {
572			case MOP_K_PRTY_11:
573				(void)fprintf(fd, "PDP-11\n");
574				break;
575			case MOP_K_PRTY_CMSV:
576				(void)fprintf(fd,
577					      "Communication Server\n");
578				break;
579			case MOP_K_PRTY_PRO:
580				(void)fprintf(fd, "Professional\n");
581				break;
582			case MOP_K_PRTY_SCO:
583				(void)fprintf(fd, "Scorpio\n");
584				break;
585			case MOP_K_PRTY_AMB:
586				(void)fprintf(fd, "Amber\n");
587				break;
588			case MOP_K_PRTY_BRI:
589				(void)fprintf(fd, "XLII Bridge\n");
590				break;
591			default:
592				(void)fprintf(fd, "Unknown\n");
593				break;
594			};
595			break;
596		case MOP_K_INFO_DLTY:
597			tmpc = mopGetChar(pkt,index);
598			(void)fprintf(fd,"Data Link Typ:   %02x ",tmpc);
599			switch (tmpc) {
600			case MOP_K_DLTY_NI:
601				(void)fprintf(fd, "Ethernet\n");
602				break;
603			case MOP_K_DLTY_DDCMP:
604				(void)fprintf(fd, "DDCMP\n");
605				break;
606			case MOP_K_DLTY_LAPB:
607				(void)fprintf(fd, "LAPB (X.25)\n");
608				break;
609			default:
610				(void)fprintf(fd, "Unknown\n");
611				break;
612			};
613			break;
614		case MOP_K_INFO_DLBSZ:
615			tmps = mopGetShort(pkt,index);
616			(void)fprintf(fd,"DL Buff Size : %04x (%d)\n",
617				      tmps,tmps);
618			break;
619		default:
620			if (((device = NMA_C_SOFD_LCS) ||   /* DECserver 100 */
621			     (device = NMA_C_SOFD_DS2) ||   /* DECserver 200 */
622			     (device = NMA_C_SOFD_DP2) ||   /* DECserver 250 */
623			     (device = NMA_C_SOFD_DS3)) &&  /* DECserver 300 */
624			    ((itype > 101) && (itype < 107)))
625			{
626		        	switch (itype) {
627				case 102:
628					ucp = pkt + *index;
629					*index = *index + ilen;
630					(void)fprintf(fd,
631						     "ROM Sftwr Ver:   %02x '",
632						      ilen);
633					for (i = 0; i < ilen; i++) {
634						(void)fprintf(fd,"%c",ucp[i]);
635					}
636					(void)fprintf(fd, "'\n");
637					break;
638				case 103:
639					ucp = pkt + *index;
640					*index = *index + ilen;
641					(void)fprintf(fd,
642						     "Software Ver :   %02x '",
643						      ilen);
644					for (i = 0; i < ilen; i++) {
645						(void)fprintf(fd, "%c",ucp[i]);
646					}
647					(void)fprintf(fd, "'\n");
648					break;
649				case 104:
650					tmps = mopGetShort(pkt,index);
651					(void)fprintf(fd,
652						"DECnet Addr  : %d.%d (%d)\n",
653						      tmps / 1024,
654						      tmps % 1024,
655						      tmps);
656					break;
657				case 105:
658					ucp = pkt + *index;
659					*index = *index + ilen;
660					(void)fprintf(fd,
661						     "Node Name    :   %02x '",
662						      ilen);
663					for (i = 0; i < ilen; i++) {
664						(void)fprintf(fd, "%c",ucp[i]);
665					}
666					(void)fprintf(fd, "'\n");
667					break;
668				case 106:
669					ucp = pkt + *index;
670					*index = *index + ilen;
671					(void)fprintf(fd,
672						     "Node Ident   :   %02x '",
673						      ilen);
674					for (i = 0; i < ilen; i++) {
675						(void)fprintf(fd, "%c",ucp[i]);
676					}
677					(void)fprintf(fd, "'\n");
678					break;
679				};
680			} else {
681				ucp = pkt + *index; *index = *index + ilen;
682				(void)fprintf(fd, "Info Type    : %04x (%d)\n",
683					      itype,
684					      itype);
685				(void)fprintf(fd, "Info Data    :   %02x ",
686					      ilen);
687				for (i = 0; i < ilen; i++) {
688					if ((i % 16) == 0) {
689						if ((i / 16) == 0) {
690						} else {
691							(void)fprintf(fd,
692						     "\n                    ");
693						};
694					};
695					(void)fprintf(fd, "%02x ",ucp[i]);
696				}
697				(void)fprintf(fd, "\n");
698			};
699		}
700		itype = mopGetShort(pkt,index);
701        }
702}
703
704