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