Coverage Report

Created: 2026-01-09 07:21

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