Line | Count | Source |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include <glib.h> |
5 | | |
6 | | #include "fu-uswid-struct.h" |
7 | | #include "fu-byte-array.h" |
8 | | #include "fu-mem-private.h" |
9 | | #include "fu-string.h" |
10 | | |
11 | | #ifdef G_LOG_DOMAIN |
12 | | #undef G_LOG_DOMAIN |
13 | | #endif |
14 | 0 | #define G_LOG_DOMAIN "FuStruct" |
15 | | |
16 | | |
17 | | const gchar * |
18 | | fu_uswid_payload_compression_to_string(FuUswidPayloadCompression val) |
19 | 0 | { |
20 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_NONE) |
21 | 0 | return "none"; |
22 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_ZLIB) |
23 | 0 | return "zlib"; |
24 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_LZMA) |
25 | 0 | return "lzma"; |
26 | 0 | return NULL; |
27 | 0 | } |
28 | | FuUswidPayloadCompression |
29 | | fu_uswid_payload_compression_from_string(const gchar *val) |
30 | 0 | { |
31 | 0 | if (g_strcmp0(val, "none") == 0) |
32 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
33 | 0 | if (g_strcmp0(val, "zlib") == 0) |
34 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_ZLIB; |
35 | 0 | if (g_strcmp0(val, "lzma") == 0) |
36 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_LZMA; |
37 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
38 | 0 | } |
39 | | /** |
40 | | * fu_struct_uswid_ref: (skip): |
41 | | **/ |
42 | | FuStructUswid * |
43 | | fu_struct_uswid_ref(FuStructUswid *st) |
44 | 0 | { |
45 | 0 | g_return_val_if_fail(st != NULL, NULL); |
46 | 0 | st->refcount++; |
47 | 0 | return st; |
48 | 0 | } |
49 | | /** |
50 | | * fu_struct_uswid_unref: (skip): |
51 | | **/ |
52 | | void |
53 | | fu_struct_uswid_unref(FuStructUswid *st) |
54 | 232k | { |
55 | 232k | g_return_if_fail(st != NULL); |
56 | 232k | if (st->refcount == 0) { |
57 | 0 | g_critical("FuStructUswid refcount already zero"); |
58 | 0 | return; |
59 | 0 | } |
60 | 232k | if (--st->refcount > 0) |
61 | 0 | return; |
62 | 232k | if (st->buf != NULL) |
63 | 229k | g_byte_array_unref(st->buf); |
64 | 232k | g_free(st); |
65 | 232k | } |
66 | | /** |
67 | | * fu_struct_uswid_new_internal: (skip): |
68 | | **/ |
69 | | static FuStructUswid * |
70 | | fu_struct_uswid_new_internal(void) |
71 | 232k | { |
72 | 232k | FuStructUswid *st = g_new0(FuStructUswid, 1); |
73 | 232k | st->refcount = 1; |
74 | 232k | return st; |
75 | 232k | } |
76 | | |
77 | | /* getters */ |
78 | | /** |
79 | | * fu_struct_uswid_get_magic: (skip): |
80 | | **/ |
81 | | static const fwupd_guid_t * |
82 | | fu_struct_uswid_get_magic(const FuStructUswid *st) |
83 | 228k | { |
84 | 228k | g_return_val_if_fail(st != NULL, NULL); |
85 | 228k | return (const fwupd_guid_t *) (st->buf->data + 0); |
86 | 228k | } |
87 | | /** |
88 | | * fu_struct_uswid_get_hdrver: (skip): |
89 | | **/ |
90 | | guint8 |
91 | | fu_struct_uswid_get_hdrver(const FuStructUswid *st) |
92 | 114k | { |
93 | 114k | g_return_val_if_fail(st != NULL, 0x0); |
94 | 114k | return st->buf->data[16]; |
95 | 114k | } |
96 | | /** |
97 | | * fu_struct_uswid_get_hdrsz: (skip): |
98 | | **/ |
99 | | guint16 |
100 | | fu_struct_uswid_get_hdrsz(const FuStructUswid *st) |
101 | 113k | { |
102 | 113k | g_return_val_if_fail(st != NULL, 0x0); |
103 | 113k | return fu_memread_uint16(st->buf->data + 17, G_LITTLE_ENDIAN); |
104 | 113k | } |
105 | | /** |
106 | | * fu_struct_uswid_get_payloadsz: (skip): |
107 | | **/ |
108 | | guint32 |
109 | | fu_struct_uswid_get_payloadsz(const FuStructUswid *st) |
110 | 113k | { |
111 | 113k | g_return_val_if_fail(st != NULL, 0x0); |
112 | 113k | return fu_memread_uint32(st->buf->data + 19, G_LITTLE_ENDIAN); |
113 | 113k | } |
114 | | /** |
115 | | * fu_struct_uswid_get_flags: (skip): |
116 | | **/ |
117 | | guint8 |
118 | | fu_struct_uswid_get_flags(const FuStructUswid *st) |
119 | 63.6k | { |
120 | 63.6k | g_return_val_if_fail(st != NULL, 0x0); |
121 | 63.6k | return st->buf->data[23]; |
122 | 63.6k | } |
123 | | /** |
124 | | * fu_struct_uswid_get_compression: (skip): |
125 | | **/ |
126 | | guint8 |
127 | | fu_struct_uswid_get_compression(const FuStructUswid *st) |
128 | 14.5k | { |
129 | 14.5k | g_return_val_if_fail(st != NULL, 0x0); |
130 | 14.5k | return st->buf->data[24]; |
131 | 14.5k | } |
132 | | |
133 | | /* setters */ |
134 | | /** |
135 | | * fu_struct_uswid_set_magic: (skip): |
136 | | **/ |
137 | | static void |
138 | | fu_struct_uswid_set_magic(FuStructUswid *st, const fwupd_guid_t *value) |
139 | 3.00k | { |
140 | 3.00k | g_return_if_fail(st != NULL); |
141 | 3.00k | g_return_if_fail(value != NULL); |
142 | 3.00k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
143 | 3.00k | } |
144 | | /** |
145 | | * fu_struct_uswid_set_hdrver: (skip): |
146 | | **/ |
147 | | void |
148 | | fu_struct_uswid_set_hdrver(FuStructUswid *st, guint8 value) |
149 | 2.99k | { |
150 | 2.99k | g_return_if_fail(st != NULL); |
151 | 2.99k | st->buf->data[16] = value; |
152 | 2.99k | } |
153 | | /** |
154 | | * fu_struct_uswid_set_hdrsz: (skip): |
155 | | **/ |
156 | | void |
157 | | fu_struct_uswid_set_hdrsz(FuStructUswid *st, guint16 value) |
158 | 5.32k | { |
159 | 5.32k | g_return_if_fail(st != NULL); |
160 | 5.32k | fu_memwrite_uint16(st->buf->data + 17, value, G_LITTLE_ENDIAN); |
161 | 5.32k | } |
162 | | /** |
163 | | * fu_struct_uswid_set_payloadsz: (skip): |
164 | | **/ |
165 | | void |
166 | | fu_struct_uswid_set_payloadsz(FuStructUswid *st, guint32 value) |
167 | 2.99k | { |
168 | 2.99k | g_return_if_fail(st != NULL); |
169 | 2.99k | fu_memwrite_uint32(st->buf->data + 19, value, G_LITTLE_ENDIAN); |
170 | 2.99k | } |
171 | | /** |
172 | | * fu_struct_uswid_set_flags: (skip): |
173 | | **/ |
174 | | void |
175 | | fu_struct_uswid_set_flags(FuStructUswid *st, guint8 value) |
176 | 721 | { |
177 | 721 | g_return_if_fail(st != NULL); |
178 | 721 | st->buf->data[23] = value; |
179 | 721 | } |
180 | | /** |
181 | | * fu_struct_uswid_set_compression: (skip): |
182 | | **/ |
183 | | void |
184 | | fu_struct_uswid_set_compression(FuStructUswid *st, guint8 value) |
185 | 673 | { |
186 | 673 | g_return_if_fail(st != NULL); |
187 | 673 | st->buf->data[24] = value; |
188 | 673 | } |
189 | | /** |
190 | | * fu_struct_uswid_new: (skip): |
191 | | **/ |
192 | | FuStructUswid * |
193 | | fu_struct_uswid_new(void) |
194 | 3.00k | { |
195 | 3.00k | FuStructUswid *st = fu_struct_uswid_new_internal(); |
196 | 3.00k | st->buf = g_byte_array_sized_new(25); |
197 | 3.00k | fu_byte_array_set_size(st->buf, 25, 0x0); |
198 | 3.00k | fu_struct_uswid_set_magic(st, (fwupd_guid_t *) "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf"); |
199 | 3.00k | fu_struct_uswid_set_hdrsz(st, 25); |
200 | 3.00k | return st; |
201 | 3.00k | } |
202 | | /** |
203 | | * fu_struct_uswid_to_string: (skip): |
204 | | **/ |
205 | | static gchar * |
206 | | fu_struct_uswid_to_string(const FuStructUswid *st) |
207 | 0 | { |
208 | 0 | g_autoptr(GString) str = g_string_new("FuStructUswid:\n"); |
209 | 0 | g_return_val_if_fail(st != NULL, NULL); |
210 | 0 | g_string_append_printf(str, " hdrver: 0x%x\n", |
211 | 0 | (guint) fu_struct_uswid_get_hdrver(st)); |
212 | 0 | g_string_append_printf(str, " hdrsz: 0x%x\n", |
213 | 0 | (guint) fu_struct_uswid_get_hdrsz(st)); |
214 | 0 | g_string_append_printf(str, " payloadsz: 0x%x\n", |
215 | 0 | (guint) fu_struct_uswid_get_payloadsz(st)); |
216 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
217 | 0 | (guint) fu_struct_uswid_get_flags(st)); |
218 | 0 | g_string_append_printf(str, " compression: 0x%x\n", |
219 | 0 | (guint) fu_struct_uswid_get_compression(st)); |
220 | 0 | if (str->len > 0) |
221 | 0 | g_string_set_size(str, str->len - 1); |
222 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
223 | 0 | } |
224 | | static gboolean |
225 | | fu_struct_uswid_validate_internal(FuStructUswid *st, GError **error) |
226 | 228k | { |
227 | 228k | g_return_val_if_fail(st != NULL, FALSE); |
228 | 228k | if (memcmp(fu_struct_uswid_get_magic(st), "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf", 16) != 0) { |
229 | 0 | g_set_error_literal(error, |
230 | 0 | FWUPD_ERROR, |
231 | 0 | FWUPD_ERROR_INVALID_DATA, |
232 | 0 | "constant FuStructUswid.magic was not valid"); |
233 | 0 | return FALSE; |
234 | 0 | } |
235 | 228k | return TRUE; |
236 | 228k | } |
237 | | /** |
238 | | * fu_struct_uswid_validate_stream: (skip): |
239 | | **/ |
240 | | gboolean |
241 | | fu_struct_uswid_validate_stream(GInputStream *stream, gsize offset, GError **error) |
242 | 114k | { |
243 | 114k | g_autoptr(FuStructUswid) st = fu_struct_uswid_new_internal(); |
244 | 114k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
245 | 114k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
246 | 114k | st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
247 | 114k | if (st->buf == NULL) { |
248 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
249 | 0 | return FALSE; |
250 | 0 | } |
251 | 114k | if (st->buf->len != 25) { |
252 | 500 | g_set_error(error, |
253 | 500 | FWUPD_ERROR, |
254 | 500 | FWUPD_ERROR_INVALID_DATA, |
255 | 500 | "FuStructUswid requested 0x%x and got 0x%x", |
256 | 500 | (guint) 25, |
257 | 500 | (guint) st->buf->len); |
258 | 500 | return FALSE; |
259 | 500 | } |
260 | 114k | return fu_struct_uswid_validate_internal(st, error); |
261 | 114k | } |
262 | | static gboolean |
263 | | fu_struct_uswid_parse_internal(FuStructUswid *st, GError **error) |
264 | 114k | { |
265 | 114k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
266 | 0 | g_autofree gchar *str = fu_struct_uswid_to_string(st); |
267 | 0 | g_debug("%s", str); |
268 | 0 | } |
269 | 114k | if (!fu_struct_uswid_validate_internal(st, error)) |
270 | 0 | return FALSE; |
271 | 114k | return TRUE; |
272 | 114k | } |
273 | | /** |
274 | | * fu_struct_uswid_parse_stream: (skip): |
275 | | **/ |
276 | | FuStructUswid * |
277 | | fu_struct_uswid_parse_stream(GInputStream *stream, gsize offset, GError **error) |
278 | 114k | { |
279 | 114k | g_autoptr(FuStructUswid) st = fu_struct_uswid_new_internal(); |
280 | 114k | st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
281 | 114k | if (st->buf == NULL) { |
282 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
283 | 0 | return NULL; |
284 | 0 | } |
285 | 114k | if (st->buf->len != 25) { |
286 | 0 | g_set_error(error, |
287 | 0 | FWUPD_ERROR, |
288 | 0 | FWUPD_ERROR_INVALID_DATA, |
289 | 0 | "FuStructUswid requested 0x%x and got 0x%x", |
290 | 0 | (guint) 25, |
291 | 0 | (guint) st->buf->len); |
292 | 0 | return NULL; |
293 | 0 | } |
294 | 114k | if (!fu_struct_uswid_parse_internal(st, error)) |
295 | 0 | return NULL; |
296 | 114k | return g_steal_pointer(&st); |
297 | 114k | } |