1/*	$NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos 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 "port.h"
28#ifndef lint
29__RCSID("$NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos Exp $");
30#endif
31
32#include "os.h"
33#include "dl.h"
34#include "get.h"
35#include "mopdef.h"
36#include "print.h"
37
38void
39mopDumpDL(FILE *fd, const u_char *pkt, int trans)
40{
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;
46
47	len = mopGetLength(pkt, trans);
48
49	switch (trans) {
50	case TRANS_8023:
51		idx = 22;
52		moplen = len - 8;
53		break;
54	default:
55		idx = 16;
56		moplen = len;
57	}
58	code = mopGetChar(pkt,&idx);
59
60	switch (code) {
61	case MOP_K_CODE_MLT:
62
63		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
64		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
65
66		if (moplen > 6) {
67			tmpl = mopGetLong(pkt,&idx);/* Load Address */
68			(void)fprintf(fd,"Load Address : %08x\n", tmpl);
69		}
70
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						       "                    ");
82				        }
83				}
84
85				(void)fprintf(fd, "%02x ",
86					      mopGetChar(pkt,&idx));
87				if ((i % 16) == 15)
88					(void)fprintf(fd,"\n");
89			}
90
91			if ((i % 16) != 15)
92				(void)fprintf(fd,"\n");
93#else
94			idx = idx + moplen - 10;
95#endif
96		}
97
98		tmpl = mopGetLong(pkt,&idx);	/* Load Address */
99		(void)fprintf(fd,"Xfer Address : %08x\n", tmpl);
100
101		break;
102	case MOP_K_CODE_DCM:
103
104		/* Empty Message */
105
106		break;
107	case MOP_K_CODE_MLD:
108
109		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
110		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
111
112		tmpl = mopGetLong(pkt,&idx);	/* Load Address */
113		(void)fprintf(fd,"Load Address : %08x\n", tmpl);
114
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						       "                    ");
126					}
127				}
128				(void)fprintf(fd,"%02x ",
129					      mopGetChar(pkt,&idx));
130				if ((i % 16) == 15)
131					(void)fprintf(fd,"\n");
132			}
133
134			if ((i % 16) != 15)
135				(void)fprintf(fd,"\n");
136#else
137			idx = idx + moplen - 6;
138#endif
139		}
140
141		break;
142	case MOP_K_CODE_ASV:
143
144		/* Empty Message */
145
146		break;
147	case MOP_K_CODE_RMD:
148
149		tmpl = mopGetLong(pkt,&idx);	/* Memory Address */
150		(void)fprintf(fd,"Mem Address  : %08x\n", tmpl);
151
152		tmps = mopGetShort(pkt,&idx);	/* Count */
153		(void)fprintf(fd,"Count        : %04x (%d)\n",tmps,tmps);
154
155		break;
156	case MOP_K_CODE_RPR:
157
158		tmpc = mopGetChar(pkt,&idx);	/* Device Type */
159		(void)fprintf(fd, "Device Type  :   %02x ",tmpc);
160		mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
161
162		tmpc = mopGetChar(pkt,&idx);	/* Format Version */
163		(void)fprintf(fd,"Format       :   %02x\n",tmpc);
164
165		tmpc = mopGetChar(pkt,&idx);	/* Program Type */
166		(void)fprintf(fd,"Program Type :   %02x ",tmpc);
167		mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n");
168
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';
174		}
175
176		(void)fprintf(fd,"Software     :   %02x '%s'\n",tmpc,program);
177
178		tmpc = mopGetChar(pkt,&idx);	/* Processor */
179		(void)fprintf(fd,"Processor    :   %02x ",tmpc);
180		mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n");
181
182		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
183
184		break;
185	case MOP_K_CODE_RML:
186
187		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
188		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
189
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");
196		}
197
198		break;
199	case MOP_K_CODE_RDS:
200
201		tmpc = mopGetChar(pkt,&idx);	/* Device Type */
202		(void)fprintf(fd, "Device Type  :   %02x ",tmpc);
203		mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n");
204
205		tmpc = mopGetChar(pkt,&idx);	/* Format Version */
206		(void)fprintf(fd,"Format       :   %02x\n",tmpc);
207
208		tmpl = mopGetLong(pkt,&idx);	/* Memory Size */
209		(void)fprintf(fd,"Memory Size  : %08x\n", tmpl);
210
211		tmpc = mopGetChar(pkt,&idx);	/* Bits */
212		(void)fprintf(fd,"Bits         :   %02x\n",tmpc);
213
214		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
215
216		break;
217	case MOP_K_CODE_MDD:
218
219		tmpl = mopGetLong(pkt,&idx);	/* Memory Address */
220		(void)fprintf(fd,"Mem Address  : %08x\n", tmpl);
221
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						       "                    ");
233				        }
234				}
235				(void)fprintf(fd,"%02x ",
236					      mopGetChar(pkt,&idx));
237				if ((i % 16) == 15)
238					(void)fprintf(fd,"\n");
239			}
240			if ((i % 16) != 15)
241				(void)fprintf(fd,"\n");
242#else
243			idx = idx + moplen - 5;
244#endif
245		}
246
247		break;
248	case MOP_K_CODE_PLT:
249
250		tmpc = mopGetChar(pkt,&idx);	/* Load Number */
251		(void)fprintf(fd,"Load Number  :   %02x\n",tmpc);
252
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));
263				}
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));
271				}
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));
280				}
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));
288				}
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;
299			}
300			tmpc = mopGetChar(pkt,&idx);/* Parameter Type */
301		}
302
303		tmpl = mopGetLong(pkt,&idx);	/* Transfer Address */
304		(void)fprintf(fd,"Transfer Addr: %08x\n", tmpl);
305
306		break;
307	default:
308		break;
309	}
310}
311
312
313