Coverage Report

Created: 2025-07-01 07:09

/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_literal(error,
197
0
                            FWUPD_ERROR,
198
0
                            FWUPD_ERROR_INVALID_DATA,
199
0
                            "constant FuStructCcgxPureHidFwInfo.signature was not valid");
200
0
        return FALSE;
201
0
    }
202
0
    return TRUE;
203
0
}
204
static gboolean
205
fu_struct_ccgx_pure_hid_fw_info_parse_internal(FuStructCcgxPureHidFwInfo *st, GError **error)
206
0
{
207
0
    if (!fu_struct_ccgx_pure_hid_fw_info_validate_internal(st, error))
208
0
        return FALSE;
209
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
210
0
        g_autofree gchar *str = fu_struct_ccgx_pure_hid_fw_info_to_string(st);
211
0
        g_debug("%s", str);
212
0
    }
213
0
    return TRUE;
214
0
}
215
216
/**
217
 * fu_struct_ccgx_pure_hid_fw_info_parse: (skip):
218
 **/
219
FuStructCcgxPureHidFwInfo *
220
fu_struct_ccgx_pure_hid_fw_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
221
0
{
222
0
    g_autoptr(GByteArray) st = g_byte_array_new();
223
0
    g_return_val_if_fail(buf != NULL, NULL);
224
0
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
225
0
    if (!fu_memchk_read(bufsz, offset, 60, error)) {
226
0
        g_prefix_error(error, "invalid struct FuStructCcgxPureHidFwInfo: ");
227
0
        return NULL;
228
0
    }
229
0
    g_byte_array_append(st, buf + offset, 60);
230
0
    if (!fu_struct_ccgx_pure_hid_fw_info_parse_internal(st, error))
231
0
        return NULL;
232
0
    return g_steal_pointer(&st);
233
0
}
234
/* getters */
235
236
/* setters */
237
/**
238
 * fu_struct_ccgx_pure_hid_command_set_report_id: (skip):
239
 **/
240
static void
241
fu_struct_ccgx_pure_hid_command_set_report_id(FuStructCcgxPureHidCommand *st, FuCcgxPureHidReportId value)
242
0
{
243
0
    g_return_if_fail(st != NULL);
244
0
    st->data[0] = value;
245
0
}
246
/**
247
 * fu_struct_ccgx_pure_hid_command_set_cmd: (skip):
248
 **/
249
void
250
fu_struct_ccgx_pure_hid_command_set_cmd(FuStructCcgxPureHidCommand *st, guint8 value)
251
0
{
252
0
    g_return_if_fail(st != NULL);
253
0
    st->data[1] = value;
254
0
}
255
/**
256
 * fu_struct_ccgx_pure_hid_command_set_opt: (skip):
257
 **/
258
void
259
fu_struct_ccgx_pure_hid_command_set_opt(FuStructCcgxPureHidCommand *st, guint8 value)
260
0
{
261
0
    g_return_if_fail(st != NULL);
262
0
    st->data[2] = value;
263
0
}
264
/**
265
 * fu_struct_ccgx_pure_hid_command_set_pad1: (skip):
266
 **/
267
void
268
fu_struct_ccgx_pure_hid_command_set_pad1(FuStructCcgxPureHidCommand *st, guint8 value)
269
0
{
270
0
    g_return_if_fail(st != NULL);
271
0
    st->data[3] = value;
272
0
}
273
/**
274
 * fu_struct_ccgx_pure_hid_command_set_pad2: (skip):
275
 **/
276
void
277
fu_struct_ccgx_pure_hid_command_set_pad2(FuStructCcgxPureHidCommand *st, guint32 value)
278
0
{
279
0
    g_return_if_fail(st != NULL);
280
0
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
281
0
}
282
/**
283
 * fu_struct_ccgx_pure_hid_command_new: (skip):
284
 **/
285
FuStructCcgxPureHidCommand *
286
fu_struct_ccgx_pure_hid_command_new(void)
287
0
{
288
0
    FuStructCcgxPureHidCommand *st = g_byte_array_sized_new(8);
289
0
    fu_byte_array_set_size(st, 8, 0x0);
290
0
    fu_struct_ccgx_pure_hid_command_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_COMMAND);
291
0
    fu_struct_ccgx_pure_hid_command_set_pad1(st, 0x00);
292
0
    fu_struct_ccgx_pure_hid_command_set_pad2(st, 0xCCCCCCCC);
293
0
    return st;
294
0
}
295
/* getters */
296
297
/* setters */
298
/**
299
 * fu_struct_ccgx_pure_hid_write_hdr_set_report_id: (skip):
300
 **/
301
static void
302
fu_struct_ccgx_pure_hid_write_hdr_set_report_id(FuStructCcgxPureHidWriteHdr *st, FuCcgxPureHidReportId value)
303
0
{
304
0
    g_return_if_fail(st != NULL);
305
0
    st->data[0] = value;
306
0
}
307
/**
308
 * fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp: (skip):
309
 **/
310
void
311
fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp(FuStructCcgxPureHidWriteHdr *st, guint8 value)
312
0
{
313
0
    g_return_if_fail(st != NULL);
314
0
    st->data[1] = value;
315
0
}
316
/**
317
 * fu_struct_ccgx_pure_hid_write_hdr_set_addr: (skip):
318
 **/
319
void
320
fu_struct_ccgx_pure_hid_write_hdr_set_addr(FuStructCcgxPureHidWriteHdr *st, guint16 value)
321
0
{
322
0
    g_return_if_fail(st != NULL);
323
0
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
324
0
}
325
/**
326
 * fu_struct_ccgx_pure_hid_write_hdr_set_data: (skip):
327
 **/
328
gboolean
329
fu_struct_ccgx_pure_hid_write_hdr_set_data(FuStructCcgxPureHidWriteHdr *st, const guint8 *buf, gsize bufsz, GError **error)
330
0
{
331
0
    g_return_val_if_fail(st != NULL, FALSE);
332
0
    g_return_val_if_fail(buf != NULL, FALSE);
333
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
334
0
    return fu_memcpy_safe(st->data, st->len, 4, buf, bufsz, 0x0, bufsz, error);
335
0
}
336
/**
337
 * fu_struct_ccgx_pure_hid_write_hdr_new: (skip):
338
 **/
339
FuStructCcgxPureHidWriteHdr *
340
fu_struct_ccgx_pure_hid_write_hdr_new(void)
341
0
{
342
0
    FuStructCcgxPureHidWriteHdr *st = g_byte_array_sized_new(132);
343
0
    fu_byte_array_set_size(st, 132, 0x0);
344
0
    fu_struct_ccgx_pure_hid_write_hdr_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_WRITE);
345
0
    return st;
346
0
}