123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- /** @file
- *
- * PXE Preboot API
- *
- */
-
- /* PXE API interface for Etherboot.
- *
- * Copyright (C) 2004 Michael Brown <mbrown@fensystems.co.uk>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include <stdint.h>
- #include <string.h>
- #include <malloc.h>
- #include <gpxe/uaccess.h>
- #include <gpxe/dhcp.h>
- #include "pxe.h"
- #include "pxe_callbacks.h"
-
- /**
- * UNLOAD BASE CODE STACK
- *
- * @v None -
- * @ret ...
- *
- */
- PXENV_EXIT_t pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) {
- DBG ( "PXENV_UNLOAD_STACK" );
-
- #if 0
- /* We need to call cleanup() at some point. The network card
- * has already been disabled by ENSURE_CAN_UNLOAD(), but for
- * the sake of completeness we should call the console_fini()
- * etc. that are part of cleanup().
- *
- * There seems to be a lack of consensus on which is the final
- * PXE API call to make, but it's a fairly safe bet that all
- * the potential shutdown sequences will include a call to
- * PXENV_UNLOAD_STACK at some point, so we may as well do it
- * here.
- */
- cleanup();
-
- if ( ! success ) {
- unload_stack->Status = PXENV_STATUS_KEEP_ALL;
- return PXENV_EXIT_FAILURE;
- }
- #endif
-
- unload_stack->Status = PXENV_STATUS_SUCCESS;
- return PXENV_EXIT_SUCCESS;
- }
-
- /* PXENV_GET_CACHED_INFO
- *
- * Status: working
- */
- PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
- *get_cached_info ) {
- struct dhcp_packet dhcppkt;
- void *data = NULL;
- size_t len;
- int msgtype;
- struct dhcp_option_block *options;
- userptr_t buffer;
- int rc;
-
- DBG ( "PXENV_GET_CACHED_INFO %d", get_cached_info->PacketType );
-
- /* This is really, really awkward to support with our multiple
- * sources of options.
- */
- if ( get_cached_info->BufferLimit == 0 ) {
- DBG ( " without an external buffer. Aargh." );
- goto err;
- }
-
- DBG ( " to %04x:%04x+%x\n", get_cached_info->Buffer.segment,
- get_cached_info->Buffer.offset, get_cached_info->BufferLimit );
-
- /* Allocate space for temporary copy */
- len = get_cached_info->BufferLimit;
- data = malloc ( len );
- if ( ! data ) {
- DBG ( " out of memory" );
- goto err;
- }
-
- /* Construct DHCP packet */
- if ( get_cached_info->PacketType == PXENV_PACKET_TYPE_DHCP_DISCOVER ) {
- msgtype = DHCPDISCOVER;
- options = &dhcp_request_options;
- } else {
- msgtype = DHCPACK;
- options = NULL;
- }
- if ( ( rc = create_dhcp_packet ( pxe_netdev, msgtype, data, len,
- &dhcppkt ) ) != 0 ) {
- DBG ( " failed to build packet" );
- goto err;
- }
- if ( ( rc = copy_dhcp_packet_options ( &dhcppkt, options ) ) != 0 ) {
- DBG ( " failed to copy options" );
- goto err;
- }
-
- /* Copy packet to client buffer */
- buffer = real_to_user ( get_cached_info->Buffer.segment,
- get_cached_info->Buffer.offset );
- copy_to_user ( buffer, 0, data, len );
-
- free ( data );
- get_cached_info->Status = PXENV_STATUS_SUCCESS;
- return PXENV_EXIT_SUCCESS;
-
- err:
- if ( data )
- free ( data );
- get_cached_info->Status = PXENV_STATUS_OUT_OF_RESOURCES;
- return PXENV_EXIT_FAILURE;
- }
-
- /* PXENV_RESTART_TFTP
- *
- * Status: working
- */
- PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
- *restart_tftp ) {
- DBG ( "PXENV_RESTART_TFTP" );
-
- #if 0
- /* Words cannot describe the complete mismatch between the PXE
- * specification and any possible version of reality...
- */
- restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
- restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
- DBG ( "(" );
- tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
- DBG ( ")" );
- if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
-
- /* Fire up the new NBP */
- restart_tftp->Status = xstartpxe();
- #endif
-
- /* Not sure what "SUCCESS" actually means, since we can only
- * return if the new NBP failed to boot...
- */
- return PXENV_EXIT_SUCCESS;
- }
-
- /* PXENV_START_UNDI
- *
- * Status: working
- */
- PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
-
- DBG ( "PXENV_START_UNDI" );
-
- #if 0
- /* Record PCI bus & devfn passed by caller, so we know which
- * NIC they want to use.
- *
- * If they don't match our already-existing NIC structure, set
- * values to ensure that the specified NIC is used at the next
- * call to pxe_intialise_nic().
- */
- bus = ( start_undi->AX >> 8 ) & 0xff;
- devfn = start_undi->AX & 0xff;
-
- #warning "device probing mechanism has completely changed"
- #if 0
- if ( ( pci->dev.driver == NULL ) ||
- ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
- /* This is quite a bit of a hack and relies on
- * knowledge of the internal operation of Etherboot's
- * probe mechanism.
- */
- DBG ( " set PCI %hhx:%hhx.%hhx",
- bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
- dev->type = BOOT_NIC;
- dev->to_probe = PROBE_PCI;
- memset ( &dev->state, 0, sizeof(dev->state) );
- pci->advance = 1;
- pci->dev.use_specified = 1;
- pci->dev.bus = bus;
- pci->dev.devfn = devfn;
- }
- #endif
-
- #endif
-
- start_undi->Status = PXENV_STATUS_SUCCESS;
- return PXENV_EXIT_SUCCESS;
- }
-
- /* PXENV_STOP_UNDI
- *
- * Status: working
- */
- PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
- DBG ( "PXENV_STOP_UNDI" );
-
- #if 0
- if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
- stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
- return PXENV_EXIT_FAILURE;
- }
- #endif
-
- stop_undi->Status = PXENV_STATUS_SUCCESS;
- return PXENV_EXIT_SUCCESS;
- }
-
- /* PXENV_START_BASE
- *
- * Status: won't implement (requires major structural changes)
- */
- PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
- DBG ( "PXENV_START_BASE" );
-
- start_base->Status = PXENV_STATUS_UNSUPPORTED;
- return PXENV_EXIT_FAILURE;
- }
-
- /* PXENV_STOP_BASE
- *
- * Status: working
- */
- PXENV_EXIT_t pxenv_stop_base ( struct s_PXENV_STOP_BASE *stop_base ) {
- DBG ( "PXENV_STOP_BASE" );
-
- /* The only time we will be called is when the NBP is trying
- * to shut down the PXE stack. There's nothing we need to do
- * in this call.
- */
-
- stop_base->Status = PXENV_STATUS_SUCCESS;
- return PXENV_EXIT_SUCCESS;
- }
|