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