summaryrefslogtreecommitdiff
path: root/addons/tftp/nxd_tftp_client.h
blob: af124f22b9860e9ab8718ea91e0db4f7a95f0be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2025-present Eclipse ThreadX Contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */ 
/** NetX Component                                                        */
/**                                                                       */
/**   Trivial File Transfer Protocol (TFTP) Client                        */
/**                                                                       */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/**************************************************************************/ 
/*                                                                        */ 
/*  APPLICATION INTERFACE DEFINITION                       RELEASE        */ 
/*                                                                        */ 
/*    nxd_tftp_client.h                                   PORTABLE C      */ 
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This file defines the NetX Trivial File Transfer Protocol (TFTP)    */ 
/*    Client component, including all data types and external references  */ 
/*    It is assumed that nx_api.h and nx_port.h have already been         */ 
/*    included, along with fx_api.h and fx_port.h.                        */
/*                                                                        */ 
/**************************************************************************/

#ifndef NXD_TFTP_CLIENT_H
#define NXD_TFTP_CLIENT_H

/* Determine if a C++ compiler is being used.  If so, ensure that standard
   C is used to process the API information.  */

#ifdef   __cplusplus

/* Yes, C++ compiler is present.  Use standard C.  */
extern   "C" {

#endif

#include "nx_api.h"

/* Define the NetX TFTP CLIENT ID.  */
                                             
#define NXD_TFTP_CLIENT_ID                          0x54465460UL


/* Define TFTP maximum error string.  */

#ifndef NX_TFTP_ERROR_STRING_MAX
#define NX_TFTP_ERROR_STRING_MAX            64          /* Maximum error sting size   */
#endif

/* Define TFTP UDP socket create options.  */

#ifndef NX_TFTP_TYPE_OF_SERVICE
#define NX_TFTP_TYPE_OF_SERVICE             NX_IP_NORMAL
#endif

#ifndef NX_TFTP_FRAGMENT_OPTION
#define NX_TFTP_FRAGMENT_OPTION             NX_DONT_FRAGMENT
#endif  

#ifndef NX_TFTP_TIME_TO_LIVE
#define NX_TFTP_TIME_TO_LIVE                0x80
#endif


/* If the host application wishes to specify a source port, define it here. The default is to let
   NetX choose the TFTP Client source port. */
#ifndef NX_TFTP_SOURCE_PORT
#define NX_TFTP_SOURCE_PORT                NX_ANY_PORT
#endif

#define NX_TFTP_QUEUE_DEPTH                 5
        
#define NX_TFTP_FILE_TRANSFER_MAX           512         /* 512 byte maximum file transfer                      */


/* Define open types.  */

#define NX_TFTP_OPEN_FOR_READ               0x01        /* TFTP open for reading                                */
#define NX_TFTP_OPEN_FOR_WRITE              0x02        /* TFTP open for writing                                */ 


/* Define TFTP message codes.  */

#define NX_TFTP_CODE_READ                   0x01        /* TFTP read file request                               */ 
#define NX_TFTP_CODE_WRITE                  0x02        /* TFTP write file request                              */ 
#define NX_TFTP_CODE_DATA                   0x03        /* TFTP data packet                                     */ 
#define NX_TFTP_CODE_ACK                    0x04        /* TFTP command/data acknowledgement                    */ 
#define NX_TFTP_CODE_ERROR                  0x05        /* TFTP error message                                   */ 


/* Define TFTP error code constants.  */

#define NX_TFTP_ERROR_NOT_DEFINED           0x00        /* TFTP not defined error code, see error string        */
#define NX_TFTP_ERROR_FILE_NOT_FOUND        0x01        /* TFTP file not found error code                       */ 
#define NX_TFTP_ERROR_ACCESS_VIOLATION      0x02        /* TFTP file access violation error code                */ 
#define NX_TFTP_ERROR_DISK_FULL             0x03        /* TFTP disk full error code                            */ 
#define NX_TFTP_ERROR_ILLEGAL_OPERATION     0x04        /* TFTP illegal operation error code                    */ 
#define NX_TFTP_CODE_ERROR                  0x05        /* TFTP client request received error code from server  */ 
#define NX_TFTP_ERROR_FILE_EXISTS           0x06        /* TFTP file already exists error code                  */ 
#define NX_TFTP_ERROR_NO_SUCH_USER          0x07        /* TFTP no such user error code                         */ 
#define NX_TFTP_INVALID_SERVER_ADDRESS      0x08        /* Invalid TFTP server IP extracted from received packet*/
#define NX_TFTP_NO_ACK_RECEIVED             0x09        /* Did not receive TFTP server ACK response             */
#define NX_TFTP_INVALID_BLOCK_NUMBER        0x0A        /* Invalid block number received from Server response   */
#define NX_TFTP_INVALID_INTERFACE           0x0B        /* Invalid interface for TFTP Client                    */
                                                        /* (or multihome not supported)                         */
#define NX_TFTP_INVALID_IP_VERSION          0x0C        /* Invalid or unsupported IP version specified          */


/* Define offsets into the TFTP message buffer.  */

#define NX_TFTP_CODE_OFFSET                 0           /* Offset to TFTP code in buffer                        */
#define NX_TFTP_FILENAME_OFFSET             2           /* Offset to TFTP filename in message                   */ 
#define NX_TFTP_BLOCK_NUMBER_OFFSET         2           /* Offset to TFTP block number in buffer                */ 
#define NX_TFTP_DATA_OFFSET                 4           /* Offset to TFTP data in buffer                        */ 
#define NX_TFTP_ERROR_CODE_OFFSET           2           /* Offset to TFTP error code                            */ 
#define NX_TFTP_ERROR_STRING_OFFSET         4           /* Offset to TFPT error string                          */ 


/* Define return code constants.  */

#define NX_TFTP_ERROR                       0xC0        /* TFTP internal error                                  */ 
#define NX_TFTP_TIMEOUT                     0xC1        /* TFTP timeout occurred                                */ 
#define NX_TFTP_FAILED                      0xC2        /* TFTP error                                           */ 
#define NX_TFTP_NOT_OPEN                    0xC3        /* TFTP not opened error                                */ 
#define NX_TFTP_NOT_CLOSED                  0xC4        /* TFTP not closed error                                */ 
#define NX_TFTP_END_OF_FILE                 0xC5        /* TFTP end of file error                               */ 
#define NX_TFTP_POOL_ERROR                  0xC6        /* TFTP packet pool size error - less than 560 bytes    */ 


/* Define TFTP connection states.  */

#define NX_TFTP_STATE_NOT_OPEN              0           /* TFTP connection not open                             */ 
#define NX_TFTP_STATE_OPEN                  1           /* TFTP connection open                                 */ 
#define NX_TFTP_STATE_WRITE_OPEN            2           /* TFTP connection open for writing                     */ 
#define NX_TFTP_STATE_END_OF_FILE           3           /* TFTP connection at end of file                       */ 
#define NX_TFTP_STATE_ERROR                 4           /* TFTP error condition                                 */ 
#define NX_TFTP_STATE_FINISHED              5           /* TFTP finished writing condition                      */ 


/* Define the TFTP Server UDP port number */

#define NX_TFTP_SERVER_PORT                 69          /* Port for TFTP server                                 */


/* Define the basic TFTP Client data structure.  */

typedef struct NX_TFTP_CLIENT_STRUCT 
{
    ULONG           nx_tftp_client_id;                              /* TFTP Client ID                       */
    CHAR           *nx_tftp_client_name;                            /* Name of this TFTP client             */
    UINT            nx_tftp_client_interface_index;                 /* Index specifying network interface   */
    NX_IP          *nx_tftp_client_ip_ptr;                          /* Pointer to associated IP structure   */ 
    NX_PACKET_POOL *nx_tftp_client_packet_pool_ptr;                 /* Pointer to TFTP client packet pool   */ 
    NXD_ADDRESS     nx_tftp_client_server_ip;                       /* Server's IP address                  */ 
    UINT            nx_tftp_client_server_port;                     /* Server's port number (69 originally) */ 
    UINT            nx_tftp_client_state;                           /* State of TFTP client                 */ 
    USHORT          nx_tftp_client_block_number;                    /* Block number in file transfer        */ 
    USHORT          nx_tftp_client_reserved;                        /* Reserved for future use              */ 
    UINT            nx_tftp_client_error_code;                      /* Error code received                  */ 
    CHAR            nx_tftp_client_error_string[NX_TFTP_ERROR_STRING_MAX + 1];
    NX_UDP_SOCKET   nx_tftp_client_socket;                          /* TFTP Socket                          */

} NX_TFTP_CLIENT;



#ifndef NX_TFTP_SOURCE_CODE

/* Application caller is present, perform API mapping.  */

/* Determine if error checking is desired.  If so, map API functions
   to the appropriate error checking front-ends.  Otherwise, map API
   functions to the core functions that actually perform the work.
   Note: error checking is enabled by default.  */

#ifdef NX_DISABLE_ERROR_CHECKING

/******************* Services without error checking.  ***********************/

/* NetX (IPv4 supported only) services  */
#define nx_tftp_client_file_open                _nx_tftp_client_file_open
                                
/* For NetX applications, map the NetX TFTP service to the NetX Duo TFTP service.  */
#define nx_tftp_client_create(a,b,c,d)          _nxd_tftp_client_create(a,b,c,d,NX_IP_VERSION_V4)
#define nx_tftp_client_packet_allocate(a,b,c)   _nxd_tftp_client_packet_allocate(a,b,c, NX_IP_VERSION_V4)
#define nx_tftp_client_delete                   _nxd_tftp_client_delete                         
#define nx_tftp_client_error_info_get           _nxd_tftp_client_error_info_get
#define nx_tftp_client_file_close(a)            _nxd_tftp_client_file_close(a, NX_IP_VERSION_V4)
#define nx_tftp_client_file_read(a,b,c)         _nxd_tftp_client_file_read(a,b,c,NX_IP_VERSION_V4)
#define nx_tftp_client_file_write(a,b,c)        _nxd_tftp_client_file_write(a,b,c,NX_IP_VERSION_V4)
#define nx_tftp_client_set_interface            _nxd_tftp_client_set_interface

/* NetX Duo TFTP (IPv4 and IPv6 supported) services. */
#define nxd_tftp_client_create                  _nxd_tftp_client_create
#define nxd_tftp_client_delete                  _nxd_tftp_client_delete
#define nxd_tftp_client_file_open               _nxd_tftp_client_file_open
#define nxd_tftp_client_error_info_get          _nxd_tftp_client_error_info_get
#define nxd_tftp_client_file_close              _nxd_tftp_client_file_close
#define nxd_tftp_client_file_read               _nxd_tftp_client_file_read
#define nxd_tftp_client_file_write              _nxd_tftp_client_file_write
#define nxd_tftp_client_packet_allocate         _nxd_tftp_client_packet_allocate
#define nxd_tftp_client_set_interface           _nxd_tftp_client_set_interface

#else

/*************** Services with error checking.  ******************/

/* NetX (IPv4 supported only) services  */
#define nx_tftp_client_file_open                _nxe_tftp_client_file_open
                                            
/* For NetX TFTP applications, map the NetX TFTP service to the equivalent NetX Duo TFTP service.  */
#define nx_tftp_client_create(a,b,c,d)          _nxde_tftp_client_create(a,b,c,d,NX_IP_VERSION_V4)
#define nx_tftp_client_packet_allocate(a,b,c)   _nxde_tftp_client_packet_allocate(a,b,c,NX_IP_VERSION_V4)
#define nx_tftp_client_delete                   _nxde_tftp_client_delete
#define nx_tftp_client_error_info_get           _nxde_tftp_client_error_info_get
#define nx_tftp_client_file_close(a)            _nxde_tftp_client_file_close(a, NX_IP_VERSION_V4)
#define nx_tftp_client_file_read(a,b,c)         _nxde_tftp_client_file_read(a,b,c,NX_IP_VERSION_V4)
#define nx_tftp_client_file_write(a,b,c)        _nxde_tftp_client_file_write(a,b,c,NX_IP_VERSION_V4)
#define nx_tftp_client_set_interface            _nxde_tftp_client_set_interface

/* NetX Duo (IPv4 and IPv6 supported) services. */
#define nxd_tftp_client_create                  _nxde_tftp_client_create
#define nxd_tftp_client_delete                  _nxde_tftp_client_delete
#define nxd_tftp_client_file_open               _nxde_tftp_client_file_open
#define nxd_tftp_client_error_info_get          _nxde_tftp_client_error_info_get
#define nxd_tftp_client_file_close              _nxde_tftp_client_file_close
#define nxd_tftp_client_file_read               _nxde_tftp_client_file_read
#define nxd_tftp_client_file_write              _nxde_tftp_client_file_write
#define nxd_tftp_client_packet_allocate         _nxde_tftp_client_packet_allocate
#define nxd_tftp_client_set_interface           _nxde_tftp_client_set_interface


#endif  /* NX_DISABLE_ERROR_CHECKING */

/* Define the prototypes accessible to the application software.  */

UINT        nx_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, ULONG server_ip_address, UINT open_type, ULONG wait_option);

UINT        nxd_tftp_client_create(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *tftp_client_name, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, UINT ip_type);
UINT        nxd_tftp_client_delete(NX_TFTP_CLIENT *tftp_client_ptr);
UINT        nxd_tftp_client_error_info_get(NX_TFTP_CLIENT *tftp_client_ptr, UINT *error_code, CHAR **error_string);
UINT        nxd_tftp_client_file_close(NX_TFTP_CLIENT *tftp_client_ptr, UINT ip_type);
UINT        nxd_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, NXD_ADDRESS *server_ip_address, UINT open_type, ULONG wait_option, UINT ip_type);
UINT        nxd_tftp_client_file_read(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        nxd_tftp_client_file_write(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET *packet_ptr, ULONG wait_option, UINT ip_type);
UINT        nxd_tftp_client_packet_allocate(NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        nxd_tftp_client_set_interface(NX_TFTP_CLIENT *tftpv6_client_ptr, UINT if_index);

#else

/* TFTP source code is being compiled, do not perform any API mapping.  */
             
UINT        _nxe_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, ULONG server_ip_address, UINT open_type, ULONG wait_option);
UINT        _nx_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, ULONG server_ip_address, UINT open_type, ULONG wait_option);  

UINT        _nxde_tftp_client_create(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *tftp_client_name, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, UINT ip_type);
UINT        _nxd_tftp_client_create(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *tftp_client_name, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, UINT ip_type);
UINT        _nxde_tftp_client_delete(NX_TFTP_CLIENT *tftp_client_ptr);
UINT        _nxd_tftp_client_delete(NX_TFTP_CLIENT *tftp_client_ptr);
UINT        _nxde_tftp_client_error_info_get(NX_TFTP_CLIENT *tftp_client_ptr, UINT *error_code, CHAR **error_string);
UINT        _nxd_tftp_client_error_info_get(NX_TFTP_CLIENT *tftp_client_ptr, UINT *error_code, CHAR **error_string);
UINT        _nxde_tftp_client_file_close(NX_TFTP_CLIENT *tftp_client_ptr, UINT ip_type);
UINT        _nxd_tftp_client_file_close(NX_TFTP_CLIENT *tftp_client_ptr, UINT ip_type);   
UINT        _nxde_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, NXD_ADDRESS *server_ip_address, UINT open_type, ULONG wait_option, UINT ip_type);
UINT        _nxd_tftp_client_file_open(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, NXD_ADDRESS *server_ip_address, UINT open_type, ULONG wait_option, UINT ip_type);
UINT        _nxde_tftp_client_file_read(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxd_tftp_client_file_read(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxde_tftp_client_file_write(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET *packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxd_tftp_client_file_write(NX_TFTP_CLIENT *tftp_client_ptr, NX_PACKET *packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxde_tftp_client_packet_allocate(NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxd_tftp_client_packet_allocate(NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr, ULONG wait_option, UINT ip_type);
UINT        _nxde_tftp_client_set_interface(NX_TFTP_CLIENT *tftp_client_ptr, UINT if_index);
UINT        _nxd_tftp_client_set_interface(NX_TFTP_CLIENT *tftp_client_ptr, UINT if_index);



#endif    /* NX_TFTP_SOURCE_CODE */
                            
/* Internal functions. */  
UINT  _nx_tftp_client_file_open_internal(NX_TFTP_CLIENT *tftp_client_ptr, CHAR *file_name, NXD_ADDRESS *server_ip_address, UINT open_type, ULONG wait_option, UINT  ip_type);


/* Determine if a C++ compiler is being used.  If so, complete the standard
   C conditional started above.  */
#ifdef   __cplusplus
        }
#endif   

#endif   /* NXD_TFTP_CLIENT_H */