Line 10... |
Line 10... |
* Plasma FTP server and FTP client and TFTP server and client
|
* Plasma FTP server and FTP client and TFTP server and client
|
* and Telnet server.
|
* and Telnet server.
|
*--------------------------------------------------------------------*/
|
*--------------------------------------------------------------------*/
|
#undef INCLUDE_FILESYS
|
#undef INCLUDE_FILESYS
|
#define INCLUDE_FILESYS
|
#define INCLUDE_FILESYS
|
#ifdef WIN32
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#define _LIBC
|
|
#endif
|
|
#include "rtos.h"
|
#include "rtos.h"
|
#include "tcpip.h"
|
#include "tcpip.h"
|
|
|
#ifdef DLL_SETUP
|
#ifdef DLL_SETUP
|
static void ConsoleRun(IPSocket *socket, char *argv[]);
|
static void ConsoleRun(IPSocket *socket, char *argv[]);
|
Line 205... |
Line 198... |
else
|
else
|
bytes = IPWrite(socket, info->buf + info->bytes, bytes);
|
bytes = IPWrite(socket, info->buf + info->bytes, bytes);
|
info->bytes += bytes;
|
info->bytes += bytes;
|
if(info->bytes == info->size || (bytes == 0 && state > IP_TCP))
|
if(info->bytes == info->size || (bytes == 0 && state > IP_TCP))
|
{
|
{
|
socket->userFunc(info->buf, info->bytes);
|
socket->userFunc(socket, info->buf, info->bytes);
|
free(info);
|
free(info);
|
socket->userPtr = NULL;
|
socket->userPtr = NULL;
|
IPClose(socket);
|
IPClose(socket);
|
}
|
}
|
}
|
}
|
Line 268... |
Line 261... |
}
|
}
|
|
|
|
|
IPSocket *FtpTransfer(uint32 ip, char *user, char *passwd,
|
IPSocket *FtpTransfer(uint32 ip, char *user, char *passwd,
|
char *filename, uint8 *buf, int size,
|
char *filename, uint8 *buf, int size,
|
int send, void (*callback)(uint8 *data, int size))
|
int send, IPCallbackPtr callback)
|
{
|
{
|
IPSocket *socket, *socketTransfer;
|
IPSocket *socket, *socketTransfer;
|
FtpInfo *info;
|
FtpInfo *info;
|
uint8 *ptr;
|
uint8 *ptr;
|
info = (FtpInfo*)malloc(sizeof(FtpInfo));
|
info = (FtpInfo*)malloc(sizeof(FtpInfo));
|
Line 380... |
Line 373... |
memcpy((uint8*)socket->userPtr + blockNum * 512 - 512, buf+4, bytes-4);
|
memcpy((uint8*)socket->userPtr + blockNum * 512 - 512, buf+4, bytes-4);
|
buf[1] = 4; //ACK
|
buf[1] = 4; //ACK
|
IPWrite(socket, buf, 4);
|
IPWrite(socket, buf, 4);
|
if(bytes-4 < 512)
|
if(bytes-4 < 512)
|
{
|
{
|
socket->userFunc(socket->userPtr, length);
|
socket->userFunc(socket, socket->userPtr, length);
|
IPClose(socket);
|
IPClose(socket);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
IPSocket *TftpTransfer(uint32 ip, char *filename, uint8 *buffer, int size,
|
IPSocket *TftpTransfer(uint32 ip, char *filename, uint8 *buffer, int size,
|
void (*callback)(uint8 *data, int bytes))
|
IPCallbackPtr callback)
|
{
|
{
|
IPSocket *socket;
|
IPSocket *socket;
|
uint8 buf[512+4];
|
uint8 buf[512+4];
|
int bytes;
|
int bytes;
|
socket = IPOpen(IP_MODE_UDP, ip, 69, TftpCallback);
|
socket = IPOpen(IP_MODE_UDP, ip, 69, TftpCallback);
|
Line 811... |
Line 804... |
else
|
else
|
printf("Ping Reply\n");
|
printf("Ping Reply\n");
|
}
|
}
|
|
|
|
|
static void DnsResultCallback(IPSocket *socket, uint32 ip, void *arg)
|
static void DnsResultCallback(IPSocket *socket, uint8 *arg, int ipIn)
|
{
|
{
|
char buf[COMMAND_BUFFER_SIZE];
|
char buf[COMMAND_BUFFER_SIZE];
|
IPSocket *socketTelnet = arg;
|
IPSocket *socketTelnet = (IPSocket*)arg;
|
IPSocket *socketPing;
|
IPSocket *socketPing;
|
|
uint32 ip=ipIn;
|
(void)socket;
|
(void)socket;
|
|
|
sprintf(buf, "ip=%d.%d.%d.%d\r\n",
|
sprintf(buf, "ip=%d.%d.%d.%d\r\n",
|
(uint8)(ip >> 24), (uint8)(ip >> 16), (uint8)(ip >> 8), (uint8)ip);
|
(uint8)(ip >> 24), (uint8)(ip >> 16), (uint8)(ip >> 8), (uint8)ip);
|
IPPrintf(socketTelnet, buf);
|
IPPrintf(socketTelnet, buf);
|
Line 836... |
Line 830... |
|
|
if('0' <= argv[1][0] && argv[1][0] <= '9')
|
if('0' <= argv[1][0] && argv[1][0] <= '9')
|
{
|
{
|
sscanf(argv[1], "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3);
|
sscanf(argv[1], "%d.%d.%d.%d", &ip0, &ip1, &ip2, &ip3);
|
ip0 = (ip0 << 24) | (ip1 << 16) | (ip2 << 8) | ip3;
|
ip0 = (ip0 << 24) | (ip1 << 16) | (ip2 << 8) | ip3;
|
DnsResultCallback(socket, ip0, socket);
|
DnsResultCallback(socket, (uint8*)socket, ip0);
|
}
|
}
|
else
|
else
|
{
|
{
|
IPResolve(argv[1], DnsResultCallback, socket);
|
IPResolve(argv[1], DnsResultCallback, (void*)socket);
|
IPPrintf(socket, "Sent DNS request");
|
IPPrintf(socket, "Sent DNS request");
|
}
|
}
|
}
|
}
|
|
|
|
|
static void ConsoleTransferDone(uint8 *data, int length)
|
static void ConsoleTransferDone(IPSocket *socket, uint8 *data, int length)
|
{
|
{
|
FILE *file;
|
FILE *file;
|
|
(void)socket;
|
|
|
IPPrintf(socketTelnet, "Transfer Done");
|
IPPrintf(socketTelnet, "Transfer Done");
|
file = fopen(storageFilename, "w");
|
file = fopen(storageFilename, "w");
|
if(file)
|
if(file)
|
{
|
{
|
fwrite(data, 1, length, file);
|
fwrite(data, 1, length, file);
|
Line 1067... |
Line 1063... |
TelnetFuncList[i].func = (ConsoleFunc)funcPtr;
|
TelnetFuncList[i].func = (ConsoleFunc)funcPtr;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
socket->userFunc = socket->funcPtr;
|
socket->userFunc = (IPCallbackPtr)socket->funcPtr;
|
funcPtr(socket, argv);
|
funcPtr(socket, argv);
|
}
|
}
|
|
|
|
|
typedef struct NameValue_t {
|
typedef struct NameValue_t {
|