1 /* $OpenBSD: dl.c,v 1.8 2009/10/27 23:59:52 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1993-95 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 #include "os.h" 28 #include "common/get.h" 29 #include "common/print.h" 30 #include "common/mopdef.h" 31 32 void 33 mopDumpDL(FILE *fd, u_char *pkt, int trans) 34 { 35 int i, idx = 0; 36 long tmpl; 37 u_char tmpc, c, program[17], code, *ucp; 38 u_short len, tmps, moplen; 39 40 len = mopGetLength(pkt, trans); 41 42 switch (trans) { 43 case TRANS_8023: 44 idx = 22; 45 moplen = len - 8; 46 break; 47 default: 48 idx = 16; 49 moplen = len; 50 } 51 code = mopGetChar(pkt, &idx); 52 53 switch (code) { 54 case MOP_K_CODE_MLT: 55 tmpc = mopGetChar(pkt, &idx); /* Load Number */ 56 fprintf(fd, "Load Number : %02x\n", tmpc); 57 58 if (moplen > 6) { 59 tmpl = mopGetLong(pkt, &idx);/* Load Address */ 60 fprintf(fd, "Load Address : %08lx\n", tmpl); 61 } 62 63 if (moplen > 10) { 64 for (i = 0; i < (moplen - 10); i++) { 65 if ((i % 16) == 0) { 66 if ((i / 16) == 0) 67 fprintf(fd, 68 "Image Data : %04x ", 69 moplen-10); 70 else 71 fprintf(fd, 72 " "); 73 } 74 75 fprintf(fd, "%02x ", mopGetChar(pkt, &idx)); 76 if ((i % 16) == 15) 77 fprintf(fd, "\n"); 78 } 79 80 if ((i % 16) != 15) 81 fprintf(fd, "\n"); 82 } 83 84 tmpl = mopGetLong(pkt, &idx); /* Load Address */ 85 fprintf(fd, "Xfer Address : %08lx\n", tmpl); 86 break; 87 case MOP_K_CODE_DCM: 88 /* Empty Message */ 89 break; 90 case MOP_K_CODE_MLD: 91 tmpc = mopGetChar(pkt, &idx); /* Load Number */ 92 fprintf(fd, "Load Number : %02x\n", tmpc); 93 94 tmpl = mopGetLong(pkt, &idx); /* Load Address */ 95 fprintf(fd, "Load Address : %08lx\n", tmpl); 96 97 if (moplen > 6) { 98 for (i = 0; i < (moplen - 6); i++) { 99 if ((i % 16) == 0) 100 if ((i / 16) == 0) 101 fprintf(fd, 102 "Image Data : %04x ", 103 moplen-6); 104 else 105 fprintf(fd, 106 " "); 107 108 fprintf(fd, "%02x ", mopGetChar(pkt, &idx)); 109 if ((i % 16) == 15) 110 fprintf(fd, "\n"); 111 } 112 113 if ((i % 16) != 15) 114 fprintf(fd, "\n"); 115 } 116 break; 117 case MOP_K_CODE_ASV: 118 /* Empty Message */ 119 break; 120 case MOP_K_CODE_RMD: 121 tmpl = mopGetLong(pkt, &idx); /* Memory Address */ 122 fprintf(fd, "Mem Address : %08lx\n", tmpl); 123 tmps = mopGetShort(pkt, &idx); /* Count */ 124 fprintf(fd, "Count : %04x (%d)\n", tmps, tmps); 125 break; 126 case MOP_K_CODE_RPR: 127 tmpc = mopGetChar(pkt, &idx); /* Device Type */ 128 fprintf(fd, "Device Type : %02x ", tmpc); 129 mopPrintDevice(fd, tmpc); 130 fprintf(fd, "\n"); 131 132 tmpc = mopGetChar(pkt, &idx); /* Format Version */ 133 fprintf(fd, "Format : %02x\n", tmpc); 134 135 tmpc = mopGetChar(pkt, &idx); /* Program Type */ 136 fprintf(fd, "Program Type : %02x ", tmpc); 137 mopPrintPGTY(fd, tmpc); 138 fprintf(fd, "\n"); 139 140 program[0] = 0; 141 tmpc = mopGetChar(pkt, &idx); /* Software ID Len */ 142 for (i = 0; i < tmpc; i++) { 143 program[i] = mopGetChar(pkt, &idx); 144 program[i + 1] = '\0'; 145 } 146 147 fprintf(fd, "Software : %02x '%s'\n", tmpc, program); 148 149 tmpc = mopGetChar(pkt, &idx); /* Processor */ 150 fprintf(fd, "Processor : %02x ", tmpc); 151 mopPrintBPTY(fd, tmpc); 152 fprintf(fd, "\n"); 153 154 mopPrintInfo(fd, pkt, &idx, moplen, code, trans); 155 156 break; 157 case MOP_K_CODE_RML: 158 159 tmpc = mopGetChar(pkt, &idx); /* Load Number */ 160 fprintf(fd, "Load Number : %02x\n", tmpc); 161 162 tmpc = mopGetChar(pkt, &idx); /* Error */ 163 fprintf(fd, "Error : %02x (", tmpc); 164 if ((tmpc == 0)) 165 fprintf(fd, "no error)\n"); 166 else 167 fprintf(fd, "error)\n"); 168 169 break; 170 case MOP_K_CODE_RDS: 171 172 tmpc = mopGetChar(pkt, &idx); /* Device Type */ 173 fprintf(fd, "Device Type : %02x ", tmpc); 174 mopPrintDevice(fd, tmpc); 175 fprintf(fd, "\n"); 176 177 tmpc = mopGetChar(pkt, &idx); /* Format Version */ 178 fprintf(fd, "Format : %02x\n", tmpc); 179 180 tmpl = mopGetLong(pkt, &idx); /* Memory Size */ 181 fprintf(fd, "Memory Size : %08lx\n", tmpl); 182 183 tmpc = mopGetChar(pkt, &idx); /* Bits */ 184 fprintf(fd, "Bits : %02x\n", tmpc); 185 186 mopPrintInfo(fd, pkt, &idx, moplen, code, trans); 187 188 break; 189 case MOP_K_CODE_MDD: 190 191 tmpl = mopGetLong(pkt, &idx); /* Memory Address */ 192 fprintf(fd, "Mem Address : %08lx\n", tmpl); 193 194 if (moplen > 5) { 195 for (i = 0; i < (moplen - 5); i++) { 196 if ((i % 16) == 0) { 197 if ((i / 16) == 0) 198 fprintf(fd, 199 "Image Data : %04x ", 200 moplen-5); 201 else 202 fprintf(fd, 203 " "); 204 } 205 fprintf(fd, "%02x ", mopGetChar(pkt, &idx)); 206 if ((i % 16) == 15) 207 fprintf(fd, "\n"); 208 } 209 if ((i % 16) != 15) 210 fprintf(fd, "\n"); 211 } 212 213 break; 214 case MOP_K_CODE_PLT: 215 216 tmpc = mopGetChar(pkt, &idx); /* Load Number */ 217 fprintf(fd, "Load Number : %02x\n", tmpc); 218 219 tmpc = mopGetChar(pkt, &idx); /* Parameter Type */ 220 while (tmpc != MOP_K_PLTP_END) { 221 c = mopGetChar(pkt, &idx); /* Parameter Length */ 222 switch (tmpc) { 223 case MOP_K_PLTP_TSN: /* Target Name */ 224 fprintf(fd, "Target Name : %02x '", c); 225 for (i = 0; i < c; i++) 226 fprintf(fd, "%c", 227 mopGetChar(pkt, &idx)); 228 fprintf(fd, "'\n"); 229 break; 230 case MOP_K_PLTP_TSA: /* Target Address */ 231 fprintf(fd, "Target Addr : %02x ", c); 232 for (i = 0; i < c; i++) 233 fprintf(fd, "%02x ", 234 mopGetChar(pkt, &idx)); 235 fprintf(fd, "\n"); 236 break; 237 case MOP_K_PLTP_HSN: /* Host Name */ 238 fprintf(fd, "Host Name : %02x '", c); 239 for (i = 0; i < c; i++) 240 fprintf(fd, "%c", 241 mopGetChar(pkt, &idx)); 242 fprintf(fd, "'\n"); 243 break; 244 case MOP_K_PLTP_HSA: /* Host Address */ 245 fprintf(fd, "Host Addr : %02x ", c); 246 for (i = 0; i < c; i++) 247 fprintf(fd, "%02x ", 248 mopGetChar(pkt, &idx)); 249 fprintf(fd, "\n"); 250 break; 251 case MOP_K_PLTP_HST: /* Host Time */ 252 ucp = pkt + idx; idx = idx + 10; 253 fprintf(fd, "Host Time : "); 254 mopPrintTime(fd, ucp); 255 fprintf(fd, "\n"); 256 break; 257 default: 258 break; 259 } 260 tmpc = mopGetChar(pkt, &idx); /* Parameter Type */ 261 } 262 263 tmpl = mopGetLong(pkt, &idx); /* Transfer Address */ 264 fprintf(fd, "Transfer Addr: %08lx\n", tmpl); 265 266 break; 267 default: 268 break; 269 } 270 } 271