Coverage Report

Created: 2025-11-11 06:44

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
428
{
178
428
    g_return_if_fail(st != NULL);
179
428
    if (st->refcount == 0) {
180
0
        g_critical("FuStructCcgxMetadataHdr refcount already zero");
181
0
        return;
182
0
    }
183
428
    if (--st->refcount > 0)
184
0
        return;
185
428
    if (st->buf != NULL)
186
384
        g_byte_array_unref(st->buf);
187
428
    g_free(st);
188
428
}
189
static FuStructCcgxMetadataHdr *
190
fu_struct_ccgx_metadata_hdr_new_internal(void)
191
428
{
192
428
    FuStructCcgxMetadataHdr *st = g_new0(FuStructCcgxMetadataHdr, 1);
193
428
    st->refcount = 1;
194
428
    return st;
195
428
}
196
197
/* getters */
198
/**
199
 * fu_struct_ccgx_metadata_hdr_get_fw_checksum: (skip):
200
 **/
201
guint8
202
fu_struct_ccgx_metadata_hdr_get_fw_checksum(const FuStructCcgxMetadataHdr *st)
203
82
{
204
82
    g_return_val_if_fail(st != NULL, 0x0);
205
82
    return st->buf->data[0];
206
82
}
207
/**
208
 * fu_struct_ccgx_metadata_hdr_get_fw_entry: (skip):
209
 **/
210
guint32
211
fu_struct_ccgx_metadata_hdr_get_fw_entry(const FuStructCcgxMetadataHdr *st)
212
0
{
213
0
    g_return_val_if_fail(st != NULL, 0x0);
214
0
    return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN);
215
0
}
216
/**
217
 * fu_struct_ccgx_metadata_hdr_get_last_boot_row: (skip):
218
 **/
219
guint16
220
fu_struct_ccgx_metadata_hdr_get_last_boot_row(const FuStructCcgxMetadataHdr *st)
221
0
{
222
0
    g_return_val_if_fail(st != NULL, 0x0);
223
0
    return fu_memread_uint16(st->buf->data + 5, G_LITTLE_ENDIAN);
224
0
}
225
/**
226
 * fu_struct_ccgx_metadata_hdr_get_fw_size: (skip):
227
 **/
228
guint32
229
fu_struct_ccgx_metadata_hdr_get_fw_size(const FuStructCcgxMetadataHdr *st)
230
397
{
231
397
    g_return_val_if_fail(st != NULL, 0x0);
232
397
    return fu_memread_uint32(st->buf->data + 9, G_LITTLE_ENDIAN);
233
397
}
234
/**
235
 * fu_struct_ccgx_metadata_hdr_get_metadata_valid: (skip):
236
 **/
237
guint16
238
fu_struct_ccgx_metadata_hdr_get_metadata_valid(const FuStructCcgxMetadataHdr *st)
239
385
{
240
385
    g_return_val_if_fail(st != NULL, 0x0);
241
385
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
242
385
}
243
/**
244
 * fu_struct_ccgx_metadata_hdr_get_boot_seq: (skip):
245
 **/
246
guint32
247
fu_struct_ccgx_metadata_hdr_get_boot_seq(const FuStructCcgxMetadataHdr *st)
248
0
{
249
0
    g_return_val_if_fail(st != NULL, 0x0);
250
0
    return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN);
251
0
}
252
253
/* setters */
254
/**
255
 * fu_struct_ccgx_metadata_hdr_set_fw_checksum: (skip):
256
 **/
257
void
258
fu_struct_ccgx_metadata_hdr_set_fw_checksum(FuStructCcgxMetadataHdr *st, guint8 value)
259
0
{
260
0
    g_return_if_fail(st != NULL);
261
0
    st->buf->data[0] = value;
262
0
}
263
/**
264
 * fu_struct_ccgx_metadata_hdr_set_fw_entry: (skip):
265
 **/
266
void
267
fu_struct_ccgx_metadata_hdr_set_fw_entry(FuStructCcgxMetadataHdr *st, guint32 value)
268
0
{
269
0
    g_return_if_fail(st != NULL);
270
0
    fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN);
271
0
}
272
/**
273
 * fu_struct_ccgx_metadata_hdr_set_last_boot_row: (skip):
274
 **/
275
void
276
fu_struct_ccgx_metadata_hdr_set_last_boot_row(FuStructCcgxMetadataHdr *st, guint16 value)
277
0
{
278
0
    g_return_if_fail(st != NULL);
279
0
    fu_memwrite_uint16(st->buf->data + 5, value, G_LITTLE_ENDIAN);
280
0
}
281
/**
282
 * fu_struct_ccgx_metadata_hdr_set_fw_size: (skip):
283
 **/
284
void
285
fu_struct_ccgx_metadata_hdr_set_fw_size(FuStructCcgxMetadataHdr *st, guint32 value)
286
0
{
287
0
    g_return_if_fail(st != NULL);
288
0
    fu_memwrite_uint32(st->buf->data + 9, value, G_LITTLE_ENDIAN);
289
0
}
290
/**
291
 * fu_struct_ccgx_metadata_hdr_set_metadata_valid: (skip):
292
 **/
293
void
294
fu_struct_ccgx_metadata_hdr_set_metadata_valid(FuStructCcgxMetadataHdr *st, guint16 value)
295
55
{
296
55
    g_return_if_fail(st != NULL);
297
55
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
298
55
}
299
/**
300
 * fu_struct_ccgx_metadata_hdr_set_boot_seq: (skip):
301
 **/
302
void
303
fu_struct_ccgx_metadata_hdr_set_boot_seq(FuStructCcgxMetadataHdr *st, guint32 value)
304
0
{
305
0
    g_return_if_fail(st != NULL);
306
0
    fu_memwrite_uint32(st->buf->data + 28, value, G_LITTLE_ENDIAN);
307
0
}
308
/**
309
 * fu_struct_ccgx_metadata_hdr_new: (skip):
310
 **/
311
FuStructCcgxMetadataHdr *
312
fu_struct_ccgx_metadata_hdr_new(void)
313
55
{
314
55
    FuStructCcgxMetadataHdr *st = fu_struct_ccgx_metadata_hdr_new_internal();
315
55
    st->buf = g_byte_array_sized_new(32);
316
55
    fu_byte_array_set_size(st->buf, 32, 0x0);
317
55
    fu_struct_ccgx_metadata_hdr_set_metadata_valid(st, 0x4359);
318
55
    return st;
319
55
}
320
/**
321
 * fu_struct_ccgx_metadata_hdr_to_string: (skip):
322
 **/
323
static gchar *
324
fu_struct_ccgx_metadata_hdr_to_string(const FuStructCcgxMetadataHdr *st)
325
0
{
326
0
    g_autoptr(GString) str = g_string_new("FuStructCcgxMetadataHdr:\n");
327
0
    g_return_val_if_fail(st != NULL, NULL);
328
0
    g_string_append_printf(str, "  fw_checksum: 0x%x\n",
329
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_checksum(st));
330
0
    g_string_append_printf(str, "  fw_entry: 0x%x\n",
331
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_entry(st));
332
0
    g_string_append_printf(str, "  last_boot_row: 0x%x\n",
333
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_last_boot_row(st));
334
0
    g_string_append_printf(str, "  fw_size: 0x%x\n",
335
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_fw_size(st));
336
0
    g_string_append_printf(str, "  metadata_valid: 0x%x\n",
337
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_metadata_valid(st));
338
0
    g_string_append_printf(str, "  boot_seq: 0x%x\n",
339
0
                           (guint) fu_struct_ccgx_metadata_hdr_get_boot_seq(st));
340
0
    if (str->len > 0)
341
0
        g_string_set_size(str, str->len - 1);
342
0
    return g_string_free(g_steal_pointer(&str), FALSE);
343
0
}
344
static gboolean
345
fu_struct_ccgx_metadata_hdr_validate_internal(FuStructCcgxMetadataHdr *st, GError **error)
346
329
{
347
329
    g_return_val_if_fail(st != NULL, FALSE);
348
329
    return TRUE;
349
329
}
350
static gboolean
351
fu_struct_ccgx_metadata_hdr_parse_internal(FuStructCcgxMetadataHdr *st, GError **error)
352
329
{
353
329
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
354
0
        g_autofree gchar *str = fu_struct_ccgx_metadata_hdr_to_string(st);
355
0
        g_debug("%s", str);
356
0
    }
357
329
    if (!fu_struct_ccgx_metadata_hdr_validate_internal(st, error))
358
0
        return FALSE;
359
329
    return TRUE;
360
329
}
361
362
/**
363
 * fu_struct_ccgx_metadata_hdr_parse: (skip):
364
 **/
365
static FuStructCcgxMetadataHdr *
366
fu_struct_ccgx_metadata_hdr_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
367
373
{
368
373
    g_autoptr(FuStructCcgxMetadataHdr) st = fu_struct_ccgx_metadata_hdr_new_internal();
369
373
    g_return_val_if_fail(buf != NULL, NULL);
370
373
    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
371
373
    if (!fu_memchk_read(bufsz, offset, 32, error)) {
372
44
        g_prefix_error_literal(error, "invalid struct FuStructCcgxMetadataHdr: ");
373
44
        return NULL;
374
44
    }
375
329
    st->buf = g_byte_array_new();
376
329
    g_byte_array_append(st->buf, buf + offset, 32);
377
329
    if (!fu_struct_ccgx_metadata_hdr_parse_internal(st, error))
378
0
        return NULL;
379
329
    return g_steal_pointer(&st);
380
329
}
381
/**
382
 * fu_struct_ccgx_metadata_hdr_parse_bytes: (skip):
383
 **/
384
FuStructCcgxMetadataHdr *
385
fu_struct_ccgx_metadata_hdr_parse_bytes(GBytes *blob, gsize offset, GError **error)
386
373
{
387
373
    gsize bufsz = 0;
388
373
    const guint8 *buf = g_bytes_get_data(blob, &bufsz);
389
373
    return fu_struct_ccgx_metadata_hdr_parse(buf, bufsz, offset, error);
390
373
}