Line | Count | Source |
1 | | /* |
2 | | * This file is auto-generated, do not modify! |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include <glib.h> |
10 | | |
11 | | #include "fu-ifwi-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-bytes.h" |
14 | | #include "fu-mem-private.h" |
15 | | #include "fu-string.h" |
16 | | |
17 | | #ifdef G_LOG_DOMAIN |
18 | | #undef G_LOG_DOMAIN |
19 | | #endif |
20 | 0 | #define G_LOG_DOMAIN "FuStruct" |
21 | | /** |
22 | | * fu_struct_ifwi_cpd_ref: (skip): |
23 | | **/ |
24 | | FuStructIfwiCpd * |
25 | | fu_struct_ifwi_cpd_ref(FuStructIfwiCpd *st) |
26 | 0 | { |
27 | 0 | g_return_val_if_fail(st != NULL, NULL); |
28 | 0 | st->refcount++; |
29 | 0 | return st; |
30 | 0 | } |
31 | | /** |
32 | | * fu_struct_ifwi_cpd_unref: (skip): |
33 | | **/ |
34 | | void |
35 | | fu_struct_ifwi_cpd_unref(FuStructIfwiCpd *st) |
36 | 2.71k | { |
37 | 2.71k | g_return_if_fail(st != NULL); |
38 | 2.71k | if (st->refcount == 0) { |
39 | 0 | g_critical("FuStructIfwiCpd refcount already zero"); |
40 | 0 | return; |
41 | 0 | } |
42 | 2.71k | if (--st->refcount > 0) |
43 | 0 | return; |
44 | 2.71k | if (st->buf != NULL) |
45 | 2.71k | g_byte_array_unref(st->buf); |
46 | 2.71k | g_free(st); |
47 | 2.71k | } |
48 | | /** |
49 | | * fu_struct_ifwi_cpd_new_internal: (skip): |
50 | | **/ |
51 | | static FuStructIfwiCpd * |
52 | | fu_struct_ifwi_cpd_new_internal(void) |
53 | 2.71k | { |
54 | 2.71k | FuStructIfwiCpd *st = g_new0(FuStructIfwiCpd, 1); |
55 | 2.71k | st->refcount = 1; |
56 | 2.71k | return st; |
57 | 2.71k | } |
58 | | |
59 | | /* getters */ |
60 | | /** |
61 | | * fu_struct_ifwi_cpd_get_header_marker: (skip): |
62 | | **/ |
63 | | static guint32 |
64 | | fu_struct_ifwi_cpd_get_header_marker(const FuStructIfwiCpd *st) |
65 | 2.69k | { |
66 | 2.69k | g_return_val_if_fail(st != NULL, 0x0); |
67 | 2.69k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
68 | 2.69k | } |
69 | | /** |
70 | | * fu_struct_ifwi_cpd_get_num_of_entries: (skip): |
71 | | **/ |
72 | | guint32 |
73 | | fu_struct_ifwi_cpd_get_num_of_entries(const FuStructIfwiCpd *st) |
74 | 1.23k | { |
75 | 1.23k | g_return_val_if_fail(st != NULL, 0x0); |
76 | 1.23k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
77 | 1.23k | } |
78 | | /** |
79 | | * fu_struct_ifwi_cpd_get_header_version: (skip): |
80 | | **/ |
81 | | guint8 |
82 | | fu_struct_ifwi_cpd_get_header_version(const FuStructIfwiCpd *st) |
83 | 1.23k | { |
84 | 1.23k | g_return_val_if_fail(st != NULL, 0x0); |
85 | 1.23k | return st->buf->data[8]; |
86 | 1.23k | } |
87 | | /** |
88 | | * fu_struct_ifwi_cpd_get_entry_version: (skip): |
89 | | **/ |
90 | | guint8 |
91 | | fu_struct_ifwi_cpd_get_entry_version(const FuStructIfwiCpd *st) |
92 | 1.23k | { |
93 | 1.23k | g_return_val_if_fail(st != NULL, 0x0); |
94 | 1.23k | return st->buf->data[9]; |
95 | 1.23k | } |
96 | | /** |
97 | | * fu_struct_ifwi_cpd_get_header_length: (skip): |
98 | | **/ |
99 | | guint8 |
100 | | fu_struct_ifwi_cpd_get_header_length(const FuStructIfwiCpd *st) |
101 | 1.17k | { |
102 | 1.17k | g_return_val_if_fail(st != NULL, 0x0); |
103 | 1.17k | return st->buf->data[10]; |
104 | 1.17k | } |
105 | | /** |
106 | | * fu_struct_ifwi_cpd_get_checksum: (skip): |
107 | | **/ |
108 | | guint8 |
109 | | fu_struct_ifwi_cpd_get_checksum(const FuStructIfwiCpd *st) |
110 | 0 | { |
111 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
112 | 0 | return st->buf->data[11]; |
113 | 0 | } |
114 | | /** |
115 | | * fu_struct_ifwi_cpd_get_partition_name: (skip): |
116 | | **/ |
117 | | guint32 |
118 | | fu_struct_ifwi_cpd_get_partition_name(const FuStructIfwiCpd *st) |
119 | 1.23k | { |
120 | 1.23k | g_return_val_if_fail(st != NULL, 0x0); |
121 | 1.23k | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
122 | 1.23k | } |
123 | | /** |
124 | | * fu_struct_ifwi_cpd_get_crc32: (skip): |
125 | | **/ |
126 | | guint32 |
127 | | fu_struct_ifwi_cpd_get_crc32(const FuStructIfwiCpd *st) |
128 | 0 | { |
129 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
130 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
131 | 0 | } |
132 | | |
133 | | /* setters */ |
134 | | /** |
135 | | * fu_struct_ifwi_cpd_set_header_marker: (skip): |
136 | | **/ |
137 | | static void |
138 | | fu_struct_ifwi_cpd_set_header_marker(FuStructIfwiCpd *st, guint32 value) |
139 | 99 | { |
140 | 99 | g_return_if_fail(st != NULL); |
141 | 99 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
142 | 99 | } |
143 | | /** |
144 | | * fu_struct_ifwi_cpd_set_num_of_entries: (skip): |
145 | | **/ |
146 | | void |
147 | | fu_struct_ifwi_cpd_set_num_of_entries(FuStructIfwiCpd *st, guint32 value) |
148 | 99 | { |
149 | 99 | g_return_if_fail(st != NULL); |
150 | 99 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
151 | 99 | } |
152 | | /** |
153 | | * fu_struct_ifwi_cpd_set_header_version: (skip): |
154 | | **/ |
155 | | void |
156 | | fu_struct_ifwi_cpd_set_header_version(FuStructIfwiCpd *st, guint8 value) |
157 | 99 | { |
158 | 99 | g_return_if_fail(st != NULL); |
159 | 99 | st->buf->data[8] = value; |
160 | 99 | } |
161 | | /** |
162 | | * fu_struct_ifwi_cpd_set_entry_version: (skip): |
163 | | **/ |
164 | | void |
165 | | fu_struct_ifwi_cpd_set_entry_version(FuStructIfwiCpd *st, guint8 value) |
166 | 99 | { |
167 | 99 | g_return_if_fail(st != NULL); |
168 | 99 | st->buf->data[9] = value; |
169 | 99 | } |
170 | | /** |
171 | | * fu_struct_ifwi_cpd_set_header_length: (skip): |
172 | | **/ |
173 | | void |
174 | | fu_struct_ifwi_cpd_set_header_length(FuStructIfwiCpd *st, guint8 value) |
175 | 99 | { |
176 | 99 | g_return_if_fail(st != NULL); |
177 | 99 | st->buf->data[10] = value; |
178 | 99 | } |
179 | | /** |
180 | | * fu_struct_ifwi_cpd_set_checksum: (skip): |
181 | | **/ |
182 | | void |
183 | | fu_struct_ifwi_cpd_set_checksum(FuStructIfwiCpd *st, guint8 value) |
184 | 99 | { |
185 | 99 | g_return_if_fail(st != NULL); |
186 | 99 | st->buf->data[11] = value; |
187 | 99 | } |
188 | | /** |
189 | | * fu_struct_ifwi_cpd_set_partition_name: (skip): |
190 | | **/ |
191 | | void |
192 | | fu_struct_ifwi_cpd_set_partition_name(FuStructIfwiCpd *st, guint32 value) |
193 | 99 | { |
194 | 99 | g_return_if_fail(st != NULL); |
195 | 99 | fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
196 | 99 | } |
197 | | /** |
198 | | * fu_struct_ifwi_cpd_set_crc32: (skip): |
199 | | **/ |
200 | | void |
201 | | fu_struct_ifwi_cpd_set_crc32(FuStructIfwiCpd *st, guint32 value) |
202 | 99 | { |
203 | 99 | g_return_if_fail(st != NULL); |
204 | 99 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
205 | 99 | } |
206 | | /** |
207 | | * fu_struct_ifwi_cpd_new: (skip): |
208 | | **/ |
209 | | FuStructIfwiCpd * |
210 | | fu_struct_ifwi_cpd_new(void) |
211 | 99 | { |
212 | 99 | FuStructIfwiCpd *st = fu_struct_ifwi_cpd_new_internal(); |
213 | 99 | st->buf = g_byte_array_sized_new(20); |
214 | 99 | fu_byte_array_set_size(st->buf, 20, 0x0); |
215 | 99 | fu_struct_ifwi_cpd_set_header_marker(st, 0x44504324); |
216 | 99 | fu_struct_ifwi_cpd_set_header_length(st, 20); |
217 | 99 | return st; |
218 | 99 | } |
219 | | /** |
220 | | * fu_struct_ifwi_cpd_to_string: (skip): |
221 | | **/ |
222 | | static gchar * |
223 | | fu_struct_ifwi_cpd_to_string(const FuStructIfwiCpd *st) |
224 | 0 | { |
225 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiCpd:\n"); |
226 | 0 | g_return_val_if_fail(st != NULL, NULL); |
227 | 0 | g_string_append_printf(str, " header_marker: 0x%x\n", |
228 | 0 | (guint) fu_struct_ifwi_cpd_get_header_marker(st)); |
229 | 0 | g_string_append_printf(str, " num_of_entries: 0x%x\n", |
230 | 0 | (guint) fu_struct_ifwi_cpd_get_num_of_entries(st)); |
231 | 0 | g_string_append_printf(str, " header_version: 0x%x\n", |
232 | 0 | (guint) fu_struct_ifwi_cpd_get_header_version(st)); |
233 | 0 | g_string_append_printf(str, " entry_version: 0x%x\n", |
234 | 0 | (guint) fu_struct_ifwi_cpd_get_entry_version(st)); |
235 | 0 | g_string_append_printf(str, " header_length: 0x%x\n", |
236 | 0 | (guint) fu_struct_ifwi_cpd_get_header_length(st)); |
237 | 0 | g_string_append_printf(str, " checksum: 0x%x\n", |
238 | 0 | (guint) fu_struct_ifwi_cpd_get_checksum(st)); |
239 | 0 | g_string_append_printf(str, " partition_name: 0x%x\n", |
240 | 0 | (guint) fu_struct_ifwi_cpd_get_partition_name(st)); |
241 | 0 | g_string_append_printf(str, " crc32: 0x%x\n", |
242 | 0 | (guint) fu_struct_ifwi_cpd_get_crc32(st)); |
243 | 0 | if (str->len > 0) |
244 | 0 | g_string_set_size(str, str->len - 1); |
245 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
246 | 0 | } |
247 | | static gboolean |
248 | | fu_struct_ifwi_cpd_validate_internal(FuStructIfwiCpd *st, GError **error) |
249 | 2.58k | { |
250 | 2.58k | g_return_val_if_fail(st != NULL, FALSE); |
251 | 2.58k | if (fu_struct_ifwi_cpd_get_header_marker(st) != 0x44504324) { |
252 | 113 | g_set_error(error, |
253 | 113 | FWUPD_ERROR, |
254 | 113 | FWUPD_ERROR_INVALID_DATA, |
255 | 113 | "constant FuStructIfwiCpd.header_marker was not valid, " |
256 | 113 | "expected 0x%x and got 0x%x", |
257 | 113 | (guint) 0x44504324, |
258 | 113 | (guint) fu_struct_ifwi_cpd_get_header_marker(st)); |
259 | 113 | return FALSE; |
260 | 113 | } |
261 | 2.46k | return TRUE; |
262 | 2.58k | } |
263 | | /** |
264 | | * fu_struct_ifwi_cpd_validate_stream: (skip): |
265 | | **/ |
266 | | gboolean |
267 | | fu_struct_ifwi_cpd_validate_stream(GInputStream *stream, gsize offset, GError **error) |
268 | 1.38k | { |
269 | 1.38k | g_autoptr(FuStructIfwiCpd) st = fu_struct_ifwi_cpd_new_internal(); |
270 | 1.38k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
271 | 1.38k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
272 | 1.38k | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
273 | 1.38k | if (st->buf == NULL) { |
274 | 0 | g_prefix_error(error, "FuStructIfwiCpd failed read of 0x%x: ", (guint) 20); |
275 | 0 | return FALSE; |
276 | 0 | } |
277 | 1.38k | if (st->buf->len != 20) { |
278 | 34 | g_set_error(error, |
279 | 34 | FWUPD_ERROR, |
280 | 34 | FWUPD_ERROR_INVALID_DATA, |
281 | 34 | "FuStructIfwiCpd requested 0x%x and got 0x%x", |
282 | 34 | (guint) 20, |
283 | 34 | (guint) st->buf->len); |
284 | 34 | return FALSE; |
285 | 34 | } |
286 | 1.34k | return fu_struct_ifwi_cpd_validate_internal(st, error); |
287 | 1.38k | } |
288 | | static gboolean |
289 | | fu_struct_ifwi_cpd_parse_internal(FuStructIfwiCpd *st, GError **error) |
290 | 1.23k | { |
291 | 1.23k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
292 | 0 | g_autofree gchar *str = fu_struct_ifwi_cpd_to_string(st); |
293 | 0 | g_debug("%s", str); |
294 | 0 | } |
295 | 1.23k | if (!fu_struct_ifwi_cpd_validate_internal(st, error)) |
296 | 0 | return FALSE; |
297 | 1.23k | return TRUE; |
298 | 1.23k | } |
299 | | /** |
300 | | * fu_struct_ifwi_cpd_parse_stream: (skip): |
301 | | **/ |
302 | | FuStructIfwiCpd * |
303 | | fu_struct_ifwi_cpd_parse_stream(GInputStream *stream, gsize offset, GError **error) |
304 | 1.23k | { |
305 | 1.23k | g_autoptr(FuStructIfwiCpd) st = fu_struct_ifwi_cpd_new_internal(); |
306 | 1.23k | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
307 | 1.23k | if (st->buf == NULL) { |
308 | 0 | g_prefix_error(error, "FuStructIfwiCpd failed read of 0x%x: ", (guint) 20); |
309 | 0 | return NULL; |
310 | 0 | } |
311 | 1.23k | if (st->buf->len != 20) { |
312 | 0 | g_set_error(error, |
313 | 0 | FWUPD_ERROR, |
314 | 0 | FWUPD_ERROR_INVALID_DATA, |
315 | 0 | "FuStructIfwiCpd requested 0x%x and got 0x%x", |
316 | 0 | (guint) 20, |
317 | 0 | (guint) st->buf->len); |
318 | 0 | return NULL; |
319 | 0 | } |
320 | 1.23k | if (!fu_struct_ifwi_cpd_parse_internal(st, error)) |
321 | 0 | return NULL; |
322 | 1.23k | return g_steal_pointer(&st); |
323 | 1.23k | } |
324 | | /** |
325 | | * fu_struct_ifwi_cpd_entry_ref: (skip): |
326 | | **/ |
327 | | FuStructIfwiCpdEntry * |
328 | | fu_struct_ifwi_cpd_entry_ref(FuStructIfwiCpdEntry *st) |
329 | 0 | { |
330 | 0 | g_return_val_if_fail(st != NULL, NULL); |
331 | 0 | st->refcount++; |
332 | 0 | return st; |
333 | 0 | } |
334 | | /** |
335 | | * fu_struct_ifwi_cpd_entry_unref: (skip): |
336 | | **/ |
337 | | void |
338 | | fu_struct_ifwi_cpd_entry_unref(FuStructIfwiCpdEntry *st) |
339 | 37.2k | { |
340 | 37.2k | g_return_if_fail(st != NULL); |
341 | 37.2k | if (st->refcount == 0) { |
342 | 0 | g_critical("FuStructIfwiCpdEntry refcount already zero"); |
343 | 0 | return; |
344 | 0 | } |
345 | 37.2k | if (--st->refcount > 0) |
346 | 0 | return; |
347 | 37.2k | if (st->buf != NULL) |
348 | 37.0k | g_byte_array_unref(st->buf); |
349 | 37.2k | g_free(st); |
350 | 37.2k | } |
351 | | /** |
352 | | * fu_struct_ifwi_cpd_entry_new_internal: (skip): |
353 | | **/ |
354 | | static FuStructIfwiCpdEntry * |
355 | | fu_struct_ifwi_cpd_entry_new_internal(void) |
356 | 37.2k | { |
357 | 37.2k | FuStructIfwiCpdEntry *st = g_new0(FuStructIfwiCpdEntry, 1); |
358 | 37.2k | st->refcount = 1; |
359 | 37.2k | return st; |
360 | 37.2k | } |
361 | | |
362 | | /* getters */ |
363 | | /** |
364 | | * fu_struct_ifwi_cpd_entry_get_name: (skip): |
365 | | **/ |
366 | | gchar * |
367 | | fu_struct_ifwi_cpd_entry_get_name(const FuStructIfwiCpdEntry *st) |
368 | 36.9k | { |
369 | 36.9k | g_return_val_if_fail(st != NULL, NULL); |
370 | 36.9k | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 12, NULL); |
371 | 36.9k | } |
372 | | /** |
373 | | * fu_struct_ifwi_cpd_entry_get_offset: (skip): |
374 | | **/ |
375 | | guint32 |
376 | | fu_struct_ifwi_cpd_entry_get_offset(const FuStructIfwiCpdEntry *st) |
377 | 36.9k | { |
378 | 36.9k | g_return_val_if_fail(st != NULL, 0x0); |
379 | 36.9k | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
380 | 36.9k | } |
381 | | /** |
382 | | * fu_struct_ifwi_cpd_entry_get_length: (skip): |
383 | | **/ |
384 | | guint32 |
385 | | fu_struct_ifwi_cpd_entry_get_length(const FuStructIfwiCpdEntry *st) |
386 | 37.9k | { |
387 | 37.9k | g_return_val_if_fail(st != NULL, 0x0); |
388 | 37.9k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
389 | 37.9k | } |
390 | | |
391 | | /* setters */ |
392 | | /** |
393 | | * fu_struct_ifwi_cpd_entry_set_name: (skip): |
394 | | **/ |
395 | | gboolean |
396 | | fu_struct_ifwi_cpd_entry_set_name(FuStructIfwiCpdEntry *st, const gchar *value, GError **error) |
397 | 0 | { |
398 | 0 | gsize len; |
399 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
400 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
401 | 0 | if (value == NULL) { |
402 | 0 | memset(st->buf->data + 0, 0x0, 12); |
403 | 0 | return TRUE; |
404 | 0 | } |
405 | 0 | len = strlen(value); |
406 | 0 | if (len > 12) { |
407 | 0 | g_set_error(error, |
408 | 0 | FWUPD_ERROR, |
409 | 0 | FWUPD_ERROR_INVALID_DATA, |
410 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructIfwiCpdEntry.name (0x%x bytes)", |
411 | 0 | value, (guint) len, (guint) 12); |
412 | 0 | return FALSE; |
413 | 0 | } |
414 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
415 | 0 | } |
416 | | /** |
417 | | * fu_struct_ifwi_cpd_entry_set_offset: (skip): |
418 | | **/ |
419 | | void |
420 | | fu_struct_ifwi_cpd_entry_set_offset(FuStructIfwiCpdEntry *st, guint32 value) |
421 | 0 | { |
422 | 0 | g_return_if_fail(st != NULL); |
423 | 0 | fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
424 | 0 | } |
425 | | /** |
426 | | * fu_struct_ifwi_cpd_entry_set_length: (skip): |
427 | | **/ |
428 | | void |
429 | | fu_struct_ifwi_cpd_entry_set_length(FuStructIfwiCpdEntry *st, guint32 value) |
430 | 0 | { |
431 | 0 | g_return_if_fail(st != NULL); |
432 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
433 | 0 | } |
434 | | /** |
435 | | * fu_struct_ifwi_cpd_entry_new: (skip): |
436 | | **/ |
437 | | FuStructIfwiCpdEntry * |
438 | | fu_struct_ifwi_cpd_entry_new(void) |
439 | 0 | { |
440 | 0 | FuStructIfwiCpdEntry *st = fu_struct_ifwi_cpd_entry_new_internal(); |
441 | 0 | st->buf = g_byte_array_sized_new(24); |
442 | 0 | fu_byte_array_set_size(st->buf, 24, 0x0); |
443 | 0 | return st; |
444 | 0 | } |
445 | | /** |
446 | | * fu_struct_ifwi_cpd_entry_to_string: (skip): |
447 | | **/ |
448 | | static gchar * |
449 | | fu_struct_ifwi_cpd_entry_to_string(const FuStructIfwiCpdEntry *st) |
450 | 0 | { |
451 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiCpdEntry:\n"); |
452 | 0 | g_return_val_if_fail(st != NULL, NULL); |
453 | 0 | { |
454 | 0 | g_autofree gchar *tmp = fu_struct_ifwi_cpd_entry_get_name(st); |
455 | 0 | if (tmp != NULL) |
456 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
457 | 0 | } |
458 | 0 | g_string_append_printf(str, " offset: 0x%x\n", |
459 | 0 | (guint) fu_struct_ifwi_cpd_entry_get_offset(st)); |
460 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
461 | 0 | (guint) fu_struct_ifwi_cpd_entry_get_length(st)); |
462 | 0 | if (str->len > 0) |
463 | 0 | g_string_set_size(str, str->len - 1); |
464 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
465 | 0 | } |
466 | | static gboolean |
467 | | fu_struct_ifwi_cpd_entry_validate_internal(FuStructIfwiCpdEntry *st, GError **error) |
468 | 36.9k | { |
469 | 36.9k | g_return_val_if_fail(st != NULL, FALSE); |
470 | 36.9k | return TRUE; |
471 | 36.9k | } |
472 | | static gboolean |
473 | | fu_struct_ifwi_cpd_entry_parse_internal(FuStructIfwiCpdEntry *st, GError **error) |
474 | 36.9k | { |
475 | 36.9k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
476 | 0 | g_autofree gchar *str = fu_struct_ifwi_cpd_entry_to_string(st); |
477 | 0 | g_debug("%s", str); |
478 | 0 | } |
479 | 36.9k | if (!fu_struct_ifwi_cpd_entry_validate_internal(st, error)) |
480 | 0 | return FALSE; |
481 | 36.9k | return TRUE; |
482 | 36.9k | } |
483 | | /** |
484 | | * fu_struct_ifwi_cpd_entry_parse_stream: (skip): |
485 | | **/ |
486 | | FuStructIfwiCpdEntry * |
487 | | fu_struct_ifwi_cpd_entry_parse_stream(GInputStream *stream, gsize offset, GError **error) |
488 | 37.2k | { |
489 | 37.2k | g_autoptr(FuStructIfwiCpdEntry) st = fu_struct_ifwi_cpd_entry_new_internal(); |
490 | 37.2k | st->buf = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error); |
491 | 37.2k | if (st->buf == NULL) { |
492 | 177 | g_prefix_error(error, "FuStructIfwiCpdEntry failed read of 0x%x: ", (guint) 24); |
493 | 177 | return NULL; |
494 | 177 | } |
495 | 37.0k | if (st->buf->len != 24) { |
496 | 108 | g_set_error(error, |
497 | 108 | FWUPD_ERROR, |
498 | 108 | FWUPD_ERROR_INVALID_DATA, |
499 | 108 | "FuStructIfwiCpdEntry requested 0x%x and got 0x%x", |
500 | 108 | (guint) 24, |
501 | 108 | (guint) st->buf->len); |
502 | 108 | return NULL; |
503 | 108 | } |
504 | 36.9k | if (!fu_struct_ifwi_cpd_entry_parse_internal(st, error)) |
505 | 0 | return NULL; |
506 | 36.9k | return g_steal_pointer(&st); |
507 | 36.9k | } |
508 | | /** |
509 | | * fu_struct_ifwi_cpd_manifest_ref: (skip): |
510 | | **/ |
511 | | FuStructIfwiCpdManifest * |
512 | | fu_struct_ifwi_cpd_manifest_ref(FuStructIfwiCpdManifest *st) |
513 | 0 | { |
514 | 0 | g_return_val_if_fail(st != NULL, NULL); |
515 | 0 | st->refcount++; |
516 | 0 | return st; |
517 | 0 | } |
518 | | /** |
519 | | * fu_struct_ifwi_cpd_manifest_unref: (skip): |
520 | | **/ |
521 | | void |
522 | | fu_struct_ifwi_cpd_manifest_unref(FuStructIfwiCpdManifest *st) |
523 | 610 | { |
524 | 610 | g_return_if_fail(st != NULL); |
525 | 610 | if (st->refcount == 0) { |
526 | 0 | g_critical("FuStructIfwiCpdManifest refcount already zero"); |
527 | 0 | return; |
528 | 0 | } |
529 | 610 | if (--st->refcount > 0) |
530 | 0 | return; |
531 | 610 | if (st->buf != NULL) |
532 | 610 | g_byte_array_unref(st->buf); |
533 | 610 | g_free(st); |
534 | 610 | } |
535 | | /** |
536 | | * fu_struct_ifwi_cpd_manifest_new_internal: (skip): |
537 | | **/ |
538 | | static FuStructIfwiCpdManifest * |
539 | | fu_struct_ifwi_cpd_manifest_new_internal(void) |
540 | 610 | { |
541 | 610 | FuStructIfwiCpdManifest *st = g_new0(FuStructIfwiCpdManifest, 1); |
542 | 610 | st->refcount = 1; |
543 | 610 | return st; |
544 | 610 | } |
545 | | |
546 | | /* getters */ |
547 | | /** |
548 | | * fu_struct_ifwi_cpd_manifest_get_header_type: (skip): |
549 | | **/ |
550 | | guint32 |
551 | | fu_struct_ifwi_cpd_manifest_get_header_type(const FuStructIfwiCpdManifest *st) |
552 | 0 | { |
553 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
554 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
555 | 0 | } |
556 | | /** |
557 | | * fu_struct_ifwi_cpd_manifest_get_header_length: (skip): |
558 | | **/ |
559 | | guint32 |
560 | | fu_struct_ifwi_cpd_manifest_get_header_length(const FuStructIfwiCpdManifest *st) |
561 | 453 | { |
562 | 453 | g_return_val_if_fail(st != NULL, 0x0); |
563 | 453 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
564 | 453 | } |
565 | | /** |
566 | | * fu_struct_ifwi_cpd_manifest_get_header_version: (skip): |
567 | | **/ |
568 | | guint32 |
569 | | fu_struct_ifwi_cpd_manifest_get_header_version(const FuStructIfwiCpdManifest *st) |
570 | 0 | { |
571 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
572 | 0 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
573 | 0 | } |
574 | | /** |
575 | | * fu_struct_ifwi_cpd_manifest_get_flags: (skip): |
576 | | **/ |
577 | | guint32 |
578 | | fu_struct_ifwi_cpd_manifest_get_flags(const FuStructIfwiCpdManifest *st) |
579 | 0 | { |
580 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
581 | 0 | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
582 | 0 | } |
583 | | /** |
584 | | * fu_struct_ifwi_cpd_manifest_get_vendor: (skip): |
585 | | **/ |
586 | | guint32 |
587 | | fu_struct_ifwi_cpd_manifest_get_vendor(const FuStructIfwiCpdManifest *st) |
588 | 0 | { |
589 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
590 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
591 | 0 | } |
592 | | /** |
593 | | * fu_struct_ifwi_cpd_manifest_get_date: (skip): |
594 | | **/ |
595 | | guint32 |
596 | | fu_struct_ifwi_cpd_manifest_get_date(const FuStructIfwiCpdManifest *st) |
597 | 0 | { |
598 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
599 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
600 | 0 | } |
601 | | /** |
602 | | * fu_struct_ifwi_cpd_manifest_get_size: (skip): |
603 | | **/ |
604 | | guint32 |
605 | | fu_struct_ifwi_cpd_manifest_get_size(const FuStructIfwiCpdManifest *st) |
606 | 610 | { |
607 | 610 | g_return_val_if_fail(st != NULL, 0x0); |
608 | 610 | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
609 | 610 | } |
610 | | /** |
611 | | * fu_struct_ifwi_cpd_manifest_get_id: (skip): |
612 | | **/ |
613 | | guint32 |
614 | | fu_struct_ifwi_cpd_manifest_get_id(const FuStructIfwiCpdManifest *st) |
615 | 0 | { |
616 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
617 | 0 | return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN); |
618 | 0 | } |
619 | | /** |
620 | | * fu_struct_ifwi_cpd_manifest_get_rsvd: (skip): |
621 | | **/ |
622 | | guint32 |
623 | | fu_struct_ifwi_cpd_manifest_get_rsvd(const FuStructIfwiCpdManifest *st) |
624 | 0 | { |
625 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
626 | 0 | return fu_memread_uint32(st->buf->data + 32, G_LITTLE_ENDIAN); |
627 | 0 | } |
628 | | /** |
629 | | * fu_struct_ifwi_cpd_manifest_get_version_major: (skip): |
630 | | **/ |
631 | | guint16 |
632 | | fu_struct_ifwi_cpd_manifest_get_version_major(const FuStructIfwiCpdManifest *st) |
633 | 610 | { |
634 | 610 | g_return_val_if_fail(st != NULL, 0x0); |
635 | 610 | return fu_memread_uint16(st->buf->data + 36, G_LITTLE_ENDIAN); |
636 | 610 | } |
637 | | /** |
638 | | * fu_struct_ifwi_cpd_manifest_get_version_minor: (skip): |
639 | | **/ |
640 | | guint16 |
641 | | fu_struct_ifwi_cpd_manifest_get_version_minor(const FuStructIfwiCpdManifest *st) |
642 | 610 | { |
643 | 610 | g_return_val_if_fail(st != NULL, 0x0); |
644 | 610 | return fu_memread_uint16(st->buf->data + 38, G_LITTLE_ENDIAN); |
645 | 610 | } |
646 | | /** |
647 | | * fu_struct_ifwi_cpd_manifest_get_version_hotfix: (skip): |
648 | | **/ |
649 | | guint16 |
650 | | fu_struct_ifwi_cpd_manifest_get_version_hotfix(const FuStructIfwiCpdManifest *st) |
651 | 610 | { |
652 | 610 | g_return_val_if_fail(st != NULL, 0x0); |
653 | 610 | return fu_memread_uint16(st->buf->data + 40, G_LITTLE_ENDIAN); |
654 | 610 | } |
655 | | /** |
656 | | * fu_struct_ifwi_cpd_manifest_get_version_build: (skip): |
657 | | **/ |
658 | | guint16 |
659 | | fu_struct_ifwi_cpd_manifest_get_version_build(const FuStructIfwiCpdManifest *st) |
660 | 610 | { |
661 | 610 | g_return_val_if_fail(st != NULL, 0x0); |
662 | 610 | return fu_memread_uint16(st->buf->data + 42, G_LITTLE_ENDIAN); |
663 | 610 | } |
664 | | /** |
665 | | * fu_struct_ifwi_cpd_manifest_get_svn: (skip): |
666 | | **/ |
667 | | guint32 |
668 | | fu_struct_ifwi_cpd_manifest_get_svn(const FuStructIfwiCpdManifest *st) |
669 | 0 | { |
670 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
671 | 0 | return fu_memread_uint32(st->buf->data + 44, G_LITTLE_ENDIAN); |
672 | 0 | } |
673 | | |
674 | | /* setters */ |
675 | | /** |
676 | | * fu_struct_ifwi_cpd_manifest_set_header_type: (skip): |
677 | | **/ |
678 | | void |
679 | | fu_struct_ifwi_cpd_manifest_set_header_type(FuStructIfwiCpdManifest *st, guint32 value) |
680 | 0 | { |
681 | 0 | g_return_if_fail(st != NULL); |
682 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
683 | 0 | } |
684 | | /** |
685 | | * fu_struct_ifwi_cpd_manifest_set_header_length: (skip): |
686 | | **/ |
687 | | void |
688 | | fu_struct_ifwi_cpd_manifest_set_header_length(FuStructIfwiCpdManifest *st, guint32 value) |
689 | 0 | { |
690 | 0 | g_return_if_fail(st != NULL); |
691 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
692 | 0 | } |
693 | | /** |
694 | | * fu_struct_ifwi_cpd_manifest_set_header_version: (skip): |
695 | | **/ |
696 | | void |
697 | | fu_struct_ifwi_cpd_manifest_set_header_version(FuStructIfwiCpdManifest *st, guint32 value) |
698 | 0 | { |
699 | 0 | g_return_if_fail(st != NULL); |
700 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
701 | 0 | } |
702 | | /** |
703 | | * fu_struct_ifwi_cpd_manifest_set_flags: (skip): |
704 | | **/ |
705 | | void |
706 | | fu_struct_ifwi_cpd_manifest_set_flags(FuStructIfwiCpdManifest *st, guint32 value) |
707 | 0 | { |
708 | 0 | g_return_if_fail(st != NULL); |
709 | 0 | fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
710 | 0 | } |
711 | | /** |
712 | | * fu_struct_ifwi_cpd_manifest_set_vendor: (skip): |
713 | | **/ |
714 | | void |
715 | | fu_struct_ifwi_cpd_manifest_set_vendor(FuStructIfwiCpdManifest *st, guint32 value) |
716 | 0 | { |
717 | 0 | g_return_if_fail(st != NULL); |
718 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
719 | 0 | } |
720 | | /** |
721 | | * fu_struct_ifwi_cpd_manifest_set_date: (skip): |
722 | | **/ |
723 | | void |
724 | | fu_struct_ifwi_cpd_manifest_set_date(FuStructIfwiCpdManifest *st, guint32 value) |
725 | 0 | { |
726 | 0 | g_return_if_fail(st != NULL); |
727 | 0 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
728 | 0 | } |
729 | | /** |
730 | | * fu_struct_ifwi_cpd_manifest_set_size: (skip): |
731 | | **/ |
732 | | void |
733 | | fu_struct_ifwi_cpd_manifest_set_size(FuStructIfwiCpdManifest *st, guint32 value) |
734 | 0 | { |
735 | 0 | g_return_if_fail(st != NULL); |
736 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
737 | 0 | } |
738 | | /** |
739 | | * fu_struct_ifwi_cpd_manifest_set_id: (skip): |
740 | | **/ |
741 | | void |
742 | | fu_struct_ifwi_cpd_manifest_set_id(FuStructIfwiCpdManifest *st, guint32 value) |
743 | 0 | { |
744 | 0 | g_return_if_fail(st != NULL); |
745 | 0 | fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
746 | 0 | } |
747 | | /** |
748 | | * fu_struct_ifwi_cpd_manifest_set_rsvd: (skip): |
749 | | **/ |
750 | | void |
751 | | fu_struct_ifwi_cpd_manifest_set_rsvd(FuStructIfwiCpdManifest *st, guint32 value) |
752 | 0 | { |
753 | 0 | g_return_if_fail(st != NULL); |
754 | 0 | fu_memwrite_uint32(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
755 | 0 | } |
756 | | /** |
757 | | * fu_struct_ifwi_cpd_manifest_set_version_major: (skip): |
758 | | **/ |
759 | | void |
760 | | fu_struct_ifwi_cpd_manifest_set_version_major(FuStructIfwiCpdManifest *st, guint16 value) |
761 | 0 | { |
762 | 0 | g_return_if_fail(st != NULL); |
763 | 0 | fu_memwrite_uint16(st->buf->data + 36, value, G_LITTLE_ENDIAN); |
764 | 0 | } |
765 | | /** |
766 | | * fu_struct_ifwi_cpd_manifest_set_version_minor: (skip): |
767 | | **/ |
768 | | void |
769 | | fu_struct_ifwi_cpd_manifest_set_version_minor(FuStructIfwiCpdManifest *st, guint16 value) |
770 | 0 | { |
771 | 0 | g_return_if_fail(st != NULL); |
772 | 0 | fu_memwrite_uint16(st->buf->data + 38, value, G_LITTLE_ENDIAN); |
773 | 0 | } |
774 | | /** |
775 | | * fu_struct_ifwi_cpd_manifest_set_version_hotfix: (skip): |
776 | | **/ |
777 | | void |
778 | | fu_struct_ifwi_cpd_manifest_set_version_hotfix(FuStructIfwiCpdManifest *st, guint16 value) |
779 | 0 | { |
780 | 0 | g_return_if_fail(st != NULL); |
781 | 0 | fu_memwrite_uint16(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
782 | 0 | } |
783 | | /** |
784 | | * fu_struct_ifwi_cpd_manifest_set_version_build: (skip): |
785 | | **/ |
786 | | void |
787 | | fu_struct_ifwi_cpd_manifest_set_version_build(FuStructIfwiCpdManifest *st, guint16 value) |
788 | 0 | { |
789 | 0 | g_return_if_fail(st != NULL); |
790 | 0 | fu_memwrite_uint16(st->buf->data + 42, value, G_LITTLE_ENDIAN); |
791 | 0 | } |
792 | | /** |
793 | | * fu_struct_ifwi_cpd_manifest_set_svn: (skip): |
794 | | **/ |
795 | | void |
796 | | fu_struct_ifwi_cpd_manifest_set_svn(FuStructIfwiCpdManifest *st, guint32 value) |
797 | 0 | { |
798 | 0 | g_return_if_fail(st != NULL); |
799 | 0 | fu_memwrite_uint32(st->buf->data + 44, value, G_LITTLE_ENDIAN); |
800 | 0 | } |
801 | | /** |
802 | | * fu_struct_ifwi_cpd_manifest_new: (skip): |
803 | | **/ |
804 | | FuStructIfwiCpdManifest * |
805 | | fu_struct_ifwi_cpd_manifest_new(void) |
806 | 0 | { |
807 | 0 | FuStructIfwiCpdManifest *st = fu_struct_ifwi_cpd_manifest_new_internal(); |
808 | 0 | st->buf = g_byte_array_sized_new(48); |
809 | 0 | fu_byte_array_set_size(st->buf, 48, 0x0); |
810 | 0 | return st; |
811 | 0 | } |
812 | | /** |
813 | | * fu_struct_ifwi_cpd_manifest_to_string: (skip): |
814 | | **/ |
815 | | static gchar * |
816 | | fu_struct_ifwi_cpd_manifest_to_string(const FuStructIfwiCpdManifest *st) |
817 | 0 | { |
818 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiCpdManifest:\n"); |
819 | 0 | g_return_val_if_fail(st != NULL, NULL); |
820 | 0 | g_string_append_printf(str, " header_type: 0x%x\n", |
821 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_header_type(st)); |
822 | 0 | g_string_append_printf(str, " header_length: 0x%x\n", |
823 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_header_length(st)); |
824 | 0 | g_string_append_printf(str, " header_version: 0x%x\n", |
825 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_header_version(st)); |
826 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
827 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_flags(st)); |
828 | 0 | g_string_append_printf(str, " vendor: 0x%x\n", |
829 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_vendor(st)); |
830 | 0 | g_string_append_printf(str, " date: 0x%x\n", |
831 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_date(st)); |
832 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
833 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_size(st)); |
834 | 0 | g_string_append_printf(str, " id: 0x%x\n", |
835 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_id(st)); |
836 | 0 | g_string_append_printf(str, " rsvd: 0x%x\n", |
837 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_rsvd(st)); |
838 | 0 | g_string_append_printf(str, " version_major: 0x%x\n", |
839 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_version_major(st)); |
840 | 0 | g_string_append_printf(str, " version_minor: 0x%x\n", |
841 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_version_minor(st)); |
842 | 0 | g_string_append_printf(str, " version_hotfix: 0x%x\n", |
843 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_version_hotfix(st)); |
844 | 0 | g_string_append_printf(str, " version_build: 0x%x\n", |
845 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_version_build(st)); |
846 | 0 | g_string_append_printf(str, " svn: 0x%x\n", |
847 | 0 | (guint) fu_struct_ifwi_cpd_manifest_get_svn(st)); |
848 | 0 | if (str->len > 0) |
849 | 0 | g_string_set_size(str, str->len - 1); |
850 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
851 | 0 | } |
852 | | static gboolean |
853 | | fu_struct_ifwi_cpd_manifest_validate_internal(FuStructIfwiCpdManifest *st, GError **error) |
854 | 610 | { |
855 | 610 | g_return_val_if_fail(st != NULL, FALSE); |
856 | 610 | return TRUE; |
857 | 610 | } |
858 | | static gboolean |
859 | | fu_struct_ifwi_cpd_manifest_parse_internal(FuStructIfwiCpdManifest *st, GError **error) |
860 | 610 | { |
861 | 610 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
862 | 0 | g_autofree gchar *str = fu_struct_ifwi_cpd_manifest_to_string(st); |
863 | 0 | g_debug("%s", str); |
864 | 0 | } |
865 | 610 | if (!fu_struct_ifwi_cpd_manifest_validate_internal(st, error)) |
866 | 0 | return FALSE; |
867 | 610 | return TRUE; |
868 | 610 | } |
869 | | /** |
870 | | * fu_struct_ifwi_cpd_manifest_parse_stream: (skip): |
871 | | **/ |
872 | | FuStructIfwiCpdManifest * |
873 | | fu_struct_ifwi_cpd_manifest_parse_stream(GInputStream *stream, gsize offset, GError **error) |
874 | 610 | { |
875 | 610 | g_autoptr(FuStructIfwiCpdManifest) st = fu_struct_ifwi_cpd_manifest_new_internal(); |
876 | 610 | st->buf = fu_input_stream_read_byte_array(stream, offset, 48, NULL, error); |
877 | 610 | if (st->buf == NULL) { |
878 | 0 | g_prefix_error(error, "FuStructIfwiCpdManifest failed read of 0x%x: ", (guint) 48); |
879 | 0 | return NULL; |
880 | 0 | } |
881 | 610 | if (st->buf->len != 48) { |
882 | 0 | g_set_error(error, |
883 | 0 | FWUPD_ERROR, |
884 | 0 | FWUPD_ERROR_INVALID_DATA, |
885 | 0 | "FuStructIfwiCpdManifest requested 0x%x and got 0x%x", |
886 | 0 | (guint) 48, |
887 | 0 | (guint) st->buf->len); |
888 | 0 | return NULL; |
889 | 0 | } |
890 | 610 | if (!fu_struct_ifwi_cpd_manifest_parse_internal(st, error)) |
891 | 0 | return NULL; |
892 | 610 | return g_steal_pointer(&st); |
893 | 610 | } |
894 | | /** |
895 | | * fu_struct_ifwi_cpd_manifest_ext_ref: (skip): |
896 | | **/ |
897 | | FuStructIfwiCpdManifestExt * |
898 | | fu_struct_ifwi_cpd_manifest_ext_ref(FuStructIfwiCpdManifestExt *st) |
899 | 0 | { |
900 | 0 | g_return_val_if_fail(st != NULL, NULL); |
901 | 0 | st->refcount++; |
902 | 0 | return st; |
903 | 0 | } |
904 | | /** |
905 | | * fu_struct_ifwi_cpd_manifest_ext_unref: (skip): |
906 | | **/ |
907 | | void |
908 | | fu_struct_ifwi_cpd_manifest_ext_unref(FuStructIfwiCpdManifestExt *st) |
909 | 1.11k | { |
910 | 1.11k | g_return_if_fail(st != NULL); |
911 | 1.11k | if (st->refcount == 0) { |
912 | 0 | g_critical("FuStructIfwiCpdManifestExt refcount already zero"); |
913 | 0 | return; |
914 | 0 | } |
915 | 1.11k | if (--st->refcount > 0) |
916 | 0 | return; |
917 | 1.11k | if (st->buf != NULL) |
918 | 1.11k | g_byte_array_unref(st->buf); |
919 | 1.11k | g_free(st); |
920 | 1.11k | } |
921 | | /** |
922 | | * fu_struct_ifwi_cpd_manifest_ext_new_internal: (skip): |
923 | | **/ |
924 | | static FuStructIfwiCpdManifestExt * |
925 | | fu_struct_ifwi_cpd_manifest_ext_new_internal(void) |
926 | 1.11k | { |
927 | 1.11k | FuStructIfwiCpdManifestExt *st = g_new0(FuStructIfwiCpdManifestExt, 1); |
928 | 1.11k | st->refcount = 1; |
929 | 1.11k | return st; |
930 | 1.11k | } |
931 | | |
932 | | /* getters */ |
933 | | /** |
934 | | * fu_struct_ifwi_cpd_manifest_ext_get_extension_type: (skip): |
935 | | **/ |
936 | | guint32 |
937 | | fu_struct_ifwi_cpd_manifest_ext_get_extension_type(const FuStructIfwiCpdManifestExt *st) |
938 | 1.10k | { |
939 | 1.10k | g_return_val_if_fail(st != NULL, 0x0); |
940 | 1.10k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
941 | 1.10k | } |
942 | | /** |
943 | | * fu_struct_ifwi_cpd_manifest_ext_get_extension_length: (skip): |
944 | | **/ |
945 | | guint32 |
946 | | fu_struct_ifwi_cpd_manifest_ext_get_extension_length(const FuStructIfwiCpdManifestExt *st) |
947 | 1.03k | { |
948 | 1.03k | g_return_val_if_fail(st != NULL, 0x0); |
949 | 1.03k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
950 | 1.03k | } |
951 | | |
952 | | /* setters */ |
953 | | /** |
954 | | * fu_struct_ifwi_cpd_manifest_ext_set_extension_type: (skip): |
955 | | **/ |
956 | | void |
957 | | fu_struct_ifwi_cpd_manifest_ext_set_extension_type(FuStructIfwiCpdManifestExt *st, guint32 value) |
958 | 0 | { |
959 | 0 | g_return_if_fail(st != NULL); |
960 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
961 | 0 | } |
962 | | /** |
963 | | * fu_struct_ifwi_cpd_manifest_ext_set_extension_length: (skip): |
964 | | **/ |
965 | | void |
966 | | fu_struct_ifwi_cpd_manifest_ext_set_extension_length(FuStructIfwiCpdManifestExt *st, guint32 value) |
967 | 0 | { |
968 | 0 | g_return_if_fail(st != NULL); |
969 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
970 | 0 | } |
971 | | /** |
972 | | * fu_struct_ifwi_cpd_manifest_ext_new: (skip): |
973 | | **/ |
974 | | FuStructIfwiCpdManifestExt * |
975 | | fu_struct_ifwi_cpd_manifest_ext_new(void) |
976 | 0 | { |
977 | 0 | FuStructIfwiCpdManifestExt *st = fu_struct_ifwi_cpd_manifest_ext_new_internal(); |
978 | 0 | st->buf = g_byte_array_sized_new(8); |
979 | 0 | fu_byte_array_set_size(st->buf, 8, 0x0); |
980 | 0 | return st; |
981 | 0 | } |
982 | | /** |
983 | | * fu_struct_ifwi_cpd_manifest_ext_to_string: (skip): |
984 | | **/ |
985 | | static gchar * |
986 | | fu_struct_ifwi_cpd_manifest_ext_to_string(const FuStructIfwiCpdManifestExt *st) |
987 | 0 | { |
988 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiCpdManifestExt:\n"); |
989 | 0 | g_return_val_if_fail(st != NULL, NULL); |
990 | 0 | g_string_append_printf(str, " extension_type: 0x%x\n", |
991 | 0 | (guint) fu_struct_ifwi_cpd_manifest_ext_get_extension_type(st)); |
992 | 0 | g_string_append_printf(str, " extension_length: 0x%x\n", |
993 | 0 | (guint) fu_struct_ifwi_cpd_manifest_ext_get_extension_length(st)); |
994 | 0 | if (str->len > 0) |
995 | 0 | g_string_set_size(str, str->len - 1); |
996 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
997 | 0 | } |
998 | | static gboolean |
999 | | fu_struct_ifwi_cpd_manifest_ext_validate_internal(FuStructIfwiCpdManifestExt *st, GError **error) |
1000 | 1.10k | { |
1001 | 1.10k | g_return_val_if_fail(st != NULL, FALSE); |
1002 | 1.10k | return TRUE; |
1003 | 1.10k | } |
1004 | | static gboolean |
1005 | | fu_struct_ifwi_cpd_manifest_ext_parse_internal(FuStructIfwiCpdManifestExt *st, GError **error) |
1006 | 1.10k | { |
1007 | 1.10k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1008 | 0 | g_autofree gchar *str = fu_struct_ifwi_cpd_manifest_ext_to_string(st); |
1009 | 0 | g_debug("%s", str); |
1010 | 0 | } |
1011 | 1.10k | if (!fu_struct_ifwi_cpd_manifest_ext_validate_internal(st, error)) |
1012 | 0 | return FALSE; |
1013 | 1.10k | return TRUE; |
1014 | 1.10k | } |
1015 | | /** |
1016 | | * fu_struct_ifwi_cpd_manifest_ext_parse_stream: (skip): |
1017 | | **/ |
1018 | | FuStructIfwiCpdManifestExt * |
1019 | | fu_struct_ifwi_cpd_manifest_ext_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1020 | 1.11k | { |
1021 | 1.11k | g_autoptr(FuStructIfwiCpdManifestExt) st = fu_struct_ifwi_cpd_manifest_ext_new_internal(); |
1022 | 1.11k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1023 | 1.11k | if (st->buf == NULL) { |
1024 | 0 | g_prefix_error(error, "FuStructIfwiCpdManifestExt failed read of 0x%x: ", (guint) 8); |
1025 | 0 | return NULL; |
1026 | 0 | } |
1027 | 1.11k | if (st->buf->len != 8) { |
1028 | 13 | g_set_error(error, |
1029 | 13 | FWUPD_ERROR, |
1030 | 13 | FWUPD_ERROR_INVALID_DATA, |
1031 | 13 | "FuStructIfwiCpdManifestExt requested 0x%x and got 0x%x", |
1032 | 13 | (guint) 8, |
1033 | 13 | (guint) st->buf->len); |
1034 | 13 | return NULL; |
1035 | 13 | } |
1036 | 1.10k | if (!fu_struct_ifwi_cpd_manifest_ext_parse_internal(st, error)) |
1037 | 0 | return NULL; |
1038 | 1.10k | return g_steal_pointer(&st); |
1039 | 1.10k | } |
1040 | | /** |
1041 | | * fu_struct_ifwi_fpt_ref: (skip): |
1042 | | **/ |
1043 | | FuStructIfwiFpt * |
1044 | | fu_struct_ifwi_fpt_ref(FuStructIfwiFpt *st) |
1045 | 0 | { |
1046 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1047 | 0 | st->refcount++; |
1048 | 0 | return st; |
1049 | 0 | } |
1050 | | /** |
1051 | | * fu_struct_ifwi_fpt_unref: (skip): |
1052 | | **/ |
1053 | | void |
1054 | | fu_struct_ifwi_fpt_unref(FuStructIfwiFpt *st) |
1055 | 904 | { |
1056 | 904 | g_return_if_fail(st != NULL); |
1057 | 904 | if (st->refcount == 0) { |
1058 | 0 | g_critical("FuStructIfwiFpt refcount already zero"); |
1059 | 0 | return; |
1060 | 0 | } |
1061 | 904 | if (--st->refcount > 0) |
1062 | 0 | return; |
1063 | 904 | if (st->buf != NULL) |
1064 | 903 | g_byte_array_unref(st->buf); |
1065 | 904 | g_free(st); |
1066 | 904 | } |
1067 | | /** |
1068 | | * fu_struct_ifwi_fpt_new_internal: (skip): |
1069 | | **/ |
1070 | | static FuStructIfwiFpt * |
1071 | | fu_struct_ifwi_fpt_new_internal(void) |
1072 | 904 | { |
1073 | 904 | FuStructIfwiFpt *st = g_new0(FuStructIfwiFpt, 1); |
1074 | 904 | st->refcount = 1; |
1075 | 904 | return st; |
1076 | 904 | } |
1077 | | |
1078 | | /* getters */ |
1079 | | /** |
1080 | | * fu_struct_ifwi_fpt_get_header_marker: (skip): |
1081 | | **/ |
1082 | | static guint32 |
1083 | | fu_struct_ifwi_fpt_get_header_marker(const FuStructIfwiFpt *st) |
1084 | 899 | { |
1085 | 899 | g_return_val_if_fail(st != NULL, 0x0); |
1086 | 899 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
1087 | 899 | } |
1088 | | /** |
1089 | | * fu_struct_ifwi_fpt_get_num_of_entries: (skip): |
1090 | | **/ |
1091 | | guint32 |
1092 | | fu_struct_ifwi_fpt_get_num_of_entries(const FuStructIfwiFpt *st) |
1093 | 391 | { |
1094 | 391 | g_return_val_if_fail(st != NULL, 0x0); |
1095 | 391 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1096 | 391 | } |
1097 | | /** |
1098 | | * fu_struct_ifwi_fpt_get_header_version: (skip): |
1099 | | **/ |
1100 | | guint8 |
1101 | | fu_struct_ifwi_fpt_get_header_version(const FuStructIfwiFpt *st) |
1102 | 360 | { |
1103 | 360 | g_return_val_if_fail(st != NULL, 0x0); |
1104 | 360 | return st->buf->data[8]; |
1105 | 360 | } |
1106 | | /** |
1107 | | * fu_struct_ifwi_fpt_get_entry_version: (skip): |
1108 | | **/ |
1109 | | static guint8 |
1110 | | fu_struct_ifwi_fpt_get_entry_version(const FuStructIfwiFpt *st) |
1111 | 791 | { |
1112 | 791 | g_return_val_if_fail(st != NULL, 0x0); |
1113 | 791 | return st->buf->data[9]; |
1114 | 791 | } |
1115 | | /** |
1116 | | * fu_struct_ifwi_fpt_get_header_length: (skip): |
1117 | | **/ |
1118 | | guint8 |
1119 | | fu_struct_ifwi_fpt_get_header_length(const FuStructIfwiFpt *st) |
1120 | 350 | { |
1121 | 350 | g_return_val_if_fail(st != NULL, 0x0); |
1122 | 350 | return st->buf->data[10]; |
1123 | 350 | } |
1124 | | /** |
1125 | | * fu_struct_ifwi_fpt_get_flags: (skip): |
1126 | | **/ |
1127 | | guint8 |
1128 | | fu_struct_ifwi_fpt_get_flags(const FuStructIfwiFpt *st) |
1129 | 0 | { |
1130 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1131 | 0 | return st->buf->data[11]; |
1132 | 0 | } |
1133 | | /** |
1134 | | * fu_struct_ifwi_fpt_get_ticks_to_add: (skip): |
1135 | | **/ |
1136 | | guint16 |
1137 | | fu_struct_ifwi_fpt_get_ticks_to_add(const FuStructIfwiFpt *st) |
1138 | 0 | { |
1139 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1140 | 0 | return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN); |
1141 | 0 | } |
1142 | | /** |
1143 | | * fu_struct_ifwi_fpt_get_tokens_to_add: (skip): |
1144 | | **/ |
1145 | | guint16 |
1146 | | fu_struct_ifwi_fpt_get_tokens_to_add(const FuStructIfwiFpt *st) |
1147 | 0 | { |
1148 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1149 | 0 | return fu_memread_uint16(st->buf->data + 14, G_LITTLE_ENDIAN); |
1150 | 0 | } |
1151 | | /** |
1152 | | * fu_struct_ifwi_fpt_get_uma_size: (skip): |
1153 | | **/ |
1154 | | guint32 |
1155 | | fu_struct_ifwi_fpt_get_uma_size(const FuStructIfwiFpt *st) |
1156 | 0 | { |
1157 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1158 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
1159 | 0 | } |
1160 | | /** |
1161 | | * fu_struct_ifwi_fpt_get_crc32: (skip): |
1162 | | **/ |
1163 | | guint32 |
1164 | | fu_struct_ifwi_fpt_get_crc32(const FuStructIfwiFpt *st) |
1165 | 0 | { |
1166 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1167 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
1168 | 0 | } |
1169 | | /** |
1170 | | * fu_struct_ifwi_fpt_get_fitc_major: (skip): |
1171 | | **/ |
1172 | | guint16 |
1173 | | fu_struct_ifwi_fpt_get_fitc_major(const FuStructIfwiFpt *st) |
1174 | 0 | { |
1175 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1176 | 0 | return fu_memread_uint16(st->buf->data + 24, G_LITTLE_ENDIAN); |
1177 | 0 | } |
1178 | | /** |
1179 | | * fu_struct_ifwi_fpt_get_fitc_minor: (skip): |
1180 | | **/ |
1181 | | guint16 |
1182 | | fu_struct_ifwi_fpt_get_fitc_minor(const FuStructIfwiFpt *st) |
1183 | 0 | { |
1184 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1185 | 0 | return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN); |
1186 | 0 | } |
1187 | | /** |
1188 | | * fu_struct_ifwi_fpt_get_fitc_hotfix: (skip): |
1189 | | **/ |
1190 | | guint16 |
1191 | | fu_struct_ifwi_fpt_get_fitc_hotfix(const FuStructIfwiFpt *st) |
1192 | 0 | { |
1193 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1194 | 0 | return fu_memread_uint16(st->buf->data + 28, G_LITTLE_ENDIAN); |
1195 | 0 | } |
1196 | | /** |
1197 | | * fu_struct_ifwi_fpt_get_fitc_build: (skip): |
1198 | | **/ |
1199 | | guint16 |
1200 | | fu_struct_ifwi_fpt_get_fitc_build(const FuStructIfwiFpt *st) |
1201 | 0 | { |
1202 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1203 | 0 | return fu_memread_uint16(st->buf->data + 30, G_LITTLE_ENDIAN); |
1204 | 0 | } |
1205 | | |
1206 | | /* setters */ |
1207 | | /** |
1208 | | * fu_struct_ifwi_fpt_set_header_marker: (skip): |
1209 | | **/ |
1210 | | static void |
1211 | | fu_struct_ifwi_fpt_set_header_marker(FuStructIfwiFpt *st, guint32 value) |
1212 | 43 | { |
1213 | 43 | g_return_if_fail(st != NULL); |
1214 | 43 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
1215 | 43 | } |
1216 | | /** |
1217 | | * fu_struct_ifwi_fpt_set_num_of_entries: (skip): |
1218 | | **/ |
1219 | | void |
1220 | | fu_struct_ifwi_fpt_set_num_of_entries(FuStructIfwiFpt *st, guint32 value) |
1221 | 1 | { |
1222 | 1 | g_return_if_fail(st != NULL); |
1223 | 1 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
1224 | 1 | } |
1225 | | /** |
1226 | | * fu_struct_ifwi_fpt_set_header_version: (skip): |
1227 | | **/ |
1228 | | void |
1229 | | fu_struct_ifwi_fpt_set_header_version(FuStructIfwiFpt *st, guint8 value) |
1230 | 43 | { |
1231 | 43 | g_return_if_fail(st != NULL); |
1232 | 43 | st->buf->data[8] = value; |
1233 | 43 | } |
1234 | | /** |
1235 | | * fu_struct_ifwi_fpt_set_entry_version: (skip): |
1236 | | **/ |
1237 | | static void |
1238 | | fu_struct_ifwi_fpt_set_entry_version(FuStructIfwiFpt *st, guint8 value) |
1239 | 43 | { |
1240 | 43 | g_return_if_fail(st != NULL); |
1241 | 43 | st->buf->data[9] = value; |
1242 | 43 | } |
1243 | | /** |
1244 | | * fu_struct_ifwi_fpt_set_header_length: (skip): |
1245 | | **/ |
1246 | | void |
1247 | | fu_struct_ifwi_fpt_set_header_length(FuStructIfwiFpt *st, guint8 value) |
1248 | 43 | { |
1249 | 43 | g_return_if_fail(st != NULL); |
1250 | 43 | st->buf->data[10] = value; |
1251 | 43 | } |
1252 | | /** |
1253 | | * fu_struct_ifwi_fpt_set_flags: (skip): |
1254 | | **/ |
1255 | | void |
1256 | | fu_struct_ifwi_fpt_set_flags(FuStructIfwiFpt *st, guint8 value) |
1257 | 0 | { |
1258 | 0 | g_return_if_fail(st != NULL); |
1259 | 0 | st->buf->data[11] = value; |
1260 | 0 | } |
1261 | | /** |
1262 | | * fu_struct_ifwi_fpt_set_ticks_to_add: (skip): |
1263 | | **/ |
1264 | | void |
1265 | | fu_struct_ifwi_fpt_set_ticks_to_add(FuStructIfwiFpt *st, guint16 value) |
1266 | 0 | { |
1267 | 0 | g_return_if_fail(st != NULL); |
1268 | 0 | fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
1269 | 0 | } |
1270 | | /** |
1271 | | * fu_struct_ifwi_fpt_set_tokens_to_add: (skip): |
1272 | | **/ |
1273 | | void |
1274 | | fu_struct_ifwi_fpt_set_tokens_to_add(FuStructIfwiFpt *st, guint16 value) |
1275 | 0 | { |
1276 | 0 | g_return_if_fail(st != NULL); |
1277 | 0 | fu_memwrite_uint16(st->buf->data + 14, value, G_LITTLE_ENDIAN); |
1278 | 0 | } |
1279 | | /** |
1280 | | * fu_struct_ifwi_fpt_set_uma_size: (skip): |
1281 | | **/ |
1282 | | void |
1283 | | fu_struct_ifwi_fpt_set_uma_size(FuStructIfwiFpt *st, guint32 value) |
1284 | 0 | { |
1285 | 0 | g_return_if_fail(st != NULL); |
1286 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
1287 | 0 | } |
1288 | | /** |
1289 | | * fu_struct_ifwi_fpt_set_crc32: (skip): |
1290 | | **/ |
1291 | | void |
1292 | | fu_struct_ifwi_fpt_set_crc32(FuStructIfwiFpt *st, guint32 value) |
1293 | 0 | { |
1294 | 0 | g_return_if_fail(st != NULL); |
1295 | 0 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
1296 | 0 | } |
1297 | | /** |
1298 | | * fu_struct_ifwi_fpt_set_fitc_major: (skip): |
1299 | | **/ |
1300 | | void |
1301 | | fu_struct_ifwi_fpt_set_fitc_major(FuStructIfwiFpt *st, guint16 value) |
1302 | 0 | { |
1303 | 0 | g_return_if_fail(st != NULL); |
1304 | 0 | fu_memwrite_uint16(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
1305 | 0 | } |
1306 | | /** |
1307 | | * fu_struct_ifwi_fpt_set_fitc_minor: (skip): |
1308 | | **/ |
1309 | | void |
1310 | | fu_struct_ifwi_fpt_set_fitc_minor(FuStructIfwiFpt *st, guint16 value) |
1311 | 0 | { |
1312 | 0 | g_return_if_fail(st != NULL); |
1313 | 0 | fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN); |
1314 | 0 | } |
1315 | | /** |
1316 | | * fu_struct_ifwi_fpt_set_fitc_hotfix: (skip): |
1317 | | **/ |
1318 | | void |
1319 | | fu_struct_ifwi_fpt_set_fitc_hotfix(FuStructIfwiFpt *st, guint16 value) |
1320 | 0 | { |
1321 | 0 | g_return_if_fail(st != NULL); |
1322 | 0 | fu_memwrite_uint16(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
1323 | 0 | } |
1324 | | /** |
1325 | | * fu_struct_ifwi_fpt_set_fitc_build: (skip): |
1326 | | **/ |
1327 | | void |
1328 | | fu_struct_ifwi_fpt_set_fitc_build(FuStructIfwiFpt *st, guint16 value) |
1329 | 0 | { |
1330 | 0 | g_return_if_fail(st != NULL); |
1331 | 0 | fu_memwrite_uint16(st->buf->data + 30, value, G_LITTLE_ENDIAN); |
1332 | 0 | } |
1333 | | /** |
1334 | | * fu_struct_ifwi_fpt_new: (skip): |
1335 | | **/ |
1336 | | FuStructIfwiFpt * |
1337 | | fu_struct_ifwi_fpt_new(void) |
1338 | 43 | { |
1339 | 43 | FuStructIfwiFpt *st = fu_struct_ifwi_fpt_new_internal(); |
1340 | 43 | st->buf = g_byte_array_sized_new(32); |
1341 | 43 | fu_byte_array_set_size(st->buf, 32, 0x0); |
1342 | 43 | fu_struct_ifwi_fpt_set_header_marker(st, 0x54504624); |
1343 | 43 | fu_struct_ifwi_fpt_set_header_version(st, 0x20); |
1344 | 43 | fu_struct_ifwi_fpt_set_entry_version(st, 0x10); |
1345 | 43 | fu_struct_ifwi_fpt_set_header_length(st, 32); |
1346 | 43 | return st; |
1347 | 43 | } |
1348 | | /** |
1349 | | * fu_struct_ifwi_fpt_to_string: (skip): |
1350 | | **/ |
1351 | | static gchar * |
1352 | | fu_struct_ifwi_fpt_to_string(const FuStructIfwiFpt *st) |
1353 | 0 | { |
1354 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiFpt:\n"); |
1355 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1356 | 0 | g_string_append_printf(str, " header_marker: 0x%x\n", |
1357 | 0 | (guint) fu_struct_ifwi_fpt_get_header_marker(st)); |
1358 | 0 | g_string_append_printf(str, " num_of_entries: 0x%x\n", |
1359 | 0 | (guint) fu_struct_ifwi_fpt_get_num_of_entries(st)); |
1360 | 0 | g_string_append_printf(str, " header_version: 0x%x\n", |
1361 | 0 | (guint) fu_struct_ifwi_fpt_get_header_version(st)); |
1362 | 0 | g_string_append_printf(str, " entry_version: 0x%x\n", |
1363 | 0 | (guint) fu_struct_ifwi_fpt_get_entry_version(st)); |
1364 | 0 | g_string_append_printf(str, " header_length: 0x%x\n", |
1365 | 0 | (guint) fu_struct_ifwi_fpt_get_header_length(st)); |
1366 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
1367 | 0 | (guint) fu_struct_ifwi_fpt_get_flags(st)); |
1368 | 0 | g_string_append_printf(str, " ticks_to_add: 0x%x\n", |
1369 | 0 | (guint) fu_struct_ifwi_fpt_get_ticks_to_add(st)); |
1370 | 0 | g_string_append_printf(str, " tokens_to_add: 0x%x\n", |
1371 | 0 | (guint) fu_struct_ifwi_fpt_get_tokens_to_add(st)); |
1372 | 0 | g_string_append_printf(str, " uma_size: 0x%x\n", |
1373 | 0 | (guint) fu_struct_ifwi_fpt_get_uma_size(st)); |
1374 | 0 | g_string_append_printf(str, " crc32: 0x%x\n", |
1375 | 0 | (guint) fu_struct_ifwi_fpt_get_crc32(st)); |
1376 | 0 | g_string_append_printf(str, " fitc_major: 0x%x\n", |
1377 | 0 | (guint) fu_struct_ifwi_fpt_get_fitc_major(st)); |
1378 | 0 | g_string_append_printf(str, " fitc_minor: 0x%x\n", |
1379 | 0 | (guint) fu_struct_ifwi_fpt_get_fitc_minor(st)); |
1380 | 0 | g_string_append_printf(str, " fitc_hotfix: 0x%x\n", |
1381 | 0 | (guint) fu_struct_ifwi_fpt_get_fitc_hotfix(st)); |
1382 | 0 | g_string_append_printf(str, " fitc_build: 0x%x\n", |
1383 | 0 | (guint) fu_struct_ifwi_fpt_get_fitc_build(st)); |
1384 | 0 | if (str->len > 0) |
1385 | 0 | g_string_set_size(str, str->len - 1); |
1386 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1387 | 0 | } |
1388 | | static gboolean |
1389 | | fu_struct_ifwi_fpt_validate_internal(FuStructIfwiFpt *st, GError **error) |
1390 | 845 | { |
1391 | 845 | g_return_val_if_fail(st != NULL, FALSE); |
1392 | 845 | if (fu_struct_ifwi_fpt_get_header_marker(st) != 0x54504624) { |
1393 | 54 | g_set_error(error, |
1394 | 54 | FWUPD_ERROR, |
1395 | 54 | FWUPD_ERROR_INVALID_DATA, |
1396 | 54 | "constant FuStructIfwiFpt.header_marker was not valid, " |
1397 | 54 | "expected 0x%x and got 0x%x", |
1398 | 54 | (guint) 0x54504624, |
1399 | 54 | (guint) fu_struct_ifwi_fpt_get_header_marker(st)); |
1400 | 54 | return FALSE; |
1401 | 54 | } |
1402 | 791 | if (fu_struct_ifwi_fpt_get_entry_version(st) != 0x10) { |
1403 | 9 | g_set_error_literal(error, |
1404 | 9 | FWUPD_ERROR, |
1405 | 9 | FWUPD_ERROR_INVALID_DATA, |
1406 | 9 | "constant FuStructIfwiFpt.entry_version was not valid"); |
1407 | 9 | return FALSE; |
1408 | 9 | } |
1409 | 782 | return TRUE; |
1410 | 791 | } |
1411 | | /** |
1412 | | * fu_struct_ifwi_fpt_validate_stream: (skip): |
1413 | | **/ |
1414 | | gboolean |
1415 | | fu_struct_ifwi_fpt_validate_stream(GInputStream *stream, gsize offset, GError **error) |
1416 | 470 | { |
1417 | 470 | g_autoptr(FuStructIfwiFpt) st = fu_struct_ifwi_fpt_new_internal(); |
1418 | 470 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
1419 | 470 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
1420 | 470 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
1421 | 470 | if (st->buf == NULL) { |
1422 | 0 | g_prefix_error(error, "FuStructIfwiFpt failed read of 0x%x: ", (guint) 32); |
1423 | 0 | return FALSE; |
1424 | 0 | } |
1425 | 470 | if (st->buf->len != 32) { |
1426 | 16 | g_set_error(error, |
1427 | 16 | FWUPD_ERROR, |
1428 | 16 | FWUPD_ERROR_INVALID_DATA, |
1429 | 16 | "FuStructIfwiFpt requested 0x%x and got 0x%x", |
1430 | 16 | (guint) 32, |
1431 | 16 | (guint) st->buf->len); |
1432 | 16 | return FALSE; |
1433 | 16 | } |
1434 | 454 | return fu_struct_ifwi_fpt_validate_internal(st, error); |
1435 | 470 | } |
1436 | | static gboolean |
1437 | | fu_struct_ifwi_fpt_parse_internal(FuStructIfwiFpt *st, GError **error) |
1438 | 391 | { |
1439 | 391 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1440 | 0 | g_autofree gchar *str = fu_struct_ifwi_fpt_to_string(st); |
1441 | 0 | g_debug("%s", str); |
1442 | 0 | } |
1443 | 391 | if (!fu_struct_ifwi_fpt_validate_internal(st, error)) |
1444 | 0 | return FALSE; |
1445 | 391 | return TRUE; |
1446 | 391 | } |
1447 | | /** |
1448 | | * fu_struct_ifwi_fpt_parse_stream: (skip): |
1449 | | **/ |
1450 | | FuStructIfwiFpt * |
1451 | | fu_struct_ifwi_fpt_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1452 | 391 | { |
1453 | 391 | g_autoptr(FuStructIfwiFpt) st = fu_struct_ifwi_fpt_new_internal(); |
1454 | 391 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
1455 | 391 | if (st->buf == NULL) { |
1456 | 0 | g_prefix_error(error, "FuStructIfwiFpt failed read of 0x%x: ", (guint) 32); |
1457 | 0 | return NULL; |
1458 | 0 | } |
1459 | 391 | if (st->buf->len != 32) { |
1460 | 0 | g_set_error(error, |
1461 | 0 | FWUPD_ERROR, |
1462 | 0 | FWUPD_ERROR_INVALID_DATA, |
1463 | 0 | "FuStructIfwiFpt requested 0x%x and got 0x%x", |
1464 | 0 | (guint) 32, |
1465 | 0 | (guint) st->buf->len); |
1466 | 0 | return NULL; |
1467 | 0 | } |
1468 | 391 | if (!fu_struct_ifwi_fpt_parse_internal(st, error)) |
1469 | 0 | return NULL; |
1470 | 391 | return g_steal_pointer(&st); |
1471 | 391 | } |
1472 | | /** |
1473 | | * fu_struct_ifwi_fpt_entry_ref: (skip): |
1474 | | **/ |
1475 | | FuStructIfwiFptEntry * |
1476 | | fu_struct_ifwi_fpt_entry_ref(FuStructIfwiFptEntry *st) |
1477 | 0 | { |
1478 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1479 | 0 | st->refcount++; |
1480 | 0 | return st; |
1481 | 0 | } |
1482 | | /** |
1483 | | * fu_struct_ifwi_fpt_entry_unref: (skip): |
1484 | | **/ |
1485 | | void |
1486 | | fu_struct_ifwi_fpt_entry_unref(FuStructIfwiFptEntry *st) |
1487 | 4.24k | { |
1488 | 4.24k | g_return_if_fail(st != NULL); |
1489 | 4.24k | if (st->refcount == 0) { |
1490 | 0 | g_critical("FuStructIfwiFptEntry refcount already zero"); |
1491 | 0 | return; |
1492 | 0 | } |
1493 | 4.24k | if (--st->refcount > 0) |
1494 | 0 | return; |
1495 | 4.24k | if (st->buf != NULL) |
1496 | 4.13k | g_byte_array_unref(st->buf); |
1497 | 4.24k | g_free(st); |
1498 | 4.24k | } |
1499 | | /** |
1500 | | * fu_struct_ifwi_fpt_entry_new_internal: (skip): |
1501 | | **/ |
1502 | | static FuStructIfwiFptEntry * |
1503 | | fu_struct_ifwi_fpt_entry_new_internal(void) |
1504 | 4.24k | { |
1505 | 4.24k | FuStructIfwiFptEntry *st = g_new0(FuStructIfwiFptEntry, 1); |
1506 | 4.24k | st->refcount = 1; |
1507 | 4.24k | return st; |
1508 | 4.24k | } |
1509 | | |
1510 | | /* getters */ |
1511 | | /** |
1512 | | * fu_struct_ifwi_fpt_entry_get_partition_name: (skip): |
1513 | | **/ |
1514 | | guint32 |
1515 | | fu_struct_ifwi_fpt_entry_get_partition_name(const FuStructIfwiFptEntry *st) |
1516 | 4.10k | { |
1517 | 4.10k | g_return_val_if_fail(st != NULL, 0x0); |
1518 | 4.10k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
1519 | 4.10k | } |
1520 | | /** |
1521 | | * fu_struct_ifwi_fpt_entry_get_offset: (skip): |
1522 | | **/ |
1523 | | guint32 |
1524 | | fu_struct_ifwi_fpt_entry_get_offset(const FuStructIfwiFptEntry *st) |
1525 | 2.73k | { |
1526 | 2.73k | g_return_val_if_fail(st != NULL, 0x0); |
1527 | 2.73k | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
1528 | 2.73k | } |
1529 | | /** |
1530 | | * fu_struct_ifwi_fpt_entry_get_length: (skip): |
1531 | | **/ |
1532 | | guint32 |
1533 | | fu_struct_ifwi_fpt_entry_get_length(const FuStructIfwiFptEntry *st) |
1534 | 4.10k | { |
1535 | 4.10k | g_return_val_if_fail(st != NULL, 0x0); |
1536 | 4.10k | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
1537 | 4.10k | } |
1538 | | /** |
1539 | | * fu_struct_ifwi_fpt_entry_get_partition_type: (skip): |
1540 | | **/ |
1541 | | guint32 |
1542 | | fu_struct_ifwi_fpt_entry_get_partition_type(const FuStructIfwiFptEntry *st) |
1543 | 0 | { |
1544 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1545 | 0 | return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN); |
1546 | 0 | } |
1547 | | |
1548 | | /* setters */ |
1549 | | /** |
1550 | | * fu_struct_ifwi_fpt_entry_set_partition_name: (skip): |
1551 | | **/ |
1552 | | void |
1553 | | fu_struct_ifwi_fpt_entry_set_partition_name(FuStructIfwiFptEntry *st, guint32 value) |
1554 | 0 | { |
1555 | 0 | g_return_if_fail(st != NULL); |
1556 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
1557 | 0 | } |
1558 | | /** |
1559 | | * fu_struct_ifwi_fpt_entry_set_offset: (skip): |
1560 | | **/ |
1561 | | void |
1562 | | fu_struct_ifwi_fpt_entry_set_offset(FuStructIfwiFptEntry *st, guint32 value) |
1563 | 0 | { |
1564 | 0 | g_return_if_fail(st != NULL); |
1565 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
1566 | 0 | } |
1567 | | /** |
1568 | | * fu_struct_ifwi_fpt_entry_set_length: (skip): |
1569 | | **/ |
1570 | | void |
1571 | | fu_struct_ifwi_fpt_entry_set_length(FuStructIfwiFptEntry *st, guint32 value) |
1572 | 0 | { |
1573 | 0 | g_return_if_fail(st != NULL); |
1574 | 0 | fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
1575 | 0 | } |
1576 | | /** |
1577 | | * fu_struct_ifwi_fpt_entry_set_partition_type: (skip): |
1578 | | **/ |
1579 | | void |
1580 | | fu_struct_ifwi_fpt_entry_set_partition_type(FuStructIfwiFptEntry *st, guint32 value) |
1581 | 0 | { |
1582 | 0 | g_return_if_fail(st != NULL); |
1583 | 0 | fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
1584 | 0 | } |
1585 | | /** |
1586 | | * fu_struct_ifwi_fpt_entry_new: (skip): |
1587 | | **/ |
1588 | | FuStructIfwiFptEntry * |
1589 | | fu_struct_ifwi_fpt_entry_new(void) |
1590 | 0 | { |
1591 | 0 | FuStructIfwiFptEntry *st = fu_struct_ifwi_fpt_entry_new_internal(); |
1592 | 0 | st->buf = g_byte_array_sized_new(32); |
1593 | 0 | fu_byte_array_set_size(st->buf, 32, 0x0); |
1594 | 0 | return st; |
1595 | 0 | } |
1596 | | /** |
1597 | | * fu_struct_ifwi_fpt_entry_to_string: (skip): |
1598 | | **/ |
1599 | | static gchar * |
1600 | | fu_struct_ifwi_fpt_entry_to_string(const FuStructIfwiFptEntry *st) |
1601 | 0 | { |
1602 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfwiFptEntry:\n"); |
1603 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1604 | 0 | g_string_append_printf(str, " partition_name: 0x%x\n", |
1605 | 0 | (guint) fu_struct_ifwi_fpt_entry_get_partition_name(st)); |
1606 | 0 | g_string_append_printf(str, " offset: 0x%x\n", |
1607 | 0 | (guint) fu_struct_ifwi_fpt_entry_get_offset(st)); |
1608 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
1609 | 0 | (guint) fu_struct_ifwi_fpt_entry_get_length(st)); |
1610 | 0 | g_string_append_printf(str, " partition_type: 0x%x\n", |
1611 | 0 | (guint) fu_struct_ifwi_fpt_entry_get_partition_type(st)); |
1612 | 0 | if (str->len > 0) |
1613 | 0 | g_string_set_size(str, str->len - 1); |
1614 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1615 | 0 | } |
1616 | | static gboolean |
1617 | | fu_struct_ifwi_fpt_entry_validate_internal(FuStructIfwiFptEntry *st, GError **error) |
1618 | 4.10k | { |
1619 | 4.10k | g_return_val_if_fail(st != NULL, FALSE); |
1620 | 4.10k | return TRUE; |
1621 | 4.10k | } |
1622 | | static gboolean |
1623 | | fu_struct_ifwi_fpt_entry_parse_internal(FuStructIfwiFptEntry *st, GError **error) |
1624 | 4.10k | { |
1625 | 4.10k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1626 | 0 | g_autofree gchar *str = fu_struct_ifwi_fpt_entry_to_string(st); |
1627 | 0 | g_debug("%s", str); |
1628 | 0 | } |
1629 | 4.10k | if (!fu_struct_ifwi_fpt_entry_validate_internal(st, error)) |
1630 | 0 | return FALSE; |
1631 | 4.10k | return TRUE; |
1632 | 4.10k | } |
1633 | | /** |
1634 | | * fu_struct_ifwi_fpt_entry_parse_stream: (skip): |
1635 | | **/ |
1636 | | FuStructIfwiFptEntry * |
1637 | | fu_struct_ifwi_fpt_entry_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1638 | 4.24k | { |
1639 | 4.24k | g_autoptr(FuStructIfwiFptEntry) st = fu_struct_ifwi_fpt_entry_new_internal(); |
1640 | 4.24k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
1641 | 4.24k | if (st->buf == NULL) { |
1642 | 108 | g_prefix_error(error, "FuStructIfwiFptEntry failed read of 0x%x: ", (guint) 32); |
1643 | 108 | return NULL; |
1644 | 108 | } |
1645 | 4.13k | if (st->buf->len != 32) { |
1646 | 34 | g_set_error(error, |
1647 | 34 | FWUPD_ERROR, |
1648 | 34 | FWUPD_ERROR_INVALID_DATA, |
1649 | 34 | "FuStructIfwiFptEntry requested 0x%x and got 0x%x", |
1650 | 34 | (guint) 32, |
1651 | 34 | (guint) st->buf->len); |
1652 | 34 | return NULL; |
1653 | 34 | } |
1654 | 4.10k | if (!fu_struct_ifwi_fpt_entry_parse_internal(st, error)) |
1655 | 0 | return NULL; |
1656 | 4.10k | return g_steal_pointer(&st); |
1657 | 4.10k | } |