Coverage Report

Created: 2025-11-11 06:44

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