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 | 10.1k | { |
32 | 10.1k | if (val == FU_IFD_REGION_DESC) |
33 | 1.65k | return "desc"; |
34 | 8.50k | if (val == FU_IFD_REGION_BIOS) |
35 | 1.64k | return "bios"; |
36 | 6.86k | if (val == FU_IFD_REGION_ME) |
37 | 1.27k | return "me"; |
38 | 5.59k | if (val == FU_IFD_REGION_GBE) |
39 | 1.14k | return "gbe"; |
40 | 4.44k | if (val == FU_IFD_REGION_PLATFORM) |
41 | 1.13k | return "platform"; |
42 | 3.31k | if (val == FU_IFD_REGION_DEVEXP) |
43 | 1.02k | return "devexp"; |
44 | 2.29k | if (val == FU_IFD_REGION_BIOS2) |
45 | 615 | return "bios2"; |
46 | 1.67k | if (val == FU_IFD_REGION_EC) |
47 | 561 | return "ec"; |
48 | 1.11k | if (val == FU_IFD_REGION_IE) |
49 | 0 | return "ie"; |
50 | 1.11k | if (val == FU_IFD_REGION_10GBE) |
51 | 0 | return "10gbe"; |
52 | 1.11k | if (val == FU_IFD_REGION_MAX) |
53 | 0 | return "max"; |
54 | 1.11k | return NULL; |
55 | 1.11k | } |
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 | 46.0k | { |
95 | 46.0k | g_return_if_fail(st != NULL); |
96 | 46.0k | if (st->refcount == 0) { |
97 | 0 | g_critical("FuStructIfdFdbar refcount already zero"); |
98 | 0 | return; |
99 | 0 | } |
100 | 46.0k | if (--st->refcount > 0) |
101 | 0 | return; |
102 | 46.0k | if (st->buf != NULL) |
103 | 46.0k | g_byte_array_unref(st->buf); |
104 | 46.0k | g_free(st); |
105 | 46.0k | } |
106 | | /** |
107 | | * fu_struct_ifd_fdbar_new_internal: (skip): |
108 | | **/ |
109 | | static FuStructIfdFdbar * |
110 | | fu_struct_ifd_fdbar_new_internal(void) |
111 | 46.0k | { |
112 | 46.0k | FuStructIfdFdbar *st = g_new0(FuStructIfdFdbar, 1); |
113 | 46.0k | st->refcount = 1; |
114 | 46.0k | return st; |
115 | 46.0k | } |
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 | 79.8k | { |
124 | 79.8k | g_return_val_if_fail(st != NULL, 0x0); |
125 | 79.8k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
126 | 79.8k | } |
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 | 1.65k | { |
133 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
134 | 1.65k | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
135 | 1.65k | } |
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 | 1.65k | { |
142 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
143 | 1.65k | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
144 | 1.65k | } |
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 | 1.65k | { |
151 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
152 | 1.65k | return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN); |
153 | 1.65k | } |
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 | 767 | { |
162 | 767 | g_return_if_fail(st != NULL); |
163 | 767 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
164 | 767 | } |
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 | 118 | { |
171 | 118 | g_return_if_fail(st != NULL); |
172 | 118 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
173 | 118 | } |
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 | 118 | { |
180 | 118 | g_return_if_fail(st != NULL); |
181 | 118 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
182 | 118 | } |
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 | 118 | { |
189 | 118 | g_return_if_fail(st != NULL); |
190 | 118 | fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
191 | 118 | } |
192 | | /** |
193 | | * fu_struct_ifd_fdbar_new: (skip): |
194 | | **/ |
195 | | FuStructIfdFdbar * |
196 | | fu_struct_ifd_fdbar_new(void) |
197 | 767 | { |
198 | 767 | FuStructIfdFdbar *st = fu_struct_ifd_fdbar_new_internal(); |
199 | 767 | st->buf = g_byte_array_sized_new(32); |
200 | 767 | fu_byte_array_set_size(st->buf, 32, 0x0); |
201 | 767 | 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 | 767 | fu_struct_ifd_fdbar_set_signature(st, 0x0FF0A55A); |
203 | 767 | return st; |
204 | 767 | } |
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, " descriptor_map0: 0x%x\n", |
214 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map0(st)); |
215 | 0 | g_string_append_printf(str, " descriptor_map1: 0x%x\n", |
216 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map1(st)); |
217 | 0 | g_string_append_printf(str, " descriptor_map2: 0x%x\n", |
218 | 0 | (guint) fu_struct_ifd_fdbar_get_descriptor_map2(st)); |
219 | 0 | if (str->len > 0) |
220 | 0 | g_string_set_size(str, str->len - 1); |
221 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
222 | 0 | } |
223 | | static gboolean |
224 | | fu_struct_ifd_fdbar_validate_internal(FuStructIfdFdbar *st, GError **error) |
225 | 41.6k | { |
226 | 41.6k | g_return_val_if_fail(st != NULL, FALSE); |
227 | 41.6k | if (fu_struct_ifd_fdbar_get_signature(st) != 0x0FF0A55A) { |
228 | 38.2k | g_set_error(error, |
229 | 38.2k | FWUPD_ERROR, |
230 | 38.2k | FWUPD_ERROR_INVALID_DATA, |
231 | 38.2k | "constant FuStructIfdFdbar.signature was not valid, " |
232 | 38.2k | "expected 0x%x and got 0x%x", |
233 | 38.2k | (guint) 0x0FF0A55A, |
234 | 38.2k | (guint) fu_struct_ifd_fdbar_get_signature(st)); |
235 | 38.2k | return FALSE; |
236 | 38.2k | } |
237 | 3.37k | return TRUE; |
238 | 41.6k | } |
239 | | /** |
240 | | * fu_struct_ifd_fdbar_validate_stream: (skip): |
241 | | **/ |
242 | | gboolean |
243 | | fu_struct_ifd_fdbar_validate_stream(GInputStream *stream, gsize offset, GError **error) |
244 | 43.5k | { |
245 | 43.5k | g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal(); |
246 | 43.5k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
247 | 43.5k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
248 | 43.5k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
249 | 43.5k | if (st->buf == NULL) { |
250 | 0 | g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32); |
251 | 0 | return FALSE; |
252 | 0 | } |
253 | 43.5k | if (st->buf->len != 32) { |
254 | 3.60k | g_set_error(error, |
255 | 3.60k | FWUPD_ERROR, |
256 | 3.60k | FWUPD_ERROR_INVALID_DATA, |
257 | 3.60k | "FuStructIfdFdbar requested 0x%x and got 0x%x", |
258 | 3.60k | (guint) 32, |
259 | 3.60k | (guint) st->buf->len); |
260 | 3.60k | return FALSE; |
261 | 3.60k | } |
262 | 39.9k | return fu_struct_ifd_fdbar_validate_internal(st, error); |
263 | 43.5k | } |
264 | | static gboolean |
265 | | fu_struct_ifd_fdbar_parse_internal(FuStructIfdFdbar *st, GError **error) |
266 | 1.65k | { |
267 | 1.65k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
268 | 0 | g_autofree gchar *str = fu_struct_ifd_fdbar_to_string(st); |
269 | 0 | g_debug("%s", str); |
270 | 0 | } |
271 | 1.65k | if (!fu_struct_ifd_fdbar_validate_internal(st, error)) |
272 | 0 | return FALSE; |
273 | 1.65k | return TRUE; |
274 | 1.65k | } |
275 | | /** |
276 | | * fu_struct_ifd_fdbar_parse_stream: (skip): |
277 | | **/ |
278 | | FuStructIfdFdbar * |
279 | | fu_struct_ifd_fdbar_parse_stream(GInputStream *stream, gsize offset, GError **error) |
280 | 1.65k | { |
281 | 1.65k | g_autoptr(FuStructIfdFdbar) st = fu_struct_ifd_fdbar_new_internal(); |
282 | 1.65k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
283 | 1.65k | if (st->buf == NULL) { |
284 | 0 | g_prefix_error(error, "FuStructIfdFdbar failed read of 0x%x: ", (guint) 32); |
285 | 0 | return NULL; |
286 | 0 | } |
287 | 1.65k | if (st->buf->len != 32) { |
288 | 0 | g_set_error(error, |
289 | 0 | FWUPD_ERROR, |
290 | 0 | FWUPD_ERROR_INVALID_DATA, |
291 | 0 | "FuStructIfdFdbar requested 0x%x and got 0x%x", |
292 | 0 | (guint) 32, |
293 | 0 | (guint) st->buf->len); |
294 | 0 | return NULL; |
295 | 0 | } |
296 | 1.65k | if (!fu_struct_ifd_fdbar_parse_internal(st, error)) |
297 | 0 | return NULL; |
298 | 1.65k | return g_steal_pointer(&st); |
299 | 1.65k | } |
300 | | /** |
301 | | * fu_struct_ifd_fcba_ref: (skip): |
302 | | **/ |
303 | | FuStructIfdFcba * |
304 | | fu_struct_ifd_fcba_ref(FuStructIfdFcba *st) |
305 | 0 | { |
306 | 0 | g_return_val_if_fail(st != NULL, NULL); |
307 | 0 | st->refcount++; |
308 | 0 | return st; |
309 | 0 | } |
310 | | /** |
311 | | * fu_struct_ifd_fcba_unref: (skip): |
312 | | **/ |
313 | | void |
314 | | fu_struct_ifd_fcba_unref(FuStructIfdFcba *st) |
315 | 2.42k | { |
316 | 2.42k | g_return_if_fail(st != NULL); |
317 | 2.42k | if (st->refcount == 0) { |
318 | 0 | g_critical("FuStructIfdFcba refcount already zero"); |
319 | 0 | return; |
320 | 0 | } |
321 | 2.42k | if (--st->refcount > 0) |
322 | 0 | return; |
323 | 2.42k | if (st->buf != NULL) |
324 | 2.42k | g_byte_array_unref(st->buf); |
325 | 2.42k | g_free(st); |
326 | 2.42k | } |
327 | | /** |
328 | | * fu_struct_ifd_fcba_new_internal: (skip): |
329 | | **/ |
330 | | static FuStructIfdFcba * |
331 | | fu_struct_ifd_fcba_new_internal(void) |
332 | 2.42k | { |
333 | 2.42k | FuStructIfdFcba *st = g_new0(FuStructIfdFcba, 1); |
334 | 2.42k | st->refcount = 1; |
335 | 2.42k | return st; |
336 | 2.42k | } |
337 | | |
338 | | /* getters */ |
339 | | /** |
340 | | * fu_struct_ifd_fcba_get_flcomp: (skip): |
341 | | **/ |
342 | | guint32 |
343 | | fu_struct_ifd_fcba_get_flcomp(const FuStructIfdFcba *st) |
344 | 1.65k | { |
345 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
346 | 1.65k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
347 | 1.65k | } |
348 | | /** |
349 | | * fu_struct_ifd_fcba_get_flill: (skip): |
350 | | **/ |
351 | | guint32 |
352 | | fu_struct_ifd_fcba_get_flill(const FuStructIfdFcba *st) |
353 | 1.65k | { |
354 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
355 | 1.65k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
356 | 1.65k | } |
357 | | /** |
358 | | * fu_struct_ifd_fcba_get_flill1: (skip): |
359 | | **/ |
360 | | guint32 |
361 | | fu_struct_ifd_fcba_get_flill1(const FuStructIfdFcba *st) |
362 | 1.65k | { |
363 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
364 | 1.65k | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
365 | 1.65k | } |
366 | | |
367 | | /* setters */ |
368 | | /** |
369 | | * fu_struct_ifd_fcba_set_flcomp: (skip): |
370 | | **/ |
371 | | void |
372 | | fu_struct_ifd_fcba_set_flcomp(FuStructIfdFcba *st, guint32 value) |
373 | 118 | { |
374 | 118 | g_return_if_fail(st != NULL); |
375 | 118 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
376 | 118 | } |
377 | | /** |
378 | | * fu_struct_ifd_fcba_set_flill: (skip): |
379 | | **/ |
380 | | void |
381 | | fu_struct_ifd_fcba_set_flill(FuStructIfdFcba *st, guint32 value) |
382 | 118 | { |
383 | 118 | g_return_if_fail(st != NULL); |
384 | 118 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
385 | 118 | } |
386 | | /** |
387 | | * fu_struct_ifd_fcba_set_flill1: (skip): |
388 | | **/ |
389 | | void |
390 | | fu_struct_ifd_fcba_set_flill1(FuStructIfdFcba *st, guint32 value) |
391 | 118 | { |
392 | 118 | g_return_if_fail(st != NULL); |
393 | 118 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
394 | 118 | } |
395 | | /** |
396 | | * fu_struct_ifd_fcba_new: (skip): |
397 | | **/ |
398 | | FuStructIfdFcba * |
399 | | fu_struct_ifd_fcba_new(void) |
400 | 767 | { |
401 | 767 | FuStructIfdFcba *st = fu_struct_ifd_fcba_new_internal(); |
402 | 767 | st->buf = g_byte_array_sized_new(12); |
403 | 767 | fu_byte_array_set_size(st->buf, 12, 0x0); |
404 | 767 | return st; |
405 | 767 | } |
406 | | /** |
407 | | * fu_struct_ifd_fcba_to_string: (skip): |
408 | | **/ |
409 | | static gchar * |
410 | | fu_struct_ifd_fcba_to_string(const FuStructIfdFcba *st) |
411 | 0 | { |
412 | 0 | g_autoptr(GString) str = g_string_new("FuStructIfdFcba:\n"); |
413 | 0 | g_return_val_if_fail(st != NULL, NULL); |
414 | 0 | g_string_append_printf(str, " flcomp: 0x%x\n", |
415 | 0 | (guint) fu_struct_ifd_fcba_get_flcomp(st)); |
416 | 0 | g_string_append_printf(str, " flill: 0x%x\n", |
417 | 0 | (guint) fu_struct_ifd_fcba_get_flill(st)); |
418 | 0 | g_string_append_printf(str, " flill1: 0x%x\n", |
419 | 0 | (guint) fu_struct_ifd_fcba_get_flill1(st)); |
420 | 0 | if (str->len > 0) |
421 | 0 | g_string_set_size(str, str->len - 1); |
422 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
423 | 0 | } |
424 | | static gboolean |
425 | | fu_struct_ifd_fcba_validate_internal(FuStructIfdFcba *st, GError **error) |
426 | 1.65k | { |
427 | 1.65k | g_return_val_if_fail(st != NULL, FALSE); |
428 | 1.65k | return TRUE; |
429 | 1.65k | } |
430 | | static gboolean |
431 | | fu_struct_ifd_fcba_parse_internal(FuStructIfdFcba *st, GError **error) |
432 | 1.65k | { |
433 | 1.65k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
434 | 0 | g_autofree gchar *str = fu_struct_ifd_fcba_to_string(st); |
435 | 0 | g_debug("%s", str); |
436 | 0 | } |
437 | 1.65k | if (!fu_struct_ifd_fcba_validate_internal(st, error)) |
438 | 0 | return FALSE; |
439 | 1.65k | return TRUE; |
440 | 1.65k | } |
441 | | /** |
442 | | * fu_struct_ifd_fcba_parse_stream: (skip): |
443 | | **/ |
444 | | FuStructIfdFcba * |
445 | | fu_struct_ifd_fcba_parse_stream(GInputStream *stream, gsize offset, GError **error) |
446 | 1.65k | { |
447 | 1.65k | g_autoptr(FuStructIfdFcba) st = fu_struct_ifd_fcba_new_internal(); |
448 | 1.65k | st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
449 | 1.65k | if (st->buf == NULL) { |
450 | 0 | g_prefix_error(error, "FuStructIfdFcba failed read of 0x%x: ", (guint) 12); |
451 | 0 | return NULL; |
452 | 0 | } |
453 | 1.65k | if (st->buf->len != 12) { |
454 | 0 | g_set_error(error, |
455 | 0 | FWUPD_ERROR, |
456 | 0 | FWUPD_ERROR_INVALID_DATA, |
457 | 0 | "FuStructIfdFcba requested 0x%x and got 0x%x", |
458 | 0 | (guint) 12, |
459 | 0 | (guint) st->buf->len); |
460 | 0 | return NULL; |
461 | 0 | } |
462 | 1.65k | if (!fu_struct_ifd_fcba_parse_internal(st, error)) |
463 | 0 | return NULL; |
464 | 1.65k | return g_steal_pointer(&st); |
465 | 1.65k | } |