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