1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12 
13 
14 #ifndef _TFTP_H_
15 #define _TFTP_H_
16 
17 #include <stdint.h>
18 #include "ipv6.h"
19 
20 struct tftphdr {
21 	int16_t th_opcode;
22 	uint16_t th_data;
23 };
24 
25 struct filename_ip {
26 	uint32_t own_ip;
27 	ip6_addr_t own_ip6;
28 	uint32_t server_ip;
29 	ip6_addr_t server_ip6;
30 	ip6_addr_t dns_ip6;
31 	char filename[256];
32 	char *pl_cfgfile; /* For PXELINUX DHCPv4 option 209. Must be free()ed */
33 	char *pl_prefix;  /* For PXELINUX DHCPv4 option 210. Must be free()ed */
34 	int fd;
35 	int ip_version;
36 };
37 typedef struct filename_ip filename_ip_t;
38 
39 typedef struct {
40 	uint32_t bad_tftp_packets;
41 	uint32_t no_packets;
42 	uint32_t blocks_missed;
43 	uint32_t blocks_received;
44 } tftp_err_t;
45 
46 int tftp(filename_ip_t *fnip, unsigned char *buf, int len,
47          unsigned int retries, tftp_err_t *err);
48 int32_t handle_tftp(int fd, uint8_t *, int32_t);
49 void handle_tftp_dun(uint8_t err_code);
50 int parse_tftp_args(char buffer[], char *server_ip, char filename[], int fd, int len);
51 int tftp_get_error_info(filename_ip_t *fnip, tftp_err_t *tftperr, int rc,
52                         const char **errstr, int *ecode);
53 
54 #endif
55