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