Coverage Report

Created: 2026-06-15 06:54

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-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_parse_internal(FuStructDs20 *st, GError **error)
222
0
{
223
0
    if (g_log_get_debug_enabled()) {
224
0
        g_autofree gchar *str = fu_struct_ds20_to_string(st);
225
0
        g_debug("%s", str);
226
0
    }
227
0
    return TRUE;
228
0
}
229
/**
230
 * fu_struct_ds20_parse_stream: (skip):
231
 **/
232
FuStructDs20 *
233
fu_struct_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error)
234
0
{
235
0
    g_autoptr(FuStructDs20) st = fu_struct_ds20_new_internal();
236
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error);
237
0
    if (st->buf == NULL) {
238
0
        g_prefix_error(error, "FuStructDs20 failed read of 0x%x: ", (guint) 25);
239
0
        return NULL;
240
0
    }
241
0
    if (st->buf->len != 25) {
242
0
        g_set_error(error,
243
0
                    FWUPD_ERROR,
244
0
                    FWUPD_ERROR_INVALID_DATA,
245
0
                    "FuStructDs20 requested 0x%x and got 0x%x",
246
0
                    (guint) 25,
247
0
                    (guint) st->buf->len);
248
0
        return NULL;
249
0
    }
250
0
    if (!fu_struct_ds20_parse_internal(st, error))
251
0
        return NULL;
252
0
    return g_steal_pointer(&st);
253
0
}
254
/**
255
 * fu_struct_ms_ds20_ref: (skip):
256
 **/
257
FuStructMsDs20 *
258
fu_struct_ms_ds20_ref(FuStructMsDs20 *st)
259
0
{
260
0
    g_return_val_if_fail(st != NULL, NULL);
261
0
    st->refcount++;
262
0
    return st;
263
0
}
264
/**
265
 * fu_struct_ms_ds20_unref: (skip):
266
 **/
267
void
268
fu_struct_ms_ds20_unref(FuStructMsDs20 *st)
269
0
{
270
0
    g_return_if_fail(st != NULL);
271
0
    if (st->refcount == 0) {
272
0
        g_critical("FuStructMsDs20 refcount already zero");
273
0
        return;
274
0
    }
275
0
    if (--st->refcount > 0)
276
0
        return;
277
0
    if (st->buf != NULL)
278
0
        g_byte_array_unref(st->buf);
279
0
    g_free(st);
280
0
}
281
/**
282
 * fu_struct_ms_ds20_new_internal: (skip):
283
 **/
284
static FuStructMsDs20 *
285
fu_struct_ms_ds20_new_internal(void)
286
0
{
287
0
    FuStructMsDs20 *st = g_new0(FuStructMsDs20, 1);
288
0
    st->refcount = 1;
289
0
    return st;
290
0
}
291
292
/* getters */
293
/**
294
 * fu_struct_ms_ds20_get_size: (skip):
295
 **/
296
guint16
297
fu_struct_ms_ds20_get_size(const FuStructMsDs20 *st)
298
0
{
299
0
    g_return_val_if_fail(st != NULL, 0x0);
300
0
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
301
0
}
302
/**
303
 * fu_struct_ms_ds20_get_type: (skip):
304
 **/
305
guint16
306
fu_struct_ms_ds20_get_type(const FuStructMsDs20 *st)
307
0
{
308
0
    g_return_val_if_fail(st != NULL, 0x0);
309
0
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
310
0
}
311
312
/* setters */
313
/**
314
 * fu_struct_ms_ds20_set_size: (skip):
315
 **/
316
void
317
fu_struct_ms_ds20_set_size(FuStructMsDs20 *st, guint16 value)
318
0
{
319
0
    g_return_if_fail(st != NULL);
320
0
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
321
0
}
322
/**
323
 * fu_struct_ms_ds20_set_type: (skip):
324
 **/
325
void
326
fu_struct_ms_ds20_set_type(FuStructMsDs20 *st, guint16 value)
327
0
{
328
0
    g_return_if_fail(st != NULL);
329
0
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
330
0
}
331
/**
332
 * fu_struct_ms_ds20_new: (skip):
333
 **/
334
FuStructMsDs20 *
335
fu_struct_ms_ds20_new(void)
336
0
{
337
0
    FuStructMsDs20 *st = fu_struct_ms_ds20_new_internal();
338
0
    st->buf = g_byte_array_sized_new(4);
339
0
    fu_byte_array_set_size(st->buf, 4, 0x0);
340
0
    return st;
341
0
}
342
/**
343
 * fu_struct_ms_ds20_to_string: (skip):
344
 **/
345
static gchar *
346
fu_struct_ms_ds20_to_string(const FuStructMsDs20 *st)
347
0
{
348
0
    g_autoptr(GString) str = g_string_new("FuStructMsDs20:\n");
349
0
    g_return_val_if_fail(st != NULL, NULL);
350
0
    g_string_append_printf(str, "  size: 0x%x\n",
351
0
                           (guint) fu_struct_ms_ds20_get_size(st));
352
0
    g_string_append_printf(str, "  type: 0x%x\n",
353
0
                           (guint) fu_struct_ms_ds20_get_type(st));
354
0
    if (str->len > 0)
355
0
        g_string_set_size(str, str->len - 1);
356
0
    return g_string_free(g_steal_pointer(&str), FALSE);
357
0
}
358
static gboolean
359
fu_struct_ms_ds20_parse_internal(FuStructMsDs20 *st, GError **error)
360
0
{
361
0
    if (g_log_get_debug_enabled()) {
362
0
        g_autofree gchar *str = fu_struct_ms_ds20_to_string(st);
363
0
        g_debug("%s", str);
364
0
    }
365
0
    return TRUE;
366
0
}
367
/**
368
 * fu_struct_ms_ds20_parse_stream: (skip):
369
 **/
370
FuStructMsDs20 *
371
fu_struct_ms_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error)
372
0
{
373
0
    g_autoptr(FuStructMsDs20) st = fu_struct_ms_ds20_new_internal();
374
0
    st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
375
0
    if (st->buf == NULL) {
376
0
        g_prefix_error(error, "FuStructMsDs20 failed read of 0x%x: ", (guint) 4);
377
0
        return NULL;
378
0
    }
379
0
    if (st->buf->len != 4) {
380
0
        g_set_error(error,
381
0
                    FWUPD_ERROR,
382
0
                    FWUPD_ERROR_INVALID_DATA,
383
0
                    "FuStructMsDs20 requested 0x%x and got 0x%x",
384
0
                    (guint) 4,
385
0
                    (guint) st->buf->len);
386
0
        return NULL;
387
0
    }
388
0
    if (!fu_struct_ms_ds20_parse_internal(st, error))
389
0
        return NULL;
390
0
    return g_steal_pointer(&st);
391
0
}