Coverage Report

Created: 2026-01-09 07:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-oprom-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-oprom-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_oprom_machine_type_to_string:
23
 * @val: value
24
 *
25
 * Converts an enumerated value to a string.
26
 *
27
 * Returns: identifier string
28
 **/
29
static const gchar *
30
fu_oprom_machine_type_to_string(FuOpromMachineType val)
31
0
{
32
0
    if (val == FU_OPROM_MACHINE_TYPE_X64)
33
0
        return "x64";
34
0
    return NULL;
35
0
}
36
37
/**
38
 * fu_oprom_subsystem_to_string:
39
 * @val: value
40
 *
41
 * Converts an enumerated value to a string.
42
 *
43
 * Returns: identifier string
44
 **/
45
static const gchar *
46
fu_oprom_subsystem_to_string(FuOpromSubsystem val)
47
0
{
48
0
    if (val == FU_OPROM_SUBSYSTEM_EFI_BOOT_SRV_DRV)
49
0
        return "efi-boot-srv-drv";
50
0
    return NULL;
51
0
}
52
53
/**
54
 * fu_oprom_compression_type_to_string:
55
 * @val: value
56
 *
57
 * Converts an enumerated value to a string.
58
 *
59
 * Returns: identifier string
60
 **/
61
static const gchar *
62
fu_oprom_compression_type_to_string(FuOpromCompressionType val)
63
0
{
64
0
    if (val == FU_OPROM_COMPRESSION_TYPE_NONE)
65
0
        return "none";
66
0
    return NULL;
67
0
}
68
69
/**
70
 * fu_oprom_indicator_flags_to_string:
71
 * @val: value, e.g. %FU_OPROM_INDICATOR_FLAG_LAST
72
 *
73
 * Converts an enumerated value to a string.
74
 *
75
 * Returns: identifier string
76
 **/
77
static const gchar *
78
fu_oprom_indicator_flags_to_string(FuOpromIndicatorFlags val)
79
0
{
80
0
    if (val == FU_OPROM_INDICATOR_FLAG_NONE)
81
0
        return "none";
82
0
    if (val == FU_OPROM_INDICATOR_FLAG_LAST)
83
0
        return "last";
84
0
    return NULL;
85
0
}
86
/**
87
 * fu_struct_oprom_ref: (skip):
88
 **/
89
FuStructOprom *
90
fu_struct_oprom_ref(FuStructOprom *st)
91
0
{
92
0
    g_return_val_if_fail(st != NULL, NULL);
93
0
    st->refcount++;
94
0
    return st;
95
0
}
96
/**
97
 * fu_struct_oprom_unref: (skip):
98
 **/
99
void
100
fu_struct_oprom_unref(FuStructOprom *st)
101
7.26k
{
102
7.26k
    g_return_if_fail(st != NULL);
103
7.26k
    if (st->refcount == 0) {
104
0
        g_critical("FuStructOprom refcount already zero");
105
0
        return;
106
0
    }
107
7.26k
    if (--st->refcount > 0)
108
0
        return;
109
7.26k
    if (st->buf != NULL)
110
7.26k
        g_byte_array_unref(st->buf);
111
7.26k
    g_free(st);
112
7.26k
}
113
/**
114
 * fu_struct_oprom_new_internal: (skip):
115
 **/
116
static FuStructOprom *
117
fu_struct_oprom_new_internal(void)
118
7.26k
{
119
7.26k
    FuStructOprom *st = g_new0(FuStructOprom, 1);
120
7.26k
    st->refcount = 1;
121
7.26k
    return st;
122
7.26k
}
123
124
/* getters */
125
/**
126
 * fu_struct_oprom_get_signature: (skip):
127
 **/
128
static guint16
129
fu_struct_oprom_get_signature(const FuStructOprom *st)
130
8.48k
{
131
8.48k
    g_return_val_if_fail(st != NULL, 0x0);
132
8.48k
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
133
8.48k
}
134
/**
135
 * fu_struct_oprom_get_image_size: (skip):
136
 **/
137
guint16
138
fu_struct_oprom_get_image_size(const FuStructOprom *st)
139
0
{
140
0
    g_return_val_if_fail(st != NULL, 0x0);
141
0
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
142
0
}
143
/**
144
 * fu_struct_oprom_get_init_func_entry_point: (skip):
145
 **/
146
guint32
147
fu_struct_oprom_get_init_func_entry_point(const FuStructOprom *st)
148
0
{
149
0
    g_return_val_if_fail(st != NULL, 0x0);
150
0
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
151
0
}
152
/**
153
 * fu_struct_oprom_get_subsystem: (skip):
154
 **/
155
FuOpromSubsystem
156
fu_struct_oprom_get_subsystem(const FuStructOprom *st)
157
850
{
158
850
    g_return_val_if_fail(st != NULL, 0x0);
159
850
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
160
850
}
161
/**
162
 * fu_struct_oprom_get_machine_type: (skip):
163
 **/
164
FuOpromMachineType
165
fu_struct_oprom_get_machine_type(const FuStructOprom *st)
166
850
{
167
850
    g_return_val_if_fail(st != NULL, 0x0);
168
850
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
169
850
}
170
/**
171
 * fu_struct_oprom_get_compression_type: (skip):
172
 **/
173
FuOpromCompressionType
174
fu_struct_oprom_get_compression_type(const FuStructOprom *st)
175
850
{
176
850
    g_return_val_if_fail(st != NULL, 0x0);
177
850
    return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN);
178
850
}
179
/**
180
 * fu_struct_oprom_get_efi_image_offset: (skip):
181
 **/
182
guint16
183
fu_struct_oprom_get_efi_image_offset(const FuStructOprom *st)
184
0
{
185
0
    g_return_val_if_fail(st != NULL, 0x0);
186
0
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
187
0
}
188
/**
189
 * fu_struct_oprom_get_pci_header_offset: (skip):
190
 **/
191
guint16
192
fu_struct_oprom_get_pci_header_offset(const FuStructOprom *st)
193
850
{
194
850
    g_return_val_if_fail(st != NULL, 0x0);
195
850
    return fu_memread_uint16(st->buf->data + 24, G_LITTLE_ENDIAN);
196
850
}
197
/**
198
 * fu_struct_oprom_get_expansion_header_offset: (skip):
199
 **/
200
guint16
201
fu_struct_oprom_get_expansion_header_offset(const FuStructOprom *st)
202
758
{
203
758
    g_return_val_if_fail(st != NULL, 0x0);
204
758
    return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN);
205
758
}
206
207
/* setters */
208
/**
209
 * fu_struct_oprom_set_signature: (skip):
210
 **/
211
static void
212
fu_struct_oprom_set_signature(FuStructOprom *st, guint16 value)
213
741
{
214
741
    g_return_if_fail(st != NULL);
215
741
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
216
741
}
217
/**
218
 * fu_struct_oprom_set_image_size: (skip):
219
 **/
220
void
221
fu_struct_oprom_set_image_size(FuStructOprom *st, guint16 value)
222
741
{
223
741
    g_return_if_fail(st != NULL);
224
741
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
225
741
}
226
/**
227
 * fu_struct_oprom_set_init_func_entry_point: (skip):
228
 **/
229
void
230
fu_struct_oprom_set_init_func_entry_point(FuStructOprom *st, guint32 value)
231
0
{
232
0
    g_return_if_fail(st != NULL);
233
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
234
0
}
235
/**
236
 * fu_struct_oprom_set_subsystem: (skip):
237
 **/
238
void
239
fu_struct_oprom_set_subsystem(FuStructOprom *st, FuOpromSubsystem value)
240
741
{
241
741
    g_return_if_fail(st != NULL);
242
741
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
243
741
}
244
/**
245
 * fu_struct_oprom_set_machine_type: (skip):
246
 **/
247
void
248
fu_struct_oprom_set_machine_type(FuStructOprom *st, FuOpromMachineType value)
249
741
{
250
741
    g_return_if_fail(st != NULL);
251
741
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
252
741
}
253
/**
254
 * fu_struct_oprom_set_compression_type: (skip):
255
 **/
256
void
257
fu_struct_oprom_set_compression_type(FuStructOprom *st, FuOpromCompressionType value)
258
741
{
259
741
    g_return_if_fail(st != NULL);
260
741
    fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN);
261
741
}
262
/**
263
 * fu_struct_oprom_set_efi_image_offset: (skip):
264
 **/
265
void
266
fu_struct_oprom_set_efi_image_offset(FuStructOprom *st, guint16 value)
267
0
{
268
0
    g_return_if_fail(st != NULL);
269
0
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
270
0
}
271
/**
272
 * fu_struct_oprom_set_pci_header_offset: (skip):
273
 **/
274
void
275
fu_struct_oprom_set_pci_header_offset(FuStructOprom *st, guint16 value)
276
741
{
277
741
    g_return_if_fail(st != NULL);
278
741
    fu_memwrite_uint16(st->buf->data + 24, value, G_LITTLE_ENDIAN);
279
741
}
280
/**
281
 * fu_struct_oprom_set_expansion_header_offset: (skip):
282
 **/
283
void
284
fu_struct_oprom_set_expansion_header_offset(FuStructOprom *st, guint16 value)
285
2
{
286
2
    g_return_if_fail(st != NULL);
287
2
    fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN);
288
2
}
289
/**
290
 * fu_struct_oprom_new: (skip):
291
 **/
292
FuStructOprom *
293
fu_struct_oprom_new(void)
294
741
{
295
741
    FuStructOprom *st = fu_struct_oprom_new_internal();
296
741
    st->buf = g_byte_array_sized_new(28);
297
741
    fu_byte_array_set_size(st->buf, 28, 0x0);
298
741
    fu_struct_oprom_set_signature(st, 0xAA55);
299
741
    fu_struct_oprom_set_pci_header_offset(st, 28);
300
741
    return st;
301
741
}
302
/**
303
 * fu_struct_oprom_to_string: (skip):
304
 **/
305
static gchar *
306
fu_struct_oprom_to_string(const FuStructOprom *st)
307
0
{
308
0
    g_autoptr(GString) str = g_string_new("FuStructOprom:\n");
309
0
    g_return_val_if_fail(st != NULL, NULL);
310
0
    g_string_append_printf(str, "  signature: 0x%x\n",
311
0
                           (guint) fu_struct_oprom_get_signature(st));
312
0
    g_string_append_printf(str, "  image_size: 0x%x\n",
313
0
                           (guint) fu_struct_oprom_get_image_size(st));
314
0
    g_string_append_printf(str, "  init_func_entry_point: 0x%x\n",
315
0
                           (guint) fu_struct_oprom_get_init_func_entry_point(st));
316
0
    {
317
0
        const gchar *tmp = fu_oprom_subsystem_to_string(fu_struct_oprom_get_subsystem(st));
318
0
        if (tmp != NULL) {
319
0
            g_string_append_printf(str, "  subsystem: 0x%x [%s]\n", (guint) fu_struct_oprom_get_subsystem(st), tmp);
320
0
        } else {
321
0
            g_string_append_printf(str, "  subsystem: 0x%x\n", (guint) fu_struct_oprom_get_subsystem(st));
322
0
        }
323
0
    }
324
0
    {
325
0
        const gchar *tmp = fu_oprom_machine_type_to_string(fu_struct_oprom_get_machine_type(st));
326
0
        if (tmp != NULL) {
327
0
            g_string_append_printf(str, "  machine_type: 0x%x [%s]\n", (guint) fu_struct_oprom_get_machine_type(st), tmp);
328
0
        } else {
329
0
            g_string_append_printf(str, "  machine_type: 0x%x\n", (guint) fu_struct_oprom_get_machine_type(st));
330
0
        }
331
0
    }
332
0
    {
333
0
        const gchar *tmp = fu_oprom_compression_type_to_string(fu_struct_oprom_get_compression_type(st));
334
0
        if (tmp != NULL) {
335
0
            g_string_append_printf(str, "  compression_type: 0x%x [%s]\n", (guint) fu_struct_oprom_get_compression_type(st), tmp);
336
0
        } else {
337
0
            g_string_append_printf(str, "  compression_type: 0x%x\n", (guint) fu_struct_oprom_get_compression_type(st));
338
0
        }
339
0
    }
340
0
    g_string_append_printf(str, "  efi_image_offset: 0x%x\n",
341
0
                           (guint) fu_struct_oprom_get_efi_image_offset(st));
342
0
    g_string_append_printf(str, "  pci_header_offset: 0x%x\n",
343
0
                           (guint) fu_struct_oprom_get_pci_header_offset(st));
344
0
    g_string_append_printf(str, "  expansion_header_offset: 0x%x\n",
345
0
                           (guint) fu_struct_oprom_get_expansion_header_offset(st));
346
0
    if (str->len > 0)
347
0
        g_string_set_size(str, str->len - 1);
348
0
    return g_string_free(g_steal_pointer(&str), FALSE);
349
0
}
350
static gboolean
351
fu_struct_oprom_validate_internal(FuStructOprom *st, GError **error)
352
5.09k
{
353
5.09k
    g_return_val_if_fail(st != NULL, FALSE);
354
5.09k
    if (fu_struct_oprom_get_signature(st) != 0xAA55) {
355
3.39k
        g_set_error(error,
356
3.39k
                    FWUPD_ERROR,
357
3.39k
                    FWUPD_ERROR_INVALID_DATA,
358
3.39k
                    "constant FuStructOprom.signature was not valid, "
359
3.39k
                    "expected 0x%x and got 0x%x",
360
3.39k
                    (guint) 0xAA55,
361
3.39k
                    (guint) fu_struct_oprom_get_signature(st));
362
3.39k
        return FALSE;
363
3.39k
    }
364
1.70k
    return TRUE;
365
5.09k
}
366
/**
367
 * fu_struct_oprom_validate_stream: (skip):
368
 **/
369
gboolean
370
fu_struct_oprom_validate_stream(GInputStream *stream, gsize offset, GError **error)
371
5.67k
{
372
5.67k
    g_autoptr(FuStructOprom) st = fu_struct_oprom_new_internal();
373
5.67k
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
374
5.67k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
375
5.67k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
376
5.67k
    if (st->buf == NULL) {
377
0
        g_prefix_error(error, "FuStructOprom failed read of 0x%x: ", (guint) 28);
378
0
        return FALSE;
379
0
    }
380
5.67k
    if (st->buf->len != 28) {
381
1.43k
        g_set_error(error,
382
1.43k
                    FWUPD_ERROR,
383
1.43k
                    FWUPD_ERROR_INVALID_DATA,
384
1.43k
                    "FuStructOprom requested 0x%x and got 0x%x",
385
1.43k
                    (guint) 28,
386
1.43k
                    (guint) st->buf->len);
387
1.43k
        return FALSE;
388
1.43k
    }
389
4.24k
    return fu_struct_oprom_validate_internal(st, error);
390
5.67k
}
391
static gboolean
392
fu_struct_oprom_parse_internal(FuStructOprom *st, GError **error)
393
850
{
394
850
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
395
0
        g_autofree gchar *str = fu_struct_oprom_to_string(st);
396
0
        g_debug("%s", str);
397
0
    }
398
850
    if (!fu_struct_oprom_validate_internal(st, error))
399
0
        return FALSE;
400
850
    return TRUE;
401
850
}
402
/**
403
 * fu_struct_oprom_parse_stream: (skip):
404
 **/
405
FuStructOprom *
406
fu_struct_oprom_parse_stream(GInputStream *stream, gsize offset, GError **error)
407
850
{
408
850
    g_autoptr(FuStructOprom) st = fu_struct_oprom_new_internal();
409
850
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
410
850
    if (st->buf == NULL) {
411
0
        g_prefix_error(error, "FuStructOprom failed read of 0x%x: ", (guint) 28);
412
0
        return NULL;
413
0
    }
414
850
    if (st->buf->len != 28) {
415
0
        g_set_error(error,
416
0
                    FWUPD_ERROR,
417
0
                    FWUPD_ERROR_INVALID_DATA,
418
0
                    "FuStructOprom requested 0x%x and got 0x%x",
419
0
                    (guint) 28,
420
0
                    (guint) st->buf->len);
421
0
        return NULL;
422
0
    }
423
850
    if (!fu_struct_oprom_parse_internal(st, error))
424
0
        return NULL;
425
850
    return g_steal_pointer(&st);
426
850
}
427
/**
428
 * fu_struct_oprom_pci_ref: (skip):
429
 **/
430
FuStructOpromPci *
431
fu_struct_oprom_pci_ref(FuStructOpromPci *st)
432
0
{
433
0
    g_return_val_if_fail(st != NULL, NULL);
434
0
    st->refcount++;
435
0
    return st;
436
0
}
437
/**
438
 * fu_struct_oprom_pci_unref: (skip):
439
 **/
440
void
441
fu_struct_oprom_pci_unref(FuStructOpromPci *st)
442
1.58k
{
443
1.58k
    g_return_if_fail(st != NULL);
444
1.58k
    if (st->refcount == 0) {
445
0
        g_critical("FuStructOpromPci refcount already zero");
446
0
        return;
447
0
    }
448
1.58k
    if (--st->refcount > 0)
449
0
        return;
450
1.58k
    if (st->buf != NULL)
451
1.55k
        g_byte_array_unref(st->buf);
452
1.58k
    g_free(st);
453
1.58k
}
454
/**
455
 * fu_struct_oprom_pci_new_internal: (skip):
456
 **/
457
static FuStructOpromPci *
458
fu_struct_oprom_pci_new_internal(void)
459
1.58k
{
460
1.58k
    FuStructOpromPci *st = g_new0(FuStructOpromPci, 1);
461
1.58k
    st->refcount = 1;
462
1.58k
    return st;
463
1.58k
}
464
465
/* getters */
466
/**
467
 * fu_struct_oprom_pci_get_signature: (skip):
468
 **/
469
static guint32
470
fu_struct_oprom_pci_get_signature(const FuStructOpromPci *st)
471
847
{
472
847
    g_return_val_if_fail(st != NULL, 0x0);
473
847
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
474
847
}
475
/**
476
 * fu_struct_oprom_pci_get_vendor_id: (skip):
477
 **/
478
guint16
479
fu_struct_oprom_pci_get_vendor_id(const FuStructOpromPci *st)
480
761
{
481
761
    g_return_val_if_fail(st != NULL, 0x0);
482
761
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
483
761
}
484
/**
485
 * fu_struct_oprom_pci_get_device_id: (skip):
486
 **/
487
guint16
488
fu_struct_oprom_pci_get_device_id(const FuStructOpromPci *st)
489
761
{
490
761
    g_return_val_if_fail(st != NULL, 0x0);
491
761
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
492
761
}
493
/**
494
 * fu_struct_oprom_pci_get_device_list_pointer: (skip):
495
 **/
496
guint16
497
fu_struct_oprom_pci_get_device_list_pointer(const FuStructOpromPci *st)
498
0
{
499
0
    g_return_val_if_fail(st != NULL, 0x0);
500
0
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
501
0
}
502
/**
503
 * fu_struct_oprom_pci_get_structure_length: (skip):
504
 **/
505
guint16
506
fu_struct_oprom_pci_get_structure_length(const FuStructOpromPci *st)
507
0
{
508
0
    g_return_val_if_fail(st != NULL, 0x0);
509
0
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
510
0
}
511
/**
512
 * fu_struct_oprom_pci_get_structure_revision: (skip):
513
 **/
514
guint8
515
fu_struct_oprom_pci_get_structure_revision(const FuStructOpromPci *st)
516
0
{
517
0
    g_return_val_if_fail(st != NULL, 0x0);
518
0
    return st->buf->data[12];
519
0
}
520
/**
521
 * fu_struct_oprom_pci_get_class_code: (skip):
522
 **/
523
guint32
524
fu_struct_oprom_pci_get_class_code(const FuStructOpromPci *st)
525
0
{
526
0
    g_return_val_if_fail(st != NULL, 0x0);
527
0
    return fu_memread_uint24(st->buf->data + 13, G_LITTLE_ENDIAN);
528
0
}
529
/**
530
 * fu_struct_oprom_pci_get_image_length: (skip):
531
 **/
532
guint16
533
fu_struct_oprom_pci_get_image_length(const FuStructOpromPci *st)
534
761
{
535
761
    g_return_val_if_fail(st != NULL, 0x0);
536
761
    return fu_memread_uint16(st->buf->data + 16, G_LITTLE_ENDIAN);
537
761
}
538
/**
539
 * fu_struct_oprom_pci_get_image_revision: (skip):
540
 **/
541
guint16
542
fu_struct_oprom_pci_get_image_revision(const FuStructOpromPci *st)
543
0
{
544
0
    g_return_val_if_fail(st != NULL, 0x0);
545
0
    return fu_memread_uint16(st->buf->data + 18, G_LITTLE_ENDIAN);
546
0
}
547
/**
548
 * fu_struct_oprom_pci_get_code_type: (skip):
549
 **/
550
guint8
551
fu_struct_oprom_pci_get_code_type(const FuStructOpromPci *st)
552
758
{
553
758
    g_return_val_if_fail(st != NULL, 0x0);
554
758
    return st->buf->data[20];
555
758
}
556
/**
557
 * fu_struct_oprom_pci_get_indicator: (skip):
558
 **/
559
FuOpromIndicatorFlags
560
fu_struct_oprom_pci_get_indicator(const FuStructOpromPci *st)
561
758
{
562
758
    g_return_val_if_fail(st != NULL, 0x0);
563
758
    return st->buf->data[21];
564
758
}
565
/**
566
 * fu_struct_oprom_pci_get_max_runtime_image_length: (skip):
567
 **/
568
guint16
569
fu_struct_oprom_pci_get_max_runtime_image_length(const FuStructOpromPci *st)
570
0
{
571
0
    g_return_val_if_fail(st != NULL, 0x0);
572
0
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
573
0
}
574
/**
575
 * fu_struct_oprom_pci_get_conf_util_code_header_pointer: (skip):
576
 **/
577
guint16
578
fu_struct_oprom_pci_get_conf_util_code_header_pointer(const FuStructOpromPci *st)
579
0
{
580
0
    g_return_val_if_fail(st != NULL, 0x0);
581
0
    return fu_memread_uint16(st->buf->data + 24, G_LITTLE_ENDIAN);
582
0
}
583
/**
584
 * fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer: (skip):
585
 **/
586
guint16
587
fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer(const FuStructOpromPci *st)
588
0
{
589
0
    g_return_val_if_fail(st != NULL, 0x0);
590
0
    return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN);
591
0
}
592
593
/* setters */
594
/**
595
 * fu_struct_oprom_pci_set_signature: (skip):
596
 **/
597
static void
598
fu_struct_oprom_pci_set_signature(FuStructOpromPci *st, guint32 value)
599
741
{
600
741
    g_return_if_fail(st != NULL);
601
741
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
602
741
}
603
/**
604
 * fu_struct_oprom_pci_set_vendor_id: (skip):
605
 **/
606
void
607
fu_struct_oprom_pci_set_vendor_id(FuStructOpromPci *st, guint16 value)
608
741
{
609
741
    g_return_if_fail(st != NULL);
610
741
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
611
741
}
612
/**
613
 * fu_struct_oprom_pci_set_device_id: (skip):
614
 **/
615
void
616
fu_struct_oprom_pci_set_device_id(FuStructOpromPci *st, guint16 value)
617
741
{
618
741
    g_return_if_fail(st != NULL);
619
741
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
620
741
}
621
/**
622
 * fu_struct_oprom_pci_set_device_list_pointer: (skip):
623
 **/
624
void
625
fu_struct_oprom_pci_set_device_list_pointer(FuStructOpromPci *st, guint16 value)
626
0
{
627
0
    g_return_if_fail(st != NULL);
628
0
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
629
0
}
630
/**
631
 * fu_struct_oprom_pci_set_structure_length: (skip):
632
 **/
633
void
634
fu_struct_oprom_pci_set_structure_length(FuStructOpromPci *st, guint16 value)
635
0
{
636
0
    g_return_if_fail(st != NULL);
637
0
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
638
0
}
639
/**
640
 * fu_struct_oprom_pci_set_structure_revision: (skip):
641
 **/
642
void
643
fu_struct_oprom_pci_set_structure_revision(FuStructOpromPci *st, guint8 value)
644
0
{
645
0
    g_return_if_fail(st != NULL);
646
0
    st->buf->data[12] = value;
647
0
}
648
/**
649
 * fu_struct_oprom_pci_set_class_code: (skip):
650
 **/
651
void
652
fu_struct_oprom_pci_set_class_code(FuStructOpromPci *st, guint32 value)
653
0
{
654
0
    g_return_if_fail(st != NULL);
655
0
    fu_memwrite_uint24(st->buf->data + 13, value, G_LITTLE_ENDIAN);
656
0
}
657
/**
658
 * fu_struct_oprom_pci_set_image_length: (skip):
659
 **/
660
void
661
fu_struct_oprom_pci_set_image_length(FuStructOpromPci *st, guint16 value)
662
741
{
663
741
    g_return_if_fail(st != NULL);
664
741
    fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN);
665
741
}
666
/**
667
 * fu_struct_oprom_pci_set_image_revision: (skip):
668
 **/
669
void
670
fu_struct_oprom_pci_set_image_revision(FuStructOpromPci *st, guint16 value)
671
0
{
672
0
    g_return_if_fail(st != NULL);
673
0
    fu_memwrite_uint16(st->buf->data + 18, value, G_LITTLE_ENDIAN);
674
0
}
675
/**
676
 * fu_struct_oprom_pci_set_code_type: (skip):
677
 **/
678
void
679
fu_struct_oprom_pci_set_code_type(FuStructOpromPci *st, guint8 value)
680
741
{
681
741
    g_return_if_fail(st != NULL);
682
741
    st->buf->data[20] = value;
683
741
}
684
/**
685
 * fu_struct_oprom_pci_set_indicator: (skip):
686
 **/
687
void
688
fu_struct_oprom_pci_set_indicator(FuStructOpromPci *st, FuOpromIndicatorFlags value)
689
188
{
690
188
    g_return_if_fail(st != NULL);
691
188
    st->buf->data[21] = value;
692
188
}
693
/**
694
 * fu_struct_oprom_pci_set_max_runtime_image_length: (skip):
695
 **/
696
void
697
fu_struct_oprom_pci_set_max_runtime_image_length(FuStructOpromPci *st, guint16 value)
698
0
{
699
0
    g_return_if_fail(st != NULL);
700
0
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
701
0
}
702
/**
703
 * fu_struct_oprom_pci_set_conf_util_code_header_pointer: (skip):
704
 **/
705
void
706
fu_struct_oprom_pci_set_conf_util_code_header_pointer(FuStructOpromPci *st, guint16 value)
707
0
{
708
0
    g_return_if_fail(st != NULL);
709
0
    fu_memwrite_uint16(st->buf->data + 24, value, G_LITTLE_ENDIAN);
710
0
}
711
/**
712
 * fu_struct_oprom_pci_set_dmtf_clp_entry_point_pointer: (skip):
713
 **/
714
void
715
fu_struct_oprom_pci_set_dmtf_clp_entry_point_pointer(FuStructOpromPci *st, guint16 value)
716
0
{
717
0
    g_return_if_fail(st != NULL);
718
0
    fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN);
719
0
}
720
/**
721
 * fu_struct_oprom_pci_new: (skip):
722
 **/
723
FuStructOpromPci *
724
fu_struct_oprom_pci_new(void)
725
741
{
726
741
    FuStructOpromPci *st = fu_struct_oprom_pci_new_internal();
727
741
    st->buf = g_byte_array_sized_new(28);
728
741
    fu_byte_array_set_size(st->buf, 28, 0x0);
729
741
    fu_struct_oprom_pci_set_signature(st, 0x52494350);
730
741
    return st;
731
741
}
732
/**
733
 * fu_struct_oprom_pci_to_string: (skip):
734
 **/
735
static gchar *
736
fu_struct_oprom_pci_to_string(const FuStructOpromPci *st)
737
0
{
738
0
    g_autoptr(GString) str = g_string_new("FuStructOpromPci:\n");
739
0
    g_return_val_if_fail(st != NULL, NULL);
740
0
    g_string_append_printf(str, "  signature: 0x%x\n",
741
0
                           (guint) fu_struct_oprom_pci_get_signature(st));
742
0
    g_string_append_printf(str, "  vendor_id: 0x%x\n",
743
0
                           (guint) fu_struct_oprom_pci_get_vendor_id(st));
744
0
    g_string_append_printf(str, "  device_id: 0x%x\n",
745
0
                           (guint) fu_struct_oprom_pci_get_device_id(st));
746
0
    g_string_append_printf(str, "  device_list_pointer: 0x%x\n",
747
0
                           (guint) fu_struct_oprom_pci_get_device_list_pointer(st));
748
0
    g_string_append_printf(str, "  structure_length: 0x%x\n",
749
0
                           (guint) fu_struct_oprom_pci_get_structure_length(st));
750
0
    g_string_append_printf(str, "  structure_revision: 0x%x\n",
751
0
                           (guint) fu_struct_oprom_pci_get_structure_revision(st));
752
0
    g_string_append_printf(str, "  class_code: 0x%x\n",
753
0
                           (guint) fu_struct_oprom_pci_get_class_code(st));
754
0
    g_string_append_printf(str, "  image_length: 0x%x\n",
755
0
                           (guint) fu_struct_oprom_pci_get_image_length(st));
756
0
    g_string_append_printf(str, "  image_revision: 0x%x\n",
757
0
                           (guint) fu_struct_oprom_pci_get_image_revision(st));
758
0
    g_string_append_printf(str, "  code_type: 0x%x\n",
759
0
                           (guint) fu_struct_oprom_pci_get_code_type(st));
760
0
    {
761
0
        const gchar *tmp = fu_oprom_indicator_flags_to_string(fu_struct_oprom_pci_get_indicator(st));
762
0
        if (tmp != NULL) {
763
0
            g_string_append_printf(str, "  indicator: 0x%x [%s]\n", (guint) fu_struct_oprom_pci_get_indicator(st), tmp);
764
0
        } else {
765
0
            g_string_append_printf(str, "  indicator: 0x%x\n", (guint) fu_struct_oprom_pci_get_indicator(st));
766
0
        }
767
0
    }
768
0
    g_string_append_printf(str, "  max_runtime_image_length: 0x%x\n",
769
0
                           (guint) fu_struct_oprom_pci_get_max_runtime_image_length(st));
770
0
    g_string_append_printf(str, "  conf_util_code_header_pointer: 0x%x\n",
771
0
                           (guint) fu_struct_oprom_pci_get_conf_util_code_header_pointer(st));
772
0
    g_string_append_printf(str, "  dmtf_clp_entry_point_pointer: 0x%x\n",
773
0
                           (guint) fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer(st));
774
0
    if (str->len > 0)
775
0
        g_string_set_size(str, str->len - 1);
776
0
    return g_string_free(g_steal_pointer(&str), FALSE);
777
0
}
778
static gboolean
779
fu_struct_oprom_pci_validate_internal(FuStructOpromPci *st, GError **error)
780
804
{
781
804
    g_return_val_if_fail(st != NULL, FALSE);
782
804
    if (fu_struct_oprom_pci_get_signature(st) != 0x52494350) {
783
43
        g_set_error(error,
784
43
                    FWUPD_ERROR,
785
43
                    FWUPD_ERROR_INVALID_DATA,
786
43
                    "constant FuStructOpromPci.signature was not valid, "
787
43
                    "expected 0x%x and got 0x%x",
788
43
                    (guint) 0x52494350,
789
43
                    (guint) fu_struct_oprom_pci_get_signature(st));
790
43
        return FALSE;
791
43
    }
792
761
    return TRUE;
793
804
}
794
static gboolean
795
fu_struct_oprom_pci_parse_internal(FuStructOpromPci *st, GError **error)
796
804
{
797
804
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
798
0
        g_autofree gchar *str = fu_struct_oprom_pci_to_string(st);
799
0
        g_debug("%s", str);
800
0
    }
801
804
    if (!fu_struct_oprom_pci_validate_internal(st, error))
802
43
        return FALSE;
803
761
    return TRUE;
804
804
}
805
/**
806
 * fu_struct_oprom_pci_parse_stream: (skip):
807
 **/
808
FuStructOpromPci *
809
fu_struct_oprom_pci_parse_stream(GInputStream *stream, gsize offset, GError **error)
810
846
{
811
846
    g_autoptr(FuStructOpromPci) st = fu_struct_oprom_pci_new_internal();
812
846
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
813
846
    if (st->buf == NULL) {
814
29
        g_prefix_error(error, "FuStructOpromPci failed read of 0x%x: ", (guint) 28);
815
29
        return NULL;
816
29
    }
817
817
    if (st->buf->len != 28) {
818
13
        g_set_error(error,
819
13
                    FWUPD_ERROR,
820
13
                    FWUPD_ERROR_INVALID_DATA,
821
13
                    "FuStructOpromPci requested 0x%x and got 0x%x",
822
13
                    (guint) 28,
823
13
                    (guint) st->buf->len);
824
13
        return NULL;
825
13
    }
826
804
    if (!fu_struct_oprom_pci_parse_internal(st, error))
827
43
        return NULL;
828
761
    return g_steal_pointer(&st);
829
804
}