/[H8]/trunk/docs/Microchip TCP_IP stack/Include/TCPIP Stack/TFTPc.h
ViewVC logotype

Annotation of /trunk/docs/Microchip TCP_IP stack/Include/TCPIP Stack/TFTPc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (hide annotations) (download)
Thu Apr 19 09:01:15 2007 UTC (17 years, 3 months ago) by hedin
File MIME type: text/plain
File size: 16590 byte(s)
added the TCP/IP stack, source code.
1 hedin 15 /*********************************************************************
2     *
3     * TFTP Client module for Microchip TCP/IP Stack
4     *
5     *********************************************************************
6     * FileName: TFTPc.h
7     * Dependencies: StackTsk.h
8     * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
9     * Complier: Microchip C18 v3.02 or higher
10     * Microchip C30 v2.01 or higher
11     * Company: Microchip Technology, Inc.
12     *
13     * Software License Agreement
14     *
15     * Copyright © 2002-2007 Microchip Technology Inc. All rights
16     * reserved.
17     *
18     * Microchip licenses to you the right to use, modify, copy, and
19     * distribute:
20     * (i) the Software when embedded on a Microchip microcontroller or
21     * digital signal controller product (“Device”) which is
22     * integrated into Licensee’s product; or
23     * (ii) ONLY the Software driver source files ENC28J60.c and
24     * ENC28J60.h ported to a non-Microchip device used in
25     * conjunction with a Microchip ethernet controller for the
26     * sole purpose of interfacing with the ethernet controller.
27     *
28     * You should refer to the license agreement accompanying this
29     * Software for additional information regarding your rights and
30     * obligations.
31     *
32     * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT
33     * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
34     * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
35     * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
36     * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
37     * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
38     * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
39     * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
40     * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
41     * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
42     * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
43     *
44     * Author Date Comment
45     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46     * Nilesh Rajbharti 8/5/03 Original (Rev 1.0)
47     ********************************************************************/
48     #ifndef __TFTPC_H
49     #define __TFTPC_H
50    
51     #if defined(STACK_USE_TFTP_CLIENT)
52    
53    
54     // Number of seconds to wait before declaring TIMEOUT error on Get.
55     #define TFTP_GET_TIMEOUT_VAL (3 * TICKS_PER_SECOND)
56    
57     // Number of seconds to wait before declaring TIMEOUT error on Put
58     #define TFTP_ARP_TIMEOUT_VAL (3 * TICKS_PER_SECOND)
59    
60     // Number of attempts before declaring TIMEOUT error.
61     #define TFTP_MAX_RETRIES (3)
62    
63     // Retry count must be 1 or more.
64     #if TFTP_MAX_RETRIES <= 0
65     #error Retry count must at least be 1
66     #endif
67    
68     // Enum. of results returned by most of the TFTP functions.
69     typedef enum _TFTP_RESULT
70     {
71     TFTP_OK = 0,
72     TFTP_NOT_READY,
73     TFTP_END_OF_FILE,
74     TFTP_ERROR,
75     TFTP_RETRY,
76     TFTP_TIMEOUT
77     } TFTP_RESULT;
78    
79     // File open mode as used by TFTPFileOpen().
80     typedef enum _TFTP_FILE_MODE
81     {
82     TFTP_FILE_MODE_READ = 1,
83     TFTP_FILE_MODE_WRITE = 2
84     } TFTP_FILE_MODE;
85    
86     // Standard error codes as defined by TFTP spec.
87     // Use to decode value retuned by TFTPGetError().
88     typedef enum _TFTP_ACCESS_ERROR
89     {
90     TFTP_ERROR_NOT_DEFINED = 0,
91     TFTP_ERROR_FILE_NOT_FOUND,
92     TFTP_ERROR_ACCESS_VIOLATION,
93     TFTP_ERROR_DISK_FULL,
94     TFTP_ERROR_INVALID_OPERATION,
95     TFTP_ERROR_UNKNOWN_TID,
96     TFTP_ERROR_FILE_EXISTS,
97     TFTP_ERROR_NO_SUCH_USE
98     } TFTP_ACCESS_ERROR;
99    
100     /*********************************************************************
101     * Function: void TFTPOpen(IP_ADDR *host)
102     *
103     * PreCondition: UDP module is already initialized
104     * and at least one UDP socket is available.
105     *
106     * Input: host - IP address of remote TFTP server
107     *
108     * Output: None
109     *
110     * Side Effects: None
111     *
112     * Overview: Initiates ARP for given host and prepares
113     * TFTP module for next sequence of function calls.
114     *
115     * Note: Use TFTPIsOpened() to check if a connection was
116     * successfully opened or not.
117     *
118     ********************************************************************/
119     void TFTPOpen(IP_ADDR *host);
120    
121    
122     /*********************************************************************
123     * Function: TFTP_RESULT TFTPIsOpened(void)
124     *
125     * PreCondition: TFTPOpen() is already called.
126     *
127     * Input: None
128     *
129     * Output: TFTP_OK if previous call to TFTPOpen is complete
130     *
131     * TFTP_TIMEOUT if remote host did not respond to
132     * previous ARP request.
133     *
134     * TFTP_NOT_READY if remote has still not responded
135     * and timeout has not expired.
136     *
137     * Side Effects: None
138     *
139     * Overview: Waits for ARP reply and opens a UDP socket
140     * to perform further TFTP operations.
141     *
142     * Note: Once opened, application may keep TFTP socket
143     * open and future TFTP operations.
144     * If TFTPClose() is called to close the connection
145     * TFTPOpen() must be called again before performing
146     * any other TFTP operations.
147     ********************************************************************/
148     TFTP_RESULT TFTPIsOpened(void);
149    
150    
151     /*********************************************************************
152     * Macro: void TFTPClose(void)
153     *
154     * PreCondition: TFTPOpen is already called and TFTPIsOpened()
155     * returned TFTP_OK.
156     *
157     * Input: None
158     *
159     * Output: None
160     *
161     * Side Effects: None
162     *
163     * Overview: Closes TFTP client socket.
164     *
165     * Note: Once closed, application must do TFTPOpen to
166     * perform any new TFTP operations.
167     *
168     * If TFTP server does not change during application
169     * life-time, one may not need to call TFTPClose
170     * and keep TFTP socket open.
171     ********************************************************************/
172     #define TFTPClose(void) UDPClose(_tftpSocket)
173     extern UDP_SOCKET _tftpSocket;
174    
175    
176    
177     /*********************************************************************
178     * Macro: BOOL TFTPIsFileOpenReady(void)
179     *
180     * PreCondition: TFTPOpen is already called and TFTPIsOpened()
181     * returned TFTP_OK.
182     *
183     * Input: None
184     *
185     * Output: TRUE, if it is ok to call TFTPOpenFile()
186     * FALSE, if otherwise.
187     *
188     * Side Effects: None
189     *
190     * Overview: Checks to see if it is okay to send TFTP file
191     * open request to remote server.
192     *
193     * Note: None
194     ********************************************************************/
195     #define TFTPIsFileOpenReady() UDPIsPutReady(_tftpSocket)
196    
197    
198    
199     /*********************************************************************
200     * Function: void TFTPOpenFile(char *fileName,
201     * TFTP_FILE_MODE mode)
202     *
203     * PreCondition: TFPTIsFileOpenReady() = TRUE
204     *
205     * Input: fileName - File name that is to be opened.
206     * mode - Mode of file access
207     * Must be
208     * TFTP_FILE_MODE_READ for read
209     * TFTP_FILE_MODE_WRITE for write
210     *
211     * Output: None
212     *
213     * Side Effects: None
214     *
215     * Overview: Prepares and sends TFTP file name and mode packet.
216     *
217     * Note: By default, this funciton uses "octet" or binary
218     * mode of file transfer.
219     * Use TFTPIsFileOpened() to check if file is
220     * ready to be read or written.
221     ********************************************************************/
222     void TFTPOpenFile(char *fileName, TFTP_FILE_MODE mode);
223    
224    
225     /*********************************************************************
226     * Function: TFTP_RESULT TFTPIsFileOpened(void)
227     *
228     * PreCondition: TFTPOpenFile() is called.
229     *
230     * Input: None
231     *
232     * Output: TFTP_OK if file is ready to be read or written
233     *
234     * TFTP_RETRY if previous attempt was timed out
235     * needs to be retried.
236     *
237     * TFTP_TIMEOUT if all attempts were exhausted.
238     *
239     * TFTP_NOT_ERROR if remote server responded with
240     * error
241     *
242     * TFTP_NOT_READY if file is not yet opened.
243     *
244     * Side Effects: None
245     *
246     * Overview: Waits for remote server response regarding
247     * previous attempt to open file.
248     * If no response is received within specified
249     * timeout, fnction returns with TFTP_RETRY
250     * and application logic must issue another
251     * TFTPFileOpen().
252     *
253     * Note: None
254     ********************************************************************/
255     TFTP_RESULT TFTPIsFileOpened(void);
256    
257     /*********************************************************************
258     * Function: void TFTPCloseFile(void)
259     *
260     * PreCondition: TFTPOpenFile() was called and TFTPIsFileOpened()
261     * had returned with TFTP_OK.
262     *
263     * Input: None
264     *
265     * Output: None
266     *
267     * Side Effects: None
268     *
269     * Overview: If file is opened in read mode, it makes sure
270     * that last ACK is sent to server
271     * If file is opened in write mode, it makes sure
272     * that last block is sent out to server and
273     * waits for server to respond with ACK.
274     *
275     * Note: TFTPIsFileClosed() must be called to confirm
276     * if file was really closed.
277     ********************************************************************/
278     void TFTPCloseFile(void);
279    
280    
281     /*********************************************************************
282     * Function: TFTP_RESULT TFPTIsFileClosed(void)
283     *
284     * PreCondition: TFTPCloseFile() is already called.
285     *
286     * Input: None
287     *
288     * Output: TFTP_OK if file was successfully closdd
289     *
290     * TFTP_RETRY if file mode was Write and remote
291     * server did not receive last packet.
292     * Application must retry with last block.
293     *
294     * TFTP_TIMEOUT if all attempts were exhausted
295     * in closing file.
296     *
297     * TFTP_ERROR if remote server sent an error
298     * in response to last block.
299     * Actual error code may be read by calling
300     * TFTPGetError()
301     *
302     * TFTP_NOT_READY if file is not closed yet.
303     *
304     * Side Effects: None
305     *
306     * Overview: If file mode is Read, it simply makes that
307     * last block is acknowledged.
308     * If file mode is Write, it waits for server ack.
309     * If no ack was received within specified timeout
310     * instructs appliaction to resend last block.
311     * It keeps track of retries and declares timeout
312     * all attempts were exhausted.
313     *
314     * Note: None
315     ********************************************************************/
316     TFTP_RESULT TFTPIsFileClosed(void);
317    
318    
319    
320     /*********************************************************************
321     * Function: TFTP_RESULT TFTPIsGetReady(void)
322     *
323     * PreCondition: TFTPOpenFile() is called with TFTP_FILE_MODE_READ
324     * and TFTPIsFileOpened() returned with TRUE.
325     *
326     * Input: None
327     *
328     * Output: TFTP_OK if it there is more data byte available
329     * to read
330     *
331     * TFTP_TIMEOUT if timeout occurred waiting for
332     * new data.
333     *
334     * TFTP_END_OF_FILE if end of file has reached.
335     *
336     * TFTP_ERROR if remote server returned ERROR.
337     * Actual error code may be read by calling
338     * TFTPGetError()
339     *
340     * TFTP_NOT_READY if still waiting for new data.
341     *
342     * Side Effects: None
343     *
344     * Overview: Waits for data block. If data block does not
345     * arrive within specified timeout, it automatically
346     * sends out ack for previous block to remind
347     * server to send next data block.
348     * If all attempts are exhausted, it returns with
349     * TFTP_TIMEOUT.
350     *
351     * Note: By default, this funciton uses "octet" or binary
352     * mode of file transfer.
353     ********************************************************************/
354     TFTP_RESULT TFTPIsGetReady(void);
355    
356    
357     /*********************************************************************
358     * Function: BYTE TFTPGet(void)
359     *
360     * PreCondition: TFTPOpenFile() is called with TFTP_FILE_MODE_READ
361     * and TFTPIsGetReady() = TRUE
362     *
363     * Input: None
364     *
365     * Output: data byte as received from remote server.
366     *
367     * Side Effects: None
368     *
369     * Overview: Fetches next data byte from TFTP socket.
370     * If end of data block is reached, it issues
371     * ack to server so that next data block can be
372     * received.
373     *
374     * Note: Use this function to read file from server.
375     ********************************************************************/
376     BYTE TFTPGet(void);
377    
378    
379     /*********************************************************************
380     * Function: TFTP_RESULT TFTPIsPutReady(void)
381     *
382     * PreCondition: TFTPOpenFile() is called with TFTP_FILE_MODE_WRITE
383     * and TFTPIsFileOpened() returned with TRUE.
384     *
385     * Input: None
386     *
387     * Output: TFTP_OK if it is okay to write more data byte.
388     *
389     * TFTP_TIMEOUT if timeout occurred waiting for
390     * ack from server
391     *
392     * TFTP_RETRY if all server did not send ack
393     * on time and application needs to resend
394     * last block.
395     *
396     * TFTP_ERROR if remote server returned ERROR.
397     * Actual error code may be read by calling
398     * TFTPGetError()
399     *
400     * TFTP_NOT_READY if still waiting...
401     *
402     * Side Effects: None
403     *
404     * Overview: Waits for ack from server. If ack does not
405     * arrive within specified timeout, it it instructs
406     * application to retry last block by returning
407     * TFTP_RETRY.
408     *
409     * If all attempts are exhausted, it returns with
410     * TFTP_TIMEOUT.
411     *
412     * Note: None
413     ********************************************************************/
414     TFTP_RESULT TFTPIsPutReady(void);
415    
416    
417     /*********************************************************************
418     * Function: void TFTPPut(BYTE c)
419     *
420     * PreCondition: TFTPOpenFile() is called with TFTP_FILE_MODE_WRITE
421     * and TFTPIsPutReady() = TRUE
422     *
423     * Input: c - Data byte that is to be written
424     *
425     * Output: None
426     *
427     * Side Effects: None
428     *
429     * Overview: Puts given data byte into TFTP socket.
430     * If end of data block is reached, it
431     * transmits entire block.
432     *
433     * Note: Use this function to write file to server.
434     ********************************************************************/
435     void TFTPPut(BYTE c);
436    
437    
438     /*********************************************************************
439     * Macro: WORD TFTPGetError(void)
440     *
441     * PreCondition: One of the TFTP function returned with
442     * TFTP_ERROR result.
443     *
444     * Input: None
445     *
446     * Output: Error code as returned by remote server.
447     * Application may use TFTP_ACCESS_ERROR enum. to
448     * decode standard error code.
449     *
450     * Side Effects: None
451     *
452     * Overview: Returns previously saved error code.
453     *
454     * Note: None
455     ********************************************************************/
456     #define TFTPGetError() (_tftpError)
457     extern WORD _tftpError;
458    
459    
460     #endif //#if defined(STACK_USE_TFTP_CLIENT)
461    
462    
463     #endif

  ViewVC Help
Powered by ViewVC 1.1.20