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