/work/fu-acpi-phat-struct.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include "fu-acpi-phat-struct.h" |
5 | | #include "fu-byte-array.h" |
6 | | #include "fu-mem-private.h" |
7 | | #include "fu-string.h" |
8 | | |
9 | | #ifdef G_LOG_DOMAIN |
10 | | #undef G_LOG_DOMAIN |
11 | | #endif |
12 | 0 | #define G_LOG_DOMAIN "FuStruct" |
13 | | /* getters */ |
14 | | |
15 | | /* setters */ |
16 | | static gboolean |
17 | | fu_struct_acpi_phat_hdr_validate_internal(FuStructAcpiPhatHdr *st, GError **error) |
18 | 0 | { |
19 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
20 | 0 | if (strncmp((const gchar *) (st->data + 0), "PHAT", 4) != 0) { |
21 | 0 | g_set_error_literal(error, |
22 | 0 | FWUPD_ERROR, |
23 | 0 | FWUPD_ERROR_INVALID_DATA, |
24 | 0 | "constant FuStructAcpiPhatHdr.magic was not valid"); |
25 | 0 | return FALSE; |
26 | 0 | } |
27 | 0 | return TRUE; |
28 | 0 | } |
29 | | /** |
30 | | * fu_struct_acpi_phat_hdr_validate_stream: (skip): |
31 | | **/ |
32 | | gboolean |
33 | | fu_struct_acpi_phat_hdr_validate_stream(GInputStream *stream, gsize offset, GError **error) |
34 | 0 | { |
35 | 0 | g_autoptr(GByteArray) st = NULL; |
36 | 0 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
37 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
38 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
39 | 0 | if (st == NULL) { |
40 | 0 | g_prefix_error(error, "FuStructAcpiPhatHdr failed read of 0x%x: ", (guint) 4); |
41 | 0 | return FALSE; |
42 | 0 | } |
43 | 0 | if (st->len != 4) { |
44 | 0 | g_set_error(error, |
45 | 0 | FWUPD_ERROR, |
46 | 0 | FWUPD_ERROR_INVALID_DATA, |
47 | 0 | "FuStructAcpiPhatHdr requested 0x%x and got 0x%x", |
48 | 0 | (guint) 4, |
49 | 0 | (guint) st->len); |
50 | 0 | return FALSE; |
51 | 0 | } |
52 | 0 | return fu_struct_acpi_phat_hdr_validate_internal(st, error); |
53 | 0 | } |
54 | | /* getters */ |
55 | | /** |
56 | | * fu_struct_acpi_phat_health_record_get_signature: (skip): |
57 | | **/ |
58 | | guint16 |
59 | | fu_struct_acpi_phat_health_record_get_signature(const FuStructAcpiPhatHealthRecord *st) |
60 | 0 | { |
61 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
62 | 0 | return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN); |
63 | 0 | } |
64 | | /** |
65 | | * fu_struct_acpi_phat_health_record_get_rcdlen: (skip): |
66 | | **/ |
67 | | guint16 |
68 | | fu_struct_acpi_phat_health_record_get_rcdlen(const FuStructAcpiPhatHealthRecord *st) |
69 | 0 | { |
70 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
71 | 0 | return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN); |
72 | 0 | } |
73 | | /** |
74 | | * fu_struct_acpi_phat_health_record_get_version: (skip): |
75 | | **/ |
76 | | guint8 |
77 | | fu_struct_acpi_phat_health_record_get_version(const FuStructAcpiPhatHealthRecord *st) |
78 | 0 | { |
79 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
80 | 0 | return st->data[4]; |
81 | 0 | } |
82 | | /** |
83 | | * fu_struct_acpi_phat_health_record_get_flags: (skip): |
84 | | **/ |
85 | | guint8 |
86 | | fu_struct_acpi_phat_health_record_get_flags(const FuStructAcpiPhatHealthRecord *st) |
87 | 0 | { |
88 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
89 | 0 | return st->data[7]; |
90 | 0 | } |
91 | | /** |
92 | | * fu_struct_acpi_phat_health_record_get_device_signature: (skip): |
93 | | **/ |
94 | | const fwupd_guid_t * |
95 | | fu_struct_acpi_phat_health_record_get_device_signature(const FuStructAcpiPhatHealthRecord *st) |
96 | 0 | { |
97 | 0 | g_return_val_if_fail(st != NULL, NULL); |
98 | 0 | return (const fwupd_guid_t *) (st->data + 8); |
99 | 0 | } |
100 | | /** |
101 | | * fu_struct_acpi_phat_health_record_get_device_specific_data: (skip): |
102 | | **/ |
103 | | guint32 |
104 | | fu_struct_acpi_phat_health_record_get_device_specific_data(const FuStructAcpiPhatHealthRecord *st) |
105 | 0 | { |
106 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
107 | 0 | return fu_memread_uint32(st->data + 24, G_LITTLE_ENDIAN); |
108 | 0 | } |
109 | | |
110 | | /* setters */ |
111 | | /** |
112 | | * fu_struct_acpi_phat_health_record_set_signature: (skip): |
113 | | **/ |
114 | | void |
115 | | fu_struct_acpi_phat_health_record_set_signature(FuStructAcpiPhatHealthRecord *st, guint16 value) |
116 | 0 | { |
117 | 0 | g_return_if_fail(st != NULL); |
118 | 0 | fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN); |
119 | 0 | } |
120 | | /** |
121 | | * fu_struct_acpi_phat_health_record_set_rcdlen: (skip): |
122 | | **/ |
123 | | void |
124 | | fu_struct_acpi_phat_health_record_set_rcdlen(FuStructAcpiPhatHealthRecord *st, guint16 value) |
125 | 0 | { |
126 | 0 | g_return_if_fail(st != NULL); |
127 | 0 | fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN); |
128 | 0 | } |
129 | | /** |
130 | | * fu_struct_acpi_phat_health_record_set_version: (skip): |
131 | | **/ |
132 | | void |
133 | | fu_struct_acpi_phat_health_record_set_version(FuStructAcpiPhatHealthRecord *st, guint8 value) |
134 | 0 | { |
135 | 0 | g_return_if_fail(st != NULL); |
136 | 0 | st->data[4] = value; |
137 | 0 | } |
138 | | /** |
139 | | * fu_struct_acpi_phat_health_record_set_flags: (skip): |
140 | | **/ |
141 | | void |
142 | | fu_struct_acpi_phat_health_record_set_flags(FuStructAcpiPhatHealthRecord *st, guint8 value) |
143 | 0 | { |
144 | 0 | g_return_if_fail(st != NULL); |
145 | 0 | st->data[7] = value; |
146 | 0 | } |
147 | | /** |
148 | | * fu_struct_acpi_phat_health_record_set_device_signature: (skip): |
149 | | **/ |
150 | | void |
151 | | fu_struct_acpi_phat_health_record_set_device_signature(FuStructAcpiPhatHealthRecord *st, const fwupd_guid_t *value) |
152 | 0 | { |
153 | 0 | g_return_if_fail(st != NULL); |
154 | 0 | g_return_if_fail(value != NULL); |
155 | 0 | memcpy(st->data + 8, value, sizeof(*value)); /* nocheck:blocked */ |
156 | 0 | } |
157 | | /** |
158 | | * fu_struct_acpi_phat_health_record_set_device_specific_data: (skip): |
159 | | **/ |
160 | | void |
161 | | fu_struct_acpi_phat_health_record_set_device_specific_data(FuStructAcpiPhatHealthRecord *st, guint32 value) |
162 | 0 | { |
163 | 0 | g_return_if_fail(st != NULL); |
164 | 0 | fu_memwrite_uint32(st->data + 24, value, G_LITTLE_ENDIAN); |
165 | 0 | } |
166 | | /** |
167 | | * fu_struct_acpi_phat_health_record_new: (skip): |
168 | | **/ |
169 | | FuStructAcpiPhatHealthRecord * |
170 | | fu_struct_acpi_phat_health_record_new(void) |
171 | 0 | { |
172 | 0 | FuStructAcpiPhatHealthRecord *st = g_byte_array_sized_new(28); |
173 | 0 | fu_byte_array_set_size(st, 28, 0x0); |
174 | 0 | fu_struct_acpi_phat_health_record_set_signature(st, 0x1); |
175 | 0 | return st; |
176 | 0 | } |
177 | | /** |
178 | | * fu_struct_acpi_phat_health_record_to_string: (skip): |
179 | | **/ |
180 | | static gchar * |
181 | | fu_struct_acpi_phat_health_record_to_string(const FuStructAcpiPhatHealthRecord *st) |
182 | 0 | { |
183 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatHealthRecord:\n"); |
184 | 0 | g_return_val_if_fail(st != NULL, NULL); |
185 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
186 | 0 | (guint) fu_struct_acpi_phat_health_record_get_signature(st)); |
187 | 0 | g_string_append_printf(str, " rcdlen: 0x%x\n", |
188 | 0 | (guint) fu_struct_acpi_phat_health_record_get_rcdlen(st)); |
189 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
190 | 0 | (guint) fu_struct_acpi_phat_health_record_get_version(st)); |
191 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
192 | 0 | (guint) fu_struct_acpi_phat_health_record_get_flags(st)); |
193 | 0 | { |
194 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_health_record_get_device_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
195 | 0 | g_string_append_printf(str, " device_signature: %s\n", tmp); |
196 | 0 | } |
197 | 0 | g_string_append_printf(str, " device_specific_data: 0x%x\n", |
198 | 0 | (guint) fu_struct_acpi_phat_health_record_get_device_specific_data(st)); |
199 | 0 | if (str->len > 0) |
200 | 0 | g_string_set_size(str, str->len - 1); |
201 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
202 | 0 | } |
203 | | static gboolean |
204 | | fu_struct_acpi_phat_health_record_validate_internal(FuStructAcpiPhatHealthRecord *st, GError **error) |
205 | 0 | { |
206 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
207 | 0 | return TRUE; |
208 | 0 | } |
209 | | static gboolean |
210 | | fu_struct_acpi_phat_health_record_parse_internal(FuStructAcpiPhatHealthRecord *st, GError **error) |
211 | 0 | { |
212 | 0 | if (!fu_struct_acpi_phat_health_record_validate_internal(st, error)) |
213 | 0 | return FALSE; |
214 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
215 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_health_record_to_string(st); |
216 | 0 | g_debug("%s", str); |
217 | 0 | } |
218 | 0 | return TRUE; |
219 | 0 | } |
220 | | /** |
221 | | * fu_struct_acpi_phat_health_record_parse_stream: (skip): |
222 | | **/ |
223 | | FuStructAcpiPhatHealthRecord * |
224 | | fu_struct_acpi_phat_health_record_parse_stream(GInputStream *stream, gsize offset, GError **error) |
225 | 0 | { |
226 | 0 | g_autoptr(GByteArray) st = NULL; |
227 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
228 | 0 | if (st == NULL) { |
229 | 0 | g_prefix_error(error, "FuStructAcpiPhatHealthRecord failed read of 0x%x: ", (guint) 28); |
230 | 0 | return NULL; |
231 | 0 | } |
232 | 0 | if (st->len != 28) { |
233 | 0 | g_set_error(error, |
234 | 0 | FWUPD_ERROR, |
235 | 0 | FWUPD_ERROR_INVALID_DATA, |
236 | 0 | "FuStructAcpiPhatHealthRecord requested 0x%x and got 0x%x", |
237 | 0 | (guint) 28, |
238 | 0 | (guint) st->len); |
239 | 0 | return NULL; |
240 | 0 | } |
241 | 0 | if (!fu_struct_acpi_phat_health_record_parse_internal(st, error)) |
242 | 0 | return NULL; |
243 | 0 | return g_steal_pointer(&st); |
244 | 0 | } |
245 | | /* getters */ |
246 | | /** |
247 | | * fu_struct_acpi_phat_version_element_get_component_id: (skip): |
248 | | **/ |
249 | | const fwupd_guid_t * |
250 | | fu_struct_acpi_phat_version_element_get_component_id(const FuStructAcpiPhatVersionElement *st) |
251 | 0 | { |
252 | 0 | g_return_val_if_fail(st != NULL, NULL); |
253 | 0 | return (const fwupd_guid_t *) (st->data + 0); |
254 | 0 | } |
255 | | /** |
256 | | * fu_struct_acpi_phat_version_element_get_version_value: (skip): |
257 | | **/ |
258 | | guint64 |
259 | | fu_struct_acpi_phat_version_element_get_version_value(const FuStructAcpiPhatVersionElement *st) |
260 | 0 | { |
261 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
262 | 0 | return fu_memread_uint64(st->data + 16, G_LITTLE_ENDIAN); |
263 | 0 | } |
264 | | /** |
265 | | * fu_struct_acpi_phat_version_element_get_producer_id: (skip): |
266 | | **/ |
267 | | gchar * |
268 | | fu_struct_acpi_phat_version_element_get_producer_id(const FuStructAcpiPhatVersionElement *st) |
269 | 0 | { |
270 | 0 | g_return_val_if_fail(st != NULL, NULL); |
271 | 0 | return fu_memstrsafe(st->data, st->len, 24, 4, NULL); |
272 | 0 | } |
273 | | |
274 | | /* setters */ |
275 | | /** |
276 | | * fu_struct_acpi_phat_version_element_set_component_id: (skip): |
277 | | **/ |
278 | | void |
279 | | fu_struct_acpi_phat_version_element_set_component_id(FuStructAcpiPhatVersionElement *st, const fwupd_guid_t *value) |
280 | 0 | { |
281 | 0 | g_return_if_fail(st != NULL); |
282 | 0 | g_return_if_fail(value != NULL); |
283 | 0 | memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
284 | 0 | } |
285 | | /** |
286 | | * fu_struct_acpi_phat_version_element_set_version_value: (skip): |
287 | | **/ |
288 | | void |
289 | | fu_struct_acpi_phat_version_element_set_version_value(FuStructAcpiPhatVersionElement *st, guint64 value) |
290 | 0 | { |
291 | 0 | g_return_if_fail(st != NULL); |
292 | 0 | fu_memwrite_uint64(st->data + 16, value, G_LITTLE_ENDIAN); |
293 | 0 | } |
294 | | /** |
295 | | * fu_struct_acpi_phat_version_element_set_producer_id: (skip): |
296 | | **/ |
297 | | gboolean |
298 | | fu_struct_acpi_phat_version_element_set_producer_id(FuStructAcpiPhatVersionElement *st, const gchar *value, GError **error) |
299 | 0 | { |
300 | 0 | gsize len; |
301 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
302 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
303 | 0 | if (value == NULL) { |
304 | 0 | memset(st->data + 24, 0x0, 4); |
305 | 0 | return TRUE; |
306 | 0 | } |
307 | 0 | len = strlen(value); |
308 | 0 | if (len > 4) { |
309 | 0 | g_set_error(error, |
310 | 0 | FWUPD_ERROR, |
311 | 0 | FWUPD_ERROR_INVALID_DATA, |
312 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructAcpiPhatVersionElement.producer_id (0x%x bytes)", |
313 | 0 | value, (guint) len, (guint) 4); |
314 | 0 | return FALSE; |
315 | 0 | } |
316 | 0 | return fu_memcpy_safe(st->data, st->len, 24, (const guint8 *)value, len, 0x0, len, error); |
317 | 0 | } |
318 | | /** |
319 | | * fu_struct_acpi_phat_version_element_new: (skip): |
320 | | **/ |
321 | | FuStructAcpiPhatVersionElement * |
322 | | fu_struct_acpi_phat_version_element_new(void) |
323 | 0 | { |
324 | 0 | FuStructAcpiPhatVersionElement *st = g_byte_array_sized_new(28); |
325 | 0 | fu_byte_array_set_size(st, 28, 0x0); |
326 | 0 | return st; |
327 | 0 | } |
328 | | /** |
329 | | * fu_struct_acpi_phat_version_element_to_string: (skip): |
330 | | **/ |
331 | | static gchar * |
332 | | fu_struct_acpi_phat_version_element_to_string(const FuStructAcpiPhatVersionElement *st) |
333 | 0 | { |
334 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionElement:\n"); |
335 | 0 | g_return_val_if_fail(st != NULL, NULL); |
336 | 0 | { |
337 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_version_element_get_component_id(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
338 | 0 | g_string_append_printf(str, " component_id: %s\n", tmp); |
339 | 0 | } |
340 | 0 | g_string_append_printf(str, " version_value: 0x%x\n", |
341 | 0 | (guint) fu_struct_acpi_phat_version_element_get_version_value(st)); |
342 | 0 | { |
343 | 0 | g_autofree gchar *tmp = fu_struct_acpi_phat_version_element_get_producer_id(st); |
344 | 0 | if (tmp != NULL) |
345 | 0 | g_string_append_printf(str, " producer_id: %s\n", tmp); |
346 | 0 | } |
347 | 0 | if (str->len > 0) |
348 | 0 | g_string_set_size(str, str->len - 1); |
349 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
350 | 0 | } |
351 | | static gboolean |
352 | | fu_struct_acpi_phat_version_element_validate_internal(FuStructAcpiPhatVersionElement *st, GError **error) |
353 | 0 | { |
354 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
355 | 0 | return TRUE; |
356 | 0 | } |
357 | | static gboolean |
358 | | fu_struct_acpi_phat_version_element_parse_internal(FuStructAcpiPhatVersionElement *st, GError **error) |
359 | 0 | { |
360 | 0 | if (!fu_struct_acpi_phat_version_element_validate_internal(st, error)) |
361 | 0 | return FALSE; |
362 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
363 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_version_element_to_string(st); |
364 | 0 | g_debug("%s", str); |
365 | 0 | } |
366 | 0 | return TRUE; |
367 | 0 | } |
368 | | /** |
369 | | * fu_struct_acpi_phat_version_element_parse_stream: (skip): |
370 | | **/ |
371 | | FuStructAcpiPhatVersionElement * |
372 | | fu_struct_acpi_phat_version_element_parse_stream(GInputStream *stream, gsize offset, GError **error) |
373 | 0 | { |
374 | 0 | g_autoptr(GByteArray) st = NULL; |
375 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
376 | 0 | if (st == NULL) { |
377 | 0 | g_prefix_error(error, "FuStructAcpiPhatVersionElement failed read of 0x%x: ", (guint) 28); |
378 | 0 | return NULL; |
379 | 0 | } |
380 | 0 | if (st->len != 28) { |
381 | 0 | g_set_error(error, |
382 | 0 | FWUPD_ERROR, |
383 | 0 | FWUPD_ERROR_INVALID_DATA, |
384 | 0 | "FuStructAcpiPhatVersionElement requested 0x%x and got 0x%x", |
385 | 0 | (guint) 28, |
386 | 0 | (guint) st->len); |
387 | 0 | return NULL; |
388 | 0 | } |
389 | 0 | if (!fu_struct_acpi_phat_version_element_parse_internal(st, error)) |
390 | 0 | return NULL; |
391 | 0 | return g_steal_pointer(&st); |
392 | 0 | } |
393 | | /* getters */ |
394 | | /** |
395 | | * fu_struct_acpi_phat_version_record_get_signature: (skip): |
396 | | **/ |
397 | | guint16 |
398 | | fu_struct_acpi_phat_version_record_get_signature(const FuStructAcpiPhatVersionRecord *st) |
399 | 0 | { |
400 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
401 | 0 | return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN); |
402 | 0 | } |
403 | | /** |
404 | | * fu_struct_acpi_phat_version_record_get_rcdlen: (skip): |
405 | | **/ |
406 | | guint16 |
407 | | fu_struct_acpi_phat_version_record_get_rcdlen(const FuStructAcpiPhatVersionRecord *st) |
408 | 0 | { |
409 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
410 | 0 | return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN); |
411 | 0 | } |
412 | | /** |
413 | | * fu_struct_acpi_phat_version_record_get_version: (skip): |
414 | | **/ |
415 | | guint8 |
416 | | fu_struct_acpi_phat_version_record_get_version(const FuStructAcpiPhatVersionRecord *st) |
417 | 0 | { |
418 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
419 | 0 | return st->data[4]; |
420 | 0 | } |
421 | | /** |
422 | | * fu_struct_acpi_phat_version_record_get_record_count: (skip): |
423 | | **/ |
424 | | guint32 |
425 | | fu_struct_acpi_phat_version_record_get_record_count(const FuStructAcpiPhatVersionRecord *st) |
426 | 0 | { |
427 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
428 | 0 | return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN); |
429 | 0 | } |
430 | | |
431 | | /* setters */ |
432 | | /** |
433 | | * fu_struct_acpi_phat_version_record_set_signature: (skip): |
434 | | **/ |
435 | | void |
436 | | fu_struct_acpi_phat_version_record_set_signature(FuStructAcpiPhatVersionRecord *st, guint16 value) |
437 | 0 | { |
438 | 0 | g_return_if_fail(st != NULL); |
439 | 0 | fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN); |
440 | 0 | } |
441 | | /** |
442 | | * fu_struct_acpi_phat_version_record_set_rcdlen: (skip): |
443 | | **/ |
444 | | void |
445 | | fu_struct_acpi_phat_version_record_set_rcdlen(FuStructAcpiPhatVersionRecord *st, guint16 value) |
446 | 0 | { |
447 | 0 | g_return_if_fail(st != NULL); |
448 | 0 | fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN); |
449 | 0 | } |
450 | | /** |
451 | | * fu_struct_acpi_phat_version_record_set_version: (skip): |
452 | | **/ |
453 | | void |
454 | | fu_struct_acpi_phat_version_record_set_version(FuStructAcpiPhatVersionRecord *st, guint8 value) |
455 | 0 | { |
456 | 0 | g_return_if_fail(st != NULL); |
457 | 0 | st->data[4] = value; |
458 | 0 | } |
459 | | /** |
460 | | * fu_struct_acpi_phat_version_record_set_record_count: (skip): |
461 | | **/ |
462 | | void |
463 | | fu_struct_acpi_phat_version_record_set_record_count(FuStructAcpiPhatVersionRecord *st, guint32 value) |
464 | 0 | { |
465 | 0 | g_return_if_fail(st != NULL); |
466 | 0 | fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN); |
467 | 0 | } |
468 | | /** |
469 | | * fu_struct_acpi_phat_version_record_new: (skip): |
470 | | **/ |
471 | | FuStructAcpiPhatVersionRecord * |
472 | | fu_struct_acpi_phat_version_record_new(void) |
473 | 0 | { |
474 | 0 | FuStructAcpiPhatVersionRecord *st = g_byte_array_sized_new(12); |
475 | 0 | fu_byte_array_set_size(st, 12, 0x0); |
476 | 0 | fu_struct_acpi_phat_version_record_set_signature(st, 0x0); |
477 | 0 | return st; |
478 | 0 | } |
479 | | /** |
480 | | * fu_struct_acpi_phat_version_record_to_string: (skip): |
481 | | **/ |
482 | | static gchar * |
483 | | fu_struct_acpi_phat_version_record_to_string(const FuStructAcpiPhatVersionRecord *st) |
484 | 0 | { |
485 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionRecord:\n"); |
486 | 0 | g_return_val_if_fail(st != NULL, NULL); |
487 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
488 | 0 | (guint) fu_struct_acpi_phat_version_record_get_signature(st)); |
489 | 0 | g_string_append_printf(str, " rcdlen: 0x%x\n", |
490 | 0 | (guint) fu_struct_acpi_phat_version_record_get_rcdlen(st)); |
491 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
492 | 0 | (guint) fu_struct_acpi_phat_version_record_get_version(st)); |
493 | 0 | g_string_append_printf(str, " record_count: 0x%x\n", |
494 | 0 | (guint) fu_struct_acpi_phat_version_record_get_record_count(st)); |
495 | 0 | if (str->len > 0) |
496 | 0 | g_string_set_size(str, str->len - 1); |
497 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
498 | 0 | } |
499 | | static gboolean |
500 | | fu_struct_acpi_phat_version_record_validate_internal(FuStructAcpiPhatVersionRecord *st, GError **error) |
501 | 0 | { |
502 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
503 | 0 | return TRUE; |
504 | 0 | } |
505 | | static gboolean |
506 | | fu_struct_acpi_phat_version_record_parse_internal(FuStructAcpiPhatVersionRecord *st, GError **error) |
507 | 0 | { |
508 | 0 | if (!fu_struct_acpi_phat_version_record_validate_internal(st, error)) |
509 | 0 | return FALSE; |
510 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
511 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_version_record_to_string(st); |
512 | 0 | g_debug("%s", str); |
513 | 0 | } |
514 | 0 | return TRUE; |
515 | 0 | } |
516 | | /** |
517 | | * fu_struct_acpi_phat_version_record_parse_stream: (skip): |
518 | | **/ |
519 | | FuStructAcpiPhatVersionRecord * |
520 | | fu_struct_acpi_phat_version_record_parse_stream(GInputStream *stream, gsize offset, GError **error) |
521 | 0 | { |
522 | 0 | g_autoptr(GByteArray) st = NULL; |
523 | 0 | st = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
524 | 0 | if (st == NULL) { |
525 | 0 | g_prefix_error(error, "FuStructAcpiPhatVersionRecord failed read of 0x%x: ", (guint) 12); |
526 | 0 | return NULL; |
527 | 0 | } |
528 | 0 | if (st->len != 12) { |
529 | 0 | g_set_error(error, |
530 | 0 | FWUPD_ERROR, |
531 | 0 | FWUPD_ERROR_INVALID_DATA, |
532 | 0 | "FuStructAcpiPhatVersionRecord requested 0x%x and got 0x%x", |
533 | 0 | (guint) 12, |
534 | 0 | (guint) st->len); |
535 | 0 | return NULL; |
536 | 0 | } |
537 | 0 | if (!fu_struct_acpi_phat_version_record_parse_internal(st, error)) |
538 | 0 | return NULL; |
539 | 0 | return g_steal_pointer(&st); |
540 | 0 | } |