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