Coverage Report

Created: 2026-01-09 07:21

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