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-2023 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.3.2
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 //CodeWarrior or Win32 compiler?
79 #if defined(__CWCC__) || defined(_WIN32)
80  #pragma pack(push, 1)
81 #endif
82 
83 
84 /**
85  * @brief Read request packet (RRQ)
86  **/
87 
89 {
90  uint16_t opcode; //0-1
93 
94 
95 /**
96  * @brief Write request packet (WRQ)
97  **/
98 
99 typedef __packed_struct
100 {
101  uint16_t opcode; //0-1
102  char_t filename[]; //2
104 
105 
106 /**
107  * @brief Data packet (DATA)
108  **/
109 
110 typedef __packed_struct
111 {
112  uint16_t opcode; //0-1
113  uint16_t block; //2-3
114  uint8_t data[]; //4
116 
117 
118 /**
119  * @brief Acknowledgment packet (ACK)
120  **/
121 
122 typedef __packed_struct
123 {
124  uint16_t opcode; //0-1
125  uint16_t block; //2-3
127 
128 
129 /**
130  * @brief Error packet (ERROR)
131  **/
132 
133 typedef __packed_struct
134 {
135  uint16_t opcode; //0-1
136  uint16_t errorCode; //2-3
139 
140 
141 //CodeWarrior or Win32 compiler?
142 #if defined(__CWCC__) || defined(_WIN32)
143  #pragma pack(pop)
144 #endif
145 
146 //C++ guard
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif
char char_t
Definition: compiler_port.h:48
uint8_t opcode
Definition: dns_common.h:186
TCP/IP stack core.
uint16_t block
Definition: tftp_common.h:113
TftpAckPacket
Definition: tftp_common.h:126
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:114
TftpDataPacket
Definition: tftp_common.h:115
uint16_t errorCode
Definition: tftp_common.h:136
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:137
char_t filename[]
Definition: tftp_common.h:91
TftpRrqPacket
Definition: tftp_common.h:92
typedef __packed_struct
Read request packet (RRQ)
Definition: tftp_common.h:89
TftpErrorPacket
Definition: tftp_common.h:138
TftpWrqPacket
Definition: tftp_common.h:103