Coverage Report

Created: 2025-07-01 07:09

/work/fu-usb-device-ds20-struct.c
Line
Count
Source (jump to first uncovered line)
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include "fu-usb-device-ds20-struct.h"
5
#include "fu-byte-array.h"
6
#include "fu-mem-private.h"
7
#include "fu-string.h"
8
9
#ifdef G_LOG_DOMAIN
10
  #undef G_LOG_DOMAIN
11
#endif
12
0
#define G_LOG_DOMAIN "FuStruct"
13
14
const gchar *
15
fu_usb_device_ms_ds20_desc_to_string(FuUsbDeviceMsDs20Desc val)
16
0
{
17
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_SET_HEADER_DESCRIPTOR)
18
0
        return "set-header-descriptor";
19
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_SUBSET_HEADER_CONFIGURATION)
20
0
        return "subset-header-configuration";
21
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_SUBSET_HEADER_FUNCTION)
22
0
        return "subset-header-function";
23
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_COMPATIBLE_ID)
24
0
        return "feature-compatible-id";
25
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_REG_PROPERTY)
26
0
        return "feature-reg-property";
27
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_MIN_RESUME_TIME)
28
0
        return "feature-min-resume-time";
29
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_MODEL_ID)
30
0
        return "feature-model-id";
31
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_CCGP_DEVICE)
32
0
        return "feature-ccgp-device";
33
0
    if (val == FU_USB_DEVICE_MS_DS20_DESC_FEATURE_VENDOR_REVISION)
34
0
        return "feature-vendor-revision";
35
0
    return NULL;
36
0
}
37
/* getters */
38
/**
39
 * fu_struct_ds20_get_guid: (skip):
40
 **/
41
const fwupd_guid_t *
42
fu_struct_ds20_get_guid(const FuStructDs20 *st)
43
0
{
44
0
    g_return_val_if_fail(st != NULL, NULL);
45
0
    return (const fwupd_guid_t *) (st->data + 1);
46
0
}
47
/**
48
 * fu_struct_ds20_get_platform_ver: (skip):
49
 **/
50
guint32
51
fu_struct_ds20_get_platform_ver(const FuStructDs20 *st)
52
0
{
53
0
    g_return_val_if_fail(st != NULL, 0x0);
54
0
    return fu_memread_uint32(st->data + 17, G_LITTLE_ENDIAN);
55
0
}
56
/**
57
 * fu_struct_ds20_get_total_length: (skip):
58
 **/
59
guint16
60
fu_struct_ds20_get_total_length(const FuStructDs20 *st)
61
0
{
62
0
    g_return_val_if_fail(st != NULL, 0x0);
63
0
    return fu_memread_uint16(st->data + 21, G_LITTLE_ENDIAN);
64
0
}
65
/**
66
 * fu_struct_ds20_get_vendor_code: (skip):
67
 **/
68
guint8
69
fu_struct_ds20_get_vendor_code(const FuStructDs20 *st)
70
0
{
71
0
    g_return_val_if_fail(st != NULL, 0x0);
72
0
    return st->data[23];
73
0
}
74
/**
75
 * fu_struct_ds20_get_alt_code: (skip):
76
 **/
77
guint8
78
fu_struct_ds20_get_alt_code(const FuStructDs20 *st)
79
0
{
80
0
    g_return_val_if_fail(st != NULL, 0x0);
81
0
    return st->data[24];
82
0
}
83
84
/* setters */
85
/**
86
 * fu_struct_ds20_set_guid: (skip):
87
 **/
88
void
89
fu_struct_ds20_set_guid(FuStructDs20 *st, const fwupd_guid_t *value)
90
0
{
91
0
    g_return_if_fail(st != NULL);
92
0
    g_return_if_fail(value != NULL);
93
0
    memcpy(st->data + 1, value, sizeof(*value)); /* nocheck:blocked */
94
0
}
95
/**
96
 * fu_struct_ds20_set_platform_ver: (skip):
97
 **/
98
void
99
fu_struct_ds20_set_platform_ver(FuStructDs20 *st, guint32 value)
100
0
{
101
0
    g_return_if_fail(st != NULL);
102
0
    fu_memwrite_uint32(st->data + 17, value, G_LITTLE_ENDIAN);
103
0
}
104
/**
105
 * fu_struct_ds20_set_total_length: (skip):
106
 **/
107
void
108
fu_struct_ds20_set_total_length(FuStructDs20 *st, guint16 value)
109
0
{
110
0
    g_return_if_fail(st != NULL);
111
0
    fu_memwrite_uint16(st->data + 21, value, G_LITTLE_ENDIAN);
112
0
}
113
/**
114
 * fu_struct_ds20_set_vendor_code: (skip):
115
 **/
116
void
117
fu_struct_ds20_set_vendor_code(FuStructDs20 *st, guint8 value)
118
0
{
119
0
    g_return_if_fail(st != NULL);
120
0
    st->data[23] = value;
121
0
}
122
/**
123
 * fu_struct_ds20_set_alt_code: (skip):
124
 **/
125
void
126
fu_struct_ds20_set_alt_code(FuStructDs20 *st, guint8 value)
127
0
{
128
0
    g_return_if_fail(st != NULL);
129
0
    st->data[24] = value;
130
0
}
131
/**
132
 * fu_struct_ds20_new: (skip):
133
 **/
134
FuStructDs20 *
135
fu_struct_ds20_new(void)
136
0
{
137
0
    FuStructDs20 *st = g_byte_array_sized_new(25);
138
0
    fu_byte_array_set_size(st, 25, 0x0);
139
0
    return st;
140
0
}
141
/**
142
 * fu_struct_ds20_to_string: (skip):
143
 **/
144
static gchar *
145
fu_struct_ds20_to_string(const FuStructDs20 *st)
146
0
{
147
0
    g_autoptr(GString) str = g_string_new("FuStructDs20:\n");
148
0
    g_return_val_if_fail(st != NULL, NULL);
149
0
    {
150
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_ds20_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
151
0
        g_string_append_printf(str, "  guid: %s\n", tmp);
152
0
    }
153
0
    g_string_append_printf(str, "  platform_ver: 0x%x\n",
154
0
                           (guint) fu_struct_ds20_get_platform_ver(st));
155
0
    g_string_append_printf(str, "  total_length: 0x%x\n",
156
0
                           (guint) fu_struct_ds20_get_total_length(st));
157
0
    g_string_append_printf(str, "  vendor_code: 0x%x\n",
158
0
                           (guint) fu_struct_ds20_get_vendor_code(st));
159
0
    g_string_append_printf(str, "  alt_code: 0x%x\n",
160
0
                           (guint) fu_struct_ds20_get_alt_code(st));
161
0
    if (str->len > 0)
162
0
        g_string_set_size(str, str->len - 1);
163
0
    return g_string_free(g_steal_pointer(&str), FALSE);
164
0
}
165
static gboolean
166
fu_struct_ds20_validate_internal(FuStructDs20 *st, GError **error)
167
0
{
168
0
    g_return_val_if_fail(st != NULL, FALSE);
169
0
    return TRUE;
170
0
}
171
static gboolean
172
fu_struct_ds20_parse_internal(FuStructDs20 *st, GError **error)
173
0
{
174
0
    if (!fu_struct_ds20_validate_internal(st, error))
175
0
        return FALSE;
176
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
177
0
        g_autofree gchar *str = fu_struct_ds20_to_string(st);
178
0
        g_debug("%s", str);
179
0
    }
180
0
    return TRUE;
181
0
}
182
/**
183
 * fu_struct_ds20_parse_stream: (skip):
184
 **/
185
FuStructDs20 *
186
fu_struct_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error)
187
0
{
188
0
    g_autoptr(GByteArray) st = NULL;
189
0
    st = fu_input_stream_read_byte_array(stream, offset, 25, NULL, error);
190
0
    if (st == NULL) {
191
0
        g_prefix_error(error, "FuStructDs20 failed read of 0x%x: ", (guint) 25);
192
0
        return NULL;
193
0
    }
194
0
    if (st->len != 25) {
195
0
        g_set_error(error,
196
0
                    FWUPD_ERROR,
197
0
                    FWUPD_ERROR_INVALID_DATA,
198
0
                    "FuStructDs20 requested 0x%x and got 0x%x",
199
0
                    (guint) 25,
200
0
                    (guint) st->len);
201
0
        return NULL;
202
0
    }
203
0
    if (!fu_struct_ds20_parse_internal(st, error))
204
0
        return NULL;
205
0
    return g_steal_pointer(&st);
206
0
}
207
/* getters */
208
/**
209
 * fu_struct_ms_ds20_get_size: (skip):
210
 **/
211
guint16
212
fu_struct_ms_ds20_get_size(const FuStructMsDs20 *st)
213
0
{
214
0
    g_return_val_if_fail(st != NULL, 0x0);
215
0
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
216
0
}
217
/**
218
 * fu_struct_ms_ds20_get_type: (skip):
219
 **/
220
guint16
221
fu_struct_ms_ds20_get_type(const FuStructMsDs20 *st)
222
0
{
223
0
    g_return_val_if_fail(st != NULL, 0x0);
224
0
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
225
0
}
226
227
/* setters */
228
/**
229
 * fu_struct_ms_ds20_set_size: (skip):
230
 **/
231
void
232
fu_struct_ms_ds20_set_size(FuStructMsDs20 *st, guint16 value)
233
0
{
234
0
    g_return_if_fail(st != NULL);
235
0
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
236
0
}
237
/**
238
 * fu_struct_ms_ds20_set_type: (skip):
239
 **/
240
void
241
fu_struct_ms_ds20_set_type(FuStructMsDs20 *st, guint16 value)
242
0
{
243
0
    g_return_if_fail(st != NULL);
244
0
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
245
0
}
246
/**
247
 * fu_struct_ms_ds20_new: (skip):
248
 **/
249
FuStructMsDs20 *
250
fu_struct_ms_ds20_new(void)
251
0
{
252
0
    FuStructMsDs20 *st = g_byte_array_sized_new(4);
253
0
    fu_byte_array_set_size(st, 4, 0x0);
254
0
    return st;
255
0
}
256
/**
257
 * fu_struct_ms_ds20_to_string: (skip):
258
 **/
259
static gchar *
260
fu_struct_ms_ds20_to_string(const FuStructMsDs20 *st)
261
0
{
262
0
    g_autoptr(GString) str = g_string_new("FuStructMsDs20:\n");
263
0
    g_return_val_if_fail(st != NULL, NULL);
264
0
    g_string_append_printf(str, "  size: 0x%x\n",
265
0
                           (guint) fu_struct_ms_ds20_get_size(st));
266
0
    g_string_append_printf(str, "  type: 0x%x\n",
267
0
                           (guint) fu_struct_ms_ds20_get_type(st));
268
0
    if (str->len > 0)
269
0
        g_string_set_size(str, str->len - 1);
270
0
    return g_string_free(g_steal_pointer(&str), FALSE);
271
0
}
272
static gboolean
273
fu_struct_ms_ds20_validate_internal(FuStructMsDs20 *st, GError **error)
274
0
{
275
0
    g_return_val_if_fail(st != NULL, FALSE);
276
0
    return TRUE;
277
0
}
278
static gboolean
279
fu_struct_ms_ds20_parse_internal(FuStructMsDs20 *st, GError **error)
280
0
{
281
0
    if (!fu_struct_ms_ds20_validate_internal(st, error))
282
0
        return FALSE;
283
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
284
0
        g_autofree gchar *str = fu_struct_ms_ds20_to_string(st);
285
0
        g_debug("%s", str);
286
0
    }
287
0
    return TRUE;
288
0
}
289
/**
290
 * fu_struct_ms_ds20_parse_stream: (skip):
291
 **/
292
FuStructMsDs20 *
293
fu_struct_ms_ds20_parse_stream(GInputStream *stream, gsize offset, GError **error)
294
0
{
295
0
    g_autoptr(GByteArray) st = NULL;
296
0
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
297
0
    if (st == NULL) {
298
0
        g_prefix_error(error, "FuStructMsDs20 failed read of 0x%x: ", (guint) 4);
299
0
        return NULL;
300
0
    }
301
0
    if (st->len != 4) {
302
0
        g_set_error(error,
303
0
                    FWUPD_ERROR,
304
0
                    FWUPD_ERROR_INVALID_DATA,
305
0
                    "FuStructMsDs20 requested 0x%x and got 0x%x",
306
0
                    (guint) 4,
307
0
                    (guint) st->len);
308
0
        return NULL;
309
0
    }
310
0
    if (!fu_struct_ms_ds20_parse_internal(st, error))
311
0
        return NULL;
312
0
    return g_steal_pointer(&st);
313
0
}