/work/fu-synaptics-mst-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-synaptics-mst-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-bytes.h" |
14 | | #include "fu-mem.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_synaptics_mst_family_to_string: |
24 | | * @val: value, e.g. %FU_SYNAPTICS_MST_FAMILY_TESLA |
25 | | * |
26 | | * Converts an enumerated value to a string. |
27 | | * |
28 | | * Returns: identifier string |
29 | | **/ |
30 | | const gchar * |
31 | | fu_synaptics_mst_family_to_string(FuSynapticsMstFamily val) |
32 | 27 | { |
33 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_TESLA) |
34 | 0 | return "tesla"; |
35 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_LEAF) |
36 | 0 | return "leaf"; |
37 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_PANAMERA) |
38 | 0 | return "panamera"; |
39 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_CAYENNE) |
40 | 0 | return "cayenne"; |
41 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_SPYDER) |
42 | 0 | return "spyder"; |
43 | 27 | if (val == FU_SYNAPTICS_MST_FAMILY_CARRERA) |
44 | 0 | return "carrera"; |
45 | 27 | return NULL; |
46 | 27 | } |
47 | | /** |
48 | | * fu_synaptics_mst_family_from_string: |
49 | | * @val: (nullable): a string, e.g. `tesla` |
50 | | * |
51 | | * Converts a string to an enumerated value. |
52 | | * |
53 | | * Returns: enumerated value |
54 | | **/ |
55 | | FuSynapticsMstFamily |
56 | | fu_synaptics_mst_family_from_string(const gchar *val) |
57 | 0 | { |
58 | 0 | if (g_strcmp0(val, "tesla") == 0) |
59 | 0 | return FU_SYNAPTICS_MST_FAMILY_TESLA; |
60 | 0 | if (g_strcmp0(val, "leaf") == 0) |
61 | 0 | return FU_SYNAPTICS_MST_FAMILY_LEAF; |
62 | 0 | if (g_strcmp0(val, "panamera") == 0) |
63 | 0 | return FU_SYNAPTICS_MST_FAMILY_PANAMERA; |
64 | 0 | if (g_strcmp0(val, "cayenne") == 0) |
65 | 0 | return FU_SYNAPTICS_MST_FAMILY_CAYENNE; |
66 | 0 | if (g_strcmp0(val, "spyder") == 0) |
67 | 0 | return FU_SYNAPTICS_MST_FAMILY_SPYDER; |
68 | 0 | if (g_strcmp0(val, "carrera") == 0) |
69 | 0 | return FU_SYNAPTICS_MST_FAMILY_CARRERA; |
70 | 0 | return FU_SYNAPTICS_MST_FAMILY_UNKNOWN; |
71 | 0 | } |
72 | | |
73 | | /** |
74 | | * fu_synaptics_mst_updc_rc_to_string: |
75 | | * @val: value, e.g. %FU_SYNAPTICS_MST_UPDC_RC_INVALID |
76 | | * |
77 | | * Converts an enumerated value to a string. |
78 | | * |
79 | | * Returns: identifier string |
80 | | **/ |
81 | | const gchar * |
82 | | fu_synaptics_mst_updc_rc_to_string(FuSynapticsMstUpdcRc val) |
83 | 0 | { |
84 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_SUCCESS) |
85 | 0 | return "success"; |
86 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_INVALID) |
87 | 0 | return "invalid"; |
88 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_UNSUPPORTED) |
89 | 0 | return "unsupported"; |
90 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_FAILED) |
91 | 0 | return "failed"; |
92 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_DISABLED) |
93 | 0 | return "disabled"; |
94 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_CONFIGURE_SIGN_FAILED) |
95 | 0 | return "configure-sign-failed"; |
96 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_FIRMWARE_SIGN_FAILED) |
97 | 0 | return "firmware-sign-failed"; |
98 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_RC_ROLLBACK_FAILED) |
99 | 0 | return "rollback-failed"; |
100 | 0 | return NULL; |
101 | 0 | } |
102 | | |
103 | | /** |
104 | | * fu_synaptics_mst_updc_cmd_to_string: |
105 | | * @val: value, e.g. %FU_SYNAPTICS_MST_UPDC_CMD_DISABLE_RC |
106 | | * |
107 | | * Converts an enumerated value to a string. |
108 | | * |
109 | | * Returns: identifier string |
110 | | **/ |
111 | | const gchar * |
112 | | fu_synaptics_mst_updc_cmd_to_string(FuSynapticsMstUpdcCmd val) |
113 | 0 | { |
114 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_ENABLE_RC) |
115 | 0 | return "enable-rc"; |
116 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_DISABLE_RC) |
117 | 0 | return "disable-rc"; |
118 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_GET_ID) |
119 | 0 | return "get-id"; |
120 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_GET_VERSION) |
121 | 0 | return "get-version"; |
122 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_FLASH_MAPPING) |
123 | 0 | return "flash-mapping"; |
124 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_ENABLE_FLASH_CHIP_ERASE) |
125 | 0 | return "enable-flash-chip-erase"; |
126 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_CAL_EEPROM_CHECKSUM) |
127 | 0 | return "cal-eeprom-checksum"; |
128 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_FLASH_ERASE) |
129 | 0 | return "flash-erase"; |
130 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_CAL_EEPROM_CHECK_CRC8) |
131 | 0 | return "cal-eeprom-check-crc8"; |
132 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_CAL_EEPROM_CHECK_CRC16) |
133 | 0 | return "cal-eeprom-check-crc16"; |
134 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_ACTIVATE_FIRMWARE) |
135 | 0 | return "activate-firmware"; |
136 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_EEPROM) |
137 | 0 | return "write-to-eeprom"; |
138 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_MEMORY) |
139 | 0 | return "write-to-memory"; |
140 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_TX_DPCD) |
141 | 0 | return "write-to-tx-dpcd"; |
142 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_TX_DPCD_TX1) |
143 | 0 | return "write-to-tx-dpcd-tx1"; |
144 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_TX_DPCD_TX2) |
145 | 0 | return "write-to-tx-dpcd-tx2"; |
146 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_WRITE_TO_TX_DPCD_TX3) |
147 | 0 | return "write-to-tx-dpcd-tx3"; |
148 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_EEPROM) |
149 | 0 | return "read-from-eeprom"; |
150 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_MEMORY) |
151 | 0 | return "read-from-memory"; |
152 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_TX_DPCD) |
153 | 0 | return "read-from-tx-dpcd"; |
154 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_TX_DPCD_TX1) |
155 | 0 | return "read-from-tx-dpcd-tx1"; |
156 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_TX_DPCD_TX2) |
157 | 0 | return "read-from-tx-dpcd-tx2"; |
158 | 0 | if (val == FU_SYNAPTICS_MST_UPDC_CMD_READ_FROM_TX_DPCD_TX3) |
159 | 0 | return "read-from-tx-dpcd-tx3"; |
160 | 0 | return NULL; |
161 | 0 | } |
162 | | |
163 | | /** |
164 | | * fu_struct_synaptics_firmware_config_ref: (skip): |
165 | | **/ |
166 | | FuStructSynapticsFirmwareConfig * |
167 | | fu_struct_synaptics_firmware_config_ref(FuStructSynapticsFirmwareConfig *st) |
168 | 0 | { |
169 | 0 | g_return_val_if_fail(st != NULL, NULL); |
170 | 0 | st->refcount++; |
171 | 0 | return st; |
172 | 0 | } |
173 | | /** |
174 | | * fu_struct_synaptics_firmware_config_unref: (skip): |
175 | | **/ |
176 | | void |
177 | | fu_struct_synaptics_firmware_config_unref(FuStructSynapticsFirmwareConfig *st) |
178 | 383 | { |
179 | 383 | g_return_if_fail(st != NULL); |
180 | 383 | if (st->refcount == 0) { |
181 | 0 | g_critical("FuStructSynapticsFirmwareConfig refcount already zero"); |
182 | 0 | return; |
183 | 0 | } |
184 | 383 | if (--st->refcount > 0) |
185 | 0 | return; |
186 | 383 | if (st->buf != NULL) |
187 | 336 | g_byte_array_unref(st->buf); |
188 | 383 | g_free(st); |
189 | 383 | } |
190 | | /** |
191 | | * fu_struct_synaptics_firmware_config_new_internal: (skip): |
192 | | **/ |
193 | | static FuStructSynapticsFirmwareConfig * |
194 | | fu_struct_synaptics_firmware_config_new_internal(void) |
195 | 383 | { |
196 | 383 | FuStructSynapticsFirmwareConfig *st = g_new0(FuStructSynapticsFirmwareConfig, 1); |
197 | 383 | st->refcount = 1; |
198 | 383 | return st; |
199 | 383 | } |
200 | | |
201 | | /* getters */ |
202 | | /** |
203 | | * fu_struct_synaptics_firmware_config_get_version: (skip): |
204 | | **/ |
205 | | guint8 |
206 | | fu_struct_synaptics_firmware_config_get_version(const FuStructSynapticsFirmwareConfig *st) |
207 | 112 | { |
208 | 112 | g_return_val_if_fail(st != NULL, 0x0); |
209 | 112 | return st->buf->data[0]; |
210 | 112 | } |
211 | | /** |
212 | | * fu_struct_synaptics_firmware_config_get_magic1: (skip): |
213 | | **/ |
214 | | guint8 |
215 | | fu_struct_synaptics_firmware_config_get_magic1(const FuStructSynapticsFirmwareConfig *st) |
216 | 332 | { |
217 | 332 | g_return_val_if_fail(st != NULL, 0x0); |
218 | 332 | return st->buf->data[2]; |
219 | 332 | } |
220 | | /** |
221 | | * fu_struct_synaptics_firmware_config_get_magic2: (skip): |
222 | | **/ |
223 | | guint8 |
224 | | fu_struct_synaptics_firmware_config_get_magic2(const FuStructSynapticsFirmwareConfig *st) |
225 | 171 | { |
226 | 171 | g_return_val_if_fail(st != NULL, 0x0); |
227 | 171 | return st->buf->data[3]; |
228 | 171 | } |
229 | | |
230 | | /* setters */ |
231 | | /** |
232 | | * fu_struct_synaptics_firmware_config_to_string: (skip): |
233 | | **/ |
234 | | static gchar * |
235 | | fu_struct_synaptics_firmware_config_to_string(const FuStructSynapticsFirmwareConfig *st) |
236 | 0 | { |
237 | 0 | g_autoptr(GString) str = g_string_new("FuStructSynapticsFirmwareConfig:\n"); |
238 | 0 | g_return_val_if_fail(st != NULL, NULL); |
239 | 0 | g_string_append_printf(str, " version: 0x%x\n", |
240 | 0 | (guint) fu_struct_synaptics_firmware_config_get_version(st)); |
241 | 0 | g_string_append_printf(str, " magic1: 0x%x\n", |
242 | 0 | (guint) fu_struct_synaptics_firmware_config_get_magic1(st)); |
243 | 0 | g_string_append_printf(str, " magic2: 0x%x\n", |
244 | 0 | (guint) fu_struct_synaptics_firmware_config_get_magic2(st)); |
245 | 0 | if (str->len > 0) |
246 | 0 | g_string_set_size(str, str->len - 1); |
247 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
248 | 0 | } |
249 | | static gboolean |
250 | | fu_struct_synaptics_firmware_config_parse_internal(FuStructSynapticsFirmwareConfig *st, GError **error) |
251 | 332 | { |
252 | 332 | if (g_log_get_debug_enabled()) { |
253 | 0 | g_autofree gchar *str = fu_struct_synaptics_firmware_config_to_string(st); |
254 | 0 | g_debug("%s", str); |
255 | 0 | } |
256 | 332 | return TRUE; |
257 | 332 | } |
258 | | /** |
259 | | * fu_struct_synaptics_firmware_config_parse_stream: (skip): |
260 | | **/ |
261 | | FuStructSynapticsFirmwareConfig * |
262 | | fu_struct_synaptics_firmware_config_parse_stream(FuInputStream *stream, gsize offset, GError **error) |
263 | 383 | { |
264 | 383 | g_autoptr(FuStructSynapticsFirmwareConfig) st = fu_struct_synaptics_firmware_config_new_internal(); |
265 | 383 | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
266 | 383 | if (st->buf == NULL) { |
267 | 47 | g_prefix_error(error, "FuStructSynapticsFirmwareConfig failed read of 0x%x: ", (guint) 4); |
268 | 47 | return NULL; |
269 | 47 | } |
270 | 336 | if (st->buf->len != 4) { |
271 | 4 | g_set_error(error, |
272 | 4 | FWUPD_ERROR, |
273 | 4 | FWUPD_ERROR_INVALID_DATA, |
274 | 4 | "FuStructSynapticsFirmwareConfig requested 0x%x and got 0x%x", |
275 | 4 | (guint) 4, |
276 | 4 | (guint) st->buf->len); |
277 | 4 | return NULL; |
278 | 4 | } |
279 | 332 | if (!fu_struct_synaptics_firmware_config_parse_internal(st, error)) |
280 | 0 | return NULL; |
281 | 332 | return g_steal_pointer(&st); |
282 | 332 | } |