#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <byteswap.h>
#include <gpxe/uaccess.h>
#include <gpxe/in.h>
#include <gpxe/tftp.h>
#include <gpxe/xfer.h>
#include <gpxe/open.h>
#include <gpxe/process.h>
#include <pxe.h>
Go to the source code of this file.
Data Structures | |
| struct | pxe_tftp_connection |
| A PXE TFTP connection. More... | |
Defines | |
| #define | PXE_TFTP_URI_LEN 256 |
| Maximum length of a PXE TFTP URI. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static void | pxe_tftp_close (int rc) |
| Close PXE TFTP connection. | |
| static int | pxe_tftp_xfer_deliver_iob (struct xfer_interface *xfer __unused, struct io_buffer *iobuf, struct xfer_metadata *meta) |
| Receive new data. | |
| static void | pxe_tftp_xfer_close (struct xfer_interface *xfer __unused, int rc) |
| Handle close() event. | |
| static int | pxe_tftp_open (uint32_t ipaddress, unsigned int port, const unsigned char *filename, size_t blksize, int sizeonly) |
| Open PXE TFTP connection. | |
| PXENV_EXIT_t | pxenv_tftp_open (struct s_PXENV_TFTP_OPEN *tftp_open) |
| TFTP OPEN. | |
| PXENV_EXIT_t | pxenv_tftp_close (struct s_PXENV_TFTP_CLOSE *tftp_close) |
| TFTP CLOSE. | |
| PXENV_EXIT_t | pxenv_tftp_read (struct s_PXENV_TFTP_READ *tftp_read) |
| TFTP READ. | |
| PXENV_EXIT_t | pxenv_tftp_read_file (struct s_PXENV_TFTP_READ_FILE *tftp_read_file) |
| TFTP/MTFTP read file. | |
| PXENV_EXIT_t | pxenv_tftp_get_fsize (struct s_PXENV_TFTP_GET_FSIZE *tftp_get_fsize) |
| TFTP GET FILE SIZE. | |
Variables | |
| static struct pxe_tftp_connection | pxe_tftp |
| The PXE TFTP connection. | |
| static struct xfer_interface_operations | pxe_tftp_xfer_ops |
Definition in file pxe_tftp.c.
| #define PXE_TFTP_URI_LEN 256 |
Maximum length of a PXE TFTP URI.
The PXE TFTP API provides 128 characters for the filename; the extra 128 bytes allow for the remainder of the URI.
Definition at line 156 of file pxe_tftp.c.
Referenced by pxe_tftp_open().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static void pxe_tftp_close | ( | int | rc | ) | [static] |
Close PXE TFTP connection.
| rc | Final status code |
Definition at line 71 of file pxe_tftp.c.
References pxe_tftp_connection::rc, pxe_tftp_connection::xfer, and xfer_close().
Referenced by pxe_tftp_xfer_close(), pxe_tftp_xfer_deliver_iob(), pxenv_tftp_close(), pxenv_tftp_get_fsize(), pxenv_tftp_open(), and pxenv_tftp_read_file().
00071 { 00072 xfer_nullify ( &pxe_tftp.xfer ); 00073 xfer_close ( &pxe_tftp.xfer, rc ); 00074 pxe_tftp.rc = rc; 00075 }
| static int pxe_tftp_xfer_deliver_iob | ( | struct xfer_interface *xfer | __unused, | |
| struct io_buffer * | iobuf, | |||
| struct xfer_metadata * | meta | |||
| ) | [static] |
Receive new data.
| xfer | Data transfer interface | |
| iobuf | I/O buffer | |
| meta | Transfer metadata |
| rc | Return status code |
Definition at line 85 of file pxe_tftp.c.
References pxe_tftp_connection::buffer, copy_to_user(), io_buffer::data, DBG, ENOBUFS, free_iob(), iob_len(), pxe_tftp_connection::max_offset, xfer_metadata::offset, pxe_tftp_connection::offset, pxe_tftp_close(), pxe_tftp_connection::rc, SEEK_CUR, pxe_tftp_connection::size, pxe_tftp_connection::start, and xfer_metadata::whence.
00087 { 00088 size_t len = iob_len ( iobuf ); 00089 int rc = 0; 00090 00091 /* Calculate new buffer position */ 00092 if ( meta->whence != SEEK_CUR ) 00093 pxe_tftp.offset = 0; 00094 pxe_tftp.offset += meta->offset; 00095 00096 /* Copy data block to buffer */ 00097 if ( len == 0 ) { 00098 /* No data (pure seek); treat as success */ 00099 } else if ( pxe_tftp.offset < pxe_tftp.start ) { 00100 DBG ( " buffer underrun at %zx (min %zx)", 00101 pxe_tftp.offset, pxe_tftp.start ); 00102 rc = -ENOBUFS; 00103 } else if ( ( pxe_tftp.offset + len ) > 00104 ( pxe_tftp.start + pxe_tftp.size ) ) { 00105 DBG ( " buffer overrun at %zx (max %zx)", 00106 ( pxe_tftp.offset + len ), 00107 ( pxe_tftp.start + pxe_tftp.size ) ); 00108 rc = -ENOBUFS; 00109 } else { 00110 copy_to_user ( pxe_tftp.buffer, 00111 ( pxe_tftp.offset - pxe_tftp.start ), 00112 iobuf->data, len ); 00113 } 00114 00115 /* Calculate new buffer position */ 00116 pxe_tftp.offset += len; 00117 00118 /* Record maximum offset as the file size */ 00119 if ( pxe_tftp.max_offset < pxe_tftp.offset ) 00120 pxe_tftp.max_offset = pxe_tftp.offset; 00121 00122 /* Terminate transfer on error */ 00123 if ( rc != 0 ) 00124 pxe_tftp_close ( rc ); 00125 00126 free_iob ( iobuf ); 00127 return rc; 00128 }
| static void pxe_tftp_xfer_close | ( | struct xfer_interface *xfer | __unused, | |
| int | rc | |||
| ) | [static] |
Handle close() event.
| xfer | Data transfer interface | |
| rc | Reason for close |
Definition at line 136 of file pxe_tftp.c.
References pxe_tftp_close().
00137 { 00138 pxe_tftp_close ( rc ); 00139 }
| static int pxe_tftp_open | ( | uint32_t | ipaddress, | |
| unsigned int | port, | |||
| const unsigned char * | filename, | |||
| size_t | blksize, | |||
| int | sizeonly | |||
| ) | [static] |
Open PXE TFTP connection.
| ipaddress | IP address | |
| port | TFTP server port | |
| filename | File name | |
| blksize | Requested block size |
| rc | Return status code |
Definition at line 167 of file pxe_tftp.c.
References DBG, EINPROGRESS, htons, inet_ntoa(), memset(), ntohs, NULL, PXE_TFTP_URI_LEN, pxe_tftp_connection::rc, in_addr::s_addr, snprintf(), strerror(), TFTP_DEFAULT_BLKSIZE, TFTP_PORT, pxe_tftp_connection::xfer, xfer_init(), and xfer_open_uri_string().
Referenced by pxenv_tftp_get_fsize(), pxenv_tftp_open(), and pxenv_tftp_read_file().
00169 { 00170 char uri_string[PXE_TFTP_URI_LEN]; 00171 struct in_addr address; 00172 int rc; 00173 00174 /* Reset PXE TFTP connection structure */ 00175 memset ( &pxe_tftp, 0, sizeof ( pxe_tftp ) ); 00176 xfer_init ( &pxe_tftp.xfer, &pxe_tftp_xfer_ops, NULL ); 00177 pxe_tftp.rc = -EINPROGRESS; 00178 00179 /* Construct URI string */ 00180 address.s_addr = ipaddress; 00181 if ( ! port ) 00182 port = htons ( TFTP_PORT ); 00183 if ( blksize < TFTP_DEFAULT_BLKSIZE ) 00184 blksize = TFTP_DEFAULT_BLKSIZE; 00185 snprintf ( uri_string, sizeof ( uri_string ), 00186 "tftp%s://%s:%d%s%s?blksize=%zd", 00187 sizeonly ? "size" : "", 00188 inet_ntoa ( address ), ntohs ( port ), 00189 ( ( filename[0] == '/' ) ? "" : "/" ), filename, blksize ); 00190 DBG ( " %s", uri_string ); 00191 00192 /* Open PXE TFTP connection */ 00193 if ( ( rc = xfer_open_uri_string ( &pxe_tftp.xfer, 00194 uri_string ) ) != 0 ) { 00195 DBG ( " could not open (%s)\n", strerror ( rc ) ); 00196 return rc; 00197 } 00198 00199 return 0; 00200 }
struct pxe_tftp_connection pxe_tftp [static] |
Initial value:
{
.xfer = XFER_INIT ( &null_xfer_ops ),
}
Definition at line 62 of file pxe_tftp.c.
struct xfer_interface_operations pxe_tftp_xfer_ops [static] |
Initial value:
{
.close = pxe_tftp_xfer_close,
.vredirect = xfer_vreopen,
.window = unlimited_xfer_window,
.alloc_iob = default_xfer_alloc_iob,
.deliver_iob = pxe_tftp_xfer_deliver_iob,
.deliver_raw = xfer_deliver_as_iob,
}
Definition at line 141 of file pxe_tftp.c.
1.5.7.1