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