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