Line | Count | Source |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include <glib.h> |
5 | | |
6 | | #include "fu-uswid-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 | | |
17 | | const gchar * |
18 | | fu_uswid_payload_compression_to_string(FuUswidPayloadCompression val) |
19 | 0 | { |
20 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_NONE) |
21 | 0 | return "none"; |
22 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_ZLIB) |
23 | 0 | return "zlib"; |
24 | 0 | if (val == FU_USWID_PAYLOAD_COMPRESSION_LZMA) |
25 | 0 | return "lzma"; |
26 | 0 | return NULL; |
27 | 0 | } |
28 | | FuUswidPayloadCompression |
29 | | fu_uswid_payload_compression_from_string(const gchar *val) |
30 | 0 | { |
31 | 0 | if (g_strcmp0(val, "none") == 0) |
32 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
33 | 0 | if (g_strcmp0(val, "zlib") == 0) |
34 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_ZLIB; |
35 | 0 | if (g_strcmp0(val, "lzma") == 0) |
36 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_LZMA; |
37 | 0 | return FU_USWID_PAYLOAD_COMPRESSION_NONE; |
38 | 0 | } |
39 | | /** |
40 | | * fu_struct_uswid_ref: (skip): |
41 | | **/ |
42 | | FuStructUswid * |
43 | | fu_struct_uswid_ref(FuStructUswid *st) |
44 | 0 | { |
45 | 0 | g_return_val_if_fail(st != NULL, NULL); |
46 | 0 | st->refcount++; |
47 | 0 | return st; |
48 | 0 | } |
49 | | /** |
50 | | * fu_struct_uswid_unref: (skip): |
51 | | **/ |
52 | | void |
53 | | fu_struct_uswid_unref(FuStructUswid *st) |
54 | 198k | { |
55 | 198k | g_return_if_fail(st != NULL); |
56 | 198k | if (st->refcount == 0) { |
57 | 0 | g_critical("FuStructUswid refcount already zero"); |
58 | 0 | return; |
59 | 0 | } |
60 | 198k | if (--st->refcount > 0) |
61 | 0 | return; |
62 | 198k | if (st->buf != NULL) |
63 | 196k | g_byte_array_unref(st->buf); |
64 | 198k | g_free(st); |
65 | 198k | } |
66 | | static FuStructUswid * |
67 | | fu_struct_uswid_new_internal(void) |
68 | 198k | { |
69 | 198k | FuStructUswid *st = g_new0(FuStructUswid, 1); |
70 | 198k | st->refcount = 1; |
71 | 198k | return st; |
72 | 198k | } |
73 | | |
74 | | /* getters */ |
75 | | /** |
76 | | * fu_struct_uswid_get_magic: (skip): |
77 | | **/ |
78 | | static const fwupd_guid_t * |
79 | | fu_struct_uswid_get_magic(const FuStructUswid *st) |
80 | 196k | { |
81 | 196k | g_return_val_if_fail(st != NULL, NULL); |
82 | 196k | return (const fwupd_guid_t *) (st->buf->data + 0); |
83 | 196k | } |
84 | | /** |
85 | | * fu_struct_uswid_get_hdrver: (skip): |
86 | | **/ |
87 | | guint8 |
88 | | fu_struct_uswid_get_hdrver(const FuStructUswid *st) |
89 | 98.2k | { |
90 | 98.2k | g_return_val_if_fail(st != NULL, 0x0); |
91 | 98.2k | return st->buf->data[16]; |
92 | 98.2k | } |
93 | | /** |
94 | | * fu_struct_uswid_get_hdrsz: (skip): |
95 | | **/ |
96 | | guint16 |
97 | | fu_struct_uswid_get_hdrsz(const FuStructUswid *st) |
98 | 97.7k | { |
99 | 97.7k | g_return_val_if_fail(st != NULL, 0x0); |
100 | 97.7k | return fu_memread_uint16(st->buf->data + 17, G_LITTLE_ENDIAN); |
101 | 97.7k | } |
102 | | /** |
103 | | * fu_struct_uswid_get_payloadsz: (skip): |
104 | | **/ |
105 | | guint32 |
106 | | fu_struct_uswid_get_payloadsz(const FuStructUswid *st) |
107 | 97.7k | { |
108 | 97.7k | g_return_val_if_fail(st != NULL, 0x0); |
109 | 97.7k | return fu_memread_uint32(st->buf->data + 19, G_LITTLE_ENDIAN); |
110 | 97.7k | } |
111 | | /** |
112 | | * fu_struct_uswid_get_flags: (skip): |
113 | | **/ |
114 | | guint8 |
115 | | fu_struct_uswid_get_flags(const FuStructUswid *st) |
116 | 52.7k | { |
117 | 52.7k | g_return_val_if_fail(st != NULL, 0x0); |
118 | 52.7k | return st->buf->data[23]; |
119 | 52.7k | } |
120 | | /** |
121 | | * fu_struct_uswid_get_compression: (skip): |
122 | | **/ |
123 | | guint8 |
124 | | fu_struct_uswid_get_compression(const FuStructUswid *st) |
125 | 10.8k | { |
126 | 10.8k | g_return_val_if_fail(st != NULL, 0x0); |
127 | 10.8k | return st->buf->data[24]; |
128 | 10.8k | } |
129 | | |
130 | | /* setters */ |
131 | | /** |
132 | | * fu_struct_uswid_set_magic: (skip): |
133 | | **/ |
134 | | static void |
135 | | fu_struct_uswid_set_magic(FuStructUswid *st, const fwupd_guid_t *value) |
136 | 1.48k | { |
137 | 1.48k | g_return_if_fail(st != NULL); |
138 | 1.48k | g_return_if_fail(value != NULL); |
139 | 1.48k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
140 | 1.48k | } |
141 | | /** |
142 | | * fu_struct_uswid_set_hdrver: (skip): |
143 | | **/ |
144 | | void |
145 | | fu_struct_uswid_set_hdrver(FuStructUswid *st, guint8 value) |
146 | 1.48k | { |
147 | 1.48k | g_return_if_fail(st != NULL); |
148 | 1.48k | st->buf->data[16] = value; |
149 | 1.48k | } |
150 | | /** |
151 | | * fu_struct_uswid_set_hdrsz: (skip): |
152 | | **/ |
153 | | void |
154 | | fu_struct_uswid_set_hdrsz(FuStructUswid *st, guint16 value) |
155 | 2.30k | { |
156 | 2.30k | g_return_if_fail(st != NULL); |
157 | 2.30k | fu_memwrite_uint16(st->buf->data + 17, value, G_LITTLE_ENDIAN); |
158 | 2.30k | } |
159 | | /** |
160 | | * fu_struct_uswid_set_payloadsz: (skip): |
161 | | **/ |
162 | | void |
163 | | fu_struct_uswid_set_payloadsz(FuStructUswid *st, guint32 value) |
164 | 1.48k | { |
165 | 1.48k | g_return_if_fail(st != NULL); |
166 | 1.48k | fu_memwrite_uint32(st->buf->data + 19, value, G_LITTLE_ENDIAN); |
167 | 1.48k | } |
168 | | /** |
169 | | * fu_struct_uswid_set_flags: (skip): |
170 | | **/ |
171 | | void |
172 | | fu_struct_uswid_set_flags(FuStructUswid *st, guint8 value) |
173 | 715 | { |
174 | 715 | g_return_if_fail(st != NULL); |
175 | 715 | st->buf->data[23] = value; |
176 | 715 | } |
177 | | /** |
178 | | * fu_struct_uswid_set_compression: (skip): |
179 | | **/ |
180 | | void |
181 | | fu_struct_uswid_set_compression(FuStructUswid *st, guint8 value) |
182 | 661 | { |
183 | 661 | g_return_if_fail(st != NULL); |
184 | 661 | st->buf->data[24] = value; |
185 | 661 | } |
186 | | /** |
187 | | * fu_struct_uswid_new: (skip): |
188 | | **/ |
189 | | FuStructUswid * |
190 | | fu_struct_uswid_new(void) |
191 | 1.48k | { |
192 | 1.48k | FuStructUswid *st = fu_struct_uswid_new_internal(); |
193 | 1.48k | st->buf = g_byte_array_sized_new(25); |
194 | 1.48k | fu_byte_array_set_size(st->buf, 25, 0x0); |
195 | 1.48k | fu_struct_uswid_set_magic(st, (fwupd_guid_t *) "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf"); |
196 | 1.48k | fu_struct_uswid_set_hdrsz(st, 25); |
197 | 1.48k | return st; |
198 | 1.48k | } |
199 | | /** |
200 | | * fu_struct_uswid_to_string: (skip): |
201 | | **/ |
202 | | static gchar * |
203 | | fu_struct_uswid_to_string(const FuStructUswid *st) |
204 | 0 | { |
205 | 0 | g_autoptr(GString) str = g_string_new("FuStructUswid:\n"); |
206 | 0 | g_return_val_if_fail(st != NULL, NULL); |
207 | 0 | g_string_append_printf(str, " hdrver: 0x%x\n", |
208 | 0 | (guint) fu_struct_uswid_get_hdrver(st)); |
209 | 0 | g_string_append_printf(str, " hdrsz: 0x%x\n", |
210 | 0 | (guint) fu_struct_uswid_get_hdrsz(st)); |
211 | 0 | g_string_append_printf(str, " payloadsz: 0x%x\n", |
212 | 0 | (guint) fu_struct_uswid_get_payloadsz(st)); |
213 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
214 | 0 | (guint) fu_struct_uswid_get_flags(st)); |
215 | 0 | g_string_append_printf(str, " compression: 0x%x\n", |
216 | 0 | (guint) fu_struct_uswid_get_compression(st)); |
217 | 0 | if (str->len > 0) |
218 | 0 | g_string_set_size(str, str->len - 1); |
219 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
220 | 0 | } |
221 | | static gboolean |
222 | | fu_struct_uswid_validate_internal(FuStructUswid *st, GError **error) |
223 | 196k | { |
224 | 196k | g_return_val_if_fail(st != NULL, FALSE); |
225 | 196k | if (memcmp(fu_struct_uswid_get_magic(st), "\x53\x42\x4f\x4d\xd6\xba\x2e\xac\xa3\xe6\x7a\x52\xaa\xee\x3b\xaf", 16) != 0) { |
226 | 0 | g_set_error_literal(error, |
227 | 0 | FWUPD_ERROR, |
228 | 0 | FWUPD_ERROR_INVALID_DATA, |
229 | 0 | "constant FuStructUswid.magic was not valid"); |
230 | 0 | return FALSE; |
231 | 0 | } |
232 | 196k | return TRUE; |
233 | 196k | } |
234 | | /** |
235 | | * fu_struct_uswid_validate_stream: (skip): |
236 | | **/ |
237 | | gboolean |
238 | | fu_struct_uswid_validate_stream(GInputStream *stream, gsize offset, GError **error) |
239 | 98.7k | { |
240 | 98.7k | g_autoptr(FuStructUswid) st = fu_struct_uswid_new_internal(); |
241 | 98.7k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
242 | 98.7k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
243 | 98.7k | st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
244 | 98.7k | if (st->buf == NULL) { |
245 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
246 | 0 | return FALSE; |
247 | 0 | } |
248 | 98.7k | if (st->buf->len != 25) { |
249 | 489 | g_set_error(error, |
250 | 489 | FWUPD_ERROR, |
251 | 489 | FWUPD_ERROR_INVALID_DATA, |
252 | 489 | "FuStructUswid requested 0x%x and got 0x%x", |
253 | 489 | (guint) 25, |
254 | 489 | (guint) st->buf->len); |
255 | 489 | return FALSE; |
256 | 489 | } |
257 | 98.2k | return fu_struct_uswid_validate_internal(st, error); |
258 | 98.7k | } |
259 | | static gboolean |
260 | | fu_struct_uswid_parse_internal(FuStructUswid *st, GError **error) |
261 | 98.2k | { |
262 | 98.2k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
263 | 0 | g_autofree gchar *str = fu_struct_uswid_to_string(st); |
264 | 0 | g_debug("%s", str); |
265 | 0 | } |
266 | 98.2k | if (!fu_struct_uswid_validate_internal(st, error)) |
267 | 0 | return FALSE; |
268 | 98.2k | return TRUE; |
269 | 98.2k | } |
270 | | /** |
271 | | * fu_struct_uswid_parse_stream: (skip): |
272 | | **/ |
273 | | FuStructUswid * |
274 | | fu_struct_uswid_parse_stream(GInputStream *stream, gsize offset, GError **error) |
275 | 98.2k | { |
276 | 98.2k | g_autoptr(FuStructUswid) st = fu_struct_uswid_new_internal(); |
277 | 98.2k | st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
278 | 98.2k | if (st->buf == NULL) { |
279 | 0 | g_prefix_error(error, "FuStructUswid failed read of 0x%x: ", (guint) 25); |
280 | 0 | return NULL; |
281 | 0 | } |
282 | 98.2k | if (st->buf->len != 25) { |
283 | 0 | g_set_error(error, |
284 | 0 | FWUPD_ERROR, |
285 | 0 | FWUPD_ERROR_INVALID_DATA, |
286 | 0 | "FuStructUswid requested 0x%x and got 0x%x", |
287 | 0 | (guint) 25, |
288 | 0 | (guint) st->buf->len); |
289 | 0 | return NULL; |
290 | 0 | } |
291 | 98.2k | if (!fu_struct_uswid_parse_internal(st, error)) |
292 | 0 | return NULL; |
293 | 98.2k | return g_steal_pointer(&st); |
294 | 98.2k | } |