iPXE
blob.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <string.h>
28#include <errno.h>
29#include <ipxe/malloc.h>
30#include <ipxe/xfer.h>
31#include <ipxe/process.h>
32#include <ipxe/blob.h>
33
34/** @file
35 *
36 * Openable data blobs
37 *
38 * Within the iPXE data transfer interface model, openers are fully
39 * asynchronous and may not deliver any data until after the opener
40 * has returned. An openable data blob provides a way to open an
41 * interface that will then simply return a single fixed blob of data.
42 */
43
44/** An openable data blob */
45struct blob {
46 /** Reference count */
47 struct refcnt refcnt;
48 /** Data transfer interface */
50 /** Download process */
52 /** Data */
53 const void *data;
54 /** Length of data */
55 size_t len;
56};
57
58/**
59 * Close data blob
60 *
61 * @v blob Data blob
62 * @v rc Reason for close
63 */
64static void blob_close ( struct blob *blob, int rc ) {
65
66 /* Stop process */
68
69 /* Shut down interface */
71}
72
73/**
74 * Process data blob
75 *
76 * @v blob Data blob
77 */
78static void blob_step ( struct blob *blob ) {
79 int rc;
80
81 /* Deliver data when window opens */
82 if ( xfer_window ( &blob->xfer ) ) {
84 blob_close ( blob, rc );
85 }
86}
87
88/** Data blob interface operations */
91 INTF_OP ( intf_close, struct blob *, blob_close ),
92};
93
94/** Data blob interface descriptor */
96 INTF_DESC ( struct blob, xfer, blob_xfer_op );
97
98/** Data blob process descriptor */
101
102/**
103 * Open data blob
104 *
105 * @v xfer Data transfer interface
106 * @v data Data
107 * @v len Length of data
108 * @ret rc Return status code
109 */
110int blob_open ( struct interface *xfer, const void *data, size_t len ) {
111 struct blob *blob;
112 void *copy;
113
114 /* Allocate and initialise structure */
115 blob = zalloc ( sizeof ( *blob ) + len );
116 if ( ! blob )
117 return -ENOMEM;
118 ref_init ( &blob->refcnt, NULL );
121 copy = ( ( ( void * ) blob ) + sizeof ( *blob ) );
122 blob->data = copy;
123 blob->len = len;
124 memcpy ( copy, data, len );
125
126 /* Attach parent interface, mortalise self, and return */
128 ref_put ( &blob->refcnt );
129 return 0;
130}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static struct process_descriptor blob_process_desc
Data blob process descriptor.
Definition blob.c:99
static void blob_close(struct blob *blob, int rc)
Close data blob.
Definition blob.c:64
int blob_open(struct interface *xfer, const void *data, size_t len)
Open data blob.
Definition blob.c:110
static struct interface_operation blob_xfer_op[]
Data blob interface operations.
Definition blob.c:89
static void blob_step(struct blob *blob)
Process data blob.
Definition blob.c:78
static struct interface_descriptor blob_xfer_desc
Data blob interface descriptor.
Definition blob.c:95
Openable data blobs.
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
Error codes.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define ENOMEM
Not enough space.
Definition errno.h:535
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition interface.h:81
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
Dynamic memory allocation.
void process_del(struct process *process)
Remove process from process list.
Definition process.c:80
Processes.
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition process.h:98
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition process.h:162
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
An openable data blob.
Definition blob.c:45
struct refcnt refcnt
Reference count.
Definition blob.c:47
struct interface xfer
Data transfer interface.
Definition blob.c:49
struct process process
Download process.
Definition blob.c:51
const void * data
Data.
Definition blob.c:53
size_t len
Length of data.
Definition blob.c:55
An object interface descriptor.
Definition interface.h:56
An object interface operation.
Definition interface.h:18
An object interface.
Definition interface.h:125
A process descriptor.
Definition process.h:32
A process.
Definition process.h:18
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition xfer.c:117
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition xfer.c:147
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
Definition xfer.c:289
Data transfer interfaces.