Line | Count | Source |
1 | | /* |
2 | | * This file is auto-generated, do not modify! |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include <glib.h> |
10 | | |
11 | | #include "fu-cfu-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-bytes.h" |
14 | | #include "fu-mem-private.h" |
15 | | #include "fu-string.h" |
16 | | |
17 | | #ifdef G_LOG_DOMAIN |
18 | | #undef G_LOG_DOMAIN |
19 | | #endif |
20 | 0 | #define G_LOG_DOMAIN "FuStruct" |
21 | | |
22 | | /** |
23 | | * fu_cfu_offer_info_code_to_string: |
24 | | * @val: value, e.g. %FU_CFU_OFFER_INFO_CODE_START_OFFER_LIST |
25 | | * |
26 | | * Converts an enumerated value to a string. |
27 | | * |
28 | | * Returns: identifier string |
29 | | **/ |
30 | | const gchar * |
31 | | fu_cfu_offer_info_code_to_string(FuCfuOfferInfoCode val) |
32 | 0 | { |
33 | 0 | if (val == FU_CFU_OFFER_INFO_CODE_START_ENTIRE_TRANSACTION) |
34 | 0 | return "start-entire-transaction"; |
35 | 0 | if (val == FU_CFU_OFFER_INFO_CODE_START_OFFER_LIST) |
36 | 0 | return "start-offer-list"; |
37 | 0 | if (val == FU_CFU_OFFER_INFO_CODE_END_OFFER_LIST) |
38 | 0 | return "end-offer-list"; |
39 | 0 | return NULL; |
40 | 0 | } |
41 | | |
42 | | /** |
43 | | * fu_cfu_rr_code_to_string: |
44 | | * @val: value, e.g. %FU_CFU_RR_CODE_OFFER_REJECT_INV_COMPONENT |
45 | | * |
46 | | * Converts an enumerated value to a string. |
47 | | * |
48 | | * Returns: identifier string |
49 | | **/ |
50 | | const gchar * |
51 | | fu_cfu_rr_code_to_string(FuCfuRrCode val) |
52 | 0 | { |
53 | 0 | if (val == FU_CFU_RR_CODE_OFFER_REJECT_OLD_FIRMWARE) |
54 | 0 | return "offer-reject-old-firmware"; |
55 | 0 | if (val == FU_CFU_RR_CODE_OFFER_REJECT_INV_COMPONENT) |
56 | 0 | return "offer-reject-inv-component"; |
57 | 0 | if (val == FU_CFU_RR_CODE_UPDATE_OFFER_SWAP_PENDING) |
58 | 0 | return "update-offer-swap-pending"; |
59 | 0 | if (val == FU_CFU_RR_CODE_WRONG_BANK) |
60 | 0 | return "wrong-bank"; |
61 | 0 | if (val == FU_CFU_RR_CODE_SIGN_RULE) |
62 | 0 | return "sign-rule"; |
63 | 0 | if (val == FU_CFU_RR_CODE_VER_RELEASE_DEBUG) |
64 | 0 | return "ver-release-debug"; |
65 | 0 | if (val == FU_CFU_RR_CODE_DEBUG_SAME_VERSION) |
66 | 0 | return "debug-same-version"; |
67 | 0 | if (val == FU_CFU_RR_CODE_NONE) |
68 | 0 | return "none"; |
69 | 0 | return NULL; |
70 | 0 | } |
71 | | |
72 | | /** |
73 | | * fu_cfu_offer_status_to_string: |
74 | | * @val: value, e.g. %FU_CFU_OFFER_STATUS_ACCEPT |
75 | | * |
76 | | * Converts an enumerated value to a string. |
77 | | * |
78 | | * Returns: identifier string |
79 | | **/ |
80 | | const gchar * |
81 | | fu_cfu_offer_status_to_string(FuCfuOfferStatus val) |
82 | 0 | { |
83 | 0 | if (val == FU_CFU_OFFER_STATUS_SKIP) |
84 | 0 | return "skip"; |
85 | 0 | if (val == FU_CFU_OFFER_STATUS_ACCEPT) |
86 | 0 | return "accept"; |
87 | 0 | if (val == FU_CFU_OFFER_STATUS_REJECT) |
88 | 0 | return "reject"; |
89 | 0 | if (val == FU_CFU_OFFER_STATUS_BUSY) |
90 | 0 | return "busy"; |
91 | 0 | if (val == FU_CFU_OFFER_STATUS_COMMAND) |
92 | 0 | return "command"; |
93 | 0 | if (val == FU_CFU_OFFER_STATUS_CMD_NOT_SUPPORTED) |
94 | 0 | return "cmd-not-supported"; |
95 | 0 | return NULL; |
96 | 0 | } |
97 | | |
98 | | |
99 | | /** |
100 | | * fu_cfu_content_status_to_string: |
101 | | * @val: value, e.g. %FU_CFU_CONTENT_STATUS_ERROR_PREPARE |
102 | | * |
103 | | * Converts an enumerated value to a string. |
104 | | * |
105 | | * Returns: identifier string |
106 | | **/ |
107 | | const gchar * |
108 | | fu_cfu_content_status_to_string(FuCfuContentStatus val) |
109 | 0 | { |
110 | 0 | if (val == FU_CFU_CONTENT_STATUS_SUCCESS) |
111 | 0 | return "success"; |
112 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_PREPARE) |
113 | 0 | return "error-prepare"; |
114 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_WRITE) |
115 | 0 | return "error-write"; |
116 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_COMPLETE) |
117 | 0 | return "error-complete"; |
118 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_VERIFY) |
119 | 0 | return "error-verify"; |
120 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_CRC) |
121 | 0 | return "error-crc"; |
122 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_SIGNATURE) |
123 | 0 | return "error-signature"; |
124 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_VERSION) |
125 | 0 | return "error-version"; |
126 | 0 | if (val == FU_CFU_CONTENT_STATUS_SWAP_PENDING) |
127 | 0 | return "swap-pending"; |
128 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_INVALID_ADDR) |
129 | 0 | return "error-invalid-addr"; |
130 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_NO_OFFER) |
131 | 0 | return "error-no-offer"; |
132 | 0 | if (val == FU_CFU_CONTENT_STATUS_ERROR_INVALID) |
133 | 0 | return "error-invalid"; |
134 | 0 | return NULL; |
135 | 0 | } |
136 | | /** |
137 | | * fu_struct_cfu_get_version_rsp_ref: (skip): |
138 | | **/ |
139 | | FuStructCfuGetVersionRsp * |
140 | | fu_struct_cfu_get_version_rsp_ref(FuStructCfuGetVersionRsp *st) |
141 | 0 | { |
142 | 0 | g_return_val_if_fail(st != NULL, NULL); |
143 | 0 | st->refcount++; |
144 | 0 | return st; |
145 | 0 | } |
146 | | /** |
147 | | * fu_struct_cfu_get_version_rsp_unref: (skip): |
148 | | **/ |
149 | | void |
150 | | fu_struct_cfu_get_version_rsp_unref(FuStructCfuGetVersionRsp *st) |
151 | 0 | { |
152 | 0 | g_return_if_fail(st != NULL); |
153 | 0 | if (st->refcount == 0) { |
154 | 0 | g_critical("FuStructCfuGetVersionRsp refcount already zero"); |
155 | 0 | return; |
156 | 0 | } |
157 | 0 | if (--st->refcount > 0) |
158 | 0 | return; |
159 | 0 | if (st->buf != NULL) |
160 | 0 | g_byte_array_unref(st->buf); |
161 | 0 | g_free(st); |
162 | 0 | } |
163 | | /** |
164 | | * fu_struct_cfu_get_version_rsp_new_internal: (skip): |
165 | | **/ |
166 | | static FuStructCfuGetVersionRsp * |
167 | | fu_struct_cfu_get_version_rsp_new_internal(void) |
168 | 0 | { |
169 | 0 | FuStructCfuGetVersionRsp *st = g_new0(FuStructCfuGetVersionRsp, 1); |
170 | 0 | st->refcount = 1; |
171 | 0 | return st; |
172 | 0 | } |
173 | | |
174 | | /* getters */ |
175 | | /** |
176 | | * fu_struct_cfu_get_version_rsp_get_component_cnt: (skip): |
177 | | **/ |
178 | | guint8 |
179 | | fu_struct_cfu_get_version_rsp_get_component_cnt(const FuStructCfuGetVersionRsp *st) |
180 | 0 | { |
181 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
182 | 0 | return st->buf->data[0]; |
183 | 0 | } |
184 | | /** |
185 | | * fu_struct_cfu_get_version_rsp_get_flags: (skip): |
186 | | **/ |
187 | | guint8 |
188 | | fu_struct_cfu_get_version_rsp_get_flags(const FuStructCfuGetVersionRsp *st) |
189 | 0 | { |
190 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
191 | 0 | return st->buf->data[3]; |
192 | 0 | } |
193 | | |
194 | | /* setters */ |
195 | | /** |
196 | | * fu_struct_cfu_get_version_rsp_set_component_cnt: (skip): |
197 | | **/ |
198 | | void |
199 | | fu_struct_cfu_get_version_rsp_set_component_cnt(FuStructCfuGetVersionRsp *st, guint8 value) |
200 | 0 | { |
201 | 0 | g_return_if_fail(st != NULL); |
202 | 0 | st->buf->data[0] = value; |
203 | 0 | } |
204 | | /** |
205 | | * fu_struct_cfu_get_version_rsp_set_flags: (skip): |
206 | | **/ |
207 | | void |
208 | | fu_struct_cfu_get_version_rsp_set_flags(FuStructCfuGetVersionRsp *st, guint8 value) |
209 | 0 | { |
210 | 0 | g_return_if_fail(st != NULL); |
211 | 0 | st->buf->data[3] = value; |
212 | 0 | } |
213 | | /** |
214 | | * fu_struct_cfu_get_version_rsp_new: (skip): |
215 | | **/ |
216 | | FuStructCfuGetVersionRsp * |
217 | | fu_struct_cfu_get_version_rsp_new(void) |
218 | 0 | { |
219 | 0 | FuStructCfuGetVersionRsp *st = fu_struct_cfu_get_version_rsp_new_internal(); |
220 | 0 | st->buf = g_byte_array_sized_new(4); |
221 | 0 | fu_byte_array_set_size(st->buf, 4, 0x0); |
222 | 0 | return st; |
223 | 0 | } |
224 | | /** |
225 | | * fu_struct_cfu_get_version_rsp_to_string: (skip): |
226 | | **/ |
227 | | static gchar * |
228 | | fu_struct_cfu_get_version_rsp_to_string(const FuStructCfuGetVersionRsp *st) |
229 | 0 | { |
230 | 0 | g_autoptr(GString) str = g_string_new("FuStructCfuGetVersionRsp:\n"); |
231 | 0 | g_return_val_if_fail(st != NULL, NULL); |
232 | 0 | g_string_append_printf(str, " component_cnt: 0x%x\n", |
233 | 0 | (guint) fu_struct_cfu_get_version_rsp_get_component_cnt(st)); |
234 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
235 | 0 | (guint) fu_struct_cfu_get_version_rsp_get_flags(st)); |
236 | 0 | if (str->len > 0) |
237 | 0 | g_string_set_size(str, str->len - 1); |
238 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
239 | 0 | } |
240 | | static gboolean |
241 | | fu_struct_cfu_get_version_rsp_parse_internal(FuStructCfuGetVersionRsp *st, GError **error) |
242 | 0 | { |
243 | 0 | if (g_log_get_debug_enabled()) { |
244 | 0 | g_autofree gchar *str = fu_struct_cfu_get_version_rsp_to_string(st); |
245 | 0 | g_debug("%s", str); |
246 | 0 | } |
247 | 0 | return TRUE; |
248 | 0 | } |
249 | | |
250 | | /** |
251 | | * fu_struct_cfu_get_version_rsp_parse: (skip): |
252 | | **/ |
253 | | FuStructCfuGetVersionRsp * |
254 | | fu_struct_cfu_get_version_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
255 | 0 | { |
256 | 0 | g_autoptr(FuStructCfuGetVersionRsp) st = fu_struct_cfu_get_version_rsp_new_internal(); |
257 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
258 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
259 | 0 | if (!fu_memchk_read(bufsz, offset, 4, error)) { |
260 | 0 | g_prefix_error_literal(error, "invalid struct FuStructCfuGetVersionRsp: "); |
261 | 0 | return NULL; |
262 | 0 | } |
263 | 0 | st->buf = g_byte_array_new(); |
264 | 0 | g_byte_array_append(st->buf, buf + offset, 4); |
265 | 0 | if (!fu_struct_cfu_get_version_rsp_parse_internal(st, error)) |
266 | 0 | return NULL; |
267 | 0 | return g_steal_pointer(&st); |
268 | 0 | } |
269 | | /** |
270 | | * fu_struct_cfu_get_version_rsp_component_ref: (skip): |
271 | | **/ |
272 | | FuStructCfuGetVersionRspComponent * |
273 | | fu_struct_cfu_get_version_rsp_component_ref(FuStructCfuGetVersionRspComponent *st) |
274 | 0 | { |
275 | 0 | g_return_val_if_fail(st != NULL, NULL); |
276 | 0 | st->refcount++; |
277 | 0 | return st; |
278 | 0 | } |
279 | | /** |
280 | | * fu_struct_cfu_get_version_rsp_component_unref: (skip): |
281 | | **/ |
282 | | void |
283 | | fu_struct_cfu_get_version_rsp_component_unref(FuStructCfuGetVersionRspComponent *st) |
284 | 0 | { |
285 | 0 | g_return_if_fail(st != NULL); |
286 | 0 | if (st->refcount == 0) { |
287 | 0 | g_critical("FuStructCfuGetVersionRspComponent refcount already zero"); |
288 | 0 | return; |
289 | 0 | } |
290 | 0 | if (--st->refcount > 0) |
291 | 0 | return; |
292 | 0 | if (st->buf != NULL) |
293 | 0 | g_byte_array_unref(st->buf); |
294 | 0 | g_free(st); |
295 | 0 | } |
296 | | /** |
297 | | * fu_struct_cfu_get_version_rsp_component_new_internal: (skip): |
298 | | **/ |
299 | | static FuStructCfuGetVersionRspComponent * |
300 | | fu_struct_cfu_get_version_rsp_component_new_internal(void) |
301 | 0 | { |
302 | 0 | FuStructCfuGetVersionRspComponent *st = g_new0(FuStructCfuGetVersionRspComponent, 1); |
303 | 0 | st->refcount = 1; |
304 | 0 | return st; |
305 | 0 | } |
306 | | |
307 | | /* getters */ |
308 | | /** |
309 | | * fu_struct_cfu_get_version_rsp_component_get_fw_version: (skip): |
310 | | **/ |
311 | | guint32 |
312 | | fu_struct_cfu_get_version_rsp_component_get_fw_version(const FuStructCfuGetVersionRspComponent *st) |
313 | 0 | { |
314 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
315 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
316 | 0 | } |
317 | | /** |
318 | | * fu_struct_cfu_get_version_rsp_component_get_flags: (skip): |
319 | | **/ |
320 | | guint8 |
321 | | fu_struct_cfu_get_version_rsp_component_get_flags(const FuStructCfuGetVersionRspComponent *st) |
322 | 0 | { |
323 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
324 | 0 | return st->buf->data[4]; |
325 | 0 | } |
326 | | /** |
327 | | * fu_struct_cfu_get_version_rsp_component_get_component_id: (skip): |
328 | | **/ |
329 | | guint8 |
330 | | fu_struct_cfu_get_version_rsp_component_get_component_id(const FuStructCfuGetVersionRspComponent *st) |
331 | 0 | { |
332 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
333 | 0 | return st->buf->data[5]; |
334 | 0 | } |
335 | | |
336 | | /* setters */ |
337 | | /** |
338 | | * fu_struct_cfu_get_version_rsp_component_set_fw_version: (skip): |
339 | | **/ |
340 | | void |
341 | | fu_struct_cfu_get_version_rsp_component_set_fw_version(FuStructCfuGetVersionRspComponent *st, guint32 value) |
342 | 0 | { |
343 | 0 | g_return_if_fail(st != NULL); |
344 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
345 | 0 | } |
346 | | /** |
347 | | * fu_struct_cfu_get_version_rsp_component_set_flags: (skip): |
348 | | **/ |
349 | | void |
350 | | fu_struct_cfu_get_version_rsp_component_set_flags(FuStructCfuGetVersionRspComponent *st, guint8 value) |
351 | 0 | { |
352 | 0 | g_return_if_fail(st != NULL); |
353 | 0 | st->buf->data[4] = value; |
354 | 0 | } |
355 | | /** |
356 | | * fu_struct_cfu_get_version_rsp_component_set_component_id: (skip): |
357 | | **/ |
358 | | void |
359 | | fu_struct_cfu_get_version_rsp_component_set_component_id(FuStructCfuGetVersionRspComponent *st, guint8 value) |
360 | 0 | { |
361 | 0 | g_return_if_fail(st != NULL); |
362 | 0 | st->buf->data[5] = value; |
363 | 0 | } |
364 | | /** |
365 | | * fu_struct_cfu_get_version_rsp_component_new: (skip): |
366 | | **/ |
367 | | FuStructCfuGetVersionRspComponent * |
368 | | fu_struct_cfu_get_version_rsp_component_new(void) |
369 | 0 | { |
370 | 0 | FuStructCfuGetVersionRspComponent *st = fu_struct_cfu_get_version_rsp_component_new_internal(); |
371 | 0 | st->buf = g_byte_array_sized_new(8); |
372 | 0 | fu_byte_array_set_size(st->buf, 8, 0x0); |
373 | 0 | return st; |
374 | 0 | } |
375 | | /** |
376 | | * fu_struct_cfu_get_version_rsp_component_to_string: (skip): |
377 | | **/ |
378 | | static gchar * |
379 | | fu_struct_cfu_get_version_rsp_component_to_string(const FuStructCfuGetVersionRspComponent *st) |
380 | 0 | { |
381 | 0 | g_autoptr(GString) str = g_string_new("FuStructCfuGetVersionRspComponent:\n"); |
382 | 0 | g_return_val_if_fail(st != NULL, NULL); |
383 | 0 | g_string_append_printf(str, " fw_version: 0x%x\n", |
384 | 0 | (guint) fu_struct_cfu_get_version_rsp_component_get_fw_version(st)); |
385 | 0 | g_string_append_printf(str, " flags: 0x%x\n", |
386 | 0 | (guint) fu_struct_cfu_get_version_rsp_component_get_flags(st)); |
387 | 0 | g_string_append_printf(str, " component_id: 0x%x\n", |
388 | 0 | (guint) fu_struct_cfu_get_version_rsp_component_get_component_id(st)); |
389 | 0 | if (str->len > 0) |
390 | 0 | g_string_set_size(str, str->len - 1); |
391 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
392 | 0 | } |
393 | | static gboolean |
394 | | fu_struct_cfu_get_version_rsp_component_parse_internal(FuStructCfuGetVersionRspComponent *st, GError **error) |
395 | 0 | { |
396 | 0 | if (g_log_get_debug_enabled()) { |
397 | 0 | g_autofree gchar *str = fu_struct_cfu_get_version_rsp_component_to_string(st); |
398 | 0 | g_debug("%s", str); |
399 | 0 | } |
400 | 0 | return TRUE; |
401 | 0 | } |
402 | | |
403 | | /** |
404 | | * fu_struct_cfu_get_version_rsp_component_parse: (skip): |
405 | | **/ |
406 | | FuStructCfuGetVersionRspComponent * |
407 | | fu_struct_cfu_get_version_rsp_component_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
408 | 0 | { |
409 | 0 | g_autoptr(FuStructCfuGetVersionRspComponent) st = fu_struct_cfu_get_version_rsp_component_new_internal(); |
410 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
411 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
412 | 0 | if (!fu_memchk_read(bufsz, offset, 8, error)) { |
413 | 0 | g_prefix_error_literal(error, "invalid struct FuStructCfuGetVersionRspComponent: "); |
414 | 0 | return NULL; |
415 | 0 | } |
416 | 0 | st->buf = g_byte_array_new(); |
417 | 0 | g_byte_array_append(st->buf, buf + offset, 8); |
418 | 0 | if (!fu_struct_cfu_get_version_rsp_component_parse_internal(st, error)) |
419 | 0 | return NULL; |
420 | 0 | return g_steal_pointer(&st); |
421 | 0 | } |
422 | | /** |
423 | | * fu_struct_cfu_offer_info_req_ref: (skip): |
424 | | **/ |
425 | | FuStructCfuOfferInfoReq * |
426 | | fu_struct_cfu_offer_info_req_ref(FuStructCfuOfferInfoReq *st) |
427 | 0 | { |
428 | 0 | g_return_val_if_fail(st != NULL, NULL); |
429 | 0 | st->refcount++; |
430 | 0 | return st; |
431 | 0 | } |
432 | | /** |
433 | | * fu_struct_cfu_offer_info_req_unref: (skip): |
434 | | **/ |
435 | | void |
436 | | fu_struct_cfu_offer_info_req_unref(FuStructCfuOfferInfoReq *st) |
437 | 0 | { |
438 | 0 | g_return_if_fail(st != NULL); |
439 | 0 | if (st->refcount == 0) { |
440 | 0 | g_critical("FuStructCfuOfferInfoReq refcount already zero"); |
441 | 0 | return; |
442 | 0 | } |
443 | 0 | if (--st->refcount > 0) |
444 | 0 | return; |
445 | 0 | if (st->buf != NULL) |
446 | 0 | g_byte_array_unref(st->buf); |
447 | 0 | g_free(st); |
448 | 0 | } |
449 | | /** |
450 | | * fu_struct_cfu_offer_info_req_new_internal: (skip): |
451 | | **/ |
452 | | static FuStructCfuOfferInfoReq * |
453 | | fu_struct_cfu_offer_info_req_new_internal(void) |
454 | 0 | { |
455 | 0 | FuStructCfuOfferInfoReq *st = g_new0(FuStructCfuOfferInfoReq, 1); |
456 | 0 | st->refcount = 1; |
457 | 0 | return st; |
458 | 0 | } |
459 | | |
460 | | /* getters */ |
461 | | |
462 | | /* setters */ |
463 | | /** |
464 | | * fu_struct_cfu_offer_info_req_set_code: (skip): |
465 | | **/ |
466 | | void |
467 | | fu_struct_cfu_offer_info_req_set_code(FuStructCfuOfferInfoReq *st, FuCfuOfferInfoCode value) |
468 | 0 | { |
469 | 0 | g_return_if_fail(st != NULL); |
470 | 0 | st->buf->data[0] = value; |
471 | 0 | } |
472 | | /** |
473 | | * fu_struct_cfu_offer_info_req_set_component_id: (skip): |
474 | | **/ |
475 | | static void |
476 | | fu_struct_cfu_offer_info_req_set_component_id(FuStructCfuOfferInfoReq *st, guint8 value) |
477 | 0 | { |
478 | 0 | g_return_if_fail(st != NULL); |
479 | 0 | st->buf->data[2] = value; |
480 | 0 | } |
481 | | /** |
482 | | * fu_struct_cfu_offer_info_req_set_token: (skip): |
483 | | **/ |
484 | | static void |
485 | | fu_struct_cfu_offer_info_req_set_token(FuStructCfuOfferInfoReq *st, guint8 value) |
486 | 0 | { |
487 | 0 | g_return_if_fail(st != NULL); |
488 | 0 | st->buf->data[3] = value; |
489 | 0 | } |
490 | | /** |
491 | | * fu_struct_cfu_offer_info_req_new: (skip): |
492 | | **/ |
493 | | FuStructCfuOfferInfoReq * |
494 | | fu_struct_cfu_offer_info_req_new(void) |
495 | 0 | { |
496 | 0 | FuStructCfuOfferInfoReq *st = fu_struct_cfu_offer_info_req_new_internal(); |
497 | 0 | st->buf = g_byte_array_sized_new(16); |
498 | 0 | fu_byte_array_set_size(st->buf, 16, 0x0); |
499 | 0 | fu_struct_cfu_offer_info_req_set_component_id(st, 0xFF); |
500 | 0 | fu_struct_cfu_offer_info_req_set_token(st, 0xDE); |
501 | 0 | return st; |
502 | 0 | } |
503 | | /** |
504 | | * fu_struct_cfu_offer_rsp_ref: (skip): |
505 | | **/ |
506 | | FuStructCfuOfferRsp * |
507 | | fu_struct_cfu_offer_rsp_ref(FuStructCfuOfferRsp *st) |
508 | 0 | { |
509 | 0 | g_return_val_if_fail(st != NULL, NULL); |
510 | 0 | st->refcount++; |
511 | 0 | return st; |
512 | 0 | } |
513 | | /** |
514 | | * fu_struct_cfu_offer_rsp_unref: (skip): |
515 | | **/ |
516 | | void |
517 | | fu_struct_cfu_offer_rsp_unref(FuStructCfuOfferRsp *st) |
518 | 0 | { |
519 | 0 | g_return_if_fail(st != NULL); |
520 | 0 | if (st->refcount == 0) { |
521 | 0 | g_critical("FuStructCfuOfferRsp refcount already zero"); |
522 | 0 | return; |
523 | 0 | } |
524 | 0 | if (--st->refcount > 0) |
525 | 0 | return; |
526 | 0 | if (st->buf != NULL) |
527 | 0 | g_byte_array_unref(st->buf); |
528 | 0 | g_free(st); |
529 | 0 | } |
530 | | /** |
531 | | * fu_struct_cfu_offer_rsp_new_internal: (skip): |
532 | | **/ |
533 | | static FuStructCfuOfferRsp * |
534 | | fu_struct_cfu_offer_rsp_new_internal(void) |
535 | 0 | { |
536 | 0 | FuStructCfuOfferRsp *st = g_new0(FuStructCfuOfferRsp, 1); |
537 | 0 | st->refcount = 1; |
538 | 0 | return st; |
539 | 0 | } |
540 | | |
541 | | /* getters */ |
542 | | /** |
543 | | * fu_struct_cfu_offer_rsp_get_token: (skip): |
544 | | **/ |
545 | | guint8 |
546 | | fu_struct_cfu_offer_rsp_get_token(const FuStructCfuOfferRsp *st) |
547 | 0 | { |
548 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
549 | 0 | return st->buf->data[3]; |
550 | 0 | } |
551 | | /** |
552 | | * fu_struct_cfu_offer_rsp_get_rr_code: (skip): |
553 | | **/ |
554 | | FuCfuRrCode |
555 | | fu_struct_cfu_offer_rsp_get_rr_code(const FuStructCfuOfferRsp *st) |
556 | 0 | { |
557 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
558 | 0 | return st->buf->data[8]; |
559 | 0 | } |
560 | | /** |
561 | | * fu_struct_cfu_offer_rsp_get_status: (skip): |
562 | | **/ |
563 | | FuCfuOfferStatus |
564 | | fu_struct_cfu_offer_rsp_get_status(const FuStructCfuOfferRsp *st) |
565 | 0 | { |
566 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
567 | 0 | return st->buf->data[12]; |
568 | 0 | } |
569 | | |
570 | | /* setters */ |
571 | | /** |
572 | | * fu_struct_cfu_offer_rsp_to_string: (skip): |
573 | | **/ |
574 | | static gchar * |
575 | | fu_struct_cfu_offer_rsp_to_string(const FuStructCfuOfferRsp *st) |
576 | 0 | { |
577 | 0 | g_autoptr(GString) str = g_string_new("FuStructCfuOfferRsp:\n"); |
578 | 0 | g_return_val_if_fail(st != NULL, NULL); |
579 | 0 | g_string_append_printf(str, " token: 0x%x\n", |
580 | 0 | (guint) fu_struct_cfu_offer_rsp_get_token(st)); |
581 | 0 | { |
582 | 0 | const gchar *tmp = fu_cfu_rr_code_to_string(fu_struct_cfu_offer_rsp_get_rr_code(st)); |
583 | 0 | if (tmp != NULL) { |
584 | 0 | g_string_append_printf(str, " rr_code: 0x%x [%s]\n", (guint) fu_struct_cfu_offer_rsp_get_rr_code(st), tmp); |
585 | 0 | } else { |
586 | 0 | g_string_append_printf(str, " rr_code: 0x%x\n", (guint) fu_struct_cfu_offer_rsp_get_rr_code(st)); |
587 | 0 | } |
588 | 0 | } |
589 | 0 | { |
590 | 0 | const gchar *tmp = fu_cfu_offer_status_to_string(fu_struct_cfu_offer_rsp_get_status(st)); |
591 | 0 | if (tmp != NULL) { |
592 | 0 | g_string_append_printf(str, " status: 0x%x [%s]\n", (guint) fu_struct_cfu_offer_rsp_get_status(st), tmp); |
593 | 0 | } else { |
594 | 0 | g_string_append_printf(str, " status: 0x%x\n", (guint) fu_struct_cfu_offer_rsp_get_status(st)); |
595 | 0 | } |
596 | 0 | } |
597 | 0 | if (str->len > 0) |
598 | 0 | g_string_set_size(str, str->len - 1); |
599 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
600 | 0 | } |
601 | | static gboolean |
602 | | fu_struct_cfu_offer_rsp_parse_internal(FuStructCfuOfferRsp *st, GError **error) |
603 | 0 | { |
604 | 0 | if (g_log_get_debug_enabled()) { |
605 | 0 | g_autofree gchar *str = fu_struct_cfu_offer_rsp_to_string(st); |
606 | 0 | g_debug("%s", str); |
607 | 0 | } |
608 | 0 | return TRUE; |
609 | 0 | } |
610 | | |
611 | | /** |
612 | | * fu_struct_cfu_offer_rsp_parse: (skip): |
613 | | **/ |
614 | | FuStructCfuOfferRsp * |
615 | | fu_struct_cfu_offer_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
616 | 0 | { |
617 | 0 | g_autoptr(FuStructCfuOfferRsp) st = fu_struct_cfu_offer_rsp_new_internal(); |
618 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
619 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
620 | 0 | if (!fu_memchk_read(bufsz, offset, 16, error)) { |
621 | 0 | g_prefix_error_literal(error, "invalid struct FuStructCfuOfferRsp: "); |
622 | 0 | return NULL; |
623 | 0 | } |
624 | 0 | st->buf = g_byte_array_new(); |
625 | 0 | g_byte_array_append(st->buf, buf + offset, 16); |
626 | 0 | if (!fu_struct_cfu_offer_rsp_parse_internal(st, error)) |
627 | 0 | return NULL; |
628 | 0 | return g_steal_pointer(&st); |
629 | 0 | } |
630 | | /** |
631 | | * fu_struct_cfu_content_req_ref: (skip): |
632 | | **/ |
633 | | FuStructCfuContentReq * |
634 | | fu_struct_cfu_content_req_ref(FuStructCfuContentReq *st) |
635 | 0 | { |
636 | 0 | g_return_val_if_fail(st != NULL, NULL); |
637 | 0 | st->refcount++; |
638 | 0 | return st; |
639 | 0 | } |
640 | | /** |
641 | | * fu_struct_cfu_content_req_unref: (skip): |
642 | | **/ |
643 | | void |
644 | | fu_struct_cfu_content_req_unref(FuStructCfuContentReq *st) |
645 | 0 | { |
646 | 0 | g_return_if_fail(st != NULL); |
647 | 0 | if (st->refcount == 0) { |
648 | 0 | g_critical("FuStructCfuContentReq refcount already zero"); |
649 | 0 | return; |
650 | 0 | } |
651 | 0 | if (--st->refcount > 0) |
652 | 0 | return; |
653 | 0 | if (st->buf != NULL) |
654 | 0 | g_byte_array_unref(st->buf); |
655 | 0 | g_free(st); |
656 | 0 | } |
657 | | /** |
658 | | * fu_struct_cfu_content_req_new_internal: (skip): |
659 | | **/ |
660 | | static FuStructCfuContentReq * |
661 | | fu_struct_cfu_content_req_new_internal(void) |
662 | 0 | { |
663 | 0 | FuStructCfuContentReq *st = g_new0(FuStructCfuContentReq, 1); |
664 | 0 | st->refcount = 1; |
665 | 0 | return st; |
666 | 0 | } |
667 | | |
668 | | /* getters */ |
669 | | /** |
670 | | * fu_struct_cfu_content_req_get_flags: (skip): |
671 | | **/ |
672 | | FuCfuContentFlags |
673 | | fu_struct_cfu_content_req_get_flags(const FuStructCfuContentReq *st) |
674 | 0 | { |
675 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
676 | 0 | return st->buf->data[0]; |
677 | 0 | } |
678 | | /** |
679 | | * fu_struct_cfu_content_req_get_data_length: (skip): |
680 | | **/ |
681 | | guint8 |
682 | | fu_struct_cfu_content_req_get_data_length(const FuStructCfuContentReq *st) |
683 | 0 | { |
684 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
685 | 0 | return st->buf->data[1]; |
686 | 0 | } |
687 | | /** |
688 | | * fu_struct_cfu_content_req_get_seq_number: (skip): |
689 | | **/ |
690 | | guint16 |
691 | | fu_struct_cfu_content_req_get_seq_number(const FuStructCfuContentReq *st) |
692 | 0 | { |
693 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
694 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
695 | 0 | } |
696 | | /** |
697 | | * fu_struct_cfu_content_req_get_address: (skip): |
698 | | **/ |
699 | | guint32 |
700 | | fu_struct_cfu_content_req_get_address(const FuStructCfuContentReq *st) |
701 | 0 | { |
702 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
703 | 0 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
704 | 0 | } |
705 | | |
706 | | /* setters */ |
707 | | /** |
708 | | * fu_struct_cfu_content_req_set_flags: (skip): |
709 | | **/ |
710 | | void |
711 | | fu_struct_cfu_content_req_set_flags(FuStructCfuContentReq *st, FuCfuContentFlags value) |
712 | 0 | { |
713 | 0 | g_return_if_fail(st != NULL); |
714 | 0 | st->buf->data[0] = value; |
715 | 0 | } |
716 | | /** |
717 | | * fu_struct_cfu_content_req_set_data_length: (skip): |
718 | | **/ |
719 | | void |
720 | | fu_struct_cfu_content_req_set_data_length(FuStructCfuContentReq *st, guint8 value) |
721 | 0 | { |
722 | 0 | g_return_if_fail(st != NULL); |
723 | 0 | st->buf->data[1] = value; |
724 | 0 | } |
725 | | /** |
726 | | * fu_struct_cfu_content_req_set_seq_number: (skip): |
727 | | **/ |
728 | | void |
729 | | fu_struct_cfu_content_req_set_seq_number(FuStructCfuContentReq *st, guint16 value) |
730 | 0 | { |
731 | 0 | g_return_if_fail(st != NULL); |
732 | 0 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
733 | 0 | } |
734 | | /** |
735 | | * fu_struct_cfu_content_req_set_address: (skip): |
736 | | **/ |
737 | | void |
738 | | fu_struct_cfu_content_req_set_address(FuStructCfuContentReq *st, guint32 value) |
739 | 0 | { |
740 | 0 | g_return_if_fail(st != NULL); |
741 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
742 | 0 | } |
743 | | /** |
744 | | * fu_struct_cfu_content_req_new: (skip): |
745 | | **/ |
746 | | FuStructCfuContentReq * |
747 | | fu_struct_cfu_content_req_new(void) |
748 | 0 | { |
749 | 0 | FuStructCfuContentReq *st = fu_struct_cfu_content_req_new_internal(); |
750 | 0 | st->buf = g_byte_array_sized_new(8); |
751 | 0 | fu_byte_array_set_size(st->buf, 8, 0x0); |
752 | 0 | return st; |
753 | 0 | } |
754 | | /** |
755 | | * fu_struct_cfu_content_rsp_ref: (skip): |
756 | | **/ |
757 | | FuStructCfuContentRsp * |
758 | | fu_struct_cfu_content_rsp_ref(FuStructCfuContentRsp *st) |
759 | 0 | { |
760 | 0 | g_return_val_if_fail(st != NULL, NULL); |
761 | 0 | st->refcount++; |
762 | 0 | return st; |
763 | 0 | } |
764 | | /** |
765 | | * fu_struct_cfu_content_rsp_unref: (skip): |
766 | | **/ |
767 | | void |
768 | | fu_struct_cfu_content_rsp_unref(FuStructCfuContentRsp *st) |
769 | 0 | { |
770 | 0 | g_return_if_fail(st != NULL); |
771 | 0 | if (st->refcount == 0) { |
772 | 0 | g_critical("FuStructCfuContentRsp refcount already zero"); |
773 | 0 | return; |
774 | 0 | } |
775 | 0 | if (--st->refcount > 0) |
776 | 0 | return; |
777 | 0 | if (st->buf != NULL) |
778 | 0 | g_byte_array_unref(st->buf); |
779 | 0 | g_free(st); |
780 | 0 | } |
781 | | /** |
782 | | * fu_struct_cfu_content_rsp_new_internal: (skip): |
783 | | **/ |
784 | | static FuStructCfuContentRsp * |
785 | | fu_struct_cfu_content_rsp_new_internal(void) |
786 | 0 | { |
787 | 0 | FuStructCfuContentRsp *st = g_new0(FuStructCfuContentRsp, 1); |
788 | 0 | st->refcount = 1; |
789 | 0 | return st; |
790 | 0 | } |
791 | | |
792 | | /* getters */ |
793 | | /** |
794 | | * fu_struct_cfu_content_rsp_get_seq_number: (skip): |
795 | | **/ |
796 | | guint16 |
797 | | fu_struct_cfu_content_rsp_get_seq_number(const FuStructCfuContentRsp *st) |
798 | 0 | { |
799 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
800 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
801 | 0 | } |
802 | | /** |
803 | | * fu_struct_cfu_content_rsp_get_status: (skip): |
804 | | **/ |
805 | | FuCfuContentStatus |
806 | | fu_struct_cfu_content_rsp_get_status(const FuStructCfuContentRsp *st) |
807 | 0 | { |
808 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
809 | 0 | return st->buf->data[4]; |
810 | 0 | } |
811 | | |
812 | | /* setters */ |
813 | | /** |
814 | | * fu_struct_cfu_content_rsp_to_string: (skip): |
815 | | **/ |
816 | | static gchar * |
817 | | fu_struct_cfu_content_rsp_to_string(const FuStructCfuContentRsp *st) |
818 | 0 | { |
819 | 0 | g_autoptr(GString) str = g_string_new("FuStructCfuContentRsp:\n"); |
820 | 0 | g_return_val_if_fail(st != NULL, NULL); |
821 | 0 | g_string_append_printf(str, " seq_number: 0x%x\n", |
822 | 0 | (guint) fu_struct_cfu_content_rsp_get_seq_number(st)); |
823 | 0 | { |
824 | 0 | const gchar *tmp = fu_cfu_content_status_to_string(fu_struct_cfu_content_rsp_get_status(st)); |
825 | 0 | if (tmp != NULL) { |
826 | 0 | g_string_append_printf(str, " status: 0x%x [%s]\n", (guint) fu_struct_cfu_content_rsp_get_status(st), tmp); |
827 | 0 | } else { |
828 | 0 | g_string_append_printf(str, " status: 0x%x\n", (guint) fu_struct_cfu_content_rsp_get_status(st)); |
829 | 0 | } |
830 | 0 | } |
831 | 0 | if (str->len > 0) |
832 | 0 | g_string_set_size(str, str->len - 1); |
833 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
834 | 0 | } |
835 | | static gboolean |
836 | | fu_struct_cfu_content_rsp_parse_internal(FuStructCfuContentRsp *st, GError **error) |
837 | 0 | { |
838 | 0 | if (g_log_get_debug_enabled()) { |
839 | 0 | g_autofree gchar *str = fu_struct_cfu_content_rsp_to_string(st); |
840 | 0 | g_debug("%s", str); |
841 | 0 | } |
842 | 0 | return TRUE; |
843 | 0 | } |
844 | | |
845 | | /** |
846 | | * fu_struct_cfu_content_rsp_parse: (skip): |
847 | | **/ |
848 | | FuStructCfuContentRsp * |
849 | | fu_struct_cfu_content_rsp_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
850 | 0 | { |
851 | 0 | g_autoptr(FuStructCfuContentRsp) st = fu_struct_cfu_content_rsp_new_internal(); |
852 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
853 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
854 | 0 | if (!fu_memchk_read(bufsz, offset, 16, error)) { |
855 | 0 | g_prefix_error_literal(error, "invalid struct FuStructCfuContentRsp: "); |
856 | 0 | return NULL; |
857 | 0 | } |
858 | 0 | st->buf = g_byte_array_new(); |
859 | 0 | g_byte_array_append(st->buf, buf + offset, 16); |
860 | 0 | if (!fu_struct_cfu_content_rsp_parse_internal(st, error)) |
861 | 0 | return NULL; |
862 | 0 | return g_steal_pointer(&st); |
863 | 0 | } |