/work/fu-usb-device-ds20-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-usb-device-ds20-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 | | /** |
23 | | * fu_usb_device_ms_ds20_desc_to_string: |
24 | | * @val: value, e.g. %FU_USB_DEVICE_MS_DS20_DESC_SUBSET_HEADER_CONFIGURATION |
25 | | * |
26 | | * Converts an enumerated value to a string. |
27 | | * |
28 | | * Returns: identifier string |
29 | | **/ |
30 | | const gchar * |
31 | | fu_usb_device_ms_ds20_desc_to_string(FuUsbDeviceMsDs20Desc val) |
32 | 0 | { |
33 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_SET_HEADER_DESCRIPTOR) |
34 | 0 | return "set-header-descriptor"; |
35 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_SUBSET_HEADER_CONFIGURATION) |
36 | 0 | return "subset-header-configuration"; |
37 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_SUBSET_HEADER_FUNCTION) |
38 | 0 | return "subset-header-function"; |
39 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_COMPATIBLE_ID) |
40 | 0 | return "feature-compatible-id"; |
41 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_REG_PROPERTY) |
42 | 0 | return "feature-reg-property"; |
43 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_MIN_RESUME_TIME) |
44 | 0 | return "feature-min-resume-time"; |
45 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_MODEL_ID) |
46 | 0 | return "feature-model-id"; |
47 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_CCGP_DEVICE) |
48 | 0 | return "feature-ccgp-device"; |
49 | 0 | if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_VENDOR_REVISION) |
50 | 0 | return "feature-vendor-revision"; |
51 | 0 | return NULL; |
52 | 0 | } |
53 | | /** |
54 | | * fu_struct_ds20_ref: (skip): |
55 | | **/ |
56 | | FuStructDs20 * |
57 | | fu_struct_ds20_ref(FuStructDs20 *st) |
58 | 0 | { |
59 | 0 | g_return_val_if_fail(st != NULL, NULL); |
60 | 0 | st->refcount++; |
61 | 0 | return st; |
62 | 0 | } |
63 | | /** |
64 | | * fu_struct_ds20_unref: (skip): |
65 | | **/ |
66 | | void |
67 | | fu_struct_ds20_unref(FuStructDs20 *st) |
68 | 0 | { |
69 | 0 | g_return_if_fail(st != NULL); |
70 | 0 | if (st->refcount == 0) { |
71 | 0 | g_critical("FuStructDs20 refcount already zero"); |
72 | 0 | return; |
73 | 0 | } |
74 | 0 | if (--st->refcount > 0) |
75 | 0 | return; |
76 | 0 | if (st->buf != NULL) |
77 | 0 | g_byte_array_unref(st->buf); |
78 | 0 | g_free(st); |
79 | 0 | } |
80 | | /** |
81 | | * fu_struct_ds20_new_internal: (skip): |
82 | | **/ |
83 | | static FuStructDs20 * |
84 | | fu_struct_ds20_new_internal(void) |
85 | 0 | { |
86 | 0 | FuStructDs20 *st = g_new0(FuStructDs20, 1); |
87 | 0 | st->refcount = 1; |
88 | 0 | return st; |
89 | 0 | } |
90 | | |
91 | | /* getters */ |
92 | | /** |
93 | | * fu_struct_ds20_get_guid: (skip): |
94 | | **/ |
95 | | const fwupd_guid_t * |
96 | | fu_struct_ds20_get_guid(const FuStructDs20 *st) |
97 | 0 | { |
98 | 0 | g_return_val_if_fail(st != NULL, NULL); |
99 | 0 | return (const fwupd_guid_t *) (st->buf->data + 1); |
100 | 0 | } |
101 | | /** |
102 | | * fu_struct_ds20_get_platform_ver: (skip): |
103 | | **/ |
104 | | guint32 |
105 | | fu_struct_ds20_get_platform_ver(const FuStructDs20 *st) |
106 | 0 | { |
107 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
108 | 0 | return fu_memread_uint32(st->buf->data + 17, G_LITTLE_ENDIAN); |
109 | 0 | } |
110 | | /** |
111 | | * fu_struct_ds20_get_total_length: (skip): |
112 | | **/ |
113 | | guint16 |
114 | | fu_struct_ds20_get_total_length(const FuStructDs20 *st) |
115 | 0 | { |
116 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
117 | 0 | return fu_memread_uint16(st->buf->data + 21, G_LITTLE_ENDIAN); |
118 | 0 | } |
119 | | /** |
120 | | * fu_struct_ds20_get_vendor_code: (skip): |
121 | | **/ |
122 | | guint8 |
123 | | fu_struct_ds20_get_vendor_code(const FuStructDs20 *st) |
124 | 0 | { |
125 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
126 | 0 | return st->buf->data[23]; |
127 | 0 | } |
128 | | /** |
129 | | * fu_struct_ds20_get_alt_code: (skip): |
130 | | **/ |
131 | | guint8 |
132 | | fu_struct_ds20_get_alt_code(const FuStructDs20 *st) |
133 | 0 | { |
134 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
135 | 0 | return st->buf->data[24]; |
136 | 0 | } |
137 | | |
138 | | /* setters */ |
139 | | /** |
140 | | * fu_struct_ds20_set_guid: (skip): |
141 | | **/ |
142 | | void |
143 | | fu_struct_ds20_set_guid(FuStructDs20 *st, const fwupd_guid_t *value) |
144 | 0 | { |
145 | 0 | g_return_if_fail(st != NULL); |
146 | 0 | g_return_if_fail(value != NULL); |
147 | 0 | memcpy(st->buf->data + 1, value, sizeof(*value)); /* nocheck:blocked */ |
148 | 0 | } |
149 | | /** |
150 | | * fu_struct_ds20_set_platform_ver: (skip): |
151 | | **/ |
152 | | void |
153 | | fu_struct_ds20_set_platform_ver(FuStructDs20 *st, guint32 value) |
154 | 0 | { |
155 | 0 | g_return_if_fail(st != NULL); |
156 | 0 | fu_memwrite_uint32(st->buf->data + 17, value, G_LITTLE_ENDIAN); |
157 | 0 | } |
158 | | /** |
159 | | * fu_struct_ds20_set_total_length: (skip): |
160 | | **/ |
161 | | void |
162 | | fu_struct_ds20_set_total_length(FuStructDs20 *st, guint16 value) |
163 | 0 | { |
164 | 0 | g_return_if_fail(st != NULL); |
165 | 0 | fu_memwrite_uint16(st->buf->data + 21, value, G_LITTLE_ENDIAN); |
166 | 0 | } |
167 | | /** |
168 | | * fu_struct_ds20_set_vendor_code: (skip): |
169 | | **/ |
170 | | void |
171 | | fu_struct_ds20_set_vendor_code(FuStructDs20 *st, guint8 value) |
172 | 0 | { |
173 | 0 | g_return_if_fail(st != NULL); |
174 | 0 | st->buf->data[23] = value; |
175 | 0 | } |
176 | | /** |
177 | | * fu_struct_ds20_set_alt_code: (skip): |
178 | | **/ |
179 | | void |
180 | | fu_struct_ds20_set_alt_code(FuStructDs20 *st, guint8 value) |
181 | 0 | { |
182 | 0 | g_return_if_fail(st != NULL); |
183 | 0 | st->buf->data[24] = value; |
184 | 0 | } |
185 | | /** |
186 | | * fu_struct_ds20_new: (skip): |
187 | | **/ |
188 | | FuStructDs20 * |
189 | | fu_struct_ds20_new(void) |
190 | 0 | { |
191 | 0 | FuStructDs20 *st = fu_struct_ds20_new_internal(); |
192 | 0 | st->buf = g_byte_array_sized_new(25); |
193 | 0 | fu_byte_array_set_size(st->buf, 25, 0x0); |
194 | 0 | return st; |
195 | 0 | } |
196 | | /** |
197 | | * fu_struct_ds20_to_string: (skip): |
198 | | **/ |
199 | | static gchar * |
200 | | fu_struct_ds20_to_string(const FuStructDs20 *st) |
201 | 0 | { |
202 | 0 | g_autoptr(GString) str = g_string_new("FuStructDs20:\n"); |
203 | 0 | g_return_val_if_fail(st != NULL, NULL); |
204 | 0 | { |
205 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_ds20_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
206 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
207 | 0 | } |
208 | 0 | g_string_append_printf(str, " platform_ver: 0x%x\n", |
209 | 0 | (guint) fu_struct_ds20_get_platform_ver(st)); |
210 | 0 | g_string_append_printf(str, " total_length: 0x%x\n", |
211 | 0 | (guint) fu_struct_ds20_get_total_length(st)); |
212 | 0 | g_string_append_printf(str, " vendor_code: 0x%x\n", |
213 | 0 | (guint) fu_struct_ds20_get_vendor_code(st)); |
214 | 0 | g_string_append_printf(str, " alt_code: 0x%x\n", |
215 | 0 | (guint) fu_struct_ds20_get_alt_code(st)); |
216 | 0 | if (str->len > 0) |
217 | 0 | g_string_set_size(str, str->len - 1); |
218 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
219 | 0 | } |
220 | | static gboolean |
221 | | fu_struct_ds20_validate_internal(FuStructDs20 *st, GError **error) |
222 | 0 | { |
223 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
224 | 0 | return TRUE; |
225 | 0 | } |
226 | | static gboolean |
227 | | fu_struct_ds20_parse_internal(FuStructDs20 *st, GError **error) |
228 | 0 | { |
229 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
230 | 0 | g_autofree gchar *str = fu_struct_ds20_to_string(st); |
231 | 0 | g_debug("%s", str); |
232 | 0 | } |
233 | 0 | if (!fu_struct_ds20_validate_internal(st, error)) |
234 | 0 | return FALSE; |
235 | 0 | return TRUE; |
236 | 0 | } |
237 | | /** |
238 | | * fu_struct_ds20_parse_stream: (skip): |
239 | | **/ |
240 | | FuStructDs20 * |
241 | | fu_struct_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error) |
242 | 0 | { |
243 | 0 | g_autoptr(FuStructDs20) st = fu_struct_ds20_new_internal(); |
244 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error); |
245 | 0 | if (st->buf == NULL) { |
246 | 0 | g_prefix_error(error, "FuStructDs20 failed read of 0x%x: ", (guint) 25); |
247 | 0 | return NULL; |
248 | 0 | } |
249 | 0 | if (st->buf->len != 25) { |
250 | 0 | g_set_error(error, |
251 | 0 | FWUPD_ERROR, |
252 | 0 | FWUPD_ERROR_INVALID_DATA, |
253 | 0 | "FuStructDs20 requested 0x%x and got 0x%x", |
254 | 0 | (guint) 25, |
255 | 0 | (guint) st->buf->len); |
256 | 0 | return NULL; |
257 | 0 | } |
258 | 0 | if (!fu_struct_ds20_parse_internal(st, error)) |
259 | 0 | return NULL; |
260 | 0 | return g_steal_pointer(&st); |
261 | 0 | } |
262 | | /** |
263 | | * fu_struct_ms_ds20_ref: (skip): |
264 | | **/ |
265 | | FuStructMsDs20 * |
266 | | fu_struct_ms_ds20_ref(FuStructMsDs20 *st) |
267 | 0 | { |
268 | 0 | g_return_val_if_fail(st != NULL, NULL); |
269 | 0 | st->refcount++; |
270 | 0 | return st; |
271 | 0 | } |
272 | | /** |
273 | | * fu_struct_ms_ds20_unref: (skip): |
274 | | **/ |
275 | | void |
276 | | fu_struct_ms_ds20_unref(FuStructMsDs20 *st) |
277 | 0 | { |
278 | 0 | g_return_if_fail(st != NULL); |
279 | 0 | if (st->refcount == 0) { |
280 | 0 | g_critical("FuStructMsDs20 refcount already zero"); |
281 | 0 | return; |
282 | 0 | } |
283 | 0 | if (--st->refcount > 0) |
284 | 0 | return; |
285 | 0 | if (st->buf != NULL) |
286 | 0 | g_byte_array_unref(st->buf); |
287 | 0 | g_free(st); |
288 | 0 | } |
289 | | /** |
290 | | * fu_struct_ms_ds20_new_internal: (skip): |
291 | | **/ |
292 | | static FuStructMsDs20 * |
293 | | fu_struct_ms_ds20_new_internal(void) |
294 | 0 | { |
295 | 0 | FuStructMsDs20 *st = g_new0(FuStructMsDs20, 1); |
296 | 0 | st->refcount = 1; |
297 | 0 | return st; |
298 | 0 | } |
299 | | |
300 | | /* getters */ |
301 | | /** |
302 | | * fu_struct_ms_ds20_get_size: (skip): |
303 | | **/ |
304 | | guint16 |
305 | | fu_struct_ms_ds20_get_size(const FuStructMsDs20 *st) |
306 | 0 | { |
307 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
308 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
309 | 0 | } |
310 | | /** |
311 | | * fu_struct_ms_ds20_get_type: (skip): |
312 | | **/ |
313 | | guint16 |
314 | | fu_struct_ms_ds20_get_type(const FuStructMsDs20 *st) |
315 | 0 | { |
316 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
317 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
318 | 0 | } |
319 | | |
320 | | /* setters */ |
321 | | /** |
322 | | * fu_struct_ms_ds20_set_size: (skip): |
323 | | **/ |
324 | | void |
325 | | fu_struct_ms_ds20_set_size(FuStructMsDs20 *st, guint16 value) |
326 | 0 | { |
327 | 0 | g_return_if_fail(st != NULL); |
328 | 0 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
329 | 0 | } |
330 | | /** |
331 | | * fu_struct_ms_ds20_set_type: (skip): |
332 | | **/ |
333 | | void |
334 | | fu_struct_ms_ds20_set_type(FuStructMsDs20 *st, guint16 value) |
335 | 0 | { |
336 | 0 | g_return_if_fail(st != NULL); |
337 | 0 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
338 | 0 | } |
339 | | /** |
340 | | * fu_struct_ms_ds20_new: (skip): |
341 | | **/ |
342 | | FuStructMsDs20 * |
343 | | fu_struct_ms_ds20_new(void) |
344 | 0 | { |
345 | 0 | FuStructMsDs20 *st = fu_struct_ms_ds20_new_internal(); |
346 | 0 | st->buf = g_byte_array_sized_new(4); |
347 | 0 | fu_byte_array_set_size(st->buf, 4, 0x0); |
348 | 0 | return st; |
349 | 0 | } |
350 | | /** |
351 | | * fu_struct_ms_ds20_to_string: (skip): |
352 | | **/ |
353 | | static gchar * |
354 | | fu_struct_ms_ds20_to_string(const FuStructMsDs20 *st) |
355 | 0 | { |
356 | 0 | g_autoptr(GString) str = g_string_new("FuStructMsDs20:\n"); |
357 | 0 | g_return_val_if_fail(st != NULL, NULL); |
358 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
359 | 0 | (guint) fu_struct_ms_ds20_get_size(st)); |
360 | 0 | g_string_append_printf(str, " type: 0x%x\n", |
361 | 0 | (guint) fu_struct_ms_ds20_get_type(st)); |
362 | 0 | if (str->len > 0) |
363 | 0 | g_string_set_size(str, str->len - 1); |
364 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
365 | 0 | } |
366 | | static gboolean |
367 | | fu_struct_ms_ds20_validate_internal(FuStructMsDs20 *st, GError **error) |
368 | 0 | { |
369 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
370 | 0 | return TRUE; |
371 | 0 | } |
372 | | static gboolean |
373 | | fu_struct_ms_ds20_parse_internal(FuStructMsDs20 *st, GError **error) |
374 | 0 | { |
375 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
376 | 0 | g_autofree gchar *str = fu_struct_ms_ds20_to_string(st); |
377 | 0 | g_debug("%s", str); |
378 | 0 | } |
379 | 0 | if (!fu_struct_ms_ds20_validate_internal(st, error)) |
380 | 0 | return FALSE; |
381 | 0 | return TRUE; |
382 | 0 | } |
383 | | /** |
384 | | * fu_struct_ms_ds20_parse_stream: (skip): |
385 | | **/ |
386 | | FuStructMsDs20 * |
387 | | fu_struct_ms_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error) |
388 | 0 | { |
389 | 0 | g_autoptr(FuStructMsDs20) st = fu_struct_ms_ds20_new_internal(); |
390 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
391 | 0 | if (st->buf == NULL) { |
392 | 0 | g_prefix_error(error, "FuStructMsDs20 failed read of 0x%x: ", (guint) 4); |
393 | 0 | return NULL; |
394 | 0 | } |
395 | 0 | if (st->buf->len != 4) { |
396 | 0 | g_set_error(error, |
397 | 0 | FWUPD_ERROR, |
398 | 0 | FWUPD_ERROR_INVALID_DATA, |
399 | 0 | "FuStructMsDs20 requested 0x%x and got 0x%x", |
400 | 0 | (guint) 4, |
401 | 0 | (guint) st->buf->len); |
402 | 0 | return NULL; |
403 | 0 | } |
404 | 0 | if (!fu_struct_ms_ds20_parse_internal(st, error)) |
405 | 0 | return NULL; |
406 | 0 | return g_steal_pointer(&st); |
407 | 0 | } |