| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /********************************************************************* |
| 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, PIC32 |
||
| 9 | * Compiler: Microchip C32 v1.05 or higher |
||
| 10 | * Microchip C30 v3.12 or higher |
||
| 11 | * Microchip C18 v3.30 or higher |
||
| 12 | * HI-TECH PICC-18 PRO 9.63PL2 or higher |
||
| 13 | * Company: Microchip Technology, Inc. |
||
| 14 | * |
||
| 15 | * Software License Agreement |
||
| 16 | * |
||
| 17 | * Copyright (C) 2002-2009 Microchip Technology Inc. All rights |
||
| 18 | * reserved. |
||
| 19 | * |
||
| 20 | * Microchip licenses to you the right to use, modify, copy, and |
||
| 21 | * distribute: |
||
| 22 | * (i) the Software when embedded on a Microchip microcontroller or |
||
| 23 | * digital signal controller product ("Device") which is |
||
| 24 | * integrated into Licensee's product; or |
||
| 25 | * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
| 26 | * ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device |
||
| 27 | * used in conjunction with a Microchip ethernet controller for |
||
| 28 | * the sole purpose of interfacing with the ethernet controller. |
||
| 29 | * |
||
| 30 | * You should refer to the license agreement accompanying this |
||
| 31 | * Software for additional information regarding your rights and |
||
| 32 | * obligations. |
||
| 33 | * |
||
| 34 | * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT |
||
| 35 | * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT |
||
| 36 | * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
||
| 37 | * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
| 38 | * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR |
||
| 39 | * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF |
||
| 40 | * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS |
||
| 41 | * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE |
||
| 42 | * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER |
||
| 43 | * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT |
||
| 44 | * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. |
||
| 45 | * |
||
| 46 | * Author Date Comment |
||
| 47 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 48 | * Nilesh Rajbharti 8/5/03 Original (Rev 1.0) |
||
| 49 | ********************************************************************/ |
||
| 50 | #ifndef __TFTPC_H |
||
| 51 | #define __TFTPC_H |
||
| 52 | |||
| 53 | #if defined(STACK_USE_TFTP_CLIENT) |
||
| 54 | |||
| 55 | |||
| 56 | // Number of seconds to wait before declaring TIMEOUT error on Get. |
||
| 57 | #define TFTP_GET_TIMEOUT_VAL (3u * TICKS_PER_SECOND) |
||
| 58 | |||
| 59 | // Number of seconds to wait before declaring TIMEOUT error on Put |
||
| 60 | #define TFTP_ARP_TIMEOUT_VAL (3u * TICKS_PER_SECOND) |
||
| 61 | |||
| 62 | // Number of attempts before declaring TIMEOUT error. |
||
| 63 | #define TFTP_MAX_RETRIES (3u) |
||
| 64 | |||
| 65 | // Retry count must be 1 or more. |
||
| 66 | #if TFTP_MAX_RETRIES <= 0u |
||
| 67 | #error Retry count must at least be 1 |
||
| 68 | #endif |
||
| 69 | |||
| 70 | // Enum. of results returned by most of the TFTP functions. |
||
| 71 | typedef enum _TFTP_RESULT |
||
| 72 | { |
||
| 73 | TFTP_OK = 0, |
||
| 74 | TFTP_NOT_READY, |
||
| 75 | TFTP_END_OF_FILE, |
||
| 76 | TFTP_ERROR, |
||
| 77 | TFTP_RETRY, |
||
| 78 | TFTP_TIMEOUT |
||
| 79 | } TFTP_RESULT; |
||
| 80 | |||
| 81 | // File open mode as used by TFTPFileOpen(). |
||
| 82 | typedef enum _TFTP_FILE_MODE |
||
| 83 | { |
||
| 84 | TFTP_FILE_MODE_READ = 1, |
||
| 85 | TFTP_FILE_MODE_WRITE = 2 |
||
| 86 | } TFTP_FILE_MODE; |
||
| 87 | |||
| 88 | // Standard error codes as defined by TFTP spec. |
||
| 89 | // Use to decode value retuned by TFTPGetError(). |
||
| 90 | typedef enum _TFTP_ACCESS_ERROR |
||
| 91 | { |
||
| 92 | TFTP_ERROR_NOT_DEFINED = 0, |
||
| 93 | TFTP_ERROR_FILE_NOT_FOUND, |
||
| 94 | TFTP_ERROR_ACCESS_VIOLATION, |
||
| 95 | TFTP_ERROR_DISK_FULL, |
||
| 96 | TFTP_ERROR_INVALID_OPERATION, |
||
| 97 | TFTP_ERROR_UNKNOWN_TID, |
||
| 98 | TFTP_ERROR_FILE_EXISTS, |
||
| 99 | TFTP_ERROR_NO_SUCH_USE |
||
| 100 | } TFTP_ACCESS_ERROR; |
||
| 101 | |||
| 102 | // Status codes for TFTPGetUploadStatus() function. Zero means upload success, >0 means working and <0 means fatal error. |
||
| 103 | #define TFTP_UPLOAD_COMPLETE 0 |
||
| 104 | #define TFTP_UPLOAD_GET_DNS 1 |
||
| 105 | #define TFTP_UPLOAD_RESOLVE_HOST 2 |
||
| 106 | #define TFTP_UPLOAD_CONNECT 3 |
||
| 107 | #define TFTP_UPLOAD_SEND_FILENAME 4 |
||
| 108 | #define TFTP_UPLOAD_SEND_DATA 5 |
||
| 109 | #define TFTP_UPLOAD_WAIT_FOR_CLOSURE 6 |
||
| 110 | #define TFTP_UPLOAD_HOST_RESOLVE_TIMEOUT -1 |
||
| 111 | #define TFTP_UPLOAD_CONNECT_TIMEOUT -2 |
||
| 112 | #define TFTP_UPLOAD_SERVER_ERROR -3 |
||
| 113 | |||
| 114 | typedef struct |
||
| 115 | { |
||
| 116 | BYTE *vDataPointer; |
||
| 117 | WORD wDataLength; |
||
| 118 | } TFTP_CHUNK_DESCRIPTOR; |
||
| 119 | |||
| 120 | void TFTPOpen(IP_ADDR *host); |
||
| 121 | TFTP_RESULT TFTPIsOpened(void); |
||
| 122 | void TFTPOpenFile(BYTE *fileName, TFTP_FILE_MODE mode); |
||
| 123 | |||
| 124 | #if defined(__18CXX) |
||
| 125 | // PIC18 ROM argument implementation of TFTPOpenFile |
||
| 126 | void TFTPOpenROMFile(ROM BYTE *fileName, TFTP_FILE_MODE mode); |
||
| 127 | #else |
||
| 128 | #define TFTPOpenROMFile(a,b) TFTPOpenFile((BYTE*)(a),b) |
||
| 129 | #endif |
||
| 130 | |||
| 131 | TFTP_RESULT TFTPIsFileOpened(void); |
||
| 132 | void TFTPCloseFile(void); |
||
| 133 | TFTP_RESULT TFTPIsFileClosed(void); |
||
| 134 | TFTP_RESULT TFTPIsGetReady(void); |
||
| 135 | BYTE TFTPGet(void); |
||
| 136 | TFTP_RESULT TFTPIsPutReady(void); |
||
| 137 | void TFTPPut(BYTE c); |
||
| 138 | |||
| 139 | void TFTPUploadRAMFileToHost(ROM BYTE *vRemoteHost, ROM BYTE *vFilename, BYTE *vData, WORD wDataLength); |
||
| 140 | void TFTPUploadFragmentedRAMFileToHost(ROM BYTE *vRemoteHost, ROM BYTE *vFilename, TFTP_CHUNK_DESCRIPTOR *vFirstChunkDescriptor); |
||
| 141 | CHAR TFTPGetUploadStatus(void); |
||
| 142 | |||
| 143 | /********************************************************************* |
||
| 144 | * Macro: void TFTPClose(void) |
||
| 145 | * |
||
| 146 | * PreCondition: TFTPOpen is already called and TFTPIsOpened() |
||
| 147 | * returned TFTP_OK. |
||
| 148 | * |
||
| 149 | * Input: None |
||
| 150 | * |
||
| 151 | * Output: None |
||
| 152 | * |
||
| 153 | * Side Effects: None |
||
| 154 | * |
||
| 155 | * Overview: Closes TFTP client socket. |
||
| 156 | * |
||
| 157 | * Note: Once closed, application must do TFTPOpen to |
||
| 158 | * perform any new TFTP operations. |
||
| 159 | * |
||
| 160 | * If TFTP server does not change during application |
||
| 161 | * life-time, one may not need to call TFTPClose |
||
| 162 | * and keep TFTP socket open. |
||
| 163 | ********************************************************************/ |
||
| 164 | #define TFTPClose(void) UDPClose(_tftpSocket) |
||
| 165 | extern UDP_SOCKET _tftpSocket; |
||
| 166 | |||
| 167 | /********************************************************************* |
||
| 168 | * Macro: BOOL TFTPIsFileOpenReady(void) |
||
| 169 | * |
||
| 170 | * PreCondition: TFTPOpen is already called and TFTPIsOpened() |
||
| 171 | * returned TFTP_OK. |
||
| 172 | * |
||
| 173 | * Input: None |
||
| 174 | * |
||
| 175 | * Output: TRUE, if it is ok to call TFTPOpenFile() |
||
| 176 | * FALSE, if otherwise. |
||
| 177 | * |
||
| 178 | * Side Effects: None |
||
| 179 | * |
||
| 180 | * Overview: Checks to see if it is okay to send TFTP file |
||
| 181 | * open request to remote server. |
||
| 182 | * |
||
| 183 | * Note: None |
||
| 184 | ********************************************************************/ |
||
| 185 | #define TFTPIsFileOpenReady() UDPIsPutReady(_tftpSocket) |
||
| 186 | /********************************************************************* |
||
| 187 | * Macro: WORD TFTPGetError(void) |
||
| 188 | * |
||
| 189 | * PreCondition: One of the TFTP function returned with |
||
| 190 | * TFTP_ERROR result. |
||
| 191 | * |
||
| 192 | * Input: None |
||
| 193 | * |
||
| 194 | * Output: Error code as returned by remote server. |
||
| 195 | * Application may use TFTP_ACCESS_ERROR enum. to |
||
| 196 | * decode standard error code. |
||
| 197 | * |
||
| 198 | * Side Effects: None |
||
| 199 | * |
||
| 200 | * Overview: Returns previously saved error code. |
||
| 201 | * |
||
| 202 | * Note: None |
||
| 203 | ********************************************************************/ |
||
| 204 | #define TFTPGetError() (_tftpError) |
||
| 205 | extern WORD _tftpError; |
||
| 206 | |||
| 207 | |||
| 208 | #endif //#if defined(STACK_USE_TFTP_CLIENT) |
||
| 209 | |||
| 210 | |||
| 211 | #endif |
Powered by WebSVN v2.8.3