Coverage Report

Created: 2025-07-11 06:31

/work/fu-ccgx-pure-hid-struct.c
Line
Count
Source (jump to first uncovered line)
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include "fu-ccgx-pure-hid-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_ccgx_pure_hid_fw_mode_to_string(FuCcgxPureHidFwMode val)
16
0
{
17
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_BOOT)
18
0
        return "boot";
19
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_FW1)
20
0
        return "fw1";
21
0
    if (val == FU_CCGX_PURE_HID_FW_MODE_FW2)
22
0
        return "fw2";
23
0
    return NULL;
24
0
}
25
26
27
/* getters */
28
/**
29
 * fu_struct_ccgx_pure_hid_fw_info_get_report_id: (skip):
30
 **/
31
static FuCcgxPureHidReportId
32
fu_struct_ccgx_pure_hid_fw_info_get_report_id(const FuStructCcgxPureHidFwInfo *st)
33
0
{
34
0
    g_return_val_if_fail(st != NULL, 0x0);
35
0
    return st->data[0];
36
0
}
37
/**
38
 * fu_struct_ccgx_pure_hid_fw_info_get_signature: (skip):
39
 **/
40
static guint16
41
fu_struct_ccgx_pure_hid_fw_info_get_signature(const FuStructCcgxPureHidFwInfo *st)
42
0
{
43
0
    g_return_val_if_fail(st != NULL, 0x0);
44
0
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
45
0
}
46
/**
47
 * fu_struct_ccgx_pure_hid_fw_info_get_operating_mode: (skip):
48
 **/
49
FuCcgxPureHidFwMode
50
fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(const FuStructCcgxPureHidFwInfo *st)
51
0
{
52
0
    g_return_val_if_fail(st != NULL, 0x0);
53
0
    return st->data[4];
54
0
}
55
/**
56
 * fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info: (skip):
57
 **/
58
guint8
59
fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(const FuStructCcgxPureHidFwInfo *st)
60
0
{
61
0
    g_return_val_if_fail(st != NULL, 0x0);
62
0
    return st->data[5];
63
0
}
64
/**
65
 * fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason: (skip):
66
 **/
67
guint8
68
fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(const FuStructCcgxPureHidFwInfo *st)
69
0
{
70
0
    g_return_val_if_fail(st != NULL, 0x0);
71
0
    return st->data[6];
72
0
}
73
/**
74
 * fu_struct_ccgx_pure_hid_fw_info_get_silicon_id: (skip):
75
 **/
76
guint32
77
fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(const FuStructCcgxPureHidFwInfo *st)
78
0
{
79
0
    g_return_val_if_fail(st != NULL, 0x0);
80
0
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
81
0
}
82
/**
83
 * fu_struct_ccgx_pure_hid_fw_info_get_bl_version: (skip):
84
 **/
85
guint32
86
fu_struct_ccgx_pure_hid_fw_info_get_bl_version(const FuStructCcgxPureHidFwInfo *st)
87
0
{
88
0
    g_return_val_if_fail(st != NULL, 0x0);
89
0
    return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN);
90
0
}
91
/**
92
 * fu_struct_ccgx_pure_hid_fw_info_get_image1_version: (skip):
93
 **/
94
guint32
95
fu_struct_ccgx_pure_hid_fw_info_get_image1_version(const FuStructCcgxPureHidFwInfo *st)
96
0
{
97
0
    g_return_val_if_fail(st != NULL, 0x0);
98
0
    return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN);
99
0
}
100
/**
101
 * fu_struct_ccgx_pure_hid_fw_info_get_image2_version: (skip):
102
 **/
103
guint32
104
fu_struct_ccgx_pure_hid_fw_info_get_image2_version(const FuStructCcgxPureHidFwInfo *st)
105
0
{
106
0
    g_return_val_if_fail(st != NULL, 0x0);
107
0
    return fu_memread_uint32(st->data + 28, G_LITTLE_ENDIAN);
108
0
}
109
/**
110
 * fu_struct_ccgx_pure_hid_fw_info_get_image1_row: (skip):
111
 **/
112
guint32
113
fu_struct_ccgx_pure_hid_fw_info_get_image1_row(const FuStructCcgxPureHidFwInfo *st)
114
0
{
115
0
    g_return_val_if_fail(st != NULL, 0x0);
116
0
    return fu_memread_uint32(st->data + 36, G_LITTLE_ENDIAN);
117
0
}
118
/**
119
 * fu_struct_ccgx_pure_hid_fw_info_get_image2_row: (skip):
120
 **/
121
guint32
122
fu_struct_ccgx_pure_hid_fw_info_get_image2_row(const FuStructCcgxPureHidFwInfo *st)
123
0
{
124
0
    g_return_val_if_fail(st != NULL, 0x0);
125
0
    return fu_memread_uint32(st->data + 40, G_LITTLE_ENDIAN);
126
0
}
127
/**
128
 * fu_struct_ccgx_pure_hid_fw_info_get_device_uid: (skip):
129
 **/
130
const guint8 *
131
fu_struct_ccgx_pure_hid_fw_info_get_device_uid(const FuStructCcgxPureHidFwInfo *st, gsize *bufsz)
132
0
{
133
0
    g_return_val_if_fail(st != NULL, NULL);
134
0
    if (bufsz != NULL)
135
0
        *bufsz = 6;
136
0
    return st->data + 44;
137
0
}
138
139
/* setters */
140
/**
141
 * fu_struct_ccgx_pure_hid_fw_info_to_string: (skip):
142
 **/
143
static gchar *
144
fu_struct_ccgx_pure_hid_fw_info_to_string(const FuStructCcgxPureHidFwInfo *st)
145
0
{
146
0
    g_autoptr(GString) str = g_string_new("FuStructCcgxPureHidFwInfo:\n");
147
0
    g_return_val_if_fail(st != NULL, NULL);
148
0
    {
149
0
        const gchar *tmp = fu_ccgx_pure_hid_fw_mode_to_string(fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st));
150
0
        if (tmp != NULL) {
151
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);
152
0
        } else {
153
0
            g_string_append_printf(str, "  operating_mode: 0x%x\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st));
154
0
        }
155
0
    }
156
0
    g_string_append_printf(str, "  bootloader_info: 0x%x\n",
157
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(st));
158
0
    g_string_append_printf(str, "  bootmode_reason: 0x%x\n",
159
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(st));
160
0
    g_string_append_printf(str, "  silicon_id: 0x%x\n",
161
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(st));
162
0
    g_string_append_printf(str, "  bl_version: 0x%x\n",
163
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_bl_version(st));
164
0
    g_string_append_printf(str, "  image1_version: 0x%x\n",
165
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_version(st));
166
0
    g_string_append_printf(str, "  image2_version: 0x%x\n",
167
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_version(st));
168
0
    g_string_append_printf(str, "  image1_row: 0x%x\n",
169
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_row(st));
170
0
    g_string_append_printf(str, "  image2_row: 0x%x\n",
171
0
                           (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_row(st));
172
0
    {
173
0
        gsize bufsz = 0;
174
0
        const guint8 *buf = fu_struct_ccgx_pure_hid_fw_info_get_device_uid(st, &bufsz);
175
0
        g_autoptr(GString) tmp = g_string_new(NULL);
176
0
        for (gsize i = 0; i < bufsz; i++)
177
0
            g_string_append_printf(tmp, "%02X", buf[i]);
178
0
        g_string_append_printf(str, "  device_uid: 0x%s\n", tmp->str);
179
0
    }
180
0
    if (str->len > 0)
181
0
        g_string_set_size(str, str->len - 1);
182
0
    return g_string_free(g_steal_pointer(&str), FALSE);
183
0
}
184
static gboolean
185
fu_struct_ccgx_pure_hid_fw_info_validate_internal(FuStructCcgxPureHidFwInfo *st, GError **error)
186
0
{
187
0
    g_return_val_if_fail(st != NULL, FALSE);
188
0
    if (fu_struct_ccgx_pure_hid_fw_info_get_report_id(st) != FU_CCGX_PURE_HID_REPORT_ID_INFO) {
189
0
        g_set_error_literal(error,
190
0
                            FWUPD_ERROR,
191
0
                            FWUPD_ERROR_INVALID_DATA,
192
0
                            "constant FuStructCcgxPureHidFwInfo.report_id was not valid");
193
0
        return FALSE;
194
0
    }
195
0
    if (fu_struct_ccgx_pure_hid_fw_info_get_signature(st) != 0x5943) {
196
0
        g_set_error(error,
197
0
                    FWUPD_ERROR,
198
0
                    FWUPD_ERROR_INVALID_DATA,
199
0
                    "constant FuStructCcgxPureHidFwInfo.signature was not valid, "
200
0
                    "expected 0x%x and got 0x%x",
201
0
                    (guint) 0x5943,
202
0
                    (guint) fu_struct_ccgx_pure_hid_fw_info_get_signature(st));
203
0
        return FALSE;
204
0
    }
205
0
    return TRUE;
206
0
}
207
static gboolean
208
fu_struct_ccgx_pure_hid_fw_info_parse_internal(FuStructCcgxPureHidFwInfo *st, GError **error)
209
0
{
210
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
211
0
        g_autofree gchar *str = fu_struct_ccgx_pure_hid_fw_info_to_string(st);
212
0
        g_debug("%s", str);
213
0
    }
214
0
    if (!fu_struct_ccgx_pure_hid_fw_info_validate_internal(st, error))
215
0
        return FALSE;
216
0
    return TRUE;
217
0
}
218
219
/**
220
 * fu_struct_ccgx_pure_hid_fw_info_parse: (skip):
221
 **/
222
FuStructCcgxPureHidFwInfo *
223
fu_struct_ccgx_pure_hid_fw_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
224
0
{
225
0
    g_autoptr(GByteArray) st = g_byte_array_new();
226
0
    g_return_val_if_fail(buf != NULL, NULL);
227
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
228
0
    if (!fu_memchk_read(bufsz, offset, 60, error)) {
229
0
        g_prefix_error(error, "invalid struct FuStructCcgxPureHidFwInfo: ");
230
0
        return NULL;
231
0
    }
232
0
    g_byte_array_append(st, buf + offset, 60);
233
0
    if (!fu_struct_ccgx_pure_hid_fw_info_parse_internal(st, error))
234
0
        return NULL;
235
0
    return g_steal_pointer(&st);
236
0
}
237
/* getters */
238
239
/* setters */
240
/**
241
 * fu_struct_ccgx_pure_hid_command_set_report_id: (skip):
242
 **/
243
static void
244
fu_struct_ccgx_pure_hid_command_set_report_id(FuStructCcgxPureHidCommand *st, FuCcgxPureHidReportId value)
245
0
{
246
0
    g_return_if_fail(st != NULL);
247
0
    st->data[0] = value;
248
0
}
249
/**
250
 * fu_struct_ccgx_pure_hid_command_set_cmd: (skip):
251
 **/
252
void
253
fu_struct_ccgx_pure_hid_command_set_cmd(FuStructCcgxPureHidCommand *st, guint8 value)
254
0
{
255
0
    g_return_if_fail(st != NULL);
256
0
    st->data[1] = value;
257
0
}
258
/**
259
 * fu_struct_ccgx_pure_hid_command_set_opt: (skip):
260
 **/
261
void
262
fu_struct_ccgx_pure_hid_command_set_opt(FuStructCcgxPureHidCommand *st, guint8 value)
263
0
{
264
0
    g_return_if_fail(st != NULL);
265
0
    st->data[2] = value;
266
0
}
267
/**
268
 * fu_struct_ccgx_pure_hid_command_set_pad1: (skip):
269
 **/
270
void
271
fu_struct_ccgx_pure_hid_command_set_pad1(FuStructCcgxPureHidCommand *st, guint8 value)
272
0
{
273
0
    g_return_if_fail(st != NULL);
274
0
    st->data[3] = value;
275
0
}
276
/**
277
 * fu_struct_ccgx_pure_hid_command_set_pad2: (skip):
278
 **/
279
void
280
fu_struct_ccgx_pure_hid_command_set_pad2(FuStructCcgxPureHidCommand *st, guint32 value)
281
0
{
282
0
    g_return_if_fail(st != NULL);
283
0
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
284
0
}
285
/**
286
 * fu_struct_ccgx_pure_hid_command_new: (skip):
287
 **/
288
FuStructCcgxPureHidCommand *
289
fu_struct_ccgx_pure_hid_command_new(void)
290
0
{
291
0
    FuStructCcgxPureHidCommand *st = g_byte_array_sized_new(8);
292
0
    fu_byte_array_set_size(st, 8, 0x0);
293
0
    fu_struct_ccgx_pure_hid_command_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_COMMAND);
294
0
    fu_struct_ccgx_pure_hid_command_set_pad1(st, 0x00);
295
0
    fu_struct_ccgx_pure_hid_command_set_pad2(st, 0xCCCCCCCC);
296
0
    return st;
297
0
}
298
/* getters */
299
300
/* setters */
301
/**
302
 * fu_struct_ccgx_pure_hid_write_hdr_set_report_id: (skip):
303
 **/
304
static void
305
fu_struct_ccgx_pure_hid_write_hdr_set_report_id(FuStructCcgxPureHidWriteHdr *st, FuCcgxPureHidReportId value)
306
0
{
307
0
    g_return_if_fail(st != NULL);
308
0
    st->data[0] = value;
309
0
}
310
/**
311
 * fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp: (skip):
312
 **/
313
void
314
fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp(FuStructCcgxPureHidWriteHdr *st, guint8 value)
315
0
{
316
0
    g_return_if_fail(st != NULL);
317
0
    st->data[1] = value;
318
0
}
319
/**
320
 * fu_struct_ccgx_pure_hid_write_hdr_set_addr: (skip):
321
 **/
322
void
323
fu_struct_ccgx_pure_hid_write_hdr_set_addr(FuStructCcgxPureHidWriteHdr *st, guint16 value)
324
0
{
325
0
    g_return_if_fail(st != NULL);
326
0
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
327
0
}
328
/**
329
 * fu_struct_ccgx_pure_hid_write_hdr_set_data: (skip):
330
 **/
331
gboolean
332
fu_struct_ccgx_pure_hid_write_hdr_set_data(FuStructCcgxPureHidWriteHdr *st, const guint8 *buf, gsize bufsz, GError **error)
333
0
{
334
0
    g_return_val_if_fail(st != NULL, FALSE);
335
0
    g_return_val_if_fail(buf != NULL, FALSE);
336
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
337
0
    return fu_memcpy_safe(st->data, st->len, 4, buf, bufsz, 0x0, bufsz, error);
338
0
}
339
/**
340
 * fu_struct_ccgx_pure_hid_write_hdr_new: (skip):
341
 **/
342
FuStructCcgxPureHidWriteHdr *
343
fu_struct_ccgx_pure_hid_write_hdr_new(void)
344
0
{
345
0
    FuStructCcgxPureHidWriteHdr *st = g_byte_array_sized_new(132);
346
0
    fu_byte_array_set_size(st, 132, 0x0);
347
0
    fu_struct_ccgx_pure_hid_write_hdr_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_WRITE);
348
0
    return st;
349
0
}