tftp_common.h
Go to the documentation of this file.
1 /**
2  * @file tftp_common.h
3  * @brief Definitions common to TFTP client and server
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _TFTP_COMMON_H
30 #define _TFTP_COMMON_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //TFTP port number
36 #define TFTP_PORT 69
37 
38 //C++ guard
39 #ifdef __cplusplus
40  extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief TFTP opcodes
46  **/
47 
48 typedef enum
49 {
50  TFTP_OPCODE_RRQ = 1, ///<Read request
51  TFTP_OPCODE_WRQ = 2, ///<Write request
52  TFTP_OPCODE_DATA = 3, ///<Data
53  TFTP_OPCODE_ACK = 4, ///<Acknowledgment
54  TFTP_OPCODE_ERROR = 5, ///<Error
55  TFTP_OPCODE_OACK = 6 ///<Option acknowledgment
56 } TftpOpcode;
57 
58 
59 /**
60  * @brief TFTP error codes
61  **/
62 
63 typedef enum
64 {
74 
75 
76 //CodeWarrior or Win32 compiler?
77 #if defined(__CWCC__) || defined(_WIN32)
78  #pragma pack(push, 1)
79 #endif
80 
81 
82 /**
83  * @brief Read request packet (RRQ)
84  **/
85 
86 typedef __start_packed struct
87 {
88  uint16_t opcode; //0-1
91 
92 
93 /**
94  * @brief Write request packet (WRQ)
95  **/
96 
97 typedef __start_packed struct
98 {
99  uint16_t opcode; //0-1
100  char_t filename[]; //2
102 
103 
104 /**
105  * @brief Data packet (DATA)
106  **/
107 
108 typedef __start_packed struct
109 {
110  uint16_t opcode; //0-1
111  uint16_t block; //2-3
112  uint8_t data[]; //4
114 
115 
116 /**
117  * @brief Acknowledgment packet (ACK)
118  **/
119 
120 typedef __start_packed struct
121 {
122  uint16_t opcode; //0-1
123  uint16_t block; //2-3
125 
126 
127 /**
128  * @brief Error packet (ERROR)
129  **/
130 
131 typedef __start_packed struct
132 {
133  uint16_t opcode; //0-1
134  uint16_t errorCode; //2-3
137 
138 
139 //CodeWarrior or Win32 compiler?
140 #if defined(__CWCC__) || defined(_WIN32)
141  #pragma pack(pop)
142 #endif
143 
144 //C++ guard
145 #ifdef __cplusplus
146  }
147 #endif
148 
149 #endif
char_t filename[]
Definition: tftp_common.h:89
__start_packed struct @301 TftpAckPacket
Acknowledgment packet (ACK)
char char_t
Definition: compiler_port.h:41
uint16_t opcode
Definition: tftp_common.h:88
TCP/IP stack core.
__start_packed struct @300 TftpDataPacket
Data packet (DATA)
Write request.
Definition: tftp_common.h:51
TftpErrorCode
TFTP error codes.
Definition: tftp_common.h:63
Read request.
Definition: tftp_common.h:50
char_t errorMsg[]
Definition: tftp_common.h:135
uint16_t errorCode
Definition: tftp_common.h:134
TftpOpcode
TFTP opcodes.
Definition: tftp_common.h:48
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @299 TftpWrqPacket
Write request packet (WRQ)
Acknowledgment.
Definition: tftp_common.h:53
uint8_t data[]
Definition: tftp_common.h:112
__start_packed struct @302 TftpErrorPacket
Error packet (ERROR)
uint16_t block
Definition: tftp_common.h:111
Option acknowledgment.
Definition: tftp_common.h:55
__start_packed struct @298 TftpRrqPacket
Read request packet (RRQ)