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