mikroSDK Reference Manual
tftp_client.h
Go to the documentation of this file.
1
31#ifndef _TFTP_CLIENT_H
32#define _TFTP_CLIENT_H
33
34//Dependencies
35#include "core/net.h"
36#include "tftp/tftp_common.h"
37
38//TFTP client support
39#ifndef TFTP_CLIENT_SUPPORT
40 #define TFTP_CLIENT_SUPPORT ENABLED
41#elif (TFTP_CLIENT_SUPPORT != ENABLED && TFTP_CLIENT_SUPPORT != DISABLED)
42 #error TFTP_CLIENT_SUPPORT parameter is not valid
43#endif
44
45//TFTP client tick interval
46#ifndef TFTP_CLIENT_TICK_INTERVAL
47 #define TFTP_CLIENT_TICK_INTERVAL 500
48#elif (TFTP_CLIENT_TICK_INTERVAL < 100)
49 #error TFTP_CLIENT_TICK_INTERVAL parameter is not valid
50#endif
51
52//Maximum number of retransmissions of packets
53#ifndef TFTP_CLIENT_MAX_RETRIES
54 #define TFTP_CLIENT_MAX_RETRIES 5
55#elif (TFTP_CLIENT_MAX_RETRIES < 1)
56 #error TFTP_CLIENT_MAX_RETRIES parameter is not valid
57#endif
58
59//Retransmission timeout
60#ifndef TFTP_CLIENT_TIMEOUT
61 #define TFTP_CLIENT_TIMEOUT 5000
62#elif (TFTP_CLIENT_TIMEOUT < 1000)
63 #error TFTP_CLIENT_TIMEOUT parameter is not valid
64#endif
65
66//Additional delay before closing the connection (when sending the final ACK)
67#ifndef TFTP_CLIENT_FINAL_DELAY
68 #define TFTP_CLIENT_FINAL_DELAY 10000
69#elif (TFTP_CLIENT_FINAL_DELAY < 1000)
70 #error TFTP_CLIENT_FINAL_DELAY parameter is not valid
71#endif
72
73//Block size
74#ifndef TFTP_CLIENT_BLOCK_SIZE
75 #define TFTP_CLIENT_BLOCK_SIZE 512
76#elif (TFTP_CLIENT_BLOCK_SIZE < 512)
77 #error TFTP_CLIENT_BLOCK_SIZE parameter is not valid
78#endif
79
80//Application specific context
81#ifndef TFTP_CLIENT_PRIVATE_CONTEXT
82 #define TFTP_CLIENT_PRIVATE_CONTEXT
83#endif
84
85//Maximum size of TFTP packets
86#define TFTP_CLIENT_MAX_PACKET_SIZE (sizeof(TftpDataPacket) + TFTP_CLIENT_BLOCK_SIZE)
87
88//C++ guard
89#ifdef __cplusplus
90extern "C" {
91#endif
92
93
98typedef enum
99{
100 TFTP_FILE_MODE_READ = 0,
101 TFTP_FILE_MODE_WRITE = 1,
102 TFTP_FILE_MODE_OCTET = 0,
103 TFTP_FILE_MODE_NETASCII = 2
105
106
111typedef enum
112{
113 TFTP_CLIENT_STATE_CLOSED = 0,
114 TFTP_CLIENT_STATE_RRQ = 1,
115 TFTP_CLIENT_STATE_WRQ = 2,
116 TFTP_CLIENT_STATE_DATA = 3,
117 TFTP_CLIENT_STATE_ACK = 4,
118 TFTP_CLIENT_STATE_LAST_DATA = 5,
119 TFTP_CLIENT_STATE_COMPLETE = 6,
120 TFTP_CLIENT_STATE_ERROR = 7
122
123
128typedef struct
129{
130 NetInterface *interface;
131 IpAddr serverIpAddr;
132 uint16_t serverPort;
133 uint16_t serverTid;
134 Socket *socket;
136 uint16_t block;
139 uint8_t inPacket[TFTP_CLIENT_MAX_PACKET_SIZE];
140 size_t inPacketLen;
141 size_t inDataLen;
142 size_t inDataPos;
143 uint8_t outPacket[TFTP_CLIENT_MAX_PACKET_SIZE];
145 size_t outDataLen;
146 TFTP_CLIENT_PRIVATE_CONTEXT
148
149
150//TFTP client related functions
151error_t tftpClientInit(TftpClientContext *context);
152
153error_t tftpClientBindToInterface(TftpClientContext *context,
154 NetInterface *interface);
155
156error_t tftpClientConnect(TftpClientContext *context,
157 const IpAddr *serverIpAddr, uint16_t serverPort);
158
159error_t tftpClientOpenFile(TftpClientContext *context,
160 const char_t *filename, uint_t mode);
161
162error_t tftpClientWriteFile(TftpClientContext *context,
163 const void *data, size_t length, size_t *written, uint_t flags);
164
165error_t tftpClientFlushFile(TftpClientContext *context);
166
167error_t tftpClientReadFile(TftpClientContext *context,
168 void *data, size_t size, size_t *received, uint_t flags);
169
170error_t tftpClientCloseFile(TftpClientContext *context);
171
172void tftpClientDeinit(TftpClientContext *context);
173
174//C++ guard
175#ifdef __cplusplus
176}
177#endif
178
179#endif
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
IP network address.
Definition ip.h:72
TFTP client context.
Definition tftp_client.h:129
size_t outPacketLen
Length of the outgoing packet.
Definition tftp_client.h:144
systime_t timestamp
Time stamp to manage retransmissions.
Definition tftp_client.h:137
TftpClientState state
TFTP client state.
Definition tftp_client.h:135
uint_t retransmitCount
Retransmission counter.
Definition tftp_client.h:138
Socket * socket
Underlying UDP socket.
Definition tftp_client.h:134
uint16_t block
Block number.
Definition tftp_client.h:136
size_t inPacketLen
Length of the outgoing packet.
Definition tftp_client.h:140
NetInterface * interface
Underlying network interface.
Definition tftp_client.h:130
TftpClientState
TFTP client state.
Definition tftp_client.h:112
TftpFileMode
File access modes.
Definition tftp_client.h:99
Definitions common to TFTP client and server.