Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
infomodel_elements.h
1/* infomodel_elements.h
2 * Defines elements to represent an infomodel.
3 *
4 * OPC UA information model (custom datatypes from a UANodeSet XML file)
5 * Author: Leon Schmidt <[email protected]>
6 * Copyright (C) 2022 Codewerk GmbH
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11#include <glib.h>
12#include <stdbool.h>
13#include <stdint.h>
14#include <stddef.h>
15
16#ifndef INFO_ELEM_H
17#define INFO_ELEM_H
18
19/* Enums */
20typedef enum _AliasType {
21 ALIAS_INVALID = 0,
22
23 ALIAS_BOOLEAN,
24 ALIAS_SBYTE,
25 ALIAS_BYTE,
26 ALIAS_INT16,
27 ALIAS_UINT16,
28 ALIAS_INT32,
29 ALIAS_UINT32,
30 ALIAS_INT64,
31 ALIAS_UINT64,
32 ALIAS_FLOAT,
33 ALIAS_DOUBLE,
34 ALIAS_DATETIME,
35 ALIAS_UTCTIME,
36 ALIAS_STRING,
37 ALIAS_BYTESTRING,
38 ALIAS_LOCALIZEDTEXT,
39} AliasType;
40
41typedef enum _DatatypeIdType {
42 DATATYPEID_EMPTY = 0,
43
44 DATATYPEID_NUMERIC,
45 DATATYPEID_STRING,
46 DATATYPEID_GUID,
47 DATATYPEID_OPAQUE,
48} DatatypeIdType;
49
50typedef enum _Subtype {
51 SUBTYPE_INVALID = 0,
52 SUBTYPE_UNDEFINED,
53
54 SUBTYPE_BOOLEAN,
55 SUBTYPE_SBYTE,
56 SUBTYPE_BYTE,
57 SUBTYPE_INT16,
58 SUBTYPE_UINT16,
59 SUBTYPE_INT32,
60 SUBTYPE_UINT32,
61 SUBTYPE_INT64,
62 SUBTYPE_UINT64,
63 SUBTYPE_FLOAT,
64 SUBTYPE_DOUBLE,
65 SUBTYPE_DATETIME,
66 SUBTYPE_STRING,
67 SUBTYPE_BYTESTRING,
68
69 SUBTYPE_STRUCT,
70 SUBTYPE_ENUM,
71 SUBTYPE_OPTIONSET,
72 SUBTYPE_CUSTOM,
73} Subtype;
74
75/* Container struct */
76typedef struct _Datatype {
77 unsigned int ns; /* namespace */
78 DatatypeIdType idType;
79
80 union {
81 unsigned int id_num;
82 char *id_str;
83 /* TODO support other datatypeidtypes */
84 };
85} Datatype;
86
87/* Stores Alias Types from Infomodel as a list */
88/* to translate a given ns and id to a primitive type */
89/* usually specified at the beginning of an Infomodel XML */
90typedef struct _AliasMap {
91 char *name;
92 Datatype type;
93 AliasType aType;
94
95 struct _AliasMap *next;
96} AliasMap;
97
98AliasMap *AliasMap_new(void);
99
100/* Fill in type field depending on current name */
101void AliasMap_type_lookup(AliasMap *self);
102Datatype AliasMap_find_name(AliasMap *self, const char *name);
103
104/* represents one member value of a Custom Datatype */
105/* "next" points to the next member of that custom type, */
106/* essentially creating a list of fields */
107typedef struct _Field {
108 char *name;
109 Datatype type;
110 int value;
111
112 int valueRank; /* -1: scalar, 0 or 1: one-dimensional array, > 1: matrix */
113 bool isOptional;
114 bool allowSubTypes;
115
116 struct _Field *next;
117
118 int hf_id;
119 int ett_id;
120} Field;
121
122Field *Field_new(void);
123void Field_delete(Field *self);
124
125AliasType Field_find_atype(Field *self, AliasMap *map);
126
127/* represents a Custom Datatype of the Infomodel */
128/* "next" points to the next custom datatype of that Infomodel, */
129/* essentially creating a list of custom datatypes */
130typedef struct _CustomDatatype {
131 char *name;
132 Datatype id;
133 Subtype subtype;
134 struct _CustomDatatype *customSubtype; /* only relevant if subtype == SUBTYPE_CUSTOM */
135
136 Field *fields_first;
137 Field *fields_last;
138 bool hasOptionalFields;
139 bool fieldsIgnored; /* union or derived structure: its own fields are not decoded (yet) */
140
141 int ett_id; /* only used for top level, subfields use own ett_id */
142
143 struct _CustomDatatype *next;
144} CustomDatatype;
145
146CustomDatatype *CustomDatatype_new(void);
147void CustomDatatype_delete(CustomDatatype *self);
148
149void CustomDatatype_add_field(CustomDatatype *self, Field *field);
150CustomDatatype *CustomDatatype_find(CustomDatatype *self, Datatype nodeId);
151
152/* Represents a UAObject, which is usually referenced from a packet */
153/* contains information about what Custom Datatype is used in that packet */
154/* "next" points to the next UAObject, as several may be specified in a given Infomodel */
155typedef struct _UAObject {
156 char *name;
157 Datatype id;
158
159 Datatype refEncodingRaw;
160
161 struct _UAObject *next;
162} UAObject;
163
164UAObject *UAObject_new(void);
165void UAObject_delete(UAObject *self);
166
167/* high level representation of an entire Infomodel */
168/* contains one list of aliases, custom datatypes and UAObjects respectively */
169typedef struct _Infomodel {
170 AliasMap *aliases_first;
171 AliasMap *aliases_last;
172
173 CustomDatatype *customDatatype_first;
174 CustomDatatype *customDatatype_last;
175
176 UAObject *objects_first;
177 UAObject *objects_last;
178
179} Infomodel;
180
181Infomodel *Infomodel_new(void);
182void Infomodel_delete(Infomodel *self);
183void Infomodel_add_aliasmap_entry(Infomodel *self, AliasMap *map);
184void Infomodel_add_type(Infomodel *self, CustomDatatype *type);
185void Infomodel_add_object(Infomodel *self, UAObject *object);
186
187#endif /* INFO_ELEM_H */
Definition infomodel_elements.h:90
Definition infomodel_elements.h:130
Definition infomodel_elements.h:76
Definition infomodel_elements.h:107
Definition infomodel_elements.h:169
Definition infomodel_elements.h:155