Coverage Report

Created: 2025-12-14 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-ccgx-pure-hid-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-ccgx-pure-hid-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_ccgx_pure_hid_fw_mode_to_string:
23
 * @val: value, e.g. %FU_CCGX_PURE_HID_FW_MODE_FW1
24
 *
25
 * Converts an enumerated value to a string.
26
 *
27
 * Returns: identifier string
28
 **/
29
const gchar *
30
fu_ccgx_pure_hid_fw_mode_to_string(FuCcgxPureHidFwMode val)
31
0
{
32
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_BOOT)
33
0
        return "boot";
34
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_FW1)
35
0
        return "fw1";
36
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_FW2)
37
0
        return "fw2";
38
0
    return NULL;
39
0
}
40
41
/**
42
 * fu_ccgx_pure_hid_report_id_to_string:
43
 * @val: value, e.g. %FU_CCGX_PURE_HID_REPORT_ID_COMMAND
44
 *
45
 * Converts an enumerated value to a string.
46
 *
47
 * Returns: identifier string
48
 **/
49
static const gchar *
50
fu_ccgx_pure_hid_report_id_to_string(FuCcgxPureHidReportId val)
51
0
{
52
0
    if (val == FU_CCGX_PURE_HID_REPORT_ID_INFO)
53
0
        return "info";
54
0
    if (val == FU_CCGX_PURE_HID_REPORT_ID_COMMAND)
55
0
        return "command";
56
0
    if (val == FU_CCGX_PURE_HID_REPORT_ID_WRITE)
57
0
        return "write";
58
0
    if (val == FU_CCGX_PURE_HID_REPORT_ID_READ)
59
0
        return "read";
60
0
    if (val == FU_CCGX_PURE_HID_REPORT_ID_CUSTOM)
61
0
        return "custom";
62
0
    return NULL;
63
0
}
64
65
/**
66
 * fu_struct_ccgx_pure_hid_fw_info_ref: (skip):
67
 **/
68
FuStructCcgxPureHidFwInfo *
69
fu_struct_ccgx_pure_hid_fw_info_ref(FuStructCcgxPureHidFwInfo *st)
70
0
{
71
0
    g_return_val_if_fail(st != NULL, NULL);
72
0
    st->refcount++;
73
0
    return st;
74
0
}
75
/**
76
 * fu_struct_ccgx_pure_hid_fw_info_unref: (skip):
77
 **/
78
void
79
fu_struct_ccgx_pure_hid_fw_info_unref(FuStructCcgxPureHidFwInfo *st)
80
0
{
81
0
    g_return_if_fail(st != NULL);
82
0
    if (st->refcount == 0) {
83
0
        g_critical("FuStructCcgxPureHidFwInfo refcount already zero");
84
0
        return;
85
0
    }
86
0
    if (--st->refcount > 0)
87
0
        return;
88
0
    if (st->buf != NULL)
89
0
        g_byte_array_unref(st->buf);
90
0
    g_free(st);
91
0
}
92
/**
93
 * fu_struct_ccgx_pure_hid_fw_info_new_internal: (skip):
94
 **/
95
static FuStructCcgxPureHidFwInfo *
96
fu_struct_ccgx_pure_hid_fw_info_new_internal(void)
97
0
{
98
0
    FuStructCcgxPureHidFwInfo *st = g_new0(FuStructCcgxPureHidFwInfo, 1);
99
0
    st->refcount = 1;
100
0
    return st;
101
0
}
102
103
/* getters */
104
/**
105
 * fu_struct_ccgx_pure_hid_fw_info_get_report_id: (skip):
106
 **/
107
static FuCcgxPureHidReportId
108
fu_struct_ccgx_pure_hid_fw_info_get_report_id(const FuStructCcgxPureHidFwInfo *st)
109
0
{
110
0
    g_return_val_if_fail(st != NULL, 0x0);
111
0
    return st->buf->data[0];
112
0
}
113
/**
114
 * fu_struct_ccgx_pure_hid_fw_info_get_signature: (skip):
115
 **/
116
static guint16
117
fu_struct_ccgx_pure_hid_fw_info_get_signature(const FuStructCcgxPureHidFwInfo *st)
118
0
{
119
0
    g_return_val_if_fail(st != NULL, 0x0);
120
0
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
121
0
}
122
/**
123
 * fu_struct_ccgx_pure_hid_fw_info_get_operating_mode: (skip):
124
 **/
125
FuCcgxPureHidFwMode
126
fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(const FuStructCcgxPureHidFwInfo *st)
127
0
{
128
0
    g_return_val_if_fail(st != NULL, 0x0);
129
0
    return st->buf->data[4];
130
0
}
131
/**
132
 * fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info: (skip):
133
 **/
134
guint8
135
fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(const FuStructCcgxPureHidFwInfo *st)
136
0
{
137
0
    g_return_val_if_fail(st != NULL, 0x0);
138
0
    return st->buf->data[5];
139
0
}
140
/**
141
 * fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason: (skip):
142
 **/
143
guint8
144
fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(const FuStructCcgxPureHidFwInfo *st)
145
0
{
146
0
    g_return_val_if_fail(st != NULL, 0x0);
147
0
    return st->buf->data[6];
148
0
}
149
/**
150
 * fu_struct_ccgx_pure_hid_fw_info_get_silicon_id: (skip):
151
 **/
152
guint32
153
fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(const FuStructCcgxPureHidFwInfo *st)
154
0
{
155
0
    g_return_val_if_fail(st != NULL, 0x0);
156
0
    return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN);
157
0
}
158
/**
159
 * fu_struct_ccgx_pure_hid_fw_info_get_bl_version: (skip):
160
 **/
161
guint32
162
fu_struct_ccgx_pure_hid_fw_info_get_bl_version(const FuStructCcgxPureHidFwInfo *st)
163
0
{
164
0
    g_return_val_if_fail(st != NULL, 0x0);
165
0
    return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN);
166
0
}
167
/**
168
 * fu_struct_ccgx_pure_hid_fw_info_get_image1_version: (skip):
169
 **/
170
guint32
171
fu_struct_ccgx_pure_hid_fw_info_get_image1_version(const FuStructCcgxPureHidFwInfo *st)
172
0
{
173
0
    g_return_val_if_fail(st != NULL, 0x0);
174
0
    return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN);
175
0
}
176
/**
177
 * fu_struct_ccgx_pure_hid_fw_info_get_image2_version: (skip):
178
 **/
179
guint32
180
fu_struct_ccgx_pure_hid_fw_info_get_image2_version(const FuStructCcgxPureHidFwInfo *st)
181
0
{
182
0
    g_return_val_if_fail(st != NULL, 0x0);
183
0
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
184
0
}
185
/**
186
 * fu_struct_ccgx_pure_hid_fw_info_get_image1_row: (skip):
187
 **/
188
guint32
189
fu_struct_ccgx_pure_hid_fw_info_get_image1_row(const FuStructCcgxPureHidFwInfo *st)
190
0
{
191
0
    g_return_val_if_fail(st != NULL, 0x0);
192
0
    return fu_memread_uint32(st->buf->data + 36, G_LITTLE_ENDIAN);
193
0
}
194
/**
195
 * fu_struct_ccgx_pure_hid_fw_info_get_image2_row: (skip):
196
 **/
197
guint32
198
fu_struct_ccgx_pure_hid_fw_info_get_image2_row(const FuStructCcgxPureHidFwInfo *st)
199
0
{
200
0
    g_return_val_if_fail(st != NULL, 0x0);
201
0
    return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN);
202
0
}
203
/**
204
 * fu_struct_ccgx_pure_hid_fw_info_get_device_uid: (skip):
205
 **/
206
const guint8 *
207
fu_struct_ccgx_pure_hid_fw_info_get_device_uid(const FuStructCcgxPureHidFwInfo *st, gsize *bufsz)
208
0
{
209
0
    g_return_val_if_fail(st != NULL, NULL);
210
0
    if (bufsz != NULL)
211
0
        *bufsz = 6;
212
0
    return st->buf->data + 44;
213
0
}
214
215
/* setters */
216
/**
217
 * fu_struct_ccgx_pure_hid_fw_info_to_string: (skip):
218
 **/
219
static gchar *
220
fu_struct_ccgx_pure_hid_fw_info_to_string(const FuStructCcgxPureHidFwInfo *st)
221
0
{
222
0
    g_autoptr(GString) str = g_string_new("FuStructCcgxPureHidFwInfo:\n");
223
0
    g_return_val_if_fail(st != NULL, NULL);
224
0
    {
225
0
        const gchar *tmp = fu_ccgx_pure_hid_fw_mode_to_string(fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st));
226
0
        if (tmp != NULL) {
227
0
            g_string_append_printf(str, "  operating_mode: 0x%x [%s]\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st), tmp);
228
0
        } else {
229
0
            g_string_append_printf(str, "  operating_mode: 0x%x\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st));
230
0
        }
231
0
    }
232
0
    g_string_append_printf(str, "  bootloader_info: 0x%x\n",
233
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(st));
234
0
    g_string_append_printf(str, "  bootmode_reason: 0x%x\n",
235
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(st));
236
0
    g_string_append_printf(str, "  silicon_id: 0x%x\n",
237
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(st));
238
0
    g_string_append_printf(str, "  bl_version: 0x%x\n",
239
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bl_version(st));
240
0
    g_string_append_printf(str, "  image1_version: 0x%x\n",
241
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_version(st));
242
0
    g_string_append_printf(str, "  image2_version: 0x%x\n",
243
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_version(st));
244
0
    g_string_append_printf(str, "  image1_row: 0x%x\n",
245
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_row(st));
246
0
    g_string_append_printf(str, "  image2_row: 0x%x\n",
247
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_row(st));
248
0
    {
249
0
        gsize bufsz = 0;
250
0
        const guint8 *buf = fu_struct_ccgx_pure_hid_fw_info_get_device_uid(st, &bufsz);
251
0
        g_autoptr(GString) tmp = g_string_new(NULL);
252
0
        for (gsize i = 0; i < bufsz; i++)
253
0
            g_string_append_printf(tmp, "%02X", buf[i]);
254
0
        g_string_append_printf(str, "  device_uid: 0x%s\n", tmp->str);
255
0
    }
256
0
    if (str->len > 0)
257
0
        g_string_set_size(str, str->len - 1);
258
0
    return g_string_free(g_steal_pointer(&str), FALSE);
259
0
}
260
static gboolean
261
fu_struct_ccgx_pure_hid_fw_info_validate_internal(FuStructCcgxPureHidFwInfo *st, GError **error)
262
0
{
263
0
    g_return_val_if_fail(st != NULL, FALSE);
264
0
    if (fu_struct_ccgx_pure_hid_fw_info_get_report_id(st) != FU_CCGX_PURE_HID_REPORT_ID_INFO) {
265
0
        g_set_error(error,
266
0
                    FWUPD_ERROR,
267
0
                    FWUPD_ERROR_INVALID_DATA,
268
0
                    "constant FuStructCcgxPureHidFwInfo.report_id was not valid, "
269
0
                    "expected 'FuCcgxPureHidReportId' and got '%s'",
270
0
                    fu_ccgx_pure_hid_report_id_to_string(fu_struct_ccgx_pure_hid_fw_info_get_report_id(st)));
271
0
        return FALSE;
272
0
    }
273
0
    if (fu_struct_ccgx_pure_hid_fw_info_get_signature(st) != 0x5943) {
274
0
        g_set_error(error,
275
0
                    FWUPD_ERROR,
276
0
                    FWUPD_ERROR_INVALID_DATA,
277
0
                    "constant FuStructCcgxPureHidFwInfo.signature was not valid, "
278
0
                    "expected 0x%x and got 0x%x",
279
0
                    (guint) 0x5943,
280
0
                    (guint) fu_struct_ccgx_pure_hid_fw_info_get_signature(st));
281
0
        return FALSE;
282
0
    }
283
0
    return TRUE;
284
0
}
285
static gboolean
286
fu_struct_ccgx_pure_hid_fw_info_parse_internal(FuStructCcgxPureHidFwInfo *st, GError **error)
287
0
{
288
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
289
0
        g_autofree gchar *str = fu_struct_ccgx_pure_hid_fw_info_to_string(st);
290
0
        g_debug("%s", str);
291
0
    }
292
0
    if (!fu_struct_ccgx_pure_hid_fw_info_validate_internal(st, error))
293
0
        return FALSE;
294
0
    return TRUE;
295
0
}
296
297
/**
298
 * fu_struct_ccgx_pure_hid_fw_info_parse: (skip):
299
 **/
300
FuStructCcgxPureHidFwInfo *
301
fu_struct_ccgx_pure_hid_fw_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
302
0
{
303
0
    g_autoptr(FuStructCcgxPureHidFwInfo) st = fu_struct_ccgx_pure_hid_fw_info_new_internal();
304
0
    g_return_val_if_fail(buf != NULL, NULL);
305
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
306
0
    if (!fu_memchk_read(bufsz, offset, 60, error)) {
307
0
        g_prefix_error_literal(error, "invalid struct FuStructCcgxPureHidFwInfo: ");
308
0
        return NULL;
309
0
    }
310
0
    st->buf = g_byte_array_new();
311
0
    g_byte_array_append(st->buf, buf + offset, 60);
312
0
    if (!fu_struct_ccgx_pure_hid_fw_info_parse_internal(st, error))
313
0
        return NULL;
314
0
    return g_steal_pointer(&st);
315
0
}
316
/**
317
 * fu_struct_ccgx_pure_hid_command_ref: (skip):
318
 **/
319
FuStructCcgxPureHidCommand *
320
fu_struct_ccgx_pure_hid_command_ref(FuStructCcgxPureHidCommand *st)
321
0
{
322
0
    g_return_val_if_fail(st != NULL, NULL);
323
0
    st->refcount++;
324
0
    return st;
325
0
}
326
/**
327
 * fu_struct_ccgx_pure_hid_command_unref: (skip):
328
 **/
329
void
330
fu_struct_ccgx_pure_hid_command_unref(FuStructCcgxPureHidCommand *st)
331
0
{
332
0
    g_return_if_fail(st != NULL);
333
0
    if (st->refcount == 0) {
334
0
        g_critical("FuStructCcgxPureHidCommand refcount already zero");
335
0
        return;
336
0
    }
337
0
    if (--st->refcount > 0)
338
0
        return;
339
0
    if (st->buf != NULL)
340
0
        g_byte_array_unref(st->buf);
341
0
    g_free(st);
342
0
}
343
/**
344
 * fu_struct_ccgx_pure_hid_command_new_internal: (skip):
345
 **/
346
static FuStructCcgxPureHidCommand *
347
fu_struct_ccgx_pure_hid_command_new_internal(void)
348
0
{
349
0
    FuStructCcgxPureHidCommand *st = g_new0(FuStructCcgxPureHidCommand, 1);
350
0
    st->refcount = 1;
351
0
    return st;
352
0
}
353
354
/* getters */
355
356
/* setters */
357
/**
358
 * fu_struct_ccgx_pure_hid_command_set_report_id: (skip):
359
 **/
360
static void
361
fu_struct_ccgx_pure_hid_command_set_report_id(FuStructCcgxPureHidCommand *st, FuCcgxPureHidReportId value)
362
0
{
363
0
    g_return_if_fail(st != NULL);
364
0
    st->buf->data[0] = value;
365
0
}
366
/**
367
 * fu_struct_ccgx_pure_hid_command_set_cmd: (skip):
368
 **/
369
void
370
fu_struct_ccgx_pure_hid_command_set_cmd(FuStructCcgxPureHidCommand *st, guint8 value)
371
0
{
372
0
    g_return_if_fail(st != NULL);
373
0
    st->buf->data[1] = value;
374
0
}
375
/**
376
 * fu_struct_ccgx_pure_hid_command_set_opt: (skip):
377
 **/
378
void
379
fu_struct_ccgx_pure_hid_command_set_opt(FuStructCcgxPureHidCommand *st, guint8 value)
380
0
{
381
0
    g_return_if_fail(st != NULL);
382
0
    st->buf->data[2] = value;
383
0
}
384
/**
385
 * fu_struct_ccgx_pure_hid_command_set_pad1: (skip):
386
 **/
387
void
388
fu_struct_ccgx_pure_hid_command_set_pad1(FuStructCcgxPureHidCommand *st, guint8 value)
389
0
{
390
0
    g_return_if_fail(st != NULL);
391
0
    st->buf->data[3] = value;
392
0
}
393
/**
394
 * fu_struct_ccgx_pure_hid_command_set_pad2: (skip):
395
 **/
396
void
397
fu_struct_ccgx_pure_hid_command_set_pad2(FuStructCcgxPureHidCommand *st, guint32 value)
398
0
{
399
0
    g_return_if_fail(st != NULL);
400
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
401
0
}
402
/**
403
 * fu_struct_ccgx_pure_hid_command_new: (skip):
404
 **/
405
FuStructCcgxPureHidCommand *
406
fu_struct_ccgx_pure_hid_command_new(void)
407
0
{
408
0
    FuStructCcgxPureHidCommand *st = fu_struct_ccgx_pure_hid_command_new_internal();
409
0
    st->buf = g_byte_array_sized_new(8);
410
0
    fu_byte_array_set_size(st->buf, 8, 0x0);
411
0
    fu_struct_ccgx_pure_hid_command_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_COMMAND);
412
0
    fu_struct_ccgx_pure_hid_command_set_pad1(st, 0x00);
413
0
    fu_struct_ccgx_pure_hid_command_set_pad2(st, 0xCCCCCCCC);
414
0
    return st;
415
0
}
416
/**
417
 * fu_struct_ccgx_pure_hid_write_hdr_ref: (skip):
418
 **/
419
FuStructCcgxPureHidWriteHdr *
420
fu_struct_ccgx_pure_hid_write_hdr_ref(FuStructCcgxPureHidWriteHdr *st)
421
0
{
422
0
    g_return_val_if_fail(st != NULL, NULL);
423
0
    st->refcount++;
424
0
    return st;
425
0
}
426
/**
427
 * fu_struct_ccgx_pure_hid_write_hdr_unref: (skip):
428
 **/
429
void
430
fu_struct_ccgx_pure_hid_write_hdr_unref(FuStructCcgxPureHidWriteHdr *st)
431
0
{
432
0
    g_return_if_fail(st != NULL);
433
0
    if (st->refcount == 0) {
434
0
        g_critical("FuStructCcgxPureHidWriteHdr refcount already zero");
435
0
        return;
436
0
    }
437
0
    if (--st->refcount > 0)
438
0
        return;
439
0
    if (st->buf != NULL)
440
0
        g_byte_array_unref(st->buf);
441
0
    g_free(st);
442
0
}
443
/**
444
 * fu_struct_ccgx_pure_hid_write_hdr_new_internal: (skip):
445
 **/
446
static FuStructCcgxPureHidWriteHdr *
447
fu_struct_ccgx_pure_hid_write_hdr_new_internal(void)
448
0
{
449
0
    FuStructCcgxPureHidWriteHdr *st = g_new0(FuStructCcgxPureHidWriteHdr, 1);
450
0
    st->refcount = 1;
451
0
    return st;
452
0
}
453
454
/* getters */
455
456
/* setters */
457
/**
458
 * fu_struct_ccgx_pure_hid_write_hdr_set_report_id: (skip):
459
 **/
460
static void
461
fu_struct_ccgx_pure_hid_write_hdr_set_report_id(FuStructCcgxPureHidWriteHdr *st, FuCcgxPureHidReportId value)
462
0
{
463
0
    g_return_if_fail(st != NULL);
464
0
    st->buf->data[0] = value;
465
0
}
466
/**
467
 * fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp: (skip):
468
 **/
469
void
470
fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp(FuStructCcgxPureHidWriteHdr *st, guint8 value)
471
0
{
472
0
    g_return_if_fail(st != NULL);
473
0
    st->buf->data[1] = value;
474
0
}
475
/**
476
 * fu_struct_ccgx_pure_hid_write_hdr_set_addr: (skip):
477
 **/
478
void
479
fu_struct_ccgx_pure_hid_write_hdr_set_addr(FuStructCcgxPureHidWriteHdr *st, guint16 value)
480
0
{
481
0
    g_return_if_fail(st != NULL);
482
0
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
483
0
}
484
/**
485
 * fu_struct_ccgx_pure_hid_write_hdr_set_data: (skip):
486
 **/
487
gboolean
488
fu_struct_ccgx_pure_hid_write_hdr_set_data(FuStructCcgxPureHidWriteHdr *st, const guint8 *buf, gsize bufsz, GError **error)
489
0
{
490
0
    g_return_val_if_fail(st != NULL, FALSE);
491
0
    g_return_val_if_fail(buf != NULL, FALSE);
492
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
493
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 4, buf, bufsz, 0x0, bufsz, error);
494
0
}
495
/**
496
 * fu_struct_ccgx_pure_hid_write_hdr_new: (skip):
497
 **/
498
FuStructCcgxPureHidWriteHdr *
499
fu_struct_ccgx_pure_hid_write_hdr_new(void)
500
0
{
501
0
    FuStructCcgxPureHidWriteHdr *st = fu_struct_ccgx_pure_hid_write_hdr_new_internal();
502
0
    st->buf = g_byte_array_sized_new(132);
503
0
    fu_byte_array_set_size(st->buf, 132, 0x0);
504
0
    fu_struct_ccgx_pure_hid_write_hdr_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_WRITE);
505
0
    return st;
506
0
}