Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / mopd / common / print.c
blobc640e6fccb785f39919f66a86336cf54c7b23c2b
1 /* $NetBSD: print.c,v 1.5 2009/10/20 00:51:13 snj Exp $ */
3 /*
4 * Copyright (c) 1993-96 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: print.c,v 1.5 2009/10/20 00:51:13 snj Exp $");
30 #endif
32 #include <sys/types.h>
33 #include <stdio.h>
35 #include "os.h"
36 #include "cmp.h"
37 #include "get.h"
38 #include "mopdef.h"
39 #include "nma.h"
40 #include "nmadef.h"
41 #include "print.h"
43 #define SHORT_PRINT
45 void
46 mopPrintHWA(FILE *fd, const u_char *ap)
48 (void)fprintf(fd, "%x:%x:%x:%x:%x:%x",
49 ap[0],ap[1],ap[2],ap[3],ap[4],ap[5]);
50 if (ap[0] < 10) (void)fprintf(fd, " ");
51 if (ap[1] < 10) (void)fprintf(fd, " ");
52 if (ap[2] < 10) (void)fprintf(fd, " ");
53 if (ap[3] < 10) (void)fprintf(fd, " ");
54 if (ap[4] < 10) (void)fprintf(fd, " ");
55 if (ap[5] < 10) (void)fprintf(fd, " ");
58 void
59 mopPrintBPTY(FILE *fd, u_char bpty)
61 switch(bpty) {
62 case MOP_K_BPTY_SYS:
63 (void)fprintf(fd, "System Processor");
64 break;
65 case MOP_K_BPTY_COM:
66 (void)fprintf(fd, "Communication Processor");
67 break;
68 default:
69 (void)fprintf(fd, "Unknown");
70 break;
74 void
75 mopPrintPGTY(FILE *fd, u_char pgty)
77 switch(pgty) {
78 case MOP_K_PGTY_SECLDR:
79 (void)fprintf(fd, "Secondary Loader");
80 break;
81 case MOP_K_PGTY_TERLDR:
82 (void)fprintf(fd, "Tertiary Loader");
83 break;
84 case MOP_K_PGTY_OPRSYS:
85 (void)fprintf(fd, "Operating System");
86 break;
87 case MOP_K_PGTY_MGNTFL:
88 (void)fprintf(fd, "Management File");
89 break;
90 default:
91 (void)fprintf(fd, "Unknown");
92 break;
96 void
97 mopPrintOneline(FILE *fd, const u_char *pkt, int trans)
99 int idx = 0;
100 const u_char *dst, *src;
101 u_char code;
102 u_short proto;
103 int len;
105 trans = mopGetTrans(pkt, trans);
106 mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);
107 code = mopGetChar(pkt, &idx);
109 switch (proto) {
110 case MOP_K_PROTO_DL:
111 (void)fprintf(fd, "MOP DL ");
112 break;
113 case MOP_K_PROTO_RC:
114 (void)fprintf(fd, "MOP RC ");
115 break;
116 case MOP_K_PROTO_LP:
117 (void)fprintf(fd, "MOP LP ");
118 break;
119 default:
120 switch((proto % 256)*256 + (proto / 256)) {
121 case MOP_K_PROTO_DL:
122 (void)fprintf(fd, "MOP DL ");
123 proto = MOP_K_PROTO_DL;
124 break;
125 case MOP_K_PROTO_RC:
126 (void)fprintf(fd, "MOP RC ");
127 proto = MOP_K_PROTO_RC;
128 break;
129 case MOP_K_PROTO_LP:
130 (void)fprintf(fd, "MOP LP ");
131 proto = MOP_K_PROTO_LP;
132 break;
133 default:
134 (void)fprintf(fd, "MOP ?? ");
135 break;
139 if (trans == TRANS_8023) {
140 (void)fprintf(fd, "802.3 ");
143 mopPrintHWA(fd, src); (void)fprintf(fd," > ");
144 mopPrintHWA(fd, dst);
145 if (len < 1600) {
146 (void)fprintf(fd, " len %4d code %02x ",len,code);
147 } else {
148 (void)fprintf(fd, " len %4d code %02x ",
149 (len % 256)*256 + (len /256), code);
152 switch (proto) {
153 case MOP_K_PROTO_DL:
154 switch (code) {
155 case MOP_K_CODE_MLT:
156 (void)fprintf(fd, "MLT ");
157 break;
158 case MOP_K_CODE_DCM:
159 (void)fprintf(fd, "DCM ");
160 break;
161 case MOP_K_CODE_MLD:
162 (void)fprintf(fd, "MLD ");
163 break;
164 case MOP_K_CODE_ASV:
165 (void)fprintf(fd, "ASV ");
166 break;
167 case MOP_K_CODE_RMD:
168 (void)fprintf(fd, "RMD ");
169 break;
170 case MOP_K_CODE_RPR:
171 (void)fprintf(fd, "RPR ");
172 break;
173 case MOP_K_CODE_RML:
174 (void)fprintf(fd, "RML ");
175 break;
176 case MOP_K_CODE_RDS:
177 (void)fprintf(fd, "RDS ");
178 break;
179 case MOP_K_CODE_MDD:
180 (void)fprintf(fd, "MDD ");
181 break;
182 case MOP_K_CODE_PLT:
183 (void)fprintf(fd, "PLT ");
184 break;
185 default:
186 (void)fprintf(fd, "??? ");
187 break;
189 break;
190 case MOP_K_PROTO_RC:
191 switch (code) {
192 case MOP_K_CODE_RID:
193 (void)fprintf(fd, "RID ");
194 break;
195 case MOP_K_CODE_BOT:
196 (void)fprintf(fd, "BOT ");
197 break;
198 case MOP_K_CODE_SID:
199 (void)fprintf(fd, "SID ");
200 break;
201 case MOP_K_CODE_RQC:
202 (void)fprintf(fd, "RQC ");
203 break;
204 case MOP_K_CODE_CNT:
205 (void)fprintf(fd, "CNT ");
206 break;
207 case MOP_K_CODE_RVC:
208 (void)fprintf(fd, "RVC ");
209 break;
210 case MOP_K_CODE_RLC:
211 (void)fprintf(fd, "RLC ");
212 break;
213 case MOP_K_CODE_CCP:
214 (void)fprintf(fd, "CCP ");
215 break;
216 case MOP_K_CODE_CRA:
217 (void)fprintf(fd, "CRA ");
218 break;
219 default:
220 (void)fprintf(fd, "??? ");
221 break;
223 break;
224 case MOP_K_PROTO_LP:
225 switch (code) {
226 case MOP_K_CODE_ALD:
227 (void)fprintf(fd, "ALD ");
228 break;
229 case MOP_K_CODE_PLD:
230 (void)fprintf(fd, "PLD ");
231 break;
232 default:
233 (void)fprintf(fd, "??? ");
234 break;
236 break;
237 default:
238 (void)fprintf(fd, "??? ");
239 break;
241 (void)fprintf(fd, "\n");
244 void
245 mopPrintHeader(FILE *fd, const u_char *pkt, int trans)
247 const u_char *dst, *src;
248 u_short proto;
249 int len, idx = 0;
251 trans = mopGetTrans(pkt, trans);
252 mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);
254 (void)fprintf(fd,"\nDst : ");
255 mopPrintHWA(fd, dst);
256 if (mopCmpEAddr(dl_mcst,dst) == 0) {
257 (void)fprintf(fd," MOP Dump/Load Multicast");
259 if (mopCmpEAddr(rc_mcst,dst) == 0) {
260 (void)fprintf(fd," MOP Remote Console Multicast");
262 (void)fprintf(fd,"\n");
264 (void)fprintf(fd,"Src : ");
265 mopPrintHWA(fd, src);
266 (void)fprintf(fd,"\n");
267 (void)fprintf(fd,"Proto : %04x ",proto);
268 switch (proto) {
269 case MOP_K_PROTO_DL:
270 switch (trans) {
271 case TRANS_8023:
272 (void)fprintf(fd, "MOP Dump/Load (802.3)\n");
273 break;
274 default:
275 (void)fprintf(fd, "MOP Dump/Load\n");
277 break;
278 case MOP_K_PROTO_RC:
279 switch (trans) {
280 case TRANS_8023:
281 (void)fprintf(fd, "MOP Remote Console (802.3)\n");
282 break;
283 default:
284 (void)fprintf(fd, "MOP Remote Console\n");
286 break;
287 case MOP_K_PROTO_LP:
288 switch (trans) {
289 case TRANS_8023:
290 (void)fprintf(fd, "MOP Loopback (802.3)\n");
291 break;
292 default:
293 (void)fprintf(fd, "MOP Loopback\n");
295 break;
296 default:
297 (void)fprintf(fd, "\n");
298 break;
302 (void)fprintf(fd,"Length : %04x (%d)\n",len,len);
305 void
306 mopPrintMopHeader(FILE *fd, const u_char *pkt, int trans)
308 const u_char *dst, *src;
309 u_short proto;
310 int len, idx = 0;
311 u_char code;
313 trans = mopGetTrans(pkt, trans);
314 mopGetHeader(pkt, &idx, &dst, &src, &proto, &len, trans);
316 code = mopGetChar(pkt, &idx);
318 (void)fprintf(fd, "Code : %02x ",code);
320 switch (proto) {
321 case MOP_K_PROTO_DL:
322 switch (code) {
323 case MOP_K_CODE_MLT:
324 (void)fprintf(fd,
325 "Memory Load with transfer address\n");
326 break;
327 case MOP_K_CODE_DCM:
328 (void)fprintf(fd, "Dump Complete\n");
329 break;
330 case MOP_K_CODE_MLD:
331 (void)fprintf(fd, "Memory Load\n");
332 break;
333 case MOP_K_CODE_ASV:
334 (void)fprintf(fd, "Assistance volunteer\n");
335 break;
336 case MOP_K_CODE_RMD:
337 (void)fprintf(fd, "Request memory dump\n");
338 break;
339 case MOP_K_CODE_RPR:
340 (void)fprintf(fd, "Request program\n");
341 break;
342 case MOP_K_CODE_RML:
343 (void)fprintf(fd, "Request memory load\n");
344 break;
345 case MOP_K_CODE_RDS:
346 (void)fprintf(fd, "Request Dump Service\n");
347 break;
348 case MOP_K_CODE_MDD:
349 (void)fprintf(fd, "Memory dump data\n");
350 break;
351 case MOP_K_CODE_PLT:
352 (void)fprintf(fd,
353 "Parameter load with transfer addres\n");
354 break;
355 default:
356 (void)fprintf(fd, "(unknown)\n");
357 break;
359 break;
360 case MOP_K_PROTO_RC:
361 switch (code) {
362 case MOP_K_CODE_RID:
363 (void)fprintf(fd, "Request ID\n");
364 break;
365 case MOP_K_CODE_BOT:
366 (void)fprintf(fd, "Boot\n");
367 break;
368 case MOP_K_CODE_SID:
369 (void)fprintf(fd, "System ID\n");
370 break;
371 case MOP_K_CODE_RQC:
372 (void)fprintf(fd, "Request Counters\n");
373 break;
374 case MOP_K_CODE_CNT:
375 (void)fprintf(fd, "Counters\n");
376 break;
377 case MOP_K_CODE_RVC:
378 (void)fprintf(fd, "Reserve Console\n");
379 break;
380 case MOP_K_CODE_RLC:
381 (void)fprintf(fd, "Release Console\n");
382 break;
383 case MOP_K_CODE_CCP:
384 (void)fprintf(fd, "Console Command and Poll\n");
385 break;
386 case MOP_K_CODE_CRA:
387 (void)fprintf(fd,
388 "Console Response and Acknnowledge\n");
389 break;
390 default:
391 (void)fprintf(fd, "(unknown)\n");
392 break;
394 break;
395 case MOP_K_PROTO_LP:
396 switch (code) {
397 case MOP_K_CODE_ALD:
398 (void)fprintf(fd, "Active loop data\n");
399 break;
400 case MOP_K_CODE_PLD:
401 (void)fprintf(fd, "Passive looped data\n");
402 break;
403 default:
404 (void)fprintf(fd, "(unknown)\n");
405 break;
407 break;
408 default:
409 (void)fprintf(fd, "(unknown)\n");
410 break;
414 void
415 mopPrintDevice(FILE *fd, u_char device)
417 const char *sname, *name;
419 sname = nmaGetShort((int) device);
420 name = nmaGetDevice((int) device);
422 (void)fprintf(fd, "%s '%s'",sname,name);
425 void
426 mopPrintTime(FILE *fd, const u_char *ap)
428 (void)fprintf(fd,
429 "%04d-%02d-%02d %02d:%02d:%02d.%02d %d:%02d",
430 ap[0]*100 + ap[1],
431 ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]);
434 void
435 mopPrintInfo(FILE *fd, const u_char *pkt, int *idx,
436 u_short moplen, u_char mopcode, int trans)
438 u_short itype,tmps;
439 u_char ilen ,tmpc,device;
440 u_char uc1,uc2,uc3;
441 const u_char *ucp;
442 int i;
444 device = 0;
446 switch(trans) {
447 case TRANS_ETHER:
448 moplen = moplen + 16;
449 break;
450 case TRANS_8023:
451 moplen = moplen + 14;
452 break;
455 itype = mopGetShort(pkt,idx);
457 while (*idx < (int)(moplen + 2)) {
458 ilen = mopGetChar(pkt,idx);
459 switch (itype) {
460 case 0:
461 tmpc = mopGetChar(pkt,idx);
462 *idx = *idx + tmpc;
463 break;
464 case MOP_K_INFO_VER:
465 uc1 = mopGetChar(pkt,idx);
466 uc2 = mopGetChar(pkt,idx);
467 uc3 = mopGetChar(pkt,idx);
468 (void)fprintf(fd,"Maint Version: %d.%d.%d\n",
469 uc1,uc2,uc3);
470 break;
471 case MOP_K_INFO_MFCT:
472 tmps = mopGetShort(pkt,idx);
473 (void)fprintf(fd,"Maint Funcion: %04x ( ",tmps);
474 if (tmps & 1) (void)fprintf(fd, "Loop ");
475 if (tmps & 2) (void)fprintf(fd, "Dump ");
476 if (tmps & 4) (void)fprintf(fd, "Pldr ");
477 if (tmps & 8) (void)fprintf(fd, "MLdr ");
478 if (tmps & 16) (void)fprintf(fd, "Boot ");
479 if (tmps & 32) (void)fprintf(fd, "CC ");
480 if (tmps & 64) (void)fprintf(fd, "DLC ");
481 if (tmps & 128) (void)fprintf(fd, "CCR ");
482 (void)fprintf(fd, ")\n");
483 break;
484 case MOP_K_INFO_CNU:
485 ucp = pkt + *idx; *idx = *idx + 6;
486 (void)fprintf(fd,"Console User : ");
487 mopPrintHWA(fd, ucp);
488 (void)fprintf(fd, "\n");
489 break;
490 case MOP_K_INFO_RTM:
491 tmps = mopGetShort(pkt,idx);
492 (void)fprintf(fd,"Reserv Timer : %04x (%d)\n",
493 tmps,tmps);
494 break;
495 case MOP_K_INFO_CSZ:
496 tmps = mopGetShort(pkt,idx);
497 (void)fprintf(fd,"Cons Cmd Size: %04x (%d)\n",
498 tmps,tmps);
499 break;
500 case MOP_K_INFO_RSZ:
501 tmps = mopGetShort(pkt,idx);
502 (void)fprintf(fd,"Cons Res Size: %04x (%d)\n",
503 tmps,tmps);
504 break;
505 case MOP_K_INFO_HWA:
506 ucp = pkt + *idx; *idx = *idx + 6;
507 (void)fprintf(fd,"Hardware Addr: ");
508 mopPrintHWA(fd, ucp);
509 (void)fprintf(fd, "\n");
510 break;
511 case MOP_K_INFO_TIME:
512 ucp = pkt + *idx; *idx = *idx + 10;
513 (void)fprintf(fd,"System Time: ");
514 mopPrintTime(fd, ucp);
515 (void)fprintf(fd,"\n");
516 break;
517 case MOP_K_INFO_SOFD:
518 device = mopGetChar(pkt,idx);
519 (void)fprintf(fd,"Comm Device : %02x ",device);
520 mopPrintDevice(fd, device);
521 (void)fprintf(fd, "\n");
522 break;
523 case MOP_K_INFO_SFID:
524 tmpc = mopGetChar(pkt,idx);
525 (void)fprintf(fd,"Software ID : %02x ",tmpc);
526 if ((tmpc == 0)) {
527 (void)fprintf(fd,"No software id");
529 if ((tmpc == 254)) {
530 (void)fprintf(fd,"Maintenance system");
531 tmpc = 0;
533 if ((tmpc == 255)) {
534 (void)fprintf(fd,"Standard operating system");
535 tmpc = 0;
537 if ((tmpc > 0)) {
538 (void)fprintf(fd,"'");
539 for (i = 0; i < ((int) tmpc); i++) {
540 (void)fprintf(fd,"%c",
541 mopGetChar(pkt,idx));
543 (void)fprintf(fd,"'");
545 (void)fprintf(fd,"\n");
546 break;
547 case MOP_K_INFO_PRTY:
548 tmpc = mopGetChar(pkt,idx);
549 (void)fprintf(fd,"System Proc : %02x ",tmpc);
550 switch (tmpc) {
551 case MOP_K_PRTY_11:
552 (void)fprintf(fd, "PDP-11\n");
553 break;
554 case MOP_K_PRTY_CMSV:
555 (void)fprintf(fd,
556 "Communication Server\n");
557 break;
558 case MOP_K_PRTY_PRO:
559 (void)fprintf(fd, "Professional\n");
560 break;
561 case MOP_K_PRTY_SCO:
562 (void)fprintf(fd, "Scorpio\n");
563 break;
564 case MOP_K_PRTY_AMB:
565 (void)fprintf(fd, "Amber\n");
566 break;
567 case MOP_K_PRTY_BRI:
568 (void)fprintf(fd, "XLII Bridge\n");
569 break;
570 default:
571 (void)fprintf(fd, "Unknown\n");
572 break;
574 break;
575 case MOP_K_INFO_DLTY:
576 tmpc = mopGetChar(pkt,idx);
577 (void)fprintf(fd,"Data Link Typ: %02x ",tmpc);
578 switch (tmpc) {
579 case MOP_K_DLTY_NI:
580 (void)fprintf(fd, "Ethernet\n");
581 break;
582 case MOP_K_DLTY_DDCMP:
583 (void)fprintf(fd, "DDCMP\n");
584 break;
585 case MOP_K_DLTY_LAPB:
586 (void)fprintf(fd, "LAPB (X.25)\n");
587 break;
588 default:
589 (void)fprintf(fd, "Unknown\n");
590 break;
592 break;
593 case MOP_K_INFO_DLBSZ:
594 tmps = mopGetShort(pkt,idx);
595 (void)fprintf(fd,"DL Buff Size : %04x (%d)\n",
596 tmps,tmps);
597 break;
598 default:
599 if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */
600 (device = NMA_C_SOFD_DS2) || /* DECserver 200 */
601 (device = NMA_C_SOFD_DP2) || /* DECserver 250 */
602 (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */
603 ((itype > 101) && (itype < 107)))
605 switch (itype) {
606 case 102:
607 ucp = pkt + *idx;
608 *idx = *idx + ilen;
609 (void)fprintf(fd,
610 "ROM Sftwr Ver: %02x '",
611 ilen);
612 for (i = 0; i < ilen; i++) {
613 (void)fprintf(fd,"%c",ucp[i]);
615 (void)fprintf(fd, "'\n");
616 break;
617 case 103:
618 ucp = pkt + *idx;
619 *idx = *idx + ilen;
620 (void)fprintf(fd,
621 "Software Ver : %02x '",
622 ilen);
623 for (i = 0; i < ilen; i++) {
624 (void)fprintf(fd, "%c",ucp[i]);
626 (void)fprintf(fd, "'\n");
627 break;
628 case 104:
629 tmps = mopGetShort(pkt,idx);
630 (void)fprintf(fd,
631 "DECnet Addr : %d.%d (%d)\n",
632 tmps / 1024,
633 tmps % 1024,
634 tmps);
635 break;
636 case 105:
637 ucp = pkt + *idx;
638 *idx = *idx + ilen;
639 (void)fprintf(fd,
640 "Node Name : %02x '",
641 ilen);
642 for (i = 0; i < ilen; i++) {
643 (void)fprintf(fd, "%c",ucp[i]);
645 (void)fprintf(fd, "'\n");
646 break;
647 case 106:
648 ucp = pkt + *idx;
649 *idx = *idx + ilen;
650 (void)fprintf(fd,
651 "Node Ident : %02x '",
652 ilen);
653 for (i = 0; i < ilen; i++) {
654 (void)fprintf(fd, "%c",ucp[i]);
656 (void)fprintf(fd, "'\n");
657 break;
659 } else {
660 ucp = pkt + *idx; *idx = *idx + ilen;
661 (void)fprintf(fd, "Info Type : %04x (%d)\n",
662 itype,
663 itype);
664 (void)fprintf(fd, "Info Data : %02x ",
665 ilen);
666 for (i = 0; i < ilen; i++) {
667 if ((i % 16) == 0) {
668 if ((i / 16) == 0) {
669 } else {
670 (void)fprintf(fd,
671 "\n ");
674 (void)fprintf(fd, "%02x ",ucp[i]);
676 (void)fprintf(fd, "\n");
679 itype = mopGetShort(pkt,idx);