Coverage Report

Created: 2026-01-09 07:21

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