Coverage Report

Created: 2025-07-11 06:31

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