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