Bladeren bron

Added some TFTP definitions for use with the new UDP API.

tags/v0.9.3
Michael Brown 18 jaren geleden
bovenliggende
commit
72cd29f13c
1 gewijzigde bestanden met toevoegingen van 125 en 0 verwijderingen
  1. 125
    0
      src/include/gpxe/tftp.h

+ 125
- 0
src/include/gpxe/tftp.h Bestand weergeven

@@ -0,0 +1,125 @@
1
+#ifndef	_GPXE_TFTP_H
2
+#define	_GPXE_TFTP_H
3
+
4
+/** @file
5
+ *
6
+ * TFTP protocol
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+#include <gpxe/udp.h>
12
+
13
+#define TFTP_PORT	       69 /**< Default TFTP server port */
14
+#define	TFTP_DEFAULT_BLKSIZE  512 /**< Default TFTP data block size */
15
+#define	TFTP_MAX_BLKSIZE     1432
16
+
17
+#define TFTP_RRQ		1 /**< Read request opcode */
18
+#define TFTP_WRQ		2 /**< Write request opcode */
19
+#define TFTP_DATA		3 /**< Data block opcode */
20
+#define TFTP_ACK		4 /**< Data block acknowledgement opcode */
21
+#define TFTP_ERROR		5 /**< Error opcode */
22
+#define TFTP_OACK		6 /**< Options acknowledgement opcode */
23
+
24
+#define TFTP_ERR_FILE_NOT_FOUND	1 /**< File not found */
25
+#define TFTP_ERR_ACCESS_DENIED	2 /**< Access violation */
26
+#define TFTP_ERR_DISK_FULL	3 /**< Disk full or allocation exceeded */
27
+#define TFTP_ERR_ILLEGAL_OP	4 /**< Illegal TFTP operation */
28
+#define TFTP_ERR_UNKNOWN_TID	5 /**< Unknown transfer ID */
29
+#define TFTP_ERR_FILE_EXISTS	6 /**< File already exists */
30
+#define TFTP_ERR_UNKNOWN_USER	7 /**< No such user */
31
+#define TFTP_ERR_BAD_OPTS	8 /**< Option negotiation failed */
32
+
33
+/** A TFTP read request (RRQ) packet */
34
+struct tftp_rrq {
35
+	uint16_t opcode;
36
+	char data[0];
37
+} __attribute__ (( packed ));
38
+
39
+/** A TFTP data (DATA) packet */
40
+struct tftp_data {
41
+	uint16_t opcode;
42
+	uint16_t block;
43
+	uint8_t data[0];
44
+} __attribute__ (( packed ));
45
+ 
46
+/** A TFTP acknowledgement (ACK) packet */
47
+struct tftp_ack {
48
+	uint16_t opcode;
49
+	uint16_t block;
50
+} __attribute__ (( packed ));
51
+
52
+/** A TFTP error (ERROR) packet */
53
+struct tftp_error {
54
+	uint16_t opcode;
55
+	uint16_t errcode;
56
+	char errmsg[0];
57
+} __attribute__ (( packed ));
58
+
59
+/** A TFTP options acknowledgement (OACK) packet */
60
+struct tftp_oack {
61
+	uint16_t opcode;
62
+	uint8_t data[0];
63
+} __attribute__ (( packed ));
64
+
65
+/** The common header of all TFTP packets */
66
+struct tftp_common {
67
+	uint16_t opcode;
68
+} __attribute__ (( packed ));
69
+
70
+/** A union encapsulating all TFTP packet types */
71
+union tftp_any {
72
+	struct tftp_common	common;
73
+	struct tftp_rrq		rrq;
74
+	struct tftp_data	data;
75
+	struct tftp_ack		ack;
76
+	struct tftp_error	error;
77
+	struct tftp_oack	oack;
78
+};	
79
+
80
+/**
81
+ * A TFTP session
82
+ *
83
+ * This data structure holds the state for an ongoing TFTP transfer.
84
+ */
85
+struct tftp_session {
86
+	/** UDP connection */
87
+	struct udp_connection udp;
88
+	/** Filename */
89
+	const char *filename;
90
+	/**
91
+	 * Transfer ID
92
+	 *
93
+	 * This is the transfer ID allocated by the server, used as
94
+	 * the server UDP port for all packets except the initial read
95
+	 * request.
96
+	 */
97
+	uint16_t tid;
98
+	/** Session state
99
+	 *
100
+	 * This is the block number to be used in the next ACK sent
101
+	 * back to the server, i.e. the number of the last received
102
+	 * data block.  The value zero indicates that the last
103
+	 * received block was an OACK (i.e. that the next ACK will
104
+	 * contain a block number of zero), and any value less than
105
+	 * zero indicates that the connection has not yet been opened
106
+	 * (i.e. that no blocks have yet been received).
107
+	 */
108
+	int state;
109
+	/** Data block size
110
+	 *
111
+	 * This is the "blksize" option negotiated with the TFTP
112
+	 * server.  (If the TFTP server does not support TFTP options,
113
+	 * this will default to 512).
114
+	 */
115
+	unsigned int blksize;
116
+	/** File size
117
+	 *
118
+	 * This is the value returned in the "tsize" option from the
119
+	 * TFTP server.  If the TFTP server does not support the
120
+	 * "tsize" option, this value will be zero.
121
+	 */
122
+	off_t tsize;
123
+};
124
+
125
+#endif /* _GPXE_TFTP_H */

Laden…
Annuleren
Opslaan