/work/fu-acpi-table-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-acpi-table-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 | | * fu_struct_acpi_table_ref: (skip): |
23 | | **/ |
24 | | FuStructAcpiTable * |
25 | | fu_struct_acpi_table_ref(FuStructAcpiTable *st) |
26 | 0 | { |
27 | 0 | g_return_val_if_fail(st != NULL, NULL); |
28 | 0 | st->refcount++; |
29 | 0 | return st; |
30 | 0 | } |
31 | | /** |
32 | | * fu_struct_acpi_table_unref: (skip): |
33 | | **/ |
34 | | void |
35 | | fu_struct_acpi_table_unref(FuStructAcpiTable *st) |
36 | 0 | { |
37 | 0 | g_return_if_fail(st != NULL); |
38 | 0 | if (st->refcount == 0) { |
39 | 0 | g_critical("FuStructAcpiTable refcount already zero"); |
40 | 0 | return; |
41 | 0 | } |
42 | 0 | if (--st->refcount > 0) |
43 | 0 | return; |
44 | 0 | if (st->buf != NULL) |
45 | 0 | g_byte_array_unref(st->buf); |
46 | 0 | g_free(st); |
47 | 0 | } |
48 | | /** |
49 | | * fu_struct_acpi_table_new_internal: (skip): |
50 | | **/ |
51 | | static FuStructAcpiTable * |
52 | | fu_struct_acpi_table_new_internal(void) |
53 | 0 | { |
54 | 0 | FuStructAcpiTable *st = g_new0(FuStructAcpiTable, 1); |
55 | 0 | st->refcount = 1; |
56 | 0 | return st; |
57 | 0 | } |
58 | | |
59 | | /* getters */ |
60 | | /** |
61 | | * fu_struct_acpi_table_get_signature: (skip): |
62 | | **/ |
63 | | gchar * |
64 | | fu_struct_acpi_table_get_signature(const FuStructAcpiTable *st) |
65 | 0 | { |
66 | 0 | g_return_val_if_fail(st != NULL, NULL); |
67 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
68 | 0 | } |
69 | | /** |
70 | | * fu_struct_acpi_table_get_length: (skip): |
71 | | **/ |
72 | | guint32 |
73 | | fu_struct_acpi_table_get_length(const FuStructAcpiTable *st) |
74 | 0 | { |
75 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
76 | 0 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
77 | 0 | } |
78 | | /** |
79 | | * fu_struct_acpi_table_get_revision: (skip): |
80 | | **/ |
81 | | guint8 |
82 | | fu_struct_acpi_table_get_revision(const FuStructAcpiTable *st) |
83 | 0 | { |
84 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
85 | 0 | return st->buf->data[8]; |
86 | 0 | } |
87 | | /** |
88 | | * fu_struct_acpi_table_get_checksum: (skip): |
89 | | **/ |
90 | | guint8 |
91 | | fu_struct_acpi_table_get_checksum(const FuStructAcpiTable *st) |
92 | 0 | { |
93 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
94 | 0 | return st->buf->data[9]; |
95 | 0 | } |
96 | | /** |
97 | | * fu_struct_acpi_table_get_oem_id: (skip): |
98 | | **/ |
99 | | gchar * |
100 | | fu_struct_acpi_table_get_oem_id(const FuStructAcpiTable *st) |
101 | 0 | { |
102 | 0 | g_return_val_if_fail(st != NULL, NULL); |
103 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 10, 6, NULL); |
104 | 0 | } |
105 | | /** |
106 | | * fu_struct_acpi_table_get_oem_table_id: (skip): |
107 | | **/ |
108 | | gchar * |
109 | | fu_struct_acpi_table_get_oem_table_id(const FuStructAcpiTable *st) |
110 | 0 | { |
111 | 0 | g_return_val_if_fail(st != NULL, NULL); |
112 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 16, 8, NULL); |
113 | 0 | } |
114 | | /** |
115 | | * fu_struct_acpi_table_get_oem_revision: (skip): |
116 | | **/ |
117 | | guint32 |
118 | | fu_struct_acpi_table_get_oem_revision(const FuStructAcpiTable *st) |
119 | 0 | { |
120 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
121 | 0 | return fu_memread_uint32(st->buf->data + 24, G_BIG_ENDIAN); |
122 | 0 | } |
123 | | |
124 | | /* setters */ |
125 | | /** |
126 | | * fu_struct_acpi_table_set_signature: (skip): |
127 | | **/ |
128 | | gboolean |
129 | | fu_struct_acpi_table_set_signature(FuStructAcpiTable *st, const gchar *value, GError **error) |
130 | 0 | { |
131 | 0 | gsize len; |
132 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
133 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
134 | 0 | if (value == NULL) { |
135 | 0 | memset(st->buf->data + 0, 0x0, 4); |
136 | 0 | return TRUE; |
137 | 0 | } |
138 | 0 | len = strlen(value); |
139 | 0 | if (len > 4) { |
140 | 0 | g_set_error(error, |
141 | 0 | FWUPD_ERROR, |
142 | 0 | FWUPD_ERROR_INVALID_DATA, |
143 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.signature (0x%x bytes)", |
144 | 0 | value, (guint) len, (guint) 4); |
145 | 0 | return FALSE; |
146 | 0 | } |
147 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
148 | 0 | } |
149 | | /** |
150 | | * fu_struct_acpi_table_set_length: (skip): |
151 | | **/ |
152 | | void |
153 | | fu_struct_acpi_table_set_length(FuStructAcpiTable *st, guint32 value) |
154 | 0 | { |
155 | 0 | g_return_if_fail(st != NULL); |
156 | 0 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
157 | 0 | } |
158 | | /** |
159 | | * fu_struct_acpi_table_set_revision: (skip): |
160 | | **/ |
161 | | void |
162 | | fu_struct_acpi_table_set_revision(FuStructAcpiTable *st, guint8 value) |
163 | 0 | { |
164 | 0 | g_return_if_fail(st != NULL); |
165 | 0 | st->buf->data[8] = value; |
166 | 0 | } |
167 | | /** |
168 | | * fu_struct_acpi_table_set_checksum: (skip): |
169 | | **/ |
170 | | void |
171 | | fu_struct_acpi_table_set_checksum(FuStructAcpiTable *st, guint8 value) |
172 | 0 | { |
173 | 0 | g_return_if_fail(st != NULL); |
174 | 0 | st->buf->data[9] = value; |
175 | 0 | } |
176 | | /** |
177 | | * fu_struct_acpi_table_set_oem_id: (skip): |
178 | | **/ |
179 | | gboolean |
180 | | fu_struct_acpi_table_set_oem_id(FuStructAcpiTable *st, const gchar *value, GError **error) |
181 | 0 | { |
182 | 0 | gsize len; |
183 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
184 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
185 | 0 | if (value == NULL) { |
186 | 0 | memset(st->buf->data + 10, 0x0, 6); |
187 | 0 | return TRUE; |
188 | 0 | } |
189 | 0 | len = strlen(value); |
190 | 0 | if (len > 6) { |
191 | 0 | g_set_error(error, |
192 | 0 | FWUPD_ERROR, |
193 | 0 | FWUPD_ERROR_INVALID_DATA, |
194 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_id (0x%x bytes)", |
195 | 0 | value, (guint) len, (guint) 6); |
196 | 0 | return FALSE; |
197 | 0 | } |
198 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 10, (const guint8 *)value, len, 0x0, len, error); |
199 | 0 | } |
200 | | /** |
201 | | * fu_struct_acpi_table_set_oem_table_id: (skip): |
202 | | **/ |
203 | | gboolean |
204 | | fu_struct_acpi_table_set_oem_table_id(FuStructAcpiTable *st, const gchar *value, GError **error) |
205 | 0 | { |
206 | 0 | gsize len; |
207 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
208 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
209 | 0 | if (value == NULL) { |
210 | 0 | memset(st->buf->data + 16, 0x0, 8); |
211 | 0 | return TRUE; |
212 | 0 | } |
213 | 0 | len = strlen(value); |
214 | 0 | if (len > 8) { |
215 | 0 | g_set_error(error, |
216 | 0 | FWUPD_ERROR, |
217 | 0 | FWUPD_ERROR_INVALID_DATA, |
218 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructAcpiTable.oem_table_id (0x%x bytes)", |
219 | 0 | value, (guint) len, (guint) 8); |
220 | 0 | return FALSE; |
221 | 0 | } |
222 | 0 | return fu_memcpy_safe(st->buf->data, st->buf->len, 16, (const guint8 *)value, len, 0x0, len, error); |
223 | 0 | } |
224 | | /** |
225 | | * fu_struct_acpi_table_set_oem_revision: (skip): |
226 | | **/ |
227 | | void |
228 | | fu_struct_acpi_table_set_oem_revision(FuStructAcpiTable *st, guint32 value) |
229 | 0 | { |
230 | 0 | g_return_if_fail(st != NULL); |
231 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_BIG_ENDIAN); |
232 | 0 | } |
233 | | /** |
234 | | * fu_struct_acpi_table_new: (skip): |
235 | | **/ |
236 | | FuStructAcpiTable * |
237 | | fu_struct_acpi_table_new(void) |
238 | 0 | { |
239 | 0 | FuStructAcpiTable *st = fu_struct_acpi_table_new_internal(); |
240 | 0 | st->buf = g_byte_array_sized_new(36); |
241 | 0 | fu_byte_array_set_size(st->buf, 36, 0x0); |
242 | 0 | return st; |
243 | 0 | } |
244 | | /** |
245 | | * fu_struct_acpi_table_to_string: (skip): |
246 | | **/ |
247 | | static gchar * |
248 | | fu_struct_acpi_table_to_string(const FuStructAcpiTable *st) |
249 | 0 | { |
250 | 0 | g_autoptr(GString) str = g_string_new("FuStructAcpiTable:\n"); |
251 | 0 | g_return_val_if_fail(st != NULL, NULL); |
252 | 0 | { |
253 | 0 | g_autofree gchar *tmp = fu_struct_acpi_table_get_signature(st); |
254 | 0 | if (tmp != NULL) |
255 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
256 | 0 | } |
257 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
258 | 0 | (guint) fu_struct_acpi_table_get_length(st)); |
259 | 0 | g_string_append_printf(str, " revision: 0x%x\n", |
260 | 0 | (guint) fu_struct_acpi_table_get_revision(st)); |
261 | 0 | g_string_append_printf(str, " checksum: 0x%x\n", |
262 | 0 | (guint) fu_struct_acpi_table_get_checksum(st)); |
263 | 0 | { |
264 | 0 | g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_id(st); |
265 | 0 | if (tmp != NULL) |
266 | 0 | g_string_append_printf(str, " oem_id: %s\n", tmp); |
267 | 0 | } |
268 | 0 | { |
269 | 0 | g_autofree gchar *tmp = fu_struct_acpi_table_get_oem_table_id(st); |
270 | 0 | if (tmp != NULL) |
271 | 0 | g_string_append_printf(str, " oem_table_id: %s\n", tmp); |
272 | 0 | } |
273 | 0 | g_string_append_printf(str, " oem_revision: 0x%x\n", |
274 | 0 | (guint) fu_struct_acpi_table_get_oem_revision(st)); |
275 | 0 | if (str->len > 0) |
276 | 0 | g_string_set_size(str, str->len - 1); |
277 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
278 | 0 | } |
279 | | static gboolean |
280 | | fu_struct_acpi_table_validate_internal(FuStructAcpiTable *st, GError **error) |
281 | 0 | { |
282 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
283 | 0 | return TRUE; |
284 | 0 | } |
285 | | static gboolean |
286 | | fu_struct_acpi_table_parse_internal(FuStructAcpiTable *st, GError **error) |
287 | 0 | { |
288 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
289 | 0 | g_autofree gchar *str = fu_struct_acpi_table_to_string(st); |
290 | 0 | g_debug("%s", str); |
291 | 0 | } |
292 | 0 | if (!fu_struct_acpi_table_validate_internal(st, error)) |
293 | 0 | return FALSE; |
294 | 0 | return TRUE; |
295 | 0 | } |
296 | | /** |
297 | | * fu_struct_acpi_table_parse_stream: (skip): |
298 | | **/ |
299 | | FuStructAcpiTable * |
300 | | fu_struct_acpi_table_parse_stream(GInputStream *stream, gsize offset, GError **error) |
301 | 0 | { |
302 | 0 | g_autoptr(FuStructAcpiTable) st = fu_struct_acpi_table_new_internal(); |
303 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 36, NULL, error); |
304 | 0 | if (st->buf == NULL) { |
305 | 0 | g_prefix_error(error, "FuStructAcpiTable failed read of 0x%x: ", (guint) 36); |
306 | 0 | return NULL; |
307 | 0 | } |
308 | 0 | if (st->buf->len != 36) { |
309 | 0 | g_set_error(error, |
310 | 0 | FWUPD_ERROR, |
311 | 0 | FWUPD_ERROR_INVALID_DATA, |
312 | 0 | "FuStructAcpiTable requested 0x%x and got 0x%x", |
313 | 0 | (guint) 36, |
314 | 0 | (guint) st->buf->len); |
315 | 0 | return NULL; |
316 | 0 | } |
317 | 0 | if (!fu_struct_acpi_table_parse_internal(st, error)) |
318 | 0 | return NULL; |
319 | 0 | return g_steal_pointer(&st); |
320 | 0 | } |