iPXE
efi_download.c File Reference
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/open.h>
#include <ipxe/process.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_download.h>

Go to the source code of this file.

Data Structures

struct  efi_download_file
 A single in-progress file. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FILE_SECBOOT (PERMITTED)
static void efi_download_close (struct efi_download_file *file, int rc)
 Transfer finished or was aborted.
static int efi_download_deliver_iob (struct efi_download_file *file, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Process received data.
static EFI_STATUS EFIAPI efi_download_start (IPXE_DOWNLOAD_PROTOCOL *This __unused, CHAR8 *Url, IPXE_DOWNLOAD_DATA_CALLBACK DataCallback, IPXE_DOWNLOAD_FINISH_CALLBACK FinishCallback, VOID *Context, IPXE_DOWNLOAD_FILE *File)
 Start downloading a file, and register callback functions to handle the download.
static EFI_STATUS EFIAPI efi_download_abort (IPXE_DOWNLOAD_PROTOCOL *This __unused, IPXE_DOWNLOAD_FILE File, EFI_STATUS Status)
 Forcibly abort downloading a file that is currently in progress.
static EFI_STATUS EFIAPI efi_download_poll (IPXE_DOWNLOAD_PROTOCOL *This __unused)
 Poll for more data from iPXE.
int efi_download_install (EFI_HANDLE handle)
 Install iPXE download protocol.
void efi_download_uninstall (EFI_HANDLE handle)
 Uninstall iPXE download protocol.

Variables

static EFI_GUID ipxe_download_protocol_guid = IPXE_DOWNLOAD_PROTOCOL_GUID
 iPXE download protocol GUID
static struct interface_operation efi_xfer_operations []
 Data transfer interface operations.
static struct interface_descriptor efi_download_file_xfer_desc
 EFI download data transfer interface descriptor.
static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface
 Publicly exposed iPXE download protocol.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efi_download_close()

void efi_download_close ( struct efi_download_file * file,
int rc )
static

Transfer finished or was aborted.

Parameters
fileData transfer file
rcReason for close

Definition at line 63 of file efi_download.c.

63 {
64
65 file->finish_callback ( file->context, EFIRC ( rc ) );
66
67 intf_shutdown ( &file->xfer, rc );
68
70}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition efi_snp.h:100
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition efi.h:167
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
IPXE_DOWNLOAD_FINISH_CALLBACK finish_callback
Finish callback.
struct interface xfer
Data transfer interface that provides downloaded data.
void * context
Callback context.

References efi_download_file::context, efi_snp_release(), EFIRC, efi_download_file::finish_callback, intf_shutdown(), rc, and efi_download_file::xfer.

Referenced by efi_download_abort().

◆ efi_download_deliver_iob()

int efi_download_deliver_iob ( struct efi_download_file * file,
struct io_buffer * iobuf,
struct xfer_metadata * meta )
static

Process received data.

Parameters
fileData transfer file
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 80 of file efi_download.c.

82 {
83 EFI_STATUS efirc;
84 size_t len = iob_len ( iobuf );
85 int rc;
86
87 /* Calculate new buffer position */
88 if ( meta->flags & XFER_FL_ABS_OFFSET )
89 file->pos = 0;
90 file->pos += meta->offset;
91
92 /* Call out to the data handler */
93 if ( ( efirc = file->data_callback ( file->context, iobuf->data,
94 len, file->pos ) ) != 0 ) {
95 rc = -EEFI ( efirc );
96 goto err_callback;
97 }
98
99 /* Update current buffer position */
100 file->pos += len;
101
102 /* Success */
103 rc = 0;
104
105 err_callback:
106 free_iob ( iobuf );
107 return rc;
108}
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
ring len
Length.
Definition dwmac.h:226
uint8_t meta
Metadata flags.
Definition ena.h:3
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
IPXE_DOWNLOAD_DATA_CALLBACK data_callback
Data callback.
size_t pos
Current file position.
void * data
Start of data.
Definition iobuf.h:53
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition xfer.h:48

References efi_download_file::context, io_buffer::data, efi_download_file::data_callback, EEFI, free_iob(), iob_len(), len, meta, efi_download_file::pos, rc, and XFER_FL_ABS_OFFSET.

◆ efi_download_start()

EFI_STATUS EFIAPI efi_download_start ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
CHAR8 * Url,
IPXE_DOWNLOAD_DATA_CALLBACK DataCallback,
IPXE_DOWNLOAD_FINISH_CALLBACK FinishCallback,
VOID * Context,
IPXE_DOWNLOAD_FILE * File )
static

Start downloading a file, and register callback functions to handle the download.

Parameters
ThisiPXE Download Protocol instance
UrlURL to download from
DataCallbackCallback that will be invoked when data arrives
FinishCallbackCallback that will be invoked when the download ends
ContextContext passed to the Data and Finish callbacks
FileToken that can be used to abort the download
Return values
StatusEFI status code

Definition at line 133 of file efi_download.c.

138 {
139 struct efi_download_file *file;
140 int rc;
141
143
144 file = malloc ( sizeof ( struct efi_download_file ) );
145 if ( file == NULL ) {
148 }
149
151 rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
152 if ( rc ) {
153 free ( file );
155 return EFIRC ( rc );
156 }
157
158 file->pos = 0;
159 file->data_callback = DataCallback;
160 file->finish_callback = FinishCallback;
161 file->context = Context;
162 *File = file;
163 return EFI_SUCCESS;
164}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
#define EFI_SUCCESS
Enumeration of EFI_STATUS.
static struct interface_descriptor efi_download_file_xfer_desc
EFI download data transfer interface descriptor.
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition efi_snp.h:92
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
int xfer_open(struct interface *intf, int type,...)
Open location.
Definition open.c:203
@ LOCATION_URI_STRING
Location is a URI string.
Definition open.h:35
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
A single in-progress file.

References __unused, efi_download_file::context, efi_download_file::data_callback, efi_download_file_xfer_desc, EFI_OUT_OF_RESOURCES, efi_snp_claim(), efi_snp_release(), EFI_SUCCESS, EFIRC, efi_download_file::finish_callback, free, intf_init(), LOCATION_URI_STRING, malloc(), NULL, efi_download_file::pos, rc, VOID, efi_download_file::xfer, and xfer_open().

◆ efi_download_abort()

EFI_STATUS EFIAPI efi_download_abort ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
IPXE_DOWNLOAD_FILE File,
EFI_STATUS Status )
static

Forcibly abort downloading a file that is currently in progress.

It is not safe to call this function after the Finish callback has executed.

Parameters
ThisiPXE Download Protocol instance
FileToken obtained from Start
StatusReason for aborting the download
Return values
StatusEFI status code

Definition at line 177 of file efi_download.c.

179 {
180 struct efi_download_file *file = File;
181
182 efi_download_close ( file, -EEFI ( Status ) );
183 return EFI_SUCCESS;
184}
static void efi_download_close(struct efi_download_file *file, int rc)
Transfer finished or was aborted.
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:0

References __unused, EEFI, efi_download_close(), EFI_SUCCESS, and Status.

◆ efi_download_poll()

EFI_STATUS EFIAPI efi_download_poll ( IPXE_DOWNLOAD_PROTOCOL *This __unused)
static

Poll for more data from iPXE.

This function will invoke the registered callbacks if data is available or if downloads complete.

Parameters
ThisiPXE Download Protocol instance
Return values
StatusEFI status code

Definition at line 194 of file efi_download.c.

194 {
195 step();
196 return EFI_SUCCESS;
197}
void step(void)
Single-step a single process.
Definition process.c:99

References __unused, EFI_SUCCESS, and step().

◆ efi_download_install()

int efi_download_install ( EFI_HANDLE handle)

Install iPXE download protocol.

Parameters
handleEFI handle
Return values
rcReturn status code

Definition at line 212 of file efi_download.c.

212 {
213 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
214 EFI_STATUS efirc;
215 int rc;
216
218 &handle,
221 NULL );
222 if ( efirc ) {
223 rc = -EEFI ( efirc );
224 DBG ( "Could not install download protocol: %s\n",
225 strerror ( rc ) );
226 return rc;
227 }
228
229 return 0;
230}
static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface
Publicly exposed iPXE download protocol.
static EFI_GUID ipxe_download_protocol_guid
iPXE download protocol GUID
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition smbios.h:5
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition UefiSpec.h:2010

References DBG, EEFI, EFI_HANDLE, efi_systab, handle, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, ipxe_download_protocol_guid, ipxe_download_protocol_interface, NULL, rc, and strerror().

Referenced by efi_image_exec().

◆ efi_download_uninstall()

void efi_download_uninstall ( EFI_HANDLE handle)

Uninstall iPXE download protocol.

Parameters
handleEFI handle

Definition at line 237 of file efi_download.c.

237 {
238 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
239
241 handle,
244}
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition UefiSpec.h:2011

References EFI_HANDLE, efi_systab, handle, ipxe_download_protocol_guid, ipxe_download_protocol_interface, NULL, and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

Variable Documentation

◆ ipxe_download_protocol_guid

EFI_GUID ipxe_download_protocol_guid = IPXE_DOWNLOAD_PROTOCOL_GUID
static

iPXE download protocol GUID

Definition at line 34 of file efi_download.c.

Referenced by efi_download_install(), and efi_download_uninstall().

◆ efi_xfer_operations

struct interface_operation efi_xfer_operations[]
static
Initial value:
= {
}
static int efi_download_deliver_iob(struct efi_download_file *file, struct io_buffer *iobuf, struct xfer_metadata *meta)
Process received data.
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition xfer.c:195

Data transfer interface operations.

Definition at line 111 of file efi_download.c.

◆ efi_download_file_xfer_desc

struct interface_descriptor efi_download_file_xfer_desc
static
Initial value:
=
static struct interface_operation efi_xfer_operations[]
Data transfer interface operations.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition interface.h:81

EFI download data transfer interface descriptor.

Definition at line 117 of file efi_download.c.

Referenced by efi_download_start().

◆ ipxe_download_protocol_interface

IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface
static
Initial value:
= {
}
static EFI_STATUS EFIAPI efi_download_start(IPXE_DOWNLOAD_PROTOCOL *This __unused, CHAR8 *Url, IPXE_DOWNLOAD_DATA_CALLBACK DataCallback, IPXE_DOWNLOAD_FINISH_CALLBACK FinishCallback, VOID *Context, IPXE_DOWNLOAD_FILE *File)
Start downloading a file, and register callback functions to handle the download.
static EFI_STATUS EFIAPI efi_download_abort(IPXE_DOWNLOAD_PROTOCOL *This __unused, IPXE_DOWNLOAD_FILE File, EFI_STATUS Status)
Forcibly abort downloading a file that is currently in progress.
static EFI_STATUS EFIAPI efi_download_poll(IPXE_DOWNLOAD_PROTOCOL *This __unused)
Poll for more data from iPXE.

Publicly exposed iPXE download protocol.

Definition at line 200 of file efi_download.c.

200 {
201 .Start = efi_download_start,
202 .Abort = efi_download_abort,
203 .Poll = efi_download_poll
204};

Referenced by efi_download_install(), and efi_download_uninstall().