mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-01 17:47:56 +08:00
Added +TCP code to main repo.
This commit is contained in:
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.
|
||||
* Authors include Hein Tibosch and Richard Barry
|
||||
*
|
||||
*******************************************************************************
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*** ***
|
||||
*** ***
|
||||
*** FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP ***
|
||||
*** demos have a dependency on FreeRTOS+FAT, which is only in the Labs ***
|
||||
*** download): ***
|
||||
*** ***
|
||||
*** FreeRTOS+TCP is functional and has been used in commercial products ***
|
||||
*** for some time. Be aware however that we are still refining its ***
|
||||
*** design, the source code does not yet quite conform to the strict ***
|
||||
*** coding and style standards mandated by Real Time Engineers ltd., and ***
|
||||
*** the documentation and testing is not necessarily complete. ***
|
||||
*** ***
|
||||
*** PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE ***
|
||||
*** URL: http://www.FreeRTOS.org/contact Active early adopters may, at ***
|
||||
*** the sole discretion of Real Time Engineers Ltd., be offered versions ***
|
||||
*** under a license other than that described below. ***
|
||||
*** ***
|
||||
*** ***
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*******************************************************************************
|
||||
*
|
||||
* FreeRTOS+TCP can be used under two different free open source licenses. The
|
||||
* license that applies is dependent on the processor on which FreeRTOS+TCP is
|
||||
* executed, as follows:
|
||||
*
|
||||
* If FreeRTOS+TCP is executed on one of the processors listed under the Special
|
||||
* License Arrangements heading of the FreeRTOS+TCP license information web
|
||||
* page, then it can be used under the terms of the FreeRTOS Open Source
|
||||
* License. If FreeRTOS+TCP is used on any other processor, then it can be used
|
||||
* under the terms of the GNU General Public License V2. Links to the relevant
|
||||
* licenses follow:
|
||||
*
|
||||
* The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license
|
||||
* The FreeRTOS Open Source License: http://www.FreeRTOS.org/license
|
||||
* The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* FreeRTOS+TCP is distributed in the hope that it will be useful. You cannot
|
||||
* use FreeRTOS+TCP unless you agree that you use the software 'as is'.
|
||||
* FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
|
||||
* implied, expressed, or statutory.
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/plus
|
||||
* http://www.FreeRTOS.org/labs
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __FTPCMD_H__
|
||||
|
||||
#define __FTPCMD_H__
|
||||
|
||||
#define REPL_110 "110 Restart marker reply.\r\n"
|
||||
#define REPL_120 "120 Try again in 2 minutes.\r\n"
|
||||
#define REPL_125 "125 Data connection already open; transfer starting.\r\n"
|
||||
#define REPL_150 "150 File status okay; about to open data connection.\r\n"
|
||||
#define REPL_200 "200 NOOP command successful.\r\n"
|
||||
#define REPL_200_PROGRESS "200 NOOP: data transfer in progress.\r\n"
|
||||
#define REPL_202 "202 Command not implemented, superfluous at this site.\r\n"
|
||||
#define REPL_211 "221 System status, or system help reply.\r\n"
|
||||
#define REPL_211_STATUS "221-status of %s.\r\n"
|
||||
#define REPL_211_END "221 End of status.\r\n"
|
||||
#define REPL_212 "212 Directory status.\r\n"
|
||||
#define REPL_213 "213 File status.\r\n"
|
||||
#define REPL_214 "214 Help message.\r\n"
|
||||
#define REPL_214_END "214 End Help message.\r\n"
|
||||
#define REPL_215 "215 %s system type.\r\n"
|
||||
#define REPL_220 "220 Service ready for new user.\r\n"
|
||||
#define REPL_221 "221 Service closing control connection.\r\n"
|
||||
#define REPL_225 "225 Data connection open; no transfer in progress.\r\n"
|
||||
#define REPL_226 "226 Closing data connection.\r\n"
|
||||
#define REPL_227 "227 Entering Passive Mode (%s,%s,%s,%s,%s,%s).\r\n"
|
||||
#define REPL_227_D "227 Entering Passive Mode (%u,%u,%u,%u,%u,%u).\r\n"
|
||||
#define REPL_230 "230 User logged in, proceed.\r\n"
|
||||
#define REPL_250 "250 Requested file action okay, completed.\r\n"
|
||||
#define REPL_257 "257 %s created.\r\n"
|
||||
// #define REPL_257_PWD "257 \"%s\" is current working dir.\r\n"
|
||||
#define REPL_257_PWD "257 \"%s\"\r\n"
|
||||
#define REPL_331 "331 Only anonymous user is accepted.\r\n"
|
||||
#define REPL_331_ANON "331 Anonymous login okay\r\n"
|
||||
#define REPL_332 "332 Need account for login.\r\n"
|
||||
#define REPL_350 "350 Requested file action pending further information.\r\n"
|
||||
#define REPL_421 "421 Service not available, closing control connection.\r\n"
|
||||
#define REPL_425 "425 Can't open data connection.\r\n"
|
||||
#define REPL_426 "426 Connection closed; transfer aborted.\r\n"
|
||||
#define REPL_450 "450 Requested file action not taken.\r\n"
|
||||
#define REPL_451 "451 Requested action aborted. Local error in processing.\r\n"
|
||||
#define REPL_452 "452 Requested action not taken.\r\n"
|
||||
#define REPL_500 "500 Syntax error, command unrecognized.\r\n"
|
||||
#define REPL_501 "501 Syntax error in parameters or arguments.\r\n"
|
||||
#define REPL_502 "502 Command not implemented.\r\n"
|
||||
#define REPL_503 "503 Bad sequence of commands.\r\n"
|
||||
#define REPL_504 "504 Command not implemented for that parameter.\r\n"
|
||||
#define REPL_530 "530 Not logged in.\r\n"
|
||||
#define REPL_532 "532 Need account for storing files.\r\n"
|
||||
#define REPL_550 "550 Requested action not taken.\r\n"
|
||||
#define REPL_551 "551 Requested action aborted. Page type unknown.\r\n"
|
||||
#define REPL_552 "552 Requested file action aborted.\r\n"
|
||||
#define REPL_553 "553 Requested action not taken.\r\n"
|
||||
#define REPL_553_READ_ONLY "553 Read-only file-system.\r\n"
|
||||
|
||||
enum EFTPCommand {
|
||||
ECMD_USER,
|
||||
ECMD_PASS,
|
||||
ECMD_ACCT,
|
||||
ECMD_CWD,
|
||||
ECMD_CDUP,
|
||||
ECMD_SMNT,
|
||||
ECMD_QUIT,
|
||||
ECMD_REIN,
|
||||
ECMD_PORT,
|
||||
ECMD_PASV,
|
||||
ECMD_TYPE,
|
||||
ECMD_STRU,
|
||||
ECMD_MODE,
|
||||
ECMD_RETR,
|
||||
ECMD_STOR,
|
||||
ECMD_STOU,
|
||||
ECMD_APPE,
|
||||
ECMD_ALLO,
|
||||
ECMD_REST,
|
||||
ECMD_RNFR,
|
||||
ECMD_RNTO,
|
||||
ECMD_ABOR,
|
||||
ECMD_SIZE,
|
||||
ECMD_MDTM,
|
||||
ECMD_DELE,
|
||||
ECMD_RMD,
|
||||
ECMD_MKD,
|
||||
ECMD_PWD,
|
||||
ECMD_LIST,
|
||||
ECMD_NLST,
|
||||
ECMD_SITE,
|
||||
ECMD_SYST,
|
||||
ECMD_FEAT,
|
||||
ECMD_STAT,
|
||||
ECMD_HELP,
|
||||
ECMD_NOOP,
|
||||
ECMD_EMPTY,
|
||||
ECMD_CLOSE,
|
||||
ECMD_UNKNOWN,
|
||||
};
|
||||
|
||||
typedef struct xFTP_COMMAND {
|
||||
BaseType_t xCommandLength;
|
||||
const char pcCommandName[7];
|
||||
const unsigned char ucCommandType;
|
||||
const unsigned char checkLogin;
|
||||
const unsigned char checkNullArg;
|
||||
} FTPCommand_t;
|
||||
|
||||
#define FTP_CMD_COUNT (ECMD_UNKNOWN+1)
|
||||
|
||||
extern const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ];
|
||||
|
||||
#endif // __FTPCMD_H__
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.
|
||||
* Authors include Hein Tibosch and Richard Barry
|
||||
*
|
||||
*******************************************************************************
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*** ***
|
||||
*** ***
|
||||
*** FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP ***
|
||||
*** demos have a dependency on FreeRTOS+FAT, which is only in the Labs ***
|
||||
*** download): ***
|
||||
*** ***
|
||||
*** FreeRTOS+TCP is functional and has been used in commercial products ***
|
||||
*** for some time. Be aware however that we are still refining its ***
|
||||
*** design, the source code does not yet quite conform to the strict ***
|
||||
*** coding and style standards mandated by Real Time Engineers ltd., and ***
|
||||
*** the documentation and testing is not necessarily complete. ***
|
||||
*** ***
|
||||
*** PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE ***
|
||||
*** URL: http://www.FreeRTOS.org/contact Active early adopters may, at ***
|
||||
*** the sole discretion of Real Time Engineers Ltd., be offered versions ***
|
||||
*** under a license other than that described below. ***
|
||||
*** ***
|
||||
*** ***
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*******************************************************************************
|
||||
*
|
||||
* FreeRTOS+TCP can be used under two different free open source licenses. The
|
||||
* license that applies is dependent on the processor on which FreeRTOS+TCP is
|
||||
* executed, as follows:
|
||||
*
|
||||
* If FreeRTOS+TCP is executed on one of the processors listed under the Special
|
||||
* License Arrangements heading of the FreeRTOS+TCP license information web
|
||||
* page, then it can be used under the terms of the FreeRTOS Open Source
|
||||
* License. If FreeRTOS+TCP is used on any other processor, then it can be used
|
||||
* under the terms of the GNU General Public License V2. Links to the relevant
|
||||
* licenses follow:
|
||||
*
|
||||
* The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license
|
||||
* The FreeRTOS Open Source License: http://www.FreeRTOS.org/license
|
||||
* The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* FreeRTOS+TCP is distributed in the hope that it will be useful. You cannot
|
||||
* use FreeRTOS+TCP unless you agree that you use the software 'as is'.
|
||||
* FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
|
||||
* implied, expressed, or statutory.
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/plus
|
||||
* http://www.FreeRTOS.org/labs
|
||||
*
|
||||
*/
|
||||
#ifndef FREERTOS_HTTP_COMMANDS_H
|
||||
#define FREERTOS_HTTP_COMMANDS_H
|
||||
|
||||
enum {
|
||||
WEB_REPLY_OK = 200,
|
||||
WEB_NO_CONTENT = 204,
|
||||
WEB_BAD_REQUEST = 400,
|
||||
WEB_UNAUTHORIZED = 401,
|
||||
WEB_NOT_FOUND = 404,
|
||||
WEB_GONE = 410,
|
||||
WEB_PRECONDITION_FAILED = 412,
|
||||
WEB_INTERNAL_SERVER_ERROR = 500,
|
||||
};
|
||||
|
||||
enum EWebCommand {
|
||||
ECMD_GET,
|
||||
ECMD_HEAD,
|
||||
ECMD_POST,
|
||||
ECMD_PUT,
|
||||
ECMD_DELETE,
|
||||
ECMD_TRACE,
|
||||
ECMD_OPTIONS,
|
||||
ECMD_CONNECT,
|
||||
ECMD_PATCH,
|
||||
ECMD_UNK,
|
||||
};
|
||||
|
||||
struct xWEB_COMMAND
|
||||
{
|
||||
BaseType_t xCommandLength;
|
||||
const char *pcCommandName;
|
||||
const unsigned char ucCommandType;
|
||||
};
|
||||
|
||||
#define WEB_CMD_COUNT (ECMD_UNK+1)
|
||||
|
||||
extern const struct xWEB_COMMAND xWebCommands[WEB_CMD_COUNT];
|
||||
|
||||
extern const char *webCodename (int aCode);
|
||||
|
||||
#endif /* FREERTOS_HTTP_COMMANDS_H */
|
||||
|
||||
|
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.
|
||||
* Authors include Hein Tibosch and Richard Barry
|
||||
*
|
||||
*******************************************************************************
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*** ***
|
||||
*** ***
|
||||
*** FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP ***
|
||||
*** demos have a dependency on FreeRTOS+FAT, which is only in the Labs ***
|
||||
*** download): ***
|
||||
*** ***
|
||||
*** FreeRTOS+TCP is functional and has been used in commercial products ***
|
||||
*** for some time. Be aware however that we are still refining its ***
|
||||
*** design, the source code does not yet quite conform to the strict ***
|
||||
*** coding and style standards mandated by Real Time Engineers ltd., and ***
|
||||
*** the documentation and testing is not necessarily complete. ***
|
||||
*** ***
|
||||
*** PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE ***
|
||||
*** URL: http://www.FreeRTOS.org/contact Active early adopters may, at ***
|
||||
*** the sole discretion of Real Time Engineers Ltd., be offered versions ***
|
||||
*** under a license other than that described below. ***
|
||||
*** ***
|
||||
*** ***
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*******************************************************************************
|
||||
*
|
||||
* FreeRTOS+TCP can be used under two different free open source licenses. The
|
||||
* license that applies is dependent on the processor on which FreeRTOS+TCP is
|
||||
* executed, as follows:
|
||||
*
|
||||
* If FreeRTOS+TCP is executed on one of the processors listed under the Special
|
||||
* License Arrangements heading of the FreeRTOS+TCP license information web
|
||||
* page, then it can be used under the terms of the FreeRTOS Open Source
|
||||
* License. If FreeRTOS+TCP is used on any other processor, then it can be used
|
||||
* under the terms of the GNU General Public License V2. Links to the relevant
|
||||
* licenses follow:
|
||||
*
|
||||
* The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license
|
||||
* The FreeRTOS Open Source License: http://www.FreeRTOS.org/license
|
||||
* The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* FreeRTOS+TCP is distributed in the hope that it will be useful. You cannot
|
||||
* use FreeRTOS+TCP unless you agree that you use the software 'as is'.
|
||||
* FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
|
||||
* implied, expressed, or statutory.
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/plus
|
||||
* http://www.FreeRTOS.org/labs
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Some code which is common to TCP servers like HTTP en FTP
|
||||
*/
|
||||
|
||||
#ifndef FREERTOS_TCP_SERVER_H
|
||||
#define FREERTOS_TCP_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY
|
||||
#define FTP_SERVER_USES_RELATIVE_DIRECTORY 0
|
||||
#endif
|
||||
|
||||
enum eSERVER_TYPE
|
||||
{
|
||||
eSERVER_NONE,
|
||||
eSERVER_HTTP,
|
||||
eSERVER_FTP,
|
||||
};
|
||||
|
||||
struct xFTP_CLIENT;
|
||||
|
||||
#if( ipconfigFTP_HAS_RECEIVED_HOOK != 0 )
|
||||
extern void vApplicationFTPReceivedHook( const char *pcFileName, uint32_t ulSize, struct xFTP_CLIENT *pxFTPClient );
|
||||
extern void vFTPReplyMessage( struct xFTP_CLIENT *pxFTPClient, const char *pcMessage );
|
||||
#endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */
|
||||
|
||||
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
|
||||
/*
|
||||
* Function is called when a user name has been submitted.
|
||||
* The function may return a string such as: "331 Please enter your password"
|
||||
* or return NULL to use the default reply.
|
||||
*/
|
||||
extern const char *pcApplicationFTPUserHook( const char *pcUserName );
|
||||
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
|
||||
|
||||
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
|
||||
/*
|
||||
* Function is called when a password was received.
|
||||
* Return positive value to allow the user
|
||||
*/
|
||||
extern BaseType_t xApplicationFTPPasswordHook( const char *pcUserName, const char *pcPassword );
|
||||
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
|
||||
|
||||
#if( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 )
|
||||
/*
|
||||
* The FTP server is asking for user-specific properties
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t usPortNumber; /* For reference only. Host-endian. */
|
||||
const char *pcRootDir;
|
||||
BaseType_t xReadOnly;
|
||||
}
|
||||
FTPUserProperties_t;
|
||||
extern void vApplicationFTPUserPropertiesHook( const char *pcUserName, FTPUserProperties_t *pxProperties );
|
||||
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
|
||||
|
||||
#if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
|
||||
/*
|
||||
* A GET request is received containing a special character,
|
||||
* usually a question mark.
|
||||
* const char *pcURLData; // A request, e.g. "/request?limit=75"
|
||||
* char *pcBuffer; // Here the answer can be written
|
||||
* size_t uxBufferLength; // Size of the buffer
|
||||
*
|
||||
*/
|
||||
extern size_t uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, size_t uxBufferLength );
|
||||
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
|
||||
|
||||
struct xSERVER_CONFIG
|
||||
{
|
||||
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
|
||||
BaseType_t xPortNumber; /* e.g. 80, 8080, 21 */
|
||||
BaseType_t xBackLog; /* e.g. 10, maximum number of connected TCP clients */
|
||||
const char * const pcRootDir; /* Treat this directory as the root directory */
|
||||
};
|
||||
|
||||
struct xTCP_SERVER;
|
||||
typedef struct xTCP_SERVER TCPServer_t;
|
||||
|
||||
TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount );
|
||||
void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime );
|
||||
|
||||
#if( ipconfigSUPPORT_SIGNALS != 0 )
|
||||
/* FreeRTOS_TCPServerWork() calls select().
|
||||
The two functions below provide a possibility to interrupt
|
||||
the call to select(). After the interruption, resume
|
||||
by calling FreeRTOS_TCPServerWork() again. */
|
||||
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer );
|
||||
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken );
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* FREERTOS_TCP_SERVER_H */
|
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.
|
||||
* Authors include Hein Tibosch and Richard Barry
|
||||
*
|
||||
*******************************************************************************
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*** ***
|
||||
*** ***
|
||||
*** FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP ***
|
||||
*** demos have a dependency on FreeRTOS+FAT, which is only in the Labs ***
|
||||
*** download): ***
|
||||
*** ***
|
||||
*** FreeRTOS+TCP is functional and has been used in commercial products ***
|
||||
*** for some time. Be aware however that we are still refining its ***
|
||||
*** design, the source code does not yet quite conform to the strict ***
|
||||
*** coding and style standards mandated by Real Time Engineers ltd., and ***
|
||||
*** the documentation and testing is not necessarily complete. ***
|
||||
*** ***
|
||||
*** PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE ***
|
||||
*** URL: http://www.FreeRTOS.org/contact Active early adopters may, at ***
|
||||
*** the sole discretion of Real Time Engineers Ltd., be offered versions ***
|
||||
*** under a license other than that described below. ***
|
||||
*** ***
|
||||
*** ***
|
||||
***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***
|
||||
*******************************************************************************
|
||||
*
|
||||
* FreeRTOS+TCP can be used under two different free open source licenses. The
|
||||
* license that applies is dependent on the processor on which FreeRTOS+TCP is
|
||||
* executed, as follows:
|
||||
*
|
||||
* If FreeRTOS+TCP is executed on one of the processors listed under the Special
|
||||
* License Arrangements heading of the FreeRTOS+TCP license information web
|
||||
* page, then it can be used under the terms of the FreeRTOS Open Source
|
||||
* License. If FreeRTOS+TCP is used on any other processor, then it can be used
|
||||
* under the terms of the GNU General Public License V2. Links to the relevant
|
||||
* licenses follow:
|
||||
*
|
||||
* The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license
|
||||
* The FreeRTOS Open Source License: http://www.FreeRTOS.org/license
|
||||
* The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt
|
||||
*
|
||||
* FreeRTOS+TCP is distributed in the hope that it will be useful. You cannot
|
||||
* use FreeRTOS+TCP unless you agree that you use the software 'as is'.
|
||||
* FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they
|
||||
* implied, expressed, or statutory.
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://www.FreeRTOS.org/plus
|
||||
* http://www.FreeRTOS.org/labs
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Some code which is common to TCP servers like HTTP and FTP
|
||||
*/
|
||||
|
||||
#ifndef FREERTOS_SERVER_PRIVATE_H
|
||||
#define FREERTOS_SERVER_PRIVATE_H
|
||||
|
||||
#define FREERTOS_NO_SOCKET NULL
|
||||
|
||||
/* FreeRTOS+FAT */
|
||||
#include "ff_stdio.h"
|
||||
|
||||
/* Each HTTP server has 1, at most 2 sockets */
|
||||
#define HTTP_SOCKET_COUNT 2
|
||||
|
||||
/*
|
||||
* ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
|
||||
* pcCommandBuffer': a buffer to receive and send TCP commands
|
||||
*
|
||||
* ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
|
||||
* pcFileBuffer' : a buffer to access the file system: read or write data.
|
||||
*
|
||||
* The buffers are both used for FTP as well as HTTP.
|
||||
*/
|
||||
|
||||
#ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
|
||||
#define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
|
||||
#endif
|
||||
|
||||
#ifndef ipconfigTCP_FILE_BUFFER_SIZE
|
||||
#define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
|
||||
#endif
|
||||
|
||||
struct xTCP_CLIENT;
|
||||
|
||||
typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
|
||||
typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
|
||||
|
||||
#define TCP_CLIENT_FIELDS \
|
||||
enum eSERVER_TYPE eType; \
|
||||
struct xTCP_SERVER *pxParent; \
|
||||
Socket_t xSocket; \
|
||||
const char *pcRootDir; \
|
||||
FTCPWorkFunction fWorkFunction; \
|
||||
FTCPDeleteFunction fDeleteFunction; \
|
||||
struct xTCP_CLIENT *pxNextClient
|
||||
|
||||
typedef struct xTCP_CLIENT
|
||||
{
|
||||
/* This define contains fields which must come first within each of the client structs */
|
||||
TCP_CLIENT_FIELDS;
|
||||
/* --- Keep at the top --- */
|
||||
|
||||
} TCPClient_t;
|
||||
|
||||
struct xHTTP_CLIENT
|
||||
{
|
||||
/* This define contains fields which must come first within each of the client structs */
|
||||
TCP_CLIENT_FIELDS;
|
||||
/* --- Keep at the top --- */
|
||||
|
||||
const char *pcUrlData;
|
||||
const char *pcRestData;
|
||||
char pcCurrentFilename[ ffconfigMAX_FILENAME ];
|
||||
size_t uxBytesLeft;
|
||||
FF_FILE *pxFileHandle;
|
||||
union {
|
||||
struct {
|
||||
uint32_t
|
||||
bReplySent : 1;
|
||||
};
|
||||
uint32_t ulFlags;
|
||||
} bits;
|
||||
};
|
||||
|
||||
typedef struct xHTTP_CLIENT HTTPClient_t;
|
||||
|
||||
struct xFTP_CLIENT
|
||||
{
|
||||
/* This define contains fields which must come first within each of the client structs */
|
||||
TCP_CLIENT_FIELDS;
|
||||
/* --- Keep at the top --- */
|
||||
|
||||
uint32_t ulRestartOffset;
|
||||
uint32_t ulRecvBytes;
|
||||
size_t uxBytesLeft; /* Bytes left to send */
|
||||
uint32_t ulClientIP;
|
||||
TickType_t xStartTime;
|
||||
uint16_t usClientPort;
|
||||
Socket_t xTransferSocket;
|
||||
BaseType_t xTransType;
|
||||
BaseType_t xDirCount;
|
||||
FF_FindData_t xFindData;
|
||||
FF_FILE *pxReadHandle;
|
||||
FF_FILE *pxWriteHandle;
|
||||
char pcCurrentDir[ ffconfigMAX_FILENAME ];
|
||||
char pcFileName[ ffconfigMAX_FILENAME ];
|
||||
char pcConnectionAck[ 128 ];
|
||||
char pcClientAck[ 128 ];
|
||||
union {
|
||||
struct {
|
||||
uint32_t
|
||||
bHelloSent : 1,
|
||||
bLoggedIn : 1,
|
||||
bStatusUser : 1,
|
||||
bInRename : 1,
|
||||
bReadOnly : 1;
|
||||
};
|
||||
uint32_t ulFTPFlags;
|
||||
} bits;
|
||||
union {
|
||||
struct {
|
||||
uint32_t
|
||||
bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
|
||||
bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
|
||||
bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
|
||||
bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
|
||||
bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
|
||||
};
|
||||
uint32_t ulConnFlags;
|
||||
} bits1;
|
||||
};
|
||||
|
||||
typedef struct xFTP_CLIENT FTPClient_t;
|
||||
|
||||
BaseType_t xHTTPClientWork( TCPClient_t *pxClient );
|
||||
BaseType_t xFTPClientWork( TCPClient_t *pxClient );
|
||||
|
||||
void vHTTPClientDelete( TCPClient_t *pxClient );
|
||||
void vFTPClientDelete( TCPClient_t *pxClient );
|
||||
|
||||
BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
|
||||
BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
|
||||
|
||||
struct xTCP_SERVER
|
||||
{
|
||||
SocketSet_t xSocketSet;
|
||||
/* A buffer to receive and send TCP commands, either HTTP of FTP. */
|
||||
char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
|
||||
/* A buffer to access the file system: read or write data. */
|
||||
char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
|
||||
|
||||
#if( ipconfigUSE_FTP != 0 )
|
||||
char pcNewDir[ ffconfigMAX_FILENAME ];
|
||||
#endif
|
||||
#if( ipconfigUSE_HTTP != 0 )
|
||||
char pcContentsType[40]; /* Space for the msg: "text/javascript" */
|
||||
char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */
|
||||
#endif
|
||||
BaseType_t xServerCount;
|
||||
TCPClient_t *pxClients;
|
||||
struct xSERVER
|
||||
{
|
||||
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
|
||||
const char *pcRootDir;
|
||||
Socket_t xSocket;
|
||||
} xServers[ 1 ];
|
||||
};
|
||||
|
||||
#endif /* FREERTOS_SERVER_PRIVATE_H */
|
@ -0,0 +1,71 @@
|
||||
//
|
||||
// ntpClient.h
|
||||
//
|
||||
|
||||
#ifndef __NTPCLIENT_H__
|
||||
|
||||
#define __NTPCLIENT_H__
|
||||
|
||||
#define NTP_PORT 123
|
||||
|
||||
typedef uint32_t quint32;
|
||||
typedef int32_t qint32;
|
||||
typedef uint8_t quint8;
|
||||
typedef int8_t qint8;
|
||||
|
||||
typedef union _SNtpFlags SNtpFlags;
|
||||
|
||||
/**
|
||||
* 64-bit NTP timestamp.
|
||||
*/
|
||||
struct __attribute__ ((__packed__)) _SNtpTimestamp {
|
||||
/** Number of seconds passed since Jan 1 1900, in big-endian format. */
|
||||
quint32 seconds;
|
||||
|
||||
/** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */
|
||||
quint32 fraction;
|
||||
};
|
||||
|
||||
typedef struct _SNtpTimestamp SNtpTimestamp;
|
||||
/**
|
||||
* Mandatory part of an NTP packet
|
||||
*/
|
||||
struct SNtpPacket {
|
||||
/** Flags. */
|
||||
unsigned char flags; // value 0xDB : mode 3 (client), version 3, leap indicator unknown 3
|
||||
|
||||
/** Stratum of the clock. */
|
||||
quint8 stratum; // value 0 : unspecified
|
||||
|
||||
/** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
|
||||
qint8 poll; // 10 means 1 << 10 = 1024 seconds
|
||||
|
||||
/** Precision of the clock, in log2 seconds. Note that the value is signed. */
|
||||
qint8 precision; // 0xFA = 250 = 0.015625 seconds
|
||||
|
||||
/** Round trip time to the primary reference source, in NTP short format. */
|
||||
qint32 rootDelay; // 0x5D2E = 23854 or (23854/65535)= 0.3640 sec
|
||||
|
||||
/** Nominal error relative to the primary reference source. */
|
||||
qint32 rootDispersion; // 0x0008 CAC8 = 8.7912 seconds
|
||||
|
||||
/** Reference identifier (either a 4 character string or an IP address). */
|
||||
qint8 referenceID[4]; // or just 0000
|
||||
|
||||
/** The time at which the clock was last set or corrected. */
|
||||
SNtpTimestamp referenceTimestamp; // Current time
|
||||
|
||||
/** The time at which the request departed the client for the server. */
|
||||
SNtpTimestamp originateTimestamp; // Keep 0
|
||||
|
||||
/** The time at which the request arrived at the server. */
|
||||
SNtpTimestamp receiveTimestamp; // Keep 0
|
||||
|
||||
/** The time at which the reply departed the server for client. */
|
||||
SNtpTimestamp transmitTimestamp;
|
||||
};
|
||||
|
||||
/* Add this number to get secs since 1-1-1900 */
|
||||
#define TIME1970 2208988800UL
|
||||
|
||||
#endif // __NTPCLIENT_H__
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* A simple demo for NTP using FreeRTOS+TCP
|
||||
*/
|
||||
|
||||
#ifndef NTPDEMO_H
|
||||
|
||||
#define NTPDEMO_H
|
||||
|
||||
void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user