GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/mopd/mopd/../common/dl.c Lines: 0 142 0.0 %
Date: 2017-11-07 Branches: 0 69 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: dl.c,v 1.11 2017/07/29 07:18:03 florian 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
109
				fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
110
				if ((i % 16) == 15)
111
					fprintf(fd, "\n");
112
			}
113
114
			if ((i % 16) != 15)
115
				fprintf(fd, "\n");
116
		}
117
		break;
118
	case MOP_K_CODE_ASV:
119
		/* Empty Message */
120
		break;
121
	case MOP_K_CODE_RMD:
122
		tmpl = mopGetLong(pkt, &idx);	/* Memory Address */
123
		fprintf(fd, "Mem Address  : %08lx\n", tmpl);
124
		tmps = mopGetShort(pkt, &idx);	/* Count */
125
		fprintf(fd, "Count        : %04x (%d)\n", tmps, tmps);
126
		break;
127
	case MOP_K_CODE_RPR:
128
		tmpc = mopGetChar(pkt, &idx);	/* Device Type */
129
		fprintf(fd, "Device Type  :   %02x ", tmpc);
130
		mopPrintDevice(fd, tmpc);
131
		fprintf(fd, "\n");
132
133
		tmpc = mopGetChar(pkt, &idx);	/* Format Version */
134
		fprintf(fd, "Format       :   %02x\n", tmpc);
135
136
		tmpc = mopGetChar(pkt, &idx);	/* Program Type */
137
		fprintf(fd, "Program Type :   %02x ", tmpc);
138
		mopPrintPGTY(fd, tmpc);
139
		fprintf(fd, "\n");
140
141
		program[0] = 0;
142
		tmpc = mopGetChar(pkt, &idx);	/* Software ID Len */
143
		for (i = 0; i < tmpc; i++) {
144
			program[i] = mopGetChar(pkt, &idx);
145
			program[i + 1] = '\0';
146
		}
147
148
		fprintf(fd, "Software     :   %02x '%s'\n", tmpc, program);
149
150
		tmpc = mopGetChar(pkt, &idx);	/* Processor */
151
		fprintf(fd, "Processor    :   %02x ", tmpc);
152
		mopPrintBPTY(fd, tmpc);
153
		fprintf(fd, "\n");
154
155
		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
156
157
		break;
158
	case MOP_K_CODE_RML:
159
160
		tmpc = mopGetChar(pkt, &idx);	/* Load Number */
161
		fprintf(fd, "Load Number  :   %02x\n", tmpc);
162
163
		tmpc = mopGetChar(pkt, &idx);	/* Error */
164
		fprintf(fd, "Error        :   %02x (", tmpc);
165
		if (tmpc == 0)
166
			fprintf(fd, "no error)\n");
167
		else
168
			fprintf(fd, "error)\n");
169
170
		break;
171
	case MOP_K_CODE_RDS:
172
173
		tmpc = mopGetChar(pkt, &idx);	/* Device Type */
174
		fprintf(fd, "Device Type  :   %02x ", tmpc);
175
		mopPrintDevice(fd, tmpc);
176
		fprintf(fd, "\n");
177
178
		tmpc = mopGetChar(pkt, &idx);	/* Format Version */
179
		fprintf(fd, "Format       :   %02x\n", tmpc);
180
181
		tmpl = mopGetLong(pkt, &idx);	/* Memory Size */
182
		fprintf(fd, "Memory Size  : %08lx\n", tmpl);
183
184
		tmpc = mopGetChar(pkt, &idx);	/* Bits */
185
		fprintf(fd, "Bits         :   %02x\n", tmpc);
186
187
		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
188
189
		break;
190
	case MOP_K_CODE_MDD:
191
192
		tmpl = mopGetLong(pkt, &idx);	/* Memory Address */
193
		fprintf(fd, "Mem Address  : %08lx\n", tmpl);
194
195
		if (moplen > 5) {
196
			for (i = 0; i < (moplen - 5); i++) {
197
				if ((i % 16) == 0) {
198
					if ((i / 16) == 0)
199
						fprintf(fd,
200
						    "Image Data   : %04x ",
201
						    moplen-5);
202
					else
203
						fprintf(fd,
204
						    "                    ");
205
				}
206
				fprintf(fd, "%02x ",  mopGetChar(pkt, &idx));
207
				if ((i % 16) == 15)
208
					fprintf(fd, "\n");
209
			}
210
			if ((i % 16) != 15)
211
				fprintf(fd, "\n");
212
		}
213
214
		break;
215
	case MOP_K_CODE_PLT:
216
217
		tmpc = mopGetChar(pkt, &idx);	/* Load Number */
218
		fprintf(fd, "Load Number  :   %02x\n", tmpc);
219
220
		tmpc = mopGetChar(pkt, &idx);	/* Parameter Type */
221
		while (tmpc != MOP_K_PLTP_END) {
222
			c = mopGetChar(pkt, &idx);	/* Parameter Length */
223
			switch (tmpc) {
224
			case MOP_K_PLTP_TSN:		/* Target Name */
225
				fprintf(fd, "Target Name  :   %02x '", c);
226
				for (i = 0; i < c; i++)
227
					fprintf(fd, "%c",
228
					    mopGetChar(pkt, &idx));
229
				fprintf(fd, "'\n");
230
				break;
231
			case MOP_K_PLTP_TSA:		/* Target Address */
232
				fprintf(fd, "Target Addr  :   %02x ", c);
233
				for (i = 0; i < c; i++)
234
					fprintf(fd, "%02x ",
235
					    mopGetChar(pkt, &idx));
236
				fprintf(fd, "\n");
237
				break;
238
			case MOP_K_PLTP_HSN:		/* Host Name */
239
				fprintf(fd, "Host Name    :   %02x '", c);
240
				for (i = 0; i < c; i++)
241
					fprintf(fd, "%c",
242
					    mopGetChar(pkt, &idx));
243
				fprintf(fd, "'\n");
244
				break;
245
			case MOP_K_PLTP_HSA:		/* Host Address */
246
				fprintf(fd, "Host Addr    :   %02x ", c);
247
				for (i = 0; i < c; i++)
248
					fprintf(fd, "%02x ",
249
					    mopGetChar(pkt, &idx));
250
				fprintf(fd, "\n");
251
				break;
252
			case MOP_K_PLTP_HST:		/* Host Time */
253
				ucp = pkt + idx; idx = idx + 10;
254
				fprintf(fd, "Host Time    : ");
255
				mopPrintTime(fd, ucp);
256
				fprintf(fd, "\n");
257
				break;
258
			default:
259
				break;
260
			}
261
			tmpc = mopGetChar(pkt, &idx);	/* Parameter Type */
262
		}
263
264
		tmpl = mopGetLong(pkt, &idx);	/* Transfer Address */
265
		fprintf(fd, "Transfer Addr: %08lx\n", tmpl);
266
267
		break;
268
	default:
269
		break;
270
	}
271
}