Coverage Report

Created: 2026-06-15 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-edid-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-edid-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_edid_descriptor_tag_to_string:
24
 * @val: value, e.g. %FU_EDID_DESCRIPTOR_TAG_ALPHANUMERIC_DATA_STRING
25
 *
26
 * Converts an enumerated value to a string.
27
 *
28
 * Returns: identifier string
29
 **/
30
static const gchar *
31
fu_edid_descriptor_tag_to_string(FuEdidDescriptorTag val)
32
0
{
33
0
    if (val == FU_EDID_DESCRIPTOR_TAG_DISPLAY_PRODUCT_SERIAL_NUMBER)
34
0
        return "display-product-serial-number";
35
0
    if (val == FU_EDID_DESCRIPTOR_TAG_ALPHANUMERIC_DATA_STRING)
36
0
        return "alphanumeric-data-string";
37
0
    if (val == FU_EDID_DESCRIPTOR_TAG_DISPLAY_RANGE_LIMITS)
38
0
        return "display-range-limits";
39
0
    if (val == FU_EDID_DESCRIPTOR_TAG_DISPLAY_PRODUCT_NAME)
40
0
        return "display-product-name";
41
0
    if (val == FU_EDID_DESCRIPTOR_TAG_COLOR_POINT_DATA)
42
0
        return "color-point-data";
43
0
    if (val == FU_EDID_DESCRIPTOR_TAG_STANDARD_TIMING_IDENTIFICATIONS)
44
0
        return "standard-timing-identifications";
45
0
    if (val == FU_EDID_DESCRIPTOR_TAG_DISPLAY_COLOR_MANAGEMENT_DATA)
46
0
        return "display-color-management-data";
47
0
    if (val == FU_EDID_DESCRIPTOR_TAG_CVT_TIMING_CODES)
48
0
        return "cvt-timing-codes";
49
0
    if (val == FU_EDID_DESCRIPTOR_TAG_ESTABLISHED_TIMINGS)
50
0
        return "established-timings";
51
0
    if (val == FU_EDID_DESCRIPTOR_TAG_DUMMY_DESCRIPTOR)
52
0
        return "dummy-descriptor";
53
0
    return NULL;
54
0
}
55
/**
56
 * fu_struct_edid_descriptor_ref: (skip):
57
 **/
58
FuStructEdidDescriptor *
59
fu_struct_edid_descriptor_ref(FuStructEdidDescriptor *st)
60
0
{
61
0
    g_return_val_if_fail(st != NULL, NULL);
62
0
    st->refcount++;
63
0
    return st;
64
0
}
65
/**
66
 * fu_struct_edid_descriptor_unref: (skip):
67
 **/
68
void
69
fu_struct_edid_descriptor_unref(FuStructEdidDescriptor *st)
70
1.03k
{
71
1.03k
    g_return_if_fail(st != NULL);
72
1.03k
    if (st->refcount == 0) {
73
0
        g_critical("FuStructEdidDescriptor refcount already zero");
74
0
        return;
75
0
    }
76
1.03k
    if (--st->refcount > 0)
77
0
        return;
78
1.03k
    if (st->buf != NULL)
79
1.03k
        g_byte_array_unref(st->buf);
80
1.03k
    g_free(st);
81
1.03k
}
82
/**
83
 * fu_struct_edid_descriptor_new_internal: (skip):
84
 **/
85
static FuStructEdidDescriptor *
86
fu_struct_edid_descriptor_new_internal(void)
87
1.03k
{
88
1.03k
    FuStructEdidDescriptor *st = g_new0(FuStructEdidDescriptor, 1);
89
1.03k
    st->refcount = 1;
90
1.03k
    return st;
91
1.03k
}
92
93
/* getters */
94
/**
95
 * fu_struct_edid_descriptor_get_kind: (skip):
96
 **/
97
guint16
98
fu_struct_edid_descriptor_get_kind(const FuStructEdidDescriptor *st)
99
824
{
100
824
    g_return_val_if_fail(st != NULL, 0x0);
101
824
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
102
824
}
103
/**
104
 * fu_struct_edid_descriptor_get_subkind: (skip):
105
 **/
106
guint8
107
fu_struct_edid_descriptor_get_subkind(const FuStructEdidDescriptor *st)
108
362
{
109
362
    g_return_val_if_fail(st != NULL, 0x0);
110
362
    return st->buf->data[2];
111
362
}
112
/**
113
 * fu_struct_edid_descriptor_get_tag: (skip):
114
 **/
115
FuEdidDescriptorTag
116
fu_struct_edid_descriptor_get_tag(const FuStructEdidDescriptor *st)
117
758
{
118
758
    g_return_val_if_fail(st != NULL, 0x0);
119
758
    return st->buf->data[3];
120
758
}
121
/**
122
 * fu_struct_edid_descriptor_get_data: (skip):
123
 **/
124
const guint8 *
125
fu_struct_edid_descriptor_get_data(const FuStructEdidDescriptor *st, gsize *bufsz)
126
312
{
127
312
    g_return_val_if_fail(st != NULL, NULL);
128
312
    if (bufsz != NULL)
129
312
        *bufsz = 13;
130
312
    return st->buf->data + 5;
131
312
}
132
133
/* setters */
134
/**
135
 * fu_struct_edid_descriptor_set_kind: (skip):
136
 **/
137
void
138
fu_struct_edid_descriptor_set_kind(FuStructEdidDescriptor *st, guint16 value)
139
0
{
140
0
    g_return_if_fail(st != NULL);
141
0
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
142
0
}
143
/**
144
 * fu_struct_edid_descriptor_set_subkind: (skip):
145
 **/
146
void
147
fu_struct_edid_descriptor_set_subkind(FuStructEdidDescriptor *st, guint8 value)
148
0
{
149
0
    g_return_if_fail(st != NULL);
150
0
    st->buf->data[2] = value;
151
0
}
152
/**
153
 * fu_struct_edid_descriptor_set_tag: (skip):
154
 **/
155
void
156
fu_struct_edid_descriptor_set_tag(FuStructEdidDescriptor *st, FuEdidDescriptorTag value)
157
209
{
158
209
    g_return_if_fail(st != NULL);
159
209
    st->buf->data[3] = value;
160
209
}
161
/**
162
 * fu_struct_edid_descriptor_set_data: (skip):
163
 **/
164
gboolean
165
fu_struct_edid_descriptor_set_data(FuStructEdidDescriptor *st, const guint8 *buf, gsize bufsz, GError **error)
166
209
{
167
209
    g_return_val_if_fail(st != NULL, FALSE);
168
209
    g_return_val_if_fail(buf != NULL, FALSE);
169
209
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
170
209
    return fu_memcpy_safe(st->buf->data, st->buf->len, 5, buf, bufsz, 0x0, bufsz, error);
171
209
}
172
/**
173
 * fu_struct_edid_descriptor_new: (skip):
174
 **/
175
FuStructEdidDescriptor *
176
fu_struct_edid_descriptor_new(void)
177
209
{
178
209
    FuStructEdidDescriptor *st = fu_struct_edid_descriptor_new_internal();
179
209
    st->buf = g_byte_array_sized_new(18);
180
209
    fu_byte_array_set_size(st->buf, 18, 0x0);
181
209
    return st;
182
209
}
183
/**
184
 * fu_struct_edid_descriptor_to_string: (skip):
185
 **/
186
static gchar *
187
fu_struct_edid_descriptor_to_string(const FuStructEdidDescriptor *st)
188
0
{
189
0
    g_autoptr(GString) str = g_string_new("FuStructEdidDescriptor:\n");
190
0
    g_return_val_if_fail(st != NULL, NULL);
191
0
    g_string_append_printf(str, "  kind: 0x%x\n",
192
0
                           (guint) fu_struct_edid_descriptor_get_kind(st));
193
0
    g_string_append_printf(str, "  subkind: 0x%x\n",
194
0
                           (guint) fu_struct_edid_descriptor_get_subkind(st));
195
0
    {
196
0
        const gchar *tmp = fu_edid_descriptor_tag_to_string(fu_struct_edid_descriptor_get_tag(st));
197
0
        if (tmp != NULL) {
198
0
            g_string_append_printf(str, "  tag: 0x%x [%s]\n", (guint) fu_struct_edid_descriptor_get_tag(st), tmp);
199
0
        } else {
200
0
            g_string_append_printf(str, "  tag: 0x%x\n", (guint) fu_struct_edid_descriptor_get_tag(st));
201
0
        }
202
0
    }
203
0
    {
204
0
        gsize bufsz = 0;
205
0
        const guint8 *buf = fu_struct_edid_descriptor_get_data(st, &bufsz);
206
0
        g_autoptr(GString) tmp = g_string_new(NULL);
207
0
        for (gsize i = 0; i < bufsz; i++)
208
0
            g_string_append_printf(tmp, "%02X", buf[i]);
209
0
        g_string_append_printf(str, "  data: 0x%s\n", tmp->str);
210
0
    }
211
0
    if (str->len > 0)
212
0
        g_string_set_size(str, str->len - 1);
213
0
    return g_string_free(g_steal_pointer(&str), FALSE);
214
0
}
215
static gboolean
216
fu_struct_edid_descriptor_parse_internal(FuStructEdidDescriptor *st, GError **error)
217
824
{
218
824
    if (g_log_get_debug_enabled()) {
219
0
        g_autofree gchar *str = fu_struct_edid_descriptor_to_string(st);
220
0
        g_debug("%s", str);
221
0
    }
222
824
    return TRUE;
223
824
}
224
/**
225
 * fu_struct_edid_descriptor_parse_stream: (skip):
226
 **/
227
FuStructEdidDescriptor *
228
fu_struct_edid_descriptor_parse_stream(GInputStream *stream, gsize offset, GError **error)
229
824
{
230
824
    g_autoptr(FuStructEdidDescriptor) st = fu_struct_edid_descriptor_new_internal();
231
824
    st->buf = fu_input_stream_read_byte_array(stream, offset, 18, NULL, error);
232
824
    if (st->buf == NULL) {
233
0
        g_prefix_error(error, "FuStructEdidDescriptor failed read of 0x%x: ", (guint) 18);
234
0
        return NULL;
235
0
    }
236
824
    if (st->buf->len != 18) {
237
0
        g_set_error(error,
238
0
                    FWUPD_ERROR,
239
0
                    FWUPD_ERROR_INVALID_DATA,
240
0
                    "FuStructEdidDescriptor requested 0x%x and got 0x%x",
241
0
                    (guint) 18,
242
0
                    (guint) st->buf->len);
243
0
        return NULL;
244
0
    }
245
824
    if (!fu_struct_edid_descriptor_parse_internal(st, error))
246
0
        return NULL;
247
824
    return g_steal_pointer(&st);
248
824
}
249
/**
250
 * fu_struct_edid_ref: (skip):
251
 **/
252
FuStructEdid *
253
fu_struct_edid_ref(FuStructEdid *st)
254
0
{
255
0
    g_return_val_if_fail(st != NULL, NULL);
256
0
    st->refcount++;
257
0
    return st;
258
0
}
259
/**
260
 * fu_struct_edid_unref: (skip):
261
 **/
262
void
263
fu_struct_edid_unref(FuStructEdid *st)
264
594
{
265
594
    g_return_if_fail(st != NULL);
266
594
    if (st->refcount == 0) {
267
0
        g_critical("FuStructEdid refcount already zero");
268
0
        return;
269
0
    }
270
594
    if (--st->refcount > 0)
271
0
        return;
272
594
    if (st->buf != NULL)
273
388
        g_byte_array_unref(st->buf);
274
594
    g_free(st);
275
594
}
276
/**
277
 * fu_struct_edid_new_internal: (skip):
278
 **/
279
static FuStructEdid *
280
fu_struct_edid_new_internal(void)
281
594
{
282
594
    FuStructEdid *st = g_new0(FuStructEdid, 1);
283
594
    st->refcount = 1;
284
594
    return st;
285
594
}
286
287
/* getters */
288
/**
289
 * fu_struct_edid_get_header: (skip):
290
 **/
291
static const guint8 *
292
fu_struct_edid_get_header(const FuStructEdid *st, gsize *bufsz)
293
0
{
294
0
    g_return_val_if_fail(st != NULL, NULL);
295
0
    if (bufsz != NULL)
296
0
        *bufsz = 8;
297
0
    return st->buf->data + 0;
298
0
}
299
/**
300
 * fu_struct_edid_get_manufacturer_name: (skip):
301
 **/
302
const guint8 *
303
fu_struct_edid_get_manufacturer_name(const FuStructEdid *st, gsize *bufsz)
304
206
{
305
206
    g_return_val_if_fail(st != NULL, NULL);
306
206
    if (bufsz != NULL)
307
0
        *bufsz = 2;
308
206
    return st->buf->data + 8;
309
206
}
310
/**
311
 * fu_struct_edid_get_product_code: (skip):
312
 **/
313
guint16
314
fu_struct_edid_get_product_code(const FuStructEdid *st)
315
206
{
316
206
    g_return_val_if_fail(st != NULL, 0x0);
317
206
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
318
206
}
319
/**
320
 * fu_struct_edid_get_serial_number: (skip):
321
 **/
322
guint32
323
fu_struct_edid_get_serial_number(const FuStructEdid *st)
324
401
{
325
401
    g_return_val_if_fail(st != NULL, 0x0);
326
401
    return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN);
327
401
}
328
/**
329
 * fu_struct_edid_get_week_of_manufacture: (skip):
330
 **/
331
guint8
332
fu_struct_edid_get_week_of_manufacture(const FuStructEdid *st)
333
0
{
334
0
    g_return_val_if_fail(st != NULL, 0x0);
335
0
    return st->buf->data[16];
336
0
}
337
/**
338
 * fu_struct_edid_get_year_of_manufacture: (skip):
339
 **/
340
guint8
341
fu_struct_edid_get_year_of_manufacture(const FuStructEdid *st)
342
0
{
343
0
    g_return_val_if_fail(st != NULL, 0x0);
344
0
    return st->buf->data[17];
345
0
}
346
/**
347
 * fu_struct_edid_get_edid_version_number: (skip):
348
 **/
349
static guint8
350
fu_struct_edid_get_edid_version_number(const FuStructEdid *st)
351
214
{
352
214
    g_return_val_if_fail(st != NULL, 0x0);
353
214
    return st->buf->data[18];
354
214
}
355
/**
356
 * fu_struct_edid_get_revision_number: (skip):
357
 **/
358
guint8
359
fu_struct_edid_get_revision_number(const FuStructEdid *st)
360
0
{
361
0
    g_return_val_if_fail(st != NULL, 0x0);
362
0
    return st->buf->data[19];
363
0
}
364
/**
365
 * fu_struct_edid_get_data_blocks: (skip):
366
 **/
367
const guint8 *
368
fu_struct_edid_get_data_blocks(const FuStructEdid *st, gsize *bufsz)
369
0
{
370
0
    g_return_val_if_fail(st != NULL, NULL);
371
0
    if (bufsz != NULL)
372
0
        *bufsz = 72;
373
0
    return st->buf->data + 54;
374
0
}
375
/**
376
 * fu_struct_edid_get_extension_block_count: (skip):
377
 **/
378
guint8
379
fu_struct_edid_get_extension_block_count(const FuStructEdid *st)
380
0
{
381
0
    g_return_val_if_fail(st != NULL, 0x0);
382
0
    return st->buf->data[126];
383
0
}
384
/**
385
 * fu_struct_edid_get_checksum: (skip):
386
 **/
387
guint8
388
fu_struct_edid_get_checksum(const FuStructEdid *st)
389
0
{
390
0
    g_return_val_if_fail(st != NULL, 0x0);
391
0
    return st->buf->data[127];
392
0
}
393
394
/* setters */
395
/**
396
 * fu_struct_edid_set_manufacturer_name: (skip):
397
 **/
398
gboolean
399
fu_struct_edid_set_manufacturer_name(FuStructEdid *st, const guint8 *buf, gsize bufsz, GError **error)
400
0
{
401
0
    g_return_val_if_fail(st != NULL, FALSE);
402
0
    g_return_val_if_fail(buf != NULL, FALSE);
403
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
404
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 8, buf, bufsz, 0x0, bufsz, error);
405
0
}
406
/**
407
 * fu_struct_edid_set_product_code: (skip):
408
 **/
409
void
410
fu_struct_edid_set_product_code(FuStructEdid *st, guint16 value)
411
206
{
412
206
    g_return_if_fail(st != NULL);
413
206
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
414
206
}
415
/**
416
 * fu_struct_edid_set_serial_number: (skip):
417
 **/
418
void
419
fu_struct_edid_set_serial_number(FuStructEdid *st, guint32 value)
420
80
{
421
80
    g_return_if_fail(st != NULL);
422
80
    fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN);
423
80
}
424
/**
425
 * fu_struct_edid_set_week_of_manufacture: (skip):
426
 **/
427
void
428
fu_struct_edid_set_week_of_manufacture(FuStructEdid *st, guint8 value)
429
0
{
430
0
    g_return_if_fail(st != NULL);
431
0
    st->buf->data[16] = value;
432
0
}
433
/**
434
 * fu_struct_edid_set_year_of_manufacture: (skip):
435
 **/
436
void
437
fu_struct_edid_set_year_of_manufacture(FuStructEdid *st, guint8 value)
438
0
{
439
0
    g_return_if_fail(st != NULL);
440
0
    st->buf->data[17] = value;
441
0
}
442
/**
443
 * fu_struct_edid_set_edid_version_number: (skip):
444
 **/
445
static void
446
fu_struct_edid_set_edid_version_number(FuStructEdid *st, guint8 value)
447
206
{
448
206
    g_return_if_fail(st != NULL);
449
206
    st->buf->data[18] = value;
450
206
}
451
/**
452
 * fu_struct_edid_set_revision_number: (skip):
453
 **/
454
void
455
fu_struct_edid_set_revision_number(FuStructEdid *st, guint8 value)
456
206
{
457
206
    g_return_if_fail(st != NULL);
458
206
    st->buf->data[19] = value;
459
206
}
460
/**
461
 * fu_struct_edid_set_data_blocks: (skip):
462
 **/
463
gboolean
464
fu_struct_edid_set_data_blocks(FuStructEdid *st, const guint8 *buf, gsize bufsz, GError **error)
465
0
{
466
0
    g_return_val_if_fail(st != NULL, FALSE);
467
0
    g_return_val_if_fail(buf != NULL, FALSE);
468
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
469
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 54, buf, bufsz, 0x0, bufsz, error);
470
0
}
471
/**
472
 * fu_struct_edid_set_extension_block_count: (skip):
473
 **/
474
void
475
fu_struct_edid_set_extension_block_count(FuStructEdid *st, guint8 value)
476
0
{
477
0
    g_return_if_fail(st != NULL);
478
0
    st->buf->data[126] = value;
479
0
}
480
/**
481
 * fu_struct_edid_set_checksum: (skip):
482
 **/
483
void
484
fu_struct_edid_set_checksum(FuStructEdid *st, guint8 value)
485
0
{
486
0
    g_return_if_fail(st != NULL);
487
0
    st->buf->data[127] = value;
488
0
}
489
/**
490
 * fu_struct_edid_new: (skip):
491
 **/
492
FuStructEdid *
493
fu_struct_edid_new(void)
494
206
{
495
206
    FuStructEdid *st = fu_struct_edid_new_internal();
496
206
    st->buf = g_byte_array_sized_new(128);
497
206
    fu_byte_array_set_size(st->buf, 128, 0x0);
498
206
    memcpy(st->buf->data + 0x0, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8); /* nocheck:blocked */
499
206
    fu_struct_edid_set_edid_version_number(st, 0x1);
500
206
    fu_struct_edid_set_revision_number(st, 0x3);
501
206
    return st;
502
206
}
503
/**
504
 * fu_struct_edid_to_string: (skip):
505
 **/
506
static gchar *
507
fu_struct_edid_to_string(const FuStructEdid *st)
508
0
{
509
0
    g_autoptr(GString) str = g_string_new("FuStructEdid:\n");
510
0
    g_return_val_if_fail(st != NULL, NULL);
511
0
    {
512
0
        gsize bufsz = 0;
513
0
        const guint8 *buf = fu_struct_edid_get_header(st, &bufsz);
514
0
        g_autoptr(GString) tmp = g_string_new(NULL);
515
0
        for (gsize i = 0; i < bufsz; i++)
516
0
            g_string_append_printf(tmp, "%02X", buf[i]);
517
0
        g_string_append_printf(str, "  header: 0x%s\n", tmp->str);
518
0
    }
519
0
    {
520
0
        gsize bufsz = 0;
521
0
        const guint8 *buf = fu_struct_edid_get_manufacturer_name(st, &bufsz);
522
0
        g_autoptr(GString) tmp = g_string_new(NULL);
523
0
        for (gsize i = 0; i < bufsz; i++)
524
0
            g_string_append_printf(tmp, "%02X", buf[i]);
525
0
        g_string_append_printf(str, "  manufacturer_name: 0x%s\n", tmp->str);
526
0
    }
527
0
    g_string_append_printf(str, "  product_code: 0x%x\n",
528
0
                           (guint) fu_struct_edid_get_product_code(st));
529
0
    g_string_append_printf(str, "  serial_number: 0x%x\n",
530
0
                           (guint) fu_struct_edid_get_serial_number(st));
531
0
    g_string_append_printf(str, "  week_of_manufacture: 0x%x\n",
532
0
                           (guint) fu_struct_edid_get_week_of_manufacture(st));
533
0
    g_string_append_printf(str, "  year_of_manufacture: 0x%x\n",
534
0
                           (guint) fu_struct_edid_get_year_of_manufacture(st));
535
0
    g_string_append_printf(str, "  edid_version_number: 0x%x\n",
536
0
                           (guint) fu_struct_edid_get_edid_version_number(st));
537
0
    g_string_append_printf(str, "  revision_number: 0x%x\n",
538
0
                           (guint) fu_struct_edid_get_revision_number(st));
539
0
    {
540
0
        gsize bufsz = 0;
541
0
        const guint8 *buf = fu_struct_edid_get_data_blocks(st, &bufsz);
542
0
        g_autoptr(GString) tmp = g_string_new(NULL);
543
0
        for (gsize i = 0; i < bufsz; i++)
544
0
            g_string_append_printf(tmp, "%02X", buf[i]);
545
0
        g_string_append_printf(str, "  data_blocks: 0x%s\n", tmp->str);
546
0
    }
547
0
    g_string_append_printf(str, "  extension_block_count: 0x%x\n",
548
0
                           (guint) fu_struct_edid_get_extension_block_count(st));
549
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
550
0
                           (guint) fu_struct_edid_get_checksum(st));
551
0
    if (str->len > 0)
552
0
        g_string_set_size(str, str->len - 1);
553
0
    return g_string_free(g_steal_pointer(&str), FALSE);
554
0
}
555
static gboolean
556
fu_struct_edid_validate_internal(FuStructEdid *st, GError **error)
557
364
{
558
364
    g_return_val_if_fail(st != NULL, FALSE);
559
364
    if (memcmp(st->buf->data + 0, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8) != 0) {
560
150
        g_set_error_literal(error,
561
150
                            FWUPD_ERROR,
562
150
                            FWUPD_ERROR_INVALID_DATA,
563
150
                            "constant FuStructEdid.header was not valid");
564
150
        return FALSE;
565
150
    }
566
214
    if (fu_struct_edid_get_edid_version_number(st) != 0x1) {
567
8
        g_set_error_literal(error,
568
8
                            FWUPD_ERROR,
569
8
                            FWUPD_ERROR_INVALID_DATA,
570
8
                            "constant FuStructEdid.edid_version_number was not valid");
571
8
        return FALSE;
572
8
    }
573
206
    return TRUE;
574
214
}
575
static gboolean
576
fu_struct_edid_parse_internal(FuStructEdid *st, GError **error)
577
364
{
578
364
    if (g_log_get_debug_enabled()) {
579
0
        g_autofree gchar *str = fu_struct_edid_to_string(st);
580
0
        g_debug("%s", str);
581
0
    }
582
364
    if (!fu_struct_edid_validate_internal(st, error))
583
158
        return FALSE;
584
206
    return TRUE;
585
364
}
586
/**
587
 * fu_struct_edid_parse_stream: (skip):
588
 **/
589
FuStructEdid *
590
fu_struct_edid_parse_stream(GInputStream *stream, gsize offset, GError **error)
591
388
{
592
388
    g_autoptr(FuStructEdid) st = fu_struct_edid_new_internal();
593
388
    st->buf = fu_input_stream_read_byte_array(stream, offset, 128, NULL, error);
594
388
    if (st->buf == NULL) {
595
0
        g_prefix_error(error, "FuStructEdid failed read of 0x%x: ", (guint) 128);
596
0
        return NULL;
597
0
    }
598
388
    if (st->buf->len != 128) {
599
24
        g_set_error(error,
600
24
                    FWUPD_ERROR,
601
24
                    FWUPD_ERROR_INVALID_DATA,
602
24
                    "FuStructEdid requested 0x%x and got 0x%x",
603
24
                    (guint) 128,
604
24
                    (guint) st->buf->len);
605
24
        return NULL;
606
24
    }
607
364
    if (!fu_struct_edid_parse_internal(st, error))
608
158
        return NULL;
609
206
    return g_steal_pointer(&st);
610
364
}