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