/work/fu-ccgx-pure-hid-struct.c
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-ccgx-pure-hid-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-mem-private.h" |
14 | | #include "fu-string.h" |
15 | | |
16 | | #ifdef G_LOG_DOMAIN |
17 | | #undef G_LOG_DOMAIN |
18 | | #endif |
19 | 0 | #define G_LOG_DOMAIN "FuStruct" |
20 | | |
21 | | /** |
22 | | * fu_ccgx_pure_hid_fw_mode_to_string: |
23 | | * @val: value, e.g. %FU_CCGX_PURE_HID_FW_MODE_FW1 |
24 | | * |
25 | | * Converts an enumerated value to a string. |
26 | | * |
27 | | * Returns: identifier string |
28 | | **/ |
29 | | const gchar * |
30 | | fu_ccgx_pure_hid_fw_mode_to_string(FuCcgxPureHidFwMode val) |
31 | 0 | { |
32 | 0 | if (val == FU_CCGX_PURE_HID_FW_MODE_BOOT) |
33 | 0 | return "boot"; |
34 | 0 | if (val == FU_CCGX_PURE_HID_FW_MODE_FW1) |
35 | 0 | return "fw1"; |
36 | 0 | if (val == FU_CCGX_PURE_HID_FW_MODE_FW2) |
37 | 0 | return "fw2"; |
38 | 0 | return NULL; |
39 | 0 | } |
40 | | |
41 | | /** |
42 | | * fu_ccgx_pure_hid_report_id_to_string: |
43 | | * @val: value, e.g. %FU_CCGX_PURE_HID_REPORT_ID_COMMAND |
44 | | * |
45 | | * Converts an enumerated value to a string. |
46 | | * |
47 | | * Returns: identifier string |
48 | | **/ |
49 | | static const gchar * |
50 | | fu_ccgx_pure_hid_report_id_to_string(FuCcgxPureHidReportId val) |
51 | 0 | { |
52 | 0 | if (val == FU_CCGX_PURE_HID_REPORT_ID_INFO) |
53 | 0 | return "info"; |
54 | 0 | if (val == FU_CCGX_PURE_HID_REPORT_ID_COMMAND) |
55 | 0 | return "command"; |
56 | 0 | if (val == FU_CCGX_PURE_HID_REPORT_ID_WRITE) |
57 | 0 | return "write"; |
58 | 0 | if (val == FU_CCGX_PURE_HID_REPORT_ID_READ) |
59 | 0 | return "read"; |
60 | 0 | if (val == FU_CCGX_PURE_HID_REPORT_ID_CUSTOM) |
61 | 0 | return "custom"; |
62 | 0 | return NULL; |
63 | 0 | } |
64 | | |
65 | | /** |
66 | | * fu_struct_ccgx_pure_hid_fw_info_ref: (skip): |
67 | | **/ |
68 | | FuStructCcgxPureHidFwInfo * |
69 | | fu_struct_ccgx_pure_hid_fw_info_ref(FuStructCcgxPureHidFwInfo *st) |
70 | 0 | { |
71 | 0 | g_return_val_if_fail(st != NULL, NULL); |
72 | 0 | st->refcount++; |
73 | 0 | return st; |
74 | 0 | } |
75 | | /** |
76 | | * fu_struct_ccgx_pure_hid_fw_info_unref: (skip): |
77 | | **/ |
78 | | void |
79 | | fu_struct_ccgx_pure_hid_fw_info_unref(FuStructCcgxPureHidFwInfo *st) |
80 | 0 | { |
81 | 0 | g_return_if_fail(st != NULL); |
82 | 0 | if (st->refcount == 0) { |
83 | 0 | g_critical("FuStructCcgxPureHidFwInfo refcount already zero"); |
84 | 0 | return; |
85 | 0 | } |
86 | 0 | if (--st->refcount > 0) |
87 | 0 | return; |
88 | 0 | if (st->buf != NULL) |
89 | 0 | g_byte_array_unref(st->buf); |
90 | 0 | g_free(st); |
91 | 0 | } |
92 | | /** |
93 | | * fu_struct_ccgx_pure_hid_fw_info_new_internal: (skip): |
94 | | **/ |
95 | | static FuStructCcgxPureHidFwInfo * |
96 | | fu_struct_ccgx_pure_hid_fw_info_new_internal(void) |
97 | 0 | { |
98 | 0 | FuStructCcgxPureHidFwInfo *st = g_new0(FuStructCcgxPureHidFwInfo, 1); |
99 | 0 | st->refcount = 1; |
100 | 0 | return st; |
101 | 0 | } |
102 | | |
103 | | /* getters */ |
104 | | /** |
105 | | * fu_struct_ccgx_pure_hid_fw_info_get_report_id: (skip): |
106 | | **/ |
107 | | static FuCcgxPureHidReportId |
108 | | fu_struct_ccgx_pure_hid_fw_info_get_report_id(const FuStructCcgxPureHidFwInfo *st) |
109 | 0 | { |
110 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
111 | 0 | return st->buf->data[0]; |
112 | 0 | } |
113 | | /** |
114 | | * fu_struct_ccgx_pure_hid_fw_info_get_signature: (skip): |
115 | | **/ |
116 | | static guint16 |
117 | | fu_struct_ccgx_pure_hid_fw_info_get_signature(const FuStructCcgxPureHidFwInfo *st) |
118 | 0 | { |
119 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
120 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
121 | 0 | } |
122 | | /** |
123 | | * fu_struct_ccgx_pure_hid_fw_info_get_operating_mode: (skip): |
124 | | **/ |
125 | | FuCcgxPureHidFwMode |
126 | | fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(const FuStructCcgxPureHidFwInfo *st) |
127 | 0 | { |
128 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
129 | 0 | return st->buf->data[4]; |
130 | 0 | } |
131 | | /** |
132 | | * fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info: (skip): |
133 | | **/ |
134 | | guint8 |
135 | | fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(const FuStructCcgxPureHidFwInfo *st) |
136 | 0 | { |
137 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
138 | 0 | return st->buf->data[5]; |
139 | 0 | } |
140 | | /** |
141 | | * fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason: (skip): |
142 | | **/ |
143 | | guint8 |
144 | | fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(const FuStructCcgxPureHidFwInfo *st) |
145 | 0 | { |
146 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
147 | 0 | return st->buf->data[6]; |
148 | 0 | } |
149 | | /** |
150 | | * fu_struct_ccgx_pure_hid_fw_info_get_silicon_id: (skip): |
151 | | **/ |
152 | | guint32 |
153 | | fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(const FuStructCcgxPureHidFwInfo *st) |
154 | 0 | { |
155 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
156 | 0 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
157 | 0 | } |
158 | | /** |
159 | | * fu_struct_ccgx_pure_hid_fw_info_get_bl_version: (skip): |
160 | | **/ |
161 | | guint32 |
162 | | fu_struct_ccgx_pure_hid_fw_info_get_bl_version(const FuStructCcgxPureHidFwInfo *st) |
163 | 0 | { |
164 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
165 | 0 | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
166 | 0 | } |
167 | | /** |
168 | | * fu_struct_ccgx_pure_hid_fw_info_get_image1_version: (skip): |
169 | | **/ |
170 | | guint32 |
171 | | fu_struct_ccgx_pure_hid_fw_info_get_image1_version(const FuStructCcgxPureHidFwInfo *st) |
172 | 0 | { |
173 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
174 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
175 | 0 | } |
176 | | /** |
177 | | * fu_struct_ccgx_pure_hid_fw_info_get_image2_version: (skip): |
178 | | **/ |
179 | | guint32 |
180 | | fu_struct_ccgx_pure_hid_fw_info_get_image2_version(const FuStructCcgxPureHidFwInfo *st) |
181 | 0 | { |
182 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
183 | 0 | return fu_memread_uint32(st->buf->data + 28, G_LITTLE_ENDIAN); |
184 | 0 | } |
185 | | /** |
186 | | * fu_struct_ccgx_pure_hid_fw_info_get_image1_row: (skip): |
187 | | **/ |
188 | | guint32 |
189 | | fu_struct_ccgx_pure_hid_fw_info_get_image1_row(const FuStructCcgxPureHidFwInfo *st) |
190 | 0 | { |
191 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
192 | 0 | return fu_memread_uint32(st->buf->data + 36, G_LITTLE_ENDIAN); |
193 | 0 | } |
194 | | /** |
195 | | * fu_struct_ccgx_pure_hid_fw_info_get_image2_row: (skip): |
196 | | **/ |
197 | | guint32 |
198 | | fu_struct_ccgx_pure_hid_fw_info_get_image2_row(const FuStructCcgxPureHidFwInfo *st) |
199 | 0 | { |
200 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
201 | 0 | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
202 | 0 | } |
203 | | /** |
204 | | * fu_struct_ccgx_pure_hid_fw_info_get_device_uid: (skip): |
205 | | **/ |
206 | | const guint8 * |
207 | | fu_struct_ccgx_pure_hid_fw_info_get_device_uid(const FuStructCcgxPureHidFwInfo *st, gsize *bufsz) |
208 | 0 | { |
209 | 0 | g_return_val_if_fail(st != NULL, NULL); |
210 | 0 | if (bufsz != NULL) |
211 | 0 | *bufsz = 6; |
212 | 0 | return st->buf->data + 44; |
213 | 0 | } |
214 | | |
215 | | /* setters */ |
216 | | /** |
217 | | * fu_struct_ccgx_pure_hid_fw_info_to_string: (skip): |
218 | | **/ |
219 | | static gchar * |
220 | | fu_struct_ccgx_pure_hid_fw_info_to_string(const FuStructCcgxPureHidFwInfo *st) |
221 | 0 | { |
222 | 0 | g_autoptr(GString) str = g_string_new("FuStructCcgxPureHidFwInfo:\n"); |
223 | 0 | g_return_val_if_fail(st != NULL, NULL); |
224 | 0 | { |
225 | 0 | const gchar *tmp = fu_ccgx_pure_hid_report_id_to_string(fu_struct_ccgx_pure_hid_fw_info_get_report_id(st)); |
226 | 0 | if (tmp != NULL) { |
227 | 0 | g_string_append_printf(str, " report_id: 0x%x [%s]\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_report_id(st), tmp); |
228 | 0 | } else { |
229 | 0 | g_string_append_printf(str, " report_id: 0x%x\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_report_id(st)); |
230 | 0 | } |
231 | 0 | } |
232 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
233 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_signature(st)); |
234 | 0 | { |
235 | 0 | const gchar *tmp = fu_ccgx_pure_hid_fw_mode_to_string(fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st)); |
236 | 0 | if (tmp != NULL) { |
237 | 0 | g_string_append_printf(str, " operating_mode: 0x%x [%s]\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st), tmp); |
238 | 0 | } else { |
239 | 0 | g_string_append_printf(str, " operating_mode: 0x%x\n", (guint) fu_struct_ccgx_pure_hid_fw_info_get_operating_mode(st)); |
240 | 0 | } |
241 | 0 | } |
242 | 0 | g_string_append_printf(str, " bootloader_info: 0x%x\n", |
243 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootloader_info(st)); |
244 | 0 | g_string_append_printf(str, " bootmode_reason: 0x%x\n", |
245 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_bootmode_reason(st)); |
246 | 0 | g_string_append_printf(str, " silicon_id: 0x%x\n", |
247 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_silicon_id(st)); |
248 | 0 | g_string_append_printf(str, " bl_version: 0x%x\n", |
249 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_bl_version(st)); |
250 | 0 | g_string_append_printf(str, " image1_version: 0x%x\n", |
251 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_version(st)); |
252 | 0 | g_string_append_printf(str, " image2_version: 0x%x\n", |
253 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_version(st)); |
254 | 0 | g_string_append_printf(str, " image1_row: 0x%x\n", |
255 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_image1_row(st)); |
256 | 0 | g_string_append_printf(str, " image2_row: 0x%x\n", |
257 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_image2_row(st)); |
258 | 0 | { |
259 | 0 | gsize bufsz = 0; |
260 | 0 | const guint8 *buf = fu_struct_ccgx_pure_hid_fw_info_get_device_uid(st, &bufsz); |
261 | 0 | g_autoptr(GString) tmp = g_string_new(NULL); |
262 | 0 | for (gsize i = 0; i < bufsz; i++) |
263 | 0 | g_string_append_printf(tmp, "%02X", buf[i]); |
264 | 0 | g_string_append_printf(str, " device_uid: 0x%s\n", tmp->str); |
265 | 0 | } |
266 | 0 | if (str->len > 0) |
267 | 0 | g_string_set_size(str, str->len - 1); |
268 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
269 | 0 | } |
270 | | static gboolean |
271 | | fu_struct_ccgx_pure_hid_fw_info_validate_internal(FuStructCcgxPureHidFwInfo *st, GError **error) |
272 | 0 | { |
273 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
274 | 0 | if (fu_struct_ccgx_pure_hid_fw_info_get_report_id(st) != FU_CCGX_PURE_HID_REPORT_ID_INFO) { |
275 | 0 | g_set_error(error, |
276 | 0 | FWUPD_ERROR, |
277 | 0 | FWUPD_ERROR_INVALID_DATA, |
278 | 0 | "constant FuStructCcgxPureHidFwInfo.report_id was not valid, " |
279 | 0 | "expected 'FU_CCGX_PURE_HID_REPORT_ID_INFO' and got 0x%x '%s'", |
280 | 0 | fu_struct_ccgx_pure_hid_fw_info_get_report_id(st), |
281 | 0 | fu_ccgx_pure_hid_report_id_to_string(fu_struct_ccgx_pure_hid_fw_info_get_report_id(st))); |
282 | 0 | return FALSE; |
283 | 0 | } |
284 | 0 | if (fu_struct_ccgx_pure_hid_fw_info_get_signature(st) != 0x5943) { |
285 | 0 | g_set_error(error, |
286 | 0 | FWUPD_ERROR, |
287 | 0 | FWUPD_ERROR_INVALID_DATA, |
288 | 0 | "constant FuStructCcgxPureHidFwInfo.signature was not valid, " |
289 | 0 | "expected 0x%x and got 0x%x", |
290 | 0 | (guint) 0x5943, |
291 | 0 | (guint) fu_struct_ccgx_pure_hid_fw_info_get_signature(st)); |
292 | 0 | return FALSE; |
293 | 0 | } |
294 | 0 | return TRUE; |
295 | 0 | } |
296 | | static gboolean |
297 | | fu_struct_ccgx_pure_hid_fw_info_parse_internal(FuStructCcgxPureHidFwInfo *st, GError **error) |
298 | 0 | { |
299 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
300 | 0 | g_autofree gchar *str = fu_struct_ccgx_pure_hid_fw_info_to_string(st); |
301 | 0 | g_debug("%s", str); |
302 | 0 | } |
303 | 0 | if (!fu_struct_ccgx_pure_hid_fw_info_validate_internal(st, error)) |
304 | 0 | return FALSE; |
305 | 0 | return TRUE; |
306 | 0 | } |
307 | | |
308 | | /** |
309 | | * fu_struct_ccgx_pure_hid_fw_info_parse: (skip): |
310 | | **/ |
311 | | FuStructCcgxPureHidFwInfo * |
312 | | fu_struct_ccgx_pure_hid_fw_info_parse(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
313 | 0 | { |
314 | 0 | g_autoptr(FuStructCcgxPureHidFwInfo) st = fu_struct_ccgx_pure_hid_fw_info_new_internal(); |
315 | 0 | g_return_val_if_fail(buf != NULL, NULL); |
316 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
317 | 0 | if (!fu_memchk_read(bufsz, offset, 60, error)) { |
318 | 0 | g_prefix_error_literal(error, "invalid struct FuStructCcgxPureHidFwInfo: "); |
319 | 0 | return NULL; |
320 | 0 | } |
321 | 0 | st->buf = g_byte_array_new(); |
322 | 0 | g_byte_array_append(st->buf, buf + offset, 60); |
323 | 0 | if (!fu_struct_ccgx_pure_hid_fw_info_parse_internal(st, error)) |
324 | 0 | return NULL; |
325 | 0 | return g_steal_pointer(&st); |
326 | 0 | } |
327 | | /** |
328 | | * fu_struct_ccgx_pure_hid_command_ref: (skip): |
329 | | **/ |
330 | | FuStructCcgxPureHidCommand * |
331 | | fu_struct_ccgx_pure_hid_command_ref(FuStructCcgxPureHidCommand *st) |
332 | 0 | { |
333 | 0 | g_return_val_if_fail(st != NULL, NULL); |
334 | 0 | st->refcount++; |
335 | 0 | return st; |
336 | 0 | } |
337 | | /** |
338 | | * fu_struct_ccgx_pure_hid_command_unref: (skip): |
339 | | **/ |
340 | | void |
341 | | fu_struct_ccgx_pure_hid_command_unref(FuStructCcgxPureHidCommand *st) |
342 | 0 | { |
343 | 0 | g_return_if_fail(st != NULL); |
344 | 0 | if (st->refcount == 0) { |
345 | 0 | g_critical("FuStructCcgxPureHidCommand refcount already zero"); |
346 | 0 | return; |
347 | 0 | } |
348 | 0 | if (--st->refcount > 0) |
349 | 0 | return; |
350 | 0 | if (st->buf != NULL) |
351 | 0 | g_byte_array_unref(st->buf); |
352 | 0 | g_free(st); |
353 | 0 | } |
354 | | /** |
355 | | * fu_struct_ccgx_pure_hid_command_new_internal: (skip): |
356 | | **/ |
357 | | static FuStructCcgxPureHidCommand * |
358 | | fu_struct_ccgx_pure_hid_command_new_internal(void) |
359 | 0 | { |
360 | 0 | FuStructCcgxPureHidCommand *st = g_new0(FuStructCcgxPureHidCommand, 1); |
361 | 0 | st->refcount = 1; |
362 | 0 | return st; |
363 | 0 | } |
364 | | |
365 | | /* getters */ |
366 | | |
367 | | /* setters */ |
368 | | /** |
369 | | * fu_struct_ccgx_pure_hid_command_set_report_id: (skip): |
370 | | **/ |
371 | | static void |
372 | | fu_struct_ccgx_pure_hid_command_set_report_id(FuStructCcgxPureHidCommand *st, FuCcgxPureHidReportId value) |
373 | 0 | { |
374 | 0 | g_return_if_fail(st != NULL); |
375 | 0 | st->buf->data[0] = value; |
376 | 0 | } |
377 | | /** |
378 | | * fu_struct_ccgx_pure_hid_command_set_cmd: (skip): |
379 | | **/ |
380 | | void |
381 | | fu_struct_ccgx_pure_hid_command_set_cmd(FuStructCcgxPureHidCommand *st, guint8 value) |
382 | 0 | { |
383 | 0 | g_return_if_fail(st != NULL); |
384 | 0 | st->buf->data[1] = value; |
385 | 0 | } |
386 | | /** |
387 | | * fu_struct_ccgx_pure_hid_command_set_opt: (skip): |
388 | | **/ |
389 | | void |
390 | | fu_struct_ccgx_pure_hid_command_set_opt(FuStructCcgxPureHidCommand *st, guint8 value) |
391 | 0 | { |
392 | 0 | g_return_if_fail(st != NULL); |
393 | 0 | st->buf->data[2] = value; |
394 | 0 | } |
395 | | /** |
396 | | * fu_struct_ccgx_pure_hid_command_set_pad1: (skip): |
397 | | **/ |
398 | | void |
399 | | fu_struct_ccgx_pure_hid_command_set_pad1(FuStructCcgxPureHidCommand *st, guint8 value) |
400 | 0 | { |
401 | 0 | g_return_if_fail(st != NULL); |
402 | 0 | st->buf->data[3] = value; |
403 | 0 | } |
404 | | /** |
405 | | * fu_struct_ccgx_pure_hid_command_set_pad2: (skip): |
406 | | **/ |
407 | | void |
408 | | fu_struct_ccgx_pure_hid_command_set_pad2(FuStructCcgxPureHidCommand *st, guint32 value) |
409 | 0 | { |
410 | 0 | g_return_if_fail(st != NULL); |
411 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
412 | 0 | } |
413 | | /** |
414 | | * fu_struct_ccgx_pure_hid_command_new: (skip): |
415 | | **/ |
416 | | FuStructCcgxPureHidCommand * |
417 | | fu_struct_ccgx_pure_hid_command_new(void) |
418 | 0 | { |
419 | 0 | FuStructCcgxPureHidCommand *st = fu_struct_ccgx_pure_hid_command_new_internal(); |
420 | 0 | st->buf = g_byte_array_sized_new(8); |
421 | 0 | fu_byte_array_set_size(st->buf, 8, 0x0); |
422 | 0 | fu_struct_ccgx_pure_hid_command_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_COMMAND); |
423 | 0 | fu_struct_ccgx_pure_hid_command_set_pad1(st, 0x00); |
424 | 0 | fu_struct_ccgx_pure_hid_command_set_pad2(st, 0xCCCCCCCC); |
425 | 0 | return st; |
426 | 0 | } |
427 | | /** |
428 | | * fu_struct_ccgx_pure_hid_write_hdr_ref: (skip): |
429 | | **/ |
430 | | FuStructCcgxPureHidWriteHdr * |
431 | | fu_struct_ccgx_pure_hid_write_hdr_ref(FuStructCcgxPureHidWriteHdr *st) |
432 | 0 | { |
433 | 0 | g_return_val_if_fail(st != NULL, NULL); |
434 | 0 | st->refcount++; |
435 | 0 | return st; |
436 | 0 | } |
437 | | /** |
438 | | * fu_struct_ccgx_pure_hid_write_hdr_unref: (skip): |
439 | | **/ |
440 | | void |
441 | | fu_struct_ccgx_pure_hid_write_hdr_unref(FuStructCcgxPureHidWriteHdr *st) |
442 | 0 | { |
443 | 0 | g_return_if_fail(st != NULL); |
444 | 0 | if (st->refcount == 0) { |
445 | 0 | g_critical("FuStructCcgxPureHidWriteHdr refcount already zero"); |
446 | 0 | return; |
447 | 0 | } |
448 | 0 | if (--st->refcount > 0) |
449 | 0 | return; |
450 | 0 | if (st->buf != NULL) |
451 | 0 | g_byte_array_unref(st->buf); |
452 | 0 | g_free(st); |
453 | 0 | } |
454 | | /** |
455 | | * fu_struct_ccgx_pure_hid_write_hdr_new_internal: (skip): |
456 | | **/ |
457 | | static FuStructCcgxPureHidWriteHdr * |
458 | | fu_struct_ccgx_pure_hid_write_hdr_new_internal(void) |
459 | 0 | { |
460 | 0 | FuStructCcgxPureHidWriteHdr *st = g_new0(FuStructCcgxPureHidWriteHdr, 1); |
461 | 0 | st->refcount = 1; |
462 | 0 | return st; |
463 | 0 | } |
464 | | |
465 | | /* getters */ |
466 | | |
467 | | /* setters */ |
468 | | /** |
469 | | * fu_struct_ccgx_pure_hid_write_hdr_set_report_id: (skip): |
470 | | **/ |
471 | | static void |
472 | | fu_struct_ccgx_pure_hid_write_hdr_set_report_id(FuStructCcgxPureHidWriteHdr *st, FuCcgxPureHidReportId value) |
473 | 0 | { |
474 | 0 | g_return_if_fail(st != NULL); |
475 | 0 | st->buf->data[0] = value; |
476 | 0 | } |
477 | | /** |
478 | | * fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp: (skip): |
479 | | **/ |
480 | | void |
481 | | fu_struct_ccgx_pure_hid_write_hdr_set_pd_resp(FuStructCcgxPureHidWriteHdr *st, guint8 value) |
482 | 0 | { |
483 | 0 | g_return_if_fail(st != NULL); |
484 | 0 | st->buf->data[1] = value; |
485 | 0 | } |
486 | | /** |
487 | | * fu_struct_ccgx_pure_hid_write_hdr_set_addr: (skip): |
488 | | **/ |
489 | | void |
490 | | fu_struct_ccgx_pure_hid_write_hdr_set_addr(FuStructCcgxPureHidWriteHdr *st, guint16 value) |
491 | 0 | { |
492 | 0 | g_return_if_fail(st != NULL); |
493 | 0 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
494 | 0 | } |
495 | | /** |
496 | | * fu_struct_ccgx_pure_hid_write_hdr_set_data: (skip): |
497 | | **/ |
498 | | gboolean |
499 | | fu_struct_ccgx_pure_hid_write_hdr_set_data(FuStructCcgxPureHidWriteHdr *st, const guint8 *buf, gsize bufsz, GError **error) |
500 | 0 | { |
501 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
502 | 0 | g_return_val_if_fail(buf != NULL, FALSE); |
503 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
504 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 4, buf, bufsz, 0x0, bufsz, error); |
505 | 0 | } |
506 | | /** |
507 | | * fu_struct_ccgx_pure_hid_write_hdr_new: (skip): |
508 | | **/ |
509 | | FuStructCcgxPureHidWriteHdr * |
510 | | fu_struct_ccgx_pure_hid_write_hdr_new(void) |
511 | 0 | { |
512 | 0 | FuStructCcgxPureHidWriteHdr *st = fu_struct_ccgx_pure_hid_write_hdr_new_internal(); |
513 | 0 | st->buf = g_byte_array_sized_new(132); |
514 | 0 | fu_byte_array_set_size(st->buf, 132, 0x0); |
515 | 0 | fu_struct_ccgx_pure_hid_write_hdr_set_report_id(st, FU_CCGX_PURE_HID_REPORT_ID_WRITE); |
516 | 0 | return st; |
517 | 0 | } |