Coverage Report

Created: 2025-11-24 06:59

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