39#ifndef TFTP_SERVER_SUPPORT
40 #define TFTP_SERVER_SUPPORT ENABLED
41#elif (TFTP_SERVER_SUPPORT != ENABLED && TFTP_SERVER_SUPPORT != DISABLED)
42 #error TFTP_SERVER_SUPPORT parameter is not valid
46#ifndef TFTP_SERVER_STACK_SIZE
47 #define TFTP_SERVER_STACK_SIZE 650
48#elif (TFTP_SERVER_STACK_SIZE < 1)
49 #error TFTP_SERVER_STACK_SIZE parameter is not valid
53#ifndef TFTP_SERVER_PRIORITY
54 #define TFTP_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL
58#ifndef TFTP_SERVER_MAX_CONNECTIONS
59 #define TFTP_SERVER_MAX_CONNECTIONS 2
60#elif (TFTP_SERVER_MAX_CONNECTIONS < 1)
61 #error TFTP_SERVER_MAX_CONNECTIONS parameter is not valid
65#ifndef TFTP_SERVER_TICK_INTERVAL
66 #define TFTP_SERVER_TICK_INTERVAL 500
67#elif (TFTP_SERVER_TICK_INTERVAL < 100)
68 #error TFTP_SERVER_TICK_INTERVAL parameter is not valid
72#ifndef TFTP_SERVER_MAX_RETRIES
73 #define TFTP_SERVER_MAX_RETRIES 5
74#elif (TFTP_SERVER_MAX_RETRIES < 1)
75 #error TFTP_SERVER_MAX_RETRIES parameter is not valid
79#ifndef TFTP_SERVER_TIMEOUT
80 #define TFTP_SERVER_TIMEOUT 5000
81#elif (TFTP_SERVER_TIMEOUT < 1000)
82 #error TFTP_SERVER_TIMEOUT parameter is not valid
86#ifndef TFTP_SERVER_FINAL_DELAY
87 #define TFTP_SERVER_FINAL_DELAY 10000
88#elif (TFTP_SERVER_FINAL_DELAY < 1000)
89 #error TFTP_SERVER_FINAL_DELAY parameter is not valid
93#ifndef TFTP_SERVER_BLOCK_SIZE
94 #define TFTP_SERVER_BLOCK_SIZE 512
95#elif (TFTP_SERVER_BLOCK_SIZE < 512)
96 #error TFTP_SERVER_BLOCK_SIZE parameter is not valid
100#ifndef TFTP_SERVER_PRIVATE_CONTEXT
101 #define TFTP_SERVER_PRIVATE_CONTEXT
105#define TFTP_SERVER_MAX_PACKET_SIZE (sizeof(TftpDataPacket) + TFTP_SERVER_BLOCK_SIZE)
109#define TftpClientConnection struct _TftpClientConnection
113#define TftpServerContext struct _TftpServerContext
127 TFTP_STATE_CLOSED = 0,
129 TFTP_STATE_READING = 2,
130 TFTP_STATE_WRITING = 3,
131 TFTP_STATE_READ_COMPLETE = 4,
132 TFTP_STATE_WRITE_COMPLETE = 5
140typedef void *(*TftpServerOpenFileCallback)(
const char_t *filename,
141 const char_t *mode, bool_t writeAccess);
149 size_t offset,
const uint8_t *data,
size_t length);
157 size_t offset, uint8_t *data,
size_t size,
size_t *length);
195 uint8_t
packet[TFTP_SERVER_MAX_PACKET_SIZE];
211#if (OS_STATIC_TASK_SUPPORT == ENABLED)
216 TftpClientConnection
connection[TFTP_SERVER_MAX_CONNECTIONS];
218 uint8_t
packet[TFTP_SERVER_MAX_PACKET_SIZE];
219 TFTP_SERVER_PRIVATE_CONTEXT
226error_t tftpServerInit(TftpServerContext *context,
229error_t tftpServerStart(TftpServerContext *context);
230error_t tftpServerStop(TftpServerContext *context);
232void tftpServerTask(TftpServerContext *context);
234void tftpServerDeinit(TftpServerContext *context);
error_t
Error codes.
Definition error.h:43
uint_t OsEvent
Event object.
Definition os_port_none.h:104
uint_t OsTaskId
Task identifier.
Definition os_port_none.h:97
uint32_t systime_t
System time.
Definition os_port_none.h:90
Structure describing socket events.
Definition socket.h:395
TFTP server settings.
Definition tftp_server.h:172
TftpServerReadFileCallback readFileCallback
Read file callback function.
Definition tftp_server.h:177
TftpServerWriteFileCallback writeFileCallback
Write file callback function.
Definition tftp_server.h:176
TftpServerCloseFileCallback closeFileCallback
Close file callback function.
Definition tftp_server.h:178
uint16_t port
TFTP port number.
Definition tftp_server.h:174
TftpServerOpenFileCallback openFileCallback
Open file callback function.
Definition tftp_server.h:175
NetInterface * interface
Underlying network interface.
Definition tftp_server.h:173
TFTP client connection.
Definition tftp_server.h:187
uint_t retransmitCount
Retransmission counter.
Definition tftp_server.h:194
TftpConnectionState state
Connection state.
Definition tftp_server.h:189
void * file
File pointer.
Definition tftp_server.h:191
Socket * socket
Underlying socket.
Definition tftp_server.h:190
size_t packetLen
Length of the outgoing packet.
Definition tftp_server.h:196
uint16_t block
Block number.
Definition tftp_server.h:192
systime_t timestamp
Time stamp to manage retransmissions.
Definition tftp_server.h:193
TftpServerSettings * settings
User settings.
Definition tftp_server.h:188
uint8_t packet[TFTP_SERVER_MAX_PACKET_SIZE]
Outgoing TFTP packet.
Definition tftp_server.h:195
TFTP server context.
Definition tftp_server.h:205
OsTaskTcb taskTcb
Task control block.
Definition tftp_server.h:212
Socket * socket
Listening socket.
Definition tftp_server.h:215
bool_t running
Operational state of the TFTP server.
Definition tftp_server.h:207
TftpClientConnection connection[TFTP_SERVER_MAX_CONNECTIONS]
Client connections.
Definition tftp_server.h:216
bool_t stop
Stop request.
Definition tftp_server.h:208
OsTaskId taskId
Task identifier.
Definition tftp_server.h:210
uint8_t packet[TFTP_SERVER_MAX_PACKET_SIZE]
Incoming TFTP packet.
Definition tftp_server.h:218
OsStackType taskStack[TFTP_SERVER_STACK_SIZE]
Task stack.
Definition tftp_server.h:213
TftpServerSettings settings
User settings.
Definition tftp_server.h:206
SocketEventDesc eventDesc[TFTP_SERVER_MAX_CONNECTIONS+1]
The events the application is interested in.
Definition tftp_server.h:217
OsEvent event
Event object used to poll the sockets.
Definition tftp_server.h:209
Definitions common to TFTP client and server.
void *(* TftpServerOpenFileCallback)(const char_t *filename, const char_t *mode, bool_t writeAccess)
Open file callback function.
Definition tftp_server.h:140
TftpConnectionState
TFTP connection state.
Definition tftp_server.h:126
error_t(* TftpServerWriteFileCallback)(void *file, size_t offset, const uint8_t *data, size_t length)
Write file callback function.
Definition tftp_server.h:148
void(* TftpServerCloseFileCallback)(void *file)
Close file callback function.
Definition tftp_server.h:164
error_t(* TftpServerReadFileCallback)(void *file, size_t offset, uint8_t *data, size_t size, size_t *length)
Read file callback function.
Definition tftp_server.h:156