/work/fu-synaptics-rmi-struct.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* auto-generated, do not modify */ |
2 | | #include "config.h" |
3 | | |
4 | | #include "fu-synaptics-rmi-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_rmi_partition_id_to_string(FuRmiPartitionId val) |
16 | 0 | { |
17 | 0 | if (val == FU_RMI_PARTITION_ID_NONE) |
18 | 0 | return "none"; |
19 | 0 | if (val == FU_RMI_PARTITION_ID_BOOTLOADER) |
20 | 0 | return "bootloader"; |
21 | 0 | if (val == FU_RMI_PARTITION_ID_DEVICE_CONFIG) |
22 | 0 | return "device-config"; |
23 | 0 | if (val == FU_RMI_PARTITION_ID_FLASH_CONFIG) |
24 | 0 | return "flash-config"; |
25 | 0 | if (val == FU_RMI_PARTITION_ID_MANUFACTURING_BLOCK) |
26 | 0 | return "manufacturing-block"; |
27 | 0 | if (val == FU_RMI_PARTITION_ID_GUEST_SERIALIZATION) |
28 | 0 | return "guest-serialization"; |
29 | 0 | if (val == FU_RMI_PARTITION_ID_GLOBAL_PARAMETERS) |
30 | 0 | return "global-parameters"; |
31 | 0 | if (val == FU_RMI_PARTITION_ID_CORE_CODE) |
32 | 0 | return "core-code"; |
33 | 0 | if (val == FU_RMI_PARTITION_ID_CORE_CONFIG) |
34 | 0 | return "core-config"; |
35 | 0 | if (val == FU_RMI_PARTITION_ID_GUEST_CODE) |
36 | 0 | return "guest-code"; |
37 | 0 | if (val == FU_RMI_PARTITION_ID_DISPLAY_CONFIG) |
38 | 0 | return "display-config"; |
39 | 0 | if (val == FU_RMI_PARTITION_ID_EXTERNAL_TOUCH_AFE_CONFIG) |
40 | 0 | return "external-touch-afe-config"; |
41 | 0 | if (val == FU_RMI_PARTITION_ID_UTILITY_PARAMETER) |
42 | 0 | return "utility-parameter"; |
43 | 0 | if (val == FU_RMI_PARTITION_ID_PUBKEY) |
44 | 0 | return "pubkey"; |
45 | 0 | if (val == FU_RMI_PARTITION_ID_FIXED_LOCATION_DATA) |
46 | 0 | return "fixed-location-data"; |
47 | 0 | return NULL; |
48 | 0 | } |
49 | | |
50 | | const gchar * |
51 | | fu_rmi_container_id_to_string(FuRmiContainerId val) |
52 | 11.4k | { |
53 | 11.4k | if (val == FU_RMI_CONTAINER_ID_TOP_LEVEL) |
54 | 4.02k | return "top-level"; |
55 | 7.46k | if (val == FU_RMI_CONTAINER_ID_UI) |
56 | 0 | return "ui"; |
57 | 7.46k | if (val == FU_RMI_CONTAINER_ID_UI_CONFIG) |
58 | 0 | return "ui-config"; |
59 | 7.46k | if (val == FU_RMI_CONTAINER_ID_BL) |
60 | 0 | return "bl"; |
61 | 7.46k | if (val == FU_RMI_CONTAINER_ID_BL_IMAGE) |
62 | 207 | return "bl-image"; |
63 | 7.25k | if (val == FU_RMI_CONTAINER_ID_BL_CONFIG) |
64 | 286 | return "bl-config"; |
65 | 6.97k | if (val == FU_RMI_CONTAINER_ID_BL_LOCKDOWN_INFO) |
66 | 275 | return "bl-lockdown-info"; |
67 | 6.69k | if (val == FU_RMI_CONTAINER_ID_PERMANENT_CONFIG) |
68 | 558 | return "permanent-config"; |
69 | 6.13k | if (val == FU_RMI_CONTAINER_ID_GUEST_CODE) |
70 | 310 | return "guest-code"; |
71 | 5.82k | if (val == FU_RMI_CONTAINER_ID_BL_PROTOCOL_DESCRIPTOR) |
72 | 345 | return "bl-protocol-descriptor"; |
73 | 5.48k | if (val == FU_RMI_CONTAINER_ID_UI_PROTOCOL_DESCRIPTOR) |
74 | 201 | return "ui-protocol-descriptor"; |
75 | 5.28k | if (val == FU_RMI_CONTAINER_ID_RMI_SELF_DISCOVERY) |
76 | 277 | return "rmi-self-discovery"; |
77 | 5.00k | if (val == FU_RMI_CONTAINER_ID_RMI_PAGE_CONTENT) |
78 | 208 | return "rmi-page-content"; |
79 | 4.79k | if (val == FU_RMI_CONTAINER_ID_GENERAL_INFORMATION) |
80 | 0 | return "general-information"; |
81 | 4.79k | if (val == FU_RMI_CONTAINER_ID_DEVICE_CONFIG) |
82 | 561 | return "device-config"; |
83 | 4.23k | if (val == FU_RMI_CONTAINER_ID_FLASH_CONFIG) |
84 | 0 | return "flash-config"; |
85 | 4.23k | if (val == FU_RMI_CONTAINER_ID_GUEST_SERIALIZATION) |
86 | 287 | return "guest-serialization"; |
87 | 3.94k | if (val == FU_RMI_CONTAINER_ID_GLOBAL_PARAMETERS) |
88 | 209 | return "global-parameters"; |
89 | 3.73k | if (val == FU_RMI_CONTAINER_ID_CORE_CODE) |
90 | 0 | return "core-code"; |
91 | 3.73k | if (val == FU_RMI_CONTAINER_ID_CORE_CONFIG) |
92 | 0 | return "core-config"; |
93 | 3.73k | if (val == FU_RMI_CONTAINER_ID_DISPLAY_CONFIG) |
94 | 0 | return "display-config"; |
95 | 3.73k | if (val == FU_RMI_CONTAINER_ID_EXTERNAL_TOUCH_AFE_CONFIG) |
96 | 0 | return "external-touch-afe-config"; |
97 | 3.73k | if (val == FU_RMI_CONTAINER_ID_UTILITY) |
98 | 487 | return "utility"; |
99 | 3.25k | if (val == FU_RMI_CONTAINER_ID_UTILITY_PARAMETER) |
100 | 201 | return "utility-parameter"; |
101 | 3.05k | if (val == FU_RMI_CONTAINER_ID_FIXED_LOCATION_DATA) |
102 | 0 | return "fixed-location-data"; |
103 | 3.05k | return NULL; |
104 | 3.05k | } |
105 | | |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | /* getters */ |
112 | | /** |
113 | | * fu_struct_rmi_partition_tbl_get_partition_id: (skip): |
114 | | **/ |
115 | | FuRmiPartitionId |
116 | | fu_struct_rmi_partition_tbl_get_partition_id(const FuStructRmiPartitionTbl *st) |
117 | 0 | { |
118 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
119 | 0 | return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN); |
120 | 0 | } |
121 | | /** |
122 | | * fu_struct_rmi_partition_tbl_get_partition_len: (skip): |
123 | | **/ |
124 | | guint16 |
125 | | fu_struct_rmi_partition_tbl_get_partition_len(const FuStructRmiPartitionTbl *st) |
126 | 0 | { |
127 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
128 | 0 | return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN); |
129 | 0 | } |
130 | | /** |
131 | | * fu_struct_rmi_partition_tbl_get_partition_addr: (skip): |
132 | | **/ |
133 | | guint16 |
134 | | fu_struct_rmi_partition_tbl_get_partition_addr(const FuStructRmiPartitionTbl *st) |
135 | 0 | { |
136 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
137 | 0 | return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN); |
138 | 0 | } |
139 | | /** |
140 | | * fu_struct_rmi_partition_tbl_get_partition_prop: (skip): |
141 | | **/ |
142 | | guint16 |
143 | | fu_struct_rmi_partition_tbl_get_partition_prop(const FuStructRmiPartitionTbl *st) |
144 | 0 | { |
145 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
146 | 0 | return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN); |
147 | 0 | } |
148 | | |
149 | | /* setters */ |
150 | | /** |
151 | | * fu_struct_rmi_partition_tbl_to_string: (skip): |
152 | | **/ |
153 | | static gchar * |
154 | | fu_struct_rmi_partition_tbl_to_string(const FuStructRmiPartitionTbl *st) |
155 | 0 | { |
156 | 0 | g_autoptr(GString) str = g_string_new("FuStructRmiPartitionTbl:\n"); |
157 | 0 | g_return_val_if_fail(st != NULL, NULL); |
158 | 0 | { |
159 | 0 | const gchar *tmp = fu_rmi_partition_id_to_string(fu_struct_rmi_partition_tbl_get_partition_id(st)); |
160 | 0 | if (tmp != NULL) { |
161 | 0 | g_string_append_printf(str, " partition_id: 0x%x [%s]\n", (guint) fu_struct_rmi_partition_tbl_get_partition_id(st), tmp); |
162 | 0 | } else { |
163 | 0 | g_string_append_printf(str, " partition_id: 0x%x\n", (guint) fu_struct_rmi_partition_tbl_get_partition_id(st)); |
164 | 0 | } |
165 | 0 | } |
166 | 0 | g_string_append_printf(str, " partition_len: 0x%x\n", |
167 | 0 | (guint) fu_struct_rmi_partition_tbl_get_partition_len(st)); |
168 | 0 | g_string_append_printf(str, " partition_addr: 0x%x\n", |
169 | 0 | (guint) fu_struct_rmi_partition_tbl_get_partition_addr(st)); |
170 | 0 | g_string_append_printf(str, " partition_prop: 0x%x\n", |
171 | 0 | (guint) fu_struct_rmi_partition_tbl_get_partition_prop(st)); |
172 | 0 | if (str->len > 0) |
173 | 0 | g_string_set_size(str, str->len - 1); |
174 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
175 | 0 | } |
176 | | static gboolean |
177 | | fu_struct_rmi_partition_tbl_validate_internal(FuStructRmiPartitionTbl *st, GError **error) |
178 | 0 | { |
179 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
180 | 0 | return TRUE; |
181 | 0 | } |
182 | | static gboolean |
183 | | fu_struct_rmi_partition_tbl_parse_internal(FuStructRmiPartitionTbl *st, GError **error) |
184 | 0 | { |
185 | 0 | if (!fu_struct_rmi_partition_tbl_validate_internal(st, error)) |
186 | 0 | return FALSE; |
187 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
188 | 0 | g_autofree gchar *str = fu_struct_rmi_partition_tbl_to_string(st); |
189 | 0 | g_debug("%s", str); |
190 | 0 | } |
191 | 0 | return TRUE; |
192 | 0 | } |
193 | | |
194 | | /** |
195 | | * fu_struct_rmi_partition_tbl_parse: (skip): |
196 | | **/ |
197 | | FuStructRmiPartitionTbl * |
198 | | fu_struct_rmi_partition_tbl_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
199 | 0 | { |
200 | 0 | g_autoptr(GByteArray) st = g_byte_array_new(); |
201 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
202 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
203 | 0 | if (!fu_memchk_read(bufsz, offset, 8, error)) { |
204 | 0 | g_prefix_error(error, "invalid struct FuStructRmiPartitionTbl: "); |
205 | 0 | return NULL; |
206 | 0 | } |
207 | 0 | g_byte_array_append(st, buf + offset, 8); |
208 | 0 | if (!fu_struct_rmi_partition_tbl_parse_internal(st, error)) |
209 | 0 | return NULL; |
210 | 0 | return g_steal_pointer(&st); |
211 | 0 | } |
212 | | /* getters */ |
213 | | /** |
214 | | * fu_struct_rmi_img_get_checksum: (skip): |
215 | | **/ |
216 | | guint32 |
217 | | fu_struct_rmi_img_get_checksum(const FuStructRmiImg *st) |
218 | 2.10k | { |
219 | 2.10k | g_return_val_if_fail(st != NULL, 0x0); |
220 | 2.10k | return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN); |
221 | 2.10k | } |
222 | | /** |
223 | | * fu_struct_rmi_img_get_io_offset: (skip): |
224 | | **/ |
225 | | guint8 |
226 | | fu_struct_rmi_img_get_io_offset(const FuStructRmiImg *st) |
227 | 1.13k | { |
228 | 1.13k | g_return_val_if_fail(st != NULL, 0x0); |
229 | 1.13k | return st->data[6]; |
230 | 1.13k | } |
231 | | /** |
232 | | * fu_struct_rmi_img_get_bootloader_version: (skip): |
233 | | **/ |
234 | | guint8 |
235 | | fu_struct_rmi_img_get_bootloader_version(const FuStructRmiImg *st) |
236 | 1.13k | { |
237 | 1.13k | g_return_val_if_fail(st != NULL, 0x0); |
238 | 1.13k | return st->data[7]; |
239 | 1.13k | } |
240 | | /** |
241 | | * fu_struct_rmi_img_get_image_size: (skip): |
242 | | **/ |
243 | | guint32 |
244 | | fu_struct_rmi_img_get_image_size(const FuStructRmiImg *st) |
245 | 1.30k | { |
246 | 1.30k | g_return_val_if_fail(st != NULL, 0x0); |
247 | 1.30k | return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN); |
248 | 1.30k | } |
249 | | /** |
250 | | * fu_struct_rmi_img_get_config_size: (skip): |
251 | | **/ |
252 | | guint32 |
253 | | fu_struct_rmi_img_get_config_size(const FuStructRmiImg *st) |
254 | 64 | { |
255 | 64 | g_return_val_if_fail(st != NULL, 0x0); |
256 | 64 | return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN); |
257 | 64 | } |
258 | | /** |
259 | | * fu_struct_rmi_img_get_product_id: (skip): |
260 | | **/ |
261 | | gchar * |
262 | | fu_struct_rmi_img_get_product_id(const FuStructRmiImg *st) |
263 | 1.13k | { |
264 | 1.13k | g_return_val_if_fail(st != NULL, NULL); |
265 | 1.13k | return fu_memstrsafe(st->data, st->len, 16, 10, NULL); |
266 | 1.13k | } |
267 | | /** |
268 | | * fu_struct_rmi_img_get_package_id: (skip): |
269 | | **/ |
270 | | guint32 |
271 | | fu_struct_rmi_img_get_package_id(const FuStructRmiImg *st) |
272 | 275 | { |
273 | 275 | g_return_val_if_fail(st != NULL, 0x0); |
274 | 275 | return fu_memread_uint32(st->data + 26, G_LITTLE_ENDIAN); |
275 | 275 | } |
276 | | /** |
277 | | * fu_struct_rmi_img_get_product_info: (skip): |
278 | | **/ |
279 | | guint32 |
280 | | fu_struct_rmi_img_get_product_info(const FuStructRmiImg *st) |
281 | 1.13k | { |
282 | 1.13k | g_return_val_if_fail(st != NULL, 0x0); |
283 | 1.13k | return fu_memread_uint32(st->data + 30, G_LITTLE_ENDIAN); |
284 | 1.13k | } |
285 | | /** |
286 | | * fu_struct_rmi_img_get_fw_build_id: (skip): |
287 | | **/ |
288 | | guint32 |
289 | | fu_struct_rmi_img_get_fw_build_id(const FuStructRmiImg *st) |
290 | 275 | { |
291 | 275 | g_return_val_if_fail(st != NULL, 0x0); |
292 | 275 | return fu_memread_uint32(st->data + 80, G_LITTLE_ENDIAN); |
293 | 275 | } |
294 | | /** |
295 | | * fu_struct_rmi_img_get_signature_size: (skip): |
296 | | **/ |
297 | | guint32 |
298 | | fu_struct_rmi_img_get_signature_size(const FuStructRmiImg *st) |
299 | 80 | { |
300 | 80 | g_return_val_if_fail(st != NULL, 0x0); |
301 | 80 | return fu_memread_uint32(st->data + 84, G_LITTLE_ENDIAN); |
302 | 80 | } |
303 | | |
304 | | /* setters */ |
305 | | /** |
306 | | * fu_struct_rmi_img_set_checksum: (skip): |
307 | | **/ |
308 | | void |
309 | | fu_struct_rmi_img_set_checksum(FuStructRmiImg *st, guint32 value) |
310 | 0 | { |
311 | 0 | g_return_if_fail(st != NULL); |
312 | 0 | fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN); |
313 | 0 | } |
314 | | /** |
315 | | * fu_struct_rmi_img_set_io_offset: (skip): |
316 | | **/ |
317 | | void |
318 | | fu_struct_rmi_img_set_io_offset(FuStructRmiImg *st, guint8 value) |
319 | 0 | { |
320 | 0 | g_return_if_fail(st != NULL); |
321 | 0 | st->data[6] = value; |
322 | 0 | } |
323 | | /** |
324 | | * fu_struct_rmi_img_set_bootloader_version: (skip): |
325 | | **/ |
326 | | void |
327 | | fu_struct_rmi_img_set_bootloader_version(FuStructRmiImg *st, guint8 value) |
328 | 0 | { |
329 | 0 | g_return_if_fail(st != NULL); |
330 | 0 | st->data[7] = value; |
331 | 0 | } |
332 | | /** |
333 | | * fu_struct_rmi_img_set_image_size: (skip): |
334 | | **/ |
335 | | void |
336 | | fu_struct_rmi_img_set_image_size(FuStructRmiImg *st, guint32 value) |
337 | 0 | { |
338 | 0 | g_return_if_fail(st != NULL); |
339 | 0 | fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN); |
340 | 0 | } |
341 | | /** |
342 | | * fu_struct_rmi_img_set_config_size: (skip): |
343 | | **/ |
344 | | void |
345 | | fu_struct_rmi_img_set_config_size(FuStructRmiImg *st, guint32 value) |
346 | 0 | { |
347 | 0 | g_return_if_fail(st != NULL); |
348 | 0 | fu_memwrite_uint32(st->data + 12, value, G_LITTLE_ENDIAN); |
349 | 0 | } |
350 | | /** |
351 | | * fu_struct_rmi_img_set_product_id: (skip): |
352 | | **/ |
353 | | gboolean |
354 | | fu_struct_rmi_img_set_product_id(FuStructRmiImg *st, const gchar *value, GError **error) |
355 | 0 | { |
356 | 0 | gsize len; |
357 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
358 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
359 | 0 | if (value == NULL) { |
360 | 0 | memset(st->data + 16, 0x0, 10); |
361 | 0 | return TRUE; |
362 | 0 | } |
363 | 0 | len = strlen(value); |
364 | 0 | if (len > 10) { |
365 | 0 | g_set_error(error, |
366 | 0 | FWUPD_ERROR, |
367 | 0 | FWUPD_ERROR_INVALID_DATA, |
368 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructRmiImg.product_id (0x%x bytes)", |
369 | 0 | value, (guint) len, (guint) 10); |
370 | 0 | return FALSE; |
371 | 0 | } |
372 | 0 | return fu_memcpy_safe(st->data, st->len, 16, (const guint8 *)value, len, 0x0, len, error); |
373 | 0 | } |
374 | | /** |
375 | | * fu_struct_rmi_img_set_package_id: (skip): |
376 | | **/ |
377 | | void |
378 | | fu_struct_rmi_img_set_package_id(FuStructRmiImg *st, guint32 value) |
379 | 0 | { |
380 | 0 | g_return_if_fail(st != NULL); |
381 | 0 | fu_memwrite_uint32(st->data + 26, value, G_LITTLE_ENDIAN); |
382 | 0 | } |
383 | | /** |
384 | | * fu_struct_rmi_img_set_product_info: (skip): |
385 | | **/ |
386 | | void |
387 | | fu_struct_rmi_img_set_product_info(FuStructRmiImg *st, guint32 value) |
388 | 0 | { |
389 | 0 | g_return_if_fail(st != NULL); |
390 | 0 | fu_memwrite_uint32(st->data + 30, value, G_LITTLE_ENDIAN); |
391 | 0 | } |
392 | | /** |
393 | | * fu_struct_rmi_img_set_fw_build_id: (skip): |
394 | | **/ |
395 | | void |
396 | | fu_struct_rmi_img_set_fw_build_id(FuStructRmiImg *st, guint32 value) |
397 | 0 | { |
398 | 0 | g_return_if_fail(st != NULL); |
399 | 0 | fu_memwrite_uint32(st->data + 80, value, G_LITTLE_ENDIAN); |
400 | 0 | } |
401 | | /** |
402 | | * fu_struct_rmi_img_set_signature_size: (skip): |
403 | | **/ |
404 | | void |
405 | | fu_struct_rmi_img_set_signature_size(FuStructRmiImg *st, guint32 value) |
406 | 0 | { |
407 | 0 | g_return_if_fail(st != NULL); |
408 | 0 | fu_memwrite_uint32(st->data + 84, value, G_LITTLE_ENDIAN); |
409 | 0 | } |
410 | | /** |
411 | | * fu_struct_rmi_img_new: (skip): |
412 | | **/ |
413 | | FuStructRmiImg * |
414 | | fu_struct_rmi_img_new(void) |
415 | 7 | { |
416 | 7 | FuStructRmiImg *st = g_byte_array_sized_new(88); |
417 | 7 | fu_byte_array_set_size(st, 88, 0x0); |
418 | 7 | return st; |
419 | 7 | } |
420 | | /** |
421 | | * fu_struct_rmi_img_to_string: (skip): |
422 | | **/ |
423 | | static gchar * |
424 | | fu_struct_rmi_img_to_string(const FuStructRmiImg *st) |
425 | 0 | { |
426 | 0 | g_autoptr(GString) str = g_string_new("FuStructRmiImg:\n"); |
427 | 0 | g_return_val_if_fail(st != NULL, NULL); |
428 | 0 | g_string_append_printf(str, " checksum: 0x%x\n", |
429 | 0 | (guint) fu_struct_rmi_img_get_checksum(st)); |
430 | 0 | g_string_append_printf(str, " io_offset: 0x%x\n", |
431 | 0 | (guint) fu_struct_rmi_img_get_io_offset(st)); |
432 | 0 | g_string_append_printf(str, " bootloader_version: 0x%x\n", |
433 | 0 | (guint) fu_struct_rmi_img_get_bootloader_version(st)); |
434 | 0 | g_string_append_printf(str, " image_size: 0x%x\n", |
435 | 0 | (guint) fu_struct_rmi_img_get_image_size(st)); |
436 | 0 | g_string_append_printf(str, " config_size: 0x%x\n", |
437 | 0 | (guint) fu_struct_rmi_img_get_config_size(st)); |
438 | 0 | { |
439 | 0 | g_autofree gchar *tmp = fu_struct_rmi_img_get_product_id(st); |
440 | 0 | if (tmp != NULL) |
441 | 0 | g_string_append_printf(str, " product_id: %s\n", tmp); |
442 | 0 | } |
443 | 0 | g_string_append_printf(str, " package_id: 0x%x\n", |
444 | 0 | (guint) fu_struct_rmi_img_get_package_id(st)); |
445 | 0 | g_string_append_printf(str, " product_info: 0x%x\n", |
446 | 0 | (guint) fu_struct_rmi_img_get_product_info(st)); |
447 | 0 | g_string_append_printf(str, " fw_build_id: 0x%x\n", |
448 | 0 | (guint) fu_struct_rmi_img_get_fw_build_id(st)); |
449 | 0 | g_string_append_printf(str, " signature_size: 0x%x\n", |
450 | 0 | (guint) fu_struct_rmi_img_get_signature_size(st)); |
451 | 0 | if (str->len > 0) |
452 | 0 | g_string_set_size(str, str->len - 1); |
453 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
454 | 0 | } |
455 | | static gboolean |
456 | | fu_struct_rmi_img_validate_internal(FuStructRmiImg *st, GError **error) |
457 | 2.33k | { |
458 | 2.33k | g_return_val_if_fail(st != NULL, FALSE); |
459 | 2.33k | return TRUE; |
460 | 2.33k | } |
461 | | static gboolean |
462 | | fu_struct_rmi_img_parse_internal(FuStructRmiImg *st, GError **error) |
463 | 2.33k | { |
464 | 2.33k | if (!fu_struct_rmi_img_validate_internal(st, error)) |
465 | 0 | return FALSE; |
466 | 2.33k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
467 | 0 | g_autofree gchar *str = fu_struct_rmi_img_to_string(st); |
468 | 0 | g_debug("%s", str); |
469 | 0 | } |
470 | 2.33k | return TRUE; |
471 | 2.33k | } |
472 | | /** |
473 | | * fu_struct_rmi_img_parse_stream: (skip): |
474 | | **/ |
475 | | FuStructRmiImg * |
476 | | fu_struct_rmi_img_parse_stream(GInputStream *stream, gsize offset, GError **error) |
477 | 2.40k | { |
478 | 2.40k | g_autoptr(GByteArray) st = NULL; |
479 | 2.40k | st = fu_input_stream_read_byte_array(stream, offset, 88, NULL, error); |
480 | 2.40k | if (st == NULL) { |
481 | 0 | g_prefix_error(error, "FuStructRmiImg failed read of 0x%x: ", (guint) 88); |
482 | 0 | return NULL; |
483 | 0 | } |
484 | 2.40k | if (st->len != 88) { |
485 | 68 | g_set_error(error, |
486 | 68 | FWUPD_ERROR, |
487 | 68 | FWUPD_ERROR_INVALID_DATA, |
488 | 68 | "FuStructRmiImg requested 0x%x and got 0x%x", |
489 | 68 | (guint) 88, |
490 | 68 | (guint) st->len); |
491 | 68 | return NULL; |
492 | 68 | } |
493 | 2.33k | if (!fu_struct_rmi_img_parse_internal(st, error)) |
494 | 0 | return NULL; |
495 | 2.33k | return g_steal_pointer(&st); |
496 | 2.33k | } |
497 | | /* getters */ |
498 | | /** |
499 | | * fu_struct_rmi_container_descriptor_get_content_checksum: (skip): |
500 | | **/ |
501 | | guint32 |
502 | | fu_struct_rmi_container_descriptor_get_content_checksum(const FuStructRmiContainerDescriptor *st) |
503 | 0 | { |
504 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
505 | 0 | return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN); |
506 | 0 | } |
507 | | /** |
508 | | * fu_struct_rmi_container_descriptor_get_container_id: (skip): |
509 | | **/ |
510 | | FuRmiContainerId |
511 | | fu_struct_rmi_container_descriptor_get_container_id(const FuStructRmiContainerDescriptor *st) |
512 | 31.6k | { |
513 | 31.6k | g_return_val_if_fail(st != NULL, 0x0); |
514 | 31.6k | return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN); |
515 | 31.6k | } |
516 | | /** |
517 | | * fu_struct_rmi_container_descriptor_get_minor_version: (skip): |
518 | | **/ |
519 | | guint8 |
520 | | fu_struct_rmi_container_descriptor_get_minor_version(const FuStructRmiContainerDescriptor *st) |
521 | 0 | { |
522 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
523 | 0 | return st->data[6]; |
524 | 0 | } |
525 | | /** |
526 | | * fu_struct_rmi_container_descriptor_get_major_version: (skip): |
527 | | **/ |
528 | | guint8 |
529 | | fu_struct_rmi_container_descriptor_get_major_version(const FuStructRmiContainerDescriptor *st) |
530 | 0 | { |
531 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
532 | 0 | return st->data[7]; |
533 | 0 | } |
534 | | /** |
535 | | * fu_struct_rmi_container_descriptor_get_signature_size: (skip): |
536 | | **/ |
537 | | guint32 |
538 | | fu_struct_rmi_container_descriptor_get_signature_size(const FuStructRmiContainerDescriptor *st) |
539 | 30.8k | { |
540 | 30.8k | g_return_val_if_fail(st != NULL, 0x0); |
541 | 30.8k | return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN); |
542 | 30.8k | } |
543 | | /** |
544 | | * fu_struct_rmi_container_descriptor_get_container_option_flags: (skip): |
545 | | **/ |
546 | | guint32 |
547 | | fu_struct_rmi_container_descriptor_get_container_option_flags(const FuStructRmiContainerDescriptor *st) |
548 | 0 | { |
549 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
550 | 0 | return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN); |
551 | 0 | } |
552 | | /** |
553 | | * fu_struct_rmi_container_descriptor_get_content_options_length: (skip): |
554 | | **/ |
555 | | guint32 |
556 | | fu_struct_rmi_container_descriptor_get_content_options_length(const FuStructRmiContainerDescriptor *st) |
557 | 0 | { |
558 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
559 | 0 | return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN); |
560 | 0 | } |
561 | | /** |
562 | | * fu_struct_rmi_container_descriptor_get_content_options_address: (skip): |
563 | | **/ |
564 | | guint32 |
565 | | fu_struct_rmi_container_descriptor_get_content_options_address(const FuStructRmiContainerDescriptor *st) |
566 | 0 | { |
567 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
568 | 0 | return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN); |
569 | 0 | } |
570 | | /** |
571 | | * fu_struct_rmi_container_descriptor_get_content_length: (skip): |
572 | | **/ |
573 | | guint32 |
574 | | fu_struct_rmi_container_descriptor_get_content_length(const FuStructRmiContainerDescriptor *st) |
575 | 31.6k | { |
576 | 31.6k | g_return_val_if_fail(st != NULL, 0x0); |
577 | 31.6k | return fu_memread_uint32(st->data + 24, G_LITTLE_ENDIAN); |
578 | 31.6k | } |
579 | | /** |
580 | | * fu_struct_rmi_container_descriptor_get_content_address: (skip): |
581 | | **/ |
582 | | guint32 |
583 | | fu_struct_rmi_container_descriptor_get_content_address(const FuStructRmiContainerDescriptor *st) |
584 | 31.6k | { |
585 | 31.6k | g_return_val_if_fail(st != NULL, 0x0); |
586 | 31.6k | return fu_memread_uint32(st->data + 28, G_LITTLE_ENDIAN); |
587 | 31.6k | } |
588 | | |
589 | | /* setters */ |
590 | | /** |
591 | | * fu_struct_rmi_container_descriptor_set_content_checksum: (skip): |
592 | | **/ |
593 | | void |
594 | | fu_struct_rmi_container_descriptor_set_content_checksum(FuStructRmiContainerDescriptor *st, guint32 value) |
595 | 0 | { |
596 | 0 | g_return_if_fail(st != NULL); |
597 | 0 | fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN); |
598 | 0 | } |
599 | | /** |
600 | | * fu_struct_rmi_container_descriptor_set_container_id: (skip): |
601 | | **/ |
602 | | void |
603 | | fu_struct_rmi_container_descriptor_set_container_id(FuStructRmiContainerDescriptor *st, FuRmiContainerId value) |
604 | 104 | { |
605 | 104 | g_return_if_fail(st != NULL); |
606 | 104 | fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN); |
607 | 104 | } |
608 | | /** |
609 | | * fu_struct_rmi_container_descriptor_set_minor_version: (skip): |
610 | | **/ |
611 | | void |
612 | | fu_struct_rmi_container_descriptor_set_minor_version(FuStructRmiContainerDescriptor *st, guint8 value) |
613 | 0 | { |
614 | 0 | g_return_if_fail(st != NULL); |
615 | 0 | st->data[6] = value; |
616 | 0 | } |
617 | | /** |
618 | | * fu_struct_rmi_container_descriptor_set_major_version: (skip): |
619 | | **/ |
620 | | void |
621 | | fu_struct_rmi_container_descriptor_set_major_version(FuStructRmiContainerDescriptor *st, guint8 value) |
622 | 0 | { |
623 | 0 | g_return_if_fail(st != NULL); |
624 | 0 | st->data[7] = value; |
625 | 0 | } |
626 | | /** |
627 | | * fu_struct_rmi_container_descriptor_set_signature_size: (skip): |
628 | | **/ |
629 | | void |
630 | | fu_struct_rmi_container_descriptor_set_signature_size(FuStructRmiContainerDescriptor *st, guint32 value) |
631 | 0 | { |
632 | 0 | g_return_if_fail(st != NULL); |
633 | 0 | fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN); |
634 | 0 | } |
635 | | /** |
636 | | * fu_struct_rmi_container_descriptor_set_container_option_flags: (skip): |
637 | | **/ |
638 | | void |
639 | | fu_struct_rmi_container_descriptor_set_container_option_flags(FuStructRmiContainerDescriptor *st, guint32 value) |
640 | 0 | { |
641 | 0 | g_return_if_fail(st != NULL); |
642 | 0 | fu_memwrite_uint32(st->data + 12, value, G_LITTLE_ENDIAN); |
643 | 0 | } |
644 | | /** |
645 | | * fu_struct_rmi_container_descriptor_set_content_options_length: (skip): |
646 | | **/ |
647 | | void |
648 | | fu_struct_rmi_container_descriptor_set_content_options_length(FuStructRmiContainerDescriptor *st, guint32 value) |
649 | 0 | { |
650 | 0 | g_return_if_fail(st != NULL); |
651 | 0 | fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN); |
652 | 0 | } |
653 | | /** |
654 | | * fu_struct_rmi_container_descriptor_set_content_options_address: (skip): |
655 | | **/ |
656 | | void |
657 | | fu_struct_rmi_container_descriptor_set_content_options_address(FuStructRmiContainerDescriptor *st, guint32 value) |
658 | 0 | { |
659 | 0 | g_return_if_fail(st != NULL); |
660 | 0 | fu_memwrite_uint32(st->data + 20, value, G_LITTLE_ENDIAN); |
661 | 0 | } |
662 | | /** |
663 | | * fu_struct_rmi_container_descriptor_set_content_length: (skip): |
664 | | **/ |
665 | | void |
666 | | fu_struct_rmi_container_descriptor_set_content_length(FuStructRmiContainerDescriptor *st, guint32 value) |
667 | 0 | { |
668 | 0 | g_return_if_fail(st != NULL); |
669 | 0 | fu_memwrite_uint32(st->data + 24, value, G_LITTLE_ENDIAN); |
670 | 0 | } |
671 | | /** |
672 | | * fu_struct_rmi_container_descriptor_set_content_address: (skip): |
673 | | **/ |
674 | | void |
675 | | fu_struct_rmi_container_descriptor_set_content_address(FuStructRmiContainerDescriptor *st, guint32 value) |
676 | 104 | { |
677 | 104 | g_return_if_fail(st != NULL); |
678 | 104 | fu_memwrite_uint32(st->data + 28, value, G_LITTLE_ENDIAN); |
679 | 104 | } |
680 | | /** |
681 | | * fu_struct_rmi_container_descriptor_new: (skip): |
682 | | **/ |
683 | | FuStructRmiContainerDescriptor * |
684 | | fu_struct_rmi_container_descriptor_new(void) |
685 | 208 | { |
686 | 208 | FuStructRmiContainerDescriptor *st = g_byte_array_sized_new(32); |
687 | 208 | fu_byte_array_set_size(st, 32, 0x0); |
688 | 208 | return st; |
689 | 208 | } |
690 | | /** |
691 | | * fu_struct_rmi_container_descriptor_to_string: (skip): |
692 | | **/ |
693 | | static gchar * |
694 | | fu_struct_rmi_container_descriptor_to_string(const FuStructRmiContainerDescriptor *st) |
695 | 0 | { |
696 | 0 | g_autoptr(GString) str = g_string_new("FuStructRmiContainerDescriptor:\n"); |
697 | 0 | g_return_val_if_fail(st != NULL, NULL); |
698 | 0 | g_string_append_printf(str, " content_checksum: 0x%x\n", |
699 | 0 | (guint) fu_struct_rmi_container_descriptor_get_content_checksum(st)); |
700 | 0 | { |
701 | 0 | const gchar *tmp = fu_rmi_container_id_to_string(fu_struct_rmi_container_descriptor_get_container_id(st)); |
702 | 0 | if (tmp != NULL) { |
703 | 0 | g_string_append_printf(str, " container_id: 0x%x [%s]\n", (guint) fu_struct_rmi_container_descriptor_get_container_id(st), tmp); |
704 | 0 | } else { |
705 | 0 | g_string_append_printf(str, " container_id: 0x%x\n", (guint) fu_struct_rmi_container_descriptor_get_container_id(st)); |
706 | 0 | } |
707 | 0 | } |
708 | 0 | g_string_append_printf(str, " minor_version: 0x%x\n", |
709 | 0 | (guint) fu_struct_rmi_container_descriptor_get_minor_version(st)); |
710 | 0 | g_string_append_printf(str, " major_version: 0x%x\n", |
711 | 0 | (guint) fu_struct_rmi_container_descriptor_get_major_version(st)); |
712 | 0 | g_string_append_printf(str, " signature_size: 0x%x\n", |
713 | 0 | (guint) fu_struct_rmi_container_descriptor_get_signature_size(st)); |
714 | 0 | g_string_append_printf(str, " container_option_flags: 0x%x\n", |
715 | 0 | (guint) fu_struct_rmi_container_descriptor_get_container_option_flags(st)); |
716 | 0 | g_string_append_printf(str, " content_options_length: 0x%x\n", |
717 | 0 | (guint) fu_struct_rmi_container_descriptor_get_content_options_length(st)); |
718 | 0 | g_string_append_printf(str, " content_options_address: 0x%x\n", |
719 | 0 | (guint) fu_struct_rmi_container_descriptor_get_content_options_address(st)); |
720 | 0 | g_string_append_printf(str, " content_length: 0x%x\n", |
721 | 0 | (guint) fu_struct_rmi_container_descriptor_get_content_length(st)); |
722 | 0 | g_string_append_printf(str, " content_address: 0x%x\n", |
723 | 0 | (guint) fu_struct_rmi_container_descriptor_get_content_address(st)); |
724 | 0 | if (str->len > 0) |
725 | 0 | g_string_set_size(str, str->len - 1); |
726 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
727 | 0 | } |
728 | | static gboolean |
729 | | fu_struct_rmi_container_descriptor_validate_internal(FuStructRmiContainerDescriptor *st, GError **error) |
730 | 31.6k | { |
731 | 31.6k | g_return_val_if_fail(st != NULL, FALSE); |
732 | 31.6k | return TRUE; |
733 | 31.6k | } |
734 | | static gboolean |
735 | | fu_struct_rmi_container_descriptor_parse_internal(FuStructRmiContainerDescriptor *st, GError **error) |
736 | 31.6k | { |
737 | 31.6k | if (!fu_struct_rmi_container_descriptor_validate_internal(st, error)) |
738 | 0 | return FALSE; |
739 | 31.6k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
740 | 0 | g_autofree gchar *str = fu_struct_rmi_container_descriptor_to_string(st); |
741 | 0 | g_debug("%s", str); |
742 | 0 | } |
743 | 31.6k | return TRUE; |
744 | 31.6k | } |
745 | | /** |
746 | | * fu_struct_rmi_container_descriptor_parse_stream: (skip): |
747 | | **/ |
748 | | FuStructRmiContainerDescriptor * |
749 | | fu_struct_rmi_container_descriptor_parse_stream(GInputStream *stream, gsize offset, GError **error) |
750 | 31.9k | { |
751 | 31.9k | g_autoptr(GByteArray) st = NULL; |
752 | 31.9k | st = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
753 | 31.9k | if (st == NULL) { |
754 | 268 | g_prefix_error(error, "FuStructRmiContainerDescriptor failed read of 0x%x: ", (guint) 32); |
755 | 268 | return NULL; |
756 | 268 | } |
757 | 31.7k | if (st->len != 32) { |
758 | 24 | g_set_error(error, |
759 | 24 | FWUPD_ERROR, |
760 | 24 | FWUPD_ERROR_INVALID_DATA, |
761 | 24 | "FuStructRmiContainerDescriptor requested 0x%x and got 0x%x", |
762 | 24 | (guint) 32, |
763 | 24 | (guint) st->len); |
764 | 24 | return NULL; |
765 | 24 | } |
766 | 31.6k | if (!fu_struct_rmi_container_descriptor_parse_internal(st, error)) |
767 | 0 | return NULL; |
768 | 31.6k | return g_steal_pointer(&st); |
769 | 31.6k | } |