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-ifd-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 | | /** |
22 | | * fu_ifd_region_to_string: |
23 | | * @val: value, e.g. %FU_IFD_REGION_BIOS |
24 | | * |
25 | | * Converts an enumerated value to a string. |
26 | | * |
27 | | * Returns: identifier string |
28 | | **/ |
29 | | const gchar * |
30 | | fu_ifd_region_to_string(FuIfdRegion val) |
31 | 0 | { |
32 | 0 | if (val == FU_IFD_REGION_DESC) |
33 | 0 | return "desc"; |
34 | 0 | if (val == FU_IFD_REGION_BIOS) |
35 | 0 | return "bios"; |
36 | 0 | if (val == FU_IFD_REGION_ME) |
37 | 0 | return "me"; |
38 | 0 | if (val == FU_IFD_REGION_GBE) |
39 | 0 | return "gbe"; |
40 | 0 | if (val == FU_IFD_REGION_PLATFORM) |
41 | 0 | return "platform"; |
42 | 0 | if (val == FU_IFD_REGION_DEVEXP) |
43 | 0 | return "devexp"; |
44 | 0 | if (val == FU_IFD_REGION_BIOS2) |
45 | 0 | return "bios2"; |
46 | 0 | if (val == FU_IFD_REGION_EC) |
47 | 0 | return "ec"; |
48 | 0 | if (val == FU_IFD_REGION_IE) |
49 | 0 | return "ie"; |
50 | 0 | if (val == FU_IFD_REGION_10GBE) |
51 | 0 | return "10gbe"; |
52 | 0 | if (val == FU_IFD_REGION_MAX) |
53 | 0 | return "max"; |
54 | 0 | return NULL; |
55 | 0 | } |
56 | | |
57 | | /** |
58 | | * fu_ifd_access_to_string: |
59 | | * @val: value, e.g. %FU_IFD_ACCESS_READ |
60 | | * |
61 | | * Converts an enumerated value to a string. |
62 | | * |
63 | | * Returns: identifier string |
64 | | * |
65 | | **/ |
66 | | gchar * |
67 | | fu_ifd_access_to_string(FuIfdAccess val) |
68 | 0 | { |
69 | 0 | const gchar *data[3] = {0}; |
70 | 0 | guint idx = 0; |
71 | 0 | if (val == FU_IFD_ACCESS_NONE) |
72 | 0 | return g_strdup("none"); |
73 | 0 | if (val & FU_IFD_ACCESS_READ) |
74 | 0 | data[idx++] = "read"; |
75 | 0 | if (val & FU_IFD_ACCESS_WRITE) |
76 | 0 | data[idx++] = "write"; |
77 | 0 | return g_strjoinv(",", (gchar **)data); |
78 | 0 | } |
79 | | /** |
80 | | * fu_struct_ifd_fdbar_ref: (skip): |
81 | | **/ |
82 | | FuStructIfdFdbar * |
83 | | fu_struct_ifd_fdbar_ref(FuStructIfdFdbar *st) |
84 | 0 | { |
85 | 0 | g_return_val_if_fail(st != NULL, NULL); |
86 | 0 | st->refcount++; |
87 | 0 | return st; |
88 | 0 | } |
89 | | /** |
90 | | * fu_struct_ifd_fdbar_unref: (skip): |
91 | | **/ |
92 | | void |
93 | | fu_struct_ifd_fdbar_unref(FuStructIfdFdbar *st) |
94 | 0 | { |
95 | 0 | g_return_if_fail(st != NULL); |
96 | 0 | if (st->refcount == 0) { |
97 | 0 | g_critical("FuStructIfdFdbar refcount already zero"); |
98 | 0 | return; |
99 | 0 | } |
100 | 0 | if (--st->refcount > 0) |
101 | 0 | return; |
102 | 0 | if (st->buf != NULL) |
103 | 0 | g_byte_array_unref(st->buf); |
104 | 0 | g_free(st); |
105 | 0 | } |
106 | | /** |
107 | | * fu_struct_ifd_fdbar_new_internal: (skip): |
108 | | **/ |
109 | | static FuStructIfdFdbar * |
110 | | fu_struct_ifd_fdbar_new_internal(void) |
111 | 0 | { |
112 | 0 | FuStructIfdFdbar *st = g_new0(FuStructIfdFdbar, 1); |
113 | 0 | st->refcount = 1; |
114 | 0 | return st; |
115 | 0 | } |
116 | | |
117 | | /* getters */ |
118 | | /** |
119 | | * fu_struct_ifd_fdbar_get_signature: (skip): |
120 | | **/ |
121 | | static guint32 |
122 | | fu_struct_ifd_fdbar_get_signature(const FuStructIfdFdbar *st) |
123 | 0 | { |
124 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
125 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
126 | 0 | } |
127 | | /** |
128 | | * fu_struct_ifd_fdbar_get_descriptor_map0: (skip): |
129 | | **/ |
130 | | guint32 |
131 | | fu_struct_ifd_fdbar_get_descriptor_map0(const FuStructIfdFdbar *st) |
132 | 0 | { |
133 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
134 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
135 | 0 | } |
136 | | /** |
137 | | * fu_struct_ifd_fdbar_get_descriptor_map1: (skip): |
138 | | **/ |
139 | | guint32 |
140 | | fu_struct_ifd_fdbar_get_descriptor_map1(const FuStructIfdFdbar *st) |
141 | 0 | { |
142 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
143 | 0 | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
144 | 0 | } |
145 | | /** |
146 | | * fu_struct_ifd_fdbar_get_descriptor_map2: (skip): |
147 | | **/ |
148 | | guint32 |
149 | | fu_struct_ifd_fdbar_get_descriptor_map2(const FuStructIfdFdbar *st) |
150 | 0 | { |
151 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
152 | 0 | return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN); |
153 | 0 | } |
154 | | |
155 | | /* setters */ |
156 | | /** |
157 | | * fu_struct_ifd_fdbar_set_signature: (skip): |
158 | | **/ |
159 | | static void |
160 | | fu_struct_ifd_fdbar_set_signature(FuStructIfdFdbar *st, guint32 value) |
161 | 0 | { |
162 | 0 | g_return_if_fail(st != NULL); |
163 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
164 | 0 | } |
165 | | /** |
166 | | * fu_struct_ifd_fdbar_set_descriptor_map0: (skip): |
167 | | **/ |
168 | | void |
169 | | fu_struct_ifd_fdbar_set_descriptor_map0(FuStructIfdFdbar *st, guint32 value) |
170 | 0 | { |
171 | 0 | g_return_if_fail(st != NULL); |
172 | 0 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
173 | 0 | } |
174 | | /** |
175 | | * fu_struct_ifd_fdbar_set_descriptor_map1: (skip): |
176 | | **/ |
177 | | void |
178 | | fu_struct_ifd_fdbar_set_descriptor_map1(FuStructIfdFdbar *st, guint32 value) |
179 | 0 | { |
180 | 0 | g_return_if_fail(st != NULL); |
181 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
182 | 0 | } |
183 | | /** |
184 | | * fu_struct_ifd_fdbar_set_descriptor_map2: (skip): |
185 | | **/ |
186 | | void |
187 | | fu_struct_ifd_fdbar_set_descriptor_map2(FuStructIfdFdbar *st, guint32 value) |
188 | 0 | { |
189 | 0 | g_return_if_fail(st != NULL); |
190 | 0 | fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
191 | 0 | } |
192 | | /** |
193 | | * fu_struct_ifd_fdbar_new: (skip): |
194 | | **/ |
195 | | FuStructIfdFdbar * |
196 | | fu_struct_ifd_fdbar_new(void) |
197 | 0 | { |
198 | 0 | FuStructIfdFdbar *st = fu_struct_ifd_fdbar_new_internal(); |
199 | 0 | st->buf = g_byte_array_sized_new(32); |
200 | 0 | fu_byte_array_set_size(st->buf, 32, 0x0); |
201 | 0 | memcpy(st->buf->data + 0x0, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 16); /* nocheck:blocked */ |
202 | 0 | fu_struct_ifd_fdbar_set_signature(st, 0x0FF0A55A); |
203 | 0 | return st; |
204 | 0 | } |
205 | | /** |
206 | | * fu_struct_ifd_fdbar_to_string: (skip): |
207 | | **/ |
208 | | static gchar * |
209 | | fu_struct_ifd_fdbar_to_string(const FuStructIfdFdbar *st) |
210 | 0 | { |
211 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfdFdbar:\n"); |
212 | 0 | g_return_val_if_fail(st != NULL, NULL); |
213 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
214 | 0 | (guint) fu_struct_ifd_fdbar_get_signature(st)); |
215 | 0 | g_string_append_printf(str, " descriptor_map0: 0x%x\n", |
216 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map0(st)); |
217 | 0 | g_string_append_printf(str, " descriptor_map1: 0x%x\n", |
218 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map1(st)); |
219 | 0 | g_string_append_printf(str, " descriptor_map2: 0x%x\n", |
220 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map2(st)); |
221 | 0 | if (str->len > 0) |
222 | 0 | g_string_set_size(str, str->len - 1); |
223 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
224 | 0 | } |
225 | | static gboolean |
226 | | fu_struct_ifd_fdbar_validate_internal(FuStructIfdFdbar *st, GError **error) |
227 | 0 | { |
228 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
229 | 0 | if (fu_struct_ifd_fdbar_get_signature(st) != 0x0FF0A55A) { |
230 | 0 | g_set_error(error, |
231 | 0 | FWUPD_ERROR, |
232 | 0 | FWUPD_ERROR_INVALID_DATA, |
233 | 0 | "constant FuStructIfdFdbar.signature was not valid, " |
234 | 0 | "expected 0x%x and got 0x%x", |
235 | 0 | (guint) 0x0FF0A55A, |
236 | 0 | (guint) fu_struct_ifd_fdbar_get_signature(st)); |
237 | 0 | return FALSE; |
238 | 0 | } |
239 | 0 | return TRUE; |
240 | 0 | } |
241 | | /** |
242 | | * fu_struct_ifd_fdbar_validate_stream: (skip): |
243 | | **/ |
244 | | gboolean |
245 | | fu_struct_ifd_fdbar_validate_stream(GInputStream *stream, gsize offset, GError **error) |
246 | 0 | { |
247 | 0 | g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal(); |
248 | 0 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
249 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
250 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
251 | 0 | if (st->buf == NULL) { |
252 | 0 | g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32); |
253 | 0 | return FALSE; |
254 | 0 | } |
255 | 0 | if (st->buf->len != 32) { |
256 | 0 | g_set_error(error, |
257 | 0 | FWUPD_ERROR, |
258 | 0 | FWUPD_ERROR_INVALID_DATA, |
259 | 0 | "FuStructIfdFdbar requested 0x%x and got 0x%x", |
260 | 0 | (guint) 32, |
261 | 0 | (guint) st->buf->len); |
262 | 0 | return FALSE; |
263 | 0 | } |
264 | 0 | return fu_struct_ifd_fdbar_validate_internal(st, error); |
265 | 0 | } |
266 | | static gboolean |
267 | | fu_struct_ifd_fdbar_parse_internal(FuStructIfdFdbar *st, GError **error) |
268 | 0 | { |
269 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
270 | 0 | g_autofree gchar *str = fu_struct_ifd_fdbar_to_string(st); |
271 | 0 | g_debug("%s", str); |
272 | 0 | } |
273 | 0 | if (!fu_struct_ifd_fdbar_validate_internal(st, error)) |
274 | 0 | return FALSE; |
275 | 0 | return TRUE; |
276 | 0 | } |
277 | | /** |
278 | | * fu_struct_ifd_fdbar_parse_stream: (skip): |
279 | | **/ |
280 | | FuStructIfdFdbar * |
281 | | fu_struct_ifd_fdbar_parse_stream(GInputStream *stream, gsize offset, GError **error) |
282 | 0 | { |
283 | 0 | g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal(); |
284 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
285 | 0 | if (st->buf == NULL) { |
286 | 0 | g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32); |
287 | 0 | return NULL; |
288 | 0 | } |
289 | 0 | if (st->buf->len != 32) { |
290 | 0 | g_set_error(error, |
291 | 0 | FWUPD_ERROR, |
292 | 0 | FWUPD_ERROR_INVALID_DATA, |
293 | 0 | "FuStructIfdFdbar requested 0x%x and got 0x%x", |
294 | 0 | (guint) 32, |
295 | 0 | (guint) st->buf->len); |
296 | 0 | return NULL; |
297 | 0 | } |
298 | 0 | if (!fu_struct_ifd_fdbar_parse_internal(st, error)) |
299 | 0 | return NULL; |
300 | 0 | return g_steal_pointer(&st); |
301 | 0 | } |
302 | | /** |
303 | | * fu_struct_ifd_fcba_ref: (skip): |
304 | | **/ |
305 | | FuStructIfdFcba * |
306 | | fu_struct_ifd_fcba_ref(FuStructIfdFcba *st) |
307 | 0 | { |
308 | 0 | g_return_val_if_fail(st != NULL, NULL); |
309 | 0 | st->refcount++; |
310 | 0 | return st; |
311 | 0 | } |
312 | | /** |
313 | | * fu_struct_ifd_fcba_unref: (skip): |
314 | | **/ |
315 | | void |
316 | | fu_struct_ifd_fcba_unref(FuStructIfdFcba *st) |
317 | 0 | { |
318 | 0 | g_return_if_fail(st != NULL); |
319 | 0 | if (st->refcount == 0) { |
320 | 0 | g_critical("FuStructIfdFcba refcount already zero"); |
321 | 0 | return; |
322 | 0 | } |
323 | 0 | if (--st->refcount > 0) |
324 | 0 | return; |
325 | 0 | if (st->buf != NULL) |
326 | 0 | g_byte_array_unref(st->buf); |
327 | 0 | g_free(st); |
328 | 0 | } |
329 | | /** |
330 | | * fu_struct_ifd_fcba_new_internal: (skip): |
331 | | **/ |
332 | | static FuStructIfdFcba * |
333 | | fu_struct_ifd_fcba_new_internal(void) |
334 | 0 | { |
335 | 0 | FuStructIfdFcba *st = g_new0(FuStructIfdFcba, 1); |
336 | 0 | st->refcount = 1; |
337 | 0 | return st; |
338 | 0 | } |
339 | | |
340 | | /* getters */ |
341 | | /** |
342 | | * fu_struct_ifd_fcba_get_flcomp: (skip): |
343 | | **/ |
344 | | guint32 |
345 | | fu_struct_ifd_fcba_get_flcomp(const FuStructIfdFcba *st) |
346 | 0 | { |
347 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
348 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
349 | 0 | } |
350 | | /** |
351 | | * fu_struct_ifd_fcba_get_flill: (skip): |
352 | | **/ |
353 | | guint32 |
354 | | fu_struct_ifd_fcba_get_flill(const FuStructIfdFcba *st) |
355 | 0 | { |
356 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
357 | 0 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
358 | 0 | } |
359 | | /** |
360 | | * fu_struct_ifd_fcba_get_flill1: (skip): |
361 | | **/ |
362 | | guint32 |
363 | | fu_struct_ifd_fcba_get_flill1(const FuStructIfdFcba *st) |
364 | 0 | { |
365 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
366 | 0 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
367 | 0 | } |
368 | | |
369 | | /* setters */ |
370 | | /** |
371 | | * fu_struct_ifd_fcba_set_flcomp: (skip): |
372 | | **/ |
373 | | void |
374 | | fu_struct_ifd_fcba_set_flcomp(FuStructIfdFcba *st, guint32 value) |
375 | 0 | { |
376 | 0 | g_return_if_fail(st != NULL); |
377 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
378 | 0 | } |
379 | | /** |
380 | | * fu_struct_ifd_fcba_set_flill: (skip): |
381 | | **/ |
382 | | void |
383 | | fu_struct_ifd_fcba_set_flill(FuStructIfdFcba *st, guint32 value) |
384 | 0 | { |
385 | 0 | g_return_if_fail(st != NULL); |
386 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
387 | 0 | } |
388 | | /** |
389 | | * fu_struct_ifd_fcba_set_flill1: (skip): |
390 | | **/ |
391 | | void |
392 | | fu_struct_ifd_fcba_set_flill1(FuStructIfdFcba *st, guint32 value) |
393 | 0 | { |
394 | 0 | g_return_if_fail(st != NULL); |
395 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
396 | 0 | } |
397 | | /** |
398 | | * fu_struct_ifd_fcba_new: (skip): |
399 | | **/ |
400 | | FuStructIfdFcba * |
401 | | fu_struct_ifd_fcba_new(void) |
402 | 0 | { |
403 | 0 | FuStructIfdFcba *st = fu_struct_ifd_fcba_new_internal(); |
404 | 0 | st->buf = g_byte_array_sized_new(12); |
405 | 0 | fu_byte_array_set_size(st->buf, 12, 0x0); |
406 | 0 | return st; |
407 | 0 | } |
408 | | /** |
409 | | * fu_struct_ifd_fcba_to_string: (skip): |
410 | | **/ |
411 | | static gchar * |
412 | | fu_struct_ifd_fcba_to_string(const FuStructIfdFcba *st) |
413 | 0 | { |
414 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfdFcba:\n"); |
415 | 0 | g_return_val_if_fail(st != NULL, NULL); |
416 | 0 | g_string_append_printf(str, " flcomp: 0x%x\n", |
417 | 0 | (guint) fu_struct_ifd_fcba_get_flcomp(st)); |
418 | 0 | g_string_append_printf(str, " flill: 0x%x\n", |
419 | 0 | (guint) fu_struct_ifd_fcba_get_flill(st)); |
420 | 0 | g_string_append_printf(str, " flill1: 0x%x\n", |
421 | 0 | (guint) fu_struct_ifd_fcba_get_flill1(st)); |
422 | 0 | if (str->len > 0) |
423 | 0 | g_string_set_size(str, str->len - 1); |
424 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
425 | 0 | } |
426 | | static gboolean |
427 | | fu_struct_ifd_fcba_validate_internal(FuStructIfdFcba *st, GError **error) |
428 | 0 | { |
429 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
430 | 0 | return TRUE; |
431 | 0 | } |
432 | | static gboolean |
433 | | fu_struct_ifd_fcba_parse_internal(FuStructIfdFcba *st, GError **error) |
434 | 0 | { |
435 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
436 | 0 | g_autofree gchar *str = fu_struct_ifd_fcba_to_string(st); |
437 | 0 | g_debug("%s", str); |
438 | 0 | } |
439 | 0 | if (!fu_struct_ifd_fcba_validate_internal(st, error)) |
440 | 0 | return FALSE; |
441 | 0 | return TRUE; |
442 | 0 | } |
443 | | /** |
444 | | * fu_struct_ifd_fcba_parse_stream: (skip): |
445 | | **/ |
446 | | FuStructIfdFcba * |
447 | | fu_struct_ifd_fcba_parse_stream(GInputStream *stream, gsize offset, GError **error) |
448 | 0 | { |
449 | 0 | g_autoptr(FuStructIfdFcba) st = fu_struct_ifd_fcba_new_internal(); |
450 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
451 | 0 | if (st->buf == NULL) { |
452 | 0 | g_prefix_error(error, "FuStructIfdFcba failed read of 0x%x: ", (guint) 12); |
453 | 0 | return NULL; |
454 | 0 | } |
455 | 0 | if (st->buf->len != 12) { |
456 | 0 | g_set_error(error, |
457 | 0 | FWUPD_ERROR, |
458 | 0 | FWUPD_ERROR_INVALID_DATA, |
459 | 0 | "FuStructIfdFcba requested 0x%x and got 0x%x", |
460 | 0 | (guint) 12, |
461 | 0 | (guint) st->buf->len); |
462 | 0 | return NULL; |
463 | 0 | } |
464 | 0 | if (!fu_struct_ifd_fcba_parse_internal(st, error)) |
465 | 0 | return NULL; |
466 | 0 | return g_steal_pointer(&st); |
467 | 0 | } |