OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [netutil.c] - Diff between revs 424 and 425

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 424 Rev 425
Line 85... Line 85...
{
{
   uint8 buf[600];
   uint8 buf[600];
   int bytes;
   int bytes;
   int ip0, ip1, ip2, ip3, port0, port1;
   int ip0, ip1, ip2, ip3, port0, port1;
   IPSocket *socketOut;
   IPSocket *socketOut;
   FtpdInfo *info = (FtpdInfo*)socket->userPtr;
   FtpdInfo *info;
 
 
   if(socket == NULL)
   if(socket == NULL)
      return;
      return;
 
   info = (FtpdInfo*)socket->userPtr;
   bytes = IPRead(socket, buf, sizeof(buf)-1);
   bytes = IPRead(socket, buf, sizeof(buf)-1);
   buf[bytes] = 0;
   buf[bytes] = 0;
   //printf("(%s)\n", buf);
   //printf("(%s)\n", buf);
   if(socket->userPtr == NULL)
   if(socket->userPtr == NULL)
   {
   {
Line 281... Line 282...
   info->send = send;
   info->send = send;
   info->bytes = 0;
   info->bytes = 0;
   info->state = 0;
   info->state = 0;
   info->port = 2000;
   info->port = 2000;
   socketTransfer = IPOpen(IP_MODE_TCP, 0, info->port, FtpCallbackTransfer);
   socketTransfer = IPOpen(IP_MODE_TCP, 0, info->port, FtpCallbackTransfer);
 
   if(socketTransfer == NULL)
 
      return NULL;
   socketTransfer->userPtr = info;
   socketTransfer->userPtr = info;
   socketTransfer->userFunc = callback;
   socketTransfer->userFunc = callback;
   socket = IPOpen(IP_MODE_TCP, ip, 21, FtpCallback);
   socket = IPOpen(IP_MODE_TCP, ip, 21, FtpCallback);
 
   if(socket == NULL)
 
      return NULL;
   socket->userPtr = info;
   socket->userPtr = info;
   socket->userFunc = callback;
   socket->userFunc = callback;
   ptr = socket->headerSend;
   ptr = socket->headerSend;
   info->ip = IPAddressSelf();
   info->ip = IPAddressSelf();
   return socket;
   return socket;
Line 389... Line 394...
{
{
   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);
 
   if(socket == NULL)
 
      return NULL;
   socket->userPtr = buffer;
   socket->userPtr = buffer;
   socket->userData = size;
   socket->userData = size;
   socket->userFunc = callback;
   socket->userFunc = callback;
   buf[0] = 0;
   buf[0] = 0;
   buf[1] = 1; //read
   buf[1] = 1; //read
Line 529... Line 536...
{
{
   uint8 bufIn[COMMAND_BUFFER_SIZE+4];
   uint8 bufIn[COMMAND_BUFFER_SIZE+4];
   int bytes, i, k, found, rc;
   int bytes, i, k, found, rc;
   char *ptr, *command = (char*)socket->userPtr;
   char *ptr, *command = (char*)socket->userPtr;
   char command2[COMMAND_BUFFER_SIZE];
   char command2[COMMAND_BUFFER_SIZE];
   char *argvStorage[12], **argv = argvStorage+2;
   char *argv[10];
 
 
   if(socket->state > IP_TCP)
   if(socket->state > IP_TCP)
      return;
      return;
   for(;;)
   for(;;)
   {
   {
      bytes = IPRead(socket, bufIn, sizeof(bufIn)-1);
      memset(bufIn, 0, sizeof(bufIn));
 
      bytes = IPRead(socket, bufIn, sizeof(bufIn)-4);
      if(command == NULL)
      if(command == NULL)
      {
      {
         socket->userPtr = command = (char*)malloc(COMMAND_BUFFER_SIZE);
         socket->userPtr = command = (char*)malloc(COMMAND_BUFFER_SIZE);
         if(command == NULL)
         if(command == NULL)
         {
         {
Line 590... Line 598...
         IPPrintf(socket, "-> ");
         IPPrintf(socket, "-> ");
         continue;
         continue;
      }
      }
 
 
      //Check for file in or out
      //Check for file in or out
      for(k = 1; k < 10; ++k)
      for(k = 1; k < 9; ++k)
      {
      {
         if(argv[k][0] == '>') //stdout to file?
         if(argv[k][0] == '>') //stdout to file?
         {
         {
            if(argv[k][1])
            if(argv[k][1])
               socket->fileOut = fopen(&argv[k][1], "a");
               socket->fileOut = fopen(&argv[k][1], "a");
Line 860... Line 868...
      OS_CriticalBegin();
      OS_CriticalBegin();
      rfUnion.rebootFunc((int*)RAM_EXTERNAL_BASE, (int*)ptr, length>>2);
      rfUnion.rebootFunc((int*)RAM_EXTERNAL_BASE, (int*)ptr, length>>2);
   }
   }
   funcPtr = NULL;
   funcPtr = NULL;
   OS_CriticalBegin();
   OS_CriticalBegin();
   funcPtr(NULL);
   funcPtr(NULL);        //jump to address 0
}
}
 
 
 
 
static void ConsoleCat(IPSocket *socket, char *argv[])
static void ConsoleCat(IPSocket *socket, char *argv[])
{
{
Line 984... Line 992...
   for(bytes = 1024*128; bytes < 1024*1024*16; bytes += 1024*128)
   for(bytes = 1024*128; bytes < 1024*1024*16; bytes += 1024*128)
   {
   {
      UartPrintfCritical(".");
      UartPrintfCritical(".");
      FlashErase(bytes);
      FlashErase(bytes);
   }
   }
   funcPtr(NULL);
   funcPtr(NULL);      //jump to address 0
}
}
#endif
#endif
 
 
 
 
static void ConsoleMath(IPSocket *socket, char *argv[])
static void ConsoleMath(IPSocket *socket, char *argv[])
Line 1038... Line 1046...
 
 
   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);
   socketPing = IPOpen(IP_MODE_PING, ip, 0, PingCallback);
   socketPing = IPOpen(IP_MODE_PING, ip, 0, PingCallback);
 
   if(socketPing == NULL)
 
      return;
   socketPing->userPtr = socketTelnet;
   socketPing->userPtr = socketTelnet;
   buf[0] = 'A';
   buf[0] = 'A';
   IPWrite(socketPing, (uint8*)buf, 1);
   IPWrite(socketPing, (uint8*)buf, 1);
}
}
 
 
Line 1126... Line 1136...
static void ConsoleMkfile(IPSocket *socket, char *argv[])
static void ConsoleMkfile(IPSocket *socket, char *argv[])
{
{
   OS_FILE *file;
   OS_FILE *file;
   (void)argv;
   (void)argv;
   file = fopen("myfile.txt", "w");
   file = fopen("myfile.txt", "w");
 
   if(file == NULL)
 
      return;
   fwrite("Hello World!", 1, 12, file);
   fwrite("Hello World!", 1, 12, file);
   fclose(file);
   fclose(file);
   IPPrintf(socket, "Created myfile.txt");
   IPPrintf(socket, "Created myfile.txt");
}
}
 
 
Line 1231... Line 1243...
}
}
 
 
 
 
#ifndef EXCLUDE_DLL
#ifndef EXCLUDE_DLL
#ifndef WIN32
#ifndef WIN32
 
#undef DLL_SETUP
#define DLL_SETUP
#define DLL_SETUP
#include "dll.h"
#include "dll.h"
#else
#else
typedef void *(*DllFunc)();
typedef void *(*DllFunc)();
DllFunc DllFuncList[1];
DllFunc DllFuncList[1];
Line 1309... Line 1322...
void ConsoleRun(IPSocket *socket, char *argv[])
void ConsoleRun(IPSocket *socket, char *argv[])
{
{
   FILE *file;
   FILE *file;
   int bytes, i, run=0;
   int bytes, i, run=0;
   uint8 code[256];
   uint8 code[256];
 
   char *argv2[12];
   DllFunc funcPtr;
   DllFunc funcPtr;
 
 
   if(strcmp(argv[0], "run") == 0)
   if(strcmp(argv[0], "run") == 0)
   {
   {
      run = 1;
      run = 1;
Line 1329... Line 1343...
   bytes = fread(code, 1, sizeof(code), file);  //load first bytes
   bytes = fread(code, 1, sizeof(code), file);  //load first bytes
   if(strncmp((char*)code + 1, "ELF", 3) == 0)
   if(strncmp((char*)code + 1, "ELF", 3) == 0)
   {
   {
      funcPtr = (DllFunc)ConsoleLoadElf(file, code);
      funcPtr = (DllFunc)ConsoleLoadElf(file, code);
      fclose(file);
      fclose(file);
      argv[-1] = (char*)DllFuncList;  //DllF = argv[-1]
      argv2[0] = (char*)DllFuncList;  //DllF = argv[-1]
      argv[-2] = (char*)socket;
      argv2[1] = (char*)socket;
      for(i = 0; i < 10; ++i)
      for(i = 0; i < 10; ++i)
      {
      {
 
         argv2[i + 2] = argv[i];
         if(argv[i] == 0)
         if(argv[i] == 0)
            break;
            break;
      }
      }
#ifndef WIN32
#ifndef WIN32
      funcPtr(i, argv);
      funcPtr(i, argv2 + 2);
#endif
#endif
      return;
      return;
   }
   }
   if(run == 0)
   if(run == 0)
   {
   {

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.