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