|
@@ -12,6 +12,28 @@
|
12
|
12
|
/**
|
13
|
13
|
* Process a TFTP block
|
14
|
14
|
*
|
|
15
|
+ * @v state TFTP transfer state
|
|
16
|
+ * @v tftp_state::block Last received data block
|
|
17
|
+ * @v tftp_state::blksize Transfer block size
|
|
18
|
+ * @v data The data block to process
|
|
19
|
+ * @v buffer The buffer to fill with the data
|
|
20
|
+ * @ret True Block processed successfully
|
|
21
|
+ * @ret False Block not processed successfully
|
|
22
|
+ * @ret tftp_state::block Incremented if applicable
|
|
23
|
+ * @ret *eof End-of-file marker
|
|
24
|
+ * @err #PXENV_STATUS_TFTP_INVALID_PACKET_SIZE Packet is too large
|
|
25
|
+ * @err other As returned by fill_buffer()
|
|
26
|
+ *
|
|
27
|
+ * Process a TFTP DATA packet that has been received. If the data
|
|
28
|
+ * packet is the next data packet in the stream, its contents will be
|
|
29
|
+ * placed in the #buffer and tftp_state::block will be incremented.
|
|
30
|
+ * If the packet is the final packet, end-of-file will be indicated
|
|
31
|
+ * via #eof.
|
|
32
|
+ *
|
|
33
|
+ * If the data packet is a duplicate, then process_tftp_data() will
|
|
34
|
+ * still return True, though nothing will be done with the packet. A
|
|
35
|
+ * False return value always indicates an error that should abort the
|
|
36
|
+ * transfer.
|
15
|
37
|
*/
|
16
|
38
|
static inline int process_tftp_data ( struct tftp_state *state,
|
17
|
39
|
struct tftp_data *data,
|
|
@@ -32,7 +54,8 @@ static inline int process_tftp_data ( struct tftp_state *state,
|
32
|
54
|
if ( blksize > state->blksize ) {
|
33
|
55
|
DBG ( "TFTP: oversized block size %d (max %d)\n",
|
34
|
56
|
blksize, state->blksize );
|
35
|
|
- return 1;
|
|
57
|
+ errno = PXENV_STATUS_TFTP_INVALID_PACKET_SIZE;
|
|
58
|
+ return 0;
|
36
|
59
|
}
|
37
|
60
|
/* Place block in the buffer */
|
38
|
61
|
if ( ! fill_buffer ( buffer, data->data, state->block * state->blksize,
|
|
@@ -50,9 +73,21 @@ static inline int process_tftp_data ( struct tftp_state *state,
|
50
|
73
|
/**
|
51
|
74
|
* Download a file via TFTP
|
52
|
75
|
*
|
|
76
|
+ * @v server TFTP server
|
|
77
|
+ * @v file File name
|
|
78
|
+ * @v buffer Buffer into which to load file
|
|
79
|
+ * @ret True File was downloaded successfully
|
|
80
|
+ * @ret False File was not downloaded successfully
|
|
81
|
+ * @err #PXENV_STATUS_TFTP_UNKNOWN_OPCODE Unknown type of TFTP block received
|
|
82
|
+ * @err other As returned by tftp_open()
|
|
83
|
+ * @err other As returned by tftp_process_opts()
|
|
84
|
+ * @err other As returned by tftp_ack()
|
|
85
|
+ * @err other As returned by tftp_process_data()
|
|
86
|
+ *
|
|
87
|
+ * Download a file from a TFTP server into the specified buffer.
|
53
|
88
|
*/
|
54
|
|
-int tftp ( char *url __unused, struct sockaddr_in *server, char *file,
|
55
|
|
- struct buffer *buffer ) {
|
|
89
|
+static int tftp ( char *url __unused, struct sockaddr_in *server, char *file,
|
|
90
|
+ struct buffer *buffer ) {
|
56
|
91
|
struct tftp_state state;
|
57
|
92
|
union tftp_any *reply;
|
58
|
93
|
int eof = 0;
|