⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpip.c

📁 ST for linux SDK采用的tcp/ip协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
/*                                                                            */
/* File name   : TCPIP.C                                                      */
/*                                                                            */
/* Description : TCPIP Debug                                                  */
/*                                                                            */
/* COPYRIGHT (C) ST-Microelectronics 2005                                     */
/*                                                                            */
/* Date               Modification                 Name                       */
/* ----               ------------                 ----                       */
/* 02/03/05           Created                      M.CHAPPELLIER              */
/*                                                                            */
/******************************************************************************/

/* Includes */
/* -------- */
#include "stapp_main.h"
#include "stdebug_main.h"                 

/* Private Functions prototypes */
/* ---------------------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
BOOL TT_TCPIP_Info    (parse_t *pars_p,char *result);
#if defined(OSPLUS)
BOOL TT_TCPIP_Status  (parse_t *pars_p,char *result);
BOOL TT_TCPIP_Config  (parse_t *pars_p,char *result);
#endif
BOOL TT_TCPIP_Ping    (parse_t *pars_p,char *result);
BOOL TT_TCPIP_Stream  (parse_t *pars_p,char *result);
BOOL TT_TCPIP_Bench   (parse_t *pars_p,char *result);
#if defined(TCPIP_STACK_NEXGEN)
BOOL TT_TCPIP_FtpStart(parse_t *pars_p,char *result);
BOOL TT_TCPIP_FtpStop (parse_t *pars_p,char *result);
#endif
#endif

/* Local variables */
/* --------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
typedef struct TT_TCPIPi_Streams_s
{
 U32             NetId;                     /* Ethernet interface id    */
 U32             Handle;                    /* Handle of the stream     */
 ST_DeviceName_t Name;                      /* Name of the stream       */
 U8              Params[TCPIP_MAX_STRING];  /* Parameters of the stream */
 U8              Mode;                      /* Mode 'r' or 'w'          */
} TT_TCPIPi_Stream_t;
static TT_TCPIPi_Stream_t TT_TCPIPi_Stream[TCPIP_MAX_STREAMS];
#endif

/* Local prototypes */
/* ---------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
#if defined(TCPIP_STACK_NEXGEN)
static int TT_TCPIPi_PingCallback(int seq,int err,int datasize,int ttl,int timen,NGsockaddr *saddr,void *data);
#endif
#endif

/* ========================================================================
   Name:        TCPIP_Debug
   Description: Register the debug commands for TCPIP class
   ======================================================================== */

ST_ErrorCode_t TCPIP_Debug(void)
{
 /* Reset variables */
 /* --------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
 memset(TT_TCPIPi_Stream,0,sizeof(TT_TCPIPi_Stream));
#endif

 /* Register commands */
 /* ----------------- */
#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
 register_command("IP_INFO"      , TT_TCPIP_Info     , "Gives driver information");
#if defined(OSPLUS)
 register_command("IP_STATUS"    , TT_TCPIP_Status   , "<Id> <0|1=Reset statistics> Gives tcpip statistics");
 register_command("IP_CONFIG"    , TT_TCPIP_Config   , "<Id> <Address> <Mask> <Gateway> Get/Set ip configuration");
#endif
 register_command("IP_PING"      , TT_TCPIP_Ping     , "<Id> <IP Address> Do a ping");
 register_command("IP_BENCH"     , TT_TCPIP_Bench    , "<Id> <ServerIP> <Port> <DataSize> <PacketSize> <Iterations> Do a ip bench");
 register_command("IP_STREAMS"   , TT_TCPIP_Stream   , "<Id> <Name> <Params> <Mode> Get/Set ip streams configurations");
#if defined(TCPIP_STACK_NEXGEN)
 register_command("IP_FTP_START" , TT_TCPIP_FtpStart , "<Id> Start FTP server");
 register_command("IP_FTP_STOP"  , TT_TCPIP_FtpStop  , "<Id> Stop FTP server");
#endif
#endif

 /* Return no errors */
 /* ---------------- */
 return(ST_NO_ERROR);
}

/* ========================================================================
   Name:        TT_TCPIP_Info
   Description: Return the driver version
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
BOOL TT_TCPIP_Info(parse_t *pars_p,char *result)
{
 /* Display TCP/IP stack version */
 /* ---------------------------- */
#if defined(OSPLUS)
 print("OS+ Modules version\n");
 print("-------------------\n");
 print("Module LAN91    = %s\n",osplus_version(OSPLUS_LAN91_MODULE)); 
 print("Module LAN9X1X  = %s\n",osplus_version(OSPLUS_LAN9X1X_MODULE)); 
#if defined(OSPLUS_STMAC110_MODULE)&&defined(ST_7109)
 print("Module STMAC110 = %s\n",osplus_version(OSPLUS_STMAC110_MODULE)); 
#endif
#if defined(OSPLUS_STGMAC_MODULE)&&(defined(ST_7105)||defined(ST_7111)||defined(ST_7141)||defined(ST_7200))
 print("Module STGMAC   = %s\n",osplus_version(OSPLUS_STGMAC_MODULE)); 
#endif
 print("Module NEXGEN   = %s\n",osplus_version(OSPLUS_NEXGEN_MODULE)); 
#endif

 /* Return no errors */
 /* ---------------- */
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_Ping
   Description: Perform a ping sequence
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
BOOL TT_TCPIP_Ping(parse_t *pars_p,char *result)
{
#if defined(TCPIP_STACK_NEXGEN)
 NGsockaddr myaddr;
 NGcfgping  cfgping;
#endif
 char       ipaddr[40];
 S32        ID;

 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Get the ip to ping */
 /* ------------------ */
 if (cget_string(pars_p,"192.168.0.1",ipaddr,sizeof(ipaddr))==TRUE)
  {
   tag_current_line(pars_p,"Invalid ip address, should be [\"192.168.0.100\"]");
   return(TRUE);
  }
  
 /* Configure the ping function */
 /* --------------------------- */
#if defined(TCPIP_STACK_NEXGEN)
 ngMemSet(&cfgping,0,sizeof(cfgping));
 cfgping.repeat       = 4;
 cfgping.data_len     = 0;
 cfgping.display      = TT_TCPIPi_PingCallback;
 ngInetATON((const char *)ipaddr,&myaddr.sin_addr);
#endif

 /* Do the ping */
 /* ----------- */
#if defined(TCPIP_STACK_NEXGEN)
 if (ngPing(&myaddr,&cfgping)<0)
  {
   print("--> Ping function has returned an error !\n");
   return(TRUE);
  }
#endif

 /* Return no errors */
 /* ---------------- */
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_Config
   Description: Configure the tcpip interface
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)&&defined(OSPLUS)
BOOL TT_TCPIP_Config(parse_t *pars_p,char *result)
{
#if defined(TCPIP_STACK_NEXGEN)
 NGifnet    *netptr;
 NGsockaddr  myaddr;
#endif
 char        string[40];
 S32         ID,i;

 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Get net context */
 /* --------------- */
#if defined(TCPIP_STACK_NEXGEN)
 sprintf(string,"eth%d",ID);
 netptr=ngIfGetPtr(string);
 if (netptr==NULL)
  {
   print("--> Invalid ethernet, ID=\"%s\" doesn't exist !\n",string);
   return(TRUE);
  }
#endif

 /* Set the ip ? */
 /* ------------ */
 if (cget_string(pars_p,"-",string,sizeof(string))==TRUE)
  {
   tag_current_line(pars_p,"Invalid ip address, should be [\"192.168.0.100\"]");
   return(TRUE);
  }
 /* If there is an ip address to set */
 if (strcmp(string,"-")!=0)
  {
#if defined(TCPIP_STACK_NEXGEN)
   NGuint ip_addr;
   if (ngInetATON(string,&ip_addr)!=NG_EOK)
    {
     print("--> Invalid ip address, should be [\"192.168.0.100\"] !\n");
     return(TRUE);
    }
   if (ngIfSetOption(netptr,NG_IFO_ADDR,&ip_addr)!=NG_EOK)
    {
     print("--> Unable to set the ip address\n");
     return(TRUE);
    }
#endif
  }

 /* Set netmask ? */
 /* ------------- */
 if (cget_string(pars_p,"-",string,sizeof(string))==TRUE)
  {
   tag_current_line(pars_p,"Invalid netmask, should be [\"255.255.255.0\"]");
   return(TRUE);
  }
 /* If there is a mask to set */
 if (strcmp(string,"-")!=0)
  {
#if defined(TCPIP_STACK_NEXGEN)
   NGuint ip_netmask;
   if (ngInetATON(string,&ip_netmask)!=NG_EOK)
    {
     print("--> Invalid netmask, should be [\"255.255.255.0\"] !\n");
     return(TRUE);
    }
   if (ngIfSetOption(netptr,NG_IFO_NETMASK,&ip_netmask)!=NG_EOK)
    {
     print("--> Unable to set the netmask\n");
     return(TRUE);
    }
#endif
  }

 /* Set gateway ? */
 /* ------------- */
 if (cget_string(pars_p,"-",string,sizeof(string))==TRUE)
  {
   tag_current_line(pars_p,"Invalid gateway address, should be [\"192.168.0.254\"]");
   return(TRUE);
  }
 /* If there is a gateway to set */
 if (strcmp(string,"-")!=0)
  {
#if defined(TCPIP_STACK_NEXGEN)
   NGuint ip_gateway;
   if (ngInetATON(string,&ip_gateway)!=NG_EOK)
    {
     print("--> Invalid gateway address, should be [\"192.168.0.254\"] !\n");
     return(TRUE);
    }
   if (ngRouteDefault(ip_gateway)!=NG_EOK)
    {
     print("--> Unable to set the gateway\n");
     return(TRUE);
    }
#endif
  }

 /* Get the IP address */
 /* ------------------ */
#if defined(TCPIP_STACK_NEXGEN)
 if (ngIfGetOption(netptr,NG_IFO_ADDR,(void*)&myaddr.sin_addr)!=NG_EOK) 
  {
   print("--> Unable to get the ip address\n");
   return(TRUE);
  }
 ngInetNTOA(myaddr.sin_addr,string,sizeof(string));
#endif
 print("Ip Address  : %s\n",string);

 /* Get the net mask */
 /* ---------------- */
#if defined(TCPIP_STACK_NEXGEN)
 if (ngIfGetOption(netptr,NG_IFO_NETMASK,(void*)&myaddr.sin_addr)!=NG_EOK) 
  {                               
   print("--> Unable to get the net mask\n");
   return(TRUE);
  }
 ngInetNTOA(myaddr.sin_addr,string,sizeof(string));
#endif
 print("Netmask     : %s\n",string);

 /* Get the gateway */
 /* --------------- */
#if defined(TCPIP_STACK_NEXGEN)
 if (ngInetNTOA(ngIp_route_default.rt_gateway,string,40)!=NG_EOK)
  {
   print("--> Unable to get the gateway\n");
   return(TRUE);
  }
#endif
 print("Gateway     : %s\n",string);

 /* Get the mac address */
 /* ------------------- */
 {
  char *mac=&string[0];
#if defined(TCPIP_STACK_NEXGEN)
  if (ngIfGetOption(netptr,NG_ETHIFO_ADDR,&mac)!=NG_EOK)
   {
    print("--> Unable to get the mac address\n");
    return(TRUE);
   }
#endif
  print("MAC Address : ");
  for (i=0;i<6;i++)
   {
    print("%02X%c",(unsigned char)string[i],(i==5)?' ':':');
   }
  print("\n");
 }

 /* Return no errors */
 /* ---------------- */
 return(FALSE);
}
#endif

/* ========================================================================
   Name:        TT_TCPIP_Stream
   Description: Perform a ping sequence
   ======================================================================== */

#if defined(TCPIP)&&defined(TCPIP_MAX_NUMBER)
BOOL TT_TCPIP_Stream(parse_t *pars_p,char *result)
{
 char           STR_Name[TCPIP_MAX_STRING];
 char           STR_Mode[TCPIP_MAX_STRING];
 char           STR_Params[TCPIP_MAX_STRING];
 ST_ErrorCode_t ErrCode=ST_NO_ERROR;
 S32            ID,i,j;
 U32            STR_Handle;

 /* Get Ethernet Identifier */
 /* ----------------------- */
 if (cget_integer(pars_p,0,&ID)==TRUE)
  {
   tag_current_line(pars_p,"Invalid ethernet ID, should be [0,1,..]");
   return(TRUE);
  }
 if (ID>=TCPIP_MAX_NUMBER)
  {
   print("--> Invalid ethernet ID, should be [0,1,..] !\n");
   return(TRUE);
  }

 /* Get the name of the stream */
 /* -------------------------- */
 if (cget_string(pars_p,"-",STR_Name,sizeof(STR_Name))==TRUE)
  {
   tag_current_line(pars_p,"Invalid stream name, should be [\"IP0\",\"IP1\",\"IP2\",\"IP3\"]");
   return(TRUE);
  }

 /* If this is none, display the list of streams */
 /* -------------------------------------------- */
 if (strcmp(STR_Name,"-")==0)
  {
   for (i=0;i<TCPIP_MAX_STREAMS;i++)
    {
     if (TT_TCPIPi_Stream[i].Name[0]!=0) break;
    }
   if (i==TCPIP_MAX_STREAMS)
    {
     print("--> Stream list is empty !\n");
     return(FALSE);
    }
   print("+-------+-------------+---------------------------------------------+------+\n");
   print("| NetId | Stream name | Stream parameters                           | Mode |\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -