2005-05-20 17:50:37 +00:00
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* PXE UDP API
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <byteswap.h>
|
2007-06-11 17:11:29 +00:00
|
|
|
#include <gpxe/xfer.h>
|
2006-08-02 23:08:10 +00:00
|
|
|
#include <gpxe/udp.h>
|
|
|
|
#include <gpxe/uaccess.h>
|
|
|
|
#include <gpxe/process.h>
|
|
|
|
#include <pxe.h>
|
2005-05-20 17:50:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
/** A PXE UDP connection */
|
|
|
|
struct pxe_udp_connection {
|
2007-06-11 17:11:29 +00:00
|
|
|
/** Data transfer interface to UDP stack */
|
|
|
|
struct xfer_interface xfer;
|
|
|
|
/** Local address */
|
|
|
|
struct sockaddr_in local;
|
|
|
|
/** Current PXENV_UDP_READ parameter block */
|
2006-08-02 23:08:10 +00:00
|
|
|
struct s_PXENV_UDP_READ *pxenv_udp_read;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive PXE UDP data
|
|
|
|
*
|
2007-06-11 17:11:29 +00:00
|
|
|
* @v xfer Data transfer interface
|
|
|
|
* @v iobuf I/O buffer
|
|
|
|
* @v meta Data transfer metadata
|
|
|
|
* @ret rc Return status code
|
2006-08-02 23:08:10 +00:00
|
|
|
*
|
|
|
|
* Receives a packet as part of the current pxenv_udp_read()
|
|
|
|
* operation.
|
|
|
|
*/
|
2007-06-11 17:11:29 +00:00
|
|
|
static int pxe_udp_deliver_iob ( struct xfer_interface *xfer,
|
|
|
|
struct io_buffer *iobuf,
|
|
|
|
struct xfer_metadata *meta ) {
|
|
|
|
struct pxe_udp_connection *pxe_udp =
|
|
|
|
container_of ( xfer, struct pxe_udp_connection, xfer );
|
2006-08-02 23:08:10 +00:00
|
|
|
struct s_PXENV_UDP_READ *pxenv_udp_read = pxe_udp->pxenv_udp_read;
|
2007-06-11 17:11:29 +00:00
|
|
|
struct sockaddr_in *sin_src;
|
|
|
|
struct sockaddr_in *sin_dest;
|
2006-08-02 23:08:10 +00:00
|
|
|
userptr_t buffer;
|
2007-06-11 17:11:29 +00:00
|
|
|
size_t len;
|
|
|
|
int rc = 0;
|
2006-08-02 23:08:10 +00:00
|
|
|
|
|
|
|
if ( ! pxenv_udp_read ) {
|
|
|
|
DBG ( "PXE discarded UDP packet\n" );
|
2007-06-11 17:11:29 +00:00
|
|
|
rc = -ENOBUFS;
|
|
|
|
goto done;
|
2006-08-02 23:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy packet to buffer and record length */
|
|
|
|
buffer = real_to_user ( pxenv_udp_read->buffer.segment,
|
|
|
|
pxenv_udp_read->buffer.offset );
|
2007-06-11 17:11:29 +00:00
|
|
|
len = iob_len ( iobuf );
|
2006-08-02 23:08:10 +00:00
|
|
|
if ( len > pxenv_udp_read->buffer_size )
|
|
|
|
len = pxenv_udp_read->buffer_size;
|
2007-06-11 17:11:29 +00:00
|
|
|
copy_to_user ( buffer, 0, iobuf->data, len );
|
2006-08-02 23:08:10 +00:00
|
|
|
pxenv_udp_read->buffer_size = len;
|
|
|
|
|
|
|
|
/* Fill in source/dest information */
|
2007-06-11 17:11:29 +00:00
|
|
|
assert ( meta );
|
|
|
|
sin_src = ( struct sockaddr_in * ) meta->src;
|
|
|
|
assert ( sin_src );
|
2006-08-02 23:08:10 +00:00
|
|
|
assert ( sin_src->sin_family == AF_INET );
|
|
|
|
pxenv_udp_read->src_ip = sin_src->sin_addr.s_addr;
|
|
|
|
pxenv_udp_read->s_port = sin_src->sin_port;
|
2007-06-11 17:11:29 +00:00
|
|
|
sin_dest = ( struct sockaddr_in * ) meta->dest;
|
|
|
|
assert ( sin_dest );
|
2006-08-02 23:08:10 +00:00
|
|
|
assert ( sin_dest->sin_family == AF_INET );
|
|
|
|
pxenv_udp_read->dest_ip = sin_dest->sin_addr.s_addr;
|
|
|
|
pxenv_udp_read->d_port = sin_dest->sin_port;
|
|
|
|
|
|
|
|
/* Mark as received */
|
|
|
|
pxe_udp->pxenv_udp_read = NULL;
|
|
|
|
|
2007-06-11 17:11:29 +00:00
|
|
|
done:
|
|
|
|
free_iob ( iobuf );
|
|
|
|
return rc;
|
2006-08-02 23:08:10 +00:00
|
|
|
}
|
|
|
|
|
2007-06-11 17:11:29 +00:00
|
|
|
/** PXE UDP data transfer interface operations */
|
|
|
|
static struct xfer_interface_operations pxe_udp_xfer_operations = {
|
|
|
|
.close = ignore_xfer_close,
|
|
|
|
.vredirect = ignore_xfer_vredirect,
|
|
|
|
.seek = ignore_xfer_seek,
|
|
|
|
.alloc_iob = default_xfer_alloc_iob,
|
|
|
|
.deliver_iob = pxe_udp_deliver_iob,
|
|
|
|
.deliver_raw = xfer_deliver_as_iob,
|
2006-08-02 23:08:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** The PXE UDP connection */
|
|
|
|
static struct pxe_udp_connection pxe_udp = {
|
2007-06-11 17:11:29 +00:00
|
|
|
.xfer = {
|
|
|
|
.intf = {
|
|
|
|
.dest = &null_xfer.intf,
|
|
|
|
.refcnt = NULL,
|
|
|
|
},
|
|
|
|
.op = &pxe_udp_xfer_operations,
|
|
|
|
},
|
|
|
|
.local = {
|
|
|
|
.sin_family = AF_INET,
|
|
|
|
},
|
2006-08-02 23:08:10 +00:00
|
|
|
};
|
|
|
|
|
2005-05-20 17:50:37 +00:00
|
|
|
/**
|
2005-05-23 23:32:56 +00:00
|
|
|
* UDP OPEN
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @v pxenv_udp_open Pointer to a struct s_PXENV_UDP_OPEN
|
2005-05-20 17:50:37 +00:00
|
|
|
* @v s_PXENV_UDP_OPEN::src_ip IP address of this station, or 0.0.0.0
|
2005-05-23 23:32:56 +00:00
|
|
|
* @ret #PXENV_EXIT_SUCCESS Always
|
2005-05-20 17:50:37 +00:00
|
|
|
* @ret s_PXENV_UDP_OPEN::Status PXE status code
|
2006-08-02 23:08:10 +00:00
|
|
|
* @err #PXENV_STATUS_UDP_OPEN UDP connection already open
|
|
|
|
* @err #PXENV_STATUS_OUT_OF_RESOURCES Could not open connection
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
|
|
|
* Prepares the PXE stack for communication using pxenv_udp_write()
|
2005-05-27 11:37:09 +00:00
|
|
|
* and pxenv_udp_read().
|
|
|
|
*
|
|
|
|
* The IP address supplied in s_PXENV_UDP_OPEN::src_ip will be
|
|
|
|
* recorded and used as the local station's IP address for all further
|
|
|
|
* communication, including communication by means other than
|
|
|
|
* pxenv_udp_write() and pxenv_udp_read(). (If
|
|
|
|
* s_PXENV_UDP_OPEN::src_ip is 0.0.0.0, the local station's IP address
|
|
|
|
* will remain unchanged.)
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* You can only have one open UDP connection at a time. This is not a
|
|
|
|
* meaningful restriction, since pxenv_udp_write() and
|
|
|
|
* pxenv_udp_read() allow you to specify arbitrary local and remote
|
|
|
|
* ports and an arbitrary remote address for each packet. According
|
|
|
|
* to the PXE specifiation, you cannot have a UDP connection open at
|
|
|
|
* the same time as a TFTP connection; this restriction does not apply
|
|
|
|
* to Etherboot.
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* On x86, you must set the s_PXE::StatusCallout field to a nonzero
|
|
|
|
* value before calling this function in protected mode. You cannot
|
|
|
|
* call this function with a 32-bit stack segment. (See the relevant
|
|
|
|
* @ref pxe_x86_pmode16 "implementation note" for more details.)
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* @note The PXE specification does not make it clear whether the IP
|
|
|
|
* address supplied in s_PXENV_UDP_OPEN::src_ip should be used only
|
|
|
|
* for this UDP connection, or retained for all future communication.
|
|
|
|
* The latter seems more consistent with typical PXE stack behaviour.
|
2005-05-23 23:32:56 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @note Etherboot currently ignores the s_PXENV_UDP_OPEN::src_ip
|
|
|
|
* parameter.
|
|
|
|
*
|
2005-05-20 17:50:37 +00:00
|
|
|
*/
|
2006-08-02 23:08:10 +00:00
|
|
|
PXENV_EXIT_t pxenv_udp_open ( struct s_PXENV_UDP_OPEN *pxenv_udp_open ) {
|
2007-06-20 00:13:35 +00:00
|
|
|
int rc;
|
2006-08-02 23:08:10 +00:00
|
|
|
|
2005-05-20 17:50:37 +00:00
|
|
|
DBG ( "PXENV_UDP_OPEN" );
|
|
|
|
|
2007-06-11 17:11:29 +00:00
|
|
|
/* Record source IP address */
|
|
|
|
pxe_udp.local.sin_addr.s_addr = pxenv_udp_open->src_ip;
|
2006-08-02 23:08:10 +00:00
|
|
|
|
2007-06-11 17:11:29 +00:00
|
|
|
/* Open promiscuous UDP connection */
|
2007-06-20 00:13:35 +00:00
|
|
|
xfer_close ( &pxe_udp.xfer, 0 );
|
|
|
|
if ( ( rc = udp_open_promisc ( &pxe_udp.xfer ) ) != 0 ) {
|
|
|
|
pxenv_udp_open->Status = PXENV_STATUS ( rc );
|
|
|
|
return PXENV_EXIT_FAILURE;
|
|
|
|
}
|
2005-05-20 17:50:37 +00:00
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
pxenv_udp_open->Status = PXENV_STATUS_SUCCESS;
|
2005-05-20 17:50:37 +00:00
|
|
|
return PXENV_EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-05-23 23:32:56 +00:00
|
|
|
* UDP CLOSE
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @v pxenv_udp_close Pointer to a struct s_PXENV_UDP_CLOSE
|
2005-05-23 23:32:56 +00:00
|
|
|
* @ret #PXENV_EXIT_SUCCESS Always
|
2005-05-20 17:50:37 +00:00
|
|
|
* @ret s_PXENV_UDP_CLOSE::Status PXE status code
|
2005-05-24 00:11:25 +00:00
|
|
|
* @err None -
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* Closes a UDP connection opened with pxenv_udp_open().
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* You can only have one open UDP connection at a time. You cannot
|
|
|
|
* have a UDP connection open at the same time as a TFTP connection.
|
|
|
|
* You cannot use pxenv_udp_close() to close a TFTP connection; use
|
2006-08-02 23:08:10 +00:00
|
|
|
* pxenv_tftp_close() instead.
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* On x86, you must set the s_PXE::StatusCallout field to a nonzero
|
|
|
|
* value before calling this function in protected mode. You cannot
|
|
|
|
* call this function with a 32-bit stack segment. (See the relevant
|
|
|
|
* @ref pxe_x86_pmode16 "implementation note" for more details.)
|
2005-05-23 23:32:56 +00:00
|
|
|
*
|
2005-05-20 17:50:37 +00:00
|
|
|
*/
|
2006-08-02 23:08:10 +00:00
|
|
|
PXENV_EXIT_t pxenv_udp_close ( struct s_PXENV_UDP_CLOSE *pxenv_udp_close ) {
|
2005-05-20 17:50:37 +00:00
|
|
|
DBG ( "PXENV_UDP_CLOSE" );
|
2006-08-02 23:08:10 +00:00
|
|
|
|
|
|
|
/* Close UDP connection */
|
2007-06-20 00:13:35 +00:00
|
|
|
xfer_close ( &pxe_udp.xfer, 0 );
|
2006-08-02 23:08:10 +00:00
|
|
|
|
|
|
|
pxenv_udp_close->Status = PXENV_STATUS_SUCCESS;
|
2005-05-20 17:50:37 +00:00
|
|
|
return PXENV_EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-05-23 23:32:56 +00:00
|
|
|
* UDP WRITE
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @v pxenv_udp_write Pointer to a struct s_PXENV_UDP_WRITE
|
2005-05-20 17:50:37 +00:00
|
|
|
* @v s_PXENV_UDP_WRITE::ip Destination IP address
|
2005-05-27 11:37:09 +00:00
|
|
|
* @v s_PXENV_UDP_WRITE::gw Relay agent IP address, or 0.0.0.0
|
2005-05-20 17:50:37 +00:00
|
|
|
* @v s_PXENV_UDP_WRITE::src_port Source UDP port, or 0
|
|
|
|
* @v s_PXENV_UDP_WRITE::dst_port Destination UDP port
|
|
|
|
* @v s_PXENV_UDP_WRITE::buffer_size Length of the UDP payload
|
|
|
|
* @v s_PXENV_UDP_WRITE::buffer Address of the UDP payload
|
2005-05-23 23:32:56 +00:00
|
|
|
* @ret #PXENV_EXIT_SUCCESS Packet was transmitted successfully
|
2005-05-24 17:00:55 +00:00
|
|
|
* @ret #PXENV_EXIT_FAILURE Packet could not be transmitted
|
2005-05-20 17:50:37 +00:00
|
|
|
* @ret s_PXENV_UDP_WRITE::Status PXE status code
|
2006-08-02 23:08:10 +00:00
|
|
|
* @err #PXENV_STATUS_UDP_CLOSED UDP connection is not open
|
|
|
|
* @err #PXENV_STATUS_UNDI_TRANSMIT_ERROR Could not transmit packet
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
|
|
|
* Transmits a single UDP packet. A valid IP and UDP header will be
|
|
|
|
* prepended to the payload in s_PXENV_UDP_WRITE::buffer; the buffer
|
|
|
|
* should not contain precomputed IP and UDP headers, nor should it
|
|
|
|
* contain space allocated for these headers. The first byte of the
|
|
|
|
* buffer will be transmitted as the first byte following the UDP
|
|
|
|
* header.
|
|
|
|
*
|
|
|
|
* If s_PXENV_UDP_WRITE::gw is 0.0.0.0, normal IP routing will take
|
2005-05-27 11:37:09 +00:00
|
|
|
* place. See the relevant @ref pxe_routing "implementation note" for
|
|
|
|
* more details.
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
|
|
|
* If s_PXENV_UDP_WRITE::src_port is 0, port 2069 will be used.
|
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* You must have opened a UDP connection with pxenv_udp_open() before
|
2006-08-02 23:08:10 +00:00
|
|
|
* calling pxenv_udp_write().
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* On x86, you must set the s_PXE::StatusCallout field to a nonzero
|
|
|
|
* value before calling this function in protected mode. You cannot
|
|
|
|
* call this function with a 32-bit stack segment. (See the relevant
|
|
|
|
* @ref pxe_x86_pmode16 "implementation note" for more details.)
|
2005-05-23 23:32:56 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @note Etherboot currently ignores the s_PXENV_UDP_WRITE::gw
|
|
|
|
* parameter.
|
|
|
|
*
|
2005-05-20 17:50:37 +00:00
|
|
|
*/
|
2006-08-02 23:08:10 +00:00
|
|
|
PXENV_EXIT_t pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) {
|
2007-06-11 17:11:29 +00:00
|
|
|
struct sockaddr_in dest;
|
|
|
|
struct xfer_metadata meta = {
|
|
|
|
.src = ( struct sockaddr * ) &pxe_udp.local,
|
|
|
|
.dest = ( struct sockaddr * ) &dest,
|
|
|
|
};
|
|
|
|
size_t len;
|
|
|
|
struct io_buffer *iobuf;
|
|
|
|
userptr_t buffer;
|
2006-08-09 01:57:02 +00:00
|
|
|
int rc;
|
2005-05-20 17:50:37 +00:00
|
|
|
|
|
|
|
DBG ( "PXENV_UDP_WRITE" );
|
2006-08-02 23:08:10 +00:00
|
|
|
|
|
|
|
/* Construct destination socket address */
|
|
|
|
memset ( &dest, 0, sizeof ( dest ) );
|
2007-06-11 17:11:29 +00:00
|
|
|
dest.sin_family = AF_INET;
|
|
|
|
dest.sin_addr.s_addr = pxenv_udp_write->ip;
|
|
|
|
dest.sin_port = pxenv_udp_write->dst_port;
|
2006-08-02 23:08:10 +00:00
|
|
|
|
|
|
|
/* Set local (source) port. PXE spec says source port is 2069
|
|
|
|
* if not specified. Really, this ought to be set at UDP open
|
|
|
|
* time but hey, we didn't design this API.
|
|
|
|
*/
|
2007-06-11 17:11:29 +00:00
|
|
|
pxe_udp.local.sin_port = pxenv_udp_write->src_port;
|
|
|
|
if ( ! pxe_udp.local.sin_port )
|
|
|
|
pxe_udp.local.sin_port = htons ( 2069 );
|
2006-08-02 23:08:10 +00:00
|
|
|
|
2005-05-20 17:50:37 +00:00
|
|
|
/* FIXME: we ignore the gateway specified, since we're
|
|
|
|
* confident of being able to do our own routing. We should
|
|
|
|
* probably allow for multiple gateways.
|
|
|
|
*/
|
2006-08-09 01:57:02 +00:00
|
|
|
|
2007-06-11 17:11:29 +00:00
|
|
|
/* Allocate and fill data buffer */
|
|
|
|
len = pxenv_udp_write->buffer_size;
|
|
|
|
iobuf = xfer_alloc_iob ( &pxe_udp.xfer, len );
|
|
|
|
if ( ! iobuf ) {
|
|
|
|
pxenv_udp_write->Status = PXENV_STATUS_OUT_OF_RESOURCES;
|
|
|
|
return PXENV_EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
buffer = real_to_user ( pxenv_udp_write->buffer.segment,
|
|
|
|
pxenv_udp_write->buffer.offset );
|
|
|
|
copy_from_user ( iob_put ( iobuf, len ), buffer, 0, len );
|
|
|
|
|
2006-08-09 01:57:02 +00:00
|
|
|
DBG ( " %04x:%04x+%x %d->%s:%d", pxenv_udp_write->buffer.segment,
|
|
|
|
pxenv_udp_write->buffer.offset, pxenv_udp_write->buffer_size,
|
|
|
|
ntohs ( pxenv_udp_write->src_port ),
|
2007-06-11 17:11:29 +00:00
|
|
|
inet_ntoa ( dest.sin_addr ),
|
2006-08-09 01:57:02 +00:00
|
|
|
ntohs ( pxenv_udp_write->dst_port ) );
|
2005-05-20 17:50:37 +00:00
|
|
|
|
|
|
|
/* Transmit packet */
|
2007-06-11 17:11:29 +00:00
|
|
|
if ( ( rc = xfer_deliver_iob_meta ( &pxe_udp.xfer, iobuf,
|
|
|
|
&meta ) ) != 0 ) {
|
|
|
|
pxenv_udp_write->Status = PXENV_STATUS ( rc );
|
2005-05-20 17:50:37 +00:00
|
|
|
return PXENV_EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
pxenv_udp_write->Status = PXENV_STATUS_SUCCESS;
|
2005-05-20 17:50:37 +00:00
|
|
|
return PXENV_EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-05-23 23:32:56 +00:00
|
|
|
* UDP READ
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2006-08-02 23:08:10 +00:00
|
|
|
* @v pxenv_udp_read Pointer to a struct s_PXENV_UDP_READ
|
2005-05-20 17:50:37 +00:00
|
|
|
* @v s_PXENV_UDP_READ::dest_ip Destination IP address, or 0.0.0.0
|
|
|
|
* @v s_PXENV_UDP_READ::d_port Destination UDP port, or 0
|
|
|
|
* @v s_PXENV_UDP_READ::buffer_size Size of the UDP payload buffer
|
|
|
|
* @v s_PXENV_UDP_READ::buffer Address of the UDP payload buffer
|
2005-05-23 23:32:56 +00:00
|
|
|
* @ret #PXENV_EXIT_SUCCESS A packet has been received
|
|
|
|
* @ret #PXENV_EXIT_FAILURE No packet has been received
|
2005-05-20 17:50:37 +00:00
|
|
|
* @ret s_PXENV_UDP_READ::Status PXE status code
|
|
|
|
* @ret s_PXENV_UDP_READ::src_ip Source IP address
|
2005-05-23 23:32:56 +00:00
|
|
|
* @ret s_PXENV_UDP_READ::dest_ip Destination IP address
|
2005-05-20 17:50:37 +00:00
|
|
|
* @ret s_PXENV_UDP_READ::s_port Source UDP port
|
|
|
|
* @ret s_PXENV_UDP_READ::d_port Destination UDP port
|
|
|
|
* @ret s_PXENV_UDP_READ::buffer_size Length of UDP payload
|
2006-08-02 23:08:10 +00:00
|
|
|
* @err #PXENV_STATUS_UDP_CLOSED UDP connection is not open
|
2005-05-23 23:32:56 +00:00
|
|
|
* @err #PXENV_STATUS_FAILURE No packet was ready to read
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
|
|
|
* Receive a single UDP packet. This is a non-blocking call; if no
|
|
|
|
* packet is ready to read, the call will return instantly with
|
|
|
|
* s_PXENV_UDP_READ::Status==PXENV_STATUS_FAILURE.
|
|
|
|
*
|
|
|
|
* If s_PXENV_UDP_READ::dest_ip is 0.0.0.0, UDP packets addressed to
|
2005-05-24 17:00:55 +00:00
|
|
|
* any IP address will be accepted and may be returned to the caller.
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
|
|
|
* If s_PXENV_UDP_READ::d_port is 0, UDP packets addressed to any UDP
|
2005-05-24 17:00:55 +00:00
|
|
|
* port will be accepted and may be returned to the caller.
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* You must have opened a UDP connection with pxenv_udp_open() before
|
2006-08-02 23:08:10 +00:00
|
|
|
* calling pxenv_udp_read().
|
2005-05-20 17:50:37 +00:00
|
|
|
*
|
2005-05-24 17:00:55 +00:00
|
|
|
* On x86, you must set the s_PXE::StatusCallout field to a nonzero
|
|
|
|
* value before calling this function in protected mode. You cannot
|
|
|
|
* call this function with a 32-bit stack segment. (See the relevant
|
|
|
|
* @ref pxe_x86_pmode16 "implementation note" for more details.)
|
2005-05-23 23:32:56 +00:00
|
|
|
*
|
2005-05-20 17:50:37 +00:00
|
|
|
* @note The PXE specification (version 2.1) does not state that we
|
|
|
|
* should fill in s_PXENV_UDP_READ::dest_ip and
|
|
|
|
* s_PXENV_UDP_READ::d_port, but Microsoft Windows' NTLDR program
|
|
|
|
* expects us to do so, and will fail if we don't.
|
|
|
|
*
|
|
|
|
*/
|
2006-08-02 23:08:10 +00:00
|
|
|
PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) {
|
|
|
|
struct in_addr dest_ip = { .s_addr = pxenv_udp_read->dest_ip };
|
|
|
|
uint16_t d_port = pxenv_udp_read->d_port;
|
|
|
|
|
2005-05-20 17:50:37 +00:00
|
|
|
DBG ( "PXENV_UDP_READ" );
|
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
/* Try receiving a packet */
|
|
|
|
pxe_udp.pxenv_udp_read = pxenv_udp_read;
|
|
|
|
step();
|
|
|
|
if ( pxe_udp.pxenv_udp_read ) {
|
|
|
|
/* No packet received */
|
|
|
|
pxe_udp.pxenv_udp_read = NULL;
|
|
|
|
goto no_packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filter on destination address and/or port */
|
|
|
|
if ( dest_ip.s_addr && ( dest_ip.s_addr != pxenv_udp_read->dest_ip ) )
|
|
|
|
goto no_packet;
|
|
|
|
if ( d_port && ( d_port != pxenv_udp_read->d_port ) )
|
|
|
|
goto no_packet;
|
|
|
|
|
2007-01-14 19:58:41 +00:00
|
|
|
DBG ( " %04x:%04x+%x %s:", pxenv_udp_read->buffer.segment,
|
2007-01-14 18:22:37 +00:00
|
|
|
pxenv_udp_read->buffer.offset, pxenv_udp_read->buffer_size,
|
2007-01-14 19:58:41 +00:00
|
|
|
inet_ntoa ( *( ( struct in_addr * ) &pxenv_udp_read->src_ip ) ));
|
|
|
|
DBG ( "%d<-%s:%d", ntohs ( pxenv_udp_read->s_port ),
|
2007-01-14 18:22:37 +00:00
|
|
|
inet_ntoa ( *( ( struct in_addr * ) &pxenv_udp_read->dest_ip ) ),
|
|
|
|
ntohs ( pxenv_udp_read->d_port ) );
|
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
pxenv_udp_read->Status = PXENV_STATUS_SUCCESS;
|
2005-05-20 17:50:37 +00:00
|
|
|
return PXENV_EXIT_SUCCESS;
|
2005-05-24 17:00:55 +00:00
|
|
|
|
2006-08-02 23:08:10 +00:00
|
|
|
no_packet:
|
|
|
|
pxenv_udp_read->Status = PXENV_STATUS_FAILURE;
|
|
|
|
return PXENV_EXIT_FAILURE;
|
|
|
|
}
|