iPXE
pxe_tftp.c
Go to the documentation of this file.
1 /** @file
2  *
3  * PXE TFTP API
4  *
5  */
6 
7 /*
8  * Copyright (C) 2004 Michael Brown <mbrown@fensystems.co.uk>.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of the
13  * License, or any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301, USA.
24  *
25  * You can also choose to distribute this program under the terms of
26  * the Unmodified Binary Distribution Licence (as given in the file
27  * COPYING.UBDL), provided that you have satisfied its requirements.
28  */
29 
30 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <errno.h>
35 #include <byteswap.h>
36 #include <ipxe/uaccess.h>
37 #include <ipxe/in.h>
38 #include <ipxe/tftp.h>
39 #include <ipxe/iobuf.h>
40 #include <ipxe/xfer.h>
41 #include <ipxe/open.h>
42 #include <ipxe/process.h>
43 #include <ipxe/uri.h>
44 #include <realmode.h>
45 #include <pxe.h>
46 
47 /** A PXE TFTP connection */
49  /** Data transfer interface */
50  struct interface xfer;
51  /** Data buffer */
53  /** Size of data buffer */
54  size_t size;
55  /** Starting offset of data buffer */
56  size_t start;
57  /** File position */
58  size_t offset;
59  /** Maximum file position */
60  size_t max_offset;
61  /** Block size */
62  size_t blksize;
63  /** Block index */
64  unsigned int blkidx;
65  /** Overall return status code */
66  int rc;
67 };
68 
69 /**
70  * Close PXE TFTP connection
71  *
72  * @v pxe_tftp PXE TFTP connection
73  * @v rc Final status code
74  */
75 static void pxe_tftp_close ( struct pxe_tftp_connection *pxe_tftp, int rc ) {
77  pxe_tftp->rc = rc;
78 }
79 
80 /**
81  * Check flow control window
82  *
83  * @v pxe_tftp PXE TFTP connection
84  * @ret len Length of window
85  */
87 
88  return pxe_tftp->blksize;
89 }
90 
91 /**
92  * Receive new data
93  *
94  * @v pxe_tftp PXE TFTP connection
95  * @v iobuf I/O buffer
96  * @v meta Transfer metadata
97  * @ret rc Return status code
98  */
100  struct io_buffer *iobuf,
101  struct xfer_metadata *meta ) {
102  size_t len = iob_len ( iobuf );
103  int rc = 0;
104 
105  /* Calculate new buffer position */
106  if ( meta->flags & XFER_FL_ABS_OFFSET )
107  pxe_tftp->offset = 0;
108  pxe_tftp->offset += meta->offset;
109 
110  /* Copy data block to buffer */
111  if ( len == 0 ) {
112  /* No data (pure seek); treat as success */
113  } else if ( pxe_tftp->offset < pxe_tftp->start ) {
114  DBG ( " buffer underrun at %zx (min %zx)",
116  rc = -ENOBUFS;
117  } else if ( ( pxe_tftp->offset + len ) >
118  ( pxe_tftp->start + pxe_tftp->size ) ) {
119  DBG ( " buffer overrun at %zx (max %zx)",
120  ( pxe_tftp->offset + len ),
121  ( pxe_tftp->start + pxe_tftp->size ) );
122  rc = -ENOBUFS;
123  } else {
125  ( pxe_tftp->offset - pxe_tftp->start ),
126  iobuf->data, len );
127  }
128 
129  /* Calculate new buffer position */
130  pxe_tftp->offset += len;
131 
132  /* Record maximum offset as the file size */
135 
136  /* Terminate transfer on error */
137  if ( rc != 0 )
139 
140  free_iob ( iobuf );
141  return rc;
142 }
143 
144 /** PXE TFTP connection interface operations */
151 };
152 
153 /** PXE TFTP connection interface descriptor */
156 
157 /** The PXE TFTP connection */
158 static struct pxe_tftp_connection pxe_tftp = {
160 };
161 
162 /**
163  * Open PXE TFTP connection
164  *
165  * @v ipaddress IP address
166  * @v port TFTP server port (in network byte order)
167  * @v filename File name
168  * @v blksize Requested block size
169  * @ret rc Return status code
170  */
171 static int pxe_tftp_open ( IP4_t ipaddress, UDP_PORT_t port,
172  UINT8_t *filename, UINT16_t blksize ) {
173  union {
174  struct sockaddr sa;
175  struct sockaddr_in sin;
176  } server;
177  struct uri *uri;
178  int rc;
179 
180  /* Reset PXE TFTP connection structure */
181  memset ( &pxe_tftp, 0, sizeof ( pxe_tftp ) );
187 
188  /* Construct URI */
189  memset ( &server, 0, sizeof ( server ) );
190  server.sin.sin_family = AF_INET;
191  server.sin.sin_addr.s_addr = ipaddress;
192  server.sin.sin_port = port;
193  DBG ( " %s", sock_ntoa ( &server.sa ) );
194  if ( port )
195  DBG ( ":%d", ntohs ( port ) );
196  DBG ( ":%s", filename );
197  uri = pxe_uri ( &server.sa, ( ( char * ) filename ) );
198  if ( ! uri ) {
199  DBG ( " could not create URI\n" );
200  return -ENOMEM;
201  }
202 
203  /* Open PXE TFTP connection */
204  if ( ( rc = xfer_open_uri ( &pxe_tftp.xfer, uri ) ) != 0 ) {
205  DBG ( " could not open (%s)\n", strerror ( rc ) );
206  return rc;
207  }
208 
209  return 0;
210 }
211 
212 /**
213  * TFTP OPEN
214  *
215  * @v tftp_open Pointer to a struct s_PXENV_TFTP_OPEN
216  * @v s_PXENV_TFTP_OPEN::ServerIPAddress TFTP server IP address
217  * @v s_PXENV_TFTP_OPEN::GatewayIPAddress Relay agent IP address, or 0.0.0.0
218  * @v s_PXENV_TFTP_OPEN::FileName Name of file to open
219  * @v s_PXENV_TFTP_OPEN::TFTPPort TFTP server UDP port
220  * @v s_PXENV_TFTP_OPEN::PacketSize TFTP blksize option to request
221  * @ret #PXENV_EXIT_SUCCESS File was opened
222  * @ret #PXENV_EXIT_FAILURE File was not opened
223  * @ret s_PXENV_TFTP_OPEN::Status PXE status code
224  * @ret s_PXENV_TFTP_OPEN::PacketSize Negotiated blksize
225  * @err #PXENV_STATUS_TFTP_INVALID_PACKET_SIZE Requested blksize too small
226  *
227  * Opens a TFTP connection for downloading a file a block at a time
228  * using pxenv_tftp_read().
229  *
230  * If s_PXENV_TFTP_OPEN::GatewayIPAddress is 0.0.0.0, normal IP
231  * routing will take place. See the relevant
232  * @ref pxe_routing "implementation note" for more details.
233  *
234  * On x86, you must set the s_PXE::StatusCallout field to a nonzero
235  * value before calling this function in protected mode. You cannot
236  * call this function with a 32-bit stack segment. (See the relevant
237  * @ref pxe_x86_pmode16 "implementation note" for more details.)
238  *
239  * @note According to the PXE specification version 2.1, this call
240  * "opens a file for reading/writing", though how writing is to be
241  * achieved without the existence of an API call %pxenv_tftp_write()
242  * is not made clear.
243  *
244  * @note Despite the existence of the numerous statements within the
245  * PXE specification of the form "...if a TFTP/MTFTP or UDP connection
246  * is active...", you cannot use pxenv_tftp_open() and
247  * pxenv_tftp_read() to read a file via MTFTP; only via plain old
248  * TFTP. If you want to use MTFTP, use pxenv_tftp_read_file()
249  * instead. Astute readers will note that, since
250  * pxenv_tftp_read_file() is an atomic operation from the point of
251  * view of the PXE API, it is conceptually impossible to issue any
252  * other PXE API call "if an MTFTP connection is active".
253  */
255  int rc;
256 
257  DBG ( "PXENV_TFTP_OPEN" );
258 
259  /* Guard against callers that fail to close before re-opening */
260  pxe_tftp_close ( &pxe_tftp, 0 );
261 
262  /* Open connection */
263  if ( ( rc = pxe_tftp_open ( tftp_open->ServerIPAddress,
264  tftp_open->TFTPPort,
265  tftp_open->FileName,
266  tftp_open->PacketSize ) ) != 0 ) {
267  tftp_open->Status = PXENV_STATUS ( rc );
268  return PXENV_EXIT_FAILURE;
269  }
270 
271  /* Wait for OACK to arrive so that we have the block size */
272  while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) &&
273  ( pxe_tftp.max_offset == 0 ) ) {
274  step();
275  }
277  tftp_open->PacketSize = pxe_tftp.blksize;
278  DBG ( " blksize=%d", tftp_open->PacketSize );
279 
280  /* EINPROGRESS is normal; we don't wait for the whole transfer */
281  if ( rc == -EINPROGRESS )
282  rc = 0;
283 
284  tftp_open->Status = PXENV_STATUS ( rc );
286 }
287 
288 /**
289  * TFTP CLOSE
290  *
291  * @v tftp_close Pointer to a struct s_PXENV_TFTP_CLOSE
292  * @ret #PXENV_EXIT_SUCCESS File was closed successfully
293  * @ret #PXENV_EXIT_FAILURE File was not closed
294  * @ret s_PXENV_TFTP_CLOSE::Status PXE status code
295  * @err None -
296  *
297  * Close a connection previously opened with pxenv_tftp_open(). You
298  * must have previously opened a connection with pxenv_tftp_open().
299  *
300  * On x86, you must set the s_PXE::StatusCallout field to a nonzero
301  * value before calling this function in protected mode. You cannot
302  * call this function with a 32-bit stack segment. (See the relevant
303  * @ref pxe_x86_pmode16 "implementation note" for more details.)
304  */
306  DBG ( "PXENV_TFTP_CLOSE" );
307 
308  pxe_tftp_close ( &pxe_tftp, 0 );
310  return PXENV_EXIT_SUCCESS;
311 }
312 
313 /**
314  * TFTP READ
315  *
316  * @v tftp_read Pointer to a struct s_PXENV_TFTP_READ
317  * @v s_PXENV_TFTP_READ::Buffer Address of data buffer
318  * @ret #PXENV_EXIT_SUCCESS Data was read successfully
319  * @ret #PXENV_EXIT_FAILURE Data was not read
320  * @ret s_PXENV_TFTP_READ::Status PXE status code
321  * @ret s_PXENV_TFTP_READ::PacketNumber TFTP packet number
322  * @ret s_PXENV_TFTP_READ::BufferSize Length of data written into buffer
323  *
324  * Reads a single packet from a connection previously opened with
325  * pxenv_tftp_open() into the data buffer pointed to by
326  * s_PXENV_TFTP_READ::Buffer. You must have previously opened a
327  * connection with pxenv_tftp_open(). The data written into
328  * s_PXENV_TFTP_READ::Buffer is just the file data; the various
329  * network headers have already been removed.
330  *
331  * The buffer must be large enough to contain a packet of the size
332  * negotiated via the s_PXENV_TFTP_OPEN::PacketSize field in the
333  * pxenv_tftp_open() call. It is worth noting that the PXE
334  * specification does @b not require the caller to fill in
335  * s_PXENV_TFTP_READ::BufferSize before calling pxenv_tftp_read(), so
336  * the PXE stack is free to ignore whatever value the caller might
337  * place there and just assume that the buffer is large enough. That
338  * said, it may be worth the caller always filling in
339  * s_PXENV_TFTP_READ::BufferSize to guard against PXE stacks that
340  * mistake it for an input parameter.
341  *
342  * The length of the TFTP data packet will be returned via
343  * s_PXENV_TFTP_READ::BufferSize. If this length is less than the
344  * blksize negotiated via s_PXENV_TFTP_OPEN::PacketSize in the call to
345  * pxenv_tftp_open(), this indicates that the block is the last block
346  * in the file. Note that zero is a valid length for
347  * s_PXENV_TFTP_READ::BufferSize, and will occur when the length of
348  * the file is a multiple of the blksize.
349  *
350  * The PXE specification doesn't actually state that calls to
351  * pxenv_tftp_read() will return the data packets in strict sequential
352  * order, though most PXE stacks will probably do so. The sequence
353  * number of the packet will be returned in
354  * s_PXENV_TFTP_READ::PacketNumber. The first packet in the file has
355  * a sequence number of one, not zero.
356  *
357  * To guard against flawed PXE stacks, the caller should probably set
358  * s_PXENV_TFTP_READ::PacketNumber to one less than the expected
359  * returned value (i.e. set it to zero for the first call to
360  * pxenv_tftp_read() and then re-use the returned s_PXENV_TFTP_READ
361  * parameter block for subsequent calls without modifying
362  * s_PXENV_TFTP_READ::PacketNumber between calls). The caller should
363  * also guard against potential problems caused by flawed
364  * implementations returning the occasional duplicate packet, by
365  * checking that the value returned in s_PXENV_TFTP_READ::PacketNumber
366  * is as expected (i.e. one greater than that returned from the
367  * previous call to pxenv_tftp_read()).
368  *
369  * On x86, you must set the s_PXE::StatusCallout field to a nonzero
370  * value before calling this function in protected mode. You cannot
371  * call this function with a 32-bit stack segment. (See the relevant
372  * @ref pxe_x86_pmode16 "implementation note" for more details.)
373  */
374 static PXENV_EXIT_t pxenv_tftp_read ( struct s_PXENV_TFTP_READ *tftp_read ) {
375  int rc;
376 
377  DBG ( "PXENV_TFTP_READ to %04x:%04x",
378  tftp_read->Buffer.segment, tftp_read->Buffer.offset );
379 
380  /* Read single block into buffer */
381  pxe_tftp.buffer = real_to_user ( tftp_read->Buffer.segment,
382  tftp_read->Buffer.offset );
385  while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) &&
386  ( pxe_tftp.offset == pxe_tftp.start ) )
387  step();
389  tftp_read->BufferSize = ( pxe_tftp.offset - pxe_tftp.start );
390  tftp_read->PacketNumber = ++pxe_tftp.blkidx;
391 
392  /* EINPROGRESS is normal if we haven't reached EOF yet */
393  if ( rc == -EINPROGRESS )
394  rc = 0;
395 
396  tftp_read->Status = PXENV_STATUS ( rc );
398 }
399 
400 /**
401  * TFTP/MTFTP read file
402  *
403  * @v tftp_read_file Pointer to a struct s_PXENV_TFTP_READ_FILE
404  * @v s_PXENV_TFTP_READ_FILE::FileName File name
405  * @v s_PXENV_TFTP_READ_FILE::BufferSize Size of the receive buffer
406  * @v s_PXENV_TFTP_READ_FILE::Buffer Address of the receive buffer
407  * @v s_PXENV_TFTP_READ_FILE::ServerIPAddress TFTP server IP address
408  * @v s_PXENV_TFTP_READ_FILE::GatewayIPAddress Relay agent IP address
409  * @v s_PXENV_TFTP_READ_FILE::McastIPAddress File's multicast IP address
410  * @v s_PXENV_TFTP_READ_FILE::TFTPClntPort Client multicast UDP port
411  * @v s_PXENV_TFTP_READ_FILE::TFTPSrvPort Server multicast UDP port
412  * @v s_PXENV_TFTP_READ_FILE::TFTPOpenTimeOut Time to wait for first packet
413  * @v s_PXENV_TFTP_READ_FILE::TFTPReopenDelay MTFTP inactivity timeout
414  * @ret #PXENV_EXIT_SUCCESS File downloaded successfully
415  * @ret #PXENV_EXIT_FAILURE File not downloaded
416  * @ret s_PXENV_TFTP_READ_FILE::Status PXE status code
417  * @ret s_PXENV_TFTP_READ_FILE::BufferSize Length of downloaded file
418  *
419  * Downloads an entire file via either TFTP or MTFTP into the buffer
420  * pointed to by s_PXENV_TFTP_READ_FILE::Buffer.
421  *
422  * The PXE specification does not make it clear how the caller
423  * requests that MTFTP be used rather than TFTP (or vice versa). One
424  * reasonable guess is that setting
425  * s_PXENV_TFTP_READ_FILE::McastIPAddress to 0.0.0.0 would cause TFTP
426  * to be used instead of MTFTP, though it is conceivable that some PXE
427  * stacks would interpret that as "use the DHCP-provided multicast IP
428  * address" instead. Some PXE stacks will not implement MTFTP at all,
429  * and will always use TFTP.
430  *
431  * It is not specified whether or not
432  * s_PXENV_TFTP_READ_FILE::TFTPSrvPort will be used as the TFTP server
433  * port for TFTP (rather than MTFTP) downloads. Callers should assume
434  * that the only way to access a TFTP server on a non-standard port is
435  * to use pxenv_tftp_open() and pxenv_tftp_read().
436  *
437  * If s_PXENV_TFTP_READ_FILE::GatewayIPAddress is 0.0.0.0, normal IP
438  * routing will take place. See the relevant
439  * @ref pxe_routing "implementation note" for more details.
440  *
441  * It is interesting to note that s_PXENV_TFTP_READ_FILE::Buffer is an
442  * #ADDR32_t type, i.e. nominally a flat physical address. Some PXE
443  * NBPs (e.g. NTLDR) are known to call pxenv_tftp_read_file() in real
444  * mode with s_PXENV_TFTP_READ_FILE::Buffer set to an address above
445  * 1MB. This means that PXE stacks must be prepared to write to areas
446  * outside base memory. Exactly how this is to be achieved is not
447  * specified, though using INT 15,87 is as close to a standard method
448  * as any, and should probably be used. Switching to protected-mode
449  * in order to access high memory will fail if pxenv_tftp_read_file()
450  * is called in V86 mode; it is reasonably to expect that a V86
451  * monitor would intercept the relatively well-defined INT 15,87 if it
452  * wants the PXE stack to be able to write to high memory.
453  *
454  * Things get even more interesting if pxenv_tftp_read_file() is
455  * called in protected mode, because there is then absolutely no way
456  * for the PXE stack to write to an absolute physical address. You
457  * can't even get around the problem by creating a special "access
458  * everything" segment in the s_PXE data structure, because the
459  * #SEGDESC_t descriptors are limited to 64kB in size.
460  *
461  * Previous versions of the PXE specification (e.g. WfM 1.1a) provide
462  * a separate API call, %pxenv_tftp_read_file_pmode(), specifically to
463  * work around this problem. The s_PXENV_TFTP_READ_FILE_PMODE
464  * parameter block splits s_PXENV_TFTP_READ_FILE::Buffer into
465  * s_PXENV_TFTP_READ_FILE_PMODE::BufferSelector and
466  * s_PXENV_TFTP_READ_FILE_PMODE::BufferOffset, i.e. it provides a
467  * protected-mode segment:offset address for the data buffer. This
468  * API call is no longer present in version 2.1 of the PXE
469  * specification.
470  *
471  * Etherboot makes the assumption that s_PXENV_TFTP_READ_FILE::Buffer
472  * is an offset relative to the caller's data segment, when
473  * pxenv_tftp_read_file() is called in protected mode.
474  *
475  * On x86, you must set the s_PXE::StatusCallout field to a nonzero
476  * value before calling this function in protected mode. You cannot
477  * call this function with a 32-bit stack segment. (See the relevant
478  * @ref pxe_x86_pmode16 "implementation note" for more details.)
479  */
481  *tftp_read_file ) {
482  int rc;
483 
484  DBG ( "PXENV_TFTP_READ_FILE to %08x+%x", tftp_read_file->Buffer,
485  tftp_read_file->BufferSize );
486 
487  /* Open TFTP file */
488  if ( ( rc = pxe_tftp_open ( tftp_read_file->ServerIPAddress, 0,
489  tftp_read_file->FileName, 0 ) ) != 0 ) {
490  tftp_read_file->Status = PXENV_STATUS ( rc );
491  return PXENV_EXIT_FAILURE;
492  }
493 
494  /* Read entire file */
495  pxe_tftp.buffer = phys_to_user ( tftp_read_file->Buffer );
496  pxe_tftp.size = tftp_read_file->BufferSize;
497  while ( ( rc = pxe_tftp.rc ) == -EINPROGRESS )
498  step();
500  tftp_read_file->BufferSize = pxe_tftp.max_offset;
501 
502  /* Close TFTP file */
503  pxe_tftp_close ( &pxe_tftp, rc );
504 
505  tftp_read_file->Status = PXENV_STATUS ( rc );
507 }
508 
509 /**
510  * TFTP GET FILE SIZE
511  *
512  * @v tftp_get_fsize Pointer to a struct s_PXENV_TFTP_GET_FSIZE
513  * @v s_PXENV_TFTP_GET_FSIZE::ServerIPAddress TFTP server IP address
514  * @v s_PXENV_TFTP_GET_FSIZE::GatewayIPAddress Relay agent IP address
515  * @v s_PXENV_TFTP_GET_FSIZE::FileName File name
516  * @ret #PXENV_EXIT_SUCCESS File size was determined successfully
517  * @ret #PXENV_EXIT_FAILURE File size was not determined
518  * @ret s_PXENV_TFTP_GET_FSIZE::Status PXE status code
519  * @ret s_PXENV_TFTP_GET_FSIZE::FileSize File size
520  *
521  * Determine the size of a file on a TFTP server. This uses the
522  * "tsize" TFTP option, and so will not work with a TFTP server that
523  * does not support TFTP options, or that does not support the "tsize"
524  * option.
525  *
526  * The PXE specification states that this API call will @b not open a
527  * TFTP connection for subsequent use with pxenv_tftp_read(). (This
528  * is somewhat daft, since the only way to obtain the file size via
529  * the "tsize" option involves issuing a TFTP open request, but that's
530  * life.)
531  *
532  * You cannot call pxenv_tftp_get_fsize() while a TFTP or UDP
533  * connection is open.
534  *
535  * If s_PXENV_TFTP_GET_FSIZE::GatewayIPAddress is 0.0.0.0, normal IP
536  * routing will take place. See the relevant
537  * @ref pxe_routing "implementation note" for more details.
538  *
539  * On x86, you must set the s_PXE::StatusCallout field to a nonzero
540  * value before calling this function in protected mode. You cannot
541  * call this function with a 32-bit stack segment. (See the relevant
542  * @ref pxe_x86_pmode16 "implementation note" for more details.)
543  *
544  * @note There is no way to specify the TFTP server port with this API
545  * call. Though you can open a file using a non-standard TFTP server
546  * port (via s_PXENV_TFTP_OPEN::TFTPPort or, potentially,
547  * s_PXENV_TFTP_READ_FILE::TFTPSrvPort), you can only get the size of
548  * a file from a TFTP server listening on the standard TFTP port.
549  * "Consistency" is not a word in Intel's vocabulary.
550  */
552  *tftp_get_fsize ) {
553  int rc;
554 
555  DBG ( "PXENV_TFTP_GET_FSIZE" );
556 
557  /* Open TFTP file */
558  if ( ( rc = pxe_tftp_open ( tftp_get_fsize->ServerIPAddress, 0,
559  tftp_get_fsize->FileName, 0 ) ) != 0 ) {
560  tftp_get_fsize->Status = PXENV_STATUS ( rc );
561  return PXENV_EXIT_FAILURE;
562  }
563 
564  /* Wait for initial seek to arrive, and record size */
565  while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) &&
566  ( pxe_tftp.max_offset == 0 ) ) {
567  step();
568  }
569  tftp_get_fsize->FileSize = pxe_tftp.max_offset;
570  DBG ( " fsize=%d", tftp_get_fsize->FileSize );
571 
572  /* EINPROGRESS is normal; we don't wait for the whole transfer */
573  if ( rc == -EINPROGRESS )
574  rc = 0;
575 
576  /* Close TFTP file */
577  pxe_tftp_close ( &pxe_tftp, rc );
578 
579  tftp_get_fsize->Status = PXENV_STATUS ( rc );
581 }
582 
583 /** PXE TFTP API */
584 struct pxe_api_call pxe_tftp_api[] __pxe_api_call = {
586  struct s_PXENV_TFTP_OPEN ),
588  struct s_PXENV_TFTP_CLOSE ),
590  struct s_PXENV_TFTP_READ ),
592  struct s_PXENV_TFTP_READ_FILE ),
594  struct s_PXENV_TFTP_GET_FSIZE ),
595 };
UINT16_t PacketNumber
TFTP packet number.
Definition: pxe_api.h:625
struct pxe_api_call pxe_tftp_api [] __pxe_api_call
PXE TFTP API.
Definition: pxe_tftp.c:584
An object interface operation.
Definition: interface.h:17
static int pxe_tftp_open(IP4_t ipaddress, UDP_PORT_t port, UINT8_t *filename, UINT16_t blksize)
Open PXE TFTP connection.
Definition: pxe_tftp.c:171
IP4_t ServerIPAddress
TFTP server IP address.
Definition: pxe_api.h:650
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
Data transfer metadata.
Definition: xfer.h:22
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
#define PXENV_EXIT_FAILURE
An error occurred.
Definition: pxe_types.h:46
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
Error codes.
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct uri * pxe_uri(struct sockaddr *sa_server, const char *filename)
Construct URI from server address and filename.
Definition: uri.c:808
#define INTF_INIT(descriptor)
Initialise a static object interface.
Definition: interface.h:217
Parameter block for pxenv_tftp_read()
Definition: pxe_api.h:623
int xfer_open_uri(struct interface *intf, struct uri *uri)
Open URI.
Definition: open.c:67
uint32_t blksize
Block size for this segment.
Definition: pccrc.h:24
#define PXENV_TFTP_READ
PXE API function code for pxenv_tftp_read()
Definition: pxe_api.h:620
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
IPv4 socket address.
Definition: in.h:82
PXENV_EXIT_t pxenv_tftp_read_file(struct s_PXENV_TFTP_READ_FILE *tftp_read_file)
TFTP/MTFTP read file.
Definition: pxe_tftp.c:480
#define ntohs(value)
Definition: byteswap.h:136
size_t size
Size of data buffer.
Definition: pxe_tftp.c:54
static size_t pxe_tftp_xfer_window(struct pxe_tftp_connection *pxe_tftp)
Check flow control window.
Definition: pxe_tftp.c:86
Uniform Resource Identifiers.
unsigned int blkidx
Block index.
Definition: pxe_tftp.c:64
Access to external ("user") memory.
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
PXENV_STATUS_t Status
PXE status code.
Definition: pxe_api.h:624
UINT32_t BufferSize
Size of data buffer.
Definition: pxe_api.h:648
#define PXE_API_CALL(_opcode, _entry, _params_type)
Define a PXE API call.
Definition: pxe.h:108
Data transfer interfaces.
UINT16_t BufferSize
Size of data buffer.
Definition: pxe_api.h:626
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct interface_descriptor pxe_tftp_xfer_desc
PXE TFTP connection interface descriptor.
Definition: pxe_tftp.c:154
UINT16_t PXENV_EXIT_t
A PXE exit code.
Definition: pxe_types.h:44
u8 port
Port number.
Definition: CIB_PRM.h:31
IP4_t ServerIPAddress
TFTP server IP address.
Definition: pxe_api.h:690
UINT8_t FileName[128]
File name.
Definition: pxe_api.h:647
#define PXENV_TFTP_READ_FILE
PXE API function code for pxenv_tftp_read_file()
Definition: pxe_api.h:642
An object interface.
Definition: interface.h:124
struct interface xfer
Data transfer interface.
Definition: pxe_tftp.c:50
static int tftp_open(struct interface *xfer, struct uri *uri)
Initiate TFTP download.
Definition: tftp.c:1148
UINT16_t UDP_PORT_t
A UDP port.
Definition: pxe_types.h:67
userptr_t buffer
Data buffer.
Definition: pxe_tftp.c:52
uint8_t UINT8_t
An 8-bit unsigned integer.
Definition: pxe_types.h:31
struct sockaddr sa
Definition: syslog.c:55
static void pxe_tftp_close(struct pxe_tftp_connection *pxe_tftp, int rc)
Close PXE TFTP connection.
Definition: pxe_tftp.c:75
size_t max_offset
Maximum file position.
Definition: pxe_tftp.c:60
static struct pxe_tftp_connection pxe_tftp
The PXE TFTP connection.
Definition: pxe_tftp.c:158
Parameter block for pxenv_tftp_get_fsize()
Definition: pxe_api.h:688
static void tftp_close(struct tftp_request *tftp, int rc)
Terminate download.
Definition: tftp.c:1060
#define EINPROGRESS
Operation in progress.
Definition: errno.h:418
int meta(WINDOW *, bool)
Generalized socket address structure.
Definition: socket.h:96
An object interface descriptor.
Definition: interface.h:55
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXENV_TFTP_OPEN
PXE API function code for pxenv_tftp_open()
Definition: pxe_api.h:571
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
TFTP protocol.
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
UINT8_t FileName[128]
File name.
Definition: pxe_api.h:692
static int pxe_tftp_xfer_deliver(struct pxe_tftp_connection *pxe_tftp, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive new data.
Definition: pxe_tftp.c:99
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
int rc
Overall return status code.
Definition: pxe_tftp.c:66
Processes.
Data transfer interface opening.
Parameter block for pxenv_tftp_close()
Definition: pxe_api.h:604
PXENV_STATUS_t Status
PXE status code.
Definition: pxe_api.h:646
#define PXENV_EXIT_SUCCESS
No error occurred.
Definition: pxe_types.h:45
#define PXENV_TFTP_CLOSE
PXE API function code for pxenv_tftp_close()
Definition: pxe_api.h:601
PXENV_STATUS_t Status
PXE status code.
Definition: pxe_api.h:689
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
size_t start
Starting offset of data buffer.
Definition: pxe_tftp.c:56
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint32_t len
Length.
Definition: ena.h:14
A PXE API call.
Definition: pxe.h:81
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
uint16_t UINT16_t
A 16-bit unsigned integer.
Definition: pxe_types.h:34
void * data
Start of data.
Definition: iobuf.h:48
void step(void)
Single-step a single process.
Definition: process.c:98
Parameter block for pxenv_tftp_read_file()
Definition: pxe_api.h:645
UINT32_t FileSize
Size of the file.
Definition: pxe_api.h:693
Parameter block for pxenv_tftp_open()
Definition: pxe_api.h:574
#define TFTP_DEFAULT_BLKSIZE
Default TFTP data block size.
Definition: tftp.h:15
ADDR32_t Buffer
Address of data buffer.
Definition: pxe_api.h:649
#define PXENV_TFTP_GET_FSIZE
PXE API function code for pxenv_tftp_get_fsize()
Definition: pxe_api.h:685
SEGOFF16_t Buffer
Address of data buffer.
Definition: pxe_api.h:627
A Uniform Resource Identifier.
Definition: uri.h:64
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
static PXENV_EXIT_t pxenv_tftp_read(struct s_PXENV_TFTP_READ *tftp_read)
TFTP READ.
Definition: pxe_tftp.c:374
static PXENV_EXIT_t pxenv_tftp_close(struct s_PXENV_TFTP_CLOSE *tftp_close)
TFTP CLOSE.
Definition: pxe_tftp.c:305
UINT32_t IP4_t
An IPv4 address.
Definition: pxe_types.h:60
static PXENV_EXIT_t pxenv_tftp_open(struct s_PXENV_TFTP_OPEN *tftp_open)
TFTP OPEN.
Definition: pxe_tftp.c:254
struct sockaddr_in sin
Definition: syslog.c:57
#define PXENV_STATUS_SUCCESS
Definition: pxe_error.h:19
static PXENV_EXIT_t pxenv_tftp_get_fsize(struct s_PXENV_TFTP_GET_FSIZE *tftp_get_fsize)
TFTP GET FILE SIZE.
Definition: pxe_tftp.c:551
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
A PXE TFTP connection.
Definition: pxe_tftp.c:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct interface_operation pxe_tftp_xfer_ops[]
PXE TFTP connection interface operations.
Definition: pxe_tftp.c:145
#define PXENV_STATUS(rc)
Derive PXENV_STATUS code from iPXE error number.
Definition: pxe_error.h:121
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
size_t blksize
Block size.
Definition: pxe_tftp.c:62
size_t offset
File position.
Definition: pxe_tftp.c:58
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33