]>
Commit | Line | Data |
---|---|---|
bbaa79b8 JI |
1 | /* Copyright (C) 2015 Open Information Security Foundation |
2 | * | |
3 | * You can copy, redistribute or modify this Program under the terms of | |
4 | * the GNU General Public License version 2 as published by the Free | |
5 | * Software Foundation. | |
6 | * | |
7 | * This program is distributed in the hope that it will be useful, | |
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | * GNU General Public License for more details. | |
11 | * | |
12 | * You should have received a copy of the GNU General Public License | |
13 | * version 2 along with this program; if not, write to the Free Software | |
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
15 | * 02110-1301, USA. | |
16 | */ | |
17 | ||
18 | /** | |
19 | * \file | |
20 | * | |
21 | * \author Jason Ish <jason.ish@oisf.net> | |
22 | * | |
23 | * This file contains the DNP3 object decoders. | |
24 | */ | |
25 | ||
26 | #include "suricata-common.h" | |
27 | ||
28 | #include "app-layer-dnp3.h" | |
29 | #include "app-layer-dnp3-objects.h" | |
30 | ||
31 | void DNP3FreeObjectPoint(int group, int variation, void *point); | |
32 | ||
33 | #if 0 | |
34 | static void DNP3HexDump(uint8_t *data, int len) | |
35 | { | |
36 | for (int i = 0; i < len; i++) { | |
37 | printf("%02x ", data[i]); | |
38 | } | |
39 | } | |
40 | #endif | |
41 | ||
42 | /** | |
43 | * \brief Allocate a list for DNP3 points. | |
44 | */ | |
45 | DNP3PointList *DNP3PointListAlloc(void) | |
46 | { | |
47 | DNP3PointList *items = SCCalloc(1, sizeof(*items)); | |
48 | if (unlikely(items == NULL)) { | |
49 | return NULL; | |
50 | } | |
51 | TAILQ_INIT(items); | |
52 | return items; | |
53 | } | |
54 | ||
55 | /** | |
56 | * \brief Free a DNP3PointList. | |
57 | */ | |
58 | void DNP3FreeObjectPointList(int group, int variation, DNP3PointList *list) | |
59 | { | |
60 | DNP3Point *point; | |
61 | while ((point = TAILQ_FIRST(list)) != NULL) { | |
62 | TAILQ_REMOVE(list, point, next); | |
63 | if (point->data != NULL) { | |
64 | DNP3FreeObjectPoint(group, variation, point->data); | |
65 | } | |
66 | SCFree(point); | |
67 | } | |
68 | SCFree(list); | |
69 | } | |
70 | ||
71 | /** | |
72 | * \brief Read an uint8_t from a buffer. | |
73 | * | |
74 | * Reads a uint8_t from a buffer advancing the pointer and | |
75 | * decrementing the length. | |
76 | * | |
77 | * \param buf A pointer to the buffer to read from. | |
78 | * \param len A pointer to the buffer length. | |
79 | * \param out A pointer to where the value will be stored. | |
80 | * | |
81 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
82 | * otherwise 0 is returned. | |
83 | */ | |
84 | static int DNP3ReadUint8(const uint8_t **buf, uint32_t *len, uint8_t *out) | |
85 | { | |
86 | if (*len < (int)sizeof(*out)) { | |
87 | return 0; | |
88 | } | |
89 | *out = *(uint8_t *)(*buf); | |
90 | *buf += sizeof(*out); | |
91 | *len -= sizeof(*out); | |
92 | return 1; | |
93 | } | |
94 | ||
95 | /** | |
96 | * \brief Read an uint16_t from a buffer. | |
97 | * | |
98 | * Reads an uint16_t from a buffer advancing the pointer and | |
99 | * decrementing the length. | |
100 | * | |
101 | * \param buf A pointer to the buffer to read from. | |
102 | * \param len A pointer to the buffer length. | |
103 | * \param out A pointer to where the value will be stored. | |
104 | * | |
105 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
106 | * otherwise 0 is returned. | |
107 | */ | |
108 | static int DNP3ReadUint16(const uint8_t **buf, uint32_t *len, uint16_t *out) | |
109 | { | |
110 | if (*len < (int)sizeof(*out)) { | |
111 | return 0; | |
112 | } | |
113 | *out = DNP3_SWAP16(*(uint16_t *)(*buf)); | |
114 | *buf += sizeof(*out); | |
115 | *len -= sizeof(*out); | |
116 | return 1; | |
117 | } | |
118 | ||
119 | /** | |
120 | * \brief Read an unsigned 24 bit integer from a buffer. | |
121 | * | |
122 | * Reads an an unsigned 24 bit integer from a buffer advancing the | |
123 | * pointer and decrementing the length. | |
124 | * | |
125 | * \param buf A pointer to the buffer to read from. | |
126 | * \param len A pointer to the buffer length. | |
127 | * \param out A pointer to where the value will be stored. | |
128 | * | |
129 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
130 | * otherwise 0 is returned. | |
131 | */ | |
132 | static int DNP3ReadUint24(const uint8_t **buf, uint32_t *len, uint32_t *out) | |
133 | { | |
134 | if (*len < (int)(sizeof(uint8_t) * 3)) { | |
135 | return 0; | |
136 | } | |
137 | ||
138 | #if __BYTE_ORDER__ == __BIG_ENDIAN | |
139 | *out = ((uint32_t)(*buf)[0] << 16) | ((uint32_t)(*buf)[1] << 8) | | |
140 | (uint32_t)(*buf)[2]; | |
141 | #elif __BYTE_ORDER == __LITTLE_ENDIAN | |
142 | *out = ((uint64_t)(*buf)[0]) | ((uint64_t)(*buf)[1] << 8) | | |
143 | ((uint64_t)(*buf)[2] << 16); | |
144 | #endif | |
145 | ||
146 | *buf += 3; | |
147 | *len -= 3; | |
148 | ||
149 | return 1; | |
150 | } | |
151 | ||
152 | /** | |
153 | * \brief Read an uint32_t from a buffer. | |
154 | * | |
155 | * Reads an uint32_t from a buffer advancing the pointer and | |
156 | * decrementing the length. | |
157 | * | |
158 | * \param buf A pointer to the buffer to read from. | |
159 | * \param len A pointer to the buffer length. | |
160 | * \param out A pointer to where the value will be stored. | |
161 | * | |
162 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
163 | * otherwise 0 is returned. | |
164 | */ | |
165 | static int DNP3ReadUint32(const uint8_t **buf, uint32_t *len, uint32_t *out) | |
166 | { | |
167 | if (*len < (int)sizeof(*out)) { | |
168 | return 0; | |
169 | } | |
170 | *out = DNP3_SWAP32(*(uint32_t *)(*buf)); | |
171 | *buf += sizeof(*out); | |
172 | *len -= sizeof(*out); | |
173 | return 1; | |
174 | } | |
175 | ||
176 | /** | |
177 | * \brief Read an unsigned 48 bit integer from a buffer. | |
178 | * | |
179 | * Reads an an unsigned 48 bit integer from a buffer advancing the | |
180 | * pointer and decrementing the length. | |
181 | * | |
182 | * \param buf A pointer to the buffer to read from. | |
183 | * \param len A pointer to the buffer length. | |
184 | * \param out A pointer to where the value will be stored. | |
185 | * | |
186 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
187 | * otherwise 0 is returned. | |
188 | */ | |
189 | static int DNP3ReadUint48(const uint8_t **buf, uint32_t *len, uint64_t *out) | |
190 | { | |
191 | if (*len < (int)(sizeof(uint8_t) * 6)) { | |
192 | return 0; | |
193 | } | |
194 | ||
195 | #if __BYTE_ORDER__ == __BIG_ENDIAN | |
196 | *out = ((uint64_t)(*buf)[0] << 40) | ((uint64_t)(*buf)[1] << 32) | | |
197 | ((uint64_t)(*buf)[2] << 24) | ((uint64_t)(*buf)[3] << 16) | | |
198 | ((uint64_t)(*buf)[4] << 8) | (uint64_t)(*buf)[5]; | |
199 | #elif __BYTE_ORDER == __LITTLE_ENDIAN | |
200 | *out = ((uint64_t)(*buf)[0]) | ((uint64_t)(*buf)[1] << 8) | | |
201 | ((uint64_t)(*buf)[2] << 16) | ((uint64_t)(*buf)[3] << 24) | | |
202 | ((uint64_t)(*buf)[4] << 32) | ((uint64_t)(*buf)[5] << 40); | |
203 | #endif | |
204 | ||
205 | *buf += 6; | |
206 | *len -= 6; | |
207 | ||
208 | return 1; | |
209 | } | |
210 | ||
211 | /** | |
212 | * \brief Read a 32 bit float from a buffer. | |
213 | * | |
214 | * Reads an 32 bit float from a buffer advancing the pointer and | |
215 | * decrementing the length. | |
216 | * | |
217 | * \param buf A pointer to the buffer to read from. | |
218 | * \param len A pointer to the buffer length. | |
219 | * \param out A pointer to where the value will be stored. | |
220 | * | |
221 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
222 | * otherwise 0 is returned. | |
223 | */ | |
224 | static int DNP3ReadFloat32(const uint8_t **buf, uint32_t *len, float *out) | |
225 | { | |
226 | if (*len < 4) { | |
227 | return 0; | |
228 | } | |
229 | ||
230 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
231 | *((uint8_t *)out + 0) = (*buf)[0]; | |
232 | *((uint8_t *)out + 1) = (*buf)[1]; | |
233 | *((uint8_t *)out + 2) = (*buf)[2]; | |
234 | *((uint8_t *)out + 3) = (*buf)[3]; | |
235 | #else | |
236 | *((uint8_t *)out + 3) = (*buf)[0]; | |
237 | *((uint8_t *)out + 2) = (*buf)[1]; | |
238 | *((uint8_t *)out + 1) = (*buf)[2]; | |
239 | *((uint8_t *)out + 0) = (*buf)[3]; | |
240 | #endif | |
241 | *len -= 4; | |
242 | *buf += 4; | |
243 | ||
244 | return 1; | |
245 | } | |
246 | ||
247 | /** | |
248 | * \brief Read a 64 bit float from a buffer. | |
249 | * | |
250 | * Reads an 64 bit float from a buffer advancing the pointer and | |
251 | * decrementing the length. | |
252 | * | |
253 | * \param buf A pointer to the buffer to read from. | |
254 | * \param len A pointer to the buffer length. | |
255 | * \param out A pointer to where the value will be stored. | |
256 | * | |
257 | * \retval Returns 1 if there was enough space in the buffer to read from, | |
258 | * otherwise 0 is returned. | |
259 | */ | |
260 | static int DNP3ReadFloat64(const uint8_t **buf, uint32_t *len, double *out) | |
261 | { | |
262 | if (*len < 8) { | |
263 | return 0; | |
264 | } | |
265 | ||
266 | #if __BYTE_ORDER == __LITTLE_ENDIAN | |
267 | *((uint8_t *)out + 0) = (*buf)[0]; | |
268 | *((uint8_t *)out + 1) = (*buf)[1]; | |
269 | *((uint8_t *)out + 2) = (*buf)[2]; | |
270 | *((uint8_t *)out + 3) = (*buf)[3]; | |
271 | *((uint8_t *)out + 4) = (*buf)[4]; | |
272 | *((uint8_t *)out + 5) = (*buf)[5]; | |
273 | *((uint8_t *)out + 6) = (*buf)[6]; | |
274 | *((uint8_t *)out + 7) = (*buf)[7]; | |
275 | #else | |
276 | *((uint8_t *)out + 7) = (*buf)[0]; | |
277 | *((uint8_t *)out + 6) = (*buf)[1]; | |
278 | *((uint8_t *)out + 5) = (*buf)[2]; | |
279 | *((uint8_t *)out + 4) = (*buf)[3]; | |
280 | *((uint8_t *)out + 3) = (*buf)[4]; | |
281 | *((uint8_t *)out + 2) = (*buf)[5]; | |
282 | *((uint8_t *)out + 1) = (*buf)[6]; | |
283 | *((uint8_t *)out + 0) = (*buf)[7]; | |
284 | #endif | |
285 | *len -= 8; | |
286 | *buf += 8; | |
287 | ||
288 | return 1; | |
289 | } | |
290 | ||
291 | /** | |
292 | * \brief Get the prefix value and advance the buffer. | |
293 | */ | |
294 | static int DNP3ReadPrefix( | |
295 | const uint8_t **buf, uint32_t *len, uint8_t prefix_code, uint32_t *out) | |
296 | { | |
297 | uint8_t prefix_len = 0; | |
298 | ||
299 | switch (prefix_code) { | |
300 | case 0x01: | |
301 | case 0x04: | |
302 | prefix_len = 1; | |
303 | break; | |
304 | case 0x02: | |
305 | case 0x05: | |
306 | prefix_len = 2; | |
307 | break; | |
308 | case 0x03: | |
309 | case 0x06: | |
310 | prefix_len = 4; | |
311 | default: | |
312 | break; | |
313 | } | |
314 | ||
315 | if (*len < (uint32_t)prefix_len) { | |
316 | return 0; | |
317 | } | |
318 | ||
319 | switch (prefix_len) { | |
320 | case sizeof(uint32_t): | |
65bf0697 JI |
321 | if (!DNP3ReadUint32(buf, len, out)) { |
322 | return 0; | |
323 | } | |
bbaa79b8 JI |
324 | break; |
325 | case sizeof(uint16_t): { | |
326 | /* Temp value for strict-aliasing. */ | |
327 | uint16_t val = 0; | |
65bf0697 JI |
328 | if (!DNP3ReadUint16(buf, len, &val)) { |
329 | return 0; | |
330 | } | |
bbaa79b8 JI |
331 | *out = val; |
332 | break; | |
333 | } | |
334 | case sizeof(uint8_t): { | |
335 | /* Temp value for strict-aliasing. */ | |
336 | uint8_t val = 0; | |
65bf0697 JI |
337 | if (!DNP3ReadUint8(buf, len, &val)) { |
338 | return 0; | |
339 | } | |
bbaa79b8 JI |
340 | *out = val; |
341 | break; | |
342 | } | |
343 | default: | |
344 | *out = 0; | |
345 | break; | |
346 | } | |
347 | ||
348 | return 1; | |
349 | } | |
350 | ||
351 | /** | |
352 | * \brief Add an object to a DNP3PointList. | |
353 | * | |
354 | * \retval 1 if successfull, 0 on failure. | |
355 | */ | |
53a8c753 | 356 | static int DNP3AddPoint(DNP3PointList *list, void *object, uint32_t point_index, |
bbaa79b8 JI |
357 | uint8_t prefix_code, uint32_t prefix) |
358 | { | |
359 | DNP3Point *point = SCCalloc(1, sizeof(*point)); | |
360 | if (unlikely(point == NULL)) { | |
361 | return 0; | |
362 | } | |
363 | TAILQ_INSERT_TAIL(list, point, next); | |
364 | point->data = object; | |
365 | point->prefix = prefix; | |
53a8c753 | 366 | point->index = point_index; |
bbaa79b8 JI |
367 | switch (prefix_code) { |
368 | case 0x00: | |
369 | break; | |
370 | case 0x01: | |
371 | case 0x02: | |
372 | case 0x03: | |
373 | point->index = prefix; | |
374 | break; | |
375 | case 0x04: | |
376 | case 0x05: | |
377 | case 0x06: | |
378 | point->size = prefix; | |
379 | break; | |
380 | default: | |
381 | break; | |
382 | } | |
383 | ||
384 | return 1; | |
385 | } | |
386 | ||
387 | /* START GENERATED CODE */ | |
388 | ||
389 | /* Code generated by: | |
390 | * ./scripts/dnp3-gen/dnp3-gen.py | |
391 | */ | |
392 | ||
393 | static int DNP3DecodeObjectG1V1(const uint8_t **buf, uint32_t *len, | |
394 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
395 | DNP3PointList *points) | |
396 | { | |
397 | DNP3ObjectG1V1 *object = NULL; | |
8c4e53e8 | 398 | uint32_t bytes = (count / 8) + 1; |
bbaa79b8 | 399 | uint32_t prefix = 0; |
8c4e53e8 | 400 | uint32_t point_index = start; |
bbaa79b8 JI |
401 | |
402 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
403 | goto error; | |
404 | } | |
405 | ||
8c4e53e8 | 406 | for (uint32_t i = 0; i < bytes; i++) { |
bbaa79b8 JI |
407 | |
408 | uint8_t octet; | |
409 | ||
410 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
411 | goto error; | |
412 | } | |
413 | ||
414 | for (int j = 0; j < 8 && count; j = j + 1) { | |
415 | ||
416 | object = SCCalloc(1, sizeof(*object)); | |
417 | if (unlikely(object == NULL)) { | |
418 | goto error; | |
419 | } | |
420 | ||
421 | object->state = (octet >> j) & 0x1; | |
422 | ||
53a8c753 | 423 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
424 | goto error; |
425 | } | |
426 | ||
427 | object = NULL; | |
428 | count--; | |
53a8c753 | 429 | point_index++; |
bbaa79b8 JI |
430 | } |
431 | ||
432 | } | |
433 | ||
434 | return 1; | |
435 | error: | |
436 | if (object != NULL) { | |
437 | SCFree(object); | |
438 | } | |
439 | return 0; | |
440 | } | |
441 | ||
442 | static int DNP3DecodeObjectG1V2(const uint8_t **buf, uint32_t *len, | |
443 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
444 | DNP3PointList *points) | |
445 | { | |
446 | DNP3ObjectG1V2 *object = NULL; | |
447 | uint32_t prefix = 0; | |
53a8c753 | 448 | uint32_t point_index = start; |
bbaa79b8 | 449 | |
8c4e53e8 PA |
450 | if (*len < count/8) { |
451 | goto error; | |
452 | } | |
bbaa79b8 JI |
453 | while (count--) { |
454 | ||
455 | object = SCCalloc(1, sizeof(*object)); | |
456 | if (unlikely(object == NULL)) { | |
457 | goto error; | |
458 | } | |
459 | ||
460 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
461 | goto error; | |
462 | } | |
463 | ||
464 | { | |
465 | uint8_t octet; | |
466 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
467 | goto error; | |
468 | } | |
469 | object->online = (octet >> 0) & 0x1; | |
470 | object->restart = (octet >> 1) & 0x1; | |
471 | object->comm_lost = (octet >> 2) & 0x1; | |
472 | object->remote_forced = (octet >> 3) & 0x1; | |
473 | object->local_forced = (octet >> 4) & 0x1; | |
474 | object->chatter_filter = (octet >> 5) & 0x1; | |
475 | object->reserved = (octet >> 6) & 0x1; | |
476 | object->state = (octet >> 7) & 0x1; | |
477 | } | |
478 | ||
53a8c753 | 479 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
480 | goto error; |
481 | } | |
482 | ||
483 | object = NULL; | |
53a8c753 | 484 | point_index++; |
bbaa79b8 JI |
485 | } |
486 | ||
487 | return 1; | |
488 | error: | |
489 | if (object != NULL) { | |
490 | SCFree(object); | |
491 | } | |
492 | ||
493 | return 0; | |
494 | } | |
495 | ||
496 | static int DNP3DecodeObjectG2V1(const uint8_t **buf, uint32_t *len, | |
497 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
498 | DNP3PointList *points) | |
499 | { | |
500 | DNP3ObjectG2V1 *object = NULL; | |
501 | uint32_t prefix = 0; | |
53a8c753 | 502 | uint32_t point_index = start; |
bbaa79b8 | 503 | |
8c4e53e8 PA |
504 | if (*len < count/8) { |
505 | goto error; | |
506 | } | |
bbaa79b8 JI |
507 | while (count--) { |
508 | ||
509 | object = SCCalloc(1, sizeof(*object)); | |
510 | if (unlikely(object == NULL)) { | |
511 | goto error; | |
512 | } | |
513 | ||
514 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
515 | goto error; | |
516 | } | |
517 | ||
518 | if (!DNP3ReadUint8(buf, len, &object->state)) { | |
519 | goto error; | |
520 | } | |
521 | ||
53a8c753 | 522 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
523 | goto error; |
524 | } | |
525 | ||
526 | object = NULL; | |
53a8c753 | 527 | point_index++; |
bbaa79b8 JI |
528 | } |
529 | ||
530 | return 1; | |
531 | error: | |
532 | if (object != NULL) { | |
533 | SCFree(object); | |
534 | } | |
535 | ||
536 | return 0; | |
537 | } | |
538 | ||
539 | static int DNP3DecodeObjectG2V2(const uint8_t **buf, uint32_t *len, | |
540 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
541 | DNP3PointList *points) | |
542 | { | |
543 | DNP3ObjectG2V2 *object = NULL; | |
544 | uint32_t prefix = 0; | |
53a8c753 | 545 | uint32_t point_index = start; |
bbaa79b8 | 546 | |
8c4e53e8 PA |
547 | if (*len < count/8) { |
548 | goto error; | |
549 | } | |
bbaa79b8 JI |
550 | while (count--) { |
551 | ||
552 | object = SCCalloc(1, sizeof(*object)); | |
553 | if (unlikely(object == NULL)) { | |
554 | goto error; | |
555 | } | |
556 | ||
557 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
558 | goto error; | |
559 | } | |
560 | ||
561 | { | |
562 | uint8_t octet; | |
563 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
564 | goto error; | |
565 | } | |
566 | object->online = (octet >> 0) & 0x1; | |
567 | object->restart = (octet >> 1) & 0x1; | |
568 | object->comm_lost = (octet >> 2) & 0x1; | |
569 | object->remote_forced = (octet >> 3) & 0x1; | |
570 | object->local_forced = (octet >> 4) & 0x1; | |
571 | object->chatter_filter = (octet >> 5) & 0x1; | |
572 | object->reserved = (octet >> 6) & 0x1; | |
573 | object->state = (octet >> 7) & 0x1; | |
574 | } | |
575 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
576 | goto error; | |
577 | } | |
578 | ||
53a8c753 | 579 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
580 | goto error; |
581 | } | |
582 | ||
583 | object = NULL; | |
53a8c753 | 584 | point_index++; |
bbaa79b8 JI |
585 | } |
586 | ||
587 | return 1; | |
588 | error: | |
589 | if (object != NULL) { | |
590 | SCFree(object); | |
591 | } | |
592 | ||
593 | return 0; | |
594 | } | |
595 | ||
596 | static int DNP3DecodeObjectG2V3(const uint8_t **buf, uint32_t *len, | |
597 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
598 | DNP3PointList *points) | |
599 | { | |
600 | DNP3ObjectG2V3 *object = NULL; | |
601 | uint32_t prefix = 0; | |
53a8c753 | 602 | uint32_t point_index = start; |
bbaa79b8 | 603 | |
8c4e53e8 PA |
604 | if (*len < count/8) { |
605 | goto error; | |
606 | } | |
bbaa79b8 JI |
607 | while (count--) { |
608 | ||
609 | object = SCCalloc(1, sizeof(*object)); | |
610 | if (unlikely(object == NULL)) { | |
611 | goto error; | |
612 | } | |
613 | ||
614 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
615 | goto error; | |
616 | } | |
617 | ||
618 | { | |
619 | uint8_t octet; | |
620 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
621 | goto error; | |
622 | } | |
623 | object->online = (octet >> 0) & 0x1; | |
624 | object->restart = (octet >> 1) & 0x1; | |
625 | object->comm_lost = (octet >> 2) & 0x1; | |
626 | object->remote_forced = (octet >> 3) & 0x1; | |
627 | object->local_forced = (octet >> 4) & 0x1; | |
628 | object->chatter_filter = (octet >> 5) & 0x1; | |
629 | object->reserved = (octet >> 6) & 0x1; | |
630 | object->state = (octet >> 7) & 0x1; | |
631 | } | |
632 | if (!DNP3ReadUint16(buf, len, &object->timestamp)) { | |
633 | goto error; | |
634 | } | |
635 | ||
53a8c753 | 636 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
637 | goto error; |
638 | } | |
639 | ||
640 | object = NULL; | |
53a8c753 | 641 | point_index++; |
bbaa79b8 JI |
642 | } |
643 | ||
644 | return 1; | |
645 | error: | |
646 | if (object != NULL) { | |
647 | SCFree(object); | |
648 | } | |
649 | ||
650 | return 0; | |
651 | } | |
652 | ||
653 | static int DNP3DecodeObjectG3V1(const uint8_t **buf, uint32_t *len, | |
654 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
655 | DNP3PointList *points) | |
656 | { | |
657 | DNP3ObjectG3V1 *object = NULL; | |
8c4e53e8 | 658 | uint32_t bytes = (count / 8) + 1; |
bbaa79b8 | 659 | uint32_t prefix = 0; |
8c4e53e8 | 660 | uint32_t point_index = start; |
bbaa79b8 JI |
661 | |
662 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
663 | goto error; | |
664 | } | |
665 | ||
8c4e53e8 | 666 | for (uint32_t i = 0; i < bytes; i++) { |
bbaa79b8 JI |
667 | |
668 | uint8_t octet; | |
669 | ||
670 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
671 | goto error; | |
672 | } | |
673 | ||
674 | for (int j = 0; j < 8 && count; j = j + 2) { | |
675 | ||
676 | object = SCCalloc(1, sizeof(*object)); | |
677 | if (unlikely(object == NULL)) { | |
678 | goto error; | |
679 | } | |
680 | ||
681 | object->state = (octet >> j) & 0x3; | |
682 | ||
53a8c753 | 683 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
684 | goto error; |
685 | } | |
686 | ||
687 | object = NULL; | |
688 | count--; | |
53a8c753 | 689 | point_index++; |
bbaa79b8 JI |
690 | } |
691 | ||
692 | } | |
693 | ||
694 | return 1; | |
695 | error: | |
696 | if (object != NULL) { | |
697 | SCFree(object); | |
698 | } | |
699 | return 0; | |
700 | } | |
701 | ||
702 | static int DNP3DecodeObjectG3V2(const uint8_t **buf, uint32_t *len, | |
703 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
704 | DNP3PointList *points) | |
705 | { | |
706 | DNP3ObjectG3V2 *object = NULL; | |
707 | uint32_t prefix = 0; | |
53a8c753 | 708 | uint32_t point_index = start; |
bbaa79b8 | 709 | |
8c4e53e8 PA |
710 | if (*len < count/8) { |
711 | goto error; | |
712 | } | |
bbaa79b8 JI |
713 | while (count--) { |
714 | ||
715 | object = SCCalloc(1, sizeof(*object)); | |
716 | if (unlikely(object == NULL)) { | |
717 | goto error; | |
718 | } | |
719 | ||
720 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
721 | goto error; | |
722 | } | |
723 | ||
724 | { | |
725 | uint8_t octet; | |
726 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
727 | goto error; | |
728 | } | |
729 | object->online = (octet >> 0) & 0x1; | |
730 | object->restart = (octet >> 1) & 0x1; | |
731 | object->comm_lost = (octet >> 2) & 0x1; | |
732 | object->remote_forced = (octet >> 3) & 0x1; | |
733 | object->local_forced = (octet >> 4) & 0x1; | |
734 | object->chatter_filter = (octet >> 5) & 0x1; | |
735 | object->state = (octet >> 6) & 0x3; | |
736 | } | |
737 | ||
53a8c753 | 738 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
739 | goto error; |
740 | } | |
741 | ||
742 | object = NULL; | |
53a8c753 | 743 | point_index++; |
bbaa79b8 JI |
744 | } |
745 | ||
746 | return 1; | |
747 | error: | |
748 | if (object != NULL) { | |
749 | SCFree(object); | |
750 | } | |
751 | ||
752 | return 0; | |
753 | } | |
754 | ||
755 | static int DNP3DecodeObjectG4V1(const uint8_t **buf, uint32_t *len, | |
756 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
757 | DNP3PointList *points) | |
758 | { | |
759 | DNP3ObjectG4V1 *object = NULL; | |
760 | uint32_t prefix = 0; | |
53a8c753 | 761 | uint32_t point_index = start; |
bbaa79b8 | 762 | |
8c4e53e8 PA |
763 | if (*len < count/8) { |
764 | goto error; | |
765 | } | |
bbaa79b8 JI |
766 | while (count--) { |
767 | ||
768 | object = SCCalloc(1, sizeof(*object)); | |
769 | if (unlikely(object == NULL)) { | |
770 | goto error; | |
771 | } | |
772 | ||
773 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
774 | goto error; | |
775 | } | |
776 | ||
777 | { | |
778 | uint8_t octet; | |
779 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
780 | goto error; | |
781 | } | |
782 | object->online = (octet >> 0) & 0x1; | |
783 | object->restart = (octet >> 1) & 0x1; | |
784 | object->comm_lost = (octet >> 2) & 0x1; | |
785 | object->remote_forced = (octet >> 3) & 0x1; | |
786 | object->local_forced = (octet >> 4) & 0x1; | |
787 | object->chatter_filter = (octet >> 5) & 0x1; | |
788 | object->state = (octet >> 6) & 0x3; | |
789 | } | |
790 | ||
53a8c753 | 791 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
792 | goto error; |
793 | } | |
794 | ||
795 | object = NULL; | |
53a8c753 | 796 | point_index++; |
bbaa79b8 JI |
797 | } |
798 | ||
799 | return 1; | |
800 | error: | |
801 | if (object != NULL) { | |
802 | SCFree(object); | |
803 | } | |
804 | ||
805 | return 0; | |
806 | } | |
807 | ||
808 | static int DNP3DecodeObjectG4V2(const uint8_t **buf, uint32_t *len, | |
809 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
810 | DNP3PointList *points) | |
811 | { | |
812 | DNP3ObjectG4V2 *object = NULL; | |
813 | uint32_t prefix = 0; | |
53a8c753 | 814 | uint32_t point_index = start; |
bbaa79b8 | 815 | |
8c4e53e8 PA |
816 | if (*len < count/8) { |
817 | goto error; | |
818 | } | |
bbaa79b8 JI |
819 | while (count--) { |
820 | ||
821 | object = SCCalloc(1, sizeof(*object)); | |
822 | if (unlikely(object == NULL)) { | |
823 | goto error; | |
824 | } | |
825 | ||
826 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
827 | goto error; | |
828 | } | |
829 | ||
830 | { | |
831 | uint8_t octet; | |
832 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
833 | goto error; | |
834 | } | |
835 | object->online = (octet >> 0) & 0x1; | |
836 | object->restart = (octet >> 1) & 0x1; | |
837 | object->comm_lost = (octet >> 2) & 0x1; | |
838 | object->remote_forced = (octet >> 3) & 0x1; | |
839 | object->local_forced = (octet >> 4) & 0x1; | |
840 | object->chatter_filter = (octet >> 5) & 0x1; | |
841 | object->state = (octet >> 6) & 0x3; | |
842 | } | |
843 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
844 | goto error; | |
845 | } | |
846 | ||
53a8c753 | 847 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
848 | goto error; |
849 | } | |
850 | ||
851 | object = NULL; | |
53a8c753 | 852 | point_index++; |
bbaa79b8 JI |
853 | } |
854 | ||
855 | return 1; | |
856 | error: | |
857 | if (object != NULL) { | |
858 | SCFree(object); | |
859 | } | |
860 | ||
861 | return 0; | |
862 | } | |
863 | ||
864 | static int DNP3DecodeObjectG4V3(const uint8_t **buf, uint32_t *len, | |
865 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
866 | DNP3PointList *points) | |
867 | { | |
868 | DNP3ObjectG4V3 *object = NULL; | |
869 | uint32_t prefix = 0; | |
53a8c753 | 870 | uint32_t point_index = start; |
bbaa79b8 | 871 | |
8c4e53e8 PA |
872 | if (*len < count/8) { |
873 | goto error; | |
874 | } | |
bbaa79b8 JI |
875 | while (count--) { |
876 | ||
877 | object = SCCalloc(1, sizeof(*object)); | |
878 | if (unlikely(object == NULL)) { | |
879 | goto error; | |
880 | } | |
881 | ||
882 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
883 | goto error; | |
884 | } | |
885 | ||
886 | { | |
887 | uint8_t octet; | |
888 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
889 | goto error; | |
890 | } | |
891 | object->online = (octet >> 0) & 0x1; | |
892 | object->restart = (octet >> 1) & 0x1; | |
893 | object->comm_lost = (octet >> 2) & 0x1; | |
894 | object->remote_forced = (octet >> 3) & 0x1; | |
895 | object->local_forced = (octet >> 4) & 0x1; | |
896 | object->chatter_filter = (octet >> 5) & 0x1; | |
897 | object->state = (octet >> 6) & 0x3; | |
898 | } | |
899 | if (!DNP3ReadUint16(buf, len, &object->relative_time_ms)) { | |
900 | goto error; | |
901 | } | |
902 | ||
53a8c753 | 903 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
904 | goto error; |
905 | } | |
906 | ||
907 | object = NULL; | |
53a8c753 | 908 | point_index++; |
bbaa79b8 JI |
909 | } |
910 | ||
911 | return 1; | |
912 | error: | |
913 | if (object != NULL) { | |
914 | SCFree(object); | |
915 | } | |
916 | ||
917 | return 0; | |
918 | } | |
919 | ||
920 | static int DNP3DecodeObjectG10V1(const uint8_t **buf, uint32_t *len, | |
921 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
922 | DNP3PointList *points) | |
923 | { | |
924 | DNP3ObjectG10V1 *object = NULL; | |
8c4e53e8 | 925 | uint32_t bytes = (count / 8) + 1; |
bbaa79b8 | 926 | uint32_t prefix = 0; |
8c4e53e8 | 927 | uint32_t point_index = start; |
bbaa79b8 JI |
928 | |
929 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
930 | goto error; | |
931 | } | |
932 | ||
8c4e53e8 | 933 | for (uint32_t i = 0; i < bytes; i++) { |
bbaa79b8 JI |
934 | |
935 | uint8_t octet; | |
936 | ||
937 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
938 | goto error; | |
939 | } | |
940 | ||
941 | for (int j = 0; j < 8 && count; j = j + 1) { | |
942 | ||
943 | object = SCCalloc(1, sizeof(*object)); | |
944 | if (unlikely(object == NULL)) { | |
945 | goto error; | |
946 | } | |
947 | ||
948 | object->state = (octet >> j) & 0x1; | |
949 | ||
53a8c753 | 950 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
951 | goto error; |
952 | } | |
953 | ||
954 | object = NULL; | |
955 | count--; | |
53a8c753 | 956 | point_index++; |
bbaa79b8 JI |
957 | } |
958 | ||
959 | } | |
960 | ||
961 | return 1; | |
962 | error: | |
963 | if (object != NULL) { | |
964 | SCFree(object); | |
965 | } | |
966 | return 0; | |
967 | } | |
968 | ||
969 | static int DNP3DecodeObjectG10V2(const uint8_t **buf, uint32_t *len, | |
970 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
971 | DNP3PointList *points) | |
972 | { | |
973 | DNP3ObjectG10V2 *object = NULL; | |
974 | uint32_t prefix = 0; | |
53a8c753 | 975 | uint32_t point_index = start; |
bbaa79b8 | 976 | |
8c4e53e8 PA |
977 | if (*len < count/8) { |
978 | goto error; | |
979 | } | |
bbaa79b8 JI |
980 | while (count--) { |
981 | ||
982 | object = SCCalloc(1, sizeof(*object)); | |
983 | if (unlikely(object == NULL)) { | |
984 | goto error; | |
985 | } | |
986 | ||
987 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
988 | goto error; | |
989 | } | |
990 | ||
991 | { | |
992 | uint8_t octet; | |
993 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
994 | goto error; | |
995 | } | |
996 | object->online = (octet >> 0) & 0x1; | |
997 | object->restart = (octet >> 1) & 0x1; | |
998 | object->comm_lost = (octet >> 2) & 0x1; | |
999 | object->remote_forced = (octet >> 3) & 0x1; | |
1000 | object->local_forced = (octet >> 4) & 0x1; | |
1001 | object->reserved0 = (octet >> 5) & 0x1; | |
1002 | object->reserved1 = (octet >> 6) & 0x1; | |
1003 | object->state = (octet >> 7) & 0x1; | |
1004 | } | |
1005 | ||
53a8c753 | 1006 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1007 | goto error; |
1008 | } | |
1009 | ||
1010 | object = NULL; | |
53a8c753 | 1011 | point_index++; |
bbaa79b8 JI |
1012 | } |
1013 | ||
1014 | return 1; | |
1015 | error: | |
1016 | if (object != NULL) { | |
1017 | SCFree(object); | |
1018 | } | |
1019 | ||
1020 | return 0; | |
1021 | } | |
1022 | ||
1023 | static int DNP3DecodeObjectG11V1(const uint8_t **buf, uint32_t *len, | |
1024 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1025 | DNP3PointList *points) | |
1026 | { | |
1027 | DNP3ObjectG11V1 *object = NULL; | |
1028 | uint32_t prefix = 0; | |
53a8c753 | 1029 | uint32_t point_index = start; |
bbaa79b8 | 1030 | |
8c4e53e8 PA |
1031 | if (*len < count/8) { |
1032 | goto error; | |
1033 | } | |
bbaa79b8 JI |
1034 | while (count--) { |
1035 | ||
1036 | object = SCCalloc(1, sizeof(*object)); | |
1037 | if (unlikely(object == NULL)) { | |
1038 | goto error; | |
1039 | } | |
1040 | ||
1041 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1042 | goto error; | |
1043 | } | |
1044 | ||
1045 | { | |
1046 | uint8_t octet; | |
1047 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1048 | goto error; | |
1049 | } | |
1050 | object->online = (octet >> 0) & 0x1; | |
1051 | object->restart = (octet >> 1) & 0x1; | |
1052 | object->comm_lost = (octet >> 2) & 0x1; | |
1053 | object->remote_forced = (octet >> 3) & 0x1; | |
1054 | object->local_forced = (octet >> 4) & 0x1; | |
1055 | object->reserved0 = (octet >> 5) & 0x1; | |
1056 | object->reserved1 = (octet >> 6) & 0x1; | |
1057 | object->state = (octet >> 7) & 0x1; | |
1058 | } | |
1059 | ||
53a8c753 | 1060 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1061 | goto error; |
1062 | } | |
1063 | ||
1064 | object = NULL; | |
53a8c753 | 1065 | point_index++; |
bbaa79b8 JI |
1066 | } |
1067 | ||
1068 | return 1; | |
1069 | error: | |
1070 | if (object != NULL) { | |
1071 | SCFree(object); | |
1072 | } | |
1073 | ||
1074 | return 0; | |
1075 | } | |
1076 | ||
1077 | static int DNP3DecodeObjectG11V2(const uint8_t **buf, uint32_t *len, | |
1078 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1079 | DNP3PointList *points) | |
1080 | { | |
1081 | DNP3ObjectG11V2 *object = NULL; | |
1082 | uint32_t prefix = 0; | |
53a8c753 | 1083 | uint32_t point_index = start; |
bbaa79b8 | 1084 | |
8c4e53e8 PA |
1085 | if (*len < count/8) { |
1086 | goto error; | |
1087 | } | |
bbaa79b8 JI |
1088 | while (count--) { |
1089 | ||
1090 | object = SCCalloc(1, sizeof(*object)); | |
1091 | if (unlikely(object == NULL)) { | |
1092 | goto error; | |
1093 | } | |
1094 | ||
1095 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1096 | goto error; | |
1097 | } | |
1098 | ||
1099 | { | |
1100 | uint8_t octet; | |
1101 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1102 | goto error; | |
1103 | } | |
1104 | object->online = (octet >> 0) & 0x1; | |
1105 | object->restart = (octet >> 1) & 0x1; | |
1106 | object->comm_lost = (octet >> 2) & 0x1; | |
1107 | object->remote_forced = (octet >> 3) & 0x1; | |
1108 | object->local_forced = (octet >> 4) & 0x1; | |
1109 | object->reserved0 = (octet >> 5) & 0x1; | |
1110 | object->reserved1 = (octet >> 6) & 0x1; | |
1111 | object->state = (octet >> 7) & 0x1; | |
1112 | } | |
1113 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
1114 | goto error; | |
1115 | } | |
1116 | ||
53a8c753 | 1117 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1118 | goto error; |
1119 | } | |
1120 | ||
1121 | object = NULL; | |
53a8c753 | 1122 | point_index++; |
bbaa79b8 JI |
1123 | } |
1124 | ||
1125 | return 1; | |
1126 | error: | |
1127 | if (object != NULL) { | |
1128 | SCFree(object); | |
1129 | } | |
1130 | ||
1131 | return 0; | |
1132 | } | |
1133 | ||
1134 | static int DNP3DecodeObjectG12V1(const uint8_t **buf, uint32_t *len, | |
1135 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1136 | DNP3PointList *points) | |
1137 | { | |
1138 | DNP3ObjectG12V1 *object = NULL; | |
1139 | uint32_t prefix = 0; | |
53a8c753 | 1140 | uint32_t point_index = start; |
bbaa79b8 | 1141 | |
8c4e53e8 PA |
1142 | if (*len < count/8) { |
1143 | goto error; | |
1144 | } | |
bbaa79b8 JI |
1145 | while (count--) { |
1146 | ||
1147 | object = SCCalloc(1, sizeof(*object)); | |
1148 | if (unlikely(object == NULL)) { | |
1149 | goto error; | |
1150 | } | |
1151 | ||
1152 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1153 | goto error; | |
1154 | } | |
1155 | ||
1156 | { | |
1157 | uint8_t octet; | |
1158 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1159 | goto error; | |
1160 | } | |
1161 | object->op_type = (octet >> 0) & 0xf; | |
1162 | object->qu = (octet >> 4) & 0x1; | |
1163 | object->cr = (octet >> 5) & 0x1; | |
1164 | object->tcc = (octet >> 6) & 0x3; | |
1165 | } | |
1166 | if (!DNP3ReadUint8(buf, len, &object->count)) { | |
1167 | goto error; | |
1168 | } | |
1169 | if (!DNP3ReadUint32(buf, len, &object->ontime)) { | |
1170 | goto error; | |
1171 | } | |
1172 | if (!DNP3ReadUint32(buf, len, &object->offtime)) { | |
1173 | goto error; | |
1174 | } | |
1175 | { | |
1176 | uint8_t octet; | |
1177 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1178 | goto error; | |
1179 | } | |
1180 | object->status_code = (octet >> 0) & 0x7f; | |
1181 | object->reserved = (octet >> 7) & 0x1; | |
1182 | } | |
1183 | ||
53a8c753 | 1184 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1185 | goto error; |
1186 | } | |
1187 | ||
1188 | object = NULL; | |
53a8c753 | 1189 | point_index++; |
bbaa79b8 JI |
1190 | } |
1191 | ||
1192 | return 1; | |
1193 | error: | |
1194 | if (object != NULL) { | |
1195 | SCFree(object); | |
1196 | } | |
1197 | ||
1198 | return 0; | |
1199 | } | |
1200 | ||
1201 | static int DNP3DecodeObjectG12V2(const uint8_t **buf, uint32_t *len, | |
1202 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1203 | DNP3PointList *points) | |
1204 | { | |
1205 | DNP3ObjectG12V2 *object = NULL; | |
1206 | uint32_t prefix = 0; | |
53a8c753 | 1207 | uint32_t point_index = start; |
bbaa79b8 | 1208 | |
8c4e53e8 PA |
1209 | if (*len < count/8) { |
1210 | goto error; | |
1211 | } | |
bbaa79b8 JI |
1212 | while (count--) { |
1213 | ||
1214 | object = SCCalloc(1, sizeof(*object)); | |
1215 | if (unlikely(object == NULL)) { | |
1216 | goto error; | |
1217 | } | |
1218 | ||
1219 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1220 | goto error; | |
1221 | } | |
1222 | ||
1223 | { | |
1224 | uint8_t octet; | |
1225 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1226 | goto error; | |
1227 | } | |
1228 | object->op_type = (octet >> 0) & 0xf; | |
1229 | object->qu = (octet >> 4) & 0x1; | |
1230 | object->cr = (octet >> 5) & 0x1; | |
1231 | object->tcc = (octet >> 6) & 0x3; | |
1232 | } | |
1233 | if (!DNP3ReadUint8(buf, len, &object->count)) { | |
1234 | goto error; | |
1235 | } | |
1236 | if (!DNP3ReadUint32(buf, len, &object->ontime)) { | |
1237 | goto error; | |
1238 | } | |
1239 | if (!DNP3ReadUint32(buf, len, &object->offtime)) { | |
1240 | goto error; | |
1241 | } | |
1242 | { | |
1243 | uint8_t octet; | |
1244 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1245 | goto error; | |
1246 | } | |
1247 | object->status_code = (octet >> 0) & 0x7f; | |
1248 | object->reserved = (octet >> 7) & 0x1; | |
1249 | } | |
1250 | ||
53a8c753 | 1251 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1252 | goto error; |
1253 | } | |
1254 | ||
1255 | object = NULL; | |
53a8c753 | 1256 | point_index++; |
bbaa79b8 JI |
1257 | } |
1258 | ||
1259 | return 1; | |
1260 | error: | |
1261 | if (object != NULL) { | |
1262 | SCFree(object); | |
1263 | } | |
1264 | ||
1265 | return 0; | |
1266 | } | |
1267 | ||
1268 | static int DNP3DecodeObjectG12V3(const uint8_t **buf, uint32_t *len, | |
1269 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1270 | DNP3PointList *points) | |
1271 | { | |
1272 | DNP3ObjectG12V3 *object = NULL; | |
8c4e53e8 | 1273 | uint32_t bytes = (count / 8) + 1; |
bbaa79b8 | 1274 | uint32_t prefix = 0; |
8c4e53e8 | 1275 | uint32_t point_index = start; |
bbaa79b8 JI |
1276 | |
1277 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1278 | goto error; | |
1279 | } | |
1280 | ||
8c4e53e8 | 1281 | for (uint32_t i = 0; i < bytes; i++) { |
bbaa79b8 JI |
1282 | |
1283 | uint8_t octet; | |
1284 | ||
1285 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1286 | goto error; | |
1287 | } | |
1288 | ||
1289 | for (int j = 0; j < 8 && count; j = j + 1) { | |
1290 | ||
1291 | object = SCCalloc(1, sizeof(*object)); | |
1292 | if (unlikely(object == NULL)) { | |
1293 | goto error; | |
1294 | } | |
1295 | ||
1296 | object->point = (octet >> j) & 0x1; | |
1297 | ||
53a8c753 | 1298 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1299 | goto error; |
1300 | } | |
1301 | ||
1302 | object = NULL; | |
1303 | count--; | |
53a8c753 | 1304 | point_index++; |
bbaa79b8 JI |
1305 | } |
1306 | ||
1307 | } | |
1308 | ||
1309 | return 1; | |
1310 | error: | |
1311 | if (object != NULL) { | |
1312 | SCFree(object); | |
1313 | } | |
1314 | return 0; | |
1315 | } | |
1316 | ||
1317 | static int DNP3DecodeObjectG13V1(const uint8_t **buf, uint32_t *len, | |
1318 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1319 | DNP3PointList *points) | |
1320 | { | |
1321 | DNP3ObjectG13V1 *object = NULL; | |
1322 | uint32_t prefix = 0; | |
53a8c753 | 1323 | uint32_t point_index = start; |
bbaa79b8 | 1324 | |
8c4e53e8 PA |
1325 | if (*len < count/8) { |
1326 | goto error; | |
1327 | } | |
bbaa79b8 JI |
1328 | while (count--) { |
1329 | ||
1330 | object = SCCalloc(1, sizeof(*object)); | |
1331 | if (unlikely(object == NULL)) { | |
1332 | goto error; | |
1333 | } | |
1334 | ||
1335 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1336 | goto error; | |
1337 | } | |
1338 | ||
1339 | { | |
1340 | uint8_t octet; | |
1341 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1342 | goto error; | |
1343 | } | |
1344 | object->status_code = (octet >> 0) & 0x7f; | |
1345 | object->commanded_state = (octet >> 7) & 0x1; | |
1346 | } | |
1347 | ||
53a8c753 | 1348 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1349 | goto error; |
1350 | } | |
1351 | ||
1352 | object = NULL; | |
53a8c753 | 1353 | point_index++; |
bbaa79b8 JI |
1354 | } |
1355 | ||
1356 | return 1; | |
1357 | error: | |
1358 | if (object != NULL) { | |
1359 | SCFree(object); | |
1360 | } | |
1361 | ||
1362 | return 0; | |
1363 | } | |
1364 | ||
1365 | static int DNP3DecodeObjectG13V2(const uint8_t **buf, uint32_t *len, | |
1366 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1367 | DNP3PointList *points) | |
1368 | { | |
1369 | DNP3ObjectG13V2 *object = NULL; | |
1370 | uint32_t prefix = 0; | |
53a8c753 | 1371 | uint32_t point_index = start; |
bbaa79b8 | 1372 | |
8c4e53e8 PA |
1373 | if (*len < count/8) { |
1374 | goto error; | |
1375 | } | |
bbaa79b8 JI |
1376 | while (count--) { |
1377 | ||
1378 | object = SCCalloc(1, sizeof(*object)); | |
1379 | if (unlikely(object == NULL)) { | |
1380 | goto error; | |
1381 | } | |
1382 | ||
1383 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1384 | goto error; | |
1385 | } | |
1386 | ||
1387 | { | |
1388 | uint8_t octet; | |
1389 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1390 | goto error; | |
1391 | } | |
1392 | object->status_code = (octet >> 0) & 0x7f; | |
1393 | object->commanded_state = (octet >> 7) & 0x1; | |
1394 | } | |
1395 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
1396 | goto error; | |
1397 | } | |
1398 | ||
53a8c753 | 1399 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1400 | goto error; |
1401 | } | |
1402 | ||
1403 | object = NULL; | |
53a8c753 | 1404 | point_index++; |
bbaa79b8 JI |
1405 | } |
1406 | ||
1407 | return 1; | |
1408 | error: | |
1409 | if (object != NULL) { | |
1410 | SCFree(object); | |
1411 | } | |
1412 | ||
1413 | return 0; | |
1414 | } | |
1415 | ||
1416 | static int DNP3DecodeObjectG20V1(const uint8_t **buf, uint32_t *len, | |
1417 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1418 | DNP3PointList *points) | |
1419 | { | |
1420 | DNP3ObjectG20V1 *object = NULL; | |
1421 | uint32_t prefix = 0; | |
53a8c753 | 1422 | uint32_t point_index = start; |
bbaa79b8 | 1423 | |
8c4e53e8 PA |
1424 | if (*len < count/8) { |
1425 | goto error; | |
1426 | } | |
bbaa79b8 JI |
1427 | while (count--) { |
1428 | ||
1429 | object = SCCalloc(1, sizeof(*object)); | |
1430 | if (unlikely(object == NULL)) { | |
1431 | goto error; | |
1432 | } | |
1433 | ||
1434 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1435 | goto error; | |
1436 | } | |
1437 | ||
1438 | { | |
1439 | uint8_t octet; | |
1440 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1441 | goto error; | |
1442 | } | |
1443 | object->online = (octet >> 0) & 0x1; | |
1444 | object->restart = (octet >> 1) & 0x1; | |
1445 | object->comm_lost = (octet >> 2) & 0x1; | |
1446 | object->remote_forced = (octet >> 3) & 0x1; | |
1447 | object->local_forced = (octet >> 4) & 0x1; | |
1448 | object->rollover = (octet >> 5) & 0x1; | |
1449 | object->discontinuity = (octet >> 6) & 0x1; | |
1450 | object->reserved0 = (octet >> 7) & 0x1; | |
1451 | } | |
1452 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1453 | goto error; | |
1454 | } | |
1455 | ||
53a8c753 | 1456 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1457 | goto error; |
1458 | } | |
1459 | ||
1460 | object = NULL; | |
53a8c753 | 1461 | point_index++; |
bbaa79b8 JI |
1462 | } |
1463 | ||
1464 | return 1; | |
1465 | error: | |
1466 | if (object != NULL) { | |
1467 | SCFree(object); | |
1468 | } | |
1469 | ||
1470 | return 0; | |
1471 | } | |
1472 | ||
1473 | static int DNP3DecodeObjectG20V2(const uint8_t **buf, uint32_t *len, | |
1474 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1475 | DNP3PointList *points) | |
1476 | { | |
1477 | DNP3ObjectG20V2 *object = NULL; | |
1478 | uint32_t prefix = 0; | |
53a8c753 | 1479 | uint32_t point_index = start; |
bbaa79b8 | 1480 | |
8c4e53e8 PA |
1481 | if (*len < count/8) { |
1482 | goto error; | |
1483 | } | |
bbaa79b8 JI |
1484 | while (count--) { |
1485 | ||
1486 | object = SCCalloc(1, sizeof(*object)); | |
1487 | if (unlikely(object == NULL)) { | |
1488 | goto error; | |
1489 | } | |
1490 | ||
1491 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1492 | goto error; | |
1493 | } | |
1494 | ||
1495 | { | |
1496 | uint8_t octet; | |
1497 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1498 | goto error; | |
1499 | } | |
1500 | object->online = (octet >> 0) & 0x1; | |
1501 | object->restart = (octet >> 1) & 0x1; | |
1502 | object->comm_lost = (octet >> 2) & 0x1; | |
1503 | object->remote_forced = (octet >> 3) & 0x1; | |
1504 | object->local_forced = (octet >> 4) & 0x1; | |
1505 | object->rollover = (octet >> 5) & 0x1; | |
1506 | object->discontinuity = (octet >> 6) & 0x1; | |
1507 | object->reserved0 = (octet >> 7) & 0x1; | |
1508 | } | |
1509 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
1510 | goto error; | |
1511 | } | |
1512 | ||
53a8c753 | 1513 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1514 | goto error; |
1515 | } | |
1516 | ||
1517 | object = NULL; | |
53a8c753 | 1518 | point_index++; |
bbaa79b8 JI |
1519 | } |
1520 | ||
1521 | return 1; | |
1522 | error: | |
1523 | if (object != NULL) { | |
1524 | SCFree(object); | |
1525 | } | |
1526 | ||
1527 | return 0; | |
1528 | } | |
1529 | ||
1530 | static int DNP3DecodeObjectG20V3(const uint8_t **buf, uint32_t *len, | |
1531 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1532 | DNP3PointList *points) | |
1533 | { | |
1534 | DNP3ObjectG20V3 *object = NULL; | |
1535 | uint32_t prefix = 0; | |
53a8c753 | 1536 | uint32_t point_index = start; |
bbaa79b8 | 1537 | |
8c4e53e8 PA |
1538 | if (*len < count/8) { |
1539 | goto error; | |
1540 | } | |
bbaa79b8 JI |
1541 | while (count--) { |
1542 | ||
1543 | object = SCCalloc(1, sizeof(*object)); | |
1544 | if (unlikely(object == NULL)) { | |
1545 | goto error; | |
1546 | } | |
1547 | ||
1548 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1549 | goto error; | |
1550 | } | |
1551 | ||
1552 | { | |
1553 | uint8_t octet; | |
1554 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1555 | goto error; | |
1556 | } | |
1557 | object->online = (octet >> 0) & 0x1; | |
1558 | object->restart = (octet >> 1) & 0x1; | |
1559 | object->comm_lost = (octet >> 2) & 0x1; | |
1560 | object->remote_forced = (octet >> 3) & 0x1; | |
1561 | object->local_forced = (octet >> 4) & 0x1; | |
1562 | object->rollover = (octet >> 5) & 0x1; | |
1563 | object->reserved0 = (octet >> 6) & 0x1; | |
1564 | object->reserved1 = (octet >> 7) & 0x1; | |
1565 | } | |
1566 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1567 | goto error; | |
1568 | } | |
1569 | ||
53a8c753 | 1570 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1571 | goto error; |
1572 | } | |
1573 | ||
1574 | object = NULL; | |
53a8c753 | 1575 | point_index++; |
bbaa79b8 JI |
1576 | } |
1577 | ||
1578 | return 1; | |
1579 | error: | |
1580 | if (object != NULL) { | |
1581 | SCFree(object); | |
1582 | } | |
1583 | ||
1584 | return 0; | |
1585 | } | |
1586 | ||
1587 | static int DNP3DecodeObjectG20V4(const uint8_t **buf, uint32_t *len, | |
1588 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1589 | DNP3PointList *points) | |
1590 | { | |
1591 | DNP3ObjectG20V4 *object = NULL; | |
1592 | uint32_t prefix = 0; | |
53a8c753 | 1593 | uint32_t point_index = start; |
bbaa79b8 | 1594 | |
8c4e53e8 PA |
1595 | if (*len < count/8) { |
1596 | goto error; | |
1597 | } | |
bbaa79b8 JI |
1598 | while (count--) { |
1599 | ||
1600 | object = SCCalloc(1, sizeof(*object)); | |
1601 | if (unlikely(object == NULL)) { | |
1602 | goto error; | |
1603 | } | |
1604 | ||
1605 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1606 | goto error; | |
1607 | } | |
1608 | ||
1609 | { | |
1610 | uint8_t octet; | |
1611 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1612 | goto error; | |
1613 | } | |
1614 | object->online = (octet >> 0) & 0x1; | |
1615 | object->restart = (octet >> 1) & 0x1; | |
1616 | object->comm_lost = (octet >> 2) & 0x1; | |
1617 | object->remote_forced = (octet >> 3) & 0x1; | |
1618 | object->local_forced = (octet >> 4) & 0x1; | |
1619 | object->rollover = (octet >> 5) & 0x1; | |
1620 | object->reserved0 = (octet >> 6) & 0x1; | |
1621 | object->reserved1 = (octet >> 7) & 0x1; | |
1622 | } | |
1623 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
1624 | goto error; | |
1625 | } | |
1626 | ||
53a8c753 | 1627 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1628 | goto error; |
1629 | } | |
1630 | ||
1631 | object = NULL; | |
53a8c753 | 1632 | point_index++; |
bbaa79b8 JI |
1633 | } |
1634 | ||
1635 | return 1; | |
1636 | error: | |
1637 | if (object != NULL) { | |
1638 | SCFree(object); | |
1639 | } | |
1640 | ||
1641 | return 0; | |
1642 | } | |
1643 | ||
1644 | static int DNP3DecodeObjectG20V5(const uint8_t **buf, uint32_t *len, | |
1645 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1646 | DNP3PointList *points) | |
1647 | { | |
1648 | DNP3ObjectG20V5 *object = NULL; | |
1649 | uint32_t prefix = 0; | |
53a8c753 | 1650 | uint32_t point_index = start; |
bbaa79b8 | 1651 | |
8c4e53e8 PA |
1652 | if (*len < count/8) { |
1653 | goto error; | |
1654 | } | |
bbaa79b8 JI |
1655 | while (count--) { |
1656 | ||
1657 | object = SCCalloc(1, sizeof(*object)); | |
1658 | if (unlikely(object == NULL)) { | |
1659 | goto error; | |
1660 | } | |
1661 | ||
1662 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1663 | goto error; | |
1664 | } | |
1665 | ||
1666 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1667 | goto error; | |
1668 | } | |
1669 | ||
53a8c753 | 1670 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1671 | goto error; |
1672 | } | |
1673 | ||
1674 | object = NULL; | |
53a8c753 | 1675 | point_index++; |
bbaa79b8 JI |
1676 | } |
1677 | ||
1678 | return 1; | |
1679 | error: | |
1680 | if (object != NULL) { | |
1681 | SCFree(object); | |
1682 | } | |
1683 | ||
1684 | return 0; | |
1685 | } | |
1686 | ||
1687 | static int DNP3DecodeObjectG20V6(const uint8_t **buf, uint32_t *len, | |
1688 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1689 | DNP3PointList *points) | |
1690 | { | |
1691 | DNP3ObjectG20V6 *object = NULL; | |
1692 | uint32_t prefix = 0; | |
53a8c753 | 1693 | uint32_t point_index = start; |
bbaa79b8 | 1694 | |
8c4e53e8 PA |
1695 | if (*len < count/8) { |
1696 | goto error; | |
1697 | } | |
bbaa79b8 JI |
1698 | while (count--) { |
1699 | ||
1700 | object = SCCalloc(1, sizeof(*object)); | |
1701 | if (unlikely(object == NULL)) { | |
1702 | goto error; | |
1703 | } | |
1704 | ||
1705 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1706 | goto error; | |
1707 | } | |
1708 | ||
1709 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
1710 | goto error; | |
1711 | } | |
1712 | ||
53a8c753 | 1713 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1714 | goto error; |
1715 | } | |
1716 | ||
1717 | object = NULL; | |
53a8c753 | 1718 | point_index++; |
bbaa79b8 JI |
1719 | } |
1720 | ||
1721 | return 1; | |
1722 | error: | |
1723 | if (object != NULL) { | |
1724 | SCFree(object); | |
1725 | } | |
1726 | ||
1727 | return 0; | |
1728 | } | |
1729 | ||
1730 | static int DNP3DecodeObjectG20V7(const uint8_t **buf, uint32_t *len, | |
1731 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1732 | DNP3PointList *points) | |
1733 | { | |
1734 | DNP3ObjectG20V7 *object = NULL; | |
1735 | uint32_t prefix = 0; | |
53a8c753 | 1736 | uint32_t point_index = start; |
bbaa79b8 | 1737 | |
8c4e53e8 PA |
1738 | if (*len < count/8) { |
1739 | goto error; | |
1740 | } | |
bbaa79b8 JI |
1741 | while (count--) { |
1742 | ||
1743 | object = SCCalloc(1, sizeof(*object)); | |
1744 | if (unlikely(object == NULL)) { | |
1745 | goto error; | |
1746 | } | |
1747 | ||
1748 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1749 | goto error; | |
1750 | } | |
1751 | ||
1752 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1753 | goto error; | |
1754 | } | |
1755 | ||
53a8c753 | 1756 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1757 | goto error; |
1758 | } | |
1759 | ||
1760 | object = NULL; | |
53a8c753 | 1761 | point_index++; |
bbaa79b8 JI |
1762 | } |
1763 | ||
1764 | return 1; | |
1765 | error: | |
1766 | if (object != NULL) { | |
1767 | SCFree(object); | |
1768 | } | |
1769 | ||
1770 | return 0; | |
1771 | } | |
1772 | ||
1773 | static int DNP3DecodeObjectG20V8(const uint8_t **buf, uint32_t *len, | |
1774 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1775 | DNP3PointList *points) | |
1776 | { | |
1777 | DNP3ObjectG20V8 *object = NULL; | |
1778 | uint32_t prefix = 0; | |
53a8c753 | 1779 | uint32_t point_index = start; |
bbaa79b8 | 1780 | |
8c4e53e8 PA |
1781 | if (*len < count/8) { |
1782 | goto error; | |
1783 | } | |
bbaa79b8 JI |
1784 | while (count--) { |
1785 | ||
1786 | object = SCCalloc(1, sizeof(*object)); | |
1787 | if (unlikely(object == NULL)) { | |
1788 | goto error; | |
1789 | } | |
1790 | ||
1791 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1792 | goto error; | |
1793 | } | |
1794 | ||
1795 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
1796 | goto error; | |
1797 | } | |
1798 | ||
53a8c753 | 1799 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1800 | goto error; |
1801 | } | |
1802 | ||
1803 | object = NULL; | |
53a8c753 | 1804 | point_index++; |
bbaa79b8 JI |
1805 | } |
1806 | ||
1807 | return 1; | |
1808 | error: | |
1809 | if (object != NULL) { | |
1810 | SCFree(object); | |
1811 | } | |
1812 | ||
1813 | return 0; | |
1814 | } | |
1815 | ||
1816 | static int DNP3DecodeObjectG21V1(const uint8_t **buf, uint32_t *len, | |
1817 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1818 | DNP3PointList *points) | |
1819 | { | |
1820 | DNP3ObjectG21V1 *object = NULL; | |
1821 | uint32_t prefix = 0; | |
53a8c753 | 1822 | uint32_t point_index = start; |
bbaa79b8 | 1823 | |
8c4e53e8 PA |
1824 | if (*len < count/8) { |
1825 | goto error; | |
1826 | } | |
bbaa79b8 JI |
1827 | while (count--) { |
1828 | ||
1829 | object = SCCalloc(1, sizeof(*object)); | |
1830 | if (unlikely(object == NULL)) { | |
1831 | goto error; | |
1832 | } | |
1833 | ||
1834 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1835 | goto error; | |
1836 | } | |
1837 | ||
1838 | { | |
1839 | uint8_t octet; | |
1840 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1841 | goto error; | |
1842 | } | |
1843 | object->online = (octet >> 0) & 0x1; | |
1844 | object->restart = (octet >> 1) & 0x1; | |
1845 | object->comm_lost = (octet >> 2) & 0x1; | |
1846 | object->remote_forced = (octet >> 3) & 0x1; | |
1847 | object->local_forced = (octet >> 4) & 0x1; | |
1848 | object->rollover = (octet >> 5) & 0x1; | |
1849 | object->discontinuity = (octet >> 6) & 0x1; | |
1850 | object->reserved0 = (octet >> 7) & 0x1; | |
1851 | } | |
1852 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1853 | goto error; | |
1854 | } | |
1855 | ||
53a8c753 | 1856 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1857 | goto error; |
1858 | } | |
1859 | ||
1860 | object = NULL; | |
53a8c753 | 1861 | point_index++; |
bbaa79b8 JI |
1862 | } |
1863 | ||
1864 | return 1; | |
1865 | error: | |
1866 | if (object != NULL) { | |
1867 | SCFree(object); | |
1868 | } | |
1869 | ||
1870 | return 0; | |
1871 | } | |
1872 | ||
1873 | static int DNP3DecodeObjectG21V2(const uint8_t **buf, uint32_t *len, | |
1874 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1875 | DNP3PointList *points) | |
1876 | { | |
1877 | DNP3ObjectG21V2 *object = NULL; | |
1878 | uint32_t prefix = 0; | |
53a8c753 | 1879 | uint32_t point_index = start; |
bbaa79b8 | 1880 | |
8c4e53e8 PA |
1881 | if (*len < count/8) { |
1882 | goto error; | |
1883 | } | |
bbaa79b8 JI |
1884 | while (count--) { |
1885 | ||
1886 | object = SCCalloc(1, sizeof(*object)); | |
1887 | if (unlikely(object == NULL)) { | |
1888 | goto error; | |
1889 | } | |
1890 | ||
1891 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1892 | goto error; | |
1893 | } | |
1894 | ||
1895 | { | |
1896 | uint8_t octet; | |
1897 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1898 | goto error; | |
1899 | } | |
1900 | object->online = (octet >> 0) & 0x1; | |
1901 | object->restart = (octet >> 1) & 0x1; | |
1902 | object->comm_lost = (octet >> 2) & 0x1; | |
1903 | object->remote_forced = (octet >> 3) & 0x1; | |
1904 | object->local_forced = (octet >> 4) & 0x1; | |
1905 | object->rollover = (octet >> 5) & 0x1; | |
1906 | object->discontinuity = (octet >> 6) & 0x1; | |
1907 | object->reserved0 = (octet >> 7) & 0x1; | |
1908 | } | |
1909 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
1910 | goto error; | |
1911 | } | |
1912 | ||
53a8c753 | 1913 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1914 | goto error; |
1915 | } | |
1916 | ||
1917 | object = NULL; | |
53a8c753 | 1918 | point_index++; |
bbaa79b8 JI |
1919 | } |
1920 | ||
1921 | return 1; | |
1922 | error: | |
1923 | if (object != NULL) { | |
1924 | SCFree(object); | |
1925 | } | |
1926 | ||
1927 | return 0; | |
1928 | } | |
1929 | ||
1930 | static int DNP3DecodeObjectG21V3(const uint8_t **buf, uint32_t *len, | |
1931 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1932 | DNP3PointList *points) | |
1933 | { | |
1934 | DNP3ObjectG21V3 *object = NULL; | |
1935 | uint32_t prefix = 0; | |
53a8c753 | 1936 | uint32_t point_index = start; |
bbaa79b8 | 1937 | |
8c4e53e8 PA |
1938 | if (*len < count/8) { |
1939 | goto error; | |
1940 | } | |
bbaa79b8 JI |
1941 | while (count--) { |
1942 | ||
1943 | object = SCCalloc(1, sizeof(*object)); | |
1944 | if (unlikely(object == NULL)) { | |
1945 | goto error; | |
1946 | } | |
1947 | ||
1948 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
1949 | goto error; | |
1950 | } | |
1951 | ||
1952 | { | |
1953 | uint8_t octet; | |
1954 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
1955 | goto error; | |
1956 | } | |
1957 | object->online = (octet >> 0) & 0x1; | |
1958 | object->restart = (octet >> 1) & 0x1; | |
1959 | object->comm_lost = (octet >> 2) & 0x1; | |
1960 | object->remote_forced = (octet >> 3) & 0x1; | |
1961 | object->local_forced = (octet >> 4) & 0x1; | |
1962 | object->rollover = (octet >> 5) & 0x1; | |
1963 | object->reserved0 = (octet >> 6) & 0x1; | |
1964 | object->reserved1 = (octet >> 7) & 0x1; | |
1965 | } | |
1966 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
1967 | goto error; | |
1968 | } | |
1969 | ||
53a8c753 | 1970 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
1971 | goto error; |
1972 | } | |
1973 | ||
1974 | object = NULL; | |
53a8c753 | 1975 | point_index++; |
bbaa79b8 JI |
1976 | } |
1977 | ||
1978 | return 1; | |
1979 | error: | |
1980 | if (object != NULL) { | |
1981 | SCFree(object); | |
1982 | } | |
1983 | ||
1984 | return 0; | |
1985 | } | |
1986 | ||
1987 | static int DNP3DecodeObjectG21V4(const uint8_t **buf, uint32_t *len, | |
1988 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
1989 | DNP3PointList *points) | |
1990 | { | |
1991 | DNP3ObjectG21V4 *object = NULL; | |
1992 | uint32_t prefix = 0; | |
53a8c753 | 1993 | uint32_t point_index = start; |
bbaa79b8 | 1994 | |
8c4e53e8 PA |
1995 | if (*len < count/8) { |
1996 | goto error; | |
1997 | } | |
bbaa79b8 JI |
1998 | while (count--) { |
1999 | ||
2000 | object = SCCalloc(1, sizeof(*object)); | |
2001 | if (unlikely(object == NULL)) { | |
2002 | goto error; | |
2003 | } | |
2004 | ||
2005 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2006 | goto error; | |
2007 | } | |
2008 | ||
2009 | { | |
2010 | uint8_t octet; | |
2011 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2012 | goto error; | |
2013 | } | |
2014 | object->online = (octet >> 0) & 0x1; | |
2015 | object->restart = (octet >> 1) & 0x1; | |
2016 | object->comm_lost = (octet >> 2) & 0x1; | |
2017 | object->remote_forced = (octet >> 3) & 0x1; | |
2018 | object->local_forced = (octet >> 4) & 0x1; | |
2019 | object->rollover = (octet >> 5) & 0x1; | |
2020 | object->reserved0 = (octet >> 6) & 0x1; | |
2021 | object->reserved1 = (octet >> 7) & 0x1; | |
2022 | } | |
2023 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2024 | goto error; | |
2025 | } | |
2026 | ||
53a8c753 | 2027 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2028 | goto error; |
2029 | } | |
2030 | ||
2031 | object = NULL; | |
53a8c753 | 2032 | point_index++; |
bbaa79b8 JI |
2033 | } |
2034 | ||
2035 | return 1; | |
2036 | error: | |
2037 | if (object != NULL) { | |
2038 | SCFree(object); | |
2039 | } | |
2040 | ||
2041 | return 0; | |
2042 | } | |
2043 | ||
2044 | static int DNP3DecodeObjectG21V5(const uint8_t **buf, uint32_t *len, | |
2045 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2046 | DNP3PointList *points) | |
2047 | { | |
2048 | DNP3ObjectG21V5 *object = NULL; | |
2049 | uint32_t prefix = 0; | |
53a8c753 | 2050 | uint32_t point_index = start; |
bbaa79b8 | 2051 | |
8c4e53e8 PA |
2052 | if (*len < count/8) { |
2053 | goto error; | |
2054 | } | |
bbaa79b8 JI |
2055 | while (count--) { |
2056 | ||
2057 | object = SCCalloc(1, sizeof(*object)); | |
2058 | if (unlikely(object == NULL)) { | |
2059 | goto error; | |
2060 | } | |
2061 | ||
2062 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2063 | goto error; | |
2064 | } | |
2065 | ||
2066 | { | |
2067 | uint8_t octet; | |
2068 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2069 | goto error; | |
2070 | } | |
2071 | object->online = (octet >> 0) & 0x1; | |
2072 | object->restart = (octet >> 1) & 0x1; | |
2073 | object->comm_lost = (octet >> 2) & 0x1; | |
2074 | object->remote_forced = (octet >> 3) & 0x1; | |
2075 | object->local_forced = (octet >> 4) & 0x1; | |
2076 | object->rollover = (octet >> 5) & 0x1; | |
2077 | object->discontinuity = (octet >> 6) & 0x1; | |
2078 | object->reserved1 = (octet >> 7) & 0x1; | |
2079 | } | |
2080 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2081 | goto error; | |
2082 | } | |
2083 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2084 | goto error; | |
2085 | } | |
2086 | ||
53a8c753 | 2087 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2088 | goto error; |
2089 | } | |
2090 | ||
2091 | object = NULL; | |
53a8c753 | 2092 | point_index++; |
bbaa79b8 JI |
2093 | } |
2094 | ||
2095 | return 1; | |
2096 | error: | |
2097 | if (object != NULL) { | |
2098 | SCFree(object); | |
2099 | } | |
2100 | ||
2101 | return 0; | |
2102 | } | |
2103 | ||
2104 | static int DNP3DecodeObjectG21V6(const uint8_t **buf, uint32_t *len, | |
2105 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2106 | DNP3PointList *points) | |
2107 | { | |
2108 | DNP3ObjectG21V6 *object = NULL; | |
2109 | uint32_t prefix = 0; | |
53a8c753 | 2110 | uint32_t point_index = start; |
bbaa79b8 | 2111 | |
8c4e53e8 PA |
2112 | if (*len < count/8) { |
2113 | goto error; | |
2114 | } | |
bbaa79b8 JI |
2115 | while (count--) { |
2116 | ||
2117 | object = SCCalloc(1, sizeof(*object)); | |
2118 | if (unlikely(object == NULL)) { | |
2119 | goto error; | |
2120 | } | |
2121 | ||
2122 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2123 | goto error; | |
2124 | } | |
2125 | ||
2126 | { | |
2127 | uint8_t octet; | |
2128 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2129 | goto error; | |
2130 | } | |
2131 | object->online = (octet >> 0) & 0x1; | |
2132 | object->restart = (octet >> 1) & 0x1; | |
2133 | object->comm_lost = (octet >> 2) & 0x1; | |
2134 | object->remote_forced = (octet >> 3) & 0x1; | |
2135 | object->local_forced = (octet >> 4) & 0x1; | |
2136 | object->rollover = (octet >> 5) & 0x1; | |
2137 | object->discontinuity = (octet >> 6) & 0x1; | |
2138 | object->reserved1 = (octet >> 7) & 0x1; | |
2139 | } | |
2140 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2141 | goto error; | |
2142 | } | |
2143 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2144 | goto error; | |
2145 | } | |
2146 | ||
53a8c753 | 2147 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2148 | goto error; |
2149 | } | |
2150 | ||
2151 | object = NULL; | |
53a8c753 | 2152 | point_index++; |
bbaa79b8 JI |
2153 | } |
2154 | ||
2155 | return 1; | |
2156 | error: | |
2157 | if (object != NULL) { | |
2158 | SCFree(object); | |
2159 | } | |
2160 | ||
2161 | return 0; | |
2162 | } | |
2163 | ||
2164 | static int DNP3DecodeObjectG21V7(const uint8_t **buf, uint32_t *len, | |
2165 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2166 | DNP3PointList *points) | |
2167 | { | |
2168 | DNP3ObjectG21V7 *object = NULL; | |
2169 | uint32_t prefix = 0; | |
53a8c753 | 2170 | uint32_t point_index = start; |
bbaa79b8 | 2171 | |
8c4e53e8 PA |
2172 | if (*len < count/8) { |
2173 | goto error; | |
2174 | } | |
bbaa79b8 JI |
2175 | while (count--) { |
2176 | ||
2177 | object = SCCalloc(1, sizeof(*object)); | |
2178 | if (unlikely(object == NULL)) { | |
2179 | goto error; | |
2180 | } | |
2181 | ||
2182 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2183 | goto error; | |
2184 | } | |
2185 | ||
2186 | { | |
2187 | uint8_t octet; | |
2188 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2189 | goto error; | |
2190 | } | |
2191 | object->online = (octet >> 0) & 0x1; | |
2192 | object->restart = (octet >> 1) & 0x1; | |
2193 | object->comm_lost = (octet >> 2) & 0x1; | |
2194 | object->remote_forced = (octet >> 3) & 0x1; | |
2195 | object->local_forced = (octet >> 4) & 0x1; | |
2196 | object->rollover = (octet >> 5) & 0x1; | |
2197 | object->reserved0 = (octet >> 6) & 0x1; | |
2198 | object->reserved1 = (octet >> 7) & 0x1; | |
2199 | } | |
2200 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2201 | goto error; | |
2202 | } | |
2203 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2204 | goto error; | |
2205 | } | |
2206 | ||
53a8c753 | 2207 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2208 | goto error; |
2209 | } | |
2210 | ||
2211 | object = NULL; | |
53a8c753 | 2212 | point_index++; |
bbaa79b8 JI |
2213 | } |
2214 | ||
2215 | return 1; | |
2216 | error: | |
2217 | if (object != NULL) { | |
2218 | SCFree(object); | |
2219 | } | |
2220 | ||
2221 | return 0; | |
2222 | } | |
2223 | ||
2224 | static int DNP3DecodeObjectG21V8(const uint8_t **buf, uint32_t *len, | |
2225 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2226 | DNP3PointList *points) | |
2227 | { | |
2228 | DNP3ObjectG21V8 *object = NULL; | |
2229 | uint32_t prefix = 0; | |
53a8c753 | 2230 | uint32_t point_index = start; |
bbaa79b8 | 2231 | |
8c4e53e8 PA |
2232 | if (*len < count/8) { |
2233 | goto error; | |
2234 | } | |
bbaa79b8 JI |
2235 | while (count--) { |
2236 | ||
2237 | object = SCCalloc(1, sizeof(*object)); | |
2238 | if (unlikely(object == NULL)) { | |
2239 | goto error; | |
2240 | } | |
2241 | ||
2242 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2243 | goto error; | |
2244 | } | |
2245 | ||
2246 | { | |
2247 | uint8_t octet; | |
2248 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2249 | goto error; | |
2250 | } | |
2251 | object->online = (octet >> 0) & 0x1; | |
2252 | object->restart = (octet >> 1) & 0x1; | |
2253 | object->comm_lost = (octet >> 2) & 0x1; | |
2254 | object->remote_forced = (octet >> 3) & 0x1; | |
2255 | object->local_forced = (octet >> 4) & 0x1; | |
2256 | object->rollover = (octet >> 5) & 0x1; | |
2257 | object->reserved0 = (octet >> 6) & 0x1; | |
2258 | object->reserved1 = (octet >> 7) & 0x1; | |
2259 | } | |
2260 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2261 | goto error; | |
2262 | } | |
2263 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2264 | goto error; | |
2265 | } | |
2266 | ||
53a8c753 | 2267 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2268 | goto error; |
2269 | } | |
2270 | ||
2271 | object = NULL; | |
53a8c753 | 2272 | point_index++; |
bbaa79b8 JI |
2273 | } |
2274 | ||
2275 | return 1; | |
2276 | error: | |
2277 | if (object != NULL) { | |
2278 | SCFree(object); | |
2279 | } | |
2280 | ||
2281 | return 0; | |
2282 | } | |
2283 | ||
2284 | static int DNP3DecodeObjectG21V9(const uint8_t **buf, uint32_t *len, | |
2285 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2286 | DNP3PointList *points) | |
2287 | { | |
2288 | DNP3ObjectG21V9 *object = NULL; | |
2289 | uint32_t prefix = 0; | |
53a8c753 | 2290 | uint32_t point_index = start; |
bbaa79b8 | 2291 | |
8c4e53e8 PA |
2292 | if (*len < count/8) { |
2293 | goto error; | |
2294 | } | |
bbaa79b8 JI |
2295 | while (count--) { |
2296 | ||
2297 | object = SCCalloc(1, sizeof(*object)); | |
2298 | if (unlikely(object == NULL)) { | |
2299 | goto error; | |
2300 | } | |
2301 | ||
2302 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2303 | goto error; | |
2304 | } | |
2305 | ||
2306 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2307 | goto error; | |
2308 | } | |
2309 | ||
53a8c753 | 2310 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2311 | goto error; |
2312 | } | |
2313 | ||
2314 | object = NULL; | |
53a8c753 | 2315 | point_index++; |
bbaa79b8 JI |
2316 | } |
2317 | ||
2318 | return 1; | |
2319 | error: | |
2320 | if (object != NULL) { | |
2321 | SCFree(object); | |
2322 | } | |
2323 | ||
2324 | return 0; | |
2325 | } | |
2326 | ||
2327 | static int DNP3DecodeObjectG21V10(const uint8_t **buf, uint32_t *len, | |
2328 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2329 | DNP3PointList *points) | |
2330 | { | |
2331 | DNP3ObjectG21V10 *object = NULL; | |
2332 | uint32_t prefix = 0; | |
53a8c753 | 2333 | uint32_t point_index = start; |
bbaa79b8 | 2334 | |
8c4e53e8 PA |
2335 | if (*len < count/8) { |
2336 | goto error; | |
2337 | } | |
bbaa79b8 JI |
2338 | while (count--) { |
2339 | ||
2340 | object = SCCalloc(1, sizeof(*object)); | |
2341 | if (unlikely(object == NULL)) { | |
2342 | goto error; | |
2343 | } | |
2344 | ||
2345 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2346 | goto error; | |
2347 | } | |
2348 | ||
2349 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2350 | goto error; | |
2351 | } | |
2352 | ||
53a8c753 | 2353 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2354 | goto error; |
2355 | } | |
2356 | ||
2357 | object = NULL; | |
53a8c753 | 2358 | point_index++; |
bbaa79b8 JI |
2359 | } |
2360 | ||
2361 | return 1; | |
2362 | error: | |
2363 | if (object != NULL) { | |
2364 | SCFree(object); | |
2365 | } | |
2366 | ||
2367 | return 0; | |
2368 | } | |
2369 | ||
2370 | static int DNP3DecodeObjectG21V11(const uint8_t **buf, uint32_t *len, | |
2371 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2372 | DNP3PointList *points) | |
2373 | { | |
2374 | DNP3ObjectG21V11 *object = NULL; | |
2375 | uint32_t prefix = 0; | |
53a8c753 | 2376 | uint32_t point_index = start; |
bbaa79b8 | 2377 | |
8c4e53e8 PA |
2378 | if (*len < count/8) { |
2379 | goto error; | |
2380 | } | |
bbaa79b8 JI |
2381 | while (count--) { |
2382 | ||
2383 | object = SCCalloc(1, sizeof(*object)); | |
2384 | if (unlikely(object == NULL)) { | |
2385 | goto error; | |
2386 | } | |
2387 | ||
2388 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2389 | goto error; | |
2390 | } | |
2391 | ||
2392 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2393 | goto error; | |
2394 | } | |
2395 | ||
53a8c753 | 2396 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2397 | goto error; |
2398 | } | |
2399 | ||
2400 | object = NULL; | |
53a8c753 | 2401 | point_index++; |
bbaa79b8 JI |
2402 | } |
2403 | ||
2404 | return 1; | |
2405 | error: | |
2406 | if (object != NULL) { | |
2407 | SCFree(object); | |
2408 | } | |
2409 | ||
2410 | return 0; | |
2411 | } | |
2412 | ||
2413 | static int DNP3DecodeObjectG21V12(const uint8_t **buf, uint32_t *len, | |
2414 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2415 | DNP3PointList *points) | |
2416 | { | |
2417 | DNP3ObjectG21V12 *object = NULL; | |
2418 | uint32_t prefix = 0; | |
53a8c753 | 2419 | uint32_t point_index = start; |
bbaa79b8 | 2420 | |
8c4e53e8 PA |
2421 | if (*len < count/8) { |
2422 | goto error; | |
2423 | } | |
bbaa79b8 JI |
2424 | while (count--) { |
2425 | ||
2426 | object = SCCalloc(1, sizeof(*object)); | |
2427 | if (unlikely(object == NULL)) { | |
2428 | goto error; | |
2429 | } | |
2430 | ||
2431 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2432 | goto error; | |
2433 | } | |
2434 | ||
2435 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2436 | goto error; | |
2437 | } | |
2438 | ||
53a8c753 | 2439 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2440 | goto error; |
2441 | } | |
2442 | ||
2443 | object = NULL; | |
53a8c753 | 2444 | point_index++; |
bbaa79b8 JI |
2445 | } |
2446 | ||
2447 | return 1; | |
2448 | error: | |
2449 | if (object != NULL) { | |
2450 | SCFree(object); | |
2451 | } | |
2452 | ||
2453 | return 0; | |
2454 | } | |
2455 | ||
2456 | static int DNP3DecodeObjectG22V1(const uint8_t **buf, uint32_t *len, | |
2457 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2458 | DNP3PointList *points) | |
2459 | { | |
2460 | DNP3ObjectG22V1 *object = NULL; | |
2461 | uint32_t prefix = 0; | |
53a8c753 | 2462 | uint32_t point_index = start; |
bbaa79b8 | 2463 | |
8c4e53e8 PA |
2464 | if (*len < count/8) { |
2465 | goto error; | |
2466 | } | |
bbaa79b8 JI |
2467 | while (count--) { |
2468 | ||
2469 | object = SCCalloc(1, sizeof(*object)); | |
2470 | if (unlikely(object == NULL)) { | |
2471 | goto error; | |
2472 | } | |
2473 | ||
2474 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2475 | goto error; | |
2476 | } | |
2477 | ||
2478 | { | |
2479 | uint8_t octet; | |
2480 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2481 | goto error; | |
2482 | } | |
2483 | object->online = (octet >> 0) & 0x1; | |
2484 | object->restart = (octet >> 1) & 0x1; | |
2485 | object->comm_lost = (octet >> 2) & 0x1; | |
2486 | object->remote_forced = (octet >> 3) & 0x1; | |
2487 | object->local_forced = (octet >> 4) & 0x1; | |
2488 | object->rollover = (octet >> 5) & 0x1; | |
2489 | object->discontinuity = (octet >> 6) & 0x1; | |
2490 | object->reserved0 = (octet >> 7) & 0x1; | |
2491 | } | |
2492 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2493 | goto error; | |
2494 | } | |
2495 | ||
53a8c753 | 2496 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2497 | goto error; |
2498 | } | |
2499 | ||
2500 | object = NULL; | |
53a8c753 | 2501 | point_index++; |
bbaa79b8 JI |
2502 | } |
2503 | ||
2504 | return 1; | |
2505 | error: | |
2506 | if (object != NULL) { | |
2507 | SCFree(object); | |
2508 | } | |
2509 | ||
2510 | return 0; | |
2511 | } | |
2512 | ||
2513 | static int DNP3DecodeObjectG22V2(const uint8_t **buf, uint32_t *len, | |
2514 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2515 | DNP3PointList *points) | |
2516 | { | |
2517 | DNP3ObjectG22V2 *object = NULL; | |
2518 | uint32_t prefix = 0; | |
53a8c753 | 2519 | uint32_t point_index = start; |
bbaa79b8 | 2520 | |
8c4e53e8 PA |
2521 | if (*len < count/8) { |
2522 | goto error; | |
2523 | } | |
bbaa79b8 JI |
2524 | while (count--) { |
2525 | ||
2526 | object = SCCalloc(1, sizeof(*object)); | |
2527 | if (unlikely(object == NULL)) { | |
2528 | goto error; | |
2529 | } | |
2530 | ||
2531 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2532 | goto error; | |
2533 | } | |
2534 | ||
2535 | { | |
2536 | uint8_t octet; | |
2537 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2538 | goto error; | |
2539 | } | |
2540 | object->online = (octet >> 0) & 0x1; | |
2541 | object->restart = (octet >> 1) & 0x1; | |
2542 | object->comm_lost = (octet >> 2) & 0x1; | |
2543 | object->remote_forced = (octet >> 3) & 0x1; | |
2544 | object->local_forced = (octet >> 4) & 0x1; | |
2545 | object->rollover = (octet >> 5) & 0x1; | |
2546 | object->discontinuity = (octet >> 6) & 0x1; | |
2547 | object->reserved0 = (octet >> 7) & 0x1; | |
2548 | } | |
2549 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2550 | goto error; | |
2551 | } | |
2552 | ||
53a8c753 | 2553 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2554 | goto error; |
2555 | } | |
2556 | ||
2557 | object = NULL; | |
53a8c753 | 2558 | point_index++; |
bbaa79b8 JI |
2559 | } |
2560 | ||
2561 | return 1; | |
2562 | error: | |
2563 | if (object != NULL) { | |
2564 | SCFree(object); | |
2565 | } | |
2566 | ||
2567 | return 0; | |
2568 | } | |
2569 | ||
2570 | static int DNP3DecodeObjectG22V3(const uint8_t **buf, uint32_t *len, | |
2571 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2572 | DNP3PointList *points) | |
2573 | { | |
2574 | DNP3ObjectG22V3 *object = NULL; | |
2575 | uint32_t prefix = 0; | |
53a8c753 | 2576 | uint32_t point_index = start; |
bbaa79b8 | 2577 | |
8c4e53e8 PA |
2578 | if (*len < count/8) { |
2579 | goto error; | |
2580 | } | |
bbaa79b8 JI |
2581 | while (count--) { |
2582 | ||
2583 | object = SCCalloc(1, sizeof(*object)); | |
2584 | if (unlikely(object == NULL)) { | |
2585 | goto error; | |
2586 | } | |
2587 | ||
2588 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2589 | goto error; | |
2590 | } | |
2591 | ||
2592 | { | |
2593 | uint8_t octet; | |
2594 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2595 | goto error; | |
2596 | } | |
2597 | object->online = (octet >> 0) & 0x1; | |
2598 | object->restart = (octet >> 1) & 0x1; | |
2599 | object->comm_lost = (octet >> 2) & 0x1; | |
2600 | object->remote_forced = (octet >> 3) & 0x1; | |
2601 | object->local_forced = (octet >> 4) & 0x1; | |
2602 | object->rollover = (octet >> 5) & 0x1; | |
2603 | object->reserved0 = (octet >> 6) & 0x1; | |
2604 | object->reserved1 = (octet >> 7) & 0x1; | |
2605 | } | |
2606 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2607 | goto error; | |
2608 | } | |
2609 | ||
53a8c753 | 2610 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2611 | goto error; |
2612 | } | |
2613 | ||
2614 | object = NULL; | |
53a8c753 | 2615 | point_index++; |
bbaa79b8 JI |
2616 | } |
2617 | ||
2618 | return 1; | |
2619 | error: | |
2620 | if (object != NULL) { | |
2621 | SCFree(object); | |
2622 | } | |
2623 | ||
2624 | return 0; | |
2625 | } | |
2626 | ||
2627 | static int DNP3DecodeObjectG22V4(const uint8_t **buf, uint32_t *len, | |
2628 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2629 | DNP3PointList *points) | |
2630 | { | |
2631 | DNP3ObjectG22V4 *object = NULL; | |
2632 | uint32_t prefix = 0; | |
53a8c753 | 2633 | uint32_t point_index = start; |
bbaa79b8 | 2634 | |
8c4e53e8 PA |
2635 | if (*len < count/8) { |
2636 | goto error; | |
2637 | } | |
bbaa79b8 JI |
2638 | while (count--) { |
2639 | ||
2640 | object = SCCalloc(1, sizeof(*object)); | |
2641 | if (unlikely(object == NULL)) { | |
2642 | goto error; | |
2643 | } | |
2644 | ||
2645 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2646 | goto error; | |
2647 | } | |
2648 | ||
2649 | { | |
2650 | uint8_t octet; | |
2651 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2652 | goto error; | |
2653 | } | |
2654 | object->online = (octet >> 0) & 0x1; | |
2655 | object->restart = (octet >> 1) & 0x1; | |
2656 | object->comm_lost = (octet >> 2) & 0x1; | |
2657 | object->remote_forced = (octet >> 3) & 0x1; | |
2658 | object->local_forced = (octet >> 4) & 0x1; | |
2659 | object->rollover = (octet >> 5) & 0x1; | |
2660 | object->reserved0 = (octet >> 6) & 0x1; | |
2661 | object->reserved1 = (octet >> 7) & 0x1; | |
2662 | } | |
2663 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2664 | goto error; | |
2665 | } | |
2666 | ||
53a8c753 | 2667 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2668 | goto error; |
2669 | } | |
2670 | ||
2671 | object = NULL; | |
53a8c753 | 2672 | point_index++; |
bbaa79b8 JI |
2673 | } |
2674 | ||
2675 | return 1; | |
2676 | error: | |
2677 | if (object != NULL) { | |
2678 | SCFree(object); | |
2679 | } | |
2680 | ||
2681 | return 0; | |
2682 | } | |
2683 | ||
2684 | static int DNP3DecodeObjectG22V5(const uint8_t **buf, uint32_t *len, | |
2685 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2686 | DNP3PointList *points) | |
2687 | { | |
2688 | DNP3ObjectG22V5 *object = NULL; | |
2689 | uint32_t prefix = 0; | |
53a8c753 | 2690 | uint32_t point_index = start; |
bbaa79b8 | 2691 | |
8c4e53e8 PA |
2692 | if (*len < count/8) { |
2693 | goto error; | |
2694 | } | |
bbaa79b8 JI |
2695 | while (count--) { |
2696 | ||
2697 | object = SCCalloc(1, sizeof(*object)); | |
2698 | if (unlikely(object == NULL)) { | |
2699 | goto error; | |
2700 | } | |
2701 | ||
2702 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2703 | goto error; | |
2704 | } | |
2705 | ||
2706 | { | |
2707 | uint8_t octet; | |
2708 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2709 | goto error; | |
2710 | } | |
2711 | object->online = (octet >> 0) & 0x1; | |
2712 | object->restart = (octet >> 1) & 0x1; | |
2713 | object->comm_lost = (octet >> 2) & 0x1; | |
2714 | object->remote_forced = (octet >> 3) & 0x1; | |
2715 | object->local_forced = (octet >> 4) & 0x1; | |
2716 | object->rollover = (octet >> 5) & 0x1; | |
2717 | object->reserved0 = (octet >> 6) & 0x1; | |
2718 | object->reserved1 = (octet >> 7) & 0x1; | |
2719 | } | |
2720 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2721 | goto error; | |
2722 | } | |
2723 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2724 | goto error; | |
2725 | } | |
2726 | ||
53a8c753 | 2727 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2728 | goto error; |
2729 | } | |
2730 | ||
2731 | object = NULL; | |
53a8c753 | 2732 | point_index++; |
bbaa79b8 JI |
2733 | } |
2734 | ||
2735 | return 1; | |
2736 | error: | |
2737 | if (object != NULL) { | |
2738 | SCFree(object); | |
2739 | } | |
2740 | ||
2741 | return 0; | |
2742 | } | |
2743 | ||
2744 | static int DNP3DecodeObjectG22V6(const uint8_t **buf, uint32_t *len, | |
2745 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2746 | DNP3PointList *points) | |
2747 | { | |
2748 | DNP3ObjectG22V6 *object = NULL; | |
2749 | uint32_t prefix = 0; | |
53a8c753 | 2750 | uint32_t point_index = start; |
bbaa79b8 | 2751 | |
8c4e53e8 PA |
2752 | if (*len < count/8) { |
2753 | goto error; | |
2754 | } | |
bbaa79b8 JI |
2755 | while (count--) { |
2756 | ||
2757 | object = SCCalloc(1, sizeof(*object)); | |
2758 | if (unlikely(object == NULL)) { | |
2759 | goto error; | |
2760 | } | |
2761 | ||
2762 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2763 | goto error; | |
2764 | } | |
2765 | ||
2766 | { | |
2767 | uint8_t octet; | |
2768 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2769 | goto error; | |
2770 | } | |
2771 | object->online = (octet >> 0) & 0x1; | |
2772 | object->restart = (octet >> 1) & 0x1; | |
2773 | object->comm_lost = (octet >> 2) & 0x1; | |
2774 | object->remote_forced = (octet >> 3) & 0x1; | |
2775 | object->local_forced = (octet >> 4) & 0x1; | |
2776 | object->rollover = (octet >> 5) & 0x1; | |
2777 | object->discontinuity = (octet >> 6) & 0x1; | |
2778 | object->reserved0 = (octet >> 7) & 0x1; | |
2779 | } | |
2780 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2781 | goto error; | |
2782 | } | |
2783 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2784 | goto error; | |
2785 | } | |
2786 | ||
53a8c753 | 2787 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2788 | goto error; |
2789 | } | |
2790 | ||
2791 | object = NULL; | |
53a8c753 | 2792 | point_index++; |
bbaa79b8 JI |
2793 | } |
2794 | ||
2795 | return 1; | |
2796 | error: | |
2797 | if (object != NULL) { | |
2798 | SCFree(object); | |
2799 | } | |
2800 | ||
2801 | return 0; | |
2802 | } | |
2803 | ||
2804 | static int DNP3DecodeObjectG22V7(const uint8_t **buf, uint32_t *len, | |
2805 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2806 | DNP3PointList *points) | |
2807 | { | |
2808 | DNP3ObjectG22V7 *object = NULL; | |
2809 | uint32_t prefix = 0; | |
53a8c753 | 2810 | uint32_t point_index = start; |
bbaa79b8 | 2811 | |
8c4e53e8 PA |
2812 | if (*len < count/8) { |
2813 | goto error; | |
2814 | } | |
bbaa79b8 JI |
2815 | while (count--) { |
2816 | ||
2817 | object = SCCalloc(1, sizeof(*object)); | |
2818 | if (unlikely(object == NULL)) { | |
2819 | goto error; | |
2820 | } | |
2821 | ||
2822 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2823 | goto error; | |
2824 | } | |
2825 | ||
2826 | { | |
2827 | uint8_t octet; | |
2828 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2829 | goto error; | |
2830 | } | |
2831 | object->online = (octet >> 0) & 0x1; | |
2832 | object->restart = (octet >> 1) & 0x1; | |
2833 | object->comm_lost = (octet >> 2) & 0x1; | |
2834 | object->remote_forced = (octet >> 3) & 0x1; | |
2835 | object->local_forced = (octet >> 4) & 0x1; | |
2836 | object->rollover = (octet >> 5) & 0x1; | |
2837 | object->reserved0 = (octet >> 6) & 0x1; | |
2838 | object->reserved1 = (octet >> 7) & 0x1; | |
2839 | } | |
2840 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2841 | goto error; | |
2842 | } | |
2843 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2844 | goto error; | |
2845 | } | |
2846 | ||
53a8c753 | 2847 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2848 | goto error; |
2849 | } | |
2850 | ||
2851 | object = NULL; | |
53a8c753 | 2852 | point_index++; |
bbaa79b8 JI |
2853 | } |
2854 | ||
2855 | return 1; | |
2856 | error: | |
2857 | if (object != NULL) { | |
2858 | SCFree(object); | |
2859 | } | |
2860 | ||
2861 | return 0; | |
2862 | } | |
2863 | ||
2864 | static int DNP3DecodeObjectG22V8(const uint8_t **buf, uint32_t *len, | |
2865 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2866 | DNP3PointList *points) | |
2867 | { | |
2868 | DNP3ObjectG22V8 *object = NULL; | |
2869 | uint32_t prefix = 0; | |
53a8c753 | 2870 | uint32_t point_index = start; |
bbaa79b8 | 2871 | |
8c4e53e8 PA |
2872 | if (*len < count/8) { |
2873 | goto error; | |
2874 | } | |
bbaa79b8 JI |
2875 | while (count--) { |
2876 | ||
2877 | object = SCCalloc(1, sizeof(*object)); | |
2878 | if (unlikely(object == NULL)) { | |
2879 | goto error; | |
2880 | } | |
2881 | ||
2882 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2883 | goto error; | |
2884 | } | |
2885 | ||
2886 | { | |
2887 | uint8_t octet; | |
2888 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2889 | goto error; | |
2890 | } | |
2891 | object->online = (octet >> 0) & 0x1; | |
2892 | object->restart = (octet >> 1) & 0x1; | |
2893 | object->comm_lost = (octet >> 2) & 0x1; | |
2894 | object->remote_forced = (octet >> 3) & 0x1; | |
2895 | object->local_forced = (octet >> 4) & 0x1; | |
2896 | object->rollover = (octet >> 5) & 0x1; | |
2897 | object->reserved0 = (octet >> 6) & 0x1; | |
2898 | object->reserved1 = (octet >> 7) & 0x1; | |
2899 | } | |
2900 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
2901 | goto error; | |
2902 | } | |
2903 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
2904 | goto error; | |
2905 | } | |
2906 | ||
53a8c753 | 2907 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2908 | goto error; |
2909 | } | |
2910 | ||
2911 | object = NULL; | |
53a8c753 | 2912 | point_index++; |
bbaa79b8 JI |
2913 | } |
2914 | ||
2915 | return 1; | |
2916 | error: | |
2917 | if (object != NULL) { | |
2918 | SCFree(object); | |
2919 | } | |
2920 | ||
2921 | return 0; | |
2922 | } | |
2923 | ||
2924 | static int DNP3DecodeObjectG23V1(const uint8_t **buf, uint32_t *len, | |
2925 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2926 | DNP3PointList *points) | |
2927 | { | |
2928 | DNP3ObjectG23V1 *object = NULL; | |
2929 | uint32_t prefix = 0; | |
53a8c753 | 2930 | uint32_t point_index = start; |
bbaa79b8 | 2931 | |
8c4e53e8 PA |
2932 | if (*len < count/8) { |
2933 | goto error; | |
2934 | } | |
bbaa79b8 JI |
2935 | while (count--) { |
2936 | ||
2937 | object = SCCalloc(1, sizeof(*object)); | |
2938 | if (unlikely(object == NULL)) { | |
2939 | goto error; | |
2940 | } | |
2941 | ||
2942 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
2943 | goto error; | |
2944 | } | |
2945 | ||
2946 | { | |
2947 | uint8_t octet; | |
2948 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
2949 | goto error; | |
2950 | } | |
2951 | object->online = (octet >> 0) & 0x1; | |
2952 | object->restart = (octet >> 1) & 0x1; | |
2953 | object->comm_lost = (octet >> 2) & 0x1; | |
2954 | object->remote_forced = (octet >> 3) & 0x1; | |
2955 | object->local_forced = (octet >> 4) & 0x1; | |
2956 | object->rollover = (octet >> 5) & 0x1; | |
2957 | object->discontinuity = (octet >> 6) & 0x1; | |
2958 | object->reserved0 = (octet >> 7) & 0x1; | |
2959 | } | |
2960 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
2961 | goto error; | |
2962 | } | |
2963 | ||
53a8c753 | 2964 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
2965 | goto error; |
2966 | } | |
2967 | ||
2968 | object = NULL; | |
53a8c753 | 2969 | point_index++; |
bbaa79b8 JI |
2970 | } |
2971 | ||
2972 | return 1; | |
2973 | error: | |
2974 | if (object != NULL) { | |
2975 | SCFree(object); | |
2976 | } | |
2977 | ||
2978 | return 0; | |
2979 | } | |
2980 | ||
2981 | static int DNP3DecodeObjectG23V2(const uint8_t **buf, uint32_t *len, | |
2982 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
2983 | DNP3PointList *points) | |
2984 | { | |
2985 | DNP3ObjectG23V2 *object = NULL; | |
2986 | uint32_t prefix = 0; | |
53a8c753 | 2987 | uint32_t point_index = start; |
bbaa79b8 | 2988 | |
8c4e53e8 PA |
2989 | if (*len < count/8) { |
2990 | goto error; | |
2991 | } | |
bbaa79b8 JI |
2992 | while (count--) { |
2993 | ||
2994 | object = SCCalloc(1, sizeof(*object)); | |
2995 | if (unlikely(object == NULL)) { | |
2996 | goto error; | |
2997 | } | |
2998 | ||
2999 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3000 | goto error; | |
3001 | } | |
3002 | ||
3003 | { | |
3004 | uint8_t octet; | |
3005 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3006 | goto error; | |
3007 | } | |
3008 | object->online = (octet >> 0) & 0x1; | |
3009 | object->restart = (octet >> 1) & 0x1; | |
3010 | object->comm_lost = (octet >> 2) & 0x1; | |
3011 | object->remote_forced = (octet >> 3) & 0x1; | |
3012 | object->local_forced = (octet >> 4) & 0x1; | |
3013 | object->rollover = (octet >> 5) & 0x1; | |
3014 | object->reserved0 = (octet >> 6) & 0x1; | |
3015 | object->reserved1 = (octet >> 7) & 0x1; | |
3016 | } | |
3017 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
3018 | goto error; | |
3019 | } | |
3020 | ||
53a8c753 | 3021 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3022 | goto error; |
3023 | } | |
3024 | ||
3025 | object = NULL; | |
53a8c753 | 3026 | point_index++; |
bbaa79b8 JI |
3027 | } |
3028 | ||
3029 | return 1; | |
3030 | error: | |
3031 | if (object != NULL) { | |
3032 | SCFree(object); | |
3033 | } | |
3034 | ||
3035 | return 0; | |
3036 | } | |
3037 | ||
3038 | static int DNP3DecodeObjectG23V3(const uint8_t **buf, uint32_t *len, | |
3039 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3040 | DNP3PointList *points) | |
3041 | { | |
3042 | DNP3ObjectG23V3 *object = NULL; | |
3043 | uint32_t prefix = 0; | |
53a8c753 | 3044 | uint32_t point_index = start; |
bbaa79b8 | 3045 | |
8c4e53e8 PA |
3046 | if (*len < count/8) { |
3047 | goto error; | |
3048 | } | |
bbaa79b8 JI |
3049 | while (count--) { |
3050 | ||
3051 | object = SCCalloc(1, sizeof(*object)); | |
3052 | if (unlikely(object == NULL)) { | |
3053 | goto error; | |
3054 | } | |
3055 | ||
3056 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3057 | goto error; | |
3058 | } | |
3059 | ||
3060 | { | |
3061 | uint8_t octet; | |
3062 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3063 | goto error; | |
3064 | } | |
3065 | object->online = (octet >> 0) & 0x1; | |
3066 | object->restart = (octet >> 1) & 0x1; | |
3067 | object->comm_lost = (octet >> 2) & 0x1; | |
3068 | object->remote_forced = (octet >> 3) & 0x1; | |
3069 | object->local_forced = (octet >> 4) & 0x1; | |
3070 | object->rollover = (octet >> 5) & 0x1; | |
3071 | object->reserved0 = (octet >> 6) & 0x1; | |
3072 | object->reserved1 = (octet >> 7) & 0x1; | |
3073 | } | |
3074 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
3075 | goto error; | |
3076 | } | |
3077 | ||
53a8c753 | 3078 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3079 | goto error; |
3080 | } | |
3081 | ||
3082 | object = NULL; | |
53a8c753 | 3083 | point_index++; |
bbaa79b8 JI |
3084 | } |
3085 | ||
3086 | return 1; | |
3087 | error: | |
3088 | if (object != NULL) { | |
3089 | SCFree(object); | |
3090 | } | |
3091 | ||
3092 | return 0; | |
3093 | } | |
3094 | ||
3095 | static int DNP3DecodeObjectG23V4(const uint8_t **buf, uint32_t *len, | |
3096 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3097 | DNP3PointList *points) | |
3098 | { | |
3099 | DNP3ObjectG23V4 *object = NULL; | |
3100 | uint32_t prefix = 0; | |
53a8c753 | 3101 | uint32_t point_index = start; |
bbaa79b8 | 3102 | |
8c4e53e8 PA |
3103 | if (*len < count/8) { |
3104 | goto error; | |
3105 | } | |
bbaa79b8 JI |
3106 | while (count--) { |
3107 | ||
3108 | object = SCCalloc(1, sizeof(*object)); | |
3109 | if (unlikely(object == NULL)) { | |
3110 | goto error; | |
3111 | } | |
3112 | ||
3113 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3114 | goto error; | |
3115 | } | |
3116 | ||
3117 | { | |
3118 | uint8_t octet; | |
3119 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3120 | goto error; | |
3121 | } | |
3122 | object->online = (octet >> 0) & 0x1; | |
3123 | object->restart = (octet >> 1) & 0x1; | |
3124 | object->comm_lost = (octet >> 2) & 0x1; | |
3125 | object->remote_forced = (octet >> 3) & 0x1; | |
3126 | object->local_forced = (octet >> 4) & 0x1; | |
3127 | object->rollover = (octet >> 5) & 0x1; | |
3128 | object->reserved0 = (octet >> 6) & 0x1; | |
3129 | object->reserved1 = (octet >> 7) & 0x1; | |
3130 | } | |
3131 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
3132 | goto error; | |
3133 | } | |
3134 | ||
53a8c753 | 3135 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3136 | goto error; |
3137 | } | |
3138 | ||
3139 | object = NULL; | |
53a8c753 | 3140 | point_index++; |
bbaa79b8 JI |
3141 | } |
3142 | ||
3143 | return 1; | |
3144 | error: | |
3145 | if (object != NULL) { | |
3146 | SCFree(object); | |
3147 | } | |
3148 | ||
3149 | return 0; | |
3150 | } | |
3151 | ||
3152 | static int DNP3DecodeObjectG23V5(const uint8_t **buf, uint32_t *len, | |
3153 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3154 | DNP3PointList *points) | |
3155 | { | |
3156 | DNP3ObjectG23V5 *object = NULL; | |
3157 | uint32_t prefix = 0; | |
53a8c753 | 3158 | uint32_t point_index = start; |
bbaa79b8 | 3159 | |
8c4e53e8 PA |
3160 | if (*len < count/8) { |
3161 | goto error; | |
3162 | } | |
bbaa79b8 JI |
3163 | while (count--) { |
3164 | ||
3165 | object = SCCalloc(1, sizeof(*object)); | |
3166 | if (unlikely(object == NULL)) { | |
3167 | goto error; | |
3168 | } | |
3169 | ||
3170 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3171 | goto error; | |
3172 | } | |
3173 | ||
3174 | { | |
3175 | uint8_t octet; | |
3176 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3177 | goto error; | |
3178 | } | |
3179 | object->online = (octet >> 0) & 0x1; | |
3180 | object->restart = (octet >> 1) & 0x1; | |
3181 | object->comm_lost = (octet >> 2) & 0x1; | |
3182 | object->remote_forced = (octet >> 3) & 0x1; | |
3183 | object->local_forced = (octet >> 4) & 0x1; | |
3184 | object->rollover = (octet >> 5) & 0x1; | |
3185 | object->discontinuity = (octet >> 6) & 0x1; | |
3186 | object->reserved0 = (octet >> 7) & 0x1; | |
3187 | } | |
3188 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
3189 | goto error; | |
3190 | } | |
3191 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3192 | goto error; | |
3193 | } | |
3194 | ||
53a8c753 | 3195 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3196 | goto error; |
3197 | } | |
3198 | ||
3199 | object = NULL; | |
53a8c753 | 3200 | point_index++; |
bbaa79b8 JI |
3201 | } |
3202 | ||
3203 | return 1; | |
3204 | error: | |
3205 | if (object != NULL) { | |
3206 | SCFree(object); | |
3207 | } | |
3208 | ||
3209 | return 0; | |
3210 | } | |
3211 | ||
3212 | static int DNP3DecodeObjectG23V6(const uint8_t **buf, uint32_t *len, | |
3213 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3214 | DNP3PointList *points) | |
3215 | { | |
3216 | DNP3ObjectG23V6 *object = NULL; | |
3217 | uint32_t prefix = 0; | |
53a8c753 | 3218 | uint32_t point_index = start; |
bbaa79b8 | 3219 | |
8c4e53e8 PA |
3220 | if (*len < count/8) { |
3221 | goto error; | |
3222 | } | |
bbaa79b8 JI |
3223 | while (count--) { |
3224 | ||
3225 | object = SCCalloc(1, sizeof(*object)); | |
3226 | if (unlikely(object == NULL)) { | |
3227 | goto error; | |
3228 | } | |
3229 | ||
3230 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3231 | goto error; | |
3232 | } | |
3233 | ||
3234 | { | |
3235 | uint8_t octet; | |
3236 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3237 | goto error; | |
3238 | } | |
3239 | object->online = (octet >> 0) & 0x1; | |
3240 | object->restart = (octet >> 1) & 0x1; | |
3241 | object->comm_lost = (octet >> 2) & 0x1; | |
3242 | object->remote_forced = (octet >> 3) & 0x1; | |
3243 | object->local_forced = (octet >> 4) & 0x1; | |
3244 | object->rollover = (octet >> 5) & 0x1; | |
3245 | object->discontinuity = (octet >> 6) & 0x1; | |
3246 | object->reserved0 = (octet >> 7) & 0x1; | |
3247 | } | |
3248 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
3249 | goto error; | |
3250 | } | |
3251 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3252 | goto error; | |
3253 | } | |
3254 | ||
53a8c753 | 3255 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3256 | goto error; |
3257 | } | |
3258 | ||
3259 | object = NULL; | |
53a8c753 | 3260 | point_index++; |
bbaa79b8 JI |
3261 | } |
3262 | ||
3263 | return 1; | |
3264 | error: | |
3265 | if (object != NULL) { | |
3266 | SCFree(object); | |
3267 | } | |
3268 | ||
3269 | return 0; | |
3270 | } | |
3271 | ||
3272 | static int DNP3DecodeObjectG23V7(const uint8_t **buf, uint32_t *len, | |
3273 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3274 | DNP3PointList *points) | |
3275 | { | |
3276 | DNP3ObjectG23V7 *object = NULL; | |
3277 | uint32_t prefix = 0; | |
53a8c753 | 3278 | uint32_t point_index = start; |
bbaa79b8 | 3279 | |
8c4e53e8 PA |
3280 | if (*len < count/8) { |
3281 | goto error; | |
3282 | } | |
bbaa79b8 JI |
3283 | while (count--) { |
3284 | ||
3285 | object = SCCalloc(1, sizeof(*object)); | |
3286 | if (unlikely(object == NULL)) { | |
3287 | goto error; | |
3288 | } | |
3289 | ||
3290 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3291 | goto error; | |
3292 | } | |
3293 | ||
3294 | { | |
3295 | uint8_t octet; | |
3296 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3297 | goto error; | |
3298 | } | |
3299 | object->online = (octet >> 0) & 0x1; | |
3300 | object->restart = (octet >> 1) & 0x1; | |
3301 | object->comm_lost = (octet >> 2) & 0x1; | |
3302 | object->remote_forced = (octet >> 3) & 0x1; | |
3303 | object->local_forced = (octet >> 4) & 0x1; | |
3304 | object->rollover = (octet >> 5) & 0x1; | |
3305 | object->reserved0 = (octet >> 6) & 0x1; | |
3306 | object->reserved1 = (octet >> 7) & 0x1; | |
3307 | } | |
3308 | if (!DNP3ReadUint32(buf, len, &object->count)) { | |
3309 | goto error; | |
3310 | } | |
3311 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3312 | goto error; | |
3313 | } | |
3314 | ||
53a8c753 | 3315 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3316 | goto error; |
3317 | } | |
3318 | ||
3319 | object = NULL; | |
53a8c753 | 3320 | point_index++; |
bbaa79b8 JI |
3321 | } |
3322 | ||
3323 | return 1; | |
3324 | error: | |
3325 | if (object != NULL) { | |
3326 | SCFree(object); | |
3327 | } | |
3328 | ||
3329 | return 0; | |
3330 | } | |
3331 | ||
3332 | static int DNP3DecodeObjectG23V8(const uint8_t **buf, uint32_t *len, | |
3333 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3334 | DNP3PointList *points) | |
3335 | { | |
3336 | DNP3ObjectG23V8 *object = NULL; | |
3337 | uint32_t prefix = 0; | |
53a8c753 | 3338 | uint32_t point_index = start; |
bbaa79b8 | 3339 | |
8c4e53e8 PA |
3340 | if (*len < count/8) { |
3341 | goto error; | |
3342 | } | |
bbaa79b8 JI |
3343 | while (count--) { |
3344 | ||
3345 | object = SCCalloc(1, sizeof(*object)); | |
3346 | if (unlikely(object == NULL)) { | |
3347 | goto error; | |
3348 | } | |
3349 | ||
3350 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3351 | goto error; | |
3352 | } | |
3353 | ||
3354 | { | |
3355 | uint8_t octet; | |
3356 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3357 | goto error; | |
3358 | } | |
3359 | object->online = (octet >> 0) & 0x1; | |
3360 | object->restart = (octet >> 1) & 0x1; | |
3361 | object->comm_lost = (octet >> 2) & 0x1; | |
3362 | object->remote_forced = (octet >> 3) & 0x1; | |
3363 | object->local_forced = (octet >> 4) & 0x1; | |
3364 | object->rollover = (octet >> 5) & 0x1; | |
3365 | object->reserved0 = (octet >> 6) & 0x1; | |
3366 | object->reserved1 = (octet >> 7) & 0x1; | |
3367 | } | |
3368 | if (!DNP3ReadUint16(buf, len, &object->count)) { | |
3369 | goto error; | |
3370 | } | |
3371 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3372 | goto error; | |
3373 | } | |
3374 | ||
53a8c753 | 3375 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3376 | goto error; |
3377 | } | |
3378 | ||
3379 | object = NULL; | |
53a8c753 | 3380 | point_index++; |
bbaa79b8 JI |
3381 | } |
3382 | ||
3383 | return 1; | |
3384 | error: | |
3385 | if (object != NULL) { | |
3386 | SCFree(object); | |
3387 | } | |
3388 | ||
3389 | return 0; | |
3390 | } | |
3391 | ||
3392 | static int DNP3DecodeObjectG30V1(const uint8_t **buf, uint32_t *len, | |
3393 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3394 | DNP3PointList *points) | |
3395 | { | |
3396 | DNP3ObjectG30V1 *object = NULL; | |
3397 | uint32_t prefix = 0; | |
53a8c753 | 3398 | uint32_t point_index = start; |
bbaa79b8 | 3399 | |
8c4e53e8 PA |
3400 | if (*len < count/8) { |
3401 | goto error; | |
3402 | } | |
bbaa79b8 JI |
3403 | while (count--) { |
3404 | ||
3405 | object = SCCalloc(1, sizeof(*object)); | |
3406 | if (unlikely(object == NULL)) { | |
3407 | goto error; | |
3408 | } | |
3409 | ||
3410 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3411 | goto error; | |
3412 | } | |
3413 | ||
3414 | { | |
3415 | uint8_t octet; | |
3416 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3417 | goto error; | |
3418 | } | |
3419 | object->online = (octet >> 0) & 0x1; | |
3420 | object->restart = (octet >> 1) & 0x1; | |
3421 | object->comm_lost = (octet >> 2) & 0x1; | |
3422 | object->remote_forced = (octet >> 3) & 0x1; | |
3423 | object->local_forced = (octet >> 4) & 0x1; | |
3424 | object->over_range = (octet >> 5) & 0x1; | |
3425 | object->reference_err = (octet >> 6) & 0x1; | |
3426 | object->reserved0 = (octet >> 7) & 0x1; | |
3427 | } | |
3428 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
3429 | goto error; | |
3430 | } | |
3431 | ||
53a8c753 | 3432 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3433 | goto error; |
3434 | } | |
3435 | ||
3436 | object = NULL; | |
53a8c753 | 3437 | point_index++; |
bbaa79b8 JI |
3438 | } |
3439 | ||
3440 | return 1; | |
3441 | error: | |
3442 | if (object != NULL) { | |
3443 | SCFree(object); | |
3444 | } | |
3445 | ||
3446 | return 0; | |
3447 | } | |
3448 | ||
3449 | static int DNP3DecodeObjectG30V2(const uint8_t **buf, uint32_t *len, | |
3450 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3451 | DNP3PointList *points) | |
3452 | { | |
3453 | DNP3ObjectG30V2 *object = NULL; | |
3454 | uint32_t prefix = 0; | |
53a8c753 | 3455 | uint32_t point_index = start; |
bbaa79b8 | 3456 | |
8c4e53e8 PA |
3457 | if (*len < count/8) { |
3458 | goto error; | |
3459 | } | |
bbaa79b8 JI |
3460 | while (count--) { |
3461 | ||
3462 | object = SCCalloc(1, sizeof(*object)); | |
3463 | if (unlikely(object == NULL)) { | |
3464 | goto error; | |
3465 | } | |
3466 | ||
3467 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3468 | goto error; | |
3469 | } | |
3470 | ||
3471 | { | |
3472 | uint8_t octet; | |
3473 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3474 | goto error; | |
3475 | } | |
3476 | object->online = (octet >> 0) & 0x1; | |
3477 | object->restart = (octet >> 1) & 0x1; | |
3478 | object->comm_lost = (octet >> 2) & 0x1; | |
3479 | object->remote_forced = (octet >> 3) & 0x1; | |
3480 | object->local_forced = (octet >> 4) & 0x1; | |
3481 | object->over_range = (octet >> 5) & 0x1; | |
3482 | object->reference_err = (octet >> 6) & 0x1; | |
3483 | object->reserved0 = (octet >> 7) & 0x1; | |
3484 | } | |
3485 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
3486 | goto error; | |
3487 | } | |
3488 | ||
53a8c753 | 3489 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3490 | goto error; |
3491 | } | |
3492 | ||
3493 | object = NULL; | |
53a8c753 | 3494 | point_index++; |
bbaa79b8 JI |
3495 | } |
3496 | ||
3497 | return 1; | |
3498 | error: | |
3499 | if (object != NULL) { | |
3500 | SCFree(object); | |
3501 | } | |
3502 | ||
3503 | return 0; | |
3504 | } | |
3505 | ||
3506 | static int DNP3DecodeObjectG30V3(const uint8_t **buf, uint32_t *len, | |
3507 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3508 | DNP3PointList *points) | |
3509 | { | |
3510 | DNP3ObjectG30V3 *object = NULL; | |
3511 | uint32_t prefix = 0; | |
53a8c753 | 3512 | uint32_t point_index = start; |
bbaa79b8 | 3513 | |
8c4e53e8 PA |
3514 | if (*len < count/8) { |
3515 | goto error; | |
3516 | } | |
bbaa79b8 JI |
3517 | while (count--) { |
3518 | ||
3519 | object = SCCalloc(1, sizeof(*object)); | |
3520 | if (unlikely(object == NULL)) { | |
3521 | goto error; | |
3522 | } | |
3523 | ||
3524 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3525 | goto error; | |
3526 | } | |
3527 | ||
3528 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
3529 | goto error; | |
3530 | } | |
3531 | ||
53a8c753 | 3532 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3533 | goto error; |
3534 | } | |
3535 | ||
3536 | object = NULL; | |
53a8c753 | 3537 | point_index++; |
bbaa79b8 JI |
3538 | } |
3539 | ||
3540 | return 1; | |
3541 | error: | |
3542 | if (object != NULL) { | |
3543 | SCFree(object); | |
3544 | } | |
3545 | ||
3546 | return 0; | |
3547 | } | |
3548 | ||
3549 | static int DNP3DecodeObjectG30V4(const uint8_t **buf, uint32_t *len, | |
3550 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3551 | DNP3PointList *points) | |
3552 | { | |
3553 | DNP3ObjectG30V4 *object = NULL; | |
3554 | uint32_t prefix = 0; | |
53a8c753 | 3555 | uint32_t point_index = start; |
bbaa79b8 | 3556 | |
8c4e53e8 PA |
3557 | if (*len < count/8) { |
3558 | goto error; | |
3559 | } | |
bbaa79b8 JI |
3560 | while (count--) { |
3561 | ||
3562 | object = SCCalloc(1, sizeof(*object)); | |
3563 | if (unlikely(object == NULL)) { | |
3564 | goto error; | |
3565 | } | |
3566 | ||
3567 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3568 | goto error; | |
3569 | } | |
3570 | ||
3571 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
3572 | goto error; | |
3573 | } | |
3574 | ||
53a8c753 | 3575 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3576 | goto error; |
3577 | } | |
3578 | ||
3579 | object = NULL; | |
53a8c753 | 3580 | point_index++; |
bbaa79b8 JI |
3581 | } |
3582 | ||
3583 | return 1; | |
3584 | error: | |
3585 | if (object != NULL) { | |
3586 | SCFree(object); | |
3587 | } | |
3588 | ||
3589 | return 0; | |
3590 | } | |
3591 | ||
3592 | static int DNP3DecodeObjectG30V5(const uint8_t **buf, uint32_t *len, | |
3593 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3594 | DNP3PointList *points) | |
3595 | { | |
3596 | DNP3ObjectG30V5 *object = NULL; | |
3597 | uint32_t prefix = 0; | |
53a8c753 | 3598 | uint32_t point_index = start; |
bbaa79b8 | 3599 | |
8c4e53e8 PA |
3600 | if (*len < count/8) { |
3601 | goto error; | |
3602 | } | |
bbaa79b8 JI |
3603 | while (count--) { |
3604 | ||
3605 | object = SCCalloc(1, sizeof(*object)); | |
3606 | if (unlikely(object == NULL)) { | |
3607 | goto error; | |
3608 | } | |
3609 | ||
3610 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3611 | goto error; | |
3612 | } | |
3613 | ||
3614 | { | |
3615 | uint8_t octet; | |
3616 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3617 | goto error; | |
3618 | } | |
3619 | object->online = (octet >> 0) & 0x1; | |
3620 | object->restart = (octet >> 1) & 0x1; | |
3621 | object->comm_lost = (octet >> 2) & 0x1; | |
3622 | object->remote_forced = (octet >> 3) & 0x1; | |
3623 | object->local_forced = (octet >> 4) & 0x1; | |
3624 | object->over_range = (octet >> 5) & 0x1; | |
3625 | object->reference_err = (octet >> 6) & 0x1; | |
3626 | object->reserved0 = (octet >> 7) & 0x1; | |
3627 | } | |
3628 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
3629 | goto error; | |
3630 | } | |
3631 | ||
53a8c753 | 3632 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3633 | goto error; |
3634 | } | |
3635 | ||
3636 | object = NULL; | |
53a8c753 | 3637 | point_index++; |
bbaa79b8 JI |
3638 | } |
3639 | ||
3640 | return 1; | |
3641 | error: | |
3642 | if (object != NULL) { | |
3643 | SCFree(object); | |
3644 | } | |
3645 | ||
3646 | return 0; | |
3647 | } | |
3648 | ||
3649 | static int DNP3DecodeObjectG30V6(const uint8_t **buf, uint32_t *len, | |
3650 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3651 | DNP3PointList *points) | |
3652 | { | |
3653 | DNP3ObjectG30V6 *object = NULL; | |
3654 | uint32_t prefix = 0; | |
53a8c753 | 3655 | uint32_t point_index = start; |
bbaa79b8 | 3656 | |
8c4e53e8 PA |
3657 | if (*len < count/8) { |
3658 | goto error; | |
3659 | } | |
bbaa79b8 JI |
3660 | while (count--) { |
3661 | ||
3662 | object = SCCalloc(1, sizeof(*object)); | |
3663 | if (unlikely(object == NULL)) { | |
3664 | goto error; | |
3665 | } | |
3666 | ||
3667 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3668 | goto error; | |
3669 | } | |
3670 | ||
3671 | { | |
3672 | uint8_t octet; | |
3673 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3674 | goto error; | |
3675 | } | |
3676 | object->online = (octet >> 0) & 0x1; | |
3677 | object->restart = (octet >> 1) & 0x1; | |
3678 | object->comm_lost = (octet >> 2) & 0x1; | |
3679 | object->remote_forced = (octet >> 3) & 0x1; | |
3680 | object->local_forced = (octet >> 4) & 0x1; | |
3681 | object->over_range = (octet >> 5) & 0x1; | |
3682 | object->reference_err = (octet >> 6) & 0x1; | |
3683 | object->reserved0 = (octet >> 7) & 0x1; | |
3684 | } | |
3685 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
3686 | goto error; | |
3687 | } | |
3688 | ||
53a8c753 | 3689 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3690 | goto error; |
3691 | } | |
3692 | ||
3693 | object = NULL; | |
53a8c753 | 3694 | point_index++; |
bbaa79b8 JI |
3695 | } |
3696 | ||
3697 | return 1; | |
3698 | error: | |
3699 | if (object != NULL) { | |
3700 | SCFree(object); | |
3701 | } | |
3702 | ||
3703 | return 0; | |
3704 | } | |
3705 | ||
3706 | static int DNP3DecodeObjectG31V1(const uint8_t **buf, uint32_t *len, | |
3707 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3708 | DNP3PointList *points) | |
3709 | { | |
3710 | DNP3ObjectG31V1 *object = NULL; | |
3711 | uint32_t prefix = 0; | |
53a8c753 | 3712 | uint32_t point_index = start; |
bbaa79b8 | 3713 | |
8c4e53e8 PA |
3714 | if (*len < count/8) { |
3715 | goto error; | |
3716 | } | |
bbaa79b8 JI |
3717 | while (count--) { |
3718 | ||
3719 | object = SCCalloc(1, sizeof(*object)); | |
3720 | if (unlikely(object == NULL)) { | |
3721 | goto error; | |
3722 | } | |
3723 | ||
3724 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3725 | goto error; | |
3726 | } | |
3727 | ||
3728 | { | |
3729 | uint8_t octet; | |
3730 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3731 | goto error; | |
3732 | } | |
3733 | object->online = (octet >> 0) & 0x1; | |
3734 | object->restart = (octet >> 1) & 0x1; | |
3735 | object->comm_lost = (octet >> 2) & 0x1; | |
3736 | object->remote_forced = (octet >> 3) & 0x1; | |
3737 | object->local_forced = (octet >> 4) & 0x1; | |
3738 | object->over_range = (octet >> 5) & 0x1; | |
3739 | object->reference_err = (octet >> 6) & 0x1; | |
3740 | object->reserved0 = (octet >> 7) & 0x1; | |
3741 | } | |
3742 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
3743 | goto error; | |
3744 | } | |
3745 | ||
53a8c753 | 3746 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3747 | goto error; |
3748 | } | |
3749 | ||
3750 | object = NULL; | |
53a8c753 | 3751 | point_index++; |
bbaa79b8 JI |
3752 | } |
3753 | ||
3754 | return 1; | |
3755 | error: | |
3756 | if (object != NULL) { | |
3757 | SCFree(object); | |
3758 | } | |
3759 | ||
3760 | return 0; | |
3761 | } | |
3762 | ||
3763 | static int DNP3DecodeObjectG31V2(const uint8_t **buf, uint32_t *len, | |
3764 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3765 | DNP3PointList *points) | |
3766 | { | |
3767 | DNP3ObjectG31V2 *object = NULL; | |
3768 | uint32_t prefix = 0; | |
53a8c753 | 3769 | uint32_t point_index = start; |
bbaa79b8 | 3770 | |
8c4e53e8 PA |
3771 | if (*len < count/8) { |
3772 | goto error; | |
3773 | } | |
bbaa79b8 JI |
3774 | while (count--) { |
3775 | ||
3776 | object = SCCalloc(1, sizeof(*object)); | |
3777 | if (unlikely(object == NULL)) { | |
3778 | goto error; | |
3779 | } | |
3780 | ||
3781 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3782 | goto error; | |
3783 | } | |
3784 | ||
3785 | { | |
3786 | uint8_t octet; | |
3787 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3788 | goto error; | |
3789 | } | |
3790 | object->online = (octet >> 0) & 0x1; | |
3791 | object->restart = (octet >> 1) & 0x1; | |
3792 | object->comm_lost = (octet >> 2) & 0x1; | |
3793 | object->remote_forced = (octet >> 3) & 0x1; | |
3794 | object->local_forced = (octet >> 4) & 0x1; | |
3795 | object->over_range = (octet >> 5) & 0x1; | |
3796 | object->reference_err = (octet >> 6) & 0x1; | |
3797 | object->reserved0 = (octet >> 7) & 0x1; | |
3798 | } | |
3799 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
3800 | goto error; | |
3801 | } | |
3802 | ||
53a8c753 | 3803 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3804 | goto error; |
3805 | } | |
3806 | ||
3807 | object = NULL; | |
53a8c753 | 3808 | point_index++; |
bbaa79b8 JI |
3809 | } |
3810 | ||
3811 | return 1; | |
3812 | error: | |
3813 | if (object != NULL) { | |
3814 | SCFree(object); | |
3815 | } | |
3816 | ||
3817 | return 0; | |
3818 | } | |
3819 | ||
3820 | static int DNP3DecodeObjectG31V3(const uint8_t **buf, uint32_t *len, | |
3821 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3822 | DNP3PointList *points) | |
3823 | { | |
3824 | DNP3ObjectG31V3 *object = NULL; | |
3825 | uint32_t prefix = 0; | |
53a8c753 | 3826 | uint32_t point_index = start; |
bbaa79b8 | 3827 | |
8c4e53e8 PA |
3828 | if (*len < count/8) { |
3829 | goto error; | |
3830 | } | |
bbaa79b8 JI |
3831 | while (count--) { |
3832 | ||
3833 | object = SCCalloc(1, sizeof(*object)); | |
3834 | if (unlikely(object == NULL)) { | |
3835 | goto error; | |
3836 | } | |
3837 | ||
3838 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3839 | goto error; | |
3840 | } | |
3841 | ||
3842 | { | |
3843 | uint8_t octet; | |
3844 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3845 | goto error; | |
3846 | } | |
3847 | object->online = (octet >> 0) & 0x1; | |
3848 | object->restart = (octet >> 1) & 0x1; | |
3849 | object->comm_lost = (octet >> 2) & 0x1; | |
3850 | object->remote_forced = (octet >> 3) & 0x1; | |
3851 | object->local_forced = (octet >> 4) & 0x1; | |
3852 | object->over_range = (octet >> 5) & 0x1; | |
3853 | object->reference_err = (octet >> 6) & 0x1; | |
3854 | object->reserved0 = (octet >> 7) & 0x1; | |
3855 | } | |
3856 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
3857 | goto error; | |
3858 | } | |
3859 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3860 | goto error; | |
3861 | } | |
3862 | ||
53a8c753 | 3863 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3864 | goto error; |
3865 | } | |
3866 | ||
3867 | object = NULL; | |
53a8c753 | 3868 | point_index++; |
bbaa79b8 JI |
3869 | } |
3870 | ||
3871 | return 1; | |
3872 | error: | |
3873 | if (object != NULL) { | |
3874 | SCFree(object); | |
3875 | } | |
3876 | ||
3877 | return 0; | |
3878 | } | |
3879 | ||
3880 | static int DNP3DecodeObjectG31V4(const uint8_t **buf, uint32_t *len, | |
3881 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3882 | DNP3PointList *points) | |
3883 | { | |
3884 | DNP3ObjectG31V4 *object = NULL; | |
3885 | uint32_t prefix = 0; | |
53a8c753 | 3886 | uint32_t point_index = start; |
bbaa79b8 | 3887 | |
8c4e53e8 PA |
3888 | if (*len < count/8) { |
3889 | goto error; | |
3890 | } | |
bbaa79b8 JI |
3891 | while (count--) { |
3892 | ||
3893 | object = SCCalloc(1, sizeof(*object)); | |
3894 | if (unlikely(object == NULL)) { | |
3895 | goto error; | |
3896 | } | |
3897 | ||
3898 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3899 | goto error; | |
3900 | } | |
3901 | ||
3902 | { | |
3903 | uint8_t octet; | |
3904 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
3905 | goto error; | |
3906 | } | |
3907 | object->online = (octet >> 0) & 0x1; | |
3908 | object->restart = (octet >> 1) & 0x1; | |
3909 | object->comm_lost = (octet >> 2) & 0x1; | |
3910 | object->remote_forced = (octet >> 3) & 0x1; | |
3911 | object->local_forced = (octet >> 4) & 0x1; | |
3912 | object->over_range = (octet >> 5) & 0x1; | |
3913 | object->reference_err = (octet >> 6) & 0x1; | |
3914 | object->reserved0 = (octet >> 7) & 0x1; | |
3915 | } | |
3916 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
3917 | goto error; | |
3918 | } | |
3919 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
3920 | goto error; | |
3921 | } | |
3922 | ||
53a8c753 | 3923 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3924 | goto error; |
3925 | } | |
3926 | ||
3927 | object = NULL; | |
53a8c753 | 3928 | point_index++; |
bbaa79b8 JI |
3929 | } |
3930 | ||
3931 | return 1; | |
3932 | error: | |
3933 | if (object != NULL) { | |
3934 | SCFree(object); | |
3935 | } | |
3936 | ||
3937 | return 0; | |
3938 | } | |
3939 | ||
3940 | static int DNP3DecodeObjectG31V5(const uint8_t **buf, uint32_t *len, | |
3941 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3942 | DNP3PointList *points) | |
3943 | { | |
3944 | DNP3ObjectG31V5 *object = NULL; | |
3945 | uint32_t prefix = 0; | |
53a8c753 | 3946 | uint32_t point_index = start; |
bbaa79b8 | 3947 | |
8c4e53e8 PA |
3948 | if (*len < count/8) { |
3949 | goto error; | |
3950 | } | |
bbaa79b8 JI |
3951 | while (count--) { |
3952 | ||
3953 | object = SCCalloc(1, sizeof(*object)); | |
3954 | if (unlikely(object == NULL)) { | |
3955 | goto error; | |
3956 | } | |
3957 | ||
3958 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
3959 | goto error; | |
3960 | } | |
3961 | ||
3962 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
3963 | goto error; | |
3964 | } | |
3965 | ||
53a8c753 | 3966 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
3967 | goto error; |
3968 | } | |
3969 | ||
3970 | object = NULL; | |
53a8c753 | 3971 | point_index++; |
bbaa79b8 JI |
3972 | } |
3973 | ||
3974 | return 1; | |
3975 | error: | |
3976 | if (object != NULL) { | |
3977 | SCFree(object); | |
3978 | } | |
3979 | ||
3980 | return 0; | |
3981 | } | |
3982 | ||
3983 | static int DNP3DecodeObjectG31V6(const uint8_t **buf, uint32_t *len, | |
3984 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
3985 | DNP3PointList *points) | |
3986 | { | |
3987 | DNP3ObjectG31V6 *object = NULL; | |
3988 | uint32_t prefix = 0; | |
53a8c753 | 3989 | uint32_t point_index = start; |
bbaa79b8 | 3990 | |
8c4e53e8 PA |
3991 | if (*len < count/8) { |
3992 | goto error; | |
3993 | } | |
bbaa79b8 JI |
3994 | while (count--) { |
3995 | ||
3996 | object = SCCalloc(1, sizeof(*object)); | |
3997 | if (unlikely(object == NULL)) { | |
3998 | goto error; | |
3999 | } | |
4000 | ||
4001 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4002 | goto error; | |
4003 | } | |
4004 | ||
4005 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
4006 | goto error; | |
4007 | } | |
4008 | ||
53a8c753 | 4009 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4010 | goto error; |
4011 | } | |
4012 | ||
4013 | object = NULL; | |
53a8c753 | 4014 | point_index++; |
bbaa79b8 JI |
4015 | } |
4016 | ||
4017 | return 1; | |
4018 | error: | |
4019 | if (object != NULL) { | |
4020 | SCFree(object); | |
4021 | } | |
4022 | ||
4023 | return 0; | |
4024 | } | |
4025 | ||
4026 | static int DNP3DecodeObjectG31V7(const uint8_t **buf, uint32_t *len, | |
4027 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4028 | DNP3PointList *points) | |
4029 | { | |
4030 | DNP3ObjectG31V7 *object = NULL; | |
4031 | uint32_t prefix = 0; | |
53a8c753 | 4032 | uint32_t point_index = start; |
bbaa79b8 | 4033 | |
8c4e53e8 PA |
4034 | if (*len < count/8) { |
4035 | goto error; | |
4036 | } | |
bbaa79b8 JI |
4037 | while (count--) { |
4038 | ||
4039 | object = SCCalloc(1, sizeof(*object)); | |
4040 | if (unlikely(object == NULL)) { | |
4041 | goto error; | |
4042 | } | |
4043 | ||
4044 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4045 | goto error; | |
4046 | } | |
4047 | ||
4048 | { | |
4049 | uint8_t octet; | |
4050 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4051 | goto error; | |
4052 | } | |
4053 | object->online = (octet >> 0) & 0x1; | |
4054 | object->restart = (octet >> 1) & 0x1; | |
4055 | object->comm_lost = (octet >> 2) & 0x1; | |
4056 | object->remote_forced = (octet >> 3) & 0x1; | |
4057 | object->local_forced = (octet >> 4) & 0x1; | |
4058 | object->over_range = (octet >> 5) & 0x1; | |
4059 | object->reference_err = (octet >> 6) & 0x1; | |
4060 | object->reserved0 = (octet >> 7) & 0x1; | |
4061 | } | |
4062 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
4063 | goto error; | |
4064 | } | |
4065 | ||
53a8c753 | 4066 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4067 | goto error; |
4068 | } | |
4069 | ||
4070 | object = NULL; | |
53a8c753 | 4071 | point_index++; |
bbaa79b8 JI |
4072 | } |
4073 | ||
4074 | return 1; | |
4075 | error: | |
4076 | if (object != NULL) { | |
4077 | SCFree(object); | |
4078 | } | |
4079 | ||
4080 | return 0; | |
4081 | } | |
4082 | ||
4083 | static int DNP3DecodeObjectG31V8(const uint8_t **buf, uint32_t *len, | |
4084 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4085 | DNP3PointList *points) | |
4086 | { | |
4087 | DNP3ObjectG31V8 *object = NULL; | |
4088 | uint32_t prefix = 0; | |
53a8c753 | 4089 | uint32_t point_index = start; |
bbaa79b8 | 4090 | |
8c4e53e8 PA |
4091 | if (*len < count/8) { |
4092 | goto error; | |
4093 | } | |
bbaa79b8 JI |
4094 | while (count--) { |
4095 | ||
4096 | object = SCCalloc(1, sizeof(*object)); | |
4097 | if (unlikely(object == NULL)) { | |
4098 | goto error; | |
4099 | } | |
4100 | ||
4101 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4102 | goto error; | |
4103 | } | |
4104 | ||
4105 | { | |
4106 | uint8_t octet; | |
4107 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4108 | goto error; | |
4109 | } | |
4110 | object->online = (octet >> 0) & 0x1; | |
4111 | object->restart = (octet >> 1) & 0x1; | |
4112 | object->comm_lost = (octet >> 2) & 0x1; | |
4113 | object->remote_forced = (octet >> 3) & 0x1; | |
4114 | object->local_forced = (octet >> 4) & 0x1; | |
4115 | object->over_range = (octet >> 5) & 0x1; | |
4116 | object->reference_err = (octet >> 6) & 0x1; | |
4117 | object->reserved0 = (octet >> 7) & 0x1; | |
4118 | } | |
4119 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
4120 | goto error; | |
4121 | } | |
4122 | ||
53a8c753 | 4123 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4124 | goto error; |
4125 | } | |
4126 | ||
4127 | object = NULL; | |
53a8c753 | 4128 | point_index++; |
bbaa79b8 JI |
4129 | } |
4130 | ||
4131 | return 1; | |
4132 | error: | |
4133 | if (object != NULL) { | |
4134 | SCFree(object); | |
4135 | } | |
4136 | ||
4137 | return 0; | |
4138 | } | |
4139 | ||
4140 | static int DNP3DecodeObjectG32V1(const uint8_t **buf, uint32_t *len, | |
4141 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4142 | DNP3PointList *points) | |
4143 | { | |
4144 | DNP3ObjectG32V1 *object = NULL; | |
4145 | uint32_t prefix = 0; | |
53a8c753 | 4146 | uint32_t point_index = start; |
bbaa79b8 | 4147 | |
8c4e53e8 PA |
4148 | if (*len < count/8) { |
4149 | goto error; | |
4150 | } | |
bbaa79b8 JI |
4151 | while (count--) { |
4152 | ||
4153 | object = SCCalloc(1, sizeof(*object)); | |
4154 | if (unlikely(object == NULL)) { | |
4155 | goto error; | |
4156 | } | |
4157 | ||
4158 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4159 | goto error; | |
4160 | } | |
4161 | ||
4162 | { | |
4163 | uint8_t octet; | |
4164 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4165 | goto error; | |
4166 | } | |
4167 | object->online = (octet >> 0) & 0x1; | |
4168 | object->restart = (octet >> 1) & 0x1; | |
4169 | object->comm_lost = (octet >> 2) & 0x1; | |
4170 | object->remote_forced = (octet >> 3) & 0x1; | |
4171 | object->local_forced = (octet >> 4) & 0x1; | |
4172 | object->over_range = (octet >> 5) & 0x1; | |
4173 | object->reference_err = (octet >> 6) & 0x1; | |
4174 | object->reserved0 = (octet >> 7) & 0x1; | |
4175 | } | |
4176 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
4177 | goto error; | |
4178 | } | |
4179 | ||
53a8c753 | 4180 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4181 | goto error; |
4182 | } | |
4183 | ||
4184 | object = NULL; | |
53a8c753 | 4185 | point_index++; |
bbaa79b8 JI |
4186 | } |
4187 | ||
4188 | return 1; | |
4189 | error: | |
4190 | if (object != NULL) { | |
4191 | SCFree(object); | |
4192 | } | |
4193 | ||
4194 | return 0; | |
4195 | } | |
4196 | ||
4197 | static int DNP3DecodeObjectG32V2(const uint8_t **buf, uint32_t *len, | |
4198 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4199 | DNP3PointList *points) | |
4200 | { | |
4201 | DNP3ObjectG32V2 *object = NULL; | |
4202 | uint32_t prefix = 0; | |
53a8c753 | 4203 | uint32_t point_index = start; |
bbaa79b8 | 4204 | |
8c4e53e8 PA |
4205 | if (*len < count/8) { |
4206 | goto error; | |
4207 | } | |
bbaa79b8 JI |
4208 | while (count--) { |
4209 | ||
4210 | object = SCCalloc(1, sizeof(*object)); | |
4211 | if (unlikely(object == NULL)) { | |
4212 | goto error; | |
4213 | } | |
4214 | ||
4215 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4216 | goto error; | |
4217 | } | |
4218 | ||
4219 | { | |
4220 | uint8_t octet; | |
4221 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4222 | goto error; | |
4223 | } | |
4224 | object->online = (octet >> 0) & 0x1; | |
4225 | object->restart = (octet >> 1) & 0x1; | |
4226 | object->comm_lost = (octet >> 2) & 0x1; | |
4227 | object->remote_forced = (octet >> 3) & 0x1; | |
4228 | object->local_forced = (octet >> 4) & 0x1; | |
4229 | object->over_range = (octet >> 5) & 0x1; | |
4230 | object->reference_err = (octet >> 6) & 0x1; | |
4231 | object->reserved0 = (octet >> 7) & 0x1; | |
4232 | } | |
4233 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
4234 | goto error; | |
4235 | } | |
4236 | ||
53a8c753 | 4237 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4238 | goto error; |
4239 | } | |
4240 | ||
4241 | object = NULL; | |
53a8c753 | 4242 | point_index++; |
bbaa79b8 JI |
4243 | } |
4244 | ||
4245 | return 1; | |
4246 | error: | |
4247 | if (object != NULL) { | |
4248 | SCFree(object); | |
4249 | } | |
4250 | ||
4251 | return 0; | |
4252 | } | |
4253 | ||
4254 | static int DNP3DecodeObjectG32V3(const uint8_t **buf, uint32_t *len, | |
4255 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4256 | DNP3PointList *points) | |
4257 | { | |
4258 | DNP3ObjectG32V3 *object = NULL; | |
4259 | uint32_t prefix = 0; | |
53a8c753 | 4260 | uint32_t point_index = start; |
bbaa79b8 | 4261 | |
8c4e53e8 PA |
4262 | if (*len < count/8) { |
4263 | goto error; | |
4264 | } | |
bbaa79b8 JI |
4265 | while (count--) { |
4266 | ||
4267 | object = SCCalloc(1, sizeof(*object)); | |
4268 | if (unlikely(object == NULL)) { | |
4269 | goto error; | |
4270 | } | |
4271 | ||
4272 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4273 | goto error; | |
4274 | } | |
4275 | ||
4276 | { | |
4277 | uint8_t octet; | |
4278 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4279 | goto error; | |
4280 | } | |
4281 | object->online = (octet >> 0) & 0x1; | |
4282 | object->restart = (octet >> 1) & 0x1; | |
4283 | object->comm_lost = (octet >> 2) & 0x1; | |
4284 | object->remote_forced = (octet >> 3) & 0x1; | |
4285 | object->local_forced = (octet >> 4) & 0x1; | |
4286 | object->over_range = (octet >> 5) & 0x1; | |
4287 | object->reference_err = (octet >> 6) & 0x1; | |
4288 | object->reserved0 = (octet >> 7) & 0x1; | |
4289 | } | |
4290 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
4291 | goto error; | |
4292 | } | |
4293 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4294 | goto error; | |
4295 | } | |
4296 | ||
53a8c753 | 4297 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4298 | goto error; |
4299 | } | |
4300 | ||
4301 | object = NULL; | |
53a8c753 | 4302 | point_index++; |
bbaa79b8 JI |
4303 | } |
4304 | ||
4305 | return 1; | |
4306 | error: | |
4307 | if (object != NULL) { | |
4308 | SCFree(object); | |
4309 | } | |
4310 | ||
4311 | return 0; | |
4312 | } | |
4313 | ||
4314 | static int DNP3DecodeObjectG32V4(const uint8_t **buf, uint32_t *len, | |
4315 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4316 | DNP3PointList *points) | |
4317 | { | |
4318 | DNP3ObjectG32V4 *object = NULL; | |
4319 | uint32_t prefix = 0; | |
53a8c753 | 4320 | uint32_t point_index = start; |
bbaa79b8 | 4321 | |
8c4e53e8 PA |
4322 | if (*len < count/8) { |
4323 | goto error; | |
4324 | } | |
bbaa79b8 JI |
4325 | while (count--) { |
4326 | ||
4327 | object = SCCalloc(1, sizeof(*object)); | |
4328 | if (unlikely(object == NULL)) { | |
4329 | goto error; | |
4330 | } | |
4331 | ||
4332 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4333 | goto error; | |
4334 | } | |
4335 | ||
4336 | { | |
4337 | uint8_t octet; | |
4338 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4339 | goto error; | |
4340 | } | |
4341 | object->online = (octet >> 0) & 0x1; | |
4342 | object->restart = (octet >> 1) & 0x1; | |
4343 | object->comm_lost = (octet >> 2) & 0x1; | |
4344 | object->remote_forced = (octet >> 3) & 0x1; | |
4345 | object->local_forced = (octet >> 4) & 0x1; | |
4346 | object->over_range = (octet >> 5) & 0x1; | |
4347 | object->reference_err = (octet >> 6) & 0x1; | |
4348 | object->reserved0 = (octet >> 7) & 0x1; | |
4349 | } | |
4350 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
4351 | goto error; | |
4352 | } | |
4353 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4354 | goto error; | |
4355 | } | |
4356 | ||
53a8c753 | 4357 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4358 | goto error; |
4359 | } | |
4360 | ||
4361 | object = NULL; | |
53a8c753 | 4362 | point_index++; |
bbaa79b8 JI |
4363 | } |
4364 | ||
4365 | return 1; | |
4366 | error: | |
4367 | if (object != NULL) { | |
4368 | SCFree(object); | |
4369 | } | |
4370 | ||
4371 | return 0; | |
4372 | } | |
4373 | ||
4374 | static int DNP3DecodeObjectG32V5(const uint8_t **buf, uint32_t *len, | |
4375 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4376 | DNP3PointList *points) | |
4377 | { | |
4378 | DNP3ObjectG32V5 *object = NULL; | |
4379 | uint32_t prefix = 0; | |
53a8c753 | 4380 | uint32_t point_index = start; |
bbaa79b8 | 4381 | |
8c4e53e8 PA |
4382 | if (*len < count/8) { |
4383 | goto error; | |
4384 | } | |
bbaa79b8 JI |
4385 | while (count--) { |
4386 | ||
4387 | object = SCCalloc(1, sizeof(*object)); | |
4388 | if (unlikely(object == NULL)) { | |
4389 | goto error; | |
4390 | } | |
4391 | ||
4392 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4393 | goto error; | |
4394 | } | |
4395 | ||
4396 | { | |
4397 | uint8_t octet; | |
4398 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4399 | goto error; | |
4400 | } | |
4401 | object->online = (octet >> 0) & 0x1; | |
4402 | object->restart = (octet >> 1) & 0x1; | |
4403 | object->comm_lost = (octet >> 2) & 0x1; | |
4404 | object->remote_forced = (octet >> 3) & 0x1; | |
4405 | object->local_forced = (octet >> 4) & 0x1; | |
4406 | object->over_range = (octet >> 5) & 0x1; | |
4407 | object->reference_err = (octet >> 6) & 0x1; | |
4408 | object->reserved0 = (octet >> 7) & 0x1; | |
4409 | } | |
4410 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
4411 | goto error; | |
4412 | } | |
4413 | ||
53a8c753 | 4414 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4415 | goto error; |
4416 | } | |
4417 | ||
4418 | object = NULL; | |
53a8c753 | 4419 | point_index++; |
bbaa79b8 JI |
4420 | } |
4421 | ||
4422 | return 1; | |
4423 | error: | |
4424 | if (object != NULL) { | |
4425 | SCFree(object); | |
4426 | } | |
4427 | ||
4428 | return 0; | |
4429 | } | |
4430 | ||
4431 | static int DNP3DecodeObjectG32V6(const uint8_t **buf, uint32_t *len, | |
4432 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4433 | DNP3PointList *points) | |
4434 | { | |
4435 | DNP3ObjectG32V6 *object = NULL; | |
4436 | uint32_t prefix = 0; | |
53a8c753 | 4437 | uint32_t point_index = start; |
bbaa79b8 | 4438 | |
8c4e53e8 PA |
4439 | if (*len < count/8) { |
4440 | goto error; | |
4441 | } | |
bbaa79b8 JI |
4442 | while (count--) { |
4443 | ||
4444 | object = SCCalloc(1, sizeof(*object)); | |
4445 | if (unlikely(object == NULL)) { | |
4446 | goto error; | |
4447 | } | |
4448 | ||
4449 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4450 | goto error; | |
4451 | } | |
4452 | ||
4453 | { | |
4454 | uint8_t octet; | |
4455 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4456 | goto error; | |
4457 | } | |
4458 | object->online = (octet >> 0) & 0x1; | |
4459 | object->restart = (octet >> 1) & 0x1; | |
4460 | object->comm_lost = (octet >> 2) & 0x1; | |
4461 | object->remote_forced = (octet >> 3) & 0x1; | |
4462 | object->local_forced = (octet >> 4) & 0x1; | |
4463 | object->over_range = (octet >> 5) & 0x1; | |
4464 | object->reference_err = (octet >> 6) & 0x1; | |
4465 | object->reserved0 = (octet >> 7) & 0x1; | |
4466 | } | |
4467 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
4468 | goto error; | |
4469 | } | |
4470 | ||
53a8c753 | 4471 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4472 | goto error; |
4473 | } | |
4474 | ||
4475 | object = NULL; | |
53a8c753 | 4476 | point_index++; |
bbaa79b8 JI |
4477 | } |
4478 | ||
4479 | return 1; | |
4480 | error: | |
4481 | if (object != NULL) { | |
4482 | SCFree(object); | |
4483 | } | |
4484 | ||
4485 | return 0; | |
4486 | } | |
4487 | ||
4488 | static int DNP3DecodeObjectG32V7(const uint8_t **buf, uint32_t *len, | |
4489 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4490 | DNP3PointList *points) | |
4491 | { | |
4492 | DNP3ObjectG32V7 *object = NULL; | |
4493 | uint32_t prefix = 0; | |
53a8c753 | 4494 | uint32_t point_index = start; |
bbaa79b8 | 4495 | |
8c4e53e8 PA |
4496 | if (*len < count/8) { |
4497 | goto error; | |
4498 | } | |
bbaa79b8 JI |
4499 | while (count--) { |
4500 | ||
4501 | object = SCCalloc(1, sizeof(*object)); | |
4502 | if (unlikely(object == NULL)) { | |
4503 | goto error; | |
4504 | } | |
4505 | ||
4506 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4507 | goto error; | |
4508 | } | |
4509 | ||
4510 | { | |
4511 | uint8_t octet; | |
4512 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4513 | goto error; | |
4514 | } | |
4515 | object->online = (octet >> 0) & 0x1; | |
4516 | object->restart = (octet >> 1) & 0x1; | |
4517 | object->comm_lost = (octet >> 2) & 0x1; | |
4518 | object->remote_forced = (octet >> 3) & 0x1; | |
4519 | object->local_forced = (octet >> 4) & 0x1; | |
4520 | object->over_range = (octet >> 5) & 0x1; | |
4521 | object->reference_err = (octet >> 6) & 0x1; | |
4522 | object->reserved0 = (octet >> 7) & 0x1; | |
4523 | } | |
4524 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
4525 | goto error; | |
4526 | } | |
4527 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4528 | goto error; | |
4529 | } | |
4530 | ||
53a8c753 | 4531 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4532 | goto error; |
4533 | } | |
4534 | ||
4535 | object = NULL; | |
53a8c753 | 4536 | point_index++; |
bbaa79b8 JI |
4537 | } |
4538 | ||
4539 | return 1; | |
4540 | error: | |
4541 | if (object != NULL) { | |
4542 | SCFree(object); | |
4543 | } | |
4544 | ||
4545 | return 0; | |
4546 | } | |
4547 | ||
4548 | static int DNP3DecodeObjectG32V8(const uint8_t **buf, uint32_t *len, | |
4549 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4550 | DNP3PointList *points) | |
4551 | { | |
4552 | DNP3ObjectG32V8 *object = NULL; | |
4553 | uint32_t prefix = 0; | |
53a8c753 | 4554 | uint32_t point_index = start; |
bbaa79b8 | 4555 | |
8c4e53e8 PA |
4556 | if (*len < count/8) { |
4557 | goto error; | |
4558 | } | |
bbaa79b8 JI |
4559 | while (count--) { |
4560 | ||
4561 | object = SCCalloc(1, sizeof(*object)); | |
4562 | if (unlikely(object == NULL)) { | |
4563 | goto error; | |
4564 | } | |
4565 | ||
4566 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4567 | goto error; | |
4568 | } | |
4569 | ||
4570 | { | |
4571 | uint8_t octet; | |
4572 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4573 | goto error; | |
4574 | } | |
4575 | object->online = (octet >> 0) & 0x1; | |
4576 | object->restart = (octet >> 1) & 0x1; | |
4577 | object->comm_lost = (octet >> 2) & 0x1; | |
4578 | object->remote_forced = (octet >> 3) & 0x1; | |
4579 | object->local_forced = (octet >> 4) & 0x1; | |
4580 | object->over_range = (octet >> 5) & 0x1; | |
4581 | object->reference_err = (octet >> 6) & 0x1; | |
4582 | object->reserved0 = (octet >> 7) & 0x1; | |
4583 | } | |
4584 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
4585 | goto error; | |
4586 | } | |
4587 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4588 | goto error; | |
4589 | } | |
4590 | ||
53a8c753 | 4591 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4592 | goto error; |
4593 | } | |
4594 | ||
4595 | object = NULL; | |
53a8c753 | 4596 | point_index++; |
bbaa79b8 JI |
4597 | } |
4598 | ||
4599 | return 1; | |
4600 | error: | |
4601 | if (object != NULL) { | |
4602 | SCFree(object); | |
4603 | } | |
4604 | ||
4605 | return 0; | |
4606 | } | |
4607 | ||
4608 | static int DNP3DecodeObjectG33V1(const uint8_t **buf, uint32_t *len, | |
4609 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4610 | DNP3PointList *points) | |
4611 | { | |
4612 | DNP3ObjectG33V1 *object = NULL; | |
4613 | uint32_t prefix = 0; | |
53a8c753 | 4614 | uint32_t point_index = start; |
bbaa79b8 | 4615 | |
8c4e53e8 PA |
4616 | if (*len < count/8) { |
4617 | goto error; | |
4618 | } | |
bbaa79b8 JI |
4619 | while (count--) { |
4620 | ||
4621 | object = SCCalloc(1, sizeof(*object)); | |
4622 | if (unlikely(object == NULL)) { | |
4623 | goto error; | |
4624 | } | |
4625 | ||
4626 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4627 | goto error; | |
4628 | } | |
4629 | ||
4630 | { | |
4631 | uint8_t octet; | |
4632 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4633 | goto error; | |
4634 | } | |
4635 | object->online = (octet >> 0) & 0x1; | |
4636 | object->restart = (octet >> 1) & 0x1; | |
4637 | object->comm_lost = (octet >> 2) & 0x1; | |
4638 | object->remote_forced = (octet >> 3) & 0x1; | |
4639 | object->local_forced = (octet >> 4) & 0x1; | |
4640 | object->over_range = (octet >> 5) & 0x1; | |
4641 | object->reference_err = (octet >> 6) & 0x1; | |
4642 | object->reserved0 = (octet >> 7) & 0x1; | |
4643 | } | |
4644 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
4645 | goto error; | |
4646 | } | |
4647 | ||
53a8c753 | 4648 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4649 | goto error; |
4650 | } | |
4651 | ||
4652 | object = NULL; | |
53a8c753 | 4653 | point_index++; |
bbaa79b8 JI |
4654 | } |
4655 | ||
4656 | return 1; | |
4657 | error: | |
4658 | if (object != NULL) { | |
4659 | SCFree(object); | |
4660 | } | |
4661 | ||
4662 | return 0; | |
4663 | } | |
4664 | ||
4665 | static int DNP3DecodeObjectG33V2(const uint8_t **buf, uint32_t *len, | |
4666 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4667 | DNP3PointList *points) | |
4668 | { | |
4669 | DNP3ObjectG33V2 *object = NULL; | |
4670 | uint32_t prefix = 0; | |
53a8c753 | 4671 | uint32_t point_index = start; |
bbaa79b8 | 4672 | |
8c4e53e8 PA |
4673 | if (*len < count/8) { |
4674 | goto error; | |
4675 | } | |
bbaa79b8 JI |
4676 | while (count--) { |
4677 | ||
4678 | object = SCCalloc(1, sizeof(*object)); | |
4679 | if (unlikely(object == NULL)) { | |
4680 | goto error; | |
4681 | } | |
4682 | ||
4683 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4684 | goto error; | |
4685 | } | |
4686 | ||
4687 | { | |
4688 | uint8_t octet; | |
4689 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4690 | goto error; | |
4691 | } | |
4692 | object->online = (octet >> 0) & 0x1; | |
4693 | object->restart = (octet >> 1) & 0x1; | |
4694 | object->comm_lost = (octet >> 2) & 0x1; | |
4695 | object->remote_forced = (octet >> 3) & 0x1; | |
4696 | object->local_forced = (octet >> 4) & 0x1; | |
4697 | object->over_range = (octet >> 5) & 0x1; | |
4698 | object->reference_err = (octet >> 6) & 0x1; | |
4699 | object->reserved0 = (octet >> 7) & 0x1; | |
4700 | } | |
4701 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
4702 | goto error; | |
4703 | } | |
4704 | ||
53a8c753 | 4705 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4706 | goto error; |
4707 | } | |
4708 | ||
4709 | object = NULL; | |
53a8c753 | 4710 | point_index++; |
bbaa79b8 JI |
4711 | } |
4712 | ||
4713 | return 1; | |
4714 | error: | |
4715 | if (object != NULL) { | |
4716 | SCFree(object); | |
4717 | } | |
4718 | ||
4719 | return 0; | |
4720 | } | |
4721 | ||
4722 | static int DNP3DecodeObjectG33V3(const uint8_t **buf, uint32_t *len, | |
4723 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4724 | DNP3PointList *points) | |
4725 | { | |
4726 | DNP3ObjectG33V3 *object = NULL; | |
4727 | uint32_t prefix = 0; | |
53a8c753 | 4728 | uint32_t point_index = start; |
bbaa79b8 | 4729 | |
8c4e53e8 PA |
4730 | if (*len < count/8) { |
4731 | goto error; | |
4732 | } | |
bbaa79b8 JI |
4733 | while (count--) { |
4734 | ||
4735 | object = SCCalloc(1, sizeof(*object)); | |
4736 | if (unlikely(object == NULL)) { | |
4737 | goto error; | |
4738 | } | |
4739 | ||
4740 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4741 | goto error; | |
4742 | } | |
4743 | ||
4744 | { | |
4745 | uint8_t octet; | |
4746 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4747 | goto error; | |
4748 | } | |
4749 | object->online = (octet >> 0) & 0x1; | |
4750 | object->restart = (octet >> 1) & 0x1; | |
4751 | object->comm_lost = (octet >> 2) & 0x1; | |
4752 | object->remote_forced = (octet >> 3) & 0x1; | |
4753 | object->local_forced = (octet >> 4) & 0x1; | |
4754 | object->over_range = (octet >> 5) & 0x1; | |
4755 | object->reference_err = (octet >> 6) & 0x1; | |
4756 | object->reserved0 = (octet >> 7) & 0x1; | |
4757 | } | |
4758 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
4759 | goto error; | |
4760 | } | |
4761 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4762 | goto error; | |
4763 | } | |
4764 | ||
53a8c753 | 4765 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4766 | goto error; |
4767 | } | |
4768 | ||
4769 | object = NULL; | |
53a8c753 | 4770 | point_index++; |
bbaa79b8 JI |
4771 | } |
4772 | ||
4773 | return 1; | |
4774 | error: | |
4775 | if (object != NULL) { | |
4776 | SCFree(object); | |
4777 | } | |
4778 | ||
4779 | return 0; | |
4780 | } | |
4781 | ||
4782 | static int DNP3DecodeObjectG33V4(const uint8_t **buf, uint32_t *len, | |
4783 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4784 | DNP3PointList *points) | |
4785 | { | |
4786 | DNP3ObjectG33V4 *object = NULL; | |
4787 | uint32_t prefix = 0; | |
53a8c753 | 4788 | uint32_t point_index = start; |
bbaa79b8 | 4789 | |
8c4e53e8 PA |
4790 | if (*len < count/8) { |
4791 | goto error; | |
4792 | } | |
bbaa79b8 JI |
4793 | while (count--) { |
4794 | ||
4795 | object = SCCalloc(1, sizeof(*object)); | |
4796 | if (unlikely(object == NULL)) { | |
4797 | goto error; | |
4798 | } | |
4799 | ||
4800 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4801 | goto error; | |
4802 | } | |
4803 | ||
4804 | { | |
4805 | uint8_t octet; | |
4806 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4807 | goto error; | |
4808 | } | |
4809 | object->online = (octet >> 0) & 0x1; | |
4810 | object->restart = (octet >> 1) & 0x1; | |
4811 | object->comm_lost = (octet >> 2) & 0x1; | |
4812 | object->remote_forced = (octet >> 3) & 0x1; | |
4813 | object->local_forced = (octet >> 4) & 0x1; | |
4814 | object->over_range = (octet >> 5) & 0x1; | |
4815 | object->reference_err = (octet >> 6) & 0x1; | |
4816 | object->reserved0 = (octet >> 7) & 0x1; | |
4817 | } | |
4818 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
4819 | goto error; | |
4820 | } | |
4821 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4822 | goto error; | |
4823 | } | |
4824 | ||
53a8c753 | 4825 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4826 | goto error; |
4827 | } | |
4828 | ||
4829 | object = NULL; | |
53a8c753 | 4830 | point_index++; |
bbaa79b8 JI |
4831 | } |
4832 | ||
4833 | return 1; | |
4834 | error: | |
4835 | if (object != NULL) { | |
4836 | SCFree(object); | |
4837 | } | |
4838 | ||
4839 | return 0; | |
4840 | } | |
4841 | ||
4842 | static int DNP3DecodeObjectG33V5(const uint8_t **buf, uint32_t *len, | |
4843 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4844 | DNP3PointList *points) | |
4845 | { | |
4846 | DNP3ObjectG33V5 *object = NULL; | |
4847 | uint32_t prefix = 0; | |
53a8c753 | 4848 | uint32_t point_index = start; |
bbaa79b8 | 4849 | |
8c4e53e8 PA |
4850 | if (*len < count/8) { |
4851 | goto error; | |
4852 | } | |
bbaa79b8 JI |
4853 | while (count--) { |
4854 | ||
4855 | object = SCCalloc(1, sizeof(*object)); | |
4856 | if (unlikely(object == NULL)) { | |
4857 | goto error; | |
4858 | } | |
4859 | ||
4860 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4861 | goto error; | |
4862 | } | |
4863 | ||
4864 | { | |
4865 | uint8_t octet; | |
4866 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4867 | goto error; | |
4868 | } | |
4869 | object->online = (octet >> 0) & 0x1; | |
4870 | object->restart = (octet >> 1) & 0x1; | |
4871 | object->comm_lost = (octet >> 2) & 0x1; | |
4872 | object->remote_forced = (octet >> 3) & 0x1; | |
4873 | object->local_forced = (octet >> 4) & 0x1; | |
4874 | object->over_range = (octet >> 5) & 0x1; | |
4875 | object->reference_err = (octet >> 6) & 0x1; | |
4876 | object->reserved0 = (octet >> 7) & 0x1; | |
4877 | } | |
4878 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
4879 | goto error; | |
4880 | } | |
4881 | ||
53a8c753 | 4882 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4883 | goto error; |
4884 | } | |
4885 | ||
4886 | object = NULL; | |
53a8c753 | 4887 | point_index++; |
bbaa79b8 JI |
4888 | } |
4889 | ||
4890 | return 1; | |
4891 | error: | |
4892 | if (object != NULL) { | |
4893 | SCFree(object); | |
4894 | } | |
4895 | ||
4896 | return 0; | |
4897 | } | |
4898 | ||
4899 | static int DNP3DecodeObjectG33V6(const uint8_t **buf, uint32_t *len, | |
4900 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4901 | DNP3PointList *points) | |
4902 | { | |
4903 | DNP3ObjectG33V6 *object = NULL; | |
4904 | uint32_t prefix = 0; | |
53a8c753 | 4905 | uint32_t point_index = start; |
bbaa79b8 | 4906 | |
8c4e53e8 PA |
4907 | if (*len < count/8) { |
4908 | goto error; | |
4909 | } | |
bbaa79b8 JI |
4910 | while (count--) { |
4911 | ||
4912 | object = SCCalloc(1, sizeof(*object)); | |
4913 | if (unlikely(object == NULL)) { | |
4914 | goto error; | |
4915 | } | |
4916 | ||
4917 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4918 | goto error; | |
4919 | } | |
4920 | ||
4921 | { | |
4922 | uint8_t octet; | |
4923 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4924 | goto error; | |
4925 | } | |
4926 | object->online = (octet >> 0) & 0x1; | |
4927 | object->restart = (octet >> 1) & 0x1; | |
4928 | object->comm_lost = (octet >> 2) & 0x1; | |
4929 | object->remote_forced = (octet >> 3) & 0x1; | |
4930 | object->local_forced = (octet >> 4) & 0x1; | |
4931 | object->over_range = (octet >> 5) & 0x1; | |
4932 | object->reference_err = (octet >> 6) & 0x1; | |
4933 | object->reserved0 = (octet >> 7) & 0x1; | |
4934 | } | |
4935 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
4936 | goto error; | |
4937 | } | |
4938 | ||
53a8c753 | 4939 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
4940 | goto error; |
4941 | } | |
4942 | ||
4943 | object = NULL; | |
53a8c753 | 4944 | point_index++; |
bbaa79b8 JI |
4945 | } |
4946 | ||
4947 | return 1; | |
4948 | error: | |
4949 | if (object != NULL) { | |
4950 | SCFree(object); | |
4951 | } | |
4952 | ||
4953 | return 0; | |
4954 | } | |
4955 | ||
4956 | static int DNP3DecodeObjectG33V7(const uint8_t **buf, uint32_t *len, | |
4957 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
4958 | DNP3PointList *points) | |
4959 | { | |
4960 | DNP3ObjectG33V7 *object = NULL; | |
4961 | uint32_t prefix = 0; | |
53a8c753 | 4962 | uint32_t point_index = start; |
bbaa79b8 | 4963 | |
8c4e53e8 PA |
4964 | if (*len < count/8) { |
4965 | goto error; | |
4966 | } | |
bbaa79b8 JI |
4967 | while (count--) { |
4968 | ||
4969 | object = SCCalloc(1, sizeof(*object)); | |
4970 | if (unlikely(object == NULL)) { | |
4971 | goto error; | |
4972 | } | |
4973 | ||
4974 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
4975 | goto error; | |
4976 | } | |
4977 | ||
4978 | { | |
4979 | uint8_t octet; | |
4980 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
4981 | goto error; | |
4982 | } | |
4983 | object->online = (octet >> 0) & 0x1; | |
4984 | object->restart = (octet >> 1) & 0x1; | |
4985 | object->comm_lost = (octet >> 2) & 0x1; | |
4986 | object->remote_forced = (octet >> 3) & 0x1; | |
4987 | object->local_forced = (octet >> 4) & 0x1; | |
4988 | object->over_range = (octet >> 5) & 0x1; | |
4989 | object->reference_err = (octet >> 6) & 0x1; | |
4990 | object->reserved0 = (octet >> 7) & 0x1; | |
4991 | } | |
4992 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
4993 | goto error; | |
4994 | } | |
4995 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
4996 | goto error; | |
4997 | } | |
4998 | ||
53a8c753 | 4999 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5000 | goto error; |
5001 | } | |
5002 | ||
5003 | object = NULL; | |
53a8c753 | 5004 | point_index++; |
bbaa79b8 JI |
5005 | } |
5006 | ||
5007 | return 1; | |
5008 | error: | |
5009 | if (object != NULL) { | |
5010 | SCFree(object); | |
5011 | } | |
5012 | ||
5013 | return 0; | |
5014 | } | |
5015 | ||
5016 | static int DNP3DecodeObjectG33V8(const uint8_t **buf, uint32_t *len, | |
5017 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5018 | DNP3PointList *points) | |
5019 | { | |
5020 | DNP3ObjectG33V8 *object = NULL; | |
5021 | uint32_t prefix = 0; | |
53a8c753 | 5022 | uint32_t point_index = start; |
bbaa79b8 | 5023 | |
8c4e53e8 PA |
5024 | if (*len < count/8) { |
5025 | goto error; | |
5026 | } | |
bbaa79b8 JI |
5027 | while (count--) { |
5028 | ||
5029 | object = SCCalloc(1, sizeof(*object)); | |
5030 | if (unlikely(object == NULL)) { | |
5031 | goto error; | |
5032 | } | |
5033 | ||
5034 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5035 | goto error; | |
5036 | } | |
5037 | ||
5038 | { | |
5039 | uint8_t octet; | |
5040 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5041 | goto error; | |
5042 | } | |
5043 | object->online = (octet >> 0) & 0x1; | |
5044 | object->restart = (octet >> 1) & 0x1; | |
5045 | object->comm_lost = (octet >> 2) & 0x1; | |
5046 | object->remote_forced = (octet >> 3) & 0x1; | |
5047 | object->local_forced = (octet >> 4) & 0x1; | |
5048 | object->over_range = (octet >> 5) & 0x1; | |
5049 | object->reference_err = (octet >> 6) & 0x1; | |
5050 | object->reserved0 = (octet >> 7) & 0x1; | |
5051 | } | |
5052 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
5053 | goto error; | |
5054 | } | |
5055 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
5056 | goto error; | |
5057 | } | |
5058 | ||
53a8c753 | 5059 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5060 | goto error; |
5061 | } | |
5062 | ||
5063 | object = NULL; | |
53a8c753 | 5064 | point_index++; |
bbaa79b8 JI |
5065 | } |
5066 | ||
5067 | return 1; | |
5068 | error: | |
5069 | if (object != NULL) { | |
5070 | SCFree(object); | |
5071 | } | |
5072 | ||
5073 | return 0; | |
5074 | } | |
5075 | ||
5076 | static int DNP3DecodeObjectG34V1(const uint8_t **buf, uint32_t *len, | |
5077 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5078 | DNP3PointList *points) | |
5079 | { | |
5080 | DNP3ObjectG34V1 *object = NULL; | |
5081 | uint32_t prefix = 0; | |
53a8c753 | 5082 | uint32_t point_index = start; |
bbaa79b8 | 5083 | |
8c4e53e8 PA |
5084 | if (*len < count/8) { |
5085 | goto error; | |
5086 | } | |
bbaa79b8 JI |
5087 | while (count--) { |
5088 | ||
5089 | object = SCCalloc(1, sizeof(*object)); | |
5090 | if (unlikely(object == NULL)) { | |
5091 | goto error; | |
5092 | } | |
5093 | ||
5094 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5095 | goto error; | |
5096 | } | |
5097 | ||
5098 | if (!DNP3ReadUint16(buf, len, &object->deadband_value)) { | |
5099 | goto error; | |
5100 | } | |
5101 | ||
53a8c753 | 5102 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5103 | goto error; |
5104 | } | |
5105 | ||
5106 | object = NULL; | |
53a8c753 | 5107 | point_index++; |
bbaa79b8 JI |
5108 | } |
5109 | ||
5110 | return 1; | |
5111 | error: | |
5112 | if (object != NULL) { | |
5113 | SCFree(object); | |
5114 | } | |
5115 | ||
5116 | return 0; | |
5117 | } | |
5118 | ||
5119 | static int DNP3DecodeObjectG34V2(const uint8_t **buf, uint32_t *len, | |
5120 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5121 | DNP3PointList *points) | |
5122 | { | |
5123 | DNP3ObjectG34V2 *object = NULL; | |
5124 | uint32_t prefix = 0; | |
53a8c753 | 5125 | uint32_t point_index = start; |
bbaa79b8 | 5126 | |
8c4e53e8 PA |
5127 | if (*len < count/8) { |
5128 | goto error; | |
5129 | } | |
bbaa79b8 JI |
5130 | while (count--) { |
5131 | ||
5132 | object = SCCalloc(1, sizeof(*object)); | |
5133 | if (unlikely(object == NULL)) { | |
5134 | goto error; | |
5135 | } | |
5136 | ||
5137 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5138 | goto error; | |
5139 | } | |
5140 | ||
5141 | if (!DNP3ReadUint32(buf, len, &object->deadband_value)) { | |
5142 | goto error; | |
5143 | } | |
5144 | ||
53a8c753 | 5145 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5146 | goto error; |
5147 | } | |
5148 | ||
5149 | object = NULL; | |
53a8c753 | 5150 | point_index++; |
bbaa79b8 JI |
5151 | } |
5152 | ||
5153 | return 1; | |
5154 | error: | |
5155 | if (object != NULL) { | |
5156 | SCFree(object); | |
5157 | } | |
5158 | ||
5159 | return 0; | |
5160 | } | |
5161 | ||
5162 | static int DNP3DecodeObjectG34V3(const uint8_t **buf, uint32_t *len, | |
5163 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5164 | DNP3PointList *points) | |
5165 | { | |
5166 | DNP3ObjectG34V3 *object = NULL; | |
5167 | uint32_t prefix = 0; | |
53a8c753 | 5168 | uint32_t point_index = start; |
bbaa79b8 | 5169 | |
8c4e53e8 PA |
5170 | if (*len < count/8) { |
5171 | goto error; | |
5172 | } | |
bbaa79b8 JI |
5173 | while (count--) { |
5174 | ||
5175 | object = SCCalloc(1, sizeof(*object)); | |
5176 | if (unlikely(object == NULL)) { | |
5177 | goto error; | |
5178 | } | |
5179 | ||
5180 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5181 | goto error; | |
5182 | } | |
5183 | ||
5184 | if (!DNP3ReadFloat32(buf, len, &object->deadband_value)) { | |
5185 | goto error; | |
5186 | } | |
5187 | ||
53a8c753 | 5188 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5189 | goto error; |
5190 | } | |
5191 | ||
5192 | object = NULL; | |
53a8c753 | 5193 | point_index++; |
bbaa79b8 JI |
5194 | } |
5195 | ||
5196 | return 1; | |
5197 | error: | |
5198 | if (object != NULL) { | |
5199 | SCFree(object); | |
5200 | } | |
5201 | ||
5202 | return 0; | |
5203 | } | |
5204 | ||
5205 | static int DNP3DecodeObjectG40V1(const uint8_t **buf, uint32_t *len, | |
5206 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5207 | DNP3PointList *points) | |
5208 | { | |
5209 | DNP3ObjectG40V1 *object = NULL; | |
5210 | uint32_t prefix = 0; | |
53a8c753 | 5211 | uint32_t point_index = start; |
bbaa79b8 | 5212 | |
8c4e53e8 PA |
5213 | if (*len < count/8) { |
5214 | goto error; | |
5215 | } | |
bbaa79b8 JI |
5216 | while (count--) { |
5217 | ||
5218 | object = SCCalloc(1, sizeof(*object)); | |
5219 | if (unlikely(object == NULL)) { | |
5220 | goto error; | |
5221 | } | |
5222 | ||
5223 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5224 | goto error; | |
5225 | } | |
5226 | ||
5227 | { | |
5228 | uint8_t octet; | |
5229 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5230 | goto error; | |
5231 | } | |
5232 | object->online = (octet >> 0) & 0x1; | |
5233 | object->restart = (octet >> 1) & 0x1; | |
5234 | object->comm_lost = (octet >> 2) & 0x1; | |
5235 | object->remote_forced = (octet >> 3) & 0x1; | |
5236 | object->local_forced = (octet >> 4) & 0x1; | |
5237 | object->over_range = (octet >> 5) & 0x1; | |
5238 | object->reference_err = (octet >> 6) & 0x1; | |
5239 | object->reserved0 = (octet >> 7) & 0x1; | |
5240 | } | |
5241 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
5242 | goto error; | |
5243 | } | |
5244 | ||
53a8c753 | 5245 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5246 | goto error; |
5247 | } | |
5248 | ||
5249 | object = NULL; | |
53a8c753 | 5250 | point_index++; |
bbaa79b8 JI |
5251 | } |
5252 | ||
5253 | return 1; | |
5254 | error: | |
5255 | if (object != NULL) { | |
5256 | SCFree(object); | |
5257 | } | |
5258 | ||
5259 | return 0; | |
5260 | } | |
5261 | ||
5262 | static int DNP3DecodeObjectG40V2(const uint8_t **buf, uint32_t *len, | |
5263 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5264 | DNP3PointList *points) | |
5265 | { | |
5266 | DNP3ObjectG40V2 *object = NULL; | |
5267 | uint32_t prefix = 0; | |
53a8c753 | 5268 | uint32_t point_index = start; |
bbaa79b8 | 5269 | |
8c4e53e8 PA |
5270 | if (*len < count/8) { |
5271 | goto error; | |
5272 | } | |
bbaa79b8 JI |
5273 | while (count--) { |
5274 | ||
5275 | object = SCCalloc(1, sizeof(*object)); | |
5276 | if (unlikely(object == NULL)) { | |
5277 | goto error; | |
5278 | } | |
5279 | ||
5280 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5281 | goto error; | |
5282 | } | |
5283 | ||
5284 | { | |
5285 | uint8_t octet; | |
5286 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5287 | goto error; | |
5288 | } | |
5289 | object->online = (octet >> 0) & 0x1; | |
5290 | object->restart = (octet >> 1) & 0x1; | |
5291 | object->comm_lost = (octet >> 2) & 0x1; | |
5292 | object->remote_forced = (octet >> 3) & 0x1; | |
5293 | object->local_forced = (octet >> 4) & 0x1; | |
5294 | object->over_range = (octet >> 5) & 0x1; | |
5295 | object->reference_err = (octet >> 6) & 0x1; | |
5296 | object->reserved0 = (octet >> 7) & 0x1; | |
5297 | } | |
5298 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
5299 | goto error; | |
5300 | } | |
5301 | ||
53a8c753 | 5302 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5303 | goto error; |
5304 | } | |
5305 | ||
5306 | object = NULL; | |
53a8c753 | 5307 | point_index++; |
bbaa79b8 JI |
5308 | } |
5309 | ||
5310 | return 1; | |
5311 | error: | |
5312 | if (object != NULL) { | |
5313 | SCFree(object); | |
5314 | } | |
5315 | ||
5316 | return 0; | |
5317 | } | |
5318 | ||
5319 | static int DNP3DecodeObjectG40V3(const uint8_t **buf, uint32_t *len, | |
5320 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5321 | DNP3PointList *points) | |
5322 | { | |
5323 | DNP3ObjectG40V3 *object = NULL; | |
5324 | uint32_t prefix = 0; | |
53a8c753 | 5325 | uint32_t point_index = start; |
bbaa79b8 | 5326 | |
8c4e53e8 PA |
5327 | if (*len < count/8) { |
5328 | goto error; | |
5329 | } | |
bbaa79b8 JI |
5330 | while (count--) { |
5331 | ||
5332 | object = SCCalloc(1, sizeof(*object)); | |
5333 | if (unlikely(object == NULL)) { | |
5334 | goto error; | |
5335 | } | |
5336 | ||
5337 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5338 | goto error; | |
5339 | } | |
5340 | ||
5341 | { | |
5342 | uint8_t octet; | |
5343 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5344 | goto error; | |
5345 | } | |
5346 | object->online = (octet >> 0) & 0x1; | |
5347 | object->restart = (octet >> 1) & 0x1; | |
5348 | object->comm_lost = (octet >> 2) & 0x1; | |
5349 | object->remote_forced = (octet >> 3) & 0x1; | |
5350 | object->local_forced = (octet >> 4) & 0x1; | |
5351 | object->over_range = (octet >> 5) & 0x1; | |
5352 | object->reference_err = (octet >> 6) & 0x1; | |
5353 | object->reserved0 = (octet >> 7) & 0x1; | |
5354 | } | |
5355 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
5356 | goto error; | |
5357 | } | |
5358 | ||
53a8c753 | 5359 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5360 | goto error; |
5361 | } | |
5362 | ||
5363 | object = NULL; | |
53a8c753 | 5364 | point_index++; |
bbaa79b8 JI |
5365 | } |
5366 | ||
5367 | return 1; | |
5368 | error: | |
5369 | if (object != NULL) { | |
5370 | SCFree(object); | |
5371 | } | |
5372 | ||
5373 | return 0; | |
5374 | } | |
5375 | ||
5376 | static int DNP3DecodeObjectG40V4(const uint8_t **buf, uint32_t *len, | |
5377 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5378 | DNP3PointList *points) | |
5379 | { | |
5380 | DNP3ObjectG40V4 *object = NULL; | |
5381 | uint32_t prefix = 0; | |
53a8c753 | 5382 | uint32_t point_index = start; |
bbaa79b8 | 5383 | |
8c4e53e8 PA |
5384 | if (*len < count/8) { |
5385 | goto error; | |
5386 | } | |
bbaa79b8 JI |
5387 | while (count--) { |
5388 | ||
5389 | object = SCCalloc(1, sizeof(*object)); | |
5390 | if (unlikely(object == NULL)) { | |
5391 | goto error; | |
5392 | } | |
5393 | ||
5394 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5395 | goto error; | |
5396 | } | |
5397 | ||
5398 | { | |
5399 | uint8_t octet; | |
5400 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5401 | goto error; | |
5402 | } | |
5403 | object->online = (octet >> 0) & 0x1; | |
5404 | object->restart = (octet >> 1) & 0x1; | |
5405 | object->comm_lost = (octet >> 2) & 0x1; | |
5406 | object->remote_forced = (octet >> 3) & 0x1; | |
5407 | object->local_forced = (octet >> 4) & 0x1; | |
5408 | object->over_range = (octet >> 5) & 0x1; | |
5409 | object->reference_err = (octet >> 6) & 0x1; | |
5410 | object->reserved0 = (octet >> 7) & 0x1; | |
5411 | } | |
5412 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
5413 | goto error; | |
5414 | } | |
5415 | ||
53a8c753 | 5416 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5417 | goto error; |
5418 | } | |
5419 | ||
5420 | object = NULL; | |
53a8c753 | 5421 | point_index++; |
bbaa79b8 JI |
5422 | } |
5423 | ||
5424 | return 1; | |
5425 | error: | |
5426 | if (object != NULL) { | |
5427 | SCFree(object); | |
5428 | } | |
5429 | ||
5430 | return 0; | |
5431 | } | |
5432 | ||
5433 | static int DNP3DecodeObjectG41V1(const uint8_t **buf, uint32_t *len, | |
5434 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5435 | DNP3PointList *points) | |
5436 | { | |
5437 | DNP3ObjectG41V1 *object = NULL; | |
5438 | uint32_t prefix = 0; | |
53a8c753 | 5439 | uint32_t point_index = start; |
bbaa79b8 | 5440 | |
8c4e53e8 PA |
5441 | if (*len < count/8) { |
5442 | goto error; | |
5443 | } | |
bbaa79b8 JI |
5444 | while (count--) { |
5445 | ||
5446 | object = SCCalloc(1, sizeof(*object)); | |
5447 | if (unlikely(object == NULL)) { | |
5448 | goto error; | |
5449 | } | |
5450 | ||
5451 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5452 | goto error; | |
5453 | } | |
5454 | ||
5455 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
5456 | goto error; | |
5457 | } | |
5458 | if (!DNP3ReadUint8(buf, len, &object->control_status)) { | |
5459 | goto error; | |
5460 | } | |
5461 | ||
53a8c753 | 5462 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5463 | goto error; |
5464 | } | |
5465 | ||
5466 | object = NULL; | |
53a8c753 | 5467 | point_index++; |
bbaa79b8 JI |
5468 | } |
5469 | ||
5470 | return 1; | |
5471 | error: | |
5472 | if (object != NULL) { | |
5473 | SCFree(object); | |
5474 | } | |
5475 | ||
5476 | return 0; | |
5477 | } | |
5478 | ||
5479 | static int DNP3DecodeObjectG41V2(const uint8_t **buf, uint32_t *len, | |
5480 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5481 | DNP3PointList *points) | |
5482 | { | |
5483 | DNP3ObjectG41V2 *object = NULL; | |
5484 | uint32_t prefix = 0; | |
53a8c753 | 5485 | uint32_t point_index = start; |
bbaa79b8 | 5486 | |
8c4e53e8 PA |
5487 | if (*len < count/8) { |
5488 | goto error; | |
5489 | } | |
bbaa79b8 JI |
5490 | while (count--) { |
5491 | ||
5492 | object = SCCalloc(1, sizeof(*object)); | |
5493 | if (unlikely(object == NULL)) { | |
5494 | goto error; | |
5495 | } | |
5496 | ||
5497 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5498 | goto error; | |
5499 | } | |
5500 | ||
5501 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
5502 | goto error; | |
5503 | } | |
5504 | if (!DNP3ReadUint8(buf, len, &object->control_status)) { | |
5505 | goto error; | |
5506 | } | |
5507 | ||
53a8c753 | 5508 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5509 | goto error; |
5510 | } | |
5511 | ||
5512 | object = NULL; | |
53a8c753 | 5513 | point_index++; |
bbaa79b8 JI |
5514 | } |
5515 | ||
5516 | return 1; | |
5517 | error: | |
5518 | if (object != NULL) { | |
5519 | SCFree(object); | |
5520 | } | |
5521 | ||
5522 | return 0; | |
5523 | } | |
5524 | ||
5525 | static int DNP3DecodeObjectG41V3(const uint8_t **buf, uint32_t *len, | |
5526 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5527 | DNP3PointList *points) | |
5528 | { | |
5529 | DNP3ObjectG41V3 *object = NULL; | |
5530 | uint32_t prefix = 0; | |
53a8c753 | 5531 | uint32_t point_index = start; |
bbaa79b8 | 5532 | |
8c4e53e8 PA |
5533 | if (*len < count/8) { |
5534 | goto error; | |
5535 | } | |
bbaa79b8 JI |
5536 | while (count--) { |
5537 | ||
5538 | object = SCCalloc(1, sizeof(*object)); | |
5539 | if (unlikely(object == NULL)) { | |
5540 | goto error; | |
5541 | } | |
5542 | ||
5543 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5544 | goto error; | |
5545 | } | |
5546 | ||
5547 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
5548 | goto error; | |
5549 | } | |
5550 | if (!DNP3ReadUint8(buf, len, &object->control_status)) { | |
5551 | goto error; | |
5552 | } | |
5553 | ||
53a8c753 | 5554 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5555 | goto error; |
5556 | } | |
5557 | ||
5558 | object = NULL; | |
53a8c753 | 5559 | point_index++; |
bbaa79b8 JI |
5560 | } |
5561 | ||
5562 | return 1; | |
5563 | error: | |
5564 | if (object != NULL) { | |
5565 | SCFree(object); | |
5566 | } | |
5567 | ||
5568 | return 0; | |
5569 | } | |
5570 | ||
5571 | static int DNP3DecodeObjectG41V4(const uint8_t **buf, uint32_t *len, | |
5572 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5573 | DNP3PointList *points) | |
5574 | { | |
5575 | DNP3ObjectG41V4 *object = NULL; | |
5576 | uint32_t prefix = 0; | |
53a8c753 | 5577 | uint32_t point_index = start; |
bbaa79b8 | 5578 | |
8c4e53e8 PA |
5579 | if (*len < count/8) { |
5580 | goto error; | |
5581 | } | |
bbaa79b8 JI |
5582 | while (count--) { |
5583 | ||
5584 | object = SCCalloc(1, sizeof(*object)); | |
5585 | if (unlikely(object == NULL)) { | |
5586 | goto error; | |
5587 | } | |
5588 | ||
5589 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5590 | goto error; | |
5591 | } | |
5592 | ||
5593 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
5594 | goto error; | |
5595 | } | |
5596 | if (!DNP3ReadUint8(buf, len, &object->control_status)) { | |
5597 | goto error; | |
5598 | } | |
5599 | ||
53a8c753 | 5600 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5601 | goto error; |
5602 | } | |
5603 | ||
5604 | object = NULL; | |
53a8c753 | 5605 | point_index++; |
bbaa79b8 JI |
5606 | } |
5607 | ||
5608 | return 1; | |
5609 | error: | |
5610 | if (object != NULL) { | |
5611 | SCFree(object); | |
5612 | } | |
5613 | ||
5614 | return 0; | |
5615 | } | |
5616 | ||
5617 | static int DNP3DecodeObjectG42V1(const uint8_t **buf, uint32_t *len, | |
5618 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5619 | DNP3PointList *points) | |
5620 | { | |
5621 | DNP3ObjectG42V1 *object = NULL; | |
5622 | uint32_t prefix = 0; | |
53a8c753 | 5623 | uint32_t point_index = start; |
bbaa79b8 | 5624 | |
8c4e53e8 PA |
5625 | if (*len < count/8) { |
5626 | goto error; | |
5627 | } | |
bbaa79b8 JI |
5628 | while (count--) { |
5629 | ||
5630 | object = SCCalloc(1, sizeof(*object)); | |
5631 | if (unlikely(object == NULL)) { | |
5632 | goto error; | |
5633 | } | |
5634 | ||
5635 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5636 | goto error; | |
5637 | } | |
5638 | ||
5639 | { | |
5640 | uint8_t octet; | |
5641 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5642 | goto error; | |
5643 | } | |
5644 | object->online = (octet >> 0) & 0x1; | |
5645 | object->restart = (octet >> 1) & 0x1; | |
5646 | object->comm_lost = (octet >> 2) & 0x1; | |
5647 | object->remote_forced = (octet >> 3) & 0x1; | |
5648 | object->local_forced = (octet >> 4) & 0x1; | |
5649 | object->over_range = (octet >> 5) & 0x1; | |
5650 | object->reference_err = (octet >> 6) & 0x1; | |
5651 | object->reserved0 = (octet >> 7) & 0x1; | |
5652 | } | |
5653 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
5654 | goto error; | |
5655 | } | |
5656 | ||
53a8c753 | 5657 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5658 | goto error; |
5659 | } | |
5660 | ||
5661 | object = NULL; | |
53a8c753 | 5662 | point_index++; |
bbaa79b8 JI |
5663 | } |
5664 | ||
5665 | return 1; | |
5666 | error: | |
5667 | if (object != NULL) { | |
5668 | SCFree(object); | |
5669 | } | |
5670 | ||
5671 | return 0; | |
5672 | } | |
5673 | ||
5674 | static int DNP3DecodeObjectG42V2(const uint8_t **buf, uint32_t *len, | |
5675 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5676 | DNP3PointList *points) | |
5677 | { | |
5678 | DNP3ObjectG42V2 *object = NULL; | |
5679 | uint32_t prefix = 0; | |
53a8c753 | 5680 | uint32_t point_index = start; |
bbaa79b8 | 5681 | |
8c4e53e8 PA |
5682 | if (*len < count/8) { |
5683 | goto error; | |
5684 | } | |
bbaa79b8 JI |
5685 | while (count--) { |
5686 | ||
5687 | object = SCCalloc(1, sizeof(*object)); | |
5688 | if (unlikely(object == NULL)) { | |
5689 | goto error; | |
5690 | } | |
5691 | ||
5692 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5693 | goto error; | |
5694 | } | |
5695 | ||
5696 | { | |
5697 | uint8_t octet; | |
5698 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5699 | goto error; | |
5700 | } | |
5701 | object->online = (octet >> 0) & 0x1; | |
5702 | object->restart = (octet >> 1) & 0x1; | |
5703 | object->comm_lost = (octet >> 2) & 0x1; | |
5704 | object->remote_forced = (octet >> 3) & 0x1; | |
5705 | object->local_forced = (octet >> 4) & 0x1; | |
5706 | object->over_range = (octet >> 5) & 0x1; | |
5707 | object->reference_err = (octet >> 6) & 0x1; | |
5708 | object->reserved0 = (octet >> 7) & 0x1; | |
5709 | } | |
5710 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
5711 | goto error; | |
5712 | } | |
5713 | ||
53a8c753 | 5714 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5715 | goto error; |
5716 | } | |
5717 | ||
5718 | object = NULL; | |
53a8c753 | 5719 | point_index++; |
bbaa79b8 JI |
5720 | } |
5721 | ||
5722 | return 1; | |
5723 | error: | |
5724 | if (object != NULL) { | |
5725 | SCFree(object); | |
5726 | } | |
5727 | ||
5728 | return 0; | |
5729 | } | |
5730 | ||
5731 | static int DNP3DecodeObjectG42V3(const uint8_t **buf, uint32_t *len, | |
5732 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5733 | DNP3PointList *points) | |
5734 | { | |
5735 | DNP3ObjectG42V3 *object = NULL; | |
5736 | uint32_t prefix = 0; | |
53a8c753 | 5737 | uint32_t point_index = start; |
bbaa79b8 | 5738 | |
8c4e53e8 PA |
5739 | if (*len < count/8) { |
5740 | goto error; | |
5741 | } | |
bbaa79b8 JI |
5742 | while (count--) { |
5743 | ||
5744 | object = SCCalloc(1, sizeof(*object)); | |
5745 | if (unlikely(object == NULL)) { | |
5746 | goto error; | |
5747 | } | |
5748 | ||
5749 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5750 | goto error; | |
5751 | } | |
5752 | ||
5753 | { | |
5754 | uint8_t octet; | |
5755 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5756 | goto error; | |
5757 | } | |
5758 | object->online = (octet >> 0) & 0x1; | |
5759 | object->restart = (octet >> 1) & 0x1; | |
5760 | object->comm_lost = (octet >> 2) & 0x1; | |
5761 | object->remote_forced = (octet >> 3) & 0x1; | |
5762 | object->local_forced = (octet >> 4) & 0x1; | |
5763 | object->over_range = (octet >> 5) & 0x1; | |
5764 | object->reference_err = (octet >> 6) & 0x1; | |
5765 | object->reserved0 = (octet >> 7) & 0x1; | |
5766 | } | |
5767 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->value)) { | |
5768 | goto error; | |
5769 | } | |
5770 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
5771 | goto error; | |
5772 | } | |
5773 | ||
53a8c753 | 5774 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5775 | goto error; |
5776 | } | |
5777 | ||
5778 | object = NULL; | |
53a8c753 | 5779 | point_index++; |
bbaa79b8 JI |
5780 | } |
5781 | ||
5782 | return 1; | |
5783 | error: | |
5784 | if (object != NULL) { | |
5785 | SCFree(object); | |
5786 | } | |
5787 | ||
5788 | return 0; | |
5789 | } | |
5790 | ||
5791 | static int DNP3DecodeObjectG42V4(const uint8_t **buf, uint32_t *len, | |
5792 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5793 | DNP3PointList *points) | |
5794 | { | |
5795 | DNP3ObjectG42V4 *object = NULL; | |
5796 | uint32_t prefix = 0; | |
53a8c753 | 5797 | uint32_t point_index = start; |
bbaa79b8 | 5798 | |
8c4e53e8 PA |
5799 | if (*len < count/8) { |
5800 | goto error; | |
5801 | } | |
bbaa79b8 JI |
5802 | while (count--) { |
5803 | ||
5804 | object = SCCalloc(1, sizeof(*object)); | |
5805 | if (unlikely(object == NULL)) { | |
5806 | goto error; | |
5807 | } | |
5808 | ||
5809 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5810 | goto error; | |
5811 | } | |
5812 | ||
5813 | { | |
5814 | uint8_t octet; | |
5815 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5816 | goto error; | |
5817 | } | |
5818 | object->online = (octet >> 0) & 0x1; | |
5819 | object->restart = (octet >> 1) & 0x1; | |
5820 | object->comm_lost = (octet >> 2) & 0x1; | |
5821 | object->remote_forced = (octet >> 3) & 0x1; | |
5822 | object->local_forced = (octet >> 4) & 0x1; | |
5823 | object->over_range = (octet >> 5) & 0x1; | |
5824 | object->reference_err = (octet >> 6) & 0x1; | |
5825 | object->reserved0 = (octet >> 7) & 0x1; | |
5826 | } | |
5827 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->value)) { | |
5828 | goto error; | |
5829 | } | |
5830 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
5831 | goto error; | |
5832 | } | |
5833 | ||
53a8c753 | 5834 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5835 | goto error; |
5836 | } | |
5837 | ||
5838 | object = NULL; | |
53a8c753 | 5839 | point_index++; |
bbaa79b8 JI |
5840 | } |
5841 | ||
5842 | return 1; | |
5843 | error: | |
5844 | if (object != NULL) { | |
5845 | SCFree(object); | |
5846 | } | |
5847 | ||
5848 | return 0; | |
5849 | } | |
5850 | ||
5851 | static int DNP3DecodeObjectG42V5(const uint8_t **buf, uint32_t *len, | |
5852 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5853 | DNP3PointList *points) | |
5854 | { | |
5855 | DNP3ObjectG42V5 *object = NULL; | |
5856 | uint32_t prefix = 0; | |
53a8c753 | 5857 | uint32_t point_index = start; |
bbaa79b8 | 5858 | |
8c4e53e8 PA |
5859 | if (*len < count/8) { |
5860 | goto error; | |
5861 | } | |
bbaa79b8 JI |
5862 | while (count--) { |
5863 | ||
5864 | object = SCCalloc(1, sizeof(*object)); | |
5865 | if (unlikely(object == NULL)) { | |
5866 | goto error; | |
5867 | } | |
5868 | ||
5869 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5870 | goto error; | |
5871 | } | |
5872 | ||
5873 | { | |
5874 | uint8_t octet; | |
5875 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5876 | goto error; | |
5877 | } | |
5878 | object->online = (octet >> 0) & 0x1; | |
5879 | object->restart = (octet >> 1) & 0x1; | |
5880 | object->comm_lost = (octet >> 2) & 0x1; | |
5881 | object->remote_forced = (octet >> 3) & 0x1; | |
5882 | object->local_forced = (octet >> 4) & 0x1; | |
5883 | object->over_range = (octet >> 5) & 0x1; | |
5884 | object->reference_err = (octet >> 6) & 0x1; | |
5885 | object->reserved0 = (octet >> 7) & 0x1; | |
5886 | } | |
5887 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
5888 | goto error; | |
5889 | } | |
5890 | ||
53a8c753 | 5891 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5892 | goto error; |
5893 | } | |
5894 | ||
5895 | object = NULL; | |
53a8c753 | 5896 | point_index++; |
bbaa79b8 JI |
5897 | } |
5898 | ||
5899 | return 1; | |
5900 | error: | |
5901 | if (object != NULL) { | |
5902 | SCFree(object); | |
5903 | } | |
5904 | ||
5905 | return 0; | |
5906 | } | |
5907 | ||
5908 | static int DNP3DecodeObjectG42V6(const uint8_t **buf, uint32_t *len, | |
5909 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5910 | DNP3PointList *points) | |
5911 | { | |
5912 | DNP3ObjectG42V6 *object = NULL; | |
5913 | uint32_t prefix = 0; | |
53a8c753 | 5914 | uint32_t point_index = start; |
bbaa79b8 | 5915 | |
8c4e53e8 PA |
5916 | if (*len < count/8) { |
5917 | goto error; | |
5918 | } | |
bbaa79b8 JI |
5919 | while (count--) { |
5920 | ||
5921 | object = SCCalloc(1, sizeof(*object)); | |
5922 | if (unlikely(object == NULL)) { | |
5923 | goto error; | |
5924 | } | |
5925 | ||
5926 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5927 | goto error; | |
5928 | } | |
5929 | ||
5930 | { | |
5931 | uint8_t octet; | |
5932 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5933 | goto error; | |
5934 | } | |
5935 | object->online = (octet >> 0) & 0x1; | |
5936 | object->restart = (octet >> 1) & 0x1; | |
5937 | object->comm_lost = (octet >> 2) & 0x1; | |
5938 | object->remote_forced = (octet >> 3) & 0x1; | |
5939 | object->local_forced = (octet >> 4) & 0x1; | |
5940 | object->over_range = (octet >> 5) & 0x1; | |
5941 | object->reference_err = (octet >> 6) & 0x1; | |
5942 | object->reserved0 = (octet >> 7) & 0x1; | |
5943 | } | |
5944 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
5945 | goto error; | |
5946 | } | |
5947 | ||
53a8c753 | 5948 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
5949 | goto error; |
5950 | } | |
5951 | ||
5952 | object = NULL; | |
53a8c753 | 5953 | point_index++; |
bbaa79b8 JI |
5954 | } |
5955 | ||
5956 | return 1; | |
5957 | error: | |
5958 | if (object != NULL) { | |
5959 | SCFree(object); | |
5960 | } | |
5961 | ||
5962 | return 0; | |
5963 | } | |
5964 | ||
5965 | static int DNP3DecodeObjectG42V7(const uint8_t **buf, uint32_t *len, | |
5966 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
5967 | DNP3PointList *points) | |
5968 | { | |
5969 | DNP3ObjectG42V7 *object = NULL; | |
5970 | uint32_t prefix = 0; | |
53a8c753 | 5971 | uint32_t point_index = start; |
bbaa79b8 | 5972 | |
8c4e53e8 PA |
5973 | if (*len < count/8) { |
5974 | goto error; | |
5975 | } | |
bbaa79b8 JI |
5976 | while (count--) { |
5977 | ||
5978 | object = SCCalloc(1, sizeof(*object)); | |
5979 | if (unlikely(object == NULL)) { | |
5980 | goto error; | |
5981 | } | |
5982 | ||
5983 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
5984 | goto error; | |
5985 | } | |
5986 | ||
5987 | { | |
5988 | uint8_t octet; | |
5989 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
5990 | goto error; | |
5991 | } | |
5992 | object->online = (octet >> 0) & 0x1; | |
5993 | object->restart = (octet >> 1) & 0x1; | |
5994 | object->comm_lost = (octet >> 2) & 0x1; | |
5995 | object->remote_forced = (octet >> 3) & 0x1; | |
5996 | object->local_forced = (octet >> 4) & 0x1; | |
5997 | object->over_range = (octet >> 5) & 0x1; | |
5998 | object->reference_err = (octet >> 6) & 0x1; | |
5999 | object->reserved0 = (octet >> 7) & 0x1; | |
6000 | } | |
6001 | if (!DNP3ReadFloat32(buf, len, &object->value)) { | |
6002 | goto error; | |
6003 | } | |
6004 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6005 | goto error; | |
6006 | } | |
6007 | ||
53a8c753 | 6008 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6009 | goto error; |
6010 | } | |
6011 | ||
6012 | object = NULL; | |
53a8c753 | 6013 | point_index++; |
bbaa79b8 JI |
6014 | } |
6015 | ||
6016 | return 1; | |
6017 | error: | |
6018 | if (object != NULL) { | |
6019 | SCFree(object); | |
6020 | } | |
6021 | ||
6022 | return 0; | |
6023 | } | |
6024 | ||
6025 | static int DNP3DecodeObjectG42V8(const uint8_t **buf, uint32_t *len, | |
6026 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6027 | DNP3PointList *points) | |
6028 | { | |
6029 | DNP3ObjectG42V8 *object = NULL; | |
6030 | uint32_t prefix = 0; | |
53a8c753 | 6031 | uint32_t point_index = start; |
bbaa79b8 | 6032 | |
8c4e53e8 PA |
6033 | if (*len < count/8) { |
6034 | goto error; | |
6035 | } | |
bbaa79b8 JI |
6036 | while (count--) { |
6037 | ||
6038 | object = SCCalloc(1, sizeof(*object)); | |
6039 | if (unlikely(object == NULL)) { | |
6040 | goto error; | |
6041 | } | |
6042 | ||
6043 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6044 | goto error; | |
6045 | } | |
6046 | ||
6047 | { | |
6048 | uint8_t octet; | |
6049 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6050 | goto error; | |
6051 | } | |
6052 | object->online = (octet >> 0) & 0x1; | |
6053 | object->restart = (octet >> 1) & 0x1; | |
6054 | object->comm_lost = (octet >> 2) & 0x1; | |
6055 | object->remote_forced = (octet >> 3) & 0x1; | |
6056 | object->local_forced = (octet >> 4) & 0x1; | |
6057 | object->over_range = (octet >> 5) & 0x1; | |
6058 | object->reference_err = (octet >> 6) & 0x1; | |
6059 | object->reserved0 = (octet >> 7) & 0x1; | |
6060 | } | |
6061 | if (!DNP3ReadFloat64(buf, len, &object->value)) { | |
6062 | goto error; | |
6063 | } | |
6064 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6065 | goto error; | |
6066 | } | |
6067 | ||
53a8c753 | 6068 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6069 | goto error; |
6070 | } | |
6071 | ||
6072 | object = NULL; | |
53a8c753 | 6073 | point_index++; |
bbaa79b8 JI |
6074 | } |
6075 | ||
6076 | return 1; | |
6077 | error: | |
6078 | if (object != NULL) { | |
6079 | SCFree(object); | |
6080 | } | |
6081 | ||
6082 | return 0; | |
6083 | } | |
6084 | ||
6085 | static int DNP3DecodeObjectG43V1(const uint8_t **buf, uint32_t *len, | |
6086 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6087 | DNP3PointList *points) | |
6088 | { | |
6089 | DNP3ObjectG43V1 *object = NULL; | |
6090 | uint32_t prefix = 0; | |
53a8c753 | 6091 | uint32_t point_index = start; |
bbaa79b8 | 6092 | |
8c4e53e8 PA |
6093 | if (*len < count/8) { |
6094 | goto error; | |
6095 | } | |
bbaa79b8 JI |
6096 | while (count--) { |
6097 | ||
6098 | object = SCCalloc(1, sizeof(*object)); | |
6099 | if (unlikely(object == NULL)) { | |
6100 | goto error; | |
6101 | } | |
6102 | ||
6103 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6104 | goto error; | |
6105 | } | |
6106 | ||
6107 | { | |
6108 | uint8_t octet; | |
6109 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6110 | goto error; | |
6111 | } | |
6112 | object->status_code = (octet >> 0) & 0x7f; | |
6113 | object->reserved0 = (octet >> 7) & 0x1; | |
6114 | } | |
6115 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->commanded_value)) { | |
6116 | goto error; | |
6117 | } | |
6118 | ||
53a8c753 | 6119 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6120 | goto error; |
6121 | } | |
6122 | ||
6123 | object = NULL; | |
53a8c753 | 6124 | point_index++; |
bbaa79b8 JI |
6125 | } |
6126 | ||
6127 | return 1; | |
6128 | error: | |
6129 | if (object != NULL) { | |
6130 | SCFree(object); | |
6131 | } | |
6132 | ||
6133 | return 0; | |
6134 | } | |
6135 | ||
6136 | static int DNP3DecodeObjectG43V2(const uint8_t **buf, uint32_t *len, | |
6137 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6138 | DNP3PointList *points) | |
6139 | { | |
6140 | DNP3ObjectG43V2 *object = NULL; | |
6141 | uint32_t prefix = 0; | |
53a8c753 | 6142 | uint32_t point_index = start; |
bbaa79b8 | 6143 | |
8c4e53e8 PA |
6144 | if (*len < count/8) { |
6145 | goto error; | |
6146 | } | |
bbaa79b8 JI |
6147 | while (count--) { |
6148 | ||
6149 | object = SCCalloc(1, sizeof(*object)); | |
6150 | if (unlikely(object == NULL)) { | |
6151 | goto error; | |
6152 | } | |
6153 | ||
6154 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6155 | goto error; | |
6156 | } | |
6157 | ||
6158 | { | |
6159 | uint8_t octet; | |
6160 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6161 | goto error; | |
6162 | } | |
6163 | object->status_code = (octet >> 0) & 0x7f; | |
6164 | object->reserved0 = (octet >> 7) & 0x1; | |
6165 | } | |
6166 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->commanded_value)) { | |
6167 | goto error; | |
6168 | } | |
6169 | ||
53a8c753 | 6170 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6171 | goto error; |
6172 | } | |
6173 | ||
6174 | object = NULL; | |
53a8c753 | 6175 | point_index++; |
bbaa79b8 JI |
6176 | } |
6177 | ||
6178 | return 1; | |
6179 | error: | |
6180 | if (object != NULL) { | |
6181 | SCFree(object); | |
6182 | } | |
6183 | ||
6184 | return 0; | |
6185 | } | |
6186 | ||
6187 | static int DNP3DecodeObjectG43V3(const uint8_t **buf, uint32_t *len, | |
6188 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6189 | DNP3PointList *points) | |
6190 | { | |
6191 | DNP3ObjectG43V3 *object = NULL; | |
6192 | uint32_t prefix = 0; | |
53a8c753 | 6193 | uint32_t point_index = start; |
bbaa79b8 | 6194 | |
8c4e53e8 PA |
6195 | if (*len < count/8) { |
6196 | goto error; | |
6197 | } | |
bbaa79b8 JI |
6198 | while (count--) { |
6199 | ||
6200 | object = SCCalloc(1, sizeof(*object)); | |
6201 | if (unlikely(object == NULL)) { | |
6202 | goto error; | |
6203 | } | |
6204 | ||
6205 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6206 | goto error; | |
6207 | } | |
6208 | ||
6209 | { | |
6210 | uint8_t octet; | |
6211 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6212 | goto error; | |
6213 | } | |
6214 | object->status_code = (octet >> 0) & 0x7f; | |
6215 | object->reserved0 = (octet >> 7) & 0x1; | |
6216 | } | |
6217 | if (!DNP3ReadUint32(buf, len, (uint32_t *)&object->commanded_value)) { | |
6218 | goto error; | |
6219 | } | |
6220 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6221 | goto error; | |
6222 | } | |
6223 | ||
53a8c753 | 6224 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6225 | goto error; |
6226 | } | |
6227 | ||
6228 | object = NULL; | |
53a8c753 | 6229 | point_index++; |
bbaa79b8 JI |
6230 | } |
6231 | ||
6232 | return 1; | |
6233 | error: | |
6234 | if (object != NULL) { | |
6235 | SCFree(object); | |
6236 | } | |
6237 | ||
6238 | return 0; | |
6239 | } | |
6240 | ||
6241 | static int DNP3DecodeObjectG43V4(const uint8_t **buf, uint32_t *len, | |
6242 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6243 | DNP3PointList *points) | |
6244 | { | |
6245 | DNP3ObjectG43V4 *object = NULL; | |
6246 | uint32_t prefix = 0; | |
53a8c753 | 6247 | uint32_t point_index = start; |
bbaa79b8 | 6248 | |
8c4e53e8 PA |
6249 | if (*len < count/8) { |
6250 | goto error; | |
6251 | } | |
bbaa79b8 JI |
6252 | while (count--) { |
6253 | ||
6254 | object = SCCalloc(1, sizeof(*object)); | |
6255 | if (unlikely(object == NULL)) { | |
6256 | goto error; | |
6257 | } | |
6258 | ||
6259 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6260 | goto error; | |
6261 | } | |
6262 | ||
6263 | { | |
6264 | uint8_t octet; | |
6265 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6266 | goto error; | |
6267 | } | |
6268 | object->status_code = (octet >> 0) & 0x7f; | |
6269 | object->reserved0 = (octet >> 7) & 0x1; | |
6270 | } | |
6271 | if (!DNP3ReadUint16(buf, len, (uint16_t *)&object->commanded_value)) { | |
6272 | goto error; | |
6273 | } | |
6274 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6275 | goto error; | |
6276 | } | |
6277 | ||
53a8c753 | 6278 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6279 | goto error; |
6280 | } | |
6281 | ||
6282 | object = NULL; | |
53a8c753 | 6283 | point_index++; |
bbaa79b8 JI |
6284 | } |
6285 | ||
6286 | return 1; | |
6287 | error: | |
6288 | if (object != NULL) { | |
6289 | SCFree(object); | |
6290 | } | |
6291 | ||
6292 | return 0; | |
6293 | } | |
6294 | ||
6295 | static int DNP3DecodeObjectG43V5(const uint8_t **buf, uint32_t *len, | |
6296 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6297 | DNP3PointList *points) | |
6298 | { | |
6299 | DNP3ObjectG43V5 *object = NULL; | |
6300 | uint32_t prefix = 0; | |
53a8c753 | 6301 | uint32_t point_index = start; |
bbaa79b8 | 6302 | |
8c4e53e8 PA |
6303 | if (*len < count/8) { |
6304 | goto error; | |
6305 | } | |
bbaa79b8 JI |
6306 | while (count--) { |
6307 | ||
6308 | object = SCCalloc(1, sizeof(*object)); | |
6309 | if (unlikely(object == NULL)) { | |
6310 | goto error; | |
6311 | } | |
6312 | ||
6313 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6314 | goto error; | |
6315 | } | |
6316 | ||
6317 | { | |
6318 | uint8_t octet; | |
6319 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6320 | goto error; | |
6321 | } | |
6322 | object->status_code = (octet >> 0) & 0x7f; | |
6323 | object->reserved0 = (octet >> 7) & 0x1; | |
6324 | } | |
6325 | if (!DNP3ReadFloat32(buf, len, &object->commanded_value)) { | |
6326 | goto error; | |
6327 | } | |
6328 | ||
53a8c753 | 6329 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6330 | goto error; |
6331 | } | |
6332 | ||
6333 | object = NULL; | |
53a8c753 | 6334 | point_index++; |
bbaa79b8 JI |
6335 | } |
6336 | ||
6337 | return 1; | |
6338 | error: | |
6339 | if (object != NULL) { | |
6340 | SCFree(object); | |
6341 | } | |
6342 | ||
6343 | return 0; | |
6344 | } | |
6345 | ||
6346 | static int DNP3DecodeObjectG43V6(const uint8_t **buf, uint32_t *len, | |
6347 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6348 | DNP3PointList *points) | |
6349 | { | |
6350 | DNP3ObjectG43V6 *object = NULL; | |
6351 | uint32_t prefix = 0; | |
53a8c753 | 6352 | uint32_t point_index = start; |
bbaa79b8 | 6353 | |
8c4e53e8 PA |
6354 | if (*len < count/8) { |
6355 | goto error; | |
6356 | } | |
bbaa79b8 JI |
6357 | while (count--) { |
6358 | ||
6359 | object = SCCalloc(1, sizeof(*object)); | |
6360 | if (unlikely(object == NULL)) { | |
6361 | goto error; | |
6362 | } | |
6363 | ||
6364 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6365 | goto error; | |
6366 | } | |
6367 | ||
6368 | { | |
6369 | uint8_t octet; | |
6370 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6371 | goto error; | |
6372 | } | |
6373 | object->status_code = (octet >> 0) & 0x7f; | |
6374 | object->reserved0 = (octet >> 7) & 0x1; | |
6375 | } | |
6376 | if (!DNP3ReadFloat64(buf, len, &object->commanded_value)) { | |
6377 | goto error; | |
6378 | } | |
6379 | ||
53a8c753 | 6380 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6381 | goto error; |
6382 | } | |
6383 | ||
6384 | object = NULL; | |
53a8c753 | 6385 | point_index++; |
bbaa79b8 JI |
6386 | } |
6387 | ||
6388 | return 1; | |
6389 | error: | |
6390 | if (object != NULL) { | |
6391 | SCFree(object); | |
6392 | } | |
6393 | ||
6394 | return 0; | |
6395 | } | |
6396 | ||
6397 | static int DNP3DecodeObjectG43V7(const uint8_t **buf, uint32_t *len, | |
6398 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6399 | DNP3PointList *points) | |
6400 | { | |
6401 | DNP3ObjectG43V7 *object = NULL; | |
6402 | uint32_t prefix = 0; | |
53a8c753 | 6403 | uint32_t point_index = start; |
bbaa79b8 | 6404 | |
8c4e53e8 PA |
6405 | if (*len < count/8) { |
6406 | goto error; | |
6407 | } | |
bbaa79b8 JI |
6408 | while (count--) { |
6409 | ||
6410 | object = SCCalloc(1, sizeof(*object)); | |
6411 | if (unlikely(object == NULL)) { | |
6412 | goto error; | |
6413 | } | |
6414 | ||
6415 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6416 | goto error; | |
6417 | } | |
6418 | ||
6419 | { | |
6420 | uint8_t octet; | |
6421 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6422 | goto error; | |
6423 | } | |
6424 | object->status_code = (octet >> 0) & 0x7f; | |
6425 | object->reserved0 = (octet >> 7) & 0x1; | |
6426 | } | |
6427 | if (!DNP3ReadFloat32(buf, len, &object->commanded_value)) { | |
6428 | goto error; | |
6429 | } | |
6430 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6431 | goto error; | |
6432 | } | |
6433 | ||
53a8c753 | 6434 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6435 | goto error; |
6436 | } | |
6437 | ||
6438 | object = NULL; | |
53a8c753 | 6439 | point_index++; |
bbaa79b8 JI |
6440 | } |
6441 | ||
6442 | return 1; | |
6443 | error: | |
6444 | if (object != NULL) { | |
6445 | SCFree(object); | |
6446 | } | |
6447 | ||
6448 | return 0; | |
6449 | } | |
6450 | ||
6451 | static int DNP3DecodeObjectG43V8(const uint8_t **buf, uint32_t *len, | |
6452 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6453 | DNP3PointList *points) | |
6454 | { | |
6455 | DNP3ObjectG43V8 *object = NULL; | |
6456 | uint32_t prefix = 0; | |
53a8c753 | 6457 | uint32_t point_index = start; |
bbaa79b8 | 6458 | |
8c4e53e8 PA |
6459 | if (*len < count/8) { |
6460 | goto error; | |
6461 | } | |
bbaa79b8 JI |
6462 | while (count--) { |
6463 | ||
6464 | object = SCCalloc(1, sizeof(*object)); | |
6465 | if (unlikely(object == NULL)) { | |
6466 | goto error; | |
6467 | } | |
6468 | ||
6469 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6470 | goto error; | |
6471 | } | |
6472 | ||
6473 | { | |
6474 | uint8_t octet; | |
6475 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
6476 | goto error; | |
6477 | } | |
6478 | object->status_code = (octet >> 0) & 0x7f; | |
6479 | object->reserved0 = (octet >> 7) & 0x1; | |
6480 | } | |
6481 | if (!DNP3ReadFloat64(buf, len, &object->commanded_value)) { | |
6482 | goto error; | |
6483 | } | |
6484 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6485 | goto error; | |
6486 | } | |
6487 | ||
53a8c753 | 6488 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6489 | goto error; |
6490 | } | |
6491 | ||
6492 | object = NULL; | |
53a8c753 | 6493 | point_index++; |
bbaa79b8 JI |
6494 | } |
6495 | ||
6496 | return 1; | |
6497 | error: | |
6498 | if (object != NULL) { | |
6499 | SCFree(object); | |
6500 | } | |
6501 | ||
6502 | return 0; | |
6503 | } | |
6504 | ||
6505 | static int DNP3DecodeObjectG50V1(const uint8_t **buf, uint32_t *len, | |
6506 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6507 | DNP3PointList *points) | |
6508 | { | |
6509 | DNP3ObjectG50V1 *object = NULL; | |
6510 | uint32_t prefix = 0; | |
53a8c753 | 6511 | uint32_t point_index = start; |
bbaa79b8 | 6512 | |
8c4e53e8 PA |
6513 | if (*len < count/8) { |
6514 | goto error; | |
6515 | } | |
bbaa79b8 JI |
6516 | while (count--) { |
6517 | ||
6518 | object = SCCalloc(1, sizeof(*object)); | |
6519 | if (unlikely(object == NULL)) { | |
6520 | goto error; | |
6521 | } | |
6522 | ||
6523 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6524 | goto error; | |
6525 | } | |
6526 | ||
6527 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6528 | goto error; | |
6529 | } | |
6530 | ||
53a8c753 | 6531 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6532 | goto error; |
6533 | } | |
6534 | ||
6535 | object = NULL; | |
53a8c753 | 6536 | point_index++; |
bbaa79b8 JI |
6537 | } |
6538 | ||
6539 | return 1; | |
6540 | error: | |
6541 | if (object != NULL) { | |
6542 | SCFree(object); | |
6543 | } | |
6544 | ||
6545 | return 0; | |
6546 | } | |
6547 | ||
6548 | static int DNP3DecodeObjectG50V2(const uint8_t **buf, uint32_t *len, | |
6549 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6550 | DNP3PointList *points) | |
6551 | { | |
6552 | DNP3ObjectG50V2 *object = NULL; | |
6553 | uint32_t prefix = 0; | |
53a8c753 | 6554 | uint32_t point_index = start; |
bbaa79b8 | 6555 | |
8c4e53e8 PA |
6556 | if (*len < count/8) { |
6557 | goto error; | |
6558 | } | |
bbaa79b8 JI |
6559 | while (count--) { |
6560 | ||
6561 | object = SCCalloc(1, sizeof(*object)); | |
6562 | if (unlikely(object == NULL)) { | |
6563 | goto error; | |
6564 | } | |
6565 | ||
6566 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6567 | goto error; | |
6568 | } | |
6569 | ||
6570 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6571 | goto error; | |
6572 | } | |
6573 | if (!DNP3ReadUint32(buf, len, &object->interval)) { | |
6574 | goto error; | |
6575 | } | |
6576 | ||
53a8c753 | 6577 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6578 | goto error; |
6579 | } | |
6580 | ||
6581 | object = NULL; | |
53a8c753 | 6582 | point_index++; |
bbaa79b8 JI |
6583 | } |
6584 | ||
6585 | return 1; | |
6586 | error: | |
6587 | if (object != NULL) { | |
6588 | SCFree(object); | |
6589 | } | |
6590 | ||
6591 | return 0; | |
6592 | } | |
6593 | ||
6594 | static int DNP3DecodeObjectG50V3(const uint8_t **buf, uint32_t *len, | |
6595 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6596 | DNP3PointList *points) | |
6597 | { | |
6598 | DNP3ObjectG50V3 *object = NULL; | |
6599 | uint32_t prefix = 0; | |
53a8c753 | 6600 | uint32_t point_index = start; |
bbaa79b8 | 6601 | |
8c4e53e8 PA |
6602 | if (*len < count/8) { |
6603 | goto error; | |
6604 | } | |
bbaa79b8 JI |
6605 | while (count--) { |
6606 | ||
6607 | object = SCCalloc(1, sizeof(*object)); | |
6608 | if (unlikely(object == NULL)) { | |
6609 | goto error; | |
6610 | } | |
6611 | ||
6612 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6613 | goto error; | |
6614 | } | |
6615 | ||
6616 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6617 | goto error; | |
6618 | } | |
6619 | ||
53a8c753 | 6620 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6621 | goto error; |
6622 | } | |
6623 | ||
6624 | object = NULL; | |
53a8c753 | 6625 | point_index++; |
bbaa79b8 JI |
6626 | } |
6627 | ||
6628 | return 1; | |
6629 | error: | |
6630 | if (object != NULL) { | |
6631 | SCFree(object); | |
6632 | } | |
6633 | ||
6634 | return 0; | |
6635 | } | |
6636 | ||
6637 | static int DNP3DecodeObjectG50V4(const uint8_t **buf, uint32_t *len, | |
6638 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6639 | DNP3PointList *points) | |
6640 | { | |
6641 | DNP3ObjectG50V4 *object = NULL; | |
6642 | uint32_t prefix = 0; | |
53a8c753 | 6643 | uint32_t point_index = start; |
bbaa79b8 | 6644 | |
8c4e53e8 PA |
6645 | if (*len < count/8) { |
6646 | goto error; | |
6647 | } | |
bbaa79b8 JI |
6648 | while (count--) { |
6649 | ||
6650 | object = SCCalloc(1, sizeof(*object)); | |
6651 | if (unlikely(object == NULL)) { | |
6652 | goto error; | |
6653 | } | |
6654 | ||
6655 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6656 | goto error; | |
6657 | } | |
6658 | ||
6659 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6660 | goto error; | |
6661 | } | |
6662 | if (!DNP3ReadUint32(buf, len, &object->interval_count)) { | |
6663 | goto error; | |
6664 | } | |
6665 | if (!DNP3ReadUint8(buf, len, &object->interval_units)) { | |
6666 | goto error; | |
6667 | } | |
6668 | ||
53a8c753 | 6669 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6670 | goto error; |
6671 | } | |
6672 | ||
6673 | object = NULL; | |
53a8c753 | 6674 | point_index++; |
bbaa79b8 JI |
6675 | } |
6676 | ||
6677 | return 1; | |
6678 | error: | |
6679 | if (object != NULL) { | |
6680 | SCFree(object); | |
6681 | } | |
6682 | ||
6683 | return 0; | |
6684 | } | |
6685 | ||
6686 | static int DNP3DecodeObjectG51V1(const uint8_t **buf, uint32_t *len, | |
6687 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6688 | DNP3PointList *points) | |
6689 | { | |
6690 | DNP3ObjectG51V1 *object = NULL; | |
6691 | uint32_t prefix = 0; | |
53a8c753 | 6692 | uint32_t point_index = start; |
bbaa79b8 | 6693 | |
8c4e53e8 PA |
6694 | if (*len < count/8) { |
6695 | goto error; | |
6696 | } | |
bbaa79b8 JI |
6697 | while (count--) { |
6698 | ||
6699 | object = SCCalloc(1, sizeof(*object)); | |
6700 | if (unlikely(object == NULL)) { | |
6701 | goto error; | |
6702 | } | |
6703 | ||
6704 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6705 | goto error; | |
6706 | } | |
6707 | ||
6708 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6709 | goto error; | |
6710 | } | |
6711 | ||
53a8c753 | 6712 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6713 | goto error; |
6714 | } | |
6715 | ||
6716 | object = NULL; | |
53a8c753 | 6717 | point_index++; |
bbaa79b8 JI |
6718 | } |
6719 | ||
6720 | return 1; | |
6721 | error: | |
6722 | if (object != NULL) { | |
6723 | SCFree(object); | |
6724 | } | |
6725 | ||
6726 | return 0; | |
6727 | } | |
6728 | ||
6729 | static int DNP3DecodeObjectG51V2(const uint8_t **buf, uint32_t *len, | |
6730 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6731 | DNP3PointList *points) | |
6732 | { | |
6733 | DNP3ObjectG51V2 *object = NULL; | |
6734 | uint32_t prefix = 0; | |
53a8c753 | 6735 | uint32_t point_index = start; |
bbaa79b8 | 6736 | |
8c4e53e8 PA |
6737 | if (*len < count/8) { |
6738 | goto error; | |
6739 | } | |
bbaa79b8 JI |
6740 | while (count--) { |
6741 | ||
6742 | object = SCCalloc(1, sizeof(*object)); | |
6743 | if (unlikely(object == NULL)) { | |
6744 | goto error; | |
6745 | } | |
6746 | ||
6747 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6748 | goto error; | |
6749 | } | |
6750 | ||
6751 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
6752 | goto error; | |
6753 | } | |
6754 | ||
53a8c753 | 6755 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6756 | goto error; |
6757 | } | |
6758 | ||
6759 | object = NULL; | |
53a8c753 | 6760 | point_index++; |
bbaa79b8 JI |
6761 | } |
6762 | ||
6763 | return 1; | |
6764 | error: | |
6765 | if (object != NULL) { | |
6766 | SCFree(object); | |
6767 | } | |
6768 | ||
6769 | return 0; | |
6770 | } | |
6771 | ||
6772 | static int DNP3DecodeObjectG52V1(const uint8_t **buf, uint32_t *len, | |
6773 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6774 | DNP3PointList *points) | |
6775 | { | |
6776 | DNP3ObjectG52V1 *object = NULL; | |
6777 | uint32_t prefix = 0; | |
53a8c753 | 6778 | uint32_t point_index = start; |
bbaa79b8 | 6779 | |
8c4e53e8 PA |
6780 | if (*len < count/8) { |
6781 | goto error; | |
6782 | } | |
bbaa79b8 JI |
6783 | while (count--) { |
6784 | ||
6785 | object = SCCalloc(1, sizeof(*object)); | |
6786 | if (unlikely(object == NULL)) { | |
6787 | goto error; | |
6788 | } | |
6789 | ||
6790 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6791 | goto error; | |
6792 | } | |
6793 | ||
6794 | if (!DNP3ReadUint16(buf, len, &object->delay_secs)) { | |
6795 | goto error; | |
6796 | } | |
6797 | ||
53a8c753 | 6798 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6799 | goto error; |
6800 | } | |
6801 | ||
6802 | object = NULL; | |
53a8c753 | 6803 | point_index++; |
bbaa79b8 JI |
6804 | } |
6805 | ||
6806 | return 1; | |
6807 | error: | |
6808 | if (object != NULL) { | |
6809 | SCFree(object); | |
6810 | } | |
6811 | ||
6812 | return 0; | |
6813 | } | |
6814 | ||
6815 | static int DNP3DecodeObjectG52V2(const uint8_t **buf, uint32_t *len, | |
6816 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6817 | DNP3PointList *points) | |
6818 | { | |
6819 | DNP3ObjectG52V2 *object = NULL; | |
6820 | uint32_t prefix = 0; | |
53a8c753 | 6821 | uint32_t point_index = start; |
bbaa79b8 | 6822 | |
8c4e53e8 PA |
6823 | if (*len < count/8) { |
6824 | goto error; | |
6825 | } | |
bbaa79b8 JI |
6826 | while (count--) { |
6827 | ||
6828 | object = SCCalloc(1, sizeof(*object)); | |
6829 | if (unlikely(object == NULL)) { | |
6830 | goto error; | |
6831 | } | |
6832 | ||
6833 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6834 | goto error; | |
6835 | } | |
6836 | ||
6837 | if (!DNP3ReadUint16(buf, len, &object->delay_ms)) { | |
6838 | goto error; | |
6839 | } | |
6840 | ||
53a8c753 | 6841 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6842 | goto error; |
6843 | } | |
6844 | ||
6845 | object = NULL; | |
53a8c753 | 6846 | point_index++; |
bbaa79b8 JI |
6847 | } |
6848 | ||
6849 | return 1; | |
6850 | error: | |
6851 | if (object != NULL) { | |
6852 | SCFree(object); | |
6853 | } | |
6854 | ||
6855 | return 0; | |
6856 | } | |
6857 | ||
6858 | static int DNP3DecodeObjectG70V1(const uint8_t **buf, uint32_t *len, | |
6859 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6860 | DNP3PointList *points) | |
6861 | { | |
6862 | DNP3ObjectG70V1 *object = NULL; | |
6863 | uint32_t prefix = 0; | |
53a8c753 | 6864 | uint32_t point_index = start; |
bbaa79b8 | 6865 | |
8c4e53e8 PA |
6866 | if (*len < count/8) { |
6867 | goto error; | |
6868 | } | |
bbaa79b8 JI |
6869 | while (count--) { |
6870 | ||
6871 | object = SCCalloc(1, sizeof(*object)); | |
6872 | if (unlikely(object == NULL)) { | |
6873 | goto error; | |
6874 | } | |
6875 | ||
6876 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6877 | goto error; | |
6878 | } | |
6879 | ||
6880 | if (!DNP3ReadUint16(buf, len, &object->filename_size)) { | |
6881 | goto error; | |
6882 | } | |
6883 | if (!DNP3ReadUint8(buf, len, &object->filetype_code)) { | |
6884 | goto error; | |
6885 | } | |
6886 | if (!DNP3ReadUint8(buf, len, &object->attribute_code)) { | |
6887 | goto error; | |
6888 | } | |
6889 | if (!DNP3ReadUint16(buf, len, &object->start_record)) { | |
6890 | goto error; | |
6891 | } | |
6892 | if (!DNP3ReadUint16(buf, len, &object->end_record)) { | |
6893 | goto error; | |
6894 | } | |
6895 | if (!DNP3ReadUint32(buf, len, &object->file_size)) { | |
6896 | goto error; | |
6897 | } | |
6898 | if (!DNP3ReadUint48(buf, len, &object->created_timestamp)) { | |
6899 | goto error; | |
6900 | } | |
6901 | if (!DNP3ReadUint16(buf, len, &object->permission)) { | |
6902 | goto error; | |
6903 | } | |
6904 | if (!DNP3ReadUint32(buf, len, &object->file_id)) { | |
6905 | goto error; | |
6906 | } | |
6907 | if (!DNP3ReadUint32(buf, len, &object->owner_id)) { | |
6908 | goto error; | |
6909 | } | |
6910 | if (!DNP3ReadUint32(buf, len, &object->group_id)) { | |
6911 | goto error; | |
6912 | } | |
6913 | if (!DNP3ReadUint8(buf, len, &object->file_function_code)) { | |
6914 | goto error; | |
6915 | } | |
6916 | if (!DNP3ReadUint8(buf, len, &object->status_code)) { | |
6917 | goto error; | |
6918 | } | |
6919 | if (object->filename_size > 0) { | |
23ceb2cc JI |
6920 | if (*len < object->filename_size) { |
6921 | /* Not enough data. */ | |
6922 | goto error; | |
6923 | } | |
bbaa79b8 JI |
6924 | memcpy(object->filename, *buf, object->filename_size); |
6925 | *buf += object->filename_size; | |
6926 | *len -= object->filename_size; | |
6927 | } | |
6928 | object->filename[object->filename_size] = '\0'; | |
6929 | if (!DNP3ReadUint16(buf, len, &object->data_size)) { | |
6930 | goto error; | |
6931 | } | |
6932 | if (object->data_size > 0) { | |
23ceb2cc JI |
6933 | if (*len < object->data_size) { |
6934 | /* Not enough data. */ | |
6935 | goto error; | |
6936 | } | |
bbaa79b8 JI |
6937 | memcpy(object->data, *buf, object->data_size); |
6938 | *buf += object->data_size; | |
6939 | *len -= object->data_size; | |
6940 | } | |
6941 | object->data[object->data_size] = '\0'; | |
6942 | ||
53a8c753 | 6943 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
6944 | goto error; |
6945 | } | |
6946 | ||
6947 | object = NULL; | |
53a8c753 | 6948 | point_index++; |
bbaa79b8 JI |
6949 | } |
6950 | ||
6951 | return 1; | |
6952 | error: | |
6953 | if (object != NULL) { | |
6954 | SCFree(object); | |
6955 | } | |
6956 | ||
6957 | return 0; | |
6958 | } | |
6959 | ||
6960 | static int DNP3DecodeObjectG70V2(const uint8_t **buf, uint32_t *len, | |
6961 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
6962 | DNP3PointList *points) | |
6963 | { | |
6964 | DNP3ObjectG70V2 *object = NULL; | |
6965 | uint32_t prefix = 0; | |
53a8c753 | 6966 | uint32_t point_index = start; |
bbaa79b8 | 6967 | |
8c4e53e8 PA |
6968 | if (*len < count/8) { |
6969 | goto error; | |
6970 | } | |
bbaa79b8 JI |
6971 | while (count--) { |
6972 | ||
6973 | object = SCCalloc(1, sizeof(*object)); | |
6974 | if (unlikely(object == NULL)) { | |
6975 | goto error; | |
6976 | } | |
6977 | ||
6978 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
6979 | goto error; | |
6980 | } | |
6981 | ||
6982 | if (!DNP3ReadUint16(buf, len, &object->username_offset)) { | |
6983 | goto error; | |
6984 | } | |
6985 | if (!DNP3ReadUint16(buf, len, &object->username_size)) { | |
6986 | goto error; | |
6987 | } | |
6988 | if (!DNP3ReadUint16(buf, len, &object->password_offset)) { | |
6989 | goto error; | |
6990 | } | |
6991 | if (!DNP3ReadUint16(buf, len, &object->password_size)) { | |
6992 | goto error; | |
6993 | } | |
6994 | if (!DNP3ReadUint32(buf, len, &object->authentication_key)) { | |
6995 | goto error; | |
6996 | } | |
6997 | if (object->username_size > 0) { | |
23ceb2cc JI |
6998 | if (*len < object->username_size) { |
6999 | /* Not enough data. */ | |
7000 | goto error; | |
7001 | } | |
bbaa79b8 JI |
7002 | memcpy(object->username, *buf, object->username_size); |
7003 | *buf += object->username_size; | |
7004 | *len -= object->username_size; | |
7005 | } | |
7006 | object->username[object->username_size] = '\0'; | |
7007 | if (object->password_size > 0) { | |
23ceb2cc JI |
7008 | if (*len < object->password_size) { |
7009 | /* Not enough data. */ | |
7010 | goto error; | |
7011 | } | |
bbaa79b8 JI |
7012 | memcpy(object->password, *buf, object->password_size); |
7013 | *buf += object->password_size; | |
7014 | *len -= object->password_size; | |
7015 | } | |
7016 | object->password[object->password_size] = '\0'; | |
7017 | ||
53a8c753 | 7018 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7019 | goto error; |
7020 | } | |
7021 | ||
7022 | object = NULL; | |
53a8c753 | 7023 | point_index++; |
bbaa79b8 JI |
7024 | } |
7025 | ||
7026 | return 1; | |
7027 | error: | |
7028 | if (object != NULL) { | |
7029 | SCFree(object); | |
7030 | } | |
7031 | ||
7032 | return 0; | |
7033 | } | |
7034 | ||
7035 | static int DNP3DecodeObjectG70V3(const uint8_t **buf, uint32_t *len, | |
7036 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7037 | DNP3PointList *points) | |
7038 | { | |
7039 | DNP3ObjectG70V3 *object = NULL; | |
7040 | uint32_t prefix = 0; | |
53a8c753 | 7041 | uint32_t point_index = start; |
bbaa79b8 | 7042 | |
8c4e53e8 PA |
7043 | if (*len < count/8) { |
7044 | goto error; | |
7045 | } | |
bbaa79b8 JI |
7046 | while (count--) { |
7047 | ||
7048 | object = SCCalloc(1, sizeof(*object)); | |
7049 | if (unlikely(object == NULL)) { | |
7050 | goto error; | |
7051 | } | |
7052 | ||
7053 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7054 | goto error; | |
7055 | } | |
7056 | ||
7057 | if (!DNP3ReadUint16(buf, len, &object->filename_offset)) { | |
7058 | goto error; | |
7059 | } | |
7060 | if (!DNP3ReadUint16(buf, len, &object->filename_size)) { | |
7061 | goto error; | |
7062 | } | |
7063 | if (!DNP3ReadUint48(buf, len, &object->created)) { | |
7064 | goto error; | |
7065 | } | |
7066 | if (!DNP3ReadUint16(buf, len, &object->permissions)) { | |
7067 | goto error; | |
7068 | } | |
7069 | if (!DNP3ReadUint32(buf, len, &object->authentication_key)) { | |
7070 | goto error; | |
7071 | } | |
7072 | if (!DNP3ReadUint32(buf, len, &object->file_size)) { | |
7073 | goto error; | |
7074 | } | |
7075 | if (!DNP3ReadUint16(buf, len, &object->operational_mode)) { | |
7076 | goto error; | |
7077 | } | |
7078 | if (!DNP3ReadUint16(buf, len, &object->maximum_block_size)) { | |
7079 | goto error; | |
7080 | } | |
7081 | if (!DNP3ReadUint16(buf, len, &object->request_id)) { | |
7082 | goto error; | |
7083 | } | |
7084 | if (object->filename_size > 0) { | |
23ceb2cc JI |
7085 | if (*len < object->filename_size) { |
7086 | /* Not enough data. */ | |
7087 | goto error; | |
7088 | } | |
bbaa79b8 JI |
7089 | memcpy(object->filename, *buf, object->filename_size); |
7090 | *buf += object->filename_size; | |
7091 | *len -= object->filename_size; | |
7092 | } | |
7093 | object->filename[object->filename_size] = '\0'; | |
7094 | ||
53a8c753 | 7095 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7096 | goto error; |
7097 | } | |
7098 | ||
7099 | object = NULL; | |
53a8c753 | 7100 | point_index++; |
bbaa79b8 JI |
7101 | } |
7102 | ||
7103 | return 1; | |
7104 | error: | |
7105 | if (object != NULL) { | |
7106 | SCFree(object); | |
7107 | } | |
7108 | ||
7109 | return 0; | |
7110 | } | |
7111 | ||
7112 | static int DNP3DecodeObjectG70V4(const uint8_t **buf, uint32_t *len, | |
7113 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7114 | DNP3PointList *points) | |
7115 | { | |
7116 | DNP3ObjectG70V4 *object = NULL; | |
7117 | uint32_t prefix = 0; | |
53a8c753 | 7118 | uint32_t point_index = start; |
bbaa79b8 JI |
7119 | uint32_t offset; |
7120 | ||
7121 | if (!DNP3PrefixIsSize(prefix_code)) { | |
7122 | goto error; | |
7123 | } | |
7124 | ||
8c4e53e8 PA |
7125 | if (*len < count/8) { |
7126 | goto error; | |
7127 | } | |
bbaa79b8 JI |
7128 | while (count--) { |
7129 | ||
7130 | object = SCCalloc(1, sizeof(*object)); | |
7131 | if (unlikely(object == NULL)) { | |
7132 | goto error; | |
7133 | } | |
7134 | ||
7135 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7136 | goto error; | |
7137 | } | |
7138 | ||
7139 | offset = *len; | |
7140 | ||
7141 | if (!DNP3ReadUint32(buf, len, &object->file_handle)) { | |
7142 | goto error; | |
7143 | } | |
7144 | if (!DNP3ReadUint32(buf, len, &object->file_size)) { | |
7145 | goto error; | |
7146 | } | |
7147 | if (!DNP3ReadUint16(buf, len, &object->maximum_block_size)) { | |
7148 | goto error; | |
7149 | } | |
7150 | if (!DNP3ReadUint16(buf, len, &object->request_id)) { | |
7151 | goto error; | |
7152 | } | |
7153 | if (!DNP3ReadUint8(buf, len, &object->status_code)) { | |
7154 | goto error; | |
7155 | } | |
86b5c81e | 7156 | if (prefix - (offset - *len) >= 255 || prefix < (offset - *len)) { |
44bd3169 PA |
7157 | goto error; |
7158 | } | |
86b5c81e | 7159 | object->optional_text_len = (uint8_t)(prefix - (offset - *len)); |
bbaa79b8 | 7160 | if (object->optional_text_len > 0) { |
23ceb2cc JI |
7161 | if (*len < object->optional_text_len) { |
7162 | /* Not enough data. */ | |
7163 | goto error; | |
7164 | } | |
bbaa79b8 JI |
7165 | memcpy(object->optional_text, *buf, object->optional_text_len); |
7166 | *buf += object->optional_text_len; | |
7167 | *len -= object->optional_text_len; | |
7168 | } | |
7169 | object->optional_text[object->optional_text_len] = '\0'; | |
7170 | ||
53a8c753 | 7171 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7172 | goto error; |
7173 | } | |
7174 | ||
7175 | object = NULL; | |
53a8c753 | 7176 | point_index++; |
bbaa79b8 JI |
7177 | } |
7178 | ||
7179 | return 1; | |
7180 | error: | |
7181 | if (object != NULL) { | |
7182 | SCFree(object); | |
7183 | } | |
7184 | ||
7185 | return 0; | |
7186 | } | |
7187 | ||
7188 | static int DNP3DecodeObjectG70V5(const uint8_t **buf, uint32_t *len, | |
7189 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7190 | DNP3PointList *points) | |
7191 | { | |
7192 | DNP3ObjectG70V5 *object = NULL; | |
7193 | uint32_t prefix = 0; | |
53a8c753 | 7194 | uint32_t point_index = start; |
bbaa79b8 JI |
7195 | uint32_t offset; |
7196 | ||
7197 | if (!DNP3PrefixIsSize(prefix_code)) { | |
7198 | goto error; | |
7199 | } | |
7200 | ||
8c4e53e8 PA |
7201 | if (*len < count/8) { |
7202 | goto error; | |
7203 | } | |
bbaa79b8 JI |
7204 | while (count--) { |
7205 | ||
7206 | object = SCCalloc(1, sizeof(*object)); | |
7207 | if (unlikely(object == NULL)) { | |
7208 | goto error; | |
7209 | } | |
7210 | ||
7211 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7212 | goto error; | |
7213 | } | |
7214 | ||
7215 | offset = *len; | |
7216 | ||
7217 | if (!DNP3ReadUint32(buf, len, &object->file_handle)) { | |
7218 | goto error; | |
7219 | } | |
7220 | if (!DNP3ReadUint32(buf, len, &object->block_number)) { | |
7221 | goto error; | |
7222 | } | |
86b5c81e | 7223 | if (prefix - (offset - *len) >= 255 || prefix < (offset - *len)) { |
44bd3169 PA |
7224 | goto error; |
7225 | } | |
86b5c81e | 7226 | object->file_data_len = (uint8_t)(prefix - (offset - *len)); |
bbaa79b8 | 7227 | if (object->file_data_len > 0) { |
23ceb2cc JI |
7228 | if (*len < object->file_data_len) { |
7229 | /* Not enough data. */ | |
7230 | goto error; | |
7231 | } | |
bbaa79b8 JI |
7232 | memcpy(object->file_data, *buf, object->file_data_len); |
7233 | *buf += object->file_data_len; | |
7234 | *len -= object->file_data_len; | |
7235 | } | |
7236 | object->file_data[object->file_data_len] = '\0'; | |
7237 | ||
53a8c753 | 7238 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7239 | goto error; |
7240 | } | |
7241 | ||
7242 | object = NULL; | |
53a8c753 | 7243 | point_index++; |
bbaa79b8 JI |
7244 | } |
7245 | ||
7246 | return 1; | |
7247 | error: | |
7248 | if (object != NULL) { | |
7249 | SCFree(object); | |
7250 | } | |
7251 | ||
7252 | return 0; | |
7253 | } | |
7254 | ||
7255 | static int DNP3DecodeObjectG70V6(const uint8_t **buf, uint32_t *len, | |
7256 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7257 | DNP3PointList *points) | |
7258 | { | |
7259 | DNP3ObjectG70V6 *object = NULL; | |
7260 | uint32_t prefix = 0; | |
53a8c753 | 7261 | uint32_t point_index = start; |
bbaa79b8 JI |
7262 | uint32_t offset; |
7263 | ||
7264 | if (!DNP3PrefixIsSize(prefix_code)) { | |
7265 | goto error; | |
7266 | } | |
7267 | ||
8c4e53e8 PA |
7268 | if (*len < count/8) { |
7269 | goto error; | |
7270 | } | |
bbaa79b8 JI |
7271 | while (count--) { |
7272 | ||
7273 | object = SCCalloc(1, sizeof(*object)); | |
7274 | if (unlikely(object == NULL)) { | |
7275 | goto error; | |
7276 | } | |
7277 | ||
7278 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7279 | goto error; | |
7280 | } | |
7281 | ||
7282 | offset = *len; | |
7283 | ||
7284 | if (!DNP3ReadUint32(buf, len, &object->file_handle)) { | |
7285 | goto error; | |
7286 | } | |
7287 | if (!DNP3ReadUint32(buf, len, &object->block_number)) { | |
7288 | goto error; | |
7289 | } | |
7290 | if (!DNP3ReadUint8(buf, len, &object->status_code)) { | |
7291 | goto error; | |
7292 | } | |
86b5c81e | 7293 | if (prefix - (offset - *len) >= 255 || prefix < (offset - *len)) { |
44bd3169 PA |
7294 | goto error; |
7295 | } | |
86b5c81e | 7296 | object->optional_text_len = (uint8_t)(prefix - (offset - *len)); |
bbaa79b8 | 7297 | if (object->optional_text_len > 0) { |
23ceb2cc JI |
7298 | if (*len < object->optional_text_len) { |
7299 | /* Not enough data. */ | |
7300 | goto error; | |
7301 | } | |
bbaa79b8 JI |
7302 | memcpy(object->optional_text, *buf, object->optional_text_len); |
7303 | *buf += object->optional_text_len; | |
7304 | *len -= object->optional_text_len; | |
7305 | } | |
7306 | object->optional_text[object->optional_text_len] = '\0'; | |
7307 | ||
53a8c753 | 7308 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7309 | goto error; |
7310 | } | |
7311 | ||
7312 | object = NULL; | |
53a8c753 | 7313 | point_index++; |
bbaa79b8 JI |
7314 | } |
7315 | ||
7316 | return 1; | |
7317 | error: | |
7318 | if (object != NULL) { | |
7319 | SCFree(object); | |
7320 | } | |
7321 | ||
7322 | return 0; | |
7323 | } | |
7324 | ||
7325 | static int DNP3DecodeObjectG70V7(const uint8_t **buf, uint32_t *len, | |
7326 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7327 | DNP3PointList *points) | |
7328 | { | |
7329 | DNP3ObjectG70V7 *object = NULL; | |
7330 | uint32_t prefix = 0; | |
53a8c753 | 7331 | uint32_t point_index = start; |
bbaa79b8 | 7332 | |
8c4e53e8 PA |
7333 | if (*len < count/8) { |
7334 | goto error; | |
7335 | } | |
bbaa79b8 JI |
7336 | while (count--) { |
7337 | ||
7338 | object = SCCalloc(1, sizeof(*object)); | |
7339 | if (unlikely(object == NULL)) { | |
7340 | goto error; | |
7341 | } | |
7342 | ||
7343 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7344 | goto error; | |
7345 | } | |
7346 | ||
7347 | if (!DNP3ReadUint16(buf, len, &object->filename_offset)) { | |
7348 | goto error; | |
7349 | } | |
7350 | if (!DNP3ReadUint16(buf, len, &object->filename_size)) { | |
7351 | goto error; | |
7352 | } | |
7353 | if (!DNP3ReadUint16(buf, len, &object->file_type)) { | |
7354 | goto error; | |
7355 | } | |
7356 | if (!DNP3ReadUint32(buf, len, &object->file_size)) { | |
7357 | goto error; | |
7358 | } | |
7359 | if (!DNP3ReadUint48(buf, len, &object->created_timestamp)) { | |
7360 | goto error; | |
7361 | } | |
7362 | if (!DNP3ReadUint16(buf, len, &object->permissions)) { | |
7363 | goto error; | |
7364 | } | |
7365 | if (!DNP3ReadUint16(buf, len, &object->request_id)) { | |
7366 | goto error; | |
7367 | } | |
7368 | if (object->filename_size > 0) { | |
23ceb2cc JI |
7369 | if (*len < object->filename_size) { |
7370 | /* Not enough data. */ | |
7371 | goto error; | |
7372 | } | |
bbaa79b8 JI |
7373 | memcpy(object->filename, *buf, object->filename_size); |
7374 | *buf += object->filename_size; | |
7375 | *len -= object->filename_size; | |
7376 | } | |
7377 | object->filename[object->filename_size] = '\0'; | |
7378 | ||
53a8c753 | 7379 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7380 | goto error; |
7381 | } | |
7382 | ||
7383 | object = NULL; | |
53a8c753 | 7384 | point_index++; |
bbaa79b8 JI |
7385 | } |
7386 | ||
7387 | return 1; | |
7388 | error: | |
7389 | if (object != NULL) { | |
7390 | SCFree(object); | |
7391 | } | |
7392 | ||
7393 | return 0; | |
7394 | } | |
7395 | ||
7396 | static int DNP3DecodeObjectG70V8(const uint8_t **buf, uint32_t *len, | |
7397 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7398 | DNP3PointList *points) | |
7399 | { | |
7400 | DNP3ObjectG70V8 *object = NULL; | |
7401 | uint32_t prefix = 0; | |
53a8c753 | 7402 | uint32_t point_index = start; |
bbaa79b8 JI |
7403 | uint32_t offset; |
7404 | ||
7405 | if (prefix_code != 5) { | |
7406 | goto error; | |
7407 | } | |
7408 | ||
8c4e53e8 PA |
7409 | if (*len < count/8) { |
7410 | goto error; | |
7411 | } | |
bbaa79b8 JI |
7412 | while (count--) { |
7413 | ||
7414 | object = SCCalloc(1, sizeof(*object)); | |
7415 | if (unlikely(object == NULL)) { | |
7416 | goto error; | |
7417 | } | |
7418 | ||
7419 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7420 | goto error; | |
7421 | } | |
7422 | ||
7423 | offset = *len; | |
7424 | ||
86b5c81e | 7425 | if (prefix - (offset - *len) >= 65535 || prefix < (offset - *len)) { |
44bd3169 PA |
7426 | goto error; |
7427 | } | |
86b5c81e | 7428 | object->file_specification_len = (uint16_t)(prefix - (offset - *len)); |
bbaa79b8 | 7429 | if (object->file_specification_len > 0) { |
23ceb2cc JI |
7430 | if (*len < object->file_specification_len) { |
7431 | /* Not enough data. */ | |
7432 | goto error; | |
7433 | } | |
bbaa79b8 JI |
7434 | memcpy(object->file_specification, *buf, object->file_specification_len); |
7435 | *buf += object->file_specification_len; | |
7436 | *len -= object->file_specification_len; | |
7437 | } | |
7438 | object->file_specification[object->file_specification_len] = '\0'; | |
7439 | ||
53a8c753 | 7440 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7441 | goto error; |
7442 | } | |
7443 | ||
7444 | object = NULL; | |
53a8c753 | 7445 | point_index++; |
bbaa79b8 JI |
7446 | } |
7447 | ||
7448 | return 1; | |
7449 | error: | |
7450 | if (object != NULL) { | |
7451 | SCFree(object); | |
7452 | } | |
7453 | ||
7454 | return 0; | |
7455 | } | |
7456 | ||
7457 | static int DNP3DecodeObjectG80V1(const uint8_t **buf, uint32_t *len, | |
7458 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7459 | DNP3PointList *points) | |
7460 | { | |
7461 | DNP3ObjectG80V1 *object = NULL; | |
8c4e53e8 | 7462 | uint32_t bytes = (count / 8) + 1; |
bbaa79b8 | 7463 | uint32_t prefix = 0; |
8c4e53e8 | 7464 | uint32_t point_index = start; |
bbaa79b8 JI |
7465 | |
7466 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7467 | goto error; | |
7468 | } | |
7469 | ||
8c4e53e8 | 7470 | for (uint32_t i = 0; i < bytes; i++) { |
bbaa79b8 JI |
7471 | |
7472 | uint8_t octet; | |
7473 | ||
7474 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
7475 | goto error; | |
7476 | } | |
7477 | ||
7478 | for (int j = 0; j < 8 && count; j = j + 1) { | |
7479 | ||
7480 | object = SCCalloc(1, sizeof(*object)); | |
7481 | if (unlikely(object == NULL)) { | |
7482 | goto error; | |
7483 | } | |
7484 | ||
7485 | object->state = (octet >> j) & 0x1; | |
7486 | ||
53a8c753 | 7487 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7488 | goto error; |
7489 | } | |
7490 | ||
7491 | object = NULL; | |
7492 | count--; | |
53a8c753 | 7493 | point_index++; |
bbaa79b8 JI |
7494 | } |
7495 | ||
7496 | } | |
7497 | ||
7498 | return 1; | |
7499 | error: | |
7500 | if (object != NULL) { | |
7501 | SCFree(object); | |
7502 | } | |
7503 | return 0; | |
7504 | } | |
7505 | ||
7506 | static int DNP3DecodeObjectG81V1(const uint8_t **buf, uint32_t *len, | |
7507 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7508 | DNP3PointList *points) | |
7509 | { | |
7510 | DNP3ObjectG81V1 *object = NULL; | |
7511 | uint32_t prefix = 0; | |
53a8c753 | 7512 | uint32_t point_index = start; |
bbaa79b8 | 7513 | |
8c4e53e8 PA |
7514 | if (*len < count/8) { |
7515 | goto error; | |
7516 | } | |
bbaa79b8 JI |
7517 | while (count--) { |
7518 | ||
7519 | object = SCCalloc(1, sizeof(*object)); | |
7520 | if (unlikely(object == NULL)) { | |
7521 | goto error; | |
7522 | } | |
7523 | ||
7524 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7525 | goto error; | |
7526 | } | |
7527 | ||
7528 | { | |
7529 | uint8_t octet; | |
7530 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
7531 | goto error; | |
7532 | } | |
7533 | object->fill_percentage = (octet >> 0) & 0x7f; | |
7534 | object->overflow_state = (octet >> 7) & 0x1; | |
7535 | } | |
7536 | if (!DNP3ReadUint8(buf, len, &object->group)) { | |
7537 | goto error; | |
7538 | } | |
7539 | if (!DNP3ReadUint8(buf, len, &object->variation)) { | |
7540 | goto error; | |
7541 | } | |
7542 | ||
53a8c753 | 7543 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7544 | goto error; |
7545 | } | |
7546 | ||
7547 | object = NULL; | |
53a8c753 | 7548 | point_index++; |
bbaa79b8 JI |
7549 | } |
7550 | ||
7551 | return 1; | |
7552 | error: | |
7553 | if (object != NULL) { | |
7554 | SCFree(object); | |
7555 | } | |
7556 | ||
7557 | return 0; | |
7558 | } | |
7559 | ||
7560 | static int DNP3DecodeObjectG83V1(const uint8_t **buf, uint32_t *len, | |
7561 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7562 | DNP3PointList *points) | |
7563 | { | |
7564 | DNP3ObjectG83V1 *object = NULL; | |
7565 | uint32_t prefix = 0; | |
53a8c753 | 7566 | uint32_t point_index = start; |
bbaa79b8 | 7567 | |
8c4e53e8 PA |
7568 | if (*len < count/8) { |
7569 | goto error; | |
7570 | } | |
bbaa79b8 JI |
7571 | while (count--) { |
7572 | ||
7573 | object = SCCalloc(1, sizeof(*object)); | |
7574 | if (unlikely(object == NULL)) { | |
7575 | goto error; | |
7576 | } | |
7577 | ||
7578 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7579 | goto error; | |
7580 | } | |
7581 | ||
7582 | if (*len < 4) { | |
7583 | goto error; | |
7584 | } | |
7585 | memcpy(object->vendor_code, *buf, 4); | |
7586 | object->vendor_code[4] = '\0'; | |
7587 | *buf += 4; | |
7588 | *len -= 4; | |
7589 | if (!DNP3ReadUint16(buf, len, &object->object_id)) { | |
7590 | goto error; | |
7591 | } | |
7592 | if (!DNP3ReadUint16(buf, len, &object->length)) { | |
7593 | goto error; | |
7594 | } | |
7595 | if (object->length > 0) { | |
7596 | if (*len < object->length) { | |
7597 | /* Not enough data. */ | |
7598 | goto error; | |
7599 | } | |
7600 | object->data_objects = SCCalloc(1, object->length); | |
7601 | if (unlikely(object->data_objects == NULL)) { | |
7602 | goto error; | |
7603 | } | |
7604 | memcpy(object->data_objects, *buf, object->length); | |
7605 | *buf += object->length; | |
7606 | *len -= object->length; | |
7607 | } | |
7608 | ||
53a8c753 | 7609 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7610 | goto error; |
7611 | } | |
7612 | ||
7613 | object = NULL; | |
53a8c753 | 7614 | point_index++; |
bbaa79b8 JI |
7615 | } |
7616 | ||
7617 | return 1; | |
7618 | error: | |
7619 | if (object != NULL) { | |
8c4e53e8 PA |
7620 | if (object->data_objects != NULL) { |
7621 | SCFree(object->data_objects); | |
7622 | } | |
bbaa79b8 JI |
7623 | SCFree(object); |
7624 | } | |
7625 | ||
7626 | return 0; | |
7627 | } | |
7628 | ||
7629 | static int DNP3DecodeObjectG86V2(const uint8_t **buf, uint32_t *len, | |
7630 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7631 | DNP3PointList *points) | |
7632 | { | |
7633 | DNP3ObjectG86V2 *object = NULL; | |
7634 | uint32_t prefix = 0; | |
53a8c753 | 7635 | uint32_t point_index = start; |
bbaa79b8 | 7636 | |
8c4e53e8 PA |
7637 | if (*len < count/8) { |
7638 | goto error; | |
7639 | } | |
bbaa79b8 JI |
7640 | while (count--) { |
7641 | ||
7642 | object = SCCalloc(1, sizeof(*object)); | |
7643 | if (unlikely(object == NULL)) { | |
7644 | goto error; | |
7645 | } | |
7646 | ||
7647 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7648 | goto error; | |
7649 | } | |
7650 | ||
7651 | { | |
7652 | uint8_t octet; | |
7653 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
7654 | goto error; | |
7655 | } | |
7656 | object->rd = (octet >> 0) & 0x1; | |
7657 | object->wr = (octet >> 1) & 0x1; | |
7658 | object->st = (octet >> 2) & 0x1; | |
7659 | object->ev = (octet >> 3) & 0x1; | |
7660 | object->df = (octet >> 4) & 0x1; | |
7661 | object->padding0 = (octet >> 5) & 0x1; | |
7662 | object->padding1 = (octet >> 6) & 0x1; | |
7663 | object->padding2 = (octet >> 7) & 0x1; | |
7664 | } | |
7665 | ||
53a8c753 | 7666 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7667 | goto error; |
7668 | } | |
7669 | ||
7670 | object = NULL; | |
53a8c753 | 7671 | point_index++; |
bbaa79b8 JI |
7672 | } |
7673 | ||
7674 | return 1; | |
7675 | error: | |
7676 | if (object != NULL) { | |
7677 | SCFree(object); | |
7678 | } | |
7679 | ||
7680 | return 0; | |
7681 | } | |
7682 | ||
7683 | static int DNP3DecodeObjectG102V1(const uint8_t **buf, uint32_t *len, | |
7684 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7685 | DNP3PointList *points) | |
7686 | { | |
7687 | DNP3ObjectG102V1 *object = NULL; | |
7688 | uint32_t prefix = 0; | |
53a8c753 | 7689 | uint32_t point_index = start; |
bbaa79b8 | 7690 | |
8c4e53e8 PA |
7691 | if (*len < count/8) { |
7692 | goto error; | |
7693 | } | |
bbaa79b8 JI |
7694 | while (count--) { |
7695 | ||
7696 | object = SCCalloc(1, sizeof(*object)); | |
7697 | if (unlikely(object == NULL)) { | |
7698 | goto error; | |
7699 | } | |
7700 | ||
7701 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7702 | goto error; | |
7703 | } | |
7704 | ||
7705 | if (!DNP3ReadUint8(buf, len, &object->value)) { | |
7706 | goto error; | |
7707 | } | |
7708 | ||
53a8c753 | 7709 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7710 | goto error; |
7711 | } | |
7712 | ||
7713 | object = NULL; | |
53a8c753 | 7714 | point_index++; |
bbaa79b8 JI |
7715 | } |
7716 | ||
7717 | return 1; | |
7718 | error: | |
7719 | if (object != NULL) { | |
7720 | SCFree(object); | |
7721 | } | |
7722 | ||
7723 | return 0; | |
7724 | } | |
7725 | ||
7726 | static int DNP3DecodeObjectG120V1(const uint8_t **buf, uint32_t *len, | |
7727 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7728 | DNP3PointList *points) | |
7729 | { | |
7730 | DNP3ObjectG120V1 *object = NULL; | |
7731 | uint32_t prefix = 0; | |
53a8c753 | 7732 | uint32_t point_index = start; |
bbaa79b8 JI |
7733 | uint32_t offset; |
7734 | ||
7735 | if (prefix_code != 5) { | |
7736 | goto error; | |
7737 | } | |
7738 | ||
8c4e53e8 PA |
7739 | if (*len < count/8) { |
7740 | goto error; | |
7741 | } | |
bbaa79b8 JI |
7742 | while (count--) { |
7743 | ||
7744 | object = SCCalloc(1, sizeof(*object)); | |
7745 | if (unlikely(object == NULL)) { | |
7746 | goto error; | |
7747 | } | |
7748 | ||
7749 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7750 | goto error; | |
7751 | } | |
7752 | ||
7753 | offset = *len; | |
7754 | ||
7755 | if (!DNP3ReadUint32(buf, len, &object->csq)) { | |
7756 | goto error; | |
7757 | } | |
7758 | if (!DNP3ReadUint16(buf, len, &object->usr)) { | |
7759 | goto error; | |
7760 | } | |
7761 | if (!DNP3ReadUint8(buf, len, &object->mal)) { | |
7762 | goto error; | |
7763 | } | |
7764 | if (!DNP3ReadUint8(buf, len, &object->reason)) { | |
7765 | goto error; | |
7766 | } | |
86b5c81e PA |
7767 | if (prefix < (offset - *len)) { |
7768 | goto error; | |
7769 | } | |
7770 | object->challenge_data_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
7771 | if (object->challenge_data_len > 0) { |
7772 | if (*len < object->challenge_data_len) { | |
7773 | /* Not enough data. */ | |
7774 | goto error; | |
7775 | } | |
7776 | object->challenge_data = SCCalloc(1, object->challenge_data_len); | |
7777 | if (unlikely(object->challenge_data == NULL)) { | |
7778 | goto error; | |
7779 | } | |
7780 | memcpy(object->challenge_data, *buf, object->challenge_data_len); | |
7781 | *buf += object->challenge_data_len; | |
7782 | *len -= object->challenge_data_len; | |
7783 | } | |
7784 | ||
53a8c753 | 7785 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7786 | goto error; |
7787 | } | |
7788 | ||
7789 | object = NULL; | |
53a8c753 | 7790 | point_index++; |
bbaa79b8 JI |
7791 | } |
7792 | ||
7793 | return 1; | |
7794 | error: | |
7795 | if (object != NULL) { | |
8c4e53e8 PA |
7796 | if (object->challenge_data != NULL) { |
7797 | SCFree(object->challenge_data); | |
7798 | } | |
bbaa79b8 JI |
7799 | SCFree(object); |
7800 | } | |
7801 | ||
7802 | return 0; | |
7803 | } | |
7804 | ||
7805 | static int DNP3DecodeObjectG120V2(const uint8_t **buf, uint32_t *len, | |
7806 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7807 | DNP3PointList *points) | |
7808 | { | |
7809 | DNP3ObjectG120V2 *object = NULL; | |
7810 | uint32_t prefix = 0; | |
53a8c753 | 7811 | uint32_t point_index = start; |
bbaa79b8 JI |
7812 | uint32_t offset; |
7813 | ||
7814 | if (prefix_code != 5) { | |
7815 | goto error; | |
7816 | } | |
7817 | ||
8c4e53e8 PA |
7818 | if (*len < count/8) { |
7819 | goto error; | |
7820 | } | |
bbaa79b8 JI |
7821 | while (count--) { |
7822 | ||
7823 | object = SCCalloc(1, sizeof(*object)); | |
7824 | if (unlikely(object == NULL)) { | |
7825 | goto error; | |
7826 | } | |
7827 | ||
7828 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7829 | goto error; | |
7830 | } | |
7831 | ||
7832 | offset = *len; | |
7833 | ||
7834 | if (!DNP3ReadUint32(buf, len, &object->csq)) { | |
7835 | goto error; | |
7836 | } | |
7837 | if (!DNP3ReadUint16(buf, len, &object->usr)) { | |
7838 | goto error; | |
7839 | } | |
86b5c81e PA |
7840 | if (prefix < (offset - *len)) { |
7841 | goto error; | |
7842 | } | |
7843 | object->mac_value_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
7844 | if (object->mac_value_len > 0) { |
7845 | if (*len < object->mac_value_len) { | |
7846 | /* Not enough data. */ | |
7847 | goto error; | |
7848 | } | |
7849 | object->mac_value = SCCalloc(1, object->mac_value_len); | |
7850 | if (unlikely(object->mac_value == NULL)) { | |
7851 | goto error; | |
7852 | } | |
7853 | memcpy(object->mac_value, *buf, object->mac_value_len); | |
7854 | *buf += object->mac_value_len; | |
7855 | *len -= object->mac_value_len; | |
7856 | } | |
7857 | ||
53a8c753 | 7858 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7859 | goto error; |
7860 | } | |
7861 | ||
7862 | object = NULL; | |
53a8c753 | 7863 | point_index++; |
bbaa79b8 JI |
7864 | } |
7865 | ||
7866 | return 1; | |
7867 | error: | |
7868 | if (object != NULL) { | |
8c4e53e8 PA |
7869 | if (object->mac_value != NULL) { |
7870 | SCFree(object->mac_value); | |
7871 | } | |
bbaa79b8 JI |
7872 | SCFree(object); |
7873 | } | |
7874 | ||
7875 | return 0; | |
7876 | } | |
7877 | ||
7878 | static int DNP3DecodeObjectG120V3(const uint8_t **buf, uint32_t *len, | |
7879 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7880 | DNP3PointList *points) | |
7881 | { | |
7882 | DNP3ObjectG120V3 *object = NULL; | |
7883 | uint32_t prefix = 0; | |
53a8c753 | 7884 | uint32_t point_index = start; |
bbaa79b8 | 7885 | |
8c4e53e8 PA |
7886 | if (*len < count/8) { |
7887 | goto error; | |
7888 | } | |
bbaa79b8 JI |
7889 | while (count--) { |
7890 | ||
7891 | object = SCCalloc(1, sizeof(*object)); | |
7892 | if (unlikely(object == NULL)) { | |
7893 | goto error; | |
7894 | } | |
7895 | ||
7896 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7897 | goto error; | |
7898 | } | |
7899 | ||
7900 | if (!DNP3ReadUint32(buf, len, &object->csq)) { | |
7901 | goto error; | |
7902 | } | |
7903 | if (!DNP3ReadUint16(buf, len, &object->user_number)) { | |
7904 | goto error; | |
7905 | } | |
7906 | ||
53a8c753 | 7907 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7908 | goto error; |
7909 | } | |
7910 | ||
7911 | object = NULL; | |
53a8c753 | 7912 | point_index++; |
bbaa79b8 JI |
7913 | } |
7914 | ||
7915 | return 1; | |
7916 | error: | |
7917 | if (object != NULL) { | |
7918 | SCFree(object); | |
7919 | } | |
7920 | ||
7921 | return 0; | |
7922 | } | |
7923 | ||
7924 | static int DNP3DecodeObjectG120V4(const uint8_t **buf, uint32_t *len, | |
7925 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7926 | DNP3PointList *points) | |
7927 | { | |
7928 | DNP3ObjectG120V4 *object = NULL; | |
7929 | uint32_t prefix = 0; | |
53a8c753 | 7930 | uint32_t point_index = start; |
bbaa79b8 | 7931 | |
8c4e53e8 PA |
7932 | if (*len < count/8) { |
7933 | goto error; | |
7934 | } | |
bbaa79b8 JI |
7935 | while (count--) { |
7936 | ||
7937 | object = SCCalloc(1, sizeof(*object)); | |
7938 | if (unlikely(object == NULL)) { | |
7939 | goto error; | |
7940 | } | |
7941 | ||
7942 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7943 | goto error; | |
7944 | } | |
7945 | ||
7946 | if (!DNP3ReadUint16(buf, len, &object->user_number)) { | |
7947 | goto error; | |
7948 | } | |
7949 | ||
53a8c753 | 7950 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
7951 | goto error; |
7952 | } | |
7953 | ||
7954 | object = NULL; | |
53a8c753 | 7955 | point_index++; |
bbaa79b8 JI |
7956 | } |
7957 | ||
7958 | return 1; | |
7959 | error: | |
7960 | if (object != NULL) { | |
7961 | SCFree(object); | |
7962 | } | |
7963 | ||
7964 | return 0; | |
7965 | } | |
7966 | ||
7967 | static int DNP3DecodeObjectG120V5(const uint8_t **buf, uint32_t *len, | |
7968 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
7969 | DNP3PointList *points) | |
7970 | { | |
7971 | DNP3ObjectG120V5 *object = NULL; | |
7972 | uint32_t prefix = 0; | |
53a8c753 | 7973 | uint32_t point_index = start; |
bbaa79b8 JI |
7974 | uint32_t offset; |
7975 | ||
7976 | if (prefix_code != 5) { | |
7977 | goto error; | |
7978 | } | |
7979 | ||
8c4e53e8 PA |
7980 | if (*len < count/8) { |
7981 | goto error; | |
7982 | } | |
bbaa79b8 JI |
7983 | while (count--) { |
7984 | ||
7985 | object = SCCalloc(1, sizeof(*object)); | |
7986 | if (unlikely(object == NULL)) { | |
7987 | goto error; | |
7988 | } | |
7989 | ||
7990 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
7991 | goto error; | |
7992 | } | |
7993 | ||
7994 | offset = *len; | |
7995 | ||
7996 | if (!DNP3ReadUint32(buf, len, &object->ksq)) { | |
7997 | goto error; | |
7998 | } | |
7999 | if (!DNP3ReadUint16(buf, len, &object->user_number)) { | |
8000 | goto error; | |
8001 | } | |
8002 | if (!DNP3ReadUint8(buf, len, &object->key_wrap_alg)) { | |
8003 | goto error; | |
8004 | } | |
8005 | if (!DNP3ReadUint8(buf, len, &object->key_status)) { | |
8006 | goto error; | |
8007 | } | |
8008 | if (!DNP3ReadUint8(buf, len, &object->mal)) { | |
8009 | goto error; | |
8010 | } | |
8011 | if (!DNP3ReadUint16(buf, len, &object->challenge_data_len)) { | |
8012 | goto error; | |
8013 | } | |
8014 | if (object->challenge_data_len > 0) { | |
8015 | if (*len < object->challenge_data_len) { | |
8016 | /* Not enough data. */ | |
8017 | goto error; | |
8018 | } | |
8019 | object->challenge_data = SCCalloc(1, object->challenge_data_len); | |
8020 | if (unlikely(object->challenge_data == NULL)) { | |
8021 | goto error; | |
8022 | } | |
8023 | memcpy(object->challenge_data, *buf, object->challenge_data_len); | |
8024 | *buf += object->challenge_data_len; | |
8025 | *len -= object->challenge_data_len; | |
8026 | } | |
86b5c81e PA |
8027 | if (prefix < (offset - *len)) { |
8028 | goto error; | |
8029 | } | |
8030 | object->mac_value_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8031 | if (object->mac_value_len > 0) { |
8032 | if (*len < object->mac_value_len) { | |
8033 | /* Not enough data. */ | |
8034 | goto error; | |
8035 | } | |
8036 | object->mac_value = SCCalloc(1, object->mac_value_len); | |
8037 | if (unlikely(object->mac_value == NULL)) { | |
8038 | goto error; | |
8039 | } | |
8040 | memcpy(object->mac_value, *buf, object->mac_value_len); | |
8041 | *buf += object->mac_value_len; | |
8042 | *len -= object->mac_value_len; | |
8043 | } | |
8044 | ||
53a8c753 | 8045 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8046 | goto error; |
8047 | } | |
8048 | ||
8049 | object = NULL; | |
53a8c753 | 8050 | point_index++; |
bbaa79b8 JI |
8051 | } |
8052 | ||
8053 | return 1; | |
8054 | error: | |
8055 | if (object != NULL) { | |
8c4e53e8 PA |
8056 | if (object->challenge_data != NULL) { |
8057 | SCFree(object->challenge_data); | |
8058 | } | |
8059 | if (object->mac_value != NULL) { | |
8060 | SCFree(object->mac_value); | |
8061 | } | |
bbaa79b8 JI |
8062 | SCFree(object); |
8063 | } | |
8064 | ||
8065 | return 0; | |
8066 | } | |
8067 | ||
8068 | static int DNP3DecodeObjectG120V6(const uint8_t **buf, uint32_t *len, | |
8069 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8070 | DNP3PointList *points) | |
8071 | { | |
8072 | DNP3ObjectG120V6 *object = NULL; | |
8073 | uint32_t prefix = 0; | |
53a8c753 | 8074 | uint32_t point_index = start; |
bbaa79b8 JI |
8075 | uint32_t offset; |
8076 | ||
8077 | if (prefix_code != 5) { | |
8078 | goto error; | |
8079 | } | |
8080 | ||
8c4e53e8 PA |
8081 | if (*len < count/8) { |
8082 | goto error; | |
8083 | } | |
bbaa79b8 JI |
8084 | while (count--) { |
8085 | ||
8086 | object = SCCalloc(1, sizeof(*object)); | |
8087 | if (unlikely(object == NULL)) { | |
8088 | goto error; | |
8089 | } | |
8090 | ||
8091 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8092 | goto error; | |
8093 | } | |
8094 | ||
8095 | offset = *len; | |
8096 | ||
8097 | if (!DNP3ReadUint24(buf, len, &object->ksq)) { | |
8098 | goto error; | |
8099 | } | |
8100 | if (!DNP3ReadUint16(buf, len, &object->usr)) { | |
8101 | goto error; | |
8102 | } | |
86b5c81e PA |
8103 | if (prefix < (offset - *len)) { |
8104 | goto error; | |
8105 | } | |
8106 | object->wrapped_key_data_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8107 | if (object->wrapped_key_data_len > 0) { |
8108 | if (*len < object->wrapped_key_data_len) { | |
8109 | /* Not enough data. */ | |
8110 | goto error; | |
8111 | } | |
8112 | object->wrapped_key_data = SCCalloc(1, object->wrapped_key_data_len); | |
8113 | if (unlikely(object->wrapped_key_data == NULL)) { | |
8114 | goto error; | |
8115 | } | |
8116 | memcpy(object->wrapped_key_data, *buf, object->wrapped_key_data_len); | |
8117 | *buf += object->wrapped_key_data_len; | |
8118 | *len -= object->wrapped_key_data_len; | |
8119 | } | |
8120 | ||
53a8c753 | 8121 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8122 | goto error; |
8123 | } | |
8124 | ||
8125 | object = NULL; | |
53a8c753 | 8126 | point_index++; |
bbaa79b8 JI |
8127 | } |
8128 | ||
8129 | return 1; | |
8130 | error: | |
8131 | if (object != NULL) { | |
8c4e53e8 PA |
8132 | if (object->wrapped_key_data != NULL) { |
8133 | SCFree(object->wrapped_key_data); | |
8134 | } | |
bbaa79b8 JI |
8135 | SCFree(object); |
8136 | } | |
8137 | ||
8138 | return 0; | |
8139 | } | |
8140 | ||
8141 | static int DNP3DecodeObjectG120V7(const uint8_t **buf, uint32_t *len, | |
8142 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8143 | DNP3PointList *points) | |
8144 | { | |
8145 | DNP3ObjectG120V7 *object = NULL; | |
8146 | uint32_t prefix = 0; | |
53a8c753 | 8147 | uint32_t point_index = start; |
bbaa79b8 JI |
8148 | uint32_t offset; |
8149 | ||
8150 | if (prefix_code != 5) { | |
8151 | goto error; | |
8152 | } | |
8153 | ||
8c4e53e8 PA |
8154 | if (*len < count/8) { |
8155 | goto error; | |
8156 | } | |
bbaa79b8 JI |
8157 | while (count--) { |
8158 | ||
8159 | object = SCCalloc(1, sizeof(*object)); | |
8160 | if (unlikely(object == NULL)) { | |
8161 | goto error; | |
8162 | } | |
8163 | ||
8164 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8165 | goto error; | |
8166 | } | |
8167 | ||
8168 | offset = *len; | |
8169 | ||
8170 | if (!DNP3ReadUint32(buf, len, &object->sequence_number)) { | |
8171 | goto error; | |
8172 | } | |
8173 | if (!DNP3ReadUint16(buf, len, &object->usr)) { | |
8174 | goto error; | |
8175 | } | |
8176 | if (!DNP3ReadUint16(buf, len, &object->association_id)) { | |
8177 | goto error; | |
8178 | } | |
8179 | if (!DNP3ReadUint8(buf, len, &object->error_code)) { | |
8180 | goto error; | |
8181 | } | |
8182 | if (!DNP3ReadUint48(buf, len, &object->time_of_error)) { | |
8183 | goto error; | |
8184 | } | |
86b5c81e | 8185 | if (prefix - (offset - *len) >= 65535 || prefix < (offset - *len)) { |
44bd3169 PA |
8186 | goto error; |
8187 | } | |
86b5c81e | 8188 | object->error_text_len = (uint16_t)(prefix - (offset - *len)); |
bbaa79b8 | 8189 | if (object->error_text_len > 0) { |
23ceb2cc JI |
8190 | if (*len < object->error_text_len) { |
8191 | /* Not enough data. */ | |
8192 | goto error; | |
8193 | } | |
bbaa79b8 JI |
8194 | memcpy(object->error_text, *buf, object->error_text_len); |
8195 | *buf += object->error_text_len; | |
8196 | *len -= object->error_text_len; | |
8197 | } | |
8198 | object->error_text[object->error_text_len] = '\0'; | |
8199 | ||
53a8c753 | 8200 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8201 | goto error; |
8202 | } | |
8203 | ||
8204 | object = NULL; | |
53a8c753 | 8205 | point_index++; |
bbaa79b8 JI |
8206 | } |
8207 | ||
8208 | return 1; | |
8209 | error: | |
8210 | if (object != NULL) { | |
8211 | SCFree(object); | |
8212 | } | |
8213 | ||
8214 | return 0; | |
8215 | } | |
8216 | ||
8217 | static int DNP3DecodeObjectG120V8(const uint8_t **buf, uint32_t *len, | |
8218 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8219 | DNP3PointList *points) | |
8220 | { | |
8221 | DNP3ObjectG120V8 *object = NULL; | |
8222 | uint32_t prefix = 0; | |
53a8c753 | 8223 | uint32_t point_index = start; |
bbaa79b8 JI |
8224 | uint32_t offset; |
8225 | ||
8226 | if (prefix_code != 5) { | |
8227 | goto error; | |
8228 | } | |
8229 | ||
8c4e53e8 PA |
8230 | if (*len < count/8) { |
8231 | goto error; | |
8232 | } | |
bbaa79b8 JI |
8233 | while (count--) { |
8234 | ||
8235 | object = SCCalloc(1, sizeof(*object)); | |
8236 | if (unlikely(object == NULL)) { | |
8237 | goto error; | |
8238 | } | |
8239 | ||
8240 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8241 | goto error; | |
8242 | } | |
8243 | ||
8244 | offset = *len; | |
8245 | ||
8246 | if (!DNP3ReadUint8(buf, len, &object->key_change_method)) { | |
8247 | goto error; | |
8248 | } | |
8249 | if (!DNP3ReadUint8(buf, len, &object->certificate_type)) { | |
8250 | goto error; | |
8251 | } | |
86b5c81e PA |
8252 | if (prefix < (offset - *len)) { |
8253 | goto error; | |
8254 | } | |
8255 | object->certificate_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8256 | if (object->certificate_len > 0) { |
8257 | if (*len < object->certificate_len) { | |
8258 | /* Not enough data. */ | |
8259 | goto error; | |
8260 | } | |
8261 | object->certificate = SCCalloc(1, object->certificate_len); | |
8262 | if (unlikely(object->certificate == NULL)) { | |
8263 | goto error; | |
8264 | } | |
8265 | memcpy(object->certificate, *buf, object->certificate_len); | |
8266 | *buf += object->certificate_len; | |
8267 | *len -= object->certificate_len; | |
8268 | } | |
8269 | ||
53a8c753 | 8270 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8271 | goto error; |
8272 | } | |
8273 | ||
8274 | object = NULL; | |
53a8c753 | 8275 | point_index++; |
bbaa79b8 JI |
8276 | } |
8277 | ||
8278 | return 1; | |
8279 | error: | |
8280 | if (object != NULL) { | |
8c4e53e8 PA |
8281 | if (object->certificate != NULL) { |
8282 | SCFree(object->certificate); | |
8283 | } | |
bbaa79b8 JI |
8284 | SCFree(object); |
8285 | } | |
8286 | ||
8287 | return 0; | |
8288 | } | |
8289 | ||
8290 | static int DNP3DecodeObjectG120V9(const uint8_t **buf, uint32_t *len, | |
8291 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8292 | DNP3PointList *points) | |
8293 | { | |
8294 | DNP3ObjectG120V9 *object = NULL; | |
8295 | uint32_t prefix = 0; | |
53a8c753 | 8296 | uint32_t point_index = start; |
bbaa79b8 JI |
8297 | uint32_t offset; |
8298 | ||
8c4e53e8 PA |
8299 | if (*len < count/8) { |
8300 | goto error; | |
8301 | } | |
bbaa79b8 JI |
8302 | while (count--) { |
8303 | ||
8304 | object = SCCalloc(1, sizeof(*object)); | |
8305 | if (unlikely(object == NULL)) { | |
8306 | goto error; | |
8307 | } | |
8308 | ||
8309 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8310 | goto error; | |
8311 | } | |
8312 | ||
8313 | offset = *len; | |
8314 | ||
86b5c81e PA |
8315 | if (prefix < (offset - *len)) { |
8316 | goto error; | |
8317 | } | |
8318 | object->mac_value_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8319 | if (object->mac_value_len > 0) { |
8320 | if (*len < object->mac_value_len) { | |
8321 | /* Not enough data. */ | |
8322 | goto error; | |
8323 | } | |
8324 | object->mac_value = SCCalloc(1, object->mac_value_len); | |
8325 | if (unlikely(object->mac_value == NULL)) { | |
8326 | goto error; | |
8327 | } | |
8328 | memcpy(object->mac_value, *buf, object->mac_value_len); | |
8329 | *buf += object->mac_value_len; | |
8330 | *len -= object->mac_value_len; | |
8331 | } | |
8332 | ||
53a8c753 | 8333 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8334 | goto error; |
8335 | } | |
8336 | ||
8337 | object = NULL; | |
53a8c753 | 8338 | point_index++; |
bbaa79b8 JI |
8339 | } |
8340 | ||
8341 | return 1; | |
8342 | error: | |
8343 | if (object != NULL) { | |
8c4e53e8 PA |
8344 | if (object->mac_value != NULL) { |
8345 | SCFree(object->mac_value); | |
8346 | } | |
bbaa79b8 JI |
8347 | SCFree(object); |
8348 | } | |
8349 | ||
8350 | return 0; | |
8351 | } | |
8352 | ||
8353 | static int DNP3DecodeObjectG120V10(const uint8_t **buf, uint32_t *len, | |
8354 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8355 | DNP3PointList *points) | |
8356 | { | |
8357 | DNP3ObjectG120V10 *object = NULL; | |
8358 | uint32_t prefix = 0; | |
53a8c753 | 8359 | uint32_t point_index = start; |
bbaa79b8 JI |
8360 | |
8361 | if (prefix_code != 5) { | |
8362 | goto error; | |
8363 | } | |
8364 | ||
8c4e53e8 PA |
8365 | if (*len < count/8) { |
8366 | goto error; | |
8367 | } | |
bbaa79b8 JI |
8368 | while (count--) { |
8369 | ||
8370 | object = SCCalloc(1, sizeof(*object)); | |
8371 | if (unlikely(object == NULL)) { | |
8372 | goto error; | |
8373 | } | |
8374 | ||
8375 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8376 | goto error; | |
8377 | } | |
8378 | ||
8379 | if (!DNP3ReadUint8(buf, len, &object->key_change_method)) { | |
8380 | goto error; | |
8381 | } | |
8382 | if (!DNP3ReadUint8(buf, len, &object->operation)) { | |
8383 | goto error; | |
8384 | } | |
8385 | if (!DNP3ReadUint32(buf, len, &object->scs)) { | |
8386 | goto error; | |
8387 | } | |
8388 | if (!DNP3ReadUint16(buf, len, &object->user_role)) { | |
8389 | goto error; | |
8390 | } | |
8391 | if (!DNP3ReadUint16(buf, len, &object->user_role_expiry_interval)) { | |
8392 | goto error; | |
8393 | } | |
8394 | if (!DNP3ReadUint16(buf, len, &object->username_len)) { | |
8395 | goto error; | |
8396 | } | |
8397 | if (!DNP3ReadUint16(buf, len, &object->user_public_key_len)) { | |
8398 | goto error; | |
8399 | } | |
8400 | if (!DNP3ReadUint16(buf, len, &object->certification_data_len)) { | |
8401 | goto error; | |
8402 | } | |
8403 | if (object->username_len > 0) { | |
23ceb2cc JI |
8404 | if (*len < object->username_len) { |
8405 | /* Not enough data. */ | |
8406 | goto error; | |
8407 | } | |
bbaa79b8 JI |
8408 | memcpy(object->username, *buf, object->username_len); |
8409 | *buf += object->username_len; | |
8410 | *len -= object->username_len; | |
8411 | } | |
8412 | object->username[object->username_len] = '\0'; | |
8413 | if (object->user_public_key_len > 0) { | |
8414 | if (*len < object->user_public_key_len) { | |
8415 | /* Not enough data. */ | |
8416 | goto error; | |
8417 | } | |
8418 | object->user_public_key = SCCalloc(1, object->user_public_key_len); | |
8419 | if (unlikely(object->user_public_key == NULL)) { | |
8420 | goto error; | |
8421 | } | |
8422 | memcpy(object->user_public_key, *buf, object->user_public_key_len); | |
8423 | *buf += object->user_public_key_len; | |
8424 | *len -= object->user_public_key_len; | |
8425 | } | |
8426 | if (object->certification_data_len > 0) { | |
8427 | if (*len < object->certification_data_len) { | |
8428 | /* Not enough data. */ | |
8429 | goto error; | |
8430 | } | |
8431 | object->certification_data = SCCalloc(1, object->certification_data_len); | |
8432 | if (unlikely(object->certification_data == NULL)) { | |
8433 | goto error; | |
8434 | } | |
8435 | memcpy(object->certification_data, *buf, object->certification_data_len); | |
8436 | *buf += object->certification_data_len; | |
8437 | *len -= object->certification_data_len; | |
8438 | } | |
8439 | ||
53a8c753 | 8440 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8441 | goto error; |
8442 | } | |
8443 | ||
8444 | object = NULL; | |
53a8c753 | 8445 | point_index++; |
bbaa79b8 JI |
8446 | } |
8447 | ||
8448 | return 1; | |
8449 | error: | |
8450 | if (object != NULL) { | |
8c4e53e8 PA |
8451 | if (object->user_public_key != NULL) { |
8452 | SCFree(object->user_public_key); | |
8453 | } | |
8454 | if (object->certification_data != NULL) { | |
8455 | SCFree(object->certification_data); | |
8456 | } | |
bbaa79b8 JI |
8457 | SCFree(object); |
8458 | } | |
8459 | ||
8460 | return 0; | |
8461 | } | |
8462 | ||
8463 | static int DNP3DecodeObjectG120V11(const uint8_t **buf, uint32_t *len, | |
8464 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8465 | DNP3PointList *points) | |
8466 | { | |
8467 | DNP3ObjectG120V11 *object = NULL; | |
8468 | uint32_t prefix = 0; | |
53a8c753 | 8469 | uint32_t point_index = start; |
bbaa79b8 JI |
8470 | |
8471 | if (prefix_code != 5) { | |
8472 | goto error; | |
8473 | } | |
8474 | ||
8c4e53e8 PA |
8475 | if (*len < count/8) { |
8476 | goto error; | |
8477 | } | |
bbaa79b8 JI |
8478 | while (count--) { |
8479 | ||
8480 | object = SCCalloc(1, sizeof(*object)); | |
8481 | if (unlikely(object == NULL)) { | |
8482 | goto error; | |
8483 | } | |
8484 | ||
8485 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8486 | goto error; | |
8487 | } | |
8488 | ||
8489 | if (!DNP3ReadUint8(buf, len, &object->key_change_method)) { | |
8490 | goto error; | |
8491 | } | |
8492 | if (!DNP3ReadUint16(buf, len, &object->username_len)) { | |
8493 | goto error; | |
8494 | } | |
8495 | if (!DNP3ReadUint16(buf, len, &object->master_challenge_data_len)) { | |
8496 | goto error; | |
8497 | } | |
8498 | if (object->username_len > 0) { | |
23ceb2cc JI |
8499 | if (*len < object->username_len) { |
8500 | /* Not enough data. */ | |
8501 | goto error; | |
8502 | } | |
bbaa79b8 JI |
8503 | memcpy(object->username, *buf, object->username_len); |
8504 | *buf += object->username_len; | |
8505 | *len -= object->username_len; | |
8506 | } | |
8507 | object->username[object->username_len] = '\0'; | |
8508 | if (object->master_challenge_data_len > 0) { | |
8509 | if (*len < object->master_challenge_data_len) { | |
8510 | /* Not enough data. */ | |
8511 | goto error; | |
8512 | } | |
8513 | object->master_challenge_data = SCCalloc(1, object->master_challenge_data_len); | |
8514 | if (unlikely(object->master_challenge_data == NULL)) { | |
8515 | goto error; | |
8516 | } | |
8517 | memcpy(object->master_challenge_data, *buf, object->master_challenge_data_len); | |
8518 | *buf += object->master_challenge_data_len; | |
8519 | *len -= object->master_challenge_data_len; | |
8520 | } | |
8521 | ||
53a8c753 | 8522 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8523 | goto error; |
8524 | } | |
8525 | ||
8526 | object = NULL; | |
53a8c753 | 8527 | point_index++; |
bbaa79b8 JI |
8528 | } |
8529 | ||
8530 | return 1; | |
8531 | error: | |
8532 | if (object != NULL) { | |
8c4e53e8 PA |
8533 | if (object->master_challenge_data != NULL) { |
8534 | SCFree(object->master_challenge_data); | |
8535 | } | |
bbaa79b8 JI |
8536 | SCFree(object); |
8537 | } | |
8538 | ||
8539 | return 0; | |
8540 | } | |
8541 | ||
8542 | static int DNP3DecodeObjectG120V12(const uint8_t **buf, uint32_t *len, | |
8543 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8544 | DNP3PointList *points) | |
8545 | { | |
8546 | DNP3ObjectG120V12 *object = NULL; | |
8547 | uint32_t prefix = 0; | |
53a8c753 | 8548 | uint32_t point_index = start; |
bbaa79b8 JI |
8549 | |
8550 | if (prefix_code != 5) { | |
8551 | goto error; | |
8552 | } | |
8553 | ||
8c4e53e8 PA |
8554 | if (*len < count/8) { |
8555 | goto error; | |
8556 | } | |
bbaa79b8 JI |
8557 | while (count--) { |
8558 | ||
8559 | object = SCCalloc(1, sizeof(*object)); | |
8560 | if (unlikely(object == NULL)) { | |
8561 | goto error; | |
8562 | } | |
8563 | ||
8564 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8565 | goto error; | |
8566 | } | |
8567 | ||
8568 | if (!DNP3ReadUint32(buf, len, &object->ksq)) { | |
8569 | goto error; | |
8570 | } | |
8571 | if (!DNP3ReadUint16(buf, len, &object->user_number)) { | |
8572 | goto error; | |
8573 | } | |
8574 | if (!DNP3ReadUint16(buf, len, &object->challenge_data_len)) { | |
8575 | goto error; | |
8576 | } | |
8577 | if (object->challenge_data_len > 0) { | |
8578 | if (*len < object->challenge_data_len) { | |
8579 | /* Not enough data. */ | |
8580 | goto error; | |
8581 | } | |
8582 | object->challenge_data = SCCalloc(1, object->challenge_data_len); | |
8583 | if (unlikely(object->challenge_data == NULL)) { | |
8584 | goto error; | |
8585 | } | |
8586 | memcpy(object->challenge_data, *buf, object->challenge_data_len); | |
8587 | *buf += object->challenge_data_len; | |
8588 | *len -= object->challenge_data_len; | |
8589 | } | |
8590 | ||
53a8c753 | 8591 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8592 | goto error; |
8593 | } | |
8594 | ||
8595 | object = NULL; | |
53a8c753 | 8596 | point_index++; |
bbaa79b8 JI |
8597 | } |
8598 | ||
8599 | return 1; | |
8600 | error: | |
8601 | if (object != NULL) { | |
8c4e53e8 PA |
8602 | if (object->challenge_data != NULL) { |
8603 | SCFree(object->challenge_data); | |
8604 | } | |
bbaa79b8 JI |
8605 | SCFree(object); |
8606 | } | |
8607 | ||
8608 | return 0; | |
8609 | } | |
8610 | ||
8611 | static int DNP3DecodeObjectG120V13(const uint8_t **buf, uint32_t *len, | |
8612 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8613 | DNP3PointList *points) | |
8614 | { | |
8615 | DNP3ObjectG120V13 *object = NULL; | |
8616 | uint32_t prefix = 0; | |
53a8c753 | 8617 | uint32_t point_index = start; |
bbaa79b8 JI |
8618 | |
8619 | if (prefix_code != 5) { | |
8620 | goto error; | |
8621 | } | |
8622 | ||
8c4e53e8 PA |
8623 | if (*len < count/8) { |
8624 | goto error; | |
8625 | } | |
bbaa79b8 JI |
8626 | while (count--) { |
8627 | ||
8628 | object = SCCalloc(1, sizeof(*object)); | |
8629 | if (unlikely(object == NULL)) { | |
8630 | goto error; | |
8631 | } | |
8632 | ||
8633 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8634 | goto error; | |
8635 | } | |
8636 | ||
8637 | if (!DNP3ReadUint32(buf, len, &object->ksq)) { | |
8638 | goto error; | |
8639 | } | |
8640 | if (!DNP3ReadUint16(buf, len, &object->user_number)) { | |
8641 | goto error; | |
8642 | } | |
8643 | if (!DNP3ReadUint16(buf, len, &object->encrypted_update_key_len)) { | |
8644 | goto error; | |
8645 | } | |
8646 | if (object->encrypted_update_key_len > 0) { | |
8647 | if (*len < object->encrypted_update_key_len) { | |
8648 | /* Not enough data. */ | |
8649 | goto error; | |
8650 | } | |
8651 | object->encrypted_update_key_data = SCCalloc(1, object->encrypted_update_key_len); | |
8652 | if (unlikely(object->encrypted_update_key_data == NULL)) { | |
8653 | goto error; | |
8654 | } | |
8655 | memcpy(object->encrypted_update_key_data, *buf, object->encrypted_update_key_len); | |
8656 | *buf += object->encrypted_update_key_len; | |
8657 | *len -= object->encrypted_update_key_len; | |
8658 | } | |
8659 | ||
53a8c753 | 8660 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8661 | goto error; |
8662 | } | |
8663 | ||
8664 | object = NULL; | |
53a8c753 | 8665 | point_index++; |
bbaa79b8 JI |
8666 | } |
8667 | ||
8668 | return 1; | |
8669 | error: | |
8670 | if (object != NULL) { | |
8c4e53e8 PA |
8671 | if (object->encrypted_update_key_data != NULL) { |
8672 | SCFree(object->encrypted_update_key_data); | |
8673 | } | |
bbaa79b8 JI |
8674 | SCFree(object); |
8675 | } | |
8676 | ||
8677 | return 0; | |
8678 | } | |
8679 | ||
8680 | static int DNP3DecodeObjectG120V14(const uint8_t **buf, uint32_t *len, | |
8681 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8682 | DNP3PointList *points) | |
8683 | { | |
8684 | DNP3ObjectG120V14 *object = NULL; | |
8685 | uint32_t prefix = 0; | |
53a8c753 | 8686 | uint32_t point_index = start; |
bbaa79b8 JI |
8687 | uint32_t offset; |
8688 | ||
8689 | if (prefix_code != 5) { | |
8690 | goto error; | |
8691 | } | |
8692 | ||
8c4e53e8 PA |
8693 | if (*len < count/8) { |
8694 | goto error; | |
8695 | } | |
bbaa79b8 JI |
8696 | while (count--) { |
8697 | ||
8698 | object = SCCalloc(1, sizeof(*object)); | |
8699 | if (unlikely(object == NULL)) { | |
8700 | goto error; | |
8701 | } | |
8702 | ||
8703 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8704 | goto error; | |
8705 | } | |
8706 | ||
8707 | offset = *len; | |
8708 | ||
86b5c81e PA |
8709 | if (prefix < (offset - *len)) { |
8710 | goto error; | |
8711 | } | |
8712 | object->digital_signature_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8713 | if (object->digital_signature_len > 0) { |
8714 | if (*len < object->digital_signature_len) { | |
8715 | /* Not enough data. */ | |
8716 | goto error; | |
8717 | } | |
8718 | object->digital_signature = SCCalloc(1, object->digital_signature_len); | |
8719 | if (unlikely(object->digital_signature == NULL)) { | |
8720 | goto error; | |
8721 | } | |
8722 | memcpy(object->digital_signature, *buf, object->digital_signature_len); | |
8723 | *buf += object->digital_signature_len; | |
8724 | *len -= object->digital_signature_len; | |
8725 | } | |
8726 | ||
53a8c753 | 8727 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8728 | goto error; |
8729 | } | |
8730 | ||
8731 | object = NULL; | |
53a8c753 | 8732 | point_index++; |
bbaa79b8 JI |
8733 | } |
8734 | ||
8735 | return 1; | |
8736 | error: | |
8737 | if (object != NULL) { | |
8c4e53e8 PA |
8738 | if (object->digital_signature != NULL) { |
8739 | SCFree(object->digital_signature); | |
8740 | } | |
bbaa79b8 JI |
8741 | SCFree(object); |
8742 | } | |
8743 | ||
8744 | return 0; | |
8745 | } | |
8746 | ||
8747 | static int DNP3DecodeObjectG120V15(const uint8_t **buf, uint32_t *len, | |
8748 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8749 | DNP3PointList *points) | |
8750 | { | |
8751 | DNP3ObjectG120V15 *object = NULL; | |
8752 | uint32_t prefix = 0; | |
53a8c753 | 8753 | uint32_t point_index = start; |
bbaa79b8 JI |
8754 | uint32_t offset; |
8755 | ||
8756 | if (prefix_code != 5) { | |
8757 | goto error; | |
8758 | } | |
8759 | ||
8c4e53e8 PA |
8760 | if (*len < count/8) { |
8761 | goto error; | |
8762 | } | |
bbaa79b8 JI |
8763 | while (count--) { |
8764 | ||
8765 | object = SCCalloc(1, sizeof(*object)); | |
8766 | if (unlikely(object == NULL)) { | |
8767 | goto error; | |
8768 | } | |
8769 | ||
8770 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8771 | goto error; | |
8772 | } | |
8773 | ||
8774 | offset = *len; | |
8775 | ||
86b5c81e PA |
8776 | if (prefix < (offset - *len)) { |
8777 | goto error; | |
8778 | } | |
8779 | object->mac_len = (uint16_t)(prefix - (offset - *len)); | |
bbaa79b8 JI |
8780 | if (object->mac_len > 0) { |
8781 | if (*len < object->mac_len) { | |
8782 | /* Not enough data. */ | |
8783 | goto error; | |
8784 | } | |
8785 | object->mac = SCCalloc(1, object->mac_len); | |
8786 | if (unlikely(object->mac == NULL)) { | |
8787 | goto error; | |
8788 | } | |
8789 | memcpy(object->mac, *buf, object->mac_len); | |
8790 | *buf += object->mac_len; | |
8791 | *len -= object->mac_len; | |
8792 | } | |
8793 | ||
53a8c753 | 8794 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8795 | goto error; |
8796 | } | |
8797 | ||
8798 | object = NULL; | |
53a8c753 | 8799 | point_index++; |
bbaa79b8 JI |
8800 | } |
8801 | ||
8802 | return 1; | |
8803 | error: | |
8804 | if (object != NULL) { | |
8c4e53e8 PA |
8805 | if (object->mac != NULL) { |
8806 | SCFree(object->mac); | |
8807 | } | |
bbaa79b8 JI |
8808 | SCFree(object); |
8809 | } | |
8810 | ||
8811 | return 0; | |
8812 | } | |
8813 | ||
8814 | static int DNP3DecodeObjectG121V1(const uint8_t **buf, uint32_t *len, | |
8815 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8816 | DNP3PointList *points) | |
8817 | { | |
8818 | DNP3ObjectG121V1 *object = NULL; | |
8819 | uint32_t prefix = 0; | |
53a8c753 | 8820 | uint32_t point_index = start; |
bbaa79b8 | 8821 | |
8c4e53e8 PA |
8822 | if (*len < count/8) { |
8823 | goto error; | |
8824 | } | |
bbaa79b8 JI |
8825 | while (count--) { |
8826 | ||
8827 | object = SCCalloc(1, sizeof(*object)); | |
8828 | if (unlikely(object == NULL)) { | |
8829 | goto error; | |
8830 | } | |
8831 | ||
8832 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8833 | goto error; | |
8834 | } | |
8835 | ||
8836 | { | |
8837 | uint8_t octet; | |
8838 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
8839 | goto error; | |
8840 | } | |
8841 | object->online = (octet >> 0) & 0x1; | |
8842 | object->restart = (octet >> 1) & 0x1; | |
8843 | object->comm_lost = (octet >> 2) & 0x1; | |
8844 | object->remote_forced = (octet >> 3) & 0x1; | |
8845 | object->local_forced = (octet >> 4) & 0x1; | |
8846 | object->reserved0 = (octet >> 5) & 0x1; | |
8847 | object->discontinuity = (octet >> 6) & 0x1; | |
8848 | object->reserved1 = (octet >> 7) & 0x1; | |
8849 | } | |
8850 | if (!DNP3ReadUint16(buf, len, &object->association_id)) { | |
8851 | goto error; | |
8852 | } | |
8853 | if (!DNP3ReadUint32(buf, len, &object->count_value)) { | |
8854 | goto error; | |
8855 | } | |
8856 | ||
53a8c753 | 8857 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8858 | goto error; |
8859 | } | |
8860 | ||
8861 | object = NULL; | |
53a8c753 | 8862 | point_index++; |
bbaa79b8 JI |
8863 | } |
8864 | ||
8865 | return 1; | |
8866 | error: | |
8867 | if (object != NULL) { | |
8868 | SCFree(object); | |
8869 | } | |
8870 | ||
8871 | return 0; | |
8872 | } | |
8873 | ||
8874 | static int DNP3DecodeObjectG122V1(const uint8_t **buf, uint32_t *len, | |
8875 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8876 | DNP3PointList *points) | |
8877 | { | |
8878 | DNP3ObjectG122V1 *object = NULL; | |
8879 | uint32_t prefix = 0; | |
53a8c753 | 8880 | uint32_t point_index = start; |
bbaa79b8 | 8881 | |
8c4e53e8 PA |
8882 | if (*len < count/8) { |
8883 | goto error; | |
8884 | } | |
bbaa79b8 JI |
8885 | while (count--) { |
8886 | ||
8887 | object = SCCalloc(1, sizeof(*object)); | |
8888 | if (unlikely(object == NULL)) { | |
8889 | goto error; | |
8890 | } | |
8891 | ||
8892 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8893 | goto error; | |
8894 | } | |
8895 | ||
8896 | { | |
8897 | uint8_t octet; | |
8898 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
8899 | goto error; | |
8900 | } | |
8901 | object->online = (octet >> 0) & 0x1; | |
8902 | object->restart = (octet >> 1) & 0x1; | |
8903 | object->comm_lost = (octet >> 2) & 0x1; | |
8904 | object->remote_forced = (octet >> 3) & 0x1; | |
8905 | object->local_forced = (octet >> 4) & 0x1; | |
8906 | object->reserved0 = (octet >> 5) & 0x1; | |
8907 | object->discontinuity = (octet >> 6) & 0x1; | |
8908 | object->reserved1 = (octet >> 7) & 0x1; | |
8909 | } | |
8910 | if (!DNP3ReadUint16(buf, len, &object->association_id)) { | |
8911 | goto error; | |
8912 | } | |
8913 | if (!DNP3ReadUint32(buf, len, &object->count_value)) { | |
8914 | goto error; | |
8915 | } | |
8916 | ||
53a8c753 | 8917 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8918 | goto error; |
8919 | } | |
8920 | ||
8921 | object = NULL; | |
53a8c753 | 8922 | point_index++; |
bbaa79b8 JI |
8923 | } |
8924 | ||
8925 | return 1; | |
8926 | error: | |
8927 | if (object != NULL) { | |
8928 | SCFree(object); | |
8929 | } | |
8930 | ||
8931 | return 0; | |
8932 | } | |
8933 | ||
8934 | static int DNP3DecodeObjectG122V2(const uint8_t **buf, uint32_t *len, | |
8935 | uint8_t prefix_code, uint32_t start, uint32_t count, | |
8936 | DNP3PointList *points) | |
8937 | { | |
8938 | DNP3ObjectG122V2 *object = NULL; | |
8939 | uint32_t prefix = 0; | |
53a8c753 | 8940 | uint32_t point_index = start; |
bbaa79b8 | 8941 | |
8c4e53e8 PA |
8942 | if (*len < count/8) { |
8943 | goto error; | |
8944 | } | |
bbaa79b8 JI |
8945 | while (count--) { |
8946 | ||
8947 | object = SCCalloc(1, sizeof(*object)); | |
8948 | if (unlikely(object == NULL)) { | |
8949 | goto error; | |
8950 | } | |
8951 | ||
8952 | if (!DNP3ReadPrefix(buf, len, prefix_code, &prefix)) { | |
8953 | goto error; | |
8954 | } | |
8955 | ||
8956 | { | |
8957 | uint8_t octet; | |
8958 | if (!DNP3ReadUint8(buf, len, &octet)) { | |
8959 | goto error; | |
8960 | } | |
8961 | object->online = (octet >> 0) & 0x1; | |
8962 | object->restart = (octet >> 1) & 0x1; | |
8963 | object->comm_lost = (octet >> 2) & 0x1; | |
8964 | object->remote_forced = (octet >> 3) & 0x1; | |
8965 | object->local_forced = (octet >> 4) & 0x1; | |
8966 | object->reserved0 = (octet >> 5) & 0x1; | |
8967 | object->discontinuity = (octet >> 6) & 0x1; | |
8968 | object->reserved1 = (octet >> 7) & 0x1; | |
8969 | } | |
8970 | if (!DNP3ReadUint16(buf, len, &object->association_id)) { | |
8971 | goto error; | |
8972 | } | |
8973 | if (!DNP3ReadUint32(buf, len, &object->count_value)) { | |
8974 | goto error; | |
8975 | } | |
8976 | if (!DNP3ReadUint48(buf, len, &object->timestamp)) { | |
8977 | goto error; | |
8978 | } | |
8979 | ||
53a8c753 | 8980 | if (!DNP3AddPoint(points, object, point_index, prefix_code, prefix)) { |
bbaa79b8 JI |
8981 | goto error; |
8982 | } | |
8983 | ||
8984 | object = NULL; | |
53a8c753 | 8985 | point_index++; |
bbaa79b8 JI |
8986 | } |
8987 | ||
8988 | return 1; | |
8989 | error: | |
8990 | if (object != NULL) { | |
8991 | SCFree(object); | |
8992 | } | |
8993 | ||
8994 | return 0; | |
8995 | } | |
8996 | ||
8997 | ||
8998 | void DNP3FreeObjectPoint(int group, int variation, void *point) | |
8999 | { | |
9000 | switch(DNP3_OBJECT_CODE(group, variation)) { | |
9001 | case DNP3_OBJECT_CODE(83, 1): { | |
9002 | DNP3ObjectG83V1 *object = (DNP3ObjectG83V1 *) point; | |
9003 | if (object->data_objects != NULL) { | |
9004 | SCFree(object->data_objects); | |
9005 | } | |
9006 | break; | |
9007 | } | |
9008 | case DNP3_OBJECT_CODE(120, 1): { | |
9009 | DNP3ObjectG120V1 *object = (DNP3ObjectG120V1 *) point; | |
9010 | if (object->challenge_data != NULL) { | |
9011 | SCFree(object->challenge_data); | |
9012 | } | |
9013 | break; | |
9014 | } | |
9015 | case DNP3_OBJECT_CODE(120, 2): { | |
9016 | DNP3ObjectG120V2 *object = (DNP3ObjectG120V2 *) point; | |
9017 | if (object->mac_value != NULL) { | |
9018 | SCFree(object->mac_value); | |
9019 | } | |
9020 | break; | |
9021 | } | |
9022 | case DNP3_OBJECT_CODE(120, 5): { | |
9023 | DNP3ObjectG120V5 *object = (DNP3ObjectG120V5 *) point; | |
9024 | if (object->challenge_data != NULL) { | |
9025 | SCFree(object->challenge_data); | |
9026 | } | |
9027 | if (object->mac_value != NULL) { | |
9028 | SCFree(object->mac_value); | |
9029 | } | |
9030 | break; | |
9031 | } | |
9032 | case DNP3_OBJECT_CODE(120, 6): { | |
9033 | DNP3ObjectG120V6 *object = (DNP3ObjectG120V6 *) point; | |
9034 | if (object->wrapped_key_data != NULL) { | |
9035 | SCFree(object->wrapped_key_data); | |
9036 | } | |
9037 | break; | |
9038 | } | |
9039 | case DNP3_OBJECT_CODE(120, 8): { | |
9040 | DNP3ObjectG120V8 *object = (DNP3ObjectG120V8 *) point; | |
9041 | if (object->certificate != NULL) { | |
9042 | SCFree(object->certificate); | |
9043 | } | |
9044 | break; | |
9045 | } | |
9046 | case DNP3_OBJECT_CODE(120, 9): { | |
9047 | DNP3ObjectG120V9 *object = (DNP3ObjectG120V9 *) point; | |
9048 | if (object->mac_value != NULL) { | |
9049 | SCFree(object->mac_value); | |
9050 | } | |
9051 | break; | |
9052 | } | |
9053 | case DNP3_OBJECT_CODE(120, 10): { | |
9054 | DNP3ObjectG120V10 *object = (DNP3ObjectG120V10 *) point; | |
9055 | if (object->user_public_key != NULL) { | |
9056 | SCFree(object->user_public_key); | |
9057 | } | |
9058 | if (object->certification_data != NULL) { | |
9059 | SCFree(object->certification_data); | |
9060 | } | |
9061 | break; | |
9062 | } | |
9063 | case DNP3_OBJECT_CODE(120, 11): { | |
9064 | DNP3ObjectG120V11 *object = (DNP3ObjectG120V11 *) point; | |
9065 | if (object->master_challenge_data != NULL) { | |
9066 | SCFree(object->master_challenge_data); | |
9067 | } | |
9068 | break; | |
9069 | } | |
9070 | case DNP3_OBJECT_CODE(120, 12): { | |
9071 | DNP3ObjectG120V12 *object = (DNP3ObjectG120V12 *) point; | |
9072 | if (object->challenge_data != NULL) { | |
9073 | SCFree(object->challenge_data); | |
9074 | } | |
9075 | break; | |
9076 | } | |
9077 | case DNP3_OBJECT_CODE(120, 13): { | |
9078 | DNP3ObjectG120V13 *object = (DNP3ObjectG120V13 *) point; | |
9079 | if (object->encrypted_update_key_data != NULL) { | |
9080 | SCFree(object->encrypted_update_key_data); | |
9081 | } | |
9082 | break; | |
9083 | } | |
9084 | case DNP3_OBJECT_CODE(120, 14): { | |
9085 | DNP3ObjectG120V14 *object = (DNP3ObjectG120V14 *) point; | |
9086 | if (object->digital_signature != NULL) { | |
9087 | SCFree(object->digital_signature); | |
9088 | } | |
9089 | break; | |
9090 | } | |
9091 | case DNP3_OBJECT_CODE(120, 15): { | |
9092 | DNP3ObjectG120V15 *object = (DNP3ObjectG120V15 *) point; | |
9093 | if (object->mac != NULL) { | |
9094 | SCFree(object->mac); | |
9095 | } | |
9096 | break; | |
9097 | } | |
9098 | default: | |
9099 | break; | |
9100 | } | |
9101 | SCFree(point); | |
9102 | } | |
9103 | ||
9104 | /** | |
9105 | * \brief Decode a DNP3 object. | |
9106 | * | |
9107 | * \retval 0 on success. On failure a positive integer corresponding | |
9108 | * to a DNP3 application layer event will be returned. | |
9109 | */ | |
9110 | int DNP3DecodeObject(int group, int variation, const uint8_t **buf, | |
9111 | uint32_t *len, uint8_t prefix_code, uint32_t start, | |
9112 | uint32_t count, DNP3PointList *points) | |
9113 | { | |
9114 | int rc = 0; | |
9115 | ||
9116 | switch (DNP3_OBJECT_CODE(group, variation)) { | |
9117 | case DNP3_OBJECT_CODE(1, 1): | |
9118 | rc = DNP3DecodeObjectG1V1(buf, len, prefix_code, start, count, | |
9119 | points); | |
9120 | break; | |
9121 | case DNP3_OBJECT_CODE(1, 2): | |
9122 | rc = DNP3DecodeObjectG1V2(buf, len, prefix_code, start, count, | |
9123 | points); | |
9124 | break; | |
9125 | case DNP3_OBJECT_CODE(2, 1): | |
9126 | rc = DNP3DecodeObjectG2V1(buf, len, prefix_code, start, count, | |
9127 | points); | |
9128 | break; | |
9129 | case DNP3_OBJECT_CODE(2, 2): | |
9130 | rc = DNP3DecodeObjectG2V2(buf, len, prefix_code, start, count, | |
9131 | points); | |
9132 | break; | |
9133 | case DNP3_OBJECT_CODE(2, 3): | |
9134 | rc = DNP3DecodeObjectG2V3(buf, len, prefix_code, start, count, | |
9135 | points); | |
9136 | break; | |
9137 | case DNP3_OBJECT_CODE(3, 1): | |
9138 | rc = DNP3DecodeObjectG3V1(buf, len, prefix_code, start, count, | |
9139 | points); | |
9140 | break; | |
9141 | case DNP3_OBJECT_CODE(3, 2): | |
9142 | rc = DNP3DecodeObjectG3V2(buf, len, prefix_code, start, count, | |
9143 | points); | |
9144 | break; | |
9145 | case DNP3_OBJECT_CODE(4, 1): | |
9146 | rc = DNP3DecodeObjectG4V1(buf, len, prefix_code, start, count, | |
9147 | points); | |
9148 | break; | |
9149 | case DNP3_OBJECT_CODE(4, 2): | |
9150 | rc = DNP3DecodeObjectG4V2(buf, len, prefix_code, start, count, | |
9151 | points); | |
9152 | break; | |
9153 | case DNP3_OBJECT_CODE(4, 3): | |
9154 | rc = DNP3DecodeObjectG4V3(buf, len, prefix_code, start, count, | |
9155 | points); | |
9156 | break; | |
9157 | case DNP3_OBJECT_CODE(10, 1): | |
9158 | rc = DNP3DecodeObjectG10V1(buf, len, prefix_code, start, count, | |
9159 | points); | |
9160 | break; | |
9161 | case DNP3_OBJECT_CODE(10, 2): | |
9162 | rc = DNP3DecodeObjectG10V2(buf, len, prefix_code, start, count, | |
9163 | points); | |
9164 | break; | |
9165 | case DNP3_OBJECT_CODE(11, 1): | |
9166 | rc = DNP3DecodeObjectG11V1(buf, len, prefix_code, start, count, | |
9167 | points); | |
9168 | break; | |
9169 | case DNP3_OBJECT_CODE(11, 2): | |
9170 | rc = DNP3DecodeObjectG11V2(buf, len, prefix_code, start, count, | |
9171 | points); | |
9172 | break; | |
9173 | case DNP3_OBJECT_CODE(12, 1): | |
9174 | rc = DNP3DecodeObjectG12V1(buf, len, prefix_code, start, count, | |
9175 | points); | |
9176 | break; | |
9177 | case DNP3_OBJECT_CODE(12, 2): | |
9178 | rc = DNP3DecodeObjectG12V2(buf, len, prefix_code, start, count, | |
9179 | points); | |
9180 | break; | |
9181 | case DNP3_OBJECT_CODE(12, 3): | |
9182 | rc = DNP3DecodeObjectG12V3(buf, len, prefix_code, start, count, | |
9183 | points); | |
9184 | break; | |
9185 | case DNP3_OBJECT_CODE(13, 1): | |
9186 | rc = DNP3DecodeObjectG13V1(buf, len, prefix_code, start, count, | |
9187 | points); | |
9188 | break; | |
9189 | case DNP3_OBJECT_CODE(13, 2): | |
9190 | rc = DNP3DecodeObjectG13V2(buf, len, prefix_code, start, count, | |
9191 | points); | |
9192 | break; | |
9193 | case DNP3_OBJECT_CODE(20, 1): | |
9194 | rc = DNP3DecodeObjectG20V1(buf, len, prefix_code, start, count, | |
9195 | points); | |
9196 | break; | |
9197 | case DNP3_OBJECT_CODE(20, 2): | |
9198 | rc = DNP3DecodeObjectG20V2(buf, len, prefix_code, start, count, | |
9199 | points); | |
9200 | break; | |
9201 | case DNP3_OBJECT_CODE(20, 3): | |
9202 | rc = DNP3DecodeObjectG20V3(buf, len, prefix_code, start, count, | |
9203 | points); | |
9204 | break; | |
9205 | case DNP3_OBJECT_CODE(20, 4): | |
9206 | rc = DNP3DecodeObjectG20V4(buf, len, prefix_code, start, count, | |
9207 | points); | |
9208 | break; | |
9209 | case DNP3_OBJECT_CODE(20, 5): | |
9210 | rc = DNP3DecodeObjectG20V5(buf, len, prefix_code, start, count, | |
9211 | points); | |
9212 | break; | |
9213 | case DNP3_OBJECT_CODE(20, 6): | |
9214 | rc = DNP3DecodeObjectG20V6(buf, len, prefix_code, start, count, | |
9215 | points); | |
9216 | break; | |
9217 | case DNP3_OBJECT_CODE(20, 7): | |
9218 | rc = DNP3DecodeObjectG20V7(buf, len, prefix_code, start, count, | |
9219 | points); | |
9220 | break; | |
9221 | case DNP3_OBJECT_CODE(20, 8): | |
9222 | rc = DNP3DecodeObjectG20V8(buf, len, prefix_code, start, count, | |
9223 | points); | |
9224 | break; | |
9225 | case DNP3_OBJECT_CODE(21, 1): | |
9226 | rc = DNP3DecodeObjectG21V1(buf, len, prefix_code, start, count, | |
9227 | points); | |
9228 | break; | |
9229 | case DNP3_OBJECT_CODE(21, 2): | |
9230 | rc = DNP3DecodeObjectG21V2(buf, len, prefix_code, start, count, | |
9231 | points); | |
9232 | break; | |
9233 | case DNP3_OBJECT_CODE(21, 3): | |
9234 | rc = DNP3DecodeObjectG21V3(buf, len, prefix_code, start, count, | |
9235 | points); | |
9236 | break; | |
9237 | case DNP3_OBJECT_CODE(21, 4): | |
9238 | rc = DNP3DecodeObjectG21V4(buf, len, prefix_code, start, count, | |
9239 | points); | |
9240 | break; | |
9241 | case DNP3_OBJECT_CODE(21, 5): | |
9242 | rc = DNP3DecodeObjectG21V5(buf, len, prefix_code, start, count, | |
9243 | points); | |
9244 | break; | |
9245 | case DNP3_OBJECT_CODE(21, 6): | |
9246 | rc = DNP3DecodeObjectG21V6(buf, len, prefix_code, start, count, | |
9247 | points); | |
9248 | break; | |
9249 | case DNP3_OBJECT_CODE(21, 7): | |
9250 | rc = DNP3DecodeObjectG21V7(buf, len, prefix_code, start, count, | |
9251 | points); | |
9252 | break; | |
9253 | case DNP3_OBJECT_CODE(21, 8): | |
9254 | rc = DNP3DecodeObjectG21V8(buf, len, prefix_code, start, count, | |
9255 | points); | |
9256 | break; | |
9257 | case DNP3_OBJECT_CODE(21, 9): | |
9258 | rc = DNP3DecodeObjectG21V9(buf, len, prefix_code, start, count, | |
9259 | points); | |
9260 | break; | |
9261 | case DNP3_OBJECT_CODE(21, 10): | |
9262 | rc = DNP3DecodeObjectG21V10(buf, len, prefix_code, start, count, | |
9263 | points); | |
9264 | break; | |
9265 | case DNP3_OBJECT_CODE(21, 11): | |
9266 | rc = DNP3DecodeObjectG21V11(buf, len, prefix_code, start, count, | |
9267 | points); | |
9268 | break; | |
9269 | case DNP3_OBJECT_CODE(21, 12): | |
9270 | rc = DNP3DecodeObjectG21V12(buf, len, prefix_code, start, count, | |
9271 | points); | |
9272 | break; | |
9273 | case DNP3_OBJECT_CODE(22, 1): | |
9274 | rc = DNP3DecodeObjectG22V1(buf, len, prefix_code, start, count, | |
9275 | points); | |
9276 | break; | |
9277 | case DNP3_OBJECT_CODE(22, 2): | |
9278 | rc = DNP3DecodeObjectG22V2(buf, len, prefix_code, start, count, | |
9279 | points); | |
9280 | break; | |
9281 | case DNP3_OBJECT_CODE(22, 3): | |
9282 | rc = DNP3DecodeObjectG22V3(buf, len, prefix_code, start, count, | |
9283 | points); | |
9284 | break; | |
9285 | case DNP3_OBJECT_CODE(22, 4): | |
9286 | rc = DNP3DecodeObjectG22V4(buf, len, prefix_code, start, count, | |
9287 | points); | |
9288 | break; | |
9289 | case DNP3_OBJECT_CODE(22, 5): | |
9290 | rc = DNP3DecodeObjectG22V5(buf, len, prefix_code, start, count, | |
9291 | points); | |
9292 | break; | |
9293 | case DNP3_OBJECT_CODE(22, 6): | |
9294 | rc = DNP3DecodeObjectG22V6(buf, len, prefix_code, start, count, | |
9295 | points); | |
9296 | break; | |
9297 | case DNP3_OBJECT_CODE(22, 7): | |
9298 | rc = DNP3DecodeObjectG22V7(buf, len, prefix_code, start, count, | |
9299 | points); | |
9300 | break; | |
9301 | case DNP3_OBJECT_CODE(22, 8): | |
9302 | rc = DNP3DecodeObjectG22V8(buf, len, prefix_code, start, count, | |
9303 | points); | |
9304 | break; | |
9305 | case DNP3_OBJECT_CODE(23, 1): | |
9306 | rc = DNP3DecodeObjectG23V1(buf, len, prefix_code, start, count, | |
9307 | points); | |
9308 | break; | |
9309 | case DNP3_OBJECT_CODE(23, 2): | |
9310 | rc = DNP3DecodeObjectG23V2(buf, len, prefix_code, start, count, | |
9311 | points); | |
9312 | break; | |
9313 | case DNP3_OBJECT_CODE(23, 3): | |
9314 | rc = DNP3DecodeObjectG23V3(buf, len, prefix_code, start, count, | |
9315 | points); | |
9316 | break; | |
9317 | case DNP3_OBJECT_CODE(23, 4): | |
9318 | rc = DNP3DecodeObjectG23V4(buf, len, prefix_code, start, count, | |
9319 | points); | |
9320 | break; | |
9321 | case DNP3_OBJECT_CODE(23, 5): | |
9322 | rc = DNP3DecodeObjectG23V5(buf, len, prefix_code, start, count, | |
9323 | points); | |
9324 | break; | |
9325 | case DNP3_OBJECT_CODE(23, 6): | |
9326 | rc = DNP3DecodeObjectG23V6(buf, len, prefix_code, start, count, | |
9327 | points); | |
9328 | break; | |
9329 | case DNP3_OBJECT_CODE(23, 7): | |
9330 | rc = DNP3DecodeObjectG23V7(buf, len, prefix_code, start, count, | |
9331 | points); | |
9332 | break; | |
9333 | case DNP3_OBJECT_CODE(23, 8): | |
9334 | rc = DNP3DecodeObjectG23V8(buf, len, prefix_code, start, count, | |
9335 | points); | |
9336 | break; | |
9337 | case DNP3_OBJECT_CODE(30, 1): | |
9338 | rc = DNP3DecodeObjectG30V1(buf, len, prefix_code, start, count, | |
9339 | points); | |
9340 | break; | |
9341 | case DNP3_OBJECT_CODE(30, 2): | |
9342 | rc = DNP3DecodeObjectG30V2(buf, len, prefix_code, start, count, | |
9343 | points); | |
9344 | break; | |
9345 | case DNP3_OBJECT_CODE(30, 3): | |
9346 | rc = DNP3DecodeObjectG30V3(buf, len, prefix_code, start, count, | |
9347 | points); | |
9348 | break; | |
9349 | case DNP3_OBJECT_CODE(30, 4): | |
9350 | rc = DNP3DecodeObjectG30V4(buf, len, prefix_code, start, count, | |
9351 | points); | |
9352 | break; | |
9353 | case DNP3_OBJECT_CODE(30, 5): | |
9354 | rc = DNP3DecodeObjectG30V5(buf, len, prefix_code, start, count, | |
9355 | points); | |
9356 | break; | |
9357 | case DNP3_OBJECT_CODE(30, 6): | |
9358 | rc = DNP3DecodeObjectG30V6(buf, len, prefix_code, start, count, | |
9359 | points); | |
9360 | break; | |
9361 | case DNP3_OBJECT_CODE(31, 1): | |
9362 | rc = DNP3DecodeObjectG31V1(buf, len, prefix_code, start, count, | |
9363 | points); | |
9364 | break; | |
9365 | case DNP3_OBJECT_CODE(31, 2): | |
9366 | rc = DNP3DecodeObjectG31V2(buf, len, prefix_code, start, count, | |
9367 | points); | |
9368 | break; | |
9369 | case DNP3_OBJECT_CODE(31, 3): | |
9370 | rc = DNP3DecodeObjectG31V3(buf, len, prefix_code, start, count, | |
9371 | points); | |
9372 | break; | |
9373 | case DNP3_OBJECT_CODE(31, 4): | |
9374 | rc = DNP3DecodeObjectG31V4(buf, len, prefix_code, start, count, | |
9375 | points); | |
9376 | break; | |
9377 | case DNP3_OBJECT_CODE(31, 5): | |
9378 | rc = DNP3DecodeObjectG31V5(buf, len, prefix_code, start, count, | |
9379 | points); | |
9380 | break; | |
9381 | case DNP3_OBJECT_CODE(31, 6): | |
9382 | rc = DNP3DecodeObjectG31V6(buf, len, prefix_code, start, count, | |
9383 | points); | |
9384 | break; | |
9385 | case DNP3_OBJECT_CODE(31, 7): | |
9386 | rc = DNP3DecodeObjectG31V7(buf, len, prefix_code, start, count, | |
9387 | points); | |
9388 | break; | |
9389 | case DNP3_OBJECT_CODE(31, 8): | |
9390 | rc = DNP3DecodeObjectG31V8(buf, len, prefix_code, start, count, | |
9391 | points); | |
9392 | break; | |
9393 | case DNP3_OBJECT_CODE(32, 1): | |
9394 | rc = DNP3DecodeObjectG32V1(buf, len, prefix_code, start, count, | |
9395 | points); | |
9396 | break; | |
9397 | case DNP3_OBJECT_CODE(32, 2): | |
9398 | rc = DNP3DecodeObjectG32V2(buf, len, prefix_code, start, count, | |
9399 | points); | |
9400 | break; | |
9401 | case DNP3_OBJECT_CODE(32, 3): | |
9402 | rc = DNP3DecodeObjectG32V3(buf, len, prefix_code, start, count, | |
9403 | points); | |
9404 | break; | |
9405 | case DNP3_OBJECT_CODE(32, 4): | |
9406 | rc = DNP3DecodeObjectG32V4(buf, len, prefix_code, start, count, | |
9407 | points); | |
9408 | break; | |
9409 | case DNP3_OBJECT_CODE(32, 5): | |
9410 | rc = DNP3DecodeObjectG32V5(buf, len, prefix_code, start, count, | |
9411 | points); | |
9412 | break; | |
9413 | case DNP3_OBJECT_CODE(32, 6): | |
9414 | rc = DNP3DecodeObjectG32V6(buf, len, prefix_code, start, count, | |
9415 | points); | |
9416 | break; | |
9417 | case DNP3_OBJECT_CODE(32, 7): | |
9418 | rc = DNP3DecodeObjectG32V7(buf, len, prefix_code, start, count, | |
9419 | points); | |
9420 | break; | |
9421 | case DNP3_OBJECT_CODE(32, 8): | |
9422 | rc = DNP3DecodeObjectG32V8(buf, len, prefix_code, start, count, | |
9423 | points); | |
9424 | break; | |
9425 | case DNP3_OBJECT_CODE(33, 1): | |
9426 | rc = DNP3DecodeObjectG33V1(buf, len, prefix_code, start, count, | |
9427 | points); | |
9428 | break; | |
9429 | case DNP3_OBJECT_CODE(33, 2): | |
9430 | rc = DNP3DecodeObjectG33V2(buf, len, prefix_code, start, count, | |
9431 | points); | |
9432 | break; | |
9433 | case DNP3_OBJECT_CODE(33, 3): | |
9434 | rc = DNP3DecodeObjectG33V3(buf, len, prefix_code, start, count, | |
9435 | points); | |
9436 | break; | |
9437 | case DNP3_OBJECT_CODE(33, 4): | |
9438 | rc = DNP3DecodeObjectG33V4(buf, len, prefix_code, start, count, | |
9439 | points); | |
9440 | break; | |
9441 | case DNP3_OBJECT_CODE(33, 5): | |
9442 | rc = DNP3DecodeObjectG33V5(buf, len, prefix_code, start, count, | |
9443 | points); | |
9444 | break; | |
9445 | case DNP3_OBJECT_CODE(33, 6): | |
9446 | rc = DNP3DecodeObjectG33V6(buf, len, prefix_code, start, count, | |
9447 | points); | |
9448 | break; | |
9449 | case DNP3_OBJECT_CODE(33, 7): | |
9450 | rc = DNP3DecodeObjectG33V7(buf, len, prefix_code, start, count, | |
9451 | points); | |
9452 | break; | |
9453 | case DNP3_OBJECT_CODE(33, 8): | |
9454 | rc = DNP3DecodeObjectG33V8(buf, len, prefix_code, start, count, | |
9455 | points); | |
9456 | break; | |
9457 | case DNP3_OBJECT_CODE(34, 1): | |
9458 | rc = DNP3DecodeObjectG34V1(buf, len, prefix_code, start, count, | |
9459 | points); | |
9460 | break; | |
9461 | case DNP3_OBJECT_CODE(34, 2): | |
9462 | rc = DNP3DecodeObjectG34V2(buf, len, prefix_code, start, count, | |
9463 | points); | |
9464 | break; | |
9465 | case DNP3_OBJECT_CODE(34, 3): | |
9466 | rc = DNP3DecodeObjectG34V3(buf, len, prefix_code, start, count, | |
9467 | points); | |
9468 | break; | |
9469 | case DNP3_OBJECT_CODE(40, 1): | |
9470 | rc = DNP3DecodeObjectG40V1(buf, len, prefix_code, start, count, | |
9471 | points); | |
9472 | break; | |
9473 | case DNP3_OBJECT_CODE(40, 2): | |
9474 | rc = DNP3DecodeObjectG40V2(buf, len, prefix_code, start, count, | |
9475 | points); | |
9476 | break; | |
9477 | case DNP3_OBJECT_CODE(40, 3): | |
9478 | rc = DNP3DecodeObjectG40V3(buf, len, prefix_code, start, count, | |
9479 | points); | |
9480 | break; | |
9481 | case DNP3_OBJECT_CODE(40, 4): | |
9482 | rc = DNP3DecodeObjectG40V4(buf, len, prefix_code, start, count, | |
9483 | points); | |
9484 | break; | |
9485 | case DNP3_OBJECT_CODE(41, 1): | |
9486 | rc = DNP3DecodeObjectG41V1(buf, len, prefix_code, start, count, | |
9487 | points); | |
9488 | break; | |
9489 | case DNP3_OBJECT_CODE(41, 2): | |
9490 | rc = DNP3DecodeObjectG41V2(buf, len, prefix_code, start, count, | |
9491 | points); | |
9492 | break; | |
9493 | case DNP3_OBJECT_CODE(41, 3): | |
9494 | rc = DNP3DecodeObjectG41V3(buf, len, prefix_code, start, count, | |
9495 | points); | |
9496 | break; | |
9497 | case DNP3_OBJECT_CODE(41, 4): | |
9498 | rc = DNP3DecodeObjectG41V4(buf, len, prefix_code, start, count, | |
9499 | points); | |
9500 | break; | |
9501 | case DNP3_OBJECT_CODE(42, 1): | |
9502 | rc = DNP3DecodeObjectG42V1(buf, len, prefix_code, start, count, | |
9503 | points); | |
9504 | break; | |
9505 | case DNP3_OBJECT_CODE(42, 2): | |
9506 | rc = DNP3DecodeObjectG42V2(buf, len, prefix_code, start, count, | |
9507 | points); | |
9508 | break; | |
9509 | case DNP3_OBJECT_CODE(42, 3): | |
9510 | rc = DNP3DecodeObjectG42V3(buf, len, prefix_code, start, count, | |
9511 | points); | |
9512 | break; | |
9513 | case DNP3_OBJECT_CODE(42, 4): | |
9514 | rc = DNP3DecodeObjectG42V4(buf, len, prefix_code, start, count, | |
9515 | points); | |
9516 | break; | |
9517 | case DNP3_OBJECT_CODE(42, 5): | |
9518 | rc = DNP3DecodeObjectG42V5(buf, len, prefix_code, start, count, | |
9519 | points); | |
9520 | break; | |
9521 | case DNP3_OBJECT_CODE(42, 6): | |
9522 | rc = DNP3DecodeObjectG42V6(buf, len, prefix_code, start, count, | |
9523 | points); | |
9524 | break; | |
9525 | case DNP3_OBJECT_CODE(42, 7): | |
9526 | rc = DNP3DecodeObjectG42V7(buf, len, prefix_code, start, count, | |
9527 | points); | |
9528 | break; | |
9529 | case DNP3_OBJECT_CODE(42, 8): | |
9530 | rc = DNP3DecodeObjectG42V8(buf, len, prefix_code, start, count, | |
9531 | points); | |
9532 | break; | |
9533 | case DNP3_OBJECT_CODE(43, 1): | |
9534 | rc = DNP3DecodeObjectG43V1(buf, len, prefix_code, start, count, | |
9535 | points); | |
9536 | break; | |
9537 | case DNP3_OBJECT_CODE(43, 2): | |
9538 | rc = DNP3DecodeObjectG43V2(buf, len, prefix_code, start, count, | |
9539 | points); | |
9540 | break; | |
9541 | case DNP3_OBJECT_CODE(43, 3): | |
9542 | rc = DNP3DecodeObjectG43V3(buf, len, prefix_code, start, count, | |
9543 | points); | |
9544 | break; | |
9545 | case DNP3_OBJECT_CODE(43, 4): | |
9546 | rc = DNP3DecodeObjectG43V4(buf, len, prefix_code, start, count, | |
9547 | points); | |
9548 | break; | |
9549 | case DNP3_OBJECT_CODE(43, 5): | |
9550 | rc = DNP3DecodeObjectG43V5(buf, len, prefix_code, start, count, | |
9551 | points); | |
9552 | break; | |
9553 | case DNP3_OBJECT_CODE(43, 6): | |
9554 | rc = DNP3DecodeObjectG43V6(buf, len, prefix_code, start, count, | |
9555 | points); | |
9556 | break; | |
9557 | case DNP3_OBJECT_CODE(43, 7): | |
9558 | rc = DNP3DecodeObjectG43V7(buf, len, prefix_code, start, count, | |
9559 | points); | |
9560 | break; | |
9561 | case DNP3_OBJECT_CODE(43, 8): | |
9562 | rc = DNP3DecodeObjectG43V8(buf, len, prefix_code, start, count, | |
9563 | points); | |
9564 | break; | |
9565 | case DNP3_OBJECT_CODE(50, 1): | |
9566 | rc = DNP3DecodeObjectG50V1(buf, len, prefix_code, start, count, | |
9567 | points); | |
9568 | break; | |
9569 | case DNP3_OBJECT_CODE(50, 2): | |
9570 | rc = DNP3DecodeObjectG50V2(buf, len, prefix_code, start, count, | |
9571 | points); | |
9572 | break; | |
9573 | case DNP3_OBJECT_CODE(50, 3): | |
9574 | rc = DNP3DecodeObjectG50V3(buf, len, prefix_code, start, count, | |
9575 | points); | |
9576 | break; | |
9577 | case DNP3_OBJECT_CODE(50, 4): | |
9578 | rc = DNP3DecodeObjectG50V4(buf, len, prefix_code, start, count, | |
9579 | points); | |
9580 | break; | |
9581 | case DNP3_OBJECT_CODE(51, 1): | |
9582 | rc = DNP3DecodeObjectG51V1(buf, len, prefix_code, start, count, | |
9583 | points); | |
9584 | break; | |
9585 | case DNP3_OBJECT_CODE(51, 2): | |
9586 | rc = DNP3DecodeObjectG51V2(buf, len, prefix_code, start, count, | |
9587 | points); | |
9588 | break; | |
9589 | case DNP3_OBJECT_CODE(52, 1): | |
9590 | rc = DNP3DecodeObjectG52V1(buf, len, prefix_code, start, count, | |
9591 | points); | |
9592 | break; | |
9593 | case DNP3_OBJECT_CODE(52, 2): | |
9594 | rc = DNP3DecodeObjectG52V2(buf, len, prefix_code, start, count, | |
9595 | points); | |
9596 | break; | |
9597 | case DNP3_OBJECT_CODE(70, 1): | |
9598 | rc = DNP3DecodeObjectG70V1(buf, len, prefix_code, start, count, | |
9599 | points); | |
9600 | break; | |
9601 | case DNP3_OBJECT_CODE(70, 2): | |
9602 | rc = DNP3DecodeObjectG70V2(buf, len, prefix_code, start, count, | |
9603 | points); | |
9604 | break; | |
9605 | case DNP3_OBJECT_CODE(70, 3): | |
9606 | rc = DNP3DecodeObjectG70V3(buf, len, prefix_code, start, count, | |
9607 | points); | |
9608 | break; | |
9609 | case DNP3_OBJECT_CODE(70, 4): | |
9610 | rc = DNP3DecodeObjectG70V4(buf, len, prefix_code, start, count, | |
9611 | points); | |
9612 | break; | |
9613 | case DNP3_OBJECT_CODE(70, 5): | |
9614 | rc = DNP3DecodeObjectG70V5(buf, len, prefix_code, start, count, | |
9615 | points); | |
9616 | break; | |
9617 | case DNP3_OBJECT_CODE(70, 6): | |
9618 | rc = DNP3DecodeObjectG70V6(buf, len, prefix_code, start, count, | |
9619 | points); | |
9620 | break; | |
9621 | case DNP3_OBJECT_CODE(70, 7): | |
9622 | rc = DNP3DecodeObjectG70V7(buf, len, prefix_code, start, count, | |
9623 | points); | |
9624 | break; | |
9625 | case DNP3_OBJECT_CODE(70, 8): | |
9626 | rc = DNP3DecodeObjectG70V8(buf, len, prefix_code, start, count, | |
9627 | points); | |
9628 | break; | |
9629 | case DNP3_OBJECT_CODE(80, 1): | |
9630 | rc = DNP3DecodeObjectG80V1(buf, len, prefix_code, start, count, | |
9631 | points); | |
9632 | break; | |
9633 | case DNP3_OBJECT_CODE(81, 1): | |
9634 | rc = DNP3DecodeObjectG81V1(buf, len, prefix_code, start, count, | |
9635 | points); | |
9636 | break; | |
9637 | case DNP3_OBJECT_CODE(83, 1): | |
9638 | rc = DNP3DecodeObjectG83V1(buf, len, prefix_code, start, count, | |
9639 | points); | |
9640 | break; | |
9641 | case DNP3_OBJECT_CODE(86, 2): | |
9642 | rc = DNP3DecodeObjectG86V2(buf, len, prefix_code, start, count, | |
9643 | points); | |
9644 | break; | |
9645 | case DNP3_OBJECT_CODE(102, 1): | |
9646 | rc = DNP3DecodeObjectG102V1(buf, len, prefix_code, start, count, | |
9647 | points); | |
9648 | break; | |
9649 | case DNP3_OBJECT_CODE(120, 1): | |
9650 | rc = DNP3DecodeObjectG120V1(buf, len, prefix_code, start, count, | |
9651 | points); | |
9652 | break; | |
9653 | case DNP3_OBJECT_CODE(120, 2): | |
9654 | rc = DNP3DecodeObjectG120V2(buf, len, prefix_code, start, count, | |
9655 | points); | |
9656 | break; | |
9657 | case DNP3_OBJECT_CODE(120, 3): | |
9658 | rc = DNP3DecodeObjectG120V3(buf, len, prefix_code, start, count, | |
9659 | points); | |
9660 | break; | |
9661 | case DNP3_OBJECT_CODE(120, 4): | |
9662 | rc = DNP3DecodeObjectG120V4(buf, len, prefix_code, start, count, | |
9663 | points); | |
9664 | break; | |
9665 | case DNP3_OBJECT_CODE(120, 5): | |
9666 | rc = DNP3DecodeObjectG120V5(buf, len, prefix_code, start, count, | |
9667 | points); | |
9668 | break; | |
9669 | case DNP3_OBJECT_CODE(120, 6): | |
9670 | rc = DNP3DecodeObjectG120V6(buf, len, prefix_code, start, count, | |
9671 | points); | |
9672 | break; | |
9673 | case DNP3_OBJECT_CODE(120, 7): | |
9674 | rc = DNP3DecodeObjectG120V7(buf, len, prefix_code, start, count, | |
9675 | points); | |
9676 | break; | |
9677 | case DNP3_OBJECT_CODE(120, 8): | |
9678 | rc = DNP3DecodeObjectG120V8(buf, len, prefix_code, start, count, | |
9679 | points); | |
9680 | break; | |
9681 | case DNP3_OBJECT_CODE(120, 9): | |
9682 | rc = DNP3DecodeObjectG120V9(buf, len, prefix_code, start, count, | |
9683 | points); | |
9684 | break; | |
9685 | case DNP3_OBJECT_CODE(120, 10): | |
9686 | rc = DNP3DecodeObjectG120V10(buf, len, prefix_code, start, count, | |
9687 | points); | |
9688 | break; | |
9689 | case DNP3_OBJECT_CODE(120, 11): | |
9690 | rc = DNP3DecodeObjectG120V11(buf, len, prefix_code, start, count, | |
9691 | points); | |
9692 | break; | |
9693 | case DNP3_OBJECT_CODE(120, 12): | |
9694 | rc = DNP3DecodeObjectG120V12(buf, len, prefix_code, start, count, | |
9695 | points); | |
9696 | break; | |
9697 | case DNP3_OBJECT_CODE(120, 13): | |
9698 | rc = DNP3DecodeObjectG120V13(buf, len, prefix_code, start, count, | |
9699 | points); | |
9700 | break; | |
9701 | case DNP3_OBJECT_CODE(120, 14): | |
9702 | rc = DNP3DecodeObjectG120V14(buf, len, prefix_code, start, count, | |
9703 | points); | |
9704 | break; | |
9705 | case DNP3_OBJECT_CODE(120, 15): | |
9706 | rc = DNP3DecodeObjectG120V15(buf, len, prefix_code, start, count, | |
9707 | points); | |
9708 | break; | |
9709 | case DNP3_OBJECT_CODE(121, 1): | |
9710 | rc = DNP3DecodeObjectG121V1(buf, len, prefix_code, start, count, | |
9711 | points); | |
9712 | break; | |
9713 | case DNP3_OBJECT_CODE(122, 1): | |
9714 | rc = DNP3DecodeObjectG122V1(buf, len, prefix_code, start, count, | |
9715 | points); | |
9716 | break; | |
9717 | case DNP3_OBJECT_CODE(122, 2): | |
9718 | rc = DNP3DecodeObjectG122V2(buf, len, prefix_code, start, count, | |
9719 | points); | |
9720 | break; | |
9721 | default: | |
9722 | return DNP3_DECODER_EVENT_UNKNOWN_OBJECT; | |
9723 | } | |
9724 | ||
9725 | return rc ? 0 : DNP3_DECODER_EVENT_MALFORMED; | |
9726 | } | |
9727 | ||
9728 | /* END GENERATED CODE */ |