/work/fu-realtek-alc408x-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-realtek-alc408x-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-bytes.h" |
14 | | #include "fu-mem.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 | | |
23 | | /** |
24 | | * fu_struct_realtek_alc408x_info_ref: (skip): |
25 | | **/ |
26 | | FuStructRealtekAlc408xInfo * |
27 | | fu_struct_realtek_alc408x_info_ref(FuStructRealtekAlc408xInfo *st) |
28 | 0 | { |
29 | 0 | g_return_val_if_fail(st != NULL, NULL); |
30 | 0 | st->refcount++; |
31 | 0 | return st; |
32 | 0 | } |
33 | | /** |
34 | | * fu_struct_realtek_alc408x_info_unref: (skip): |
35 | | **/ |
36 | | void |
37 | | fu_struct_realtek_alc408x_info_unref(FuStructRealtekAlc408xInfo *st) |
38 | 0 | { |
39 | 0 | g_return_if_fail(st != NULL); |
40 | 0 | if (st->refcount == 0) { |
41 | 0 | g_critical("FuStructRealtekAlc408xInfo refcount already zero"); |
42 | 0 | return; |
43 | 0 | } |
44 | 0 | if (--st->refcount > 0) |
45 | 0 | return; |
46 | 0 | if (st->buf != NULL) |
47 | 0 | g_byte_array_unref(st->buf); |
48 | 0 | g_free(st); |
49 | 0 | } |
50 | | /** |
51 | | * fu_struct_realtek_alc408x_info_new_internal: (skip): |
52 | | **/ |
53 | | static FuStructRealtekAlc408xInfo * |
54 | | fu_struct_realtek_alc408x_info_new_internal(void) |
55 | 0 | { |
56 | 0 | FuStructRealtekAlc408xInfo *st = g_new0(FuStructRealtekAlc408xInfo, 1); |
57 | 0 | st->refcount = 1; |
58 | 0 | return st; |
59 | 0 | } |
60 | | |
61 | | /* getters */ |
62 | | /** |
63 | | * fu_struct_realtek_alc408x_info_get_vid: (skip): |
64 | | **/ |
65 | | guint16 |
66 | | fu_struct_realtek_alc408x_info_get_vid(const FuStructRealtekAlc408xInfo *st) |
67 | 0 | { |
68 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
69 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
70 | 0 | } |
71 | | /** |
72 | | * fu_struct_realtek_alc408x_info_get_pid: (skip): |
73 | | **/ |
74 | | guint16 |
75 | | fu_struct_realtek_alc408x_info_get_pid(const FuStructRealtekAlc408xInfo *st) |
76 | 0 | { |
77 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
78 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
79 | 0 | } |
80 | | /** |
81 | | * fu_struct_realtek_alc408x_info_get_chip_id: (skip): |
82 | | **/ |
83 | | guint16 |
84 | | fu_struct_realtek_alc408x_info_get_chip_id(const FuStructRealtekAlc408xInfo *st) |
85 | 0 | { |
86 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
87 | 0 | return fu_memread_uint16(st->buf->data + 6, G_BIG_ENDIAN); |
88 | 0 | } |
89 | | /** |
90 | | * fu_struct_realtek_alc408x_info_get_build_date: (skip): |
91 | | **/ |
92 | | gchar * |
93 | | fu_struct_realtek_alc408x_info_get_build_date(const FuStructRealtekAlc408xInfo *st) |
94 | 0 | { |
95 | 0 | g_return_val_if_fail(st != NULL, NULL); |
96 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 16, 8, NULL); |
97 | 0 | } |
98 | | /** |
99 | | * fu_struct_realtek_alc408x_info_get_signature: (skip): |
100 | | **/ |
101 | | static gchar * |
102 | | fu_struct_realtek_alc408x_info_get_signature(const FuStructRealtekAlc408xInfo *st) |
103 | 0 | { |
104 | 0 | g_return_val_if_fail(st != NULL, NULL); |
105 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 24, 8, NULL); |
106 | 0 | } |
107 | | /** |
108 | | * fu_struct_realtek_alc408x_info_get_magic: (skip): |
109 | | **/ |
110 | | static guint32 |
111 | | fu_struct_realtek_alc408x_info_get_magic(const FuStructRealtekAlc408xInfo *st) |
112 | 0 | { |
113 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
114 | 0 | return fu_memread_uint32(st->buf->data + 66, G_LITTLE_ENDIAN); |
115 | 0 | } |
116 | | /** |
117 | | * fu_struct_realtek_alc408x_info_get_chip: (skip): |
118 | | **/ |
119 | | guint16 |
120 | | fu_struct_realtek_alc408x_info_get_chip(const FuStructRealtekAlc408xInfo *st) |
121 | 0 | { |
122 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
123 | 0 | return fu_memread_uint16(st->buf->data + 70, G_LITTLE_ENDIAN); |
124 | 0 | } |
125 | | /** |
126 | | * fu_struct_realtek_alc408x_info_get_version_hi: (skip): |
127 | | **/ |
128 | | guint32 |
129 | | fu_struct_realtek_alc408x_info_get_version_hi(const FuStructRealtekAlc408xInfo *st) |
130 | 0 | { |
131 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
132 | 0 | return fu_memread_uint32(st->buf->data + 76, G_LITTLE_ENDIAN); |
133 | 0 | } |
134 | | /** |
135 | | * fu_struct_realtek_alc408x_info_get_version_lo: (skip): |
136 | | **/ |
137 | | guint32 |
138 | | fu_struct_realtek_alc408x_info_get_version_lo(const FuStructRealtekAlc408xInfo *st) |
139 | 0 | { |
140 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
141 | 0 | return fu_memread_uint32(st->buf->data + 80, G_LITTLE_ENDIAN); |
142 | 0 | } |
143 | | |
144 | | /* setters */ |
145 | | /** |
146 | | * fu_struct_realtek_alc408x_info_to_string: (skip): |
147 | | **/ |
148 | | static gchar * |
149 | | fu_struct_realtek_alc408x_info_to_string(const FuStructRealtekAlc408xInfo *st) |
150 | 0 | { |
151 | 0 | g_autoptr(GString) str = g_string_new("FuStructRealtekAlc408xInfo:\n"); |
152 | 0 | g_return_val_if_fail(st != NULL, NULL); |
153 | 0 | g_string_append_printf(str, " vid: 0x%x\n", |
154 | 0 | (guint) fu_struct_realtek_alc408x_info_get_vid(st)); |
155 | 0 | g_string_append_printf(str, " pid: 0x%x\n", |
156 | 0 | (guint) fu_struct_realtek_alc408x_info_get_pid(st)); |
157 | 0 | g_string_append_printf(str, " chip_id: 0x%x\n", |
158 | 0 | (guint) fu_struct_realtek_alc408x_info_get_chip_id(st)); |
159 | 0 | { |
160 | 0 | g_autofree gchar *tmp = fu_struct_realtek_alc408x_info_get_build_date(st); |
161 | 0 | if (tmp != NULL) |
162 | 0 | g_string_append_printf(str, " build_date: %s\n", tmp); |
163 | 0 | } |
164 | 0 | { |
165 | 0 | g_autofree gchar *tmp = fu_struct_realtek_alc408x_info_get_signature(st); |
166 | 0 | if (tmp != NULL) |
167 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
168 | 0 | } |
169 | 0 | g_string_append_printf(str, " magic: 0x%x\n", |
170 | 0 | (guint) fu_struct_realtek_alc408x_info_get_magic(st)); |
171 | 0 | g_string_append_printf(str, " chip: 0x%x\n", |
172 | 0 | (guint) fu_struct_realtek_alc408x_info_get_chip(st)); |
173 | 0 | g_string_append_printf(str, " version_hi: 0x%x\n", |
174 | 0 | (guint) fu_struct_realtek_alc408x_info_get_version_hi(st)); |
175 | 0 | g_string_append_printf(str, " version_lo: 0x%x\n", |
176 | 0 | (guint) fu_struct_realtek_alc408x_info_get_version_lo(st)); |
177 | 0 | if (str->len > 0) |
178 | 0 | g_string_set_size(str, str->len - 1); |
179 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
180 | 0 | } |
181 | | static gboolean |
182 | | fu_struct_realtek_alc408x_info_validate_internal(FuStructRealtekAlc408xInfo *st, GError **error) |
183 | 0 | { |
184 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
185 | 0 | if (strncmp((const gchar *) (st->buf->data + 24), "REALSIL", 8) != 0) { |
186 | 0 | g_autofree gchar *str = fu_struct_realtek_alc408x_info_get_signature(st); |
187 | 0 | g_set_error(error, |
188 | 0 | FWUPD_ERROR, |
189 | 0 | FWUPD_ERROR_INVALID_DATA, |
190 | 0 | "constant FuStructRealtekAlc408xInfo.signature was not valid, " |
191 | 0 | "expected 'REALSIL' and got '%s'", |
192 | 0 | str); |
193 | 0 | return FALSE; |
194 | 0 | } |
195 | 0 | if (fu_struct_realtek_alc408x_info_get_magic(st) != 0x12345678) { |
196 | 0 | g_set_error(error, |
197 | 0 | FWUPD_ERROR, |
198 | 0 | FWUPD_ERROR_INVALID_DATA, |
199 | 0 | "constant FuStructRealtekAlc408xInfo.magic was not valid, " |
200 | 0 | "expected 0x%x and got 0x%x", |
201 | 0 | (guint) 0x12345678, |
202 | 0 | (guint) fu_struct_realtek_alc408x_info_get_magic(st)); |
203 | 0 | return FALSE; |
204 | 0 | } |
205 | 0 | return TRUE; |
206 | 0 | } |
207 | | static gboolean |
208 | | fu_struct_realtek_alc408x_info_parse_internal(FuStructRealtekAlc408xInfo *st, GError **error) |
209 | 0 | { |
210 | 0 | if (g_log_get_debug_enabled()) { |
211 | 0 | g_autofree gchar *str = fu_struct_realtek_alc408x_info_to_string(st); |
212 | 0 | g_debug("%s", str); |
213 | 0 | } |
214 | 0 | if (!fu_struct_realtek_alc408x_info_validate_internal(st, error)) |
215 | 0 | return FALSE; |
216 | 0 | return TRUE; |
217 | 0 | } |
218 | | |
219 | | /** |
220 | | * fu_struct_realtek_alc408x_info_parse: (skip): |
221 | | **/ |
222 | | FuStructRealtekAlc408xInfo * |
223 | | fu_struct_realtek_alc408x_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
224 | 0 | { |
225 | 0 | g_autoptr(FuStructRealtekAlc408xInfo) st = fu_struct_realtek_alc408x_info_new_internal(); |
226 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
227 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
228 | 0 | if (!fu_memchk_read(bufsz, offset, 104, error)) { |
229 | 0 | g_prefix_error_literal(error, "invalid struct FuStructRealtekAlc408xInfo: "); |
230 | 0 | return NULL; |
231 | 0 | } |
232 | 0 | st->buf = g_byte_array_new(); |
233 | 0 | g_byte_array_append(st->buf, buf + offset, 104); |
234 | 0 | if (!fu_struct_realtek_alc408x_info_parse_internal(st, error)) |
235 | 0 | return NULL; |
236 | 0 | return g_steal_pointer(&st); |
237 | 0 | } |
238 | | /** |
239 | | * fu_struct_realtek_alc408x_fw_hdr_ref: (skip): |
240 | | **/ |
241 | | FuStructRealtekAlc408xFwHdr * |
242 | | fu_struct_realtek_alc408x_fw_hdr_ref(FuStructRealtekAlc408xFwHdr *st) |
243 | 0 | { |
244 | 0 | g_return_val_if_fail(st != NULL, NULL); |
245 | 0 | st->refcount++; |
246 | 0 | return st; |
247 | 0 | } |
248 | | /** |
249 | | * fu_struct_realtek_alc408x_fw_hdr_unref: (skip): |
250 | | **/ |
251 | | void |
252 | | fu_struct_realtek_alc408x_fw_hdr_unref(FuStructRealtekAlc408xFwHdr *st) |
253 | 0 | { |
254 | 0 | g_return_if_fail(st != NULL); |
255 | 0 | if (st->refcount == 0) { |
256 | 0 | g_critical("FuStructRealtekAlc408xFwHdr refcount already zero"); |
257 | 0 | return; |
258 | 0 | } |
259 | 0 | if (--st->refcount > 0) |
260 | 0 | return; |
261 | 0 | if (st->buf != NULL) |
262 | 0 | g_byte_array_unref(st->buf); |
263 | 0 | g_free(st); |
264 | 0 | } |
265 | | /** |
266 | | * fu_struct_realtek_alc408x_fw_hdr_new_internal: (skip): |
267 | | **/ |
268 | | static FuStructRealtekAlc408xFwHdr * |
269 | | fu_struct_realtek_alc408x_fw_hdr_new_internal(void) |
270 | 0 | { |
271 | 0 | FuStructRealtekAlc408xFwHdr *st = g_new0(FuStructRealtekAlc408xFwHdr, 1); |
272 | 0 | st->refcount = 1; |
273 | 0 | return st; |
274 | 0 | } |
275 | | |
276 | | /* getters */ |
277 | | /** |
278 | | * fu_struct_realtek_alc408x_fw_hdr_get_unknown1: (skip): |
279 | | **/ |
280 | | guint16 |
281 | | fu_struct_realtek_alc408x_fw_hdr_get_unknown1(const FuStructRealtekAlc408xFwHdr *st) |
282 | 0 | { |
283 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
284 | 0 | return fu_memread_uint16(st->buf->data + 0, G_BIG_ENDIAN); |
285 | 0 | } |
286 | | /** |
287 | | * fu_struct_realtek_alc408x_fw_hdr_get_magic: (skip): |
288 | | **/ |
289 | | static guint32 |
290 | | fu_struct_realtek_alc408x_fw_hdr_get_magic(const FuStructRealtekAlc408xFwHdr *st) |
291 | 0 | { |
292 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
293 | 0 | return fu_memread_uint32(st->buf->data + 2, G_BIG_ENDIAN); |
294 | 0 | } |
295 | | /** |
296 | | * fu_struct_realtek_alc408x_fw_hdr_get_chip: (skip): |
297 | | **/ |
298 | | guint16 |
299 | | fu_struct_realtek_alc408x_fw_hdr_get_chip(const FuStructRealtekAlc408xFwHdr *st) |
300 | 0 | { |
301 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
302 | 0 | return fu_memread_uint16(st->buf->data + 6, G_BIG_ENDIAN); |
303 | 0 | } |
304 | | /** |
305 | | * fu_struct_realtek_alc408x_fw_hdr_get_unknown2: (skip): |
306 | | **/ |
307 | | guint32 |
308 | | fu_struct_realtek_alc408x_fw_hdr_get_unknown2(const FuStructRealtekAlc408xFwHdr *st) |
309 | 0 | { |
310 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
311 | 0 | return fu_memread_uint32(st->buf->data + 8, G_BIG_ENDIAN); |
312 | 0 | } |
313 | | /** |
314 | | * fu_struct_realtek_alc408x_fw_hdr_get_version_hi: (skip): |
315 | | **/ |
316 | | guint32 |
317 | | fu_struct_realtek_alc408x_fw_hdr_get_version_hi(const FuStructRealtekAlc408xFwHdr *st) |
318 | 0 | { |
319 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
320 | 0 | return fu_memread_uint32(st->buf->data + 12, G_BIG_ENDIAN); |
321 | 0 | } |
322 | | /** |
323 | | * fu_struct_realtek_alc408x_fw_hdr_get_version_lo: (skip): |
324 | | **/ |
325 | | guint32 |
326 | | fu_struct_realtek_alc408x_fw_hdr_get_version_lo(const FuStructRealtekAlc408xFwHdr *st) |
327 | 0 | { |
328 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
329 | 0 | return fu_memread_uint32(st->buf->data + 16, G_BIG_ENDIAN); |
330 | 0 | } |
331 | | |
332 | | /* setters */ |
333 | | /** |
334 | | * fu_struct_realtek_alc408x_fw_hdr_set_unknown1: (skip): |
335 | | **/ |
336 | | void |
337 | | fu_struct_realtek_alc408x_fw_hdr_set_unknown1(FuStructRealtekAlc408xFwHdr *st, guint16 value) |
338 | 0 | { |
339 | 0 | g_return_if_fail(st != NULL); |
340 | 0 | fu_memwrite_uint16(st->buf->data + 0, value, G_BIG_ENDIAN); |
341 | 0 | } |
342 | | /** |
343 | | * fu_struct_realtek_alc408x_fw_hdr_set_magic: (skip): |
344 | | **/ |
345 | | static void |
346 | | fu_struct_realtek_alc408x_fw_hdr_set_magic(FuStructRealtekAlc408xFwHdr *st, guint32 value) |
347 | 0 | { |
348 | 0 | g_return_if_fail(st != NULL); |
349 | 0 | fu_memwrite_uint32(st->buf->data + 2, value, G_BIG_ENDIAN); |
350 | 0 | } |
351 | | /** |
352 | | * fu_struct_realtek_alc408x_fw_hdr_set_chip: (skip): |
353 | | **/ |
354 | | void |
355 | | fu_struct_realtek_alc408x_fw_hdr_set_chip(FuStructRealtekAlc408xFwHdr *st, guint16 value) |
356 | 0 | { |
357 | 0 | g_return_if_fail(st != NULL); |
358 | 0 | fu_memwrite_uint16(st->buf->data + 6, value, G_BIG_ENDIAN); |
359 | 0 | } |
360 | | /** |
361 | | * fu_struct_realtek_alc408x_fw_hdr_set_unknown2: (skip): |
362 | | **/ |
363 | | void |
364 | | fu_struct_realtek_alc408x_fw_hdr_set_unknown2(FuStructRealtekAlc408xFwHdr *st, guint32 value) |
365 | 0 | { |
366 | 0 | g_return_if_fail(st != NULL); |
367 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_BIG_ENDIAN); |
368 | 0 | } |
369 | | /** |
370 | | * fu_struct_realtek_alc408x_fw_hdr_set_version_hi: (skip): |
371 | | **/ |
372 | | void |
373 | | fu_struct_realtek_alc408x_fw_hdr_set_version_hi(FuStructRealtekAlc408xFwHdr *st, guint32 value) |
374 | 0 | { |
375 | 0 | g_return_if_fail(st != NULL); |
376 | 0 | fu_memwrite_uint32(st->buf->data + 12, value, G_BIG_ENDIAN); |
377 | 0 | } |
378 | | /** |
379 | | * fu_struct_realtek_alc408x_fw_hdr_set_version_lo: (skip): |
380 | | **/ |
381 | | void |
382 | | fu_struct_realtek_alc408x_fw_hdr_set_version_lo(FuStructRealtekAlc408xFwHdr *st, guint32 value) |
383 | 0 | { |
384 | 0 | g_return_if_fail(st != NULL); |
385 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_BIG_ENDIAN); |
386 | 0 | } |
387 | | /** |
388 | | * fu_struct_realtek_alc408x_fw_hdr_new: (skip): |
389 | | **/ |
390 | | FuStructRealtekAlc408xFwHdr * |
391 | | fu_struct_realtek_alc408x_fw_hdr_new(void) |
392 | 0 | { |
393 | 0 | FuStructRealtekAlc408xFwHdr *st = fu_struct_realtek_alc408x_fw_hdr_new_internal(); |
394 | 0 | st->buf = g_byte_array_sized_new(20); |
395 | 0 | fu_byte_array_set_size(st->buf, 20, 0x0); |
396 | 0 | fu_struct_realtek_alc408x_fw_hdr_set_unknown1(st, 0x3114); |
397 | 0 | fu_struct_realtek_alc408x_fw_hdr_set_magic(st, 0x12345678); |
398 | 0 | fu_struct_realtek_alc408x_fw_hdr_set_chip(st, 0x4080); |
399 | 0 | fu_struct_realtek_alc408x_fw_hdr_set_unknown2(st, 0x1); |
400 | 0 | return st; |
401 | 0 | } |
402 | | /** |
403 | | * fu_struct_realtek_alc408x_fw_hdr_to_string: (skip): |
404 | | **/ |
405 | | static gchar * |
406 | | fu_struct_realtek_alc408x_fw_hdr_to_string(const FuStructRealtekAlc408xFwHdr *st) |
407 | 0 | { |
408 | 0 | g_autoptr(GString) str = g_string_new("FuStructRealtekAlc408xFwHdr:\n"); |
409 | 0 | g_return_val_if_fail(st != NULL, NULL); |
410 | 0 | g_string_append_printf(str, " unknown1: 0x%x\n", |
411 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_unknown1(st)); |
412 | 0 | g_string_append_printf(str, " magic: 0x%x\n", |
413 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_magic(st)); |
414 | 0 | g_string_append_printf(str, " chip: 0x%x\n", |
415 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_chip(st)); |
416 | 0 | g_string_append_printf(str, " unknown2: 0x%x\n", |
417 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_unknown2(st)); |
418 | 0 | g_string_append_printf(str, " version_hi: 0x%x\n", |
419 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_version_hi(st)); |
420 | 0 | g_string_append_printf(str, " version_lo: 0x%x\n", |
421 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_version_lo(st)); |
422 | 0 | if (str->len > 0) |
423 | 0 | g_string_set_size(str, str->len - 1); |
424 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
425 | 0 | } |
426 | | static gboolean |
427 | | fu_struct_realtek_alc408x_fw_hdr_validate_internal(FuStructRealtekAlc408xFwHdr *st, GError **error) |
428 | 0 | { |
429 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
430 | 0 | if (fu_struct_realtek_alc408x_fw_hdr_get_magic(st) != 0x12345678) { |
431 | 0 | g_set_error(error, |
432 | 0 | FWUPD_ERROR, |
433 | 0 | FWUPD_ERROR_INVALID_DATA, |
434 | 0 | "constant FuStructRealtekAlc408xFwHdr.magic was not valid, " |
435 | 0 | "expected 0x%x and got 0x%x", |
436 | 0 | (guint) 0x12345678, |
437 | 0 | (guint) fu_struct_realtek_alc408x_fw_hdr_get_magic(st)); |
438 | 0 | return FALSE; |
439 | 0 | } |
440 | 0 | return TRUE; |
441 | 0 | } |
442 | | /** |
443 | | * fu_struct_realtek_alc408x_fw_hdr_validate_stream: (skip): |
444 | | **/ |
445 | | gboolean |
446 | | fu_struct_realtek_alc408x_fw_hdr_validate_stream(FuInputStream *stream, gsize offset, GError **error) |
447 | 0 | { |
448 | 0 | g_autoptr(FuStructRealtekAlc408xFwHdr) st = fu_struct_realtek_alc408x_fw_hdr_new_internal(); |
449 | 0 | g_return_val_if_fail(FU_IS_INPUT_STREAM(stream), FALSE); |
450 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
451 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
452 | 0 | if (st->buf == NULL) { |
453 | 0 | g_prefix_error(error, "FuStructRealtekAlc408xFwHdr failed read of 0x%x: ", (guint) 20); |
454 | 0 | return FALSE; |
455 | 0 | } |
456 | 0 | if (st->buf->len != 20) { |
457 | 0 | g_set_error(error, |
458 | 0 | FWUPD_ERROR, |
459 | 0 | FWUPD_ERROR_INVALID_DATA, |
460 | 0 | "FuStructRealtekAlc408xFwHdr requested 0x%x and got 0x%x", |
461 | 0 | (guint) 20, |
462 | 0 | (guint) st->buf->len); |
463 | 0 | return FALSE; |
464 | 0 | } |
465 | 0 | return fu_struct_realtek_alc408x_fw_hdr_validate_internal(st, error); |
466 | 0 | } |
467 | | static gboolean |
468 | | fu_struct_realtek_alc408x_fw_hdr_parse_internal(FuStructRealtekAlc408xFwHdr *st, GError **error) |
469 | 0 | { |
470 | 0 | if (g_log_get_debug_enabled()) { |
471 | 0 | g_autofree gchar *str = fu_struct_realtek_alc408x_fw_hdr_to_string(st); |
472 | 0 | g_debug("%s", str); |
473 | 0 | } |
474 | 0 | if (!fu_struct_realtek_alc408x_fw_hdr_validate_internal(st, error)) |
475 | 0 | return FALSE; |
476 | 0 | return TRUE; |
477 | 0 | } |
478 | | |
479 | | /** |
480 | | * fu_struct_realtek_alc408x_fw_hdr_parse: (skip): |
481 | | **/ |
482 | | FuStructRealtekAlc408xFwHdr * |
483 | | fu_struct_realtek_alc408x_fw_hdr_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
484 | 0 | { |
485 | 0 | g_autoptr(FuStructRealtekAlc408xFwHdr) st = fu_struct_realtek_alc408x_fw_hdr_new_internal(); |
486 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
487 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
488 | 0 | if (!fu_memchk_read(bufsz, offset, 20, error)) { |
489 | 0 | g_prefix_error_literal(error, "invalid struct FuStructRealtekAlc408xFwHdr: "); |
490 | 0 | return NULL; |
491 | 0 | } |
492 | 0 | st->buf = g_byte_array_new(); |
493 | 0 | g_byte_array_append(st->buf, buf + offset, 20); |
494 | 0 | if (!fu_struct_realtek_alc408x_fw_hdr_parse_internal(st, error)) |
495 | 0 | return NULL; |
496 | 0 | return g_steal_pointer(&st); |
497 | 0 | } |
498 | | /** |
499 | | * fu_struct_realtek_alc408x_fw_hdr_parse_stream: (skip): |
500 | | **/ |
501 | | FuStructRealtekAlc408xFwHdr * |
502 | | fu_struct_realtek_alc408x_fw_hdr_parse_stream(FuInputStream *stream, gsize offset, GError **error) |
503 | 0 | { |
504 | 0 | g_autoptr(FuStructRealtekAlc408xFwHdr) st = fu_struct_realtek_alc408x_fw_hdr_new_internal(); |
505 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
506 | 0 | if (st->buf == NULL) { |
507 | 0 | g_prefix_error(error, "FuStructRealtekAlc408xFwHdr failed read of 0x%x: ", (guint) 20); |
508 | 0 | return NULL; |
509 | 0 | } |
510 | 0 | if (st->buf->len != 20) { |
511 | 0 | g_set_error(error, |
512 | 0 | FWUPD_ERROR, |
513 | 0 | FWUPD_ERROR_INVALID_DATA, |
514 | 0 | "FuStructRealtekAlc408xFwHdr requested 0x%x and got 0x%x", |
515 | 0 | (guint) 20, |
516 | 0 | (guint) st->buf->len); |
517 | 0 | return NULL; |
518 | 0 | } |
519 | 0 | if (!fu_struct_realtek_alc408x_fw_hdr_parse_internal(st, error)) |
520 | 0 | return NULL; |
521 | 0 | return g_steal_pointer(&st); |
522 | 0 | } |