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