Coverage Report

Created: 2025-11-11 06:44

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