Coverage Report

Created: 2026-02-26 06:27

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.14k
{
71
1.14k
    g_return_if_fail(st != NULL);
72
1.14k
    if (st->refcount == 0) {
73
0
        g_critical("FuStructEdidDescriptor refcount already zero");
74
0
        return;
75
0
    }
76
1.14k
    if (--st->refcount > 0)
77
0
        return;
78
1.14k
    if (st->buf != NULL)
79
1.14k
        g_byte_array_unref(st->buf);
80
1.14k
    g_free(st);
81
1.14k
}
82
/**
83
 * fu_struct_edid_descriptor_new_internal: (skip):
84
 **/
85
static FuStructEdidDescriptor *
86
fu_struct_edid_descriptor_new_internal(void)
87
1.14k
{
88
1.14k
    FuStructEdidDescriptor *st = g_new0(FuStructEdidDescriptor, 1);
89
1.14k
    st->refcount = 1;
90
1.14k
    return st;
91
1.14k
}
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
920
{
100
920
    g_return_val_if_fail(st != NULL, 0x0);
101
920
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
102
920
}
103
/**
104
 * fu_struct_edid_descriptor_get_subkind: (skip):
105
 **/
106
guint8
107
fu_struct_edid_descriptor_get_subkind(const FuStructEdidDescriptor *st)
108
367
{
109
367
    g_return_val_if_fail(st != NULL, 0x0);
110
367
    return st->buf->data[2];
111
367
}
112
/**
113
 * fu_struct_edid_descriptor_get_tag: (skip):
114
 **/
115
FuEdidDescriptorTag
116
fu_struct_edid_descriptor_get_tag(const FuStructEdidDescriptor *st)
117
727
{
118
727
    g_return_val_if_fail(st != NULL, 0x0);
119
727
    return st->buf->data[3];
120
727
}
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
311
{
127
311
    g_return_val_if_fail(st != NULL, NULL);
128
311
    if (bufsz != NULL)
129
311
        *bufsz = 13;
130
311
    return st->buf->data + 5;
131
311
}
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
225
{
158
225
    g_return_if_fail(st != NULL);
159
225
    st->buf->data[3] = value;
160
225
}
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
225
{
167
225
    g_return_val_if_fail(st != NULL, FALSE);
168
225
    g_return_val_if_fail(buf != NULL, FALSE);
169
225
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
170
225
    return fu_memcpy_safe(st->buf->data, st->buf->len, 5, buf, bufsz, 0x0, bufsz, error);
171
225
}
172
/**
173
 * fu_struct_edid_descriptor_new: (skip):
174
 **/
175
FuStructEdidDescriptor *
176
fu_struct_edid_descriptor_new(void)
177
225
{
178
225
    FuStructEdidDescriptor *st = fu_struct_edid_descriptor_new_internal();
179
225
    st->buf = g_byte_array_sized_new(18);
180
225
    fu_byte_array_set_size(st->buf, 18, 0x0);
181
225
    return st;
182
225
}
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_validate_internal(FuStructEdidDescriptor *st, GError **error)
217
920
{
218
920
    g_return_val_if_fail(st != NULL, FALSE);
219
920
    return TRUE;
220
920
}
221
static gboolean
222
fu_struct_edid_descriptor_parse_internal(FuStructEdidDescriptor *st, GError **error)
223
920
{
224
920
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
225
0
        g_autofree gchar *str = fu_struct_edid_descriptor_to_string(st);
226
0
        g_debug("%s", str);
227
0
    }
228
920
    if (!fu_struct_edid_descriptor_validate_internal(st, error))
229
0
        return FALSE;
230
920
    return TRUE;
231
920
}
232
/**
233
 * fu_struct_edid_descriptor_parse_stream: (skip):
234
 **/
235
FuStructEdidDescriptor *
236
fu_struct_edid_descriptor_parse_stream(GInputStream *stream, gsize offset, GError **error)
237
920
{
238
920
    g_autoptr(FuStructEdidDescriptor) st = fu_struct_edid_descriptor_new_internal();
239
920
    st->buf = fu_input_stream_read_byte_array(stream, offset, 18, NULL, error);
240
920
    if (st->buf == NULL) {
241
0
        g_prefix_error(error, "FuStructEdidDescriptor failed read of 0x%x: ", (guint) 18);
242
0
        return NULL;
243
0
    }
244
920
    if (st->buf->len != 18) {
245
0
        g_set_error(error,
246
0
                    FWUPD_ERROR,
247
0
                    FWUPD_ERROR_INVALID_DATA,
248
0
                    "FuStructEdidDescriptor requested 0x%x and got 0x%x",
249
0
                    (guint) 18,
250
0
                    (guint) st->buf->len);
251
0
        return NULL;
252
0
    }
253
920
    if (!fu_struct_edid_descriptor_parse_internal(st, error))
254
0
        return NULL;
255
920
    return g_steal_pointer(&st);
256
920
}
257
/**
258
 * fu_struct_edid_ref: (skip):
259
 **/
260
FuStructEdid *
261
fu_struct_edid_ref(FuStructEdid *st)
262
0
{
263
0
    g_return_val_if_fail(st != NULL, NULL);
264
0
    st->refcount++;
265
0
    return st;
266
0
}
267
/**
268
 * fu_struct_edid_unref: (skip):
269
 **/
270
void
271
fu_struct_edid_unref(FuStructEdid *st)
272
573
{
273
573
    g_return_if_fail(st != NULL);
274
573
    if (st->refcount == 0) {
275
0
        g_critical("FuStructEdid refcount already zero");
276
0
        return;
277
0
    }
278
573
    if (--st->refcount > 0)
279
0
        return;
280
573
    if (st->buf != NULL)
281
343
        g_byte_array_unref(st->buf);
282
573
    g_free(st);
283
573
}
284
/**
285
 * fu_struct_edid_new_internal: (skip):
286
 **/
287
static FuStructEdid *
288
fu_struct_edid_new_internal(void)
289
573
{
290
573
    FuStructEdid *st = g_new0(FuStructEdid, 1);
291
573
    st->refcount = 1;
292
573
    return st;
293
573
}
294
295
/* getters */
296
/**
297
 * fu_struct_edid_get_header: (skip):
298
 **/
299
static const guint8 *
300
fu_struct_edid_get_header(const FuStructEdid *st, gsize *bufsz)
301
0
{
302
0
    g_return_val_if_fail(st != NULL, NULL);
303
0
    if (bufsz != NULL)
304
0
        *bufsz = 8;
305
0
    return st->buf->data + 0;
306
0
}
307
/**
308
 * fu_struct_edid_get_manufacturer_name: (skip):
309
 **/
310
const guint8 *
311
fu_struct_edid_get_manufacturer_name(const FuStructEdid *st, gsize *bufsz)
312
230
{
313
230
    g_return_val_if_fail(st != NULL, NULL);
314
230
    if (bufsz != NULL)
315
0
        *bufsz = 2;
316
230
    return st->buf->data + 8;
317
230
}
318
/**
319
 * fu_struct_edid_get_product_code: (skip):
320
 **/
321
guint16
322
fu_struct_edid_get_product_code(const FuStructEdid *st)
323
230
{
324
230
    g_return_val_if_fail(st != NULL, 0x0);
325
230
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
326
230
}
327
/**
328
 * fu_struct_edid_get_serial_number: (skip):
329
 **/
330
guint32
331
fu_struct_edid_get_serial_number(const FuStructEdid *st)
332
434
{
333
434
    g_return_val_if_fail(st != NULL, 0x0);
334
434
    return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN);
335
434
}
336
/**
337
 * fu_struct_edid_get_week_of_manufacture: (skip):
338
 **/
339
guint8
340
fu_struct_edid_get_week_of_manufacture(const FuStructEdid *st)
341
0
{
342
0
    g_return_val_if_fail(st != NULL, 0x0);
343
0
    return st->buf->data[16];
344
0
}
345
/**
346
 * fu_struct_edid_get_year_of_manufacture: (skip):
347
 **/
348
guint8
349
fu_struct_edid_get_year_of_manufacture(const FuStructEdid *st)
350
0
{
351
0
    g_return_val_if_fail(st != NULL, 0x0);
352
0
    return st->buf->data[17];
353
0
}
354
/**
355
 * fu_struct_edid_get_edid_version_number: (skip):
356
 **/
357
static guint8
358
fu_struct_edid_get_edid_version_number(const FuStructEdid *st)
359
237
{
360
237
    g_return_val_if_fail(st != NULL, 0x0);
361
237
    return st->buf->data[18];
362
237
}
363
/**
364
 * fu_struct_edid_get_revision_number: (skip):
365
 **/
366
guint8
367
fu_struct_edid_get_revision_number(const FuStructEdid *st)
368
0
{
369
0
    g_return_val_if_fail(st != NULL, 0x0);
370
0
    return st->buf->data[19];
371
0
}
372
/**
373
 * fu_struct_edid_get_data_blocks: (skip):
374
 **/
375
const guint8 *
376
fu_struct_edid_get_data_blocks(const FuStructEdid *st, gsize *bufsz)
377
0
{
378
0
    g_return_val_if_fail(st != NULL, NULL);
379
0
    if (bufsz != NULL)
380
0
        *bufsz = 72;
381
0
    return st->buf->data + 54;
382
0
}
383
/**
384
 * fu_struct_edid_get_extension_block_count: (skip):
385
 **/
386
guint8
387
fu_struct_edid_get_extension_block_count(const FuStructEdid *st)
388
0
{
389
0
    g_return_val_if_fail(st != NULL, 0x0);
390
0
    return st->buf->data[126];
391
0
}
392
/**
393
 * fu_struct_edid_get_checksum: (skip):
394
 **/
395
guint8
396
fu_struct_edid_get_checksum(const FuStructEdid *st)
397
0
{
398
0
    g_return_val_if_fail(st != NULL, 0x0);
399
0
    return st->buf->data[127];
400
0
}
401
402
/* setters */
403
/**
404
 * fu_struct_edid_set_manufacturer_name: (skip):
405
 **/
406
gboolean
407
fu_struct_edid_set_manufacturer_name(FuStructEdid *st, const guint8 *buf, gsize bufsz, GError **error)
408
0
{
409
0
    g_return_val_if_fail(st != NULL, FALSE);
410
0
    g_return_val_if_fail(buf != NULL, FALSE);
411
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
412
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 8, buf, bufsz, 0x0, bufsz, error);
413
0
}
414
/**
415
 * fu_struct_edid_set_product_code: (skip):
416
 **/
417
void
418
fu_struct_edid_set_product_code(FuStructEdid *st, guint16 value)
419
230
{
420
230
    g_return_if_fail(st != NULL);
421
230
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
422
230
}
423
/**
424
 * fu_struct_edid_set_serial_number: (skip):
425
 **/
426
void
427
fu_struct_edid_set_serial_number(FuStructEdid *st, guint32 value)
428
89
{
429
89
    g_return_if_fail(st != NULL);
430
89
    fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN);
431
89
}
432
/**
433
 * fu_struct_edid_set_week_of_manufacture: (skip):
434
 **/
435
void
436
fu_struct_edid_set_week_of_manufacture(FuStructEdid *st, guint8 value)
437
0
{
438
0
    g_return_if_fail(st != NULL);
439
0
    st->buf->data[16] = value;
440
0
}
441
/**
442
 * fu_struct_edid_set_year_of_manufacture: (skip):
443
 **/
444
void
445
fu_struct_edid_set_year_of_manufacture(FuStructEdid *st, guint8 value)
446
0
{
447
0
    g_return_if_fail(st != NULL);
448
0
    st->buf->data[17] = value;
449
0
}
450
/**
451
 * fu_struct_edid_set_edid_version_number: (skip):
452
 **/
453
static void
454
fu_struct_edid_set_edid_version_number(FuStructEdid *st, guint8 value)
455
230
{
456
230
    g_return_if_fail(st != NULL);
457
230
    st->buf->data[18] = value;
458
230
}
459
/**
460
 * fu_struct_edid_set_revision_number: (skip):
461
 **/
462
void
463
fu_struct_edid_set_revision_number(FuStructEdid *st, guint8 value)
464
230
{
465
230
    g_return_if_fail(st != NULL);
466
230
    st->buf->data[19] = value;
467
230
}
468
/**
469
 * fu_struct_edid_set_data_blocks: (skip):
470
 **/
471
gboolean
472
fu_struct_edid_set_data_blocks(FuStructEdid *st, const guint8 *buf, gsize bufsz, GError **error)
473
0
{
474
0
    g_return_val_if_fail(st != NULL, FALSE);
475
0
    g_return_val_if_fail(buf != NULL, FALSE);
476
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
477
0
    return fu_memcpy_safe(st->buf->data, st->buf->len, 54, buf, bufsz, 0x0, bufsz, error);
478
0
}
479
/**
480
 * fu_struct_edid_set_extension_block_count: (skip):
481
 **/
482
void
483
fu_struct_edid_set_extension_block_count(FuStructEdid *st, guint8 value)
484
0
{
485
0
    g_return_if_fail(st != NULL);
486
0
    st->buf->data[126] = value;
487
0
}
488
/**
489
 * fu_struct_edid_set_checksum: (skip):
490
 **/
491
void
492
fu_struct_edid_set_checksum(FuStructEdid *st, guint8 value)
493
0
{
494
0
    g_return_if_fail(st != NULL);
495
0
    st->buf->data[127] = value;
496
0
}
497
/**
498
 * fu_struct_edid_new: (skip):
499
 **/
500
FuStructEdid *
501
fu_struct_edid_new(void)
502
230
{
503
230
    FuStructEdid *st = fu_struct_edid_new_internal();
504
230
    st->buf = g_byte_array_sized_new(128);
505
230
    fu_byte_array_set_size(st->buf, 128, 0x0);
506
230
    memcpy(st->buf->data + 0x0, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8); /* nocheck:blocked */
507
230
    fu_struct_edid_set_edid_version_number(st, 0x1);
508
230
    fu_struct_edid_set_revision_number(st, 0x3);
509
230
    return st;
510
230
}
511
/**
512
 * fu_struct_edid_to_string: (skip):
513
 **/
514
static gchar *
515
fu_struct_edid_to_string(const FuStructEdid *st)
516
0
{
517
0
    g_autoptr(GString) str = g_string_new("FuStructEdid:\n");
518
0
    g_return_val_if_fail(st != NULL, NULL);
519
0
    {
520
0
        gsize bufsz = 0;
521
0
        const guint8 *buf = fu_struct_edid_get_header(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, "  header: 0x%s\n", tmp->str);
526
0
    }
527
0
    {
528
0
        gsize bufsz = 0;
529
0
        const guint8 *buf = fu_struct_edid_get_manufacturer_name(st, &bufsz);
530
0
        g_autoptr(GString) tmp = g_string_new(NULL);
531
0
        for (gsize i = 0; i < bufsz; i++)
532
0
            g_string_append_printf(tmp, "%02X", buf[i]);
533
0
        g_string_append_printf(str, "  manufacturer_name: 0x%s\n", tmp->str);
534
0
    }
535
0
    g_string_append_printf(str, "  product_code: 0x%x\n",
536
0
                           (guint) fu_struct_edid_get_product_code(st));
537
0
    g_string_append_printf(str, "  serial_number: 0x%x\n",
538
0
                           (guint) fu_struct_edid_get_serial_number(st));
539
0
    g_string_append_printf(str, "  week_of_manufacture: 0x%x\n",
540
0
                           (guint) fu_struct_edid_get_week_of_manufacture(st));
541
0
    g_string_append_printf(str, "  year_of_manufacture: 0x%x\n",
542
0
                           (guint) fu_struct_edid_get_year_of_manufacture(st));
543
0
    g_string_append_printf(str, "  edid_version_number: 0x%x\n",
544
0
                           (guint) fu_struct_edid_get_edid_version_number(st));
545
0
    g_string_append_printf(str, "  revision_number: 0x%x\n",
546
0
                           (guint) fu_struct_edid_get_revision_number(st));
547
0
    {
548
0
        gsize bufsz = 0;
549
0
        const guint8 *buf = fu_struct_edid_get_data_blocks(st, &bufsz);
550
0
        g_autoptr(GString) tmp = g_string_new(NULL);
551
0
        for (gsize i = 0; i < bufsz; i++)
552
0
            g_string_append_printf(tmp, "%02X", buf[i]);
553
0
        g_string_append_printf(str, "  data_blocks: 0x%s\n", tmp->str);
554
0
    }
555
0
    g_string_append_printf(str, "  extension_block_count: 0x%x\n",
556
0
                           (guint) fu_struct_edid_get_extension_block_count(st));
557
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
558
0
                           (guint) fu_struct_edid_get_checksum(st));
559
0
    if (str->len > 0)
560
0
        g_string_set_size(str, str->len - 1);
561
0
    return g_string_free(g_steal_pointer(&str), FALSE);
562
0
}
563
static gboolean
564
fu_struct_edid_validate_internal(FuStructEdid *st, GError **error)
565
317
{
566
317
    g_return_val_if_fail(st != NULL, FALSE);
567
317
    if (memcmp(st->buf->data + 0, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8) != 0) {
568
80
        g_set_error_literal(error,
569
80
                            FWUPD_ERROR,
570
80
                            FWUPD_ERROR_INVALID_DATA,
571
80
                            "constant FuStructEdid.header was not valid");
572
80
        return FALSE;
573
80
    }
574
237
    if (fu_struct_edid_get_edid_version_number(st) != 0x1) {
575
7
        g_set_error_literal(error,
576
7
                            FWUPD_ERROR,
577
7
                            FWUPD_ERROR_INVALID_DATA,
578
7
                            "constant FuStructEdid.edid_version_number was not valid");
579
7
        return FALSE;
580
7
    }
581
230
    return TRUE;
582
237
}
583
static gboolean
584
fu_struct_edid_parse_internal(FuStructEdid *st, GError **error)
585
317
{
586
317
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
587
0
        g_autofree gchar *str = fu_struct_edid_to_string(st);
588
0
        g_debug("%s", str);
589
0
    }
590
317
    if (!fu_struct_edid_validate_internal(st, error))
591
87
        return FALSE;
592
230
    return TRUE;
593
317
}
594
/**
595
 * fu_struct_edid_parse_stream: (skip):
596
 **/
597
FuStructEdid *
598
fu_struct_edid_parse_stream(GInputStream *stream, gsize offset, GError **error)
599
343
{
600
343
    g_autoptr(FuStructEdid) st = fu_struct_edid_new_internal();
601
343
    st->buf = fu_input_stream_read_byte_array(stream, offset, 128, NULL, error);
602
343
    if (st->buf == NULL) {
603
0
        g_prefix_error(error, "FuStructEdid failed read of 0x%x: ", (guint) 128);
604
0
        return NULL;
605
0
    }
606
343
    if (st->buf->len != 128) {
607
26
        g_set_error(error,
608
26
                    FWUPD_ERROR,
609
26
                    FWUPD_ERROR_INVALID_DATA,
610
26
                    "FuStructEdid requested 0x%x and got 0x%x",
611
26
                    (guint) 128,
612
26
                    (guint) st->buf->len);
613
26
        return NULL;
614
26
    }
615
317
    if (!fu_struct_edid_parse_internal(st, error))
616
87
        return NULL;
617
230
    return g_steal_pointer(&st);
618
317
}