summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown2005-06-01 15:13:05 +0200
committerMichael Brown2005-06-01 15:13:05 +0200
commit53a4436d94886b6b6b0d931158db2c79490591a1 (patch)
tree9f5a3b6f6644ed39d63758f66e8acbda672c903f /src/include
parentNow have enough functions to implement a standard TFTP client in around 50 (diff)
downloadipxe-53a4436d94886b6b6b0d931158db2c79490591a1.tar.gz
ipxe-53a4436d94886b6b6b0d931158db2c79490591a1.tar.xz
ipxe-53a4436d94886b6b6b0d931158db2c79490591a1.zip
TFTP upgraded to use a core function library (in tftpcore.c) which will be
shared between TFTP, TFTM and MTFTP protocols.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/etherboot.h1
-rw-r--r--src/include/pxe.h3
-rw-r--r--src/include/tftp.h161
3 files changed, 124 insertions, 41 deletions
diff --git a/src/include/etherboot.h b/src/include/etherboot.h
index 9d364282f..669ee8b24 100644
--- a/src/include/etherboot.h
+++ b/src/include/etherboot.h
@@ -154,7 +154,6 @@ enum {
#include "udp.h"
#include "tcp.h"
#include "bootp.h"
-#include "tftp.h"
#include "igmp.h"
#include "nfs.h"
#include "console.h"
diff --git a/src/include/pxe.h b/src/include/pxe.h
index 3264df0c0..f8e2de79b 100644
--- a/src/include/pxe.h
+++ b/src/include/pxe.h
@@ -4,6 +4,7 @@
#include "pxe_types.h"
#include "pxe_api.h"
#include "etherboot.h"
+#include "tftp.h"
/* Union used for PXE API calls; we don't know the type of the
* structure until we interpret the opcode. Also, Status is available
@@ -88,7 +89,7 @@ typedef struct pxe_stack {
uint32_t magic_cookie;
unsigned int len;
int eof;
- char data[TFTP_MAX_PACKET];
+ char data[TFTP_MAX_BLKSIZE];
} tftpdata;
struct {
char *buffer;
diff --git a/src/include/tftp.h b/src/include/tftp.h
index 70192067c..22329e50c 100644
--- a/src/include/tftp.h
+++ b/src/include/tftp.h
@@ -1,13 +1,17 @@
#ifndef TFTP_H
#define TFTP_H
+/** @file */
+
#include "in.h"
#include "buffer.h"
#include "nic.h"
+#include "ip.h"
+#include "udp.h"
-#define TFTP_PORT 69
-#define TFTP_DEFAULTSIZE_PACKET 512
-#define TFTP_MAX_PACKET 1432 /* 512 */
+#define TFTP_PORT 69 /**< Default TFTP server port */
+#define TFTP_DEFAULT_BLKSIZE 512
+#define TFTP_MAX_BLKSIZE 1432 /* 512 */
#define TFTP_RRQ 1
#define TFTP_WRQ 2
@@ -16,53 +20,132 @@
#define TFTP_ERROR 5
#define TFTP_OACK 6
-#define TFTP_CODE_EOF 1
-#define TFTP_CODE_MORE 2
-#define TFTP_CODE_ERROR 3
-#define TFTP_CODE_BOOT 4
-#define TFTP_CODE_CFG 5
+#define TFTP_ERR_FILE_NOT_FOUND 1 /**< File not found */
+#define TFTP_ERR_ACCESS_DENIED 2 /**< Access violation */
+#define TFTP_ERR_DISK_FULL 3 /**< Disk full or allocation exceeded */
+#define TFTP_ERR_ILLEGAL_OP 4 /**< Illegal TFTP operation */
+#define TFTP_ERR_UNKNOWN_TID 5 /**< Unknown transfer ID */
+#define TFTP_ERR_FILE_EXISTS 6 /**< File already exists */
+#define TFTP_ERR_UNKNOWN_USER 7 /**< No such user */
+#define TFTP_ERR_BAD_OPTS 8 /**< Option negotiation failed */
-struct tftp_t {
+/** A TFTP request (RRQ) packet */
+struct tftp_rrq {
+ struct iphdr ip;
+ struct udphdr udp;
+ uint16_t opcode;
+ char data[TFTP_DEFAULT_BLKSIZE];
+} PACKED;
+
+/** A TFTP data (DATA) packet */
+struct tftp_data {
+ struct iphdr ip;
+ struct udphdr udp;
+ uint16_t opcode;
+ uint16_t block;
+ uint8_t data[TFTP_MAX_BLKSIZE];
+} PACKED;
+
+/** A TFTP acknowledgement (ACK) packet */
+struct tftp_ack {
struct iphdr ip;
struct udphdr udp;
uint16_t opcode;
- union {
- uint8_t rrq[TFTP_DEFAULTSIZE_PACKET];
- struct {
- uint16_t block;
- uint8_t download[TFTP_MAX_PACKET];
- } data;
- struct {
- uint16_t block;
- } ack;
- struct {
- uint16_t errcode;
- uint8_t errmsg[TFTP_DEFAULTSIZE_PACKET];
- } err;
- struct {
- uint8_t data[TFTP_DEFAULTSIZE_PACKET+2];
- } oack;
- } u;
+ uint16_t block;
} PACKED;
-/* define a smaller tftp packet solely for making requests to conserve stack
- 512 bytes should be enough */
-struct tftpreq_t {
+/** A TFTP error (ERROR) packet */
+struct tftp_error {
struct iphdr ip;
struct udphdr udp;
uint16_t opcode;
- union {
- uint8_t rrq[512];
- struct {
- uint16_t block;
- } ack;
- struct {
- uint16_t errcode;
- uint8_t errmsg[512-2];
- } err;
- } u;
+ uint16_t errcode;
+ char errmsg[TFTP_DEFAULT_BLKSIZE];
} PACKED;
+/** A TFTP options acknowledgement (OACK) packet */
+struct tftp_oack {
+ struct iphdr ip;
+ struct udphdr udp;
+ uint16_t opcode;
+ uint8_t data[TFTP_DEFAULT_BLKSIZE];
+} PACKED;
+
+/** The common header of all TFTP packets */
+struct tftp_common {
+ struct iphdr ip;
+ struct udphdr udp;
+ uint16_t opcode;
+} PACKED;
+
+/** A union encapsulating all TFTP packet types */
+union tftp_any {
+ struct tftp_common common;
+ struct tftp_rrq rrq;
+ struct tftp_data data;
+ struct tftp_ack ack;
+ struct tftp_error error;
+ struct tftp_oack oack;
+};
+
+/**
+ * TFTP state
+ *
+ * This data structure holds the state for an ongoing TFTP transfer.
+ */
+struct tftp_state {
+ /** TFTP server address
+ *
+ * This is the IP address and UDP port from which data packets
+ * will be sent, and to which ACK packets should be sent.
+ */
+ struct sockaddr_in server;
+ /** TFTP client address
+ *
+ * The IP address, if any, is the multicast address to which
+ * data packets will be sent. The client will always send
+ * packets from its own IP address.
+ *
+ * The UDP port is the port from which the open request will
+ * be sent, and to which data packets will be sent. (Due to
+ * the "design" of the MTFTP protocol, the master client will
+ * receive its first data packet as unicast, and subsequent
+ * packets as multicast.)
+ */
+ struct sockaddr_in client;
+ /** Master client
+ *
+ * This will be true if the client is the master client for a
+ * multicast protocol (i.e. MTFTP or TFTM). (It will always
+ * be true for a non-multicast protocol, i.e. plain old TFTP).
+ */
+ int master;
+ /** Data block size
+ *
+ * This is the "blksize" option negotiated with the TFTP
+ * server. (If the TFTP server does not support TFTP options,
+ * this will default to 512).
+ */
+ unsigned int blksize;
+ /** File size
+ *
+ * This is the value returned in the "tsize" option from the
+ * TFTP server. If the TFTP server does not support the
+ * "tsize" option, this value will be zero.
+ */
+ off_t tsize;
+ /** Last received block
+ *
+ * The block number of the most recent block received from the
+ * TFTP server. Note that the first data block is block 1; a
+ * value of 0 indicates that no data blocks have yet been
+ * received.
+ */
+ unsigned int block;
+};
+
+
+
struct tftpreq_info_t {
struct sockaddr_in *server;
const char *name;