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