Coverage Report

Created: 2026-02-26 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-ccgx-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-struct.h"
12
#include "fu-byte-array.h"
13
#include "fu-bytes.h"
14
#include "fu-mem-private.h"
15
#include "fu-string.h"
16
17
#ifdef G_LOG_DOMAIN
18
  #undef G_LOG_DOMAIN
19
#endif
20
0
#define G_LOG_DOMAIN "FuStruct"
21
22
/**
23
 * fu_ccgx_image_type_to_string:
24
 * @val: value, e.g. %FU_CCGX_IMAGE_TYPE_SINGLE
25
 *
26
 * Converts an enumerated value to a string.
27
 *
28
 * Returns: identifier string
29
 **/
30
const gchar *
31
fu_ccgx_image_type_to_string(FuCcgxImageType val)
32
0
{
33
0
    if (val == FU_CCGX_IMAGE_TYPE_SINGLE)
34
0
        return "single";
35
0
    if (val == FU_CCGX_IMAGE_TYPE_DUAL_SYMMETRIC)
36
0
        return "dual-symmetric";
37
0
    if (val == FU_CCGX_IMAGE_TYPE_DUAL_ASYMMETRIC)
38
0
        return "dual-asymmetric";
39
0
    if (val == FU_CCGX_IMAGE_TYPE_DUAL_ASYMMETRIC_VARIABLE)
40
0
        return "dual-asymmetric-variable";
41
0
    return NULL;
42
0
}
43
/**
44
 * fu_ccgx_image_type_from_string:
45
 * @val: (nullable): a string, e.g. `single`
46
 *
47
 * Converts a string to an enumerated value.
48
 *
49
 * Returns: enumerated value
50
 **/
51
FuCcgxImageType
52
fu_ccgx_image_type_from_string(const gchar *val)
53
0
{
54
0
    if (g_strcmp0(val, "single") == 0)
55
0
        return FU_CCGX_IMAGE_TYPE_SINGLE;
56
0
    if (g_strcmp0(val, "dual-symmetric") == 0)
57
0
        return FU_CCGX_IMAGE_TYPE_DUAL_SYMMETRIC;
58
0
    if (g_strcmp0(val, "dual-asymmetric") == 0)
59
0
        return FU_CCGX_IMAGE_TYPE_DUAL_ASYMMETRIC;
60
0
    if (g_strcmp0(val, "dual-asymmetric-variable") == 0)
61
0
        return FU_CCGX_IMAGE_TYPE_DUAL_ASYMMETRIC_VARIABLE;
62
0
    return FU_CCGX_IMAGE_TYPE_UNKNOWN;
63
0
}
64
65
/**
66
 * fu_ccgx_fw_mode_to_string:
67
 * @val: value, e.g. %FU_CCGX_FW_MODE_FW1
68
 *
69
 * Converts an enumerated value to a string.
70
 *
71
 * Returns: identifier string
72
 **/
73
const gchar *
74
fu_ccgx_fw_mode_to_string(FuCcgxFwMode val)
75
0
{
76
0
    if (val == FU_CCGX_FW_MODE_BOOT)
77
0
        return "boot";
78
0
    if (val == FU_CCGX_FW_MODE_FW1)
79
0
        return "fw1";
80
0
    if (val == FU_CCGX_FW_MODE_FW2)
81
0
        return "fw2";
82
0
    return NULL;
83
0
}
84
85
/**
86
 * fu_ccgx_pd_resp_to_string:
87
 * @val: value, e.g. %FU_CCGX_PD_RESP_SUCCESS
88
 *
89
 * Converts an enumerated value to a string.
90
 *
91
 * Returns: identifier string
92
 **/
93
const gchar *
94
fu_ccgx_pd_resp_to_string(FuCcgxPdResp val)
95
0
{
96
0
    if (val == FU_CCGX_PD_RESP_NO_RESPONSE)
97
0
        return "no-response";
98
0
    if (val == FU_CCGX_PD_RESP_SUCCESS)
99
0
        return "success";
100
0
    if (val == FU_CCGX_PD_RESP_FLASH_DATA_AVAILABLE)
101
0
        return "flash-data-available";
102
0
    if (val == FU_CCGX_PD_RESP_INVALID_COMMAND)
103
0
        return "invalid-command";
104
0
    if (val == FU_CCGX_PD_RESP_COLLISION_DETECTED)
105
0
        return "collision-detected";
106
0
    if (val == FU_CCGX_PD_RESP_FLASH_UPDATE_FAILED)
107
0
        return "flash-update-failed";
108
0
    if (val == FU_CCGX_PD_RESP_INVALID_FW)
109
0
        return "invalid-fw";
110
0
    if (val == FU_CCGX_PD_RESP_INVALID_ARGUMENTS)
111
0
        return "invalid-arguments";
112
0
    if (val == FU_CCGX_PD_RESP_NOT_SUPPORTED)
113
0
        return "not-supported";
114
0
    if (val == FU_CCGX_PD_RESP_TRANSACTION_FAILED)
115
0
        return "transaction-failed";
116
0
    if (val == FU_CCGX_PD_RESP_PD_COMMAND_FAILED)
117
0
        return "pd-command-failed";
118
0
    if (val == FU_CCGX_PD_RESP_UNDEFINED)
119
0
        return "undefined";
120
0
    if (val == FU_CCGX_PD_RESP_RA_DETECT)
121
0
        return "ra-detect";
122
0
    if (val == FU_CCGX_PD_RESP_RA_REMOVED)
123
0
        return "ra-removed";
124
0
    if (val == FU_CCGX_PD_RESP_RESET_COMPLETE)
125
0
        return "reset-complete";
126
0
    if (val == FU_CCGX_PD_RESP_MESSAGE_QUEUE_OVERFLOW)
127
0
        return "message-queue-overflow";
128
0
    if (val == FU_CCGX_PD_RESP_OVER_CURRENT_DETECTED)
129
0
        return "over-current-detected";
130
0
    if (val == FU_CCGX_PD_RESP_OVER_VOLTAGE_DETECTED)
131
0
        return "over-voltage-detected";
132
0
    if (val == FU_CCGX_PD_RESP_TYPE_C_CONNECTED)
133
0
        return "type-c-connected";
134
0
    if (val == FU_CCGX_PD_RESP_TYPE_C_DISCONNECTED)
135
0
        return "type-c-disconnected";
136
0
    if (val == FU_CCGX_PD_RESP_PD_CONTRACT_ESTABLISHED)
137
0
        return "pd-contract-established";
138
0
    if (val == FU_CCGX_PD_RESP_DR_SWAP)
139
0
        return "dr-swap";
140
0
    if (val == FU_CCGX_PD_RESP_PR_SWAP)
141
0
        return "pr-swap";
142
0
    if (val == FU_CCGX_PD_RESP_VCON_SWAP)
143
0
        return "vcon-swap";
144
0
    if (val == FU_CCGX_PD_RESP_PS_RDY)
145
0
        return "ps-rdy";
146
0
    if (val == FU_CCGX_PD_RESP_GOTOMIN)
147
0
        return "gotomin";
148
0
    if (val == FU_CCGX_PD_RESP_ACCEPT_MESSAGE)
149
0
        return "accept-message";
150
0
    if (val == FU_CCGX_PD_RESP_REJECT_MESSAGE)
151
0
        return "reject-message";
152
0
    if (val == FU_CCGX_PD_RESP_WAIT_MESSAGE)
153
0
        return "wait-message";
154
0
    if (val == FU_CCGX_PD_RESP_HARD_RESET)
155
0
        return "hard-reset";
156
0
    if (val == FU_CCGX_PD_RESP_VDM_RECEIVED)
157
0
        return "vdm-received";
158
0
    if (val == FU_CCGX_PD_RESP_SRC_CAP_RCVD)
159
0
        return "src-cap-rcvd";
160
0
    if (val == FU_CCGX_PD_RESP_SINK_CAP_RCVD)
161
0
        return "sink-cap-rcvd";
162
0
    if (val == FU_CCGX_PD_RESP_DP_ALTERNATE_MODE)
163
0
        return "dp-alternate-mode";
164
0
    if (val == FU_CCGX_PD_RESP_DP_DEVICE_NONNECTED)
165
0
        return "dp-device-nonnected";
166
0
    if (val == FU_CCGX_PD_RESP_DP_DEVICE_NOT_CONNECTED)
167
0
        return "dp-device-not-connected";
168
0
    if (val == FU_CCGX_PD_RESP_DP_SID_NOT_FOUND)
169
0
        return "dp-sid-not-found";
170
0
    if (val == FU_CCGX_PD_RESP_MULTIPLE_SVID_DISCOVERED)
171
0
        return "multiple-svid-discovered";
172
0
    if (val == FU_CCGX_PD_RESP_DP_FUNCTION_NOT_SUPPORTED)
173
0
        return "dp-function-not-supported";
174
0
    if (val == FU_CCGX_PD_RESP_DP_PORT_CONFIG_NOT_SUPPORTED)
175
0
        return "dp-port-config-not-supported";
176
0
    if (val == FU_CCGX_PD_RESP_HARD_RESET_SENT)
177
0
        return "hard-reset-sent";
178
0
    if (val == FU_CCGX_PD_RESP_SOFT_RESET_SENT)
179
0
        return "soft-reset-sent";
180
0
    if (val == FU_CCGX_PD_RESP_CABLE_RESET_SENT)
181
0
        return "cable-reset-sent";
182
0
    if (val == FU_CCGX_PD_RESP_SOURCE_DISABLED_STATE_ENTERED)
183
0
        return "source-disabled-state-entered";
184
0
    if (val == FU_CCGX_PD_RESP_SENDER_RESPONSE_TIMER_TIMEOUT)
185
0
        return "sender-response-timer-timeout";
186
0
    if (val == FU_CCGX_PD_RESP_NO_VDM_RESPONSE_RECEIVED)
187
0
        return "no-vdm-response-received";
188
0
    return NULL;
189
0
}
190
191
192
193
194
195
196
/**
197
 * fu_struct_ccgx_metadata_hdr_ref: (skip):
198
 **/
199
FuStructCcgxMetadataHdr *
200
fu_struct_ccgx_metadata_hdr_ref(FuStructCcgxMetadataHdr *st)
201
0
{
202
0
    g_return_val_if_fail(st != NULL, NULL);
203
0
    st->refcount++;
204
0
    return st;
205
0
}
206
/**
207
 * fu_struct_ccgx_metadata_hdr_unref: (skip):
208
 **/
209
void
210
fu_struct_ccgx_metadata_hdr_unref(FuStructCcgxMetadataHdr *st)
211
293
{
212
293
    g_return_if_fail(st != NULL);
213
293
    if (st->refcount == 0) {
214
0
        g_critical("FuStructCcgxMetadataHdr refcount already zero");
215
0
        return;
216
0
    }
217
293
    if (--st->refcount > 0)
218
0
        return;
219
293
    if (st->buf != NULL)
220
257
        g_byte_array_unref(st->buf);
221
293
    g_free(st);
222
293
}
223
/**
224
 * fu_struct_ccgx_metadata_hdr_new_internal: (skip):
225
 **/
226
static FuStructCcgxMetadataHdr *
227
fu_struct_ccgx_metadata_hdr_new_internal(void)
228
293
{
229
293
    FuStructCcgxMetadataHdr *st = g_new0(FuStructCcgxMetadataHdr, 1);
230
293
    st->refcount = 1;
231
293
    return st;
232
293
}
233
234
/* getters */
235
/**
236
 * fu_struct_ccgx_metadata_hdr_get_fw_checksum: (skip):
237
 **/
238
guint8
239
fu_struct_ccgx_metadata_hdr_get_fw_checksum(const FuStructCcgxMetadataHdr *st)
240
0
{
241
0
    g_return_val_if_fail(st != NULL, 0x0);
242
0
    return st->buf->data[0];
243
0
}
244
/**
245
 * fu_struct_ccgx_metadata_hdr_get_fw_entry: (skip):
246
 **/
247
guint32
248
fu_struct_ccgx_metadata_hdr_get_fw_entry(const FuStructCcgxMetadataHdr *st)
249
0
{
250
0
    g_return_val_if_fail(st != NULL, 0x0);
251
0
    return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN);
252
0
}
253
/**
254
 * fu_struct_ccgx_metadata_hdr_get_last_boot_row: (skip):
255
 **/
256
guint16
257
fu_struct_ccgx_metadata_hdr_get_last_boot_row(const FuStructCcgxMetadataHdr *st)
258
0
{
259
0
    g_return_val_if_fail(st != NULL, 0x0);
260
0
    return fu_memread_uint16(st->buf->data + 5, G_LITTLE_ENDIAN);
261
0
}
262
/**
263
 * fu_struct_ccgx_metadata_hdr_get_fw_size: (skip):
264
 **/
265
guint32
266
fu_struct_ccgx_metadata_hdr_get_fw_size(const FuStructCcgxMetadataHdr *st)
267
268
{
268
268
    g_return_val_if_fail(st != NULL, 0x0);
269
268
    return fu_memread_uint32(st->buf->data + 9, G_LITTLE_ENDIAN);
270
268
}
271
/**
272
 * fu_struct_ccgx_metadata_hdr_get_metadata_valid: (skip):
273
 **/
274
guint16
275
fu_struct_ccgx_metadata_hdr_get_metadata_valid(const FuStructCcgxMetadataHdr *st)
276
263
{
277
263
    g_return_val_if_fail(st != NULL, 0x0);
278
263
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
279
263
}
280
/**
281
 * fu_struct_ccgx_metadata_hdr_get_boot_seq: (skip):
282
 **/
283
guint32
284
fu_struct_ccgx_metadata_hdr_get_boot_seq(const FuStructCcgxMetadataHdr *st)
285
0
{
286
0
    g_return_val_if_fail(st != NULL, 0x0);
287
0
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
288
0
}
289
290
/* setters */
291
/**
292
 * fu_struct_ccgx_metadata_hdr_set_fw_checksum: (skip):
293
 **/
294
void
295
fu_struct_ccgx_metadata_hdr_set_fw_checksum(FuStructCcgxMetadataHdr *st, guint8 value)
296
0
{
297
0
    g_return_if_fail(st != NULL);
298
0
    st->buf->data[0] = value;
299
0
}
300
/**
301
 * fu_struct_ccgx_metadata_hdr_set_fw_entry: (skip):
302
 **/
303
void
304
fu_struct_ccgx_metadata_hdr_set_fw_entry(FuStructCcgxMetadataHdr *st, guint32 value)
305
0
{
306
0
    g_return_if_fail(st != NULL);
307
0
    fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN);
308
0
}
309
/**
310
 * fu_struct_ccgx_metadata_hdr_set_last_boot_row: (skip):
311
 **/
312
void
313
fu_struct_ccgx_metadata_hdr_set_last_boot_row(FuStructCcgxMetadataHdr *st, guint16 value)
314
0
{
315
0
    g_return_if_fail(st != NULL);
316
0
    fu_memwrite_uint16(st->buf->data + 5, value, G_LITTLE_ENDIAN);
317
0
}
318
/**
319
 * fu_struct_ccgx_metadata_hdr_set_fw_size: (skip):
320
 **/
321
void
322
fu_struct_ccgx_metadata_hdr_set_fw_size(FuStructCcgxMetadataHdr *st, guint32 value)
323
0
{
324
0
    g_return_if_fail(st != NULL);
325
0
    fu_memwrite_uint32(st->buf->data + 9, value, G_LITTLE_ENDIAN);
326
0
}
327
/**
328
 * fu_struct_ccgx_metadata_hdr_set_metadata_valid: (skip):
329
 **/
330
void
331
fu_struct_ccgx_metadata_hdr_set_metadata_valid(FuStructCcgxMetadataHdr *st, guint16 value)
332
37
{
333
37
    g_return_if_fail(st != NULL);
334
37
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
335
37
}
336
/**
337
 * fu_struct_ccgx_metadata_hdr_set_boot_seq: (skip):
338
 **/
339
void
340
fu_struct_ccgx_metadata_hdr_set_boot_seq(FuStructCcgxMetadataHdr *st, guint32 value)
341
0
{
342
0
    g_return_if_fail(st != NULL);
343
0
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
344
0
}
345
/**
346
 * fu_struct_ccgx_metadata_hdr_new: (skip):
347
 **/
348
FuStructCcgxMetadataHdr *
349
fu_struct_ccgx_metadata_hdr_new(void)
350
37
{
351
37
    FuStructCcgxMetadataHdr *st = fu_struct_ccgx_metadata_hdr_new_internal();
352
37
    st->buf = g_byte_array_sized_new(32);
353
37
    fu_byte_array_set_size(st->buf, 32, 0x0);
354
37
    fu_struct_ccgx_metadata_hdr_set_metadata_valid(st, 0x4359);
355
37
    return st;
356
37
}
357
/**
358
 * fu_struct_ccgx_metadata_hdr_to_string: (skip):
359
 **/
360
static gchar *
361
fu_struct_ccgx_metadata_hdr_to_string(const FuStructCcgxMetadataHdr *st)
362
0
{
363
0
    g_autoptr(GString) str = g_string_new("FuStructCcgxMetadataHdr:\n");
364
0
    g_return_val_if_fail(st != NULL, NULL);
365
0
    g_string_append_printf(str, "  fw_checksum: 0x%x\n",
366
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_checksum(st));
367
0
    g_string_append_printf(str, "  fw_entry: 0x%x\n",
368
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_entry(st));
369
0
    g_string_append_printf(str, "  last_boot_row: 0x%x\n",
370
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_last_boot_row(st));
371
0
    g_string_append_printf(str, "  fw_size: 0x%x\n",
372
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_size(st));
373
0
    g_string_append_printf(str, "  metadata_valid: 0x%x\n",
374
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_metadata_valid(st));
375
0
    g_string_append_printf(str, "  boot_seq: 0x%x\n",
376
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_boot_seq(st));
377
0
    if (str->len > 0)
378
0
        g_string_set_size(str, str->len - 1);
379
0
    return g_string_free(g_steal_pointer(&str), FALSE);
380
0
}
381
static gboolean
382
fu_struct_ccgx_metadata_hdr_validate_internal(FuStructCcgxMetadataHdr *st, GError **error)
383
220
{
384
220
    g_return_val_if_fail(st != NULL, FALSE);
385
220
    return TRUE;
386
220
}
387
static gboolean
388
fu_struct_ccgx_metadata_hdr_parse_internal(FuStructCcgxMetadataHdr *st, GError **error)
389
220
{
390
220
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
391
0
        g_autofree gchar *str = fu_struct_ccgx_metadata_hdr_to_string(st);
392
0
        g_debug("%s", str);
393
0
    }
394
220
    if (!fu_struct_ccgx_metadata_hdr_validate_internal(st, error))
395
0
        return FALSE;
396
220
    return TRUE;
397
220
}
398
399
/**
400
 * fu_struct_ccgx_metadata_hdr_parse: (skip):
401
 **/
402
static FuStructCcgxMetadataHdr *
403
fu_struct_ccgx_metadata_hdr_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
404
256
{
405
256
    g_autoptr(FuStructCcgxMetadataHdr) st = fu_struct_ccgx_metadata_hdr_new_internal();
406
256
    g_return_val_if_fail(buf != NULL, NULL);
407
256
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
408
256
    if (!fu_memchk_read(bufsz, offset, 32, error)) {
409
36
        g_prefix_error_literal(error, "invalid struct FuStructCcgxMetadataHdr: ");
410
36
        return NULL;
411
36
    }
412
220
    st->buf = g_byte_array_new();
413
220
    g_byte_array_append(st->buf, buf + offset, 32);
414
220
    if (!fu_struct_ccgx_metadata_hdr_parse_internal(st, error))
415
0
        return NULL;
416
220
    return g_steal_pointer(&st);
417
220
}
418
/**
419
 * fu_struct_ccgx_metadata_hdr_parse_bytes: (skip):
420
 **/
421
FuStructCcgxMetadataHdr *
422
fu_struct_ccgx_metadata_hdr_parse_bytes(GBytes *blob, gsize offset, GError **error)
423
256
{
424
256
    gsize bufsz = 0;
425
256
    const guint8 *buf = fu_bytes_get_data_safe(blob, &bufsz, error);
426
256
    if (buf == NULL)
427
0
        return NULL;
428
256
    return fu_struct_ccgx_metadata_hdr_parse(buf, bufsz, offset, error);
429
256
}