Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tftp_common.h Source File

tftp_common.h

Go to the documentation of this file.
00001 /**
00002  * @file tftp_common.h
00003  * @brief Definitions common to TFTP client and server
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _TFTP_COMMON_H
00030 #define _TFTP_COMMON_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 
00035 //TFTP port number
00036 #define TFTP_PORT 69
00037 
00038 
00039 /**
00040  * @brief TFTP opcodes
00041  **/
00042 
00043 typedef enum
00044 {
00045    TFTP_OPCODE_RRQ   = 1, ///<Read request
00046    TFTP_OPCODE_WRQ   = 2, ///<Write request
00047    TFTP_OPCODE_DATA  = 3, ///<Data
00048    TFTP_OPCODE_ACK   = 4, ///<Acknowledgment
00049    TFTP_OPCODE_ERROR = 5, ///<Error
00050    TFTP_OPCODE_OACK  = 6  ///<Option acknowledgment
00051 } TftpOpcode;
00052 
00053 
00054 /**
00055  * @brief TFTP error codes
00056  **/
00057 
00058 typedef enum
00059 {
00060    TFTP_ERROR_NOT_DEFINED         = 0,
00061    TFTP_ERROR_FILE_NOT_FOUND      = 1,
00062    TFTP_ERROR_ACCESS_VIOLATION    = 2,
00063    TFTP_ERROR_DISK_FULL           = 3,
00064    TFTP_ERROR_ILLEGAL_OPERATION   = 4,
00065    TFTP_ERROR_UNKNOWN_TID         = 5,
00066    TFTP_ERROR_FILE_ALREADY_EXISTS = 6,
00067    TFTP_ERROR_NO_SUCH_USER        = 7
00068 } TftpErrorCode;
00069 
00070 
00071 //CodeWarrior or Win32 compiler?
00072 #if defined(__CWCC__) || defined(_WIN32)
00073    #pragma pack(push, 1)
00074 #endif
00075 
00076 
00077 /**
00078  * @brief Read request packet (RRQ)
00079  **/
00080 
00081 typedef __start_packed struct
00082 {
00083    uint16_t opcode;   //0-1
00084    char_t filename[]; //2
00085 } __end_packed TftpRrqPacket;
00086 
00087 
00088 /**
00089  * @brief Write request packet (WRQ)
00090  **/
00091 
00092 typedef __start_packed struct
00093 {
00094    uint16_t opcode;   //0-1
00095    char_t filename[]; //2
00096 } __end_packed TftpWrqPacket;
00097 
00098 
00099 /**
00100  * @brief Data packet (DATA)
00101  **/
00102 
00103 typedef __start_packed struct
00104 {
00105    uint16_t opcode; //0-1
00106    uint16_t block;  //2-3
00107    uint8_t data[];  //4
00108 } __end_packed TftpDataPacket;
00109 
00110 
00111 /**
00112  * @brief Acknowledgment packet (ACK)
00113  **/
00114 
00115 typedef __start_packed struct
00116 {
00117    uint16_t opcode; //0-1
00118    uint16_t block;  //2-3
00119 } __end_packed TftpAckPacket;
00120 
00121 
00122 /**
00123  * @brief Error packet (ERROR)
00124  **/
00125 
00126 typedef __start_packed struct
00127 {
00128    uint16_t opcode;    //0-1
00129    uint16_t errorCode; //2-3
00130    char_t errorMsg[];  //4
00131 } __end_packed TftpErrorPacket;
00132 
00133 
00134 //CodeWarrior or Win32 compiler?
00135 #if defined(__CWCC__) || defined(_WIN32)
00136    #pragma pack(pop)
00137 #endif
00138 
00139 #endif
00140