Coverage Report

Created: 2025-11-24 06:59

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