mikroSDK Reference Manual
tftp_server.h
Go to the documentation of this file.
1
31#ifndef _TFTP_SERVER_H
32#define _TFTP_SERVER_H
33
34//Dependencies
35#include "core/net.h"
36#include "tftp/tftp_common.h"
37
38//TFTP server support
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
43#endif
44
45//Stack size required to run the TFTP server
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
50#endif
51
52//Priority at which the TFTP server should run
53#ifndef TFTP_SERVER_PRIORITY
54 #define TFTP_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL
55#endif
56
57//Maximum number of simultaneous connections
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
62#endif
63
64//TFTP server tick interval
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
69#endif
70
71//Maximum number of retransmissions of packets
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
76#endif
77
78//Retransmission timeout
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
83#endif
84
85//Additional delay before closing the connection (when sending the final ACK)
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
90#endif
91
92//Block size
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
97#endif
98
99//Application specific context
100#ifndef TFTP_SERVER_PRIVATE_CONTEXT
101 #define TFTP_SERVER_PRIVATE_CONTEXT
102#endif
103
104//Maximum size of TFTP packets
105#define TFTP_SERVER_MAX_PACKET_SIZE (sizeof(TftpDataPacket) + TFTP_SERVER_BLOCK_SIZE)
106
107//Forward declaration of TftpClientConnection structure
109#define TftpClientConnection struct _TftpClientConnection
110
111//Forward declaration of TftpServerContext structure
112struct _TftpServerContext;
113#define TftpServerContext struct _TftpServerContext
114
115//C++ guard
116#ifdef __cplusplus
117extern "C" {
118#endif
119
120
125typedef enum
126{
127 TFTP_STATE_CLOSED = 0,
128 TFTP_STATE_OPEN = 1,
129 TFTP_STATE_READING = 2,
130 TFTP_STATE_WRITING = 3,
131 TFTP_STATE_READ_COMPLETE = 4,
132 TFTP_STATE_WRITE_COMPLETE = 5
134
135
140typedef void *(*TftpServerOpenFileCallback)(const char_t *filename,
141 const char_t *mode, bool_t writeAccess);
142
143
149 size_t offset, const uint8_t *data, size_t length);
150
151
157 size_t offset, uint8_t *data, size_t size, size_t *length);
158
159
164typedef void (*TftpServerCloseFileCallback)(void *file);
165
166
180
181
198
199
205{
207 bool_t running;
208 bool_t stop;
211#if (OS_STATIC_TASK_SUPPORT == ENABLED)
212 OsTaskTcb taskTcb;
213 OsStackType taskStack[TFTP_SERVER_STACK_SIZE];
214#endif
215 Socket *socket;
216 TftpClientConnection connection[TFTP_SERVER_MAX_CONNECTIONS];
217 SocketEventDesc eventDesc[TFTP_SERVER_MAX_CONNECTIONS + 1];
218 uint8_t packet[TFTP_SERVER_MAX_PACKET_SIZE];
219 TFTP_SERVER_PRIVATE_CONTEXT
220};
221
222
223//TFTP server related functions
224void tftpServerGetDefaultSettings(TftpServerSettings *settings);
225
226error_t tftpServerInit(TftpServerContext *context,
227 const TftpServerSettings *settings);
228
229error_t tftpServerStart(TftpServerContext *context);
230error_t tftpServerStop(TftpServerContext *context);
231
232void tftpServerTask(TftpServerContext *context);
233
234void tftpServerDeinit(TftpServerContext *context);
235
236//C++ guard
237#ifdef __cplusplus
238}
239#endif
240
241#endif
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
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