ftp.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ftp.h  -  description
00003                              -------------------
00004     begin                : mer 31 01 2007
00005     copyright            : (C) 2007 by Aurion s.r.l.
00006     email                : fabio.giovagnini@aurion-tech.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00028 /*
00029  * Copyright (c) 2007, Aurion s.r.l.
00030  * All rights reserved.
00031  *
00032  * Redistribution and use in source and binary forms, with or without
00033  * modification, are permitted provided that the following conditions
00034  * are met:
00035  * 1. Redistributions of source code must retain the above copyright
00036  *    notice, this list of conditions and the following disclaimer.
00037  * 2. Redistributions in binary form must reproduce the above copyright
00038  *    notice, this list of conditions and the following disclaimer in the
00039  *    documentation and/or other materials provided with the distribution.
00040  * 3. The name of the author may not be used to endorse or promote
00041  *    products derived from this software without specific prior
00042  *    written permission.
00043  *
00044  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00045  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00046  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00047  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00048  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00049  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00050  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00051  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00052  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00053  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00054  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00055  *
00056  * This file is part of the uIP TCP/IP stack.
00057  *
00058  * $Id: ftp.h,v 1.0.0.0 2007/01/31 21:23:49 fabio Exp $
00059  *
00060  */
00061 
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065 
00066 #ifndef __ARNFTP_H__
00067 #define __ARNFTP_H__
00068 
00069 typedef unsigned char           arn_uCHAR;
00070 typedef unsigned short          arn_uSHORT;
00071 typedef unsigned long           arn_uLONG;
00072 typedef arn_uLONG               arn_uINT;
00073 
00074 typedef signed char             arn_sCHAR;
00075 typedef signed short            arn_sSHORT;
00076 typedef signed long             arn_sLONG;
00077 typedef arn_sLONG               arn_sINT;
00078 
00079 typedef char                    arn_CHAR;
00080 typedef short                   arn_SHORT;
00081 typedef long                    arn_LONG;
00082 typedef int                     arn_INT;
00083 
00084 /* END - C Native Types */
00085 
00086 #define arnTRUE                 ((arn_uCHAR) 1)
00087 #define arnFALSE                ((arn_uCHAR) 0)
00088 typedef arn_uCHAR               arn_BOOL;
00089 
00090 #define MAX_FILENAME_LEN                128
00091 #define FTP_FLAG_CMDREQUEST             0x01
00092 #define FTP_FLAG_DATAPENDING    0x02
00093 #define FTP_FLAG_LASTDATAACK    0x04
00094 #define FTP_FLAG_CTRL                   0x80
00095 #define FTP_FLAG_DATA                   0x40
00096 
00097 struct ftp_state {
00098         struct uip_conn * dconn;        
00099         arn_uCHAR*      dataptr;                
00100         arn_uLONG       count;                  
00101         arn_uCHAR*      fSAddr;                 
00102         arn_uLONG       fSize;                  
00103         arn_uSHORT      errorCode;              
00104         arn_uSHORT localdataport;       
00105         arn_uSHORT remotedataport;      
00106         arn_uSHORT remotectrlport;      
00107         arn_uCHAR       Status;                 
00108         arn_uCHAR       CmdSnt;                 
00109         arn_uCHAR       AnsRcv;                 
00110         arn_uCHAR       flags;          
00111         arn_CHAR        fname[MAX_FILENAME_LEN];        
00112         arn_uCHAR       data[MAX_FILENAME_LEN + 8];
00113         };
00114 
00115 
00116 void ftp_init(void);
00117 void ftp_appcall(void);
00118 
00119 // callback functions and API
00120 typedef enum ftp_cmd_status {
00121         ftpcs_NONE = 0,
00122         ftpcs_INPROGRESS,
00123         ftpcs_SUCCESS,
00124         ftpcs_FAILED,
00125         ftpcs_USERNAME_REQ,
00126         ftpcs_PASSWORD_REQ
00127         } ftp_cmd_status_t;
00128 ftp_cmd_status_t ftp_connect(arn_CHAR* host,arn_uSHORT rport,struct uip_conn **sconn);
00129 ftp_cmd_status_t ftp_login(const struct uip_conn *sconn,arn_CHAR* username);
00130 ftp_cmd_status_t ftp_password(const struct uip_conn *sconn,arn_CHAR* password);
00131 ftp_cmd_status_t ftp_syst(const struct uip_conn *sconn,arn_CHAR* res);
00132 ftp_cmd_status_t ftp_port(const struct uip_conn *sconn,arn_uSHORT ldataport);
00133 ftp_cmd_status_t ftp_pasv(const struct uip_conn *sconn);
00134 ftp_cmd_status_t ftp_send(const struct uip_conn *sconn,arn_CHAR* filename,arn_uCHAR* sadd,arn_uLONG size);
00135 ftp_cmd_status_t ftp_quit(const struct uip_conn *sconn);
00136 
00137 
00138 #define STS_NONE                                                0
00139 #define STS_ERROR                                               (STS_NONE + 1)
00140 #define STS_WAITFORCONN                                 (STS_ERROR + 1)
00141 #define STS_CONNECTED                                   (STS_WAITFORCONN + 1)
00142 #define STS_SENDINGFILE                                 (STS_CONNECTED + 1)
00143 #define STS_UPOLOADOK                                   (STS_SENDINGFILE + 1)
00144 #define STS_LOGGINGIN                                   (STS_UPOLOADOK + 1)
00145 #define STS_LOGGEDIN                                    (STS_LOGGINGIN + 1)
00146 #define STS_SYST_INPROG                                 (STS_LOGGEDIN + 1)
00147 #define STS_SYST_OK                                             (STS_SYST_INPROG + 1)
00148 #define STS_PORT_INPROG                                 (STS_SYST_OK + 1)
00149 #define STS_PORT_OK                                             (STS_PORT_INPROG + 1)
00150 #define STS_DATACONN_INPROG                             (STS_PORT_OK + 1)
00151 #define STS_DATACONN_OK                                 (STS_DATACONN_INPROG + 1)
00152 #define STS_STOR_INPROG                                 (STS_DATACONN_OK + 1)
00153 #define STS_START_DATASTORE                             (STS_STOR_INPROG + 1)
00154 #define STS_SENDDATA_INPROG                             (STS_START_DATASTORE + 1)               // 16 , 0x10
00155 #define STS_SENDDATA_ENDING                             (STS_SENDDATA_INPROG + 1)
00156 #define STS_SENDDATA_OK                                 (STS_SENDDATA_ENDING + 1)
00157 #define STS_DATACONN_CLOSED_OK                  (STS_SENDDATA_OK + 1)
00158 #define STS_QUIT_INPROG                                 (STS_DATACONN_CLOSED_OK + 1)
00159 #define STS_QUIT_OK                                             (STS_QUIT_INPROG + 1)
00160 #define STS_IDLE                                                (STS_QUIT_OK + 1)
00161 arn_uCHAR ftp_getStatus(const struct uip_conn *sconn);
00162 
00163 #define ERRC_NONE                                               0
00164 #define ERRC_HOSTNAMENOTIP                              (ERRC_NONE + 1)
00165 #define ERRC_CONN                                               (ERRC_HOSTNAMENOTIP + 1)
00166 #define ERRC_FNAMETOLOONG                               (ERRC_CONN + 1)
00167 #define ERRC_SRV_WM                                             (ERRC_FNAMETOLOONG + 1)
00168 #define ERRC_LOGIN                                              (ERRC_SRV_WM + 1)
00169 #define ERRC_SYST                                               (ERRC_LOGIN + 1)
00170 #define ERRC_PORT                                               (ERRC_SYST + 1)
00171 #define ERRC_CONN_DATA                                  (ERRC_PORT + 1)
00172 #define ERRC_STOR                                               (ERRC_CONN_DATA + 1)
00173 #define ERRC_QUIT                                               (ERRC_STOR + 1)
00174 #define ERRC_PASS                                               (ERRC_QUIT + 1)
00175 arn_uCHAR ftp_getErrorCode(const struct uip_conn *sconn);
00176 
00177 
00178 /* UIP_APPCALL: the name of the application function. This function
00179    must return void and take no arguments (i.e., C type "void
00180    appfunc(void)"). */
00181 //#ifndef UIP_APPCALL
00182 //#define UIP_APPCALL     ftp_appcall
00183 //#endif
00184 
00185 
00186 /* UIP_APPSTATE_SIZE: The size of the application-specific state
00187    stored in the uip_conn structure. */
00188 #ifndef UIP_APPSTATE_SIZE
00189 #define UIP_APPSTATE_SIZE (sizeof(struct ftp_state))
00190 #endif
00191 
00192 
00193 #endif /* __ARNFTPD_H__ */
00194 
00195 #ifdef __cplusplus
00196 }
00197 #endif