iPXE
Data Structures | Functions | Variables
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. More...
 
static int efi_download_deliver_iob (struct efi_download_file *file, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Process received data. More...
 
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. More...
 
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. More...
 
static EFI_STATUS EFIAPI efi_download_poll (IPXE_DOWNLOAD_PROTOCOL *This __unused)
 Poll for more data from iPXE. More...
 
int efi_download_install (EFI_HANDLE handle)
 Install iPXE download protocol. More...
 
void efi_download_uninstall (EFI_HANDLE handle)
 Uninstall iPXE download protocol. More...
 

Variables

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ efi_download_close()

static 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:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:279
void * context
Callback context.
Definition: efi_download.c:52
IPXE_DOWNLOAD_FINISH_CALLBACK finish_callback
Finish callback.
Definition: efi_download.c:49
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:100
struct interface xfer
Data transfer interface that provides downloaded data.
Definition: efi_download.c:40
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:167

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()

static 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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
IPXE_DOWNLOAD_DATA_CALLBACK data_callback
Data callback.
Definition: efi_download.c:46
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:48
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
void * context
Callback context.
Definition: efi_download.c:52
ring len
Length.
Definition: dwmac.h:231
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
size_t pos
Current file position.
Definition: efi_download.c:43
void * data
Start of data.
Definition: iobuf.h:53
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
uint8_t meta
Metadata flags.
Definition: ena.h:14

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()

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 
)
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 
142  efi_snp_claim();
143 
144  file = malloc ( sizeof ( struct efi_download_file ) );
145  if ( file == NULL ) {
146  efi_snp_release();
147  return EFI_OUT_OF_RESOURCES;
148  }
149 
151  rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
152  if ( rc ) {
153  free ( file );
154  efi_snp_release();
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
IPXE_DOWNLOAD_DATA_CALLBACK data_callback
Data callback.
Definition: efi_download.c:46
void * context
Callback context.
Definition: efi_download.c:52
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:92
A single in-progress file.
Definition: efi_download.c:38
IPXE_DOWNLOAD_FINISH_CALLBACK finish_callback
Finish callback.
Definition: efi_download.c:49
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:124
Location is a URI string.
Definition: open.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:100
static struct interface_descriptor efi_download_file_xfer_desc
EFI download data transfer interface descriptor.
Definition: efi_download.c:117
int xfer_open(struct interface *intf, int type,...)
Open location.
Definition: open.c:203
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
size_t pos
Current file position.
Definition: efi_download.c:43
#define EFI_SUCCESS
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:115
struct interface xfer
Data transfer interface that provides downloaded data.
Definition: efi_download.c:40
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:204
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:167

References 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, efi_download_file::xfer, and xfer_open().

◆ efi_download_abort()

static 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 }
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
PXENV_STATUS_t Status
PXE status code.
Definition: pxe_api.h:57
A single in-progress file.
Definition: efi_download.c:38
#define EFI_SUCCESS
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:115
static void efi_download_close(struct efi_download_file *file, int rc)
Transfer finished or was aborted.
Definition: efi_download.c:63

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

◆ efi_download_poll()

static 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 }
#define EFI_SUCCESS
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:115
void step(void)
Single-step a single process.
Definition: process.c:99

References 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  {
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 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface
Publicly exposed iPXE download protocol.
Definition: efi_download.c:200
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
EFI_SYSTEM_TABLE * efi_systab
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint16_t handle
Handle.
Definition: smbios.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static EFI_GUID ipxe_download_protocol_guid
iPXE download protocol GUID
Definition: efi_download.c:35

References EFI_SYSTEM_TABLE::BootServices, DBG, EEFI, 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  {
239 
241  handle,
244 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
EFI Boot Services Table.
Definition: UefiSpec.h:1931
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2011
static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface
Publicly exposed iPXE download protocol.
Definition: efi_download.c:200
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static EFI_GUID ipxe_download_protocol_guid
iPXE download protocol GUID
Definition: efi_download.c:35

References EFI_SYSTEM_TABLE::BootServices, 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 35 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:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:250
static int efi_download_deliver_iob(struct efi_download_file *file, struct io_buffer *iobuf, struct xfer_metadata *meta)
Process received data.
Definition: efi_download.c:80
A single in-progress file.
Definition: efi_download.c:38
#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
static void efi_download_close(struct efi_download_file *file, int rc)
Transfer finished or was aborted.
Definition: efi_download.c:63

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.
Definition: efi_download.c:111
A single in-progress file.
Definition: efi_download.c:38
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:81
struct interface xfer
Data transfer interface that provides downloaded data.
Definition: efi_download.c:40

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_poll(IPXE_DOWNLOAD_PROTOCOL *This __unused)
Poll for more data from iPXE.
Definition: efi_download.c:194
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.
Definition: efi_download.c:133
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.
Definition: efi_download.c:177

Publicly exposed iPXE download protocol.

Definition at line 200 of file efi_download.c.

Referenced by efi_download_install(), and efi_download_uninstall().