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