Coverage Report

Created: 2025-11-24 06:59

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