/work/fu-acpi-phat-struct.c
Line | Count | Source |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include <glib.h> |
5 | | |
6 | | #include "fu-acpi-phat-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 | | * fu_struct_acpi_phat_hdr_ref: (skip): |
17 | | **/ |
18 | | FuStructAcpiPhatHdr * |
19 | | fu_struct_acpi_phat_hdr_ref(FuStructAcpiPhatHdr *st) |
20 | 0 | { |
21 | 0 | g_return_val_if_fail(st != NULL, NULL); |
22 | 0 | st->refcount++; |
23 | 0 | return st; |
24 | 0 | } |
25 | | /** |
26 | | * fu_struct_acpi_phat_hdr_unref: (skip): |
27 | | **/ |
28 | | void |
29 | | fu_struct_acpi_phat_hdr_unref(FuStructAcpiPhatHdr *st) |
30 | 276k | { |
31 | 276k | g_return_if_fail(st != NULL); |
32 | 276k | if (st->refcount == 0) { |
33 | 0 | g_critical("FuStructAcpiPhatHdr refcount already zero"); |
34 | 0 | return; |
35 | 0 | } |
36 | 276k | if (--st->refcount > 0) |
37 | 0 | return; |
38 | 276k | if (st->buf != NULL) |
39 | 276k | g_byte_array_unref(st->buf); |
40 | 276k | g_free(st); |
41 | 276k | } |
42 | | /** |
43 | | * fu_struct_acpi_phat_hdr_new_internal: (skip): |
44 | | **/ |
45 | | static FuStructAcpiPhatHdr * |
46 | | fu_struct_acpi_phat_hdr_new_internal(void) |
47 | 276k | { |
48 | 276k | FuStructAcpiPhatHdr *st = g_new0(FuStructAcpiPhatHdr, 1); |
49 | 276k | st->refcount = 1; |
50 | 276k | return st; |
51 | 276k | } |
52 | | |
53 | | /* getters */ |
54 | | /** |
55 | | * fu_struct_acpi_phat_hdr_get_magic: (skip): |
56 | | **/ |
57 | | static gchar * |
58 | | fu_struct_acpi_phat_hdr_get_magic(const FuStructAcpiPhatHdr *st) |
59 | 274k | { |
60 | 274k | g_return_val_if_fail(st != NULL, NULL); |
61 | 274k | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
62 | 274k | } |
63 | | |
64 | | /* setters */ |
65 | | static gboolean |
66 | | fu_struct_acpi_phat_hdr_validate_internal(FuStructAcpiPhatHdr *st, GError **error) |
67 | 276k | { |
68 | 276k | g_return_val_if_fail(st != NULL, FALSE); |
69 | 276k | if (strncmp((const gchar *) (st->buf->data + 0), "PHAT", 4) != 0) { |
70 | 274k | g_autofree gchar *str = fu_struct_acpi_phat_hdr_get_magic(st); |
71 | 274k | g_set_error(error, |
72 | 274k | FWUPD_ERROR, |
73 | 274k | FWUPD_ERROR_INVALID_DATA, |
74 | 274k | "constant FuStructAcpiPhatHdr.magic was not valid, " |
75 | 274k | "expected 'PHAT' and got '%s'", |
76 | 274k | str); |
77 | 274k | return FALSE; |
78 | 274k | } |
79 | 2.17k | return TRUE; |
80 | 276k | } |
81 | | /** |
82 | | * fu_struct_acpi_phat_hdr_validate_stream: (skip): |
83 | | **/ |
84 | | gboolean |
85 | | fu_struct_acpi_phat_hdr_validate_stream(GInputStream *stream, gsize offset, GError **error) |
86 | 276k | { |
87 | 276k | g_autoptr(FuStructAcpiPhatHdr) st = fu_struct_acpi_phat_hdr_new_internal(); |
88 | 276k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
89 | 276k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
90 | 276k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
91 | 276k | if (st->buf == NULL) { |
92 | 0 | g_prefix_error(error, "FuStructAcpiPhatHdr failed read of 0x%x: ", (guint) 4); |
93 | 0 | return FALSE; |
94 | 0 | } |
95 | 276k | if (st->buf->len != 4) { |
96 | 358 | g_set_error(error, |
97 | 358 | FWUPD_ERROR, |
98 | 358 | FWUPD_ERROR_INVALID_DATA, |
99 | 358 | "FuStructAcpiPhatHdr requested 0x%x and got 0x%x", |
100 | 358 | (guint) 4, |
101 | 358 | (guint) st->buf->len); |
102 | 358 | return FALSE; |
103 | 358 | } |
104 | 276k | return fu_struct_acpi_phat_hdr_validate_internal(st, error); |
105 | 276k | } |
106 | | /** |
107 | | * fu_struct_acpi_phat_health_record_ref: (skip): |
108 | | **/ |
109 | | FuStructAcpiPhatHealthRecord * |
110 | | fu_struct_acpi_phat_health_record_ref(FuStructAcpiPhatHealthRecord *st) |
111 | 0 | { |
112 | 0 | g_return_val_if_fail(st != NULL, NULL); |
113 | 0 | st->refcount++; |
114 | 0 | return st; |
115 | 0 | } |
116 | | /** |
117 | | * fu_struct_acpi_phat_health_record_unref: (skip): |
118 | | **/ |
119 | | void |
120 | | fu_struct_acpi_phat_health_record_unref(FuStructAcpiPhatHealthRecord *st) |
121 | 2.92k | { |
122 | 2.92k | g_return_if_fail(st != NULL); |
123 | 2.92k | if (st->refcount == 0) { |
124 | 0 | g_critical("FuStructAcpiPhatHealthRecord refcount already zero"); |
125 | 0 | return; |
126 | 0 | } |
127 | 2.92k | if (--st->refcount > 0) |
128 | 0 | return; |
129 | 2.92k | if (st->buf != NULL) |
130 | 2.11k | g_byte_array_unref(st->buf); |
131 | 2.92k | g_free(st); |
132 | 2.92k | } |
133 | | /** |
134 | | * fu_struct_acpi_phat_health_record_new_internal: (skip): |
135 | | **/ |
136 | | static FuStructAcpiPhatHealthRecord * |
137 | | fu_struct_acpi_phat_health_record_new_internal(void) |
138 | 2.92k | { |
139 | 2.92k | FuStructAcpiPhatHealthRecord *st = g_new0(FuStructAcpiPhatHealthRecord, 1); |
140 | 2.92k | st->refcount = 1; |
141 | 2.92k | return st; |
142 | 2.92k | } |
143 | | |
144 | | /* getters */ |
145 | | /** |
146 | | * fu_struct_acpi_phat_health_record_get_signature: (skip): |
147 | | **/ |
148 | | guint16 |
149 | | fu_struct_acpi_phat_health_record_get_signature(const FuStructAcpiPhatHealthRecord *st) |
150 | 0 | { |
151 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
152 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
153 | 0 | } |
154 | | /** |
155 | | * fu_struct_acpi_phat_health_record_get_rcdlen: (skip): |
156 | | **/ |
157 | | guint16 |
158 | | fu_struct_acpi_phat_health_record_get_rcdlen(const FuStructAcpiPhatHealthRecord *st) |
159 | 2.08k | { |
160 | 2.08k | g_return_val_if_fail(st != NULL, 0x0); |
161 | 2.08k | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
162 | 2.08k | } |
163 | | /** |
164 | | * fu_struct_acpi_phat_health_record_get_version: (skip): |
165 | | **/ |
166 | | guint8 |
167 | | fu_struct_acpi_phat_health_record_get_version(const FuStructAcpiPhatHealthRecord *st) |
168 | 0 | { |
169 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
170 | 0 | return st->buf->data[4]; |
171 | 0 | } |
172 | | /** |
173 | | * fu_struct_acpi_phat_health_record_get_flags: (skip): |
174 | | **/ |
175 | | guint8 |
176 | | fu_struct_acpi_phat_health_record_get_flags(const FuStructAcpiPhatHealthRecord *st) |
177 | 2.08k | { |
178 | 2.08k | g_return_val_if_fail(st != NULL, 0x0); |
179 | 2.08k | return st->buf->data[7]; |
180 | 2.08k | } |
181 | | /** |
182 | | * fu_struct_acpi_phat_health_record_get_device_signature: (skip): |
183 | | **/ |
184 | | const fwupd_guid_t * |
185 | | fu_struct_acpi_phat_health_record_get_device_signature(const FuStructAcpiPhatHealthRecord *st) |
186 | 2.08k | { |
187 | 2.08k | g_return_val_if_fail(st != NULL, NULL); |
188 | 2.08k | return (const fwupd_guid_t *) (st->buf->data + 8); |
189 | 2.08k | } |
190 | | /** |
191 | | * fu_struct_acpi_phat_health_record_get_device_specific_data: (skip): |
192 | | **/ |
193 | | guint32 |
194 | | fu_struct_acpi_phat_health_record_get_device_specific_data(const FuStructAcpiPhatHealthRecord *st) |
195 | 2.08k | { |
196 | 2.08k | g_return_val_if_fail(st != NULL, 0x0); |
197 | 2.08k | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
198 | 2.08k | } |
199 | | |
200 | | /* setters */ |
201 | | /** |
202 | | * fu_struct_acpi_phat_health_record_set_signature: (skip): |
203 | | **/ |
204 | | void |
205 | | fu_struct_acpi_phat_health_record_set_signature(FuStructAcpiPhatHealthRecord *st, guint16 value) |
206 | 804 | { |
207 | 804 | g_return_if_fail(st != NULL); |
208 | 804 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
209 | 804 | } |
210 | | /** |
211 | | * fu_struct_acpi_phat_health_record_set_rcdlen: (skip): |
212 | | **/ |
213 | | void |
214 | | fu_struct_acpi_phat_health_record_set_rcdlen(FuStructAcpiPhatHealthRecord *st, guint16 value) |
215 | 804 | { |
216 | 804 | g_return_if_fail(st != NULL); |
217 | 804 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
218 | 804 | } |
219 | | /** |
220 | | * fu_struct_acpi_phat_health_record_set_version: (skip): |
221 | | **/ |
222 | | void |
223 | | fu_struct_acpi_phat_health_record_set_version(FuStructAcpiPhatHealthRecord *st, guint8 value) |
224 | 804 | { |
225 | 804 | g_return_if_fail(st != NULL); |
226 | 804 | st->buf->data[4] = value; |
227 | 804 | } |
228 | | /** |
229 | | * fu_struct_acpi_phat_health_record_set_flags: (skip): |
230 | | **/ |
231 | | void |
232 | | fu_struct_acpi_phat_health_record_set_flags(FuStructAcpiPhatHealthRecord *st, guint8 value) |
233 | 804 | { |
234 | 804 | g_return_if_fail(st != NULL); |
235 | 804 | st->buf->data[7] = value; |
236 | 804 | } |
237 | | /** |
238 | | * fu_struct_acpi_phat_health_record_set_device_signature: (skip): |
239 | | **/ |
240 | | void |
241 | | fu_struct_acpi_phat_health_record_set_device_signature(FuStructAcpiPhatHealthRecord *st, const fwupd_guid_t *value) |
242 | 804 | { |
243 | 804 | g_return_if_fail(st != NULL); |
244 | 804 | g_return_if_fail(value != NULL); |
245 | 804 | memcpy(st->buf->data + 8, value, sizeof(*value)); /* nocheck:blocked */ |
246 | 804 | } |
247 | | /** |
248 | | * fu_struct_acpi_phat_health_record_set_device_specific_data: (skip): |
249 | | **/ |
250 | | void |
251 | | fu_struct_acpi_phat_health_record_set_device_specific_data(FuStructAcpiPhatHealthRecord *st, guint32 value) |
252 | 0 | { |
253 | 0 | g_return_if_fail(st != NULL); |
254 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
255 | 0 | } |
256 | | /** |
257 | | * fu_struct_acpi_phat_health_record_new: (skip): |
258 | | **/ |
259 | | FuStructAcpiPhatHealthRecord * |
260 | | fu_struct_acpi_phat_health_record_new(void) |
261 | 804 | { |
262 | 804 | FuStructAcpiPhatHealthRecord *st = fu_struct_acpi_phat_health_record_new_internal(); |
263 | 804 | st->buf = g_byte_array_sized_new(28); |
264 | 804 | fu_byte_array_set_size(st->buf, 28, 0x0); |
265 | 804 | fu_struct_acpi_phat_health_record_set_signature(st, 0x1); |
266 | 804 | return st; |
267 | 804 | } |
268 | | /** |
269 | | * fu_struct_acpi_phat_health_record_to_string: (skip): |
270 | | **/ |
271 | | static gchar * |
272 | | fu_struct_acpi_phat_health_record_to_string(const FuStructAcpiPhatHealthRecord *st) |
273 | 0 | { |
274 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatHealthRecord:\n"); |
275 | 0 | g_return_val_if_fail(st != NULL, NULL); |
276 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
277 | 0 | (guint) fu_struct_acpi_phat_health_record_get_signature(st)); |
278 | 0 | g_string_append_printf(str, " rcdlen: 0x%x\n", |
279 | 0 | (guint) fu_struct_acpi_phat_health_record_get_rcdlen(st)); |
280 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
281 | 0 | (guint) fu_struct_acpi_phat_health_record_get_version(st)); |
282 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
283 | 0 | (guint) fu_struct_acpi_phat_health_record_get_flags(st)); |
284 | 0 | { |
285 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_health_record_get_device_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
286 | 0 | g_string_append_printf(str, " device_signature: %s\n", tmp); |
287 | 0 | } |
288 | 0 | g_string_append_printf(str, " device_specific_data: 0x%x\n", |
289 | 0 | (guint) fu_struct_acpi_phat_health_record_get_device_specific_data(st)); |
290 | 0 | if (str->len > 0) |
291 | 0 | g_string_set_size(str, str->len - 1); |
292 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
293 | 0 | } |
294 | | static gboolean |
295 | | fu_struct_acpi_phat_health_record_validate_internal(FuStructAcpiPhatHealthRecord *st, GError **error) |
296 | 2.08k | { |
297 | 2.08k | g_return_val_if_fail(st != NULL, FALSE); |
298 | 2.08k | return TRUE; |
299 | 2.08k | } |
300 | | static gboolean |
301 | | fu_struct_acpi_phat_health_record_parse_internal(FuStructAcpiPhatHealthRecord *st, GError **error) |
302 | 2.08k | { |
303 | 2.08k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
304 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_health_record_to_string(st); |
305 | 0 | g_debug("%s", str); |
306 | 0 | } |
307 | 2.08k | if (!fu_struct_acpi_phat_health_record_validate_internal(st, error)) |
308 | 0 | return FALSE; |
309 | 2.08k | return TRUE; |
310 | 2.08k | } |
311 | | /** |
312 | | * fu_struct_acpi_phat_health_record_parse_stream: (skip): |
313 | | **/ |
314 | | FuStructAcpiPhatHealthRecord * |
315 | | fu_struct_acpi_phat_health_record_parse_stream(GInputStream *stream, gsize offset, GError **error) |
316 | 2.11k | { |
317 | 2.11k | g_autoptr(FuStructAcpiPhatHealthRecord) st = fu_struct_acpi_phat_health_record_new_internal(); |
318 | 2.11k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
319 | 2.11k | if (st->buf == NULL) { |
320 | 0 | g_prefix_error(error, "FuStructAcpiPhatHealthRecord failed read of 0x%x: ", (guint) 28); |
321 | 0 | return NULL; |
322 | 0 | } |
323 | 2.11k | if (st->buf->len != 28) { |
324 | 30 | g_set_error(error, |
325 | 30 | FWUPD_ERROR, |
326 | 30 | FWUPD_ERROR_INVALID_DATA, |
327 | 30 | "FuStructAcpiPhatHealthRecord requested 0x%x and got 0x%x", |
328 | 30 | (guint) 28, |
329 | 30 | (guint) st->buf->len); |
330 | 30 | return NULL; |
331 | 30 | } |
332 | 2.08k | if (!fu_struct_acpi_phat_health_record_parse_internal(st, error)) |
333 | 0 | return NULL; |
334 | 2.08k | return g_steal_pointer(&st); |
335 | 2.08k | } |
336 | | /** |
337 | | * fu_struct_acpi_phat_version_element_ref: (skip): |
338 | | **/ |
339 | | FuStructAcpiPhatVersionElement * |
340 | | fu_struct_acpi_phat_version_element_ref(FuStructAcpiPhatVersionElement *st) |
341 | 0 | { |
342 | 0 | g_return_val_if_fail(st != NULL, NULL); |
343 | 0 | st->refcount++; |
344 | 0 | return st; |
345 | 0 | } |
346 | | /** |
347 | | * fu_struct_acpi_phat_version_element_unref: (skip): |
348 | | **/ |
349 | | void |
350 | | fu_struct_acpi_phat_version_element_unref(FuStructAcpiPhatVersionElement *st) |
351 | 35.4k | { |
352 | 35.4k | g_return_if_fail(st != NULL); |
353 | 35.4k | if (st->refcount == 0) { |
354 | 0 | g_critical("FuStructAcpiPhatVersionElement refcount already zero"); |
355 | 0 | return; |
356 | 0 | } |
357 | 35.4k | if (--st->refcount > 0) |
358 | 0 | return; |
359 | 35.4k | if (st->buf != NULL) |
360 | 29.5k | g_byte_array_unref(st->buf); |
361 | 35.4k | g_free(st); |
362 | 35.4k | } |
363 | | /** |
364 | | * fu_struct_acpi_phat_version_element_new_internal: (skip): |
365 | | **/ |
366 | | static FuStructAcpiPhatVersionElement * |
367 | | fu_struct_acpi_phat_version_element_new_internal(void) |
368 | 35.4k | { |
369 | 35.4k | FuStructAcpiPhatVersionElement *st = g_new0(FuStructAcpiPhatVersionElement, 1); |
370 | 35.4k | st->refcount = 1; |
371 | 35.4k | return st; |
372 | 35.4k | } |
373 | | |
374 | | /* getters */ |
375 | | /** |
376 | | * fu_struct_acpi_phat_version_element_get_component_id: (skip): |
377 | | **/ |
378 | | const fwupd_guid_t * |
379 | | fu_struct_acpi_phat_version_element_get_component_id(const FuStructAcpiPhatVersionElement *st) |
380 | 29.5k | { |
381 | 29.5k | g_return_val_if_fail(st != NULL, NULL); |
382 | 29.5k | return (const fwupd_guid_t *) (st->buf->data + 0); |
383 | 29.5k | } |
384 | | /** |
385 | | * fu_struct_acpi_phat_version_element_get_version_value: (skip): |
386 | | **/ |
387 | | guint64 |
388 | | fu_struct_acpi_phat_version_element_get_version_value(const FuStructAcpiPhatVersionElement *st) |
389 | 29.5k | { |
390 | 29.5k | g_return_val_if_fail(st != NULL, 0x0); |
391 | 29.5k | return fu_memread_uint64(st->buf->data + 16, G_LITTLE_ENDIAN); |
392 | 29.5k | } |
393 | | /** |
394 | | * fu_struct_acpi_phat_version_element_get_producer_id: (skip): |
395 | | **/ |
396 | | gchar * |
397 | | fu_struct_acpi_phat_version_element_get_producer_id(const FuStructAcpiPhatVersionElement *st) |
398 | 29.5k | { |
399 | 29.5k | g_return_val_if_fail(st != NULL, NULL); |
400 | 29.5k | return fu_memstrsafe(st->buf->data, st->buf->len, 24, 4, NULL); |
401 | 29.5k | } |
402 | | |
403 | | /* setters */ |
404 | | /** |
405 | | * fu_struct_acpi_phat_version_element_set_component_id: (skip): |
406 | | **/ |
407 | | void |
408 | | fu_struct_acpi_phat_version_element_set_component_id(FuStructAcpiPhatVersionElement *st, const fwupd_guid_t *value) |
409 | 5.90k | { |
410 | 5.90k | g_return_if_fail(st != NULL); |
411 | 5.90k | g_return_if_fail(value != NULL); |
412 | 5.90k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
413 | 5.90k | } |
414 | | /** |
415 | | * fu_struct_acpi_phat_version_element_set_version_value: (skip): |
416 | | **/ |
417 | | void |
418 | | fu_struct_acpi_phat_version_element_set_version_value(FuStructAcpiPhatVersionElement *st, guint64 value) |
419 | 5.90k | { |
420 | 5.90k | g_return_if_fail(st != NULL); |
421 | 5.90k | fu_memwrite_uint64(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
422 | 5.90k | } |
423 | | /** |
424 | | * fu_struct_acpi_phat_version_element_set_producer_id: (skip): |
425 | | **/ |
426 | | gboolean |
427 | | fu_struct_acpi_phat_version_element_set_producer_id(FuStructAcpiPhatVersionElement *st, const gchar *value, GError **error) |
428 | 5.90k | { |
429 | 5.90k | gsize len; |
430 | 5.90k | g_return_val_if_fail(st != NULL, FALSE); |
431 | 5.90k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
432 | 5.90k | if (value == NULL) { |
433 | 4.00k | memset(st->buf->data + 24, 0x0, 4); |
434 | 4.00k | return TRUE; |
435 | 4.00k | } |
436 | 1.89k | len = strlen(value); |
437 | 1.89k | if (len > 4) { |
438 | 0 | g_set_error(error, |
439 | 0 | FWUPD_ERROR, |
440 | 0 | FWUPD_ERROR_INVALID_DATA, |
441 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructAcpiPhatVersionElement.producer_id (0x%x bytes)", |
442 | 0 | value, (guint) len, (guint) 4); |
443 | 0 | return FALSE; |
444 | 0 | } |
445 | 1.89k | return fu_memcpy_safe(st->buf->data, st->buf->len, 24, (const guint8 *)value, len, 0x0, len, error); |
446 | 1.89k | } |
447 | | /** |
448 | | * fu_struct_acpi_phat_version_element_new: (skip): |
449 | | **/ |
450 | | FuStructAcpiPhatVersionElement * |
451 | | fu_struct_acpi_phat_version_element_new(void) |
452 | 5.90k | { |
453 | 5.90k | FuStructAcpiPhatVersionElement *st = fu_struct_acpi_phat_version_element_new_internal(); |
454 | 5.90k | st->buf = g_byte_array_sized_new(28); |
455 | 5.90k | fu_byte_array_set_size(st->buf, 28, 0x0); |
456 | 5.90k | return st; |
457 | 5.90k | } |
458 | | /** |
459 | | * fu_struct_acpi_phat_version_element_to_string: (skip): |
460 | | **/ |
461 | | static gchar * |
462 | | fu_struct_acpi_phat_version_element_to_string(const FuStructAcpiPhatVersionElement *st) |
463 | 0 | { |
464 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionElement:\n"); |
465 | 0 | g_return_val_if_fail(st != NULL, NULL); |
466 | 0 | { |
467 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_acpi_phat_version_element_get_component_id(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
468 | 0 | g_string_append_printf(str, " component_id: %s\n", tmp); |
469 | 0 | } |
470 | 0 | g_string_append_printf(str, " version_value: 0x%x\n", |
471 | 0 | (guint) fu_struct_acpi_phat_version_element_get_version_value(st)); |
472 | 0 | { |
473 | 0 | g_autofree gchar *tmp = fu_struct_acpi_phat_version_element_get_producer_id(st); |
474 | 0 | if (tmp != NULL) |
475 | 0 | g_string_append_printf(str, " producer_id: %s\n", tmp); |
476 | 0 | } |
477 | 0 | if (str->len > 0) |
478 | 0 | g_string_set_size(str, str->len - 1); |
479 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
480 | 0 | } |
481 | | static gboolean |
482 | | fu_struct_acpi_phat_version_element_validate_internal(FuStructAcpiPhatVersionElement *st, GError **error) |
483 | 29.5k | { |
484 | 29.5k | g_return_val_if_fail(st != NULL, FALSE); |
485 | 29.5k | return TRUE; |
486 | 29.5k | } |
487 | | static gboolean |
488 | | fu_struct_acpi_phat_version_element_parse_internal(FuStructAcpiPhatVersionElement *st, GError **error) |
489 | 29.5k | { |
490 | 29.5k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
491 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_version_element_to_string(st); |
492 | 0 | g_debug("%s", str); |
493 | 0 | } |
494 | 29.5k | if (!fu_struct_acpi_phat_version_element_validate_internal(st, error)) |
495 | 0 | return FALSE; |
496 | 29.5k | return TRUE; |
497 | 29.5k | } |
498 | | /** |
499 | | * fu_struct_acpi_phat_version_element_parse_stream: (skip): |
500 | | **/ |
501 | | FuStructAcpiPhatVersionElement * |
502 | | fu_struct_acpi_phat_version_element_parse_stream(GInputStream *stream, gsize offset, GError **error) |
503 | 29.5k | { |
504 | 29.5k | g_autoptr(FuStructAcpiPhatVersionElement) st = fu_struct_acpi_phat_version_element_new_internal(); |
505 | 29.5k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
506 | 29.5k | if (st->buf == NULL) { |
507 | 0 | g_prefix_error(error, "FuStructAcpiPhatVersionElement failed read of 0x%x: ", (guint) 28); |
508 | 0 | return NULL; |
509 | 0 | } |
510 | 29.5k | if (st->buf->len != 28) { |
511 | 0 | g_set_error(error, |
512 | 0 | FWUPD_ERROR, |
513 | 0 | FWUPD_ERROR_INVALID_DATA, |
514 | 0 | "FuStructAcpiPhatVersionElement requested 0x%x and got 0x%x", |
515 | 0 | (guint) 28, |
516 | 0 | (guint) st->buf->len); |
517 | 0 | return NULL; |
518 | 0 | } |
519 | 29.5k | if (!fu_struct_acpi_phat_version_element_parse_internal(st, error)) |
520 | 0 | return NULL; |
521 | 29.5k | return g_steal_pointer(&st); |
522 | 29.5k | } |
523 | | /** |
524 | | * fu_struct_acpi_phat_version_record_ref: (skip): |
525 | | **/ |
526 | | FuStructAcpiPhatVersionRecord * |
527 | | fu_struct_acpi_phat_version_record_ref(FuStructAcpiPhatVersionRecord *st) |
528 | 0 | { |
529 | 0 | g_return_val_if_fail(st != NULL, NULL); |
530 | 0 | st->refcount++; |
531 | 0 | return st; |
532 | 0 | } |
533 | | /** |
534 | | * fu_struct_acpi_phat_version_record_unref: (skip): |
535 | | **/ |
536 | | void |
537 | | fu_struct_acpi_phat_version_record_unref(FuStructAcpiPhatVersionRecord *st) |
538 | 26.4k | { |
539 | 26.4k | g_return_if_fail(st != NULL); |
540 | 26.4k | if (st->refcount == 0) { |
541 | 0 | g_critical("FuStructAcpiPhatVersionRecord refcount already zero"); |
542 | 0 | return; |
543 | 0 | } |
544 | 26.4k | if (--st->refcount > 0) |
545 | 0 | return; |
546 | 26.4k | if (st->buf != NULL) |
547 | 20.2k | g_byte_array_unref(st->buf); |
548 | 26.4k | g_free(st); |
549 | 26.4k | } |
550 | | /** |
551 | | * fu_struct_acpi_phat_version_record_new_internal: (skip): |
552 | | **/ |
553 | | static FuStructAcpiPhatVersionRecord * |
554 | | fu_struct_acpi_phat_version_record_new_internal(void) |
555 | 26.4k | { |
556 | 26.4k | FuStructAcpiPhatVersionRecord *st = g_new0(FuStructAcpiPhatVersionRecord, 1); |
557 | 26.4k | st->refcount = 1; |
558 | 26.4k | return st; |
559 | 26.4k | } |
560 | | |
561 | | /* getters */ |
562 | | /** |
563 | | * fu_struct_acpi_phat_version_record_get_signature: (skip): |
564 | | **/ |
565 | | guint16 |
566 | | fu_struct_acpi_phat_version_record_get_signature(const FuStructAcpiPhatVersionRecord *st) |
567 | 0 | { |
568 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
569 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
570 | 0 | } |
571 | | /** |
572 | | * fu_struct_acpi_phat_version_record_get_rcdlen: (skip): |
573 | | **/ |
574 | | guint16 |
575 | | fu_struct_acpi_phat_version_record_get_rcdlen(const FuStructAcpiPhatVersionRecord *st) |
576 | 0 | { |
577 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
578 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
579 | 0 | } |
580 | | /** |
581 | | * fu_struct_acpi_phat_version_record_get_version: (skip): |
582 | | **/ |
583 | | guint8 |
584 | | fu_struct_acpi_phat_version_record_get_version(const FuStructAcpiPhatVersionRecord *st) |
585 | 0 | { |
586 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
587 | 0 | return st->buf->data[4]; |
588 | 0 | } |
589 | | /** |
590 | | * fu_struct_acpi_phat_version_record_get_record_count: (skip): |
591 | | **/ |
592 | | guint32 |
593 | | fu_struct_acpi_phat_version_record_get_record_count(const FuStructAcpiPhatVersionRecord *st) |
594 | 20.1k | { |
595 | 20.1k | g_return_val_if_fail(st != NULL, 0x0); |
596 | 20.1k | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
597 | 20.1k | } |
598 | | |
599 | | /* setters */ |
600 | | /** |
601 | | * fu_struct_acpi_phat_version_record_set_signature: (skip): |
602 | | **/ |
603 | | void |
604 | | fu_struct_acpi_phat_version_record_set_signature(FuStructAcpiPhatVersionRecord *st, guint16 value) |
605 | 6.27k | { |
606 | 6.27k | g_return_if_fail(st != NULL); |
607 | 6.27k | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
608 | 6.27k | } |
609 | | /** |
610 | | * fu_struct_acpi_phat_version_record_set_rcdlen: (skip): |
611 | | **/ |
612 | | void |
613 | | fu_struct_acpi_phat_version_record_set_rcdlen(FuStructAcpiPhatVersionRecord *st, guint16 value) |
614 | 6.27k | { |
615 | 6.27k | g_return_if_fail(st != NULL); |
616 | 6.27k | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
617 | 6.27k | } |
618 | | /** |
619 | | * fu_struct_acpi_phat_version_record_set_version: (skip): |
620 | | **/ |
621 | | void |
622 | | fu_struct_acpi_phat_version_record_set_version(FuStructAcpiPhatVersionRecord *st, guint8 value) |
623 | 6.27k | { |
624 | 6.27k | g_return_if_fail(st != NULL); |
625 | 6.27k | st->buf->data[4] = value; |
626 | 6.27k | } |
627 | | /** |
628 | | * fu_struct_acpi_phat_version_record_set_record_count: (skip): |
629 | | **/ |
630 | | void |
631 | | fu_struct_acpi_phat_version_record_set_record_count(FuStructAcpiPhatVersionRecord *st, guint32 value) |
632 | 6.27k | { |
633 | 6.27k | g_return_if_fail(st != NULL); |
634 | 6.27k | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
635 | 6.27k | } |
636 | | /** |
637 | | * fu_struct_acpi_phat_version_record_new: (skip): |
638 | | **/ |
639 | | FuStructAcpiPhatVersionRecord * |
640 | | fu_struct_acpi_phat_version_record_new(void) |
641 | 6.27k | { |
642 | 6.27k | FuStructAcpiPhatVersionRecord *st = fu_struct_acpi_phat_version_record_new_internal(); |
643 | 6.27k | st->buf = g_byte_array_sized_new(12); |
644 | 6.27k | fu_byte_array_set_size(st->buf, 12, 0x0); |
645 | 6.27k | fu_struct_acpi_phat_version_record_set_signature(st, 0x0); |
646 | 6.27k | return st; |
647 | 6.27k | } |
648 | | /** |
649 | | * fu_struct_acpi_phat_version_record_to_string: (skip): |
650 | | **/ |
651 | | static gchar * |
652 | | fu_struct_acpi_phat_version_record_to_string(const FuStructAcpiPhatVersionRecord *st) |
653 | 0 | { |
654 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiPhatVersionRecord:\n"); |
655 | 0 | g_return_val_if_fail(st != NULL, NULL); |
656 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
657 | 0 | (guint) fu_struct_acpi_phat_version_record_get_signature(st)); |
658 | 0 | g_string_append_printf(str, " rcdlen: 0x%x\n", |
659 | 0 | (guint) fu_struct_acpi_phat_version_record_get_rcdlen(st)); |
660 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
661 | 0 | (guint) fu_struct_acpi_phat_version_record_get_version(st)); |
662 | 0 | g_string_append_printf(str, " record_count: 0x%x\n", |
663 | 0 | (guint) fu_struct_acpi_phat_version_record_get_record_count(st)); |
664 | 0 | if (str->len > 0) |
665 | 0 | g_string_set_size(str, str->len - 1); |
666 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
667 | 0 | } |
668 | | static gboolean |
669 | | fu_struct_acpi_phat_version_record_validate_internal(FuStructAcpiPhatVersionRecord *st, GError **error) |
670 | 20.1k | { |
671 | 20.1k | g_return_val_if_fail(st != NULL, FALSE); |
672 | 20.1k | return TRUE; |
673 | 20.1k | } |
674 | | static gboolean |
675 | | fu_struct_acpi_phat_version_record_parse_internal(FuStructAcpiPhatVersionRecord *st, GError **error) |
676 | 20.1k | { |
677 | 20.1k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
678 | 0 | g_autofree gchar *str = fu_struct_acpi_phat_version_record_to_string(st); |
679 | 0 | g_debug("%s", str); |
680 | 0 | } |
681 | 20.1k | if (!fu_struct_acpi_phat_version_record_validate_internal(st, error)) |
682 | 0 | return FALSE; |
683 | 20.1k | return TRUE; |
684 | 20.1k | } |
685 | | /** |
686 | | * fu_struct_acpi_phat_version_record_parse_stream: (skip): |
687 | | **/ |
688 | | FuStructAcpiPhatVersionRecord * |
689 | | fu_struct_acpi_phat_version_record_parse_stream(GInputStream *stream, gsize offset, GError **error) |
690 | 20.2k | { |
691 | 20.2k | g_autoptr(FuStructAcpiPhatVersionRecord) st = fu_struct_acpi_phat_version_record_new_internal(); |
692 | 20.2k | st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
693 | 20.2k | if (st->buf == NULL) { |
694 | 0 | g_prefix_error(error, "FuStructAcpiPhatVersionRecord failed read of 0x%x: ", (guint) 12); |
695 | 0 | return NULL; |
696 | 0 | } |
697 | 20.2k | if (st->buf->len != 12) { |
698 | 38 | g_set_error(error, |
699 | 38 | FWUPD_ERROR, |
700 | 38 | FWUPD_ERROR_INVALID_DATA, |
701 | 38 | "FuStructAcpiPhatVersionRecord requested 0x%x and got 0x%x", |
702 | 38 | (guint) 12, |
703 | 38 | (guint) st->buf->len); |
704 | 38 | return NULL; |
705 | 38 | } |
706 | 20.1k | if (!fu_struct_acpi_phat_version_record_parse_internal(st, error)) |
707 | 0 | return NULL; |
708 | 20.1k | return g_steal_pointer(&st); |
709 | 20.1k | } |