/work/fu-sbatlevel-section-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-sbatlevel-section-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_sbat_level_section_header_ref: (skip): |
23 | | **/ |
24 | | FuStructSbatLevelSectionHeader * |
25 | | fu_struct_sbat_level_section_header_ref(FuStructSbatLevelSectionHeader *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_sbat_level_section_header_unref: (skip): |
33 | | **/ |
34 | | void |
35 | | fu_struct_sbat_level_section_header_unref(FuStructSbatLevelSectionHeader *st) |
36 | 140 | { |
37 | 140 | g_return_if_fail(st != NULL); |
38 | 140 | if (st->refcount == 0) { |
39 | 0 | g_critical("FuStructSbatLevelSectionHeader refcount already zero"); |
40 | 0 | return; |
41 | 0 | } |
42 | 140 | if (--st->refcount > 0) |
43 | 0 | return; |
44 | 140 | if (st->buf != NULL) |
45 | 117 | g_byte_array_unref(st->buf); |
46 | 140 | g_free(st); |
47 | 140 | } |
48 | | /** |
49 | | * fu_struct_sbat_level_section_header_new_internal: (skip): |
50 | | **/ |
51 | | static FuStructSbatLevelSectionHeader * |
52 | | fu_struct_sbat_level_section_header_new_internal(void) |
53 | 140 | { |
54 | 140 | FuStructSbatLevelSectionHeader *st = g_new0(FuStructSbatLevelSectionHeader, 1); |
55 | 140 | st->refcount = 1; |
56 | 140 | return st; |
57 | 140 | } |
58 | | |
59 | | /* getters */ |
60 | | /** |
61 | | * fu_struct_sbat_level_section_header_get_version: (skip): |
62 | | **/ |
63 | | static guint32 |
64 | | fu_struct_sbat_level_section_header_get_version(const FuStructSbatLevelSectionHeader *st) |
65 | 140 | { |
66 | 140 | g_return_val_if_fail(st != NULL, 0x0); |
67 | 140 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
68 | 140 | } |
69 | | /** |
70 | | * fu_struct_sbat_level_section_header_get_previous: (skip): |
71 | | **/ |
72 | | guint32 |
73 | | fu_struct_sbat_level_section_header_get_previous(const FuStructSbatLevelSectionHeader *st) |
74 | 80 | { |
75 | 80 | g_return_val_if_fail(st != NULL, 0x0); |
76 | 80 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
77 | 80 | } |
78 | | /** |
79 | | * fu_struct_sbat_level_section_header_get_latest: (skip): |
80 | | **/ |
81 | | guint32 |
82 | | fu_struct_sbat_level_section_header_get_latest(const FuStructSbatLevelSectionHeader *st) |
83 | 59 | { |
84 | 59 | g_return_val_if_fail(st != NULL, 0x0); |
85 | 59 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
86 | 59 | } |
87 | | |
88 | | /* setters */ |
89 | | /** |
90 | | * fu_struct_sbat_level_section_header_set_version: (skip): |
91 | | **/ |
92 | | static void |
93 | | fu_struct_sbat_level_section_header_set_version(FuStructSbatLevelSectionHeader *st, guint32 value) |
94 | 27 | { |
95 | 27 | g_return_if_fail(st != NULL); |
96 | 27 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
97 | 27 | } |
98 | | /** |
99 | | * fu_struct_sbat_level_section_header_set_previous: (skip): |
100 | | **/ |
101 | | void |
102 | | fu_struct_sbat_level_section_header_set_previous(FuStructSbatLevelSectionHeader *st, guint32 value) |
103 | 27 | { |
104 | 27 | g_return_if_fail(st != NULL); |
105 | 27 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
106 | 27 | } |
107 | | /** |
108 | | * fu_struct_sbat_level_section_header_set_latest: (skip): |
109 | | **/ |
110 | | void |
111 | | fu_struct_sbat_level_section_header_set_latest(FuStructSbatLevelSectionHeader *st, guint32 value) |
112 | 23 | { |
113 | 23 | g_return_if_fail(st != NULL); |
114 | 23 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
115 | 23 | } |
116 | | /** |
117 | | * fu_struct_sbat_level_section_header_new: (skip): |
118 | | **/ |
119 | | FuStructSbatLevelSectionHeader * |
120 | | fu_struct_sbat_level_section_header_new(void) |
121 | 27 | { |
122 | 27 | FuStructSbatLevelSectionHeader *st = fu_struct_sbat_level_section_header_new_internal(); |
123 | 27 | st->buf = g_byte_array_sized_new(12); |
124 | 27 | fu_byte_array_set_size(st->buf, 12, 0x0); |
125 | 27 | fu_struct_sbat_level_section_header_set_version(st, 0x0); |
126 | 27 | return st; |
127 | 27 | } |
128 | | /** |
129 | | * fu_struct_sbat_level_section_header_to_string: (skip): |
130 | | **/ |
131 | | static gchar * |
132 | | fu_struct_sbat_level_section_header_to_string(const FuStructSbatLevelSectionHeader *st) |
133 | 0 | { |
134 | 0 | g_autoptr(GString) str = g_string_new("FuStructSbatLevelSectionHeader:\n"); |
135 | 0 | g_return_val_if_fail(st != NULL, NULL); |
136 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
137 | 0 | (guint) fu_struct_sbat_level_section_header_get_version(st)); |
138 | 0 | g_string_append_printf(str, " previous: 0x%x\n", |
139 | 0 | (guint) fu_struct_sbat_level_section_header_get_previous(st)); |
140 | 0 | g_string_append_printf(str, " latest: 0x%x\n", |
141 | 0 | (guint) fu_struct_sbat_level_section_header_get_latest(st)); |
142 | 0 | if (str->len > 0) |
143 | 0 | g_string_set_size(str, str->len - 1); |
144 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
145 | 0 | } |
146 | | static gboolean |
147 | | fu_struct_sbat_level_section_header_validate_internal(FuStructSbatLevelSectionHeader *st, GError **error) |
148 | 110 | { |
149 | 110 | g_return_val_if_fail(st != NULL, FALSE); |
150 | 110 | if (fu_struct_sbat_level_section_header_get_version(st) != 0x0) { |
151 | 30 | g_set_error(error, |
152 | 30 | FWUPD_ERROR, |
153 | 30 | FWUPD_ERROR_INVALID_DATA, |
154 | 30 | "constant FuStructSbatLevelSectionHeader.version was not valid, " |
155 | 30 | "expected 0x%x and got 0x%x", |
156 | 30 | (guint) 0x0, |
157 | 30 | (guint) fu_struct_sbat_level_section_header_get_version(st)); |
158 | 30 | return FALSE; |
159 | 30 | } |
160 | 80 | return TRUE; |
161 | 110 | } |
162 | | static gboolean |
163 | | fu_struct_sbat_level_section_header_parse_internal(FuStructSbatLevelSectionHeader *st, GError **error) |
164 | 110 | { |
165 | 110 | if (g_log_get_debug_enabled()) { |
166 | 0 | g_autofree gchar *str = fu_struct_sbat_level_section_header_to_string(st); |
167 | 0 | g_debug("%s", str); |
168 | 0 | } |
169 | 110 | if (!fu_struct_sbat_level_section_header_validate_internal(st, error)) |
170 | 30 | return FALSE; |
171 | 80 | return TRUE; |
172 | 110 | } |
173 | | /** |
174 | | * fu_struct_sbat_level_section_header_parse_stream: (skip): |
175 | | **/ |
176 | | FuStructSbatLevelSectionHeader * |
177 | | fu_struct_sbat_level_section_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
178 | 113 | { |
179 | 113 | g_autoptr(FuStructSbatLevelSectionHeader) st = fu_struct_sbat_level_section_header_new_internal(); |
180 | 113 | st->buf = fu_input_stream_read_byte_array(stream, offset, 12, NULL, error); |
181 | 113 | if (st->buf == NULL) { |
182 | 0 | g_prefix_error(error, "FuStructSbatLevelSectionHeader failed read of 0x%x: ", (guint) 12); |
183 | 0 | return NULL; |
184 | 0 | } |
185 | 113 | if (st->buf->len != 12) { |
186 | 3 | g_set_error(error, |
187 | 3 | FWUPD_ERROR, |
188 | 3 | FWUPD_ERROR_INVALID_DATA, |
189 | 3 | "FuStructSbatLevelSectionHeader requested 0x%x and got 0x%x", |
190 | 3 | (guint) 12, |
191 | 3 | (guint) st->buf->len); |
192 | 3 | return NULL; |
193 | 3 | } |
194 | 110 | if (!fu_struct_sbat_level_section_header_parse_internal(st, error)) |
195 | 30 | return NULL; |
196 | 80 | return g_steal_pointer(&st); |
197 | 110 | } |