Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / mopd / common / dl.c
blob3f3c01c09899429c2e52263fa4538046c5f28715
1 /* $NetBSD: dl.c,v 1.6 2009/10/20 00:51:13 snj Exp $ */
3 /*
4 * Copyright (c) 1993-95 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: dl.c,v 1.6 2009/10/20 00:51:13 snj Exp $");
30 #endif
32 #include "os.h"
33 #include "dl.h"
34 #include "get.h"
35 #include "mopdef.h"
36 #include "print.h"
38 void
39 mopDumpDL(FILE *fd, const u_char *pkt, int trans)
41 int i,idx = 0;
42 u_int32_t tmpl;
43 u_char tmpc,c,program[257],code;
44 const u_char *ucp;
45 u_short len,tmps,moplen;
47 len = mopGetLength(pkt, trans);
49 switch (trans) {
50 case TRANS_8023:
51 idx = 22;
52 moplen = len - 8;
53 break;
54 default:
55 idx = 16;
56 moplen = len;
58 code = mopGetChar(pkt,&idx);
60 switch (code) {
61 case MOP_K_CODE_MLT:
63 tmpc = mopGetChar(pkt,&idx); /* Load Number */
64 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
66 if (moplen > 6) {
67 tmpl = mopGetLong(pkt,&idx);/* Load Address */
68 (void)fprintf(fd,"Load Address : %08x\n", tmpl);
71 if (moplen > 10) {
72 #ifndef SHORT_PRINT
73 for (i = 0; i < (moplen - 10); i++) {
74 if ((i % 16) == 0) {
75 if ((i / 16) == 0) {
76 (void)fprintf(fd,
77 "Image Data : %04x ",
78 moplen-10);
79 } else {
80 (void)fprintf(fd,
81 " ");
85 (void)fprintf(fd, "%02x ",
86 mopGetChar(pkt,&idx));
87 if ((i % 16) == 15)
88 (void)fprintf(fd,"\n");
91 if ((i % 16) != 15)
92 (void)fprintf(fd,"\n");
93 #else
94 idx = idx + moplen - 10;
95 #endif
98 tmpl = mopGetLong(pkt,&idx); /* Load Address */
99 (void)fprintf(fd,"Xfer Address : %08x\n", tmpl);
101 break;
102 case MOP_K_CODE_DCM:
104 /* Empty Message */
106 break;
107 case MOP_K_CODE_MLD:
109 tmpc = mopGetChar(pkt,&idx); /* Load Number */
110 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
112 tmpl = mopGetLong(pkt,&idx); /* Load Address */
113 (void)fprintf(fd,"Load Address : %08x\n", tmpl);
115 if (moplen > 6) {
116 #ifndef SHORT_PRINT
117 for (i = 0; i < (moplen - 6); i++) {
118 if ((i % 16) == 0) {
119 if ((i / 16) == 0) {
120 (void)fprintf(fd,
121 "Image Data : %04x ",
122 moplen-6);
123 } else {
124 (void)fprintf(fd,
125 " ");
128 (void)fprintf(fd,"%02x ",
129 mopGetChar(pkt,&idx));
130 if ((i % 16) == 15)
131 (void)fprintf(fd,"\n");
134 if ((i % 16) != 15)
135 (void)fprintf(fd,"\n");
136 #else
137 idx = idx + moplen - 6;
138 #endif
141 break;
142 case MOP_K_CODE_ASV:
144 /* Empty Message */
146 break;
147 case MOP_K_CODE_RMD:
149 tmpl = mopGetLong(pkt,&idx); /* Memory Address */
150 (void)fprintf(fd,"Mem Address : %08x\n", tmpl);
152 tmps = mopGetShort(pkt,&idx); /* Count */
153 (void)fprintf(fd,"Count : %04x (%d)\n",tmps,tmps);
155 break;
156 case MOP_K_CODE_RPR:
158 tmpc = mopGetChar(pkt,&idx); /* Device Type */
159 (void)fprintf(fd, "Device Type : %02x ",tmpc);
160 mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
162 tmpc = mopGetChar(pkt,&idx); /* Format Version */
163 (void)fprintf(fd,"Format : %02x\n",tmpc);
165 tmpc = mopGetChar(pkt,&idx); /* Program Type */
166 (void)fprintf(fd,"Program Type : %02x ",tmpc);
167 mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n");
169 program[0] = 0;
170 tmpc = mopGetChar(pkt,&idx); /* Software ID Len */
171 for (i = 0; i < tmpc; i++) {
172 program[i] = mopGetChar(pkt,&idx);
173 program[i+1] = '\0';
176 (void)fprintf(fd,"Software : %02x '%s'\n",tmpc,program);
178 tmpc = mopGetChar(pkt,&idx); /* Processor */
179 (void)fprintf(fd,"Processor : %02x ",tmpc);
180 mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n");
182 mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
184 break;
185 case MOP_K_CODE_RML:
187 tmpc = mopGetChar(pkt,&idx); /* Load Number */
188 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
190 tmpc = mopGetChar(pkt,&idx); /* Error */
191 (void)fprintf(fd,"Error : %02x (",tmpc);
192 if ((tmpc == 0)) {
193 (void)fprintf(fd,"no error)\n");
194 } else {
195 (void)fprintf(fd,"error)\n");
198 break;
199 case MOP_K_CODE_RDS:
201 tmpc = mopGetChar(pkt,&idx); /* Device Type */
202 (void)fprintf(fd, "Device Type : %02x ",tmpc);
203 mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
205 tmpc = mopGetChar(pkt,&idx); /* Format Version */
206 (void)fprintf(fd,"Format : %02x\n",tmpc);
208 tmpl = mopGetLong(pkt,&idx); /* Memory Size */
209 (void)fprintf(fd,"Memory Size : %08x\n", tmpl);
211 tmpc = mopGetChar(pkt,&idx); /* Bits */
212 (void)fprintf(fd,"Bits : %02x\n",tmpc);
214 mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
216 break;
217 case MOP_K_CODE_MDD:
219 tmpl = mopGetLong(pkt,&idx); /* Memory Address */
220 (void)fprintf(fd,"Mem Address : %08x\n", tmpl);
222 if (moplen > 5) {
223 #ifndef SHORT_PRINT
224 for (i = 0; i < (moplen - 5); i++) {
225 if ((i % 16) == 0) {
226 if ((i / 16) == 0) {
227 (void)fprintf(fd,
228 "Image Data : %04x ",
229 moplen-5);
230 } else {
231 (void)fprintf(fd,
232 " ");
235 (void)fprintf(fd,"%02x ",
236 mopGetChar(pkt,&idx));
237 if ((i % 16) == 15)
238 (void)fprintf(fd,"\n");
240 if ((i % 16) != 15)
241 (void)fprintf(fd,"\n");
242 #else
243 idx = idx + moplen - 5;
244 #endif
247 break;
248 case MOP_K_CODE_PLT:
250 tmpc = mopGetChar(pkt,&idx); /* Load Number */
251 (void)fprintf(fd,"Load Number : %02x\n",tmpc);
253 tmpc = mopGetChar(pkt,&idx); /* Parameter Type */
254 while (tmpc != MOP_K_PLTP_END) {
255 c = mopGetChar(pkt,&idx); /* Parameter Length */
256 switch(tmpc) {
257 case MOP_K_PLTP_TSN: /* Target Name */
258 (void)fprintf(fd,"Target Name : %02x '",
259 tmpc);
260 for (i = 0; i < ((int) c); i++) {
261 (void)fprintf(fd,"%c",
262 mopGetChar(pkt,&idx));
264 (void)fprintf(fd,"'\n");
265 break;
266 case MOP_K_PLTP_TSA: /* Target Address */
267 (void)fprintf(fd,"Target Addr : %02x ",c);
268 for (i = 0; i < ((int) c); i++) {
269 (void)fprintf(fd,"%02x ",
270 mopGetChar(pkt,&idx));
272 (void)fprintf(fd,"\n");
273 break;
274 case MOP_K_PLTP_HSN: /* Host Name */
275 (void)fprintf(fd,"Host Name : %02x '",
276 tmpc);
277 for (i = 0; i < ((int) c); i++) {
278 (void)fprintf(fd,"%c",
279 mopGetChar(pkt,&idx));
281 (void)fprintf(fd,"'\n");
282 break;
283 case MOP_K_PLTP_HSA: /* Host Address */
284 (void)fprintf(fd,"Host Addr : %02x ",c);
285 for (i = 0; i < ((int) c); i++) {
286 (void)fprintf(fd,"%02x ",
287 mopGetChar(pkt,&idx));
289 (void)fprintf(fd,"\n");
290 break;
291 case MOP_K_PLTP_HST: /* Host Time */
292 ucp = pkt + idx; idx = idx + 10;
293 (void)fprintf(fd,"Host Time : ");
294 mopPrintTime(fd, ucp);
295 (void)fprintf(fd,"\n");
296 break;
297 default:
298 break;
300 tmpc = mopGetChar(pkt,&idx);/* Parameter Type */
303 tmpl = mopGetLong(pkt,&idx); /* Transfer Address */
304 (void)fprintf(fd,"Transfer Addr: %08x\n", tmpl);
306 break;
307 default:
308 break;