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.
void efi_pxe_uninstall (EFI_HANDLE handle)
 Uninstall PXE base code protocol.

Detailed Description

EFI PXE base code protocol.

Definition in file efi_pxe.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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 1588 of file efi_pxe.c.

References AF_INET6, efi_pxe::apple, efi_pxe::base, EFI_SYSTEM_TABLE::BootServices, efi_pxe::buf, DBGC, EEFI, efi_apple_net_boot_protocol_guid, efi_handle_name(), efi_pxe_base_code_protocol_guid, efi_pxe_buf_operations, efi_pxe_free(), efi_pxe_start(), efi_systab, ENOMEM, FALSE, fetch_ipv4_setting(), efi_pxe::handle, handle, INIT_LIST_HEAD, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, intf_init(), efi_pxe::list, list_add_tail, memcpy(), efi_pxe::mode, _EFI_PXE_BASE_CODE_PROTOCOL::Mode, efi_pxe::name, net_device::name, 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, in_addr::s_addr, strerror(), tcpip_net_protocol(), efi_pxe::tftp, efi_pxe::udp, EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and zalloc().

Referenced by efi_image_exec().

                                                                     {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        struct tcpip_net_protocol *ipv6 = tcpip_net_protocol ( AF_INET6 );
        struct efi_pxe *pxe;
        struct in_addr ip;
        BOOLEAN use_ipv6;
        EFI_STATUS efirc;
        int rc;

        /* Allocate and initialise structure */
        pxe = zalloc ( sizeof ( *pxe ) );
        if ( ! pxe ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        ref_init ( &pxe->refcnt, efi_pxe_free );
        pxe->netdev = netdev_get ( netdev );
        pxe->name = netdev->name;
        pxe->handle = handle;
        memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
        pxe->base.Mode = &pxe->mode;
        memcpy ( &pxe->apple, &efi_apple_net_boot_protocol,
                 sizeof ( pxe->apple ) );
        pxe->buf.op = &efi_pxe_buf_operations;
        intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
        intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
        INIT_LIST_HEAD ( &pxe->queue );
        process_init_stopped ( &pxe->process, &efi_pxe_process_desc,
                               &pxe->refcnt );

        /* Crude heuristic: assume that we prefer to use IPv4 if we
         * have an IPv4 address for the network device, otherwise
         * prefer IPv6 (if available).
         */
        fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting, &ip );
        use_ipv6 = ( ip.s_addr ? FALSE : ( ipv6 != NULL ) );

        /* Start base code */
        efi_pxe_start ( &pxe->base, use_ipv6 );

        /* Install PXE base code protocol */
        if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
                        &handle,
                        &efi_pxe_base_code_protocol_guid, &pxe->base,
                        &efi_apple_net_boot_protocol_guid, &pxe->apple,
                        NULL ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
                       pxe->name, strerror ( rc ) );
                goto err_install_protocol;
        }

        /* Transfer reference to list and return */
        list_add_tail ( &pxe->list, &efi_pxes );
        DBGC ( pxe, "PXE %s installed for %s\n",
               pxe->name, efi_handle_name ( handle ) );
        return 0;

        bs->UninstallMultipleProtocolInterfaces (
                        handle,
                        &efi_pxe_base_code_protocol_guid, &pxe->base,
                        &efi_apple_net_boot_protocol_guid, &pxe->apple,
                        NULL );
 err_install_protocol:
        ref_put ( &pxe->refcnt );
 err_alloc:
        return rc;
}
void efi_pxe_uninstall ( EFI_HANDLE  handle)

Uninstall PXE base code protocol.

Parameters:
handleEFI handle

Definition at line 1662 of file efi_pxe.c.

References efi_pxe::apple, efi_pxe::base, EFI_SYSTEM_TABLE::BootServices, DBG, efi_apple_net_boot_protocol_guid, efi_handle_name(), efi_pxe_base_code_protocol_guid, efi_pxe_find(), efi_pxe_stop(), efi_systab, efi_pxe::list, list_del, NULL, ref_put, efi_pxe::refcnt, and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

                                             {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        struct efi_pxe *pxe;

        /* Locate PXE base code */
        pxe = efi_pxe_find ( handle );
        if ( ! handle ) {
                DBG ( "PXE could not find base code for %s\n",
                      efi_handle_name ( handle ) );
                return;
        }

        /* Stop base code */
        efi_pxe_stop ( &pxe->base );

        /* Uninstall PXE base code protocol */
        bs->UninstallMultipleProtocolInterfaces (
                        handle,
                        &efi_pxe_base_code_protocol_guid, &pxe->base,
                        &efi_apple_net_boot_protocol_guid, &pxe->apple,
                        NULL );

        /* Remove from list and drop list's reference */
        list_del ( &pxe->list );
        ref_put ( &pxe->refcnt );
}