iPXE
Functions
efi_pxe.h File Reference

EFI PXE base code protocol. More...

#include <ipxe/efi/efi.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_pxe_install (EFI_HANDLE handle, struct net_device *netdev)
 Install PXE base code protocol. More...
 
void efi_pxe_uninstall (EFI_HANDLE handle)
 Uninstall PXE base code protocol. More...
 

Detailed Description

EFI PXE base code protocol.

Definition in file efi_pxe.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_pxe_install()

int efi_pxe_install ( EFI_HANDLE  handle,
struct net_device netdev 
)

Install PXE base code protocol.

Parameters
handleEFI handle
netdevUnderlying network device
Return values
rcReturn status code

Definition at line 1590 of file efi_pxe.c.

1590  {
1592  struct tcpip_net_protocol *ipv6 = tcpip_net_protocol ( AF_INET6 );
1593  struct efi_pxe *pxe;
1594  struct in_addr ip;
1595  BOOLEAN use_ipv6;
1596  int leak = 0;
1597  EFI_STATUS efirc;
1598  int rc;
1599 
1600  /* Allocate and initialise structure */
1601  pxe = zalloc ( sizeof ( *pxe ) );
1602  if ( ! pxe ) {
1603  rc = -ENOMEM;
1604  goto err_alloc;
1605  }
1606  ref_init ( &pxe->refcnt, efi_pxe_free );
1607  pxe->netdev = netdev_get ( netdev );
1608  pxe->name = netdev->name;
1609  pxe->handle = handle;
1610  memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1611  pxe->base.Mode = &pxe->mode;
1613  sizeof ( pxe->apple ) );
1614  pxe->buf.op = &efi_pxe_buf_operations;
1615  intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1616  intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
1617  INIT_LIST_HEAD ( &pxe->queue );
1619  &pxe->refcnt );
1620 
1621  /* Crude heuristic: assume that we prefer to use IPv4 if we
1622  * have an IPv4 address for the network device, otherwise
1623  * prefer IPv6 (if available).
1624  */
1625  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting, &ip );
1626  use_ipv6 = ( ip.s_addr ? FALSE : ( ipv6 != NULL ) );
1627 
1628  /* Start base code */
1629  efi_pxe_start ( &pxe->base, use_ipv6 );
1630 
1631  /* Install PXE base code protocol */
1632  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1633  &handle,
1636  NULL ) ) != 0 ) {
1637  rc = -EEFI ( efirc );
1638  DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
1639  pxe->name, strerror ( rc ) );
1640  goto err_install_protocol;
1641  }
1642 
1643  /* Transfer reference to list and return */
1644  list_add_tail ( &pxe->list, &efi_pxes );
1645  DBGC ( pxe, "PXE %s installed for %s\n",
1646  pxe->name, efi_handle_name ( handle ) );
1647  return 0;
1648 
1649  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1650  handle,
1653  NULL ) ) != 0 ) {
1654  DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1655  pxe->name, strerror ( -EEFI ( efirc ) ) );
1656  leak = 1;
1657  }
1658  efi_nullify_pxe ( &pxe->base );
1659  efi_nullify_apple ( &pxe->apple );
1660  err_install_protocol:
1661  if ( ! leak )
1662  ref_put ( &pxe->refcnt );
1663  err_alloc:
1664  if ( leak )
1665  DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1666  return rc;
1667 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_PXE_BASE_CODE_MODE mode
PXE base code mode.
Definition: efi_pxe.c:84
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
struct list_head list
List of PXE base codes.
Definition: efi_pxe.c:77
static EFI_STATUS EFIAPI efi_pxe_start(EFI_PXE_BASE_CODE_PROTOCOL *base, BOOLEAN use_ipv6)
Start PXE base code.
Definition: efi_pxe.c:751
struct refcnt refcnt
Reference count.
Definition: efi_pxe.c:71
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
A PXE base code.
Definition: efi_pxe.c:69
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:912
unsigned char BOOLEAN
static struct interface_descriptor efi_pxe_tftp_desc
PXE file data transfer interface descriptor.
Definition: efi_pxe.c:415
EFI_PXE_BASE_CODE_PROTOCOL base
PXE base code protocol.
Definition: efi_pxe.c:82
#define DBGC(...)
Definition: compiler.h:505
struct interface udp
UDP interface.
Definition: efi_pxe.c:104
struct xfer_buffer buf
Data transfer buffer.
Definition: efi_pxe.c:94
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1996
EFI_APPLE_NET_BOOT_PROTOCOL apple
Apple NetBoot protocol.
Definition: efi_pxe.c:86
EFI_GUID efi_pxe_base_code_protocol_guid
PXE base code protocol GUID.
Definition: efi_guid.c:291
static struct process_descriptor efi_pxe_process_desc
UDP close process descriptor.
Definition: efi_pxe.c:624
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
const char * name
Name.
Definition: efi_pxe.c:75
EFI_HANDLE handle
Installed handle.
Definition: efi_pxe.c:80
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct net_device * netdev
Underlying network device.
Definition: efi_pxe.c:73
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct tcpip_net_protocol * tcpip_net_protocol(sa_family_t sa_family)
Find TCP/IP network-layer protocol.
Definition: tcpip.c:68
void efi_nullify_pxe(EFI_PXE_BASE_CODE_PROTOCOL *pxe)
Nullify PXE base code protocol.
Definition: efi_null.c:536
static struct net_device * netdev
Definition: gdbudp.c:52
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
struct xfer_buffer_operations * op
Data transfer buffer operations.
Definition: xferbuf.h:27
static EFI_APPLE_NET_BOOT_PROTOCOL efi_apple_net_boot_protocol
Apple NetBoot protocol.
Definition: efi_pxe.c:1571
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct xfer_buffer_operations efi_pxe_buf_operations
PXE data transfer buffer operations.
Definition: efi_pxe.c:343
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1917
IP address structure.
Definition: in.h:39
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1997
IP4_t ip
Destination IP address.
Definition: pxe_api.h:58
static struct interface_descriptor efi_pxe_udp_desc
PXE UDP interface descriptor.
Definition: efi_pxe.c:564
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition: process.h:145
struct interface tftp
(M)TFTP download interface
Definition: efi_pxe.c:97
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
EFI_GUID efi_apple_net_boot_protocol_guid
Apple NetBoot protocol GUID.
Definition: efi_guid.c:107
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct process process
UDP interface closer process.
Definition: efi_pxe.c:108
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head queue
List of received UDP packets.
Definition: efi_pxe.c:106
#define FALSE
Definition: tlan.h:45
A network-layer protocol of the TCP/IP stack (eg.
Definition: tcpip.h:140
EFI_SYSTEM_TABLE * efi_systab
void efi_nullify_apple(EFI_APPLE_NET_BOOT_PROTOCOL *apple)
Nullify Apple Net Boot protocol.
Definition: efi_null.c:571
EFI_PXE_BASE_CODE_MODE * Mode
The pointer to the EFI_PXE_BASE_CODE_MODE data for this device.
Definition: PxeBaseCode.h:930
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
static void efi_pxe_free(struct refcnt *refcnt)
Free PXE base code.
Definition: efi_pxe.c:116
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static EFI_PXE_BASE_CODE_PROTOCOL efi_pxe_base_code_protocol
PXE base code protocol.
Definition: efi_pxe.c:1490
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References AF_INET6, efi_pxe::apple, efi_pxe::base, EFI_SYSTEM_TABLE::BootServices, efi_pxe::buf, DBGC, EEFI, efi_apple_net_boot_protocol, efi_apple_net_boot_protocol_guid, efi_handle_name(), efi_nullify_apple(), efi_nullify_pxe(), efi_pxe_base_code_protocol, efi_pxe_base_code_protocol_guid, efi_pxe_buf_operations, efi_pxe_free(), efi_pxe_process_desc, efi_pxe_start(), efi_pxe_tftp_desc, efi_pxe_udp_desc, efi_systab, ENOMEM, FALSE, fetch_ipv4_setting(), handle, efi_pxe::handle, INIT_LIST_HEAD, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, intf_init(), ip, efi_pxe::list, list_add_tail, memcpy(), efi_pxe::mode, _EFI_PXE_BASE_CODE_PROTOCOL::Mode, efi_pxe::name, net_device::name, netdev, efi_pxe::netdev, netdev_get(), netdev_settings(), NULL, xfer_buffer::op, efi_pxe::process, process_init_stopped(), efi_pxe::queue, rc, ref_init, ref_put, efi_pxe::refcnt, strerror(), tcpip_net_protocol(), efi_pxe::tftp, efi_pxe::udp, EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and zalloc().

Referenced by efi_image_exec().

◆ efi_pxe_uninstall()

void efi_pxe_uninstall ( EFI_HANDLE  handle)

Uninstall PXE base code protocol.

Parameters
handleEFI handle

Definition at line 1674 of file efi_pxe.c.

1674  {
1676  struct efi_pxe *pxe;
1677  int leak = efi_shutdown_in_progress;
1678  EFI_STATUS efirc;
1679 
1680  /* Locate PXE base code */
1681  pxe = efi_pxe_find ( handle );
1682  if ( ! handle ) {
1683  DBG ( "PXE could not find base code for %s\n",
1684  efi_handle_name ( handle ) );
1685  return;
1686  }
1687 
1688  /* Stop base code */
1689  efi_pxe_stop ( &pxe->base );
1690 
1691  /* Uninstall PXE base code protocol */
1692  if ( ( ! efi_shutdown_in_progress ) &&
1693  ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1694  handle,
1697  NULL ) ) != 0 ) ) {
1698  DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1699  pxe->name, strerror ( -EEFI ( efirc ) ) );
1700  leak = 1;
1701  }
1702  efi_nullify_pxe ( &pxe->base );
1703  efi_nullify_apple ( &pxe->apple );
1704 
1705  /* Remove from list and drop list's reference */
1706  list_del ( &pxe->list );
1707  if ( ! leak )
1708  ref_put ( &pxe->refcnt );
1709 
1710  /* Report leakage, if applicable */
1711  if ( leak && ( ! efi_shutdown_in_progress ) )
1712  DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1713 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
static struct efi_pxe * efi_pxe_find(EFI_HANDLE handle)
Locate PXE base code.
Definition: efi_pxe.c:132
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct list_head list
List of PXE base codes.
Definition: efi_pxe.c:77
struct refcnt refcnt
Reference count.
Definition: efi_pxe.c:71
A PXE base code.
Definition: efi_pxe.c:69
EFI_PXE_BASE_CODE_PROTOCOL base
PXE base code protocol.
Definition: efi_pxe.c:82
#define DBGC(...)
Definition: compiler.h:505
EFI_APPLE_NET_BOOT_PROTOCOL apple
Apple NetBoot protocol.
Definition: efi_pxe.c:86
EFI_GUID efi_pxe_base_code_protocol_guid
PXE base code protocol GUID.
Definition: efi_guid.c:291
const char * name
Name.
Definition: efi_pxe.c:75
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
void efi_nullify_pxe(EFI_PXE_BASE_CODE_PROTOCOL *pxe)
Nullify PXE base code protocol.
Definition: efi_null.c:536
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1997
EFI_GUID efi_apple_net_boot_protocol_guid
Apple NetBoot protocol GUID.
Definition: efi_guid.c:107
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
void efi_nullify_apple(EFI_APPLE_NET_BOOT_PROTOCOL *apple)
Nullify Apple Net Boot protocol.
Definition: efi_null.c:571
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static EFI_STATUS EFIAPI efi_pxe_stop(EFI_PXE_BASE_CODE_PROTOCOL *base)
Stop PXE base code.
Definition: efi_pxe.c:806
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58

References efi_pxe::apple, efi_pxe::base, EFI_SYSTEM_TABLE::BootServices, DBG, DBGC, EEFI, efi_apple_net_boot_protocol_guid, efi_handle_name(), efi_nullify_apple(), efi_nullify_pxe(), efi_pxe_base_code_protocol_guid, efi_pxe_find(), efi_pxe_stop(), efi_shutdown_in_progress, efi_systab, handle, efi_pxe::list, list_del, efi_pxe::name, NULL, ref_put, efi_pxe::refcnt, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().