Coverage Report

Created: 2025-11-24 06:59

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