Ejemplo n.º 1
0
static  boolean ROUTE_walk_test
   (
      _ip_address    node_ip,
      _ip_address    node_mask,
      pointer        node_data,
      pointer        data
   ) 
{ /* Body */
   IP_ROUTE_PTR                  route = node_data;
   IP_IF_PTR                     ip_if_ptr;

   if (route != NULL) {
      if (route->DIRECT) {
         printf("DIRECT Route: %d.%d.%d.%d, NetIF=%x,DestIF=%x\n", 
             IPBYTES(route->DIRECT->ADDRESS),route->DIRECT->NETIF->HANDLE, route->DIRECT->DESTIF->HANDLE );
      } else if (route->VIRTUAL) {
         printf("VIRTUAL Route: %d.%d.%d.%d, IS DIRECT=%x,DestIF=%x\n", 
             IPBYTES(route->VIRTUAL->ADDRESS), route->VIRTUAL->IS_DIRECT->HANDLE, route->VIRTUAL->DESTIF->HANDLE);
      } else if (route->INDIRECT) { 
         printf("INDIRECT Route: %d.%d.%d.%d", IPBYTES(route->INDIRECT->GATEWAY) );
         if (route->INDIRECT->IS_DIRECT) {
            ip_if_ptr = (IP_IF_PTR)route->INDIRECT->IS_DIRECT;
            printf(", IS DIRECT IF=%x\n", ip_if_ptr->HANDLE);
         } else {
            printf("\n");
         }
     } /* Endif */
   }

   return FALSE;
} /* Endbody */
Ejemplo n.º 2
0
int_32  FTPc_open(FTPc_CONTEXT_PTR context_ptr, int_32 argc, char_ptr argv[] )
{
   int_32    response=0;
   
   if (argc != 2)  {
      printf("Usage: open <host>\n");
   } else if (context_ptr->HANDLE != NULL) {
      printf("Already connected to %s. Use close first.\n",context_ptr->HOSTNAME);
   } else {
               
      RTCS_resolve_ip_address( argv[1], &context_ptr->HOSTADDR, context_ptr->HOSTNAME, RTCS_SNAME_LEN ); 

      if (!context_ptr->HOSTADDR)  {
         printf("Unable to resolve host.\n");
      } else  {
         printf("Connecting to: %s [%ld.%ld.%ld.%ld]\n",
               context_ptr->HOSTNAME, IPBYTES(context_ptr->HOSTADDR));
   
         response = FTP_open(&context_ptr->HANDLE,context_ptr->HOSTADDR,stdout);
         if (response == RTCS_ERROR)  {
            printf("Unable to open %s\n",context_ptr->HOSTNAME);
            response = 0;
            context_ptr->HOSTADDR = 0;
            context_ptr->HANDLE = NULL;   
         }
      }
   }
   
   return response;
}
Ejemplo n.º 3
0
int_32 Shell_getroute(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;

   _ip_address       gate_ipaddr;
   _ip_address       ipaddr;
   _ip_address       ipmask;
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  {
         if (! Shell_parse_ip_address( argv[1], &ipaddr  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (argc > 2)  {
            if (! Shell_parse_ip_address( argv[2], &ipmask  ))  {
               printf("Error, invalid ip mask\n");
               return_code = SHELL_EXIT_ERROR;
            }
         }          
      }          
         
         
      if (return_code == SHELL_EXIT_SUCCESS)  {
         gate_ipaddr = RTCS_get_route(ipaddr, ipmask);
         printf("The route to ip address: %d.%d.%d.%d, netmask: %d.%d.%d.%d is gateway %d.%d.%d.%d\n",
            IPBYTES(ipaddr),IPBYTES(ipmask),IPBYTES(gate_ipaddr));
      } 
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <ipaddr> <netmask>\n", argv[0]);
      } else  {
         printf("Usage: %s <ipaddr> <netmask>\n", argv[0]);
         printf("   <ipaddr>  = IP address \n");
         printf("   <netmask> = Network mask\n");
      }
   }

   return return_code;
} /* Endbody */
Ejemplo n.º 4
0
/*FUNCTION*------------------------------------------------
* 
* Function Name: PPP_start
* Comments     :
*    
*
*END*-----------------------------------------------------*/
void PPP_start(void)
{
    uint_32           error;

    _rtcs_if_handle   ihandle;
    MQX_FILE_PTR      pfile;
    _iopcb_handle     pio;
    _ppp_handle       phandle;
    IPCP_DATA_STRUCT  ipcp_data;

    _PPP_PAP_RSECRETS = rsecrets;    /* Require authentication, allow PAP */
    _PPP_PAP_LSECRET = &lsecret;     /* Allow peer to request PAP */
    _PPP_CHAP_LNAME = localname;     /* Needed by CHAP */
    _PPP_CHAP_RSECRETS = rsecrets;   /* Require authentication, allow CHAP */
    _PPP_CHAP_LSECRETS = lsecrets;   /* Allow peer to request CHAP */

    /* Install a route for a default gateway */
    RTCS_gate_add(GATE_ADDR, INADDR_ANY, INADDR_ANY);

    pfile = fopen(PPP_DEVICE, NULL);
#ifdef PPP_DEVICE_DUN
    _io_dun_install("dun:");
    pfile = fopen("dun:", (char_ptr)pfile);
#endif
 
    pio = _iopcb_ppphdlc_init(pfile);
    _PPP_ACCM = 0;
    error = PPP_initialize(pio, &phandle);
    if (error) {
       printf("\nPPP initialize: %lx", error);
       _task_block();
    } /* Endif */

    _iopcb_open(pio, PPP_lowerup, PPP_lowerdown, phandle);
    error = RTCS_if_add(phandle, RTCS_IF_PPP, &ihandle);
    if (error) {
       printf("\nIF add failed, error = %lx", error);
       _task_block();
    } /* Endif */
    _lwsem_create(&ppp_sem, 0);
    _mem_zero(&ipcp_data, sizeof(ipcp_data));
    ipcp_data.IP_UP              = PPP_linkup;
    ipcp_data.IP_DOWN            = NULL;
    ipcp_data.IP_PARAM           = &ppp_sem;
    ipcp_data.ACCEPT_LOCAL_ADDR  = FALSE;
    ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
    ipcp_data.LOCAL_ADDR         = PPP_LOCADDR;
    ipcp_data.REMOTE_ADDR        = PPP_PEERADDR;
    ipcp_data.DEFAULT_NETMASK    = TRUE;
    ipcp_data.DEFAULT_ROUTE      = TRUE;
    error = RTCS_if_bind_IPCP(ihandle, &ipcp_data);
    if (error) {
       printf("\nIF bind failed, error = %lx", error);
       _task_block();
    } /* Endif */
    printf("\nPlease initiate PPP connection.  Waiting...");
    _lwsem_wait(&ppp_sem);
    printf("\nPPP device %s bound to %d.%d.%d.%d", PPP_DEVICE, IPBYTES(ipcp_data.LOCAL_ADDR));
}
Ejemplo n.º 5
0
int_32  Shell_Telnet_client(int_32 argc, char_ptr argv[] )
{ /* Body */
   _ip_address    hostaddr;
   char           hostname[MAX_HOSTNAMESIZE];
   int_32         error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {

      if (argc == 2)  {
         RTCS_resolve_ip_address( argv[1], &hostaddr, hostname, MAX_HOSTNAMESIZE ); 

         if (hostaddr)  {
            printf("Connecting to %s [%ld.%ld.%ld.%ld]:\n", hostname, IPBYTES(hostaddr));

            error = TELNET_connect(hostaddr);
            if (error) {
               printf("Connection failed, error 0x%04lX\n", error);
               return_code = SHELL_EXIT_ERROR;
            } 
            printf("Connection closed\n", error);
         } else  {
            printf("Unable to resolve host\n");
            return_code = SHELL_EXIT_ERROR;
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <host>\n", argv[0]);
      } else  {
         printf("Usage: %s  <host>\n", argv[0]);
         printf("   <host>   = host ip address or name\n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 6
0
int_32  Shell_get_host_by_name(int_32 argc, char_ptr argv[] )
{ /* Body */
   _ip_address          hostaddr;
   char                 hostname[MAX_HOSTNAMESIZE];

   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 2)  {
         RTCS_resolve_ip_address( argv[1], &hostaddr, hostname, MAX_HOSTNAMESIZE ); 

         if (hostaddr)  {
            printf("%s...%ld.%ld.%ld.%ld\n", hostname, IPBYTES(hostaddr));
         } else  {
         
#if RTCSCFG_ENABLE_DNS | RTCSCFG_ENABLE_LWDNS
            printf("Unable to resolve host\n");
#else
            printf("Unable to resolve host - dns service disabled\n");
#endif            
            return_code = SHELL_EXIT_ERROR;
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      }
   }
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <host>\n", argv[0]);
      } else  {
         printf("Usage: %s <host>\n", argv[0]);
         printf("   <host>   = host ip address or name\n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 7
0
boolean init_network()
{
   IPCFG_IP_ADDRESS_DATA 	ip_data;
   _enet_address           	enet_address;   
   uint_32 error;
   
   _RTCS_socket_part_init = RTCS_NUMBER_OF_SOCKETS;
   _RTCS_socket_part_grow = 2;
   _RTCS_socket_part_max  = 20;
   error = RTCS_create();
   
   if (error != RTCS_OK) 
   {
      printf("init_network: RTCS failed to initialize, error = %X", error);
      _task_block();
   }

   _IP_forward = TRUE;
   
   ip_data.ip = ENET_IPADDR;
   ip_data.mask = ENET_IPMASK;
   // we dont need the gateway adress for the netgear-switch
   //ip_data.gateway = ENET_GATEWAY; 
   
   // calculate the mac-adress
   ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);
   
   // initialize the device
   error = ipcfg_init_device (ENET_DEVICE, enet_address);
   if (error != RTCS_OK) 
   {
      printf("\nFailed to initialize ethernet device, error = %X", error);
      _task_block();
   }

#if RTCSCFG_ENABLE_LWDNS
   LWDNS_server_ipaddr = ENET_GATEWAY;   
   ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);
#endif /* RTCSCFG_ENABLE_LWDNS */

 
   printf("Setting static IP address ... ");
   error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);
   

   if (error != IPCFG_ERROR_OK) 
   {
	   printf("\nRTCS failed to bind interface with IPv4, error = %X", error);
      _task_block();
   }
   else
	   printf("OK\n");

   ipcfg_get_ip(ENET_DEVICE, &ip_data);
   printf("IP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
   printf("Subnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
   printf("Gateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
   printf("DNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));
   printf("MAC Address     : %02x:%02x:%02x:%02x:%02x:%02x\n",
		   	   	   	   	   	   enet_address[0], enet_address[1], enet_address[2], 
		   	   	   	   	   	   enet_address[3], enet_address[4], enet_address[5]);


   return TRUE;
}
Ejemplo n.º 8
0
static int32_t Shell_ipconfig_status (uint32_t enet_device)
{
    IPCFG_STATE             state;
    bool                    link;
    bool                    task;
    _enet_address           mac = {0};
    IPCFG_IP_ADDRESS_DATA   ip_data ;
#if RTCSCFG_IPCFG_ENABLE_DNS
    _ip_address             dns;
#endif
#if RTCSCFG_IPCFG_ENABLE_BOOT
    _ip_address             tftp_serveraddress;
    unsigned char           *tftp_servername;
    unsigned char           *boot_filename;
#endif
#if RTCSCFG_ENABLE_IP6
    uint32_t                result;
    uint32_t                n;
    IPCFG6_GET_ADDR_DATA    data;
    char prn_addr6[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
#endif


    state = ipcfg_get_state (enet_device);
    if (state != IPCFG_STATE_INIT)
    {
        link = ipcfg_get_link_active (enet_device);
        task = ipcfg_task_status ();
        ipcfg_get_mac (enet_device, mac);
        ipcfg_get_ip (enet_device, &ip_data);

#if RTCSCFG_IPCFG_ENABLE_DNS
        dns = ipcfg_get_dns_ip (enet_device, 0);
#endif
#if RTCSCFG_IPCFG_ENABLE_BOOT
        tftp_serveraddress = ipcfg_get_tftp_serveraddress (enet_device);
        tftp_servername = ipcfg_get_tftp_servername (enet_device);
        boot_filename = ipcfg_get_boot_filename (enet_device);
#endif
        printf ("Eth#     : %d\n", enet_device);
        printf ("Link     : %s\n", link ? "on" : "off");
        printf ("MAC      : %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

#if RTCSCFG_ENABLE_IP4

        printf ("IP4      : %d.%d.%d.%d Type: %s\n", IPBYTES(ip_data.ip), ipcfg_get_state_string (state) );
        printf ("IP4 Mask : %d.%d.%d.%d\n", IPBYTES(ip_data.mask));
#if RTCSCFG_ENABLE_GATEWAYS
        printf ("IP4 Gate : %d.%d.%d.%d\n", IPBYTES(ip_data.gateway));
#endif
#if RTCSCFG_IPCFG_ENABLE_DNS
        printf ("IP4 DNS  : %d.%d.%d.%d\n", IPBYTES(dns));
#endif

#endif /* RTCSCFG_ENABLE_IP4 */

        /************************************************/
#if RTCSCFG_ENABLE_IP6
        n = 0;
        while(!ipcfg6_get_addr(enet_device, n, &data))
        {
            if(inet_ntop(AF_INET6,&data.ip_addr, prn_addr6, sizeof(prn_addr6)))
            {
                printf("IP6      : %s ",prn_addr6);
                /* IPv6 address state */
                printf("State: ");
                switch(data.ip_addr_state)
                {
                case IP6_ADDR_STATE_PREFERRED:
                    printf("PREFERRED ");
                    break;
                case IP6_ADDR_STATE_TENTATIVE:
                    printf("TENTATIVE ");
                    break;
                case IP6_ADDR_STATE_NOT_USED:
                    printf("NOT_USED ");
                    break;
                default:
                    printf("%d ", data.ip_addr_state);
                    break;
                }

                /* IPv6 address type */
                printf("Type: ");
                switch(data.ip_addr_type)
                {
                case IP6_ADDR_TYPE_MANUAL:
                    printf("MANUAL\n");
                    break;
                case IP6_ADDR_TYPE_AUTOCONFIGURABLE:
                    printf("AUTOCONFIGURABLE\n");
                    break;
                default:
                    printf("%d\n", data.ip_addr_type);
                    break;
                }
            }
            else
            {
                printf("IP6 : ERROR IP CONVERT\n");
            }
            n++;
        }
        /* Print Scope ID.*/
        printf("ScopeID  : %d\n", ipcfg6_get_scope_id(enet_device));
#endif /* RTCSCFG_ENABLE_IP6 */

#if RTCSCFG_ENABLE_IP4

#if RTCSCFG_IPCFG_ENABLE_BOOT
        printf ("TFTP: %d.%d.%d.%d '%s'\n", IPBYTES(tftp_serveraddress), tftp_servername);
        printf ("BOOT: '%s'\n", boot_filename);
#endif

#endif /* RTCSCFG_ENABLE_IP4 */
        printf ("Link status task %s\n", task ? "running" : "stopped");
    }
    else
    {
        printf ("Ethernet device %d not yet initialized.\n", enet_device);
    }
    return SHELL_EXIT_SUCCESS;
}
Ejemplo n.º 9
0
int_32  Shell_bootloader_tftp_client(int_32 argc, char_ptr argv[] )
{
   _ip_address          hostaddr;
   char                 hostname[MAX_HOSTNAMESIZE];
   char_ptr             file_ptr;
   uint_32              tftp_handle, buffer_size,byte_number=0,bytes=0;
   uchar_ptr            buffer_ptr;
   TFTP_DATA_STRUCT     tftp_data;
   MQX_FILE_PTR         fd;
   int_32               error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;   
   int_32               i=0,address;
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
   
      if ((argc >= 3) && (argc <= 5))  {
         RTCS_resolve_ip_address( argv[1], &hostaddr, hostname, MAX_HOSTNAMESIZE ); 

         if (!hostaddr)  {
            printf("Unable to resolve host.\n");
            return_code = SHELL_EXIT_ERROR;
         } else  {
            tftp_data.SERVER   = hostaddr;
            tftp_data.FILENAME = argv[2];
            tftp_data.FILEMODE = argv[2];
            if (argc > 3)  {
               file_ptr = argv[3];
               if (argc > 4) {
                  tftp_data.FILEMODE = argv[4];
               } else {
              tftp_data.FILEMODE = argv[2];
               }
            } else {
               file_ptr = argv[2];
            }
              address = StrtoHex(argv[3]);      
             _image_data[0] = 0x00;
               printf("\nDownloading file %s from TFTP server: %s [%ld.%ld.%ld.%ld]\n",
               tftp_data.FILENAME,hostname, IPBYTES(hostaddr));
               tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data );
               if ( tftp_handle != RTCS_OK )  {
                  printf("\nError opening file %s\n",tftp_data.FILENAME);
                  return_code = SHELL_EXIT_ERROR;
               } else  {
                  while (! (*FT_TFTP->EOFT)())  {
                
                    while(1) {
                      buffer_ptr = (*FT_TFTP->READ)( &buffer_size );
                     if (buffer_ptr != NULL)  {
                       for(i=0;i<(buffer_size);i++)
                       {
                        _image_data[i+byte_number]=buffer_ptr[i];
                        
                       }
                        byte_number += buffer_size;
                        if(byte_number&0x1000)
                        printf("#");
                     
                     } else {
                     
                     switch (buffer_size) {
                         case (RTCSERR_TFTP_ERROR + 1):
                            printf("\nFile %s not found\n", tftp_data.FILENAME);
                            break;
                         case (RTCSERR_TFTP_ERROR + 2):
                            printf("\nAccess violation\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 3):
                            printf("\nDisk full or allocation exceeded\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 4):
                            printf("\nIllegal TFTP operation\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 5):
                            printf("\nUnknown transfer ID\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 6):
                            printf("\nFile already exists\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 7):
                            printf("\nNo such user\n");
                            break;
                         default:
                            if(byte_number !=0) 
                               {
                                 printf("\nTransfer 0x%x byte success",byte_number);  
                                 if(MQX_OK == _bootloader_store_image(address, byte_number, _image_data,(uchar_ptr)tftp_data.FILEMODE)) {
                                    printf("\nWrite image to table Success\n");
                                    _bootloader_list_image();
                                 }
                                 else {
                                    printf("\nWrite image to table Fail\n");
                                 }
                                 break; 
                               }
                            else 
                            printf("\nError reading file %s\n", tftp_data.FILENAME);
                         } /* Endswitch */
                     break; 
                     }  
                          
                  }
                    
                  }
                
                error = (*FT_TFTP->CLOSE)();
              
               }
            tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data );
            if ( tftp_handle != RTCS_OK )  {
               printf("\nError opening file %s\n",tftp_data.FILENAME);
               return_code = SHELL_EXIT_ERROR;
            } 
            error = (*FT_TFTP->CLOSE)();
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <host> <source> <add> [<name>]\n", argv[0]);
      } else  {
         printf("Usage: %s <host> <source> <add> [<name>]\n", argv[0]);
         printf("   <host>    = TFTP server address or name\n");
         printf("   <source>  = Source file name\n");
         printf("   <add>     = Start address (Rom address in Linker file) \n");
         printf("   [<name>]  = Name of image will be stored in table \n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 10
0
/*TASK*-----------------------------------------------------------------
*
* Function Name  : main_task
* Returned Value : void
* Comments       :
*
*END------------------------------------------------------------------*/
void main_task(uint_32 temp) {
    int_32            error;

    HTTPD_STRUCT                        *server[BSP_ENET_DEVICE_COUNT];
    extern const HTTPD_CGI_LINK_STRUCT  cgi_lnk_tbl[];
    extern const TFS_DIR_ENTRY          tfs_data[];
    HTTPD_PARAMS_STRUCT                 *params[BSP_ENET_DEVICE_COUNT];
    _enet_address                       address[BSP_ENET_DEVICE_COUNT];
    uint_32                             phy_addr[BSP_ENET_DEVICE_COUNT];
    uint_32                             ip_addr[BSP_ENET_DEVICE_COUNT];    
    uint_32                             i = 0;
    char*                               indexes[BSP_ENET_DEVICE_COUNT];
    uint_8 								n_devices = BSP_ENET_DEVICE_COUNT;
#if  DEMOCFG_USE_WIFI   
    ENET_ESSID                          ssid;
    uint_32                             mode;// = DEMOCFG_NW_MODE;
    uint_32                             sectype;// = DEMOCFG_SECURITY;
    ENET_MEDIACTL_PARAM                 param;
#endif
#if RTCSCFG_ENABLE_IP6      
    IPCFG6_GET_ADDR_DATA    data[RTCSCFG_IP6_IF_ADDRESSES_MAX];
    char prn_addr6[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
    uint_32 n = 0;
    uint_32 j = 0;
#endif
    _int_install_unexpected_isr();
    /*---------------- Initialize devices and variables ----------------------*/
    _RTCSPCB_init = 4;
    _RTCSPCB_grow = 2;
    _RTCSPCB_max = 8;
    
    _RTCSTASK_stacksize = 4500;
    /*--------------------------- Init end -----------------------------------*/ 
    
    
    PORT_PCR_REG(PORTC_BASE_PTR, 3) = PORT_PCR_MUX(5);
   // SIM_SOPT2 |= 3<<5; // 1k LPO
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    error = RTCS_create();
    if (error != RTCS_OK) 
    {
        printf("RTCS failed to initialize, error = 0x%X\n", error);
        _task_block();
    }
    _IP_forward = TRUE;
    
    for (i = 0; (i < n_devices) && (n_devices != 0); i++)
    {
        IPCFG_IP_ADDRESS_DATA	ip_data; 
        phy_addr[i] = i;
        ip_addr[i] = IPADDR(A,B,C+i,D);
        ENET_get_mac_address (phy_addr[i], ip_addr[i], address[i]);
        /* Init ENET device */
        error = ipcfg_init_device (phy_addr[i], address[i]);
        if (error != RTCS_OK) 
        {
            printf("IPCFG: Device n.%d init failed. Error = 0x%X\n", i, error);
            _task_set_error(MQX_OK);
            n_devices--;
            i--;
            continue;
        }
#if RTCSCFG_ENABLE_IP4
        ip_data.ip      = ip_addr[i];
        ip_data.mask    = ENET_IPMASK;
        ip_data.gateway = 0;
        /* Bind IPv4 address */
        //error = ipcfg_bind_staticip (phy_addr[i], &ip_data);
        error = ipcfg_bind_autoip (phy_addr[i], &ip_data);
        if (error != RTCS_OK) 
        {
            printf("\nIPCFG: Failed to bind IP address. Error = 0x%X", error);
            _task_block();
        }
#endif /* RTCSCFG_ENABLE_IP4 */
       
        indexes[i] = (char*) _mem_alloc(sizeof("\\index_x.html"));
    }  
   
    error = _io_tfs_install("tfs:", tfs_data);
 
#if DEBUG__MESSAGES 
    printf("Preparing http servers...\n");
#endif
    for (i = 0; i < n_devices; i++)
    {
        params[i] = httpd_default_params(NULL);
        params[i]->af = HTTP_INET_AF;  //IPv4+IPv6, set connection family from config.h
#if RTCSCFG_ENABLE_IP6   
        params[i]->if_scope_id = HTTP_SCOPE_ID;    // set interface number here. 0 is any .
#endif
        if (params[i])
        {
            sprintf(indexes[i], "\\index.html", i);
            params[i]->root_dir = (HTTPD_ROOT_DIR_STRUCT*)root_dir;
            params[i]->index_page = indexes[i];
            printf("Starting http server No.%d on IP", i);
             /*
            ** If there is only one interface listen on any IP address 
            ** so address can change in runtime (DHCP etc.)
            */
            #if RTCSCFG_ENABLE_IP4
            if ((i == 0) && (n_devices == 1))
            {
                params[i]->address = INADDR_ANY;
            }
            else
            {
                params[i]->address = ip_addr[i];
            }
            /* Print active ip addresses */
            printf(" %d.%d.%d.%d", IPBYTES(ip_addr[i]));
            #endif
            #if RTCSCFG_ENABLE_IP6 
            while(!ipcfg6_get_addr_info_n(i, n, &data[n]))
            {
                n++;
            }
            while(j < n)
            {
                if(inet_ntop(AF_INET6, &data[j++].ip_addr, prn_addr6, sizeof(prn_addr6)))
                {
                    /* Print active ip addresses */
                    #if RTCSCFG_ENABLE_IP4
                    printf("%s %s", (HTTP_INET_AF & AF_INET) ? " and" : "", prn_addr6);
                    #else
                    printf(" %s", prn_addr6);
                    #endif
                }
            }
            #endif
#if PSP_MQX_CPU_IS_MCF5223X
            params[i]->max_ses = 1;
#else
            params[i]->max_ses = _RTCS_socket_part_max - 1;
#endif
            server[i] = httpd_init(params[i]);
        }
        HTTPD_SET_PARAM_CGI_TBL(server[i], (HTTPD_CGI_LINK_STRUCT*)cgi_lnk_tbl);
#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE
        printf("...");
        error = httpd_server_run(server[i]);
        if (error)
        {
            printf("[FAIL]\n");
        }
        else
        {
            printf("[OK]\n");
        }
#endif
    }

    /* user stuff come here */
#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE      
    _task_create(0, SHELL_TASK, 0);
    _task_block();
#else
    printf("Servers polling started.\n")
    while (1)
    {
        for (i = 0; i < n_devices; i++)
        {
            httpd_server_poll(server[i], 1);
        }
        /* user stuff come here - only non blocking calls */
    }
#endif
}
Ejemplo n.º 11
0
void SEC_InitializeNetworking(uint_32 pcbs, uint_32 msgs, uint_32 sockets, boolean dhcp) 
{
  int_32                 error;
  IPCFG_IP_ADDRESS_DATA  ip_data;
  _enet_address          enet_address;
    
#if PSP_MQX_CPU_IS_MCF51CN
   _enet_handle ehandle;
   _rtcs_if_handle ihandle;
#endif



    /* runtime RTCS configuration */
   _RTCSPCB_init = pcbs;
   _RTCS_msgpool_init = msgs;
   _RTCS_socket_part_init = sockets;
    
   error = RTCS_create();
   if (error == RTCS_OK) {

      ip_data.ip = ENET_IPADDR;
      ip_data.mask = ENET_IPMASK;
      ip_data.gateway = ENET_IPGATEWAY;
#if RTCSCFG_ENABLE_LWDNS
      LWDNS_server_ipaddr = ENET_IPDNS;
#endif 

      ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, enet_address);
#if PSP_MQX_CPU_IS_MCF51CN
      ENET_initialize_ex(&ENET_param, BSP_DEFAULT_ENET_DEVICE, &ehandle);
      
      if (RTCS_if_add(ehandle, RTCS_IF_ENET, &ihandle) == 0) {
         if (ipcfg_init_interface(-1, ihandle) != 0) {
            RTCS_if_remove(ihandle);
            ENET_shutdown(ehandle);
                _task_block();
         }
      }
      else {
         ENET_shutdown(ehandle);
      }
#else
      ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address);
#endif
      ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE,LWDNS_server_ipaddr);

      // check link status
      printf("\nWaiting for ethernet cable plug in ... ");
      while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {};
      printf("Cable connected\n");

       /* If DHCP Enabled, get IP address from DHCP server */
      if (dhcp) {
         printf("\nDHCP bind ... ");
         error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data);
            if (error != IPCFG_ERROR_OK) {
               printf("Error %08x!\n", error);
            }
            else {
               printf("Successful!\n");
            }
      } else {
         /* Else bind with static IP */
         printf ("\nStatic IP bind ... ");
         error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data);

         if (error != IPCFG_ERROR_OK) {
            printf("Error %08x!\n",error);
         }
         else {
            printf("Successful!\n");
         }
       }

       if (error == IPCFG_ERROR_OK) {
          ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data);
          printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
          printf("\nSubnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
          printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
          printf("\nDNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0)));
       }
   } else {
       printf("\nRTCS_Create failed !\n");
       _task_block();
   }
    SEC_GetTime();
}
Ejemplo n.º 12
0
int_32  Shell_exec(int_32 argc, char_ptr argv[] )
{ /* Body */
   _ip_address          hostaddr;
   char                 hostname[MAX_HOSTNAMESIZE];
   char_ptr             host_ptr , file_ptr, format_ptr;

   boolean              print_usage, shorthelp = FALSE;
   int_32               error = 0, return_code = SHELL_EXIT_SUCCESS;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 4 )  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         print_usage = TRUE;
         return_code = SHELL_EXIT_ERROR;
      } else  {
         format_ptr = "srec";
         if (argc > 1)  {
            file_ptr = argv[1];
            if (argc > 2)  {
               host_ptr = argv[2];
               if (argc>3)  {
                  format_ptr = argv[3];
               }
            } else  {
                  printf("Error, no TFTP Server specified.\n", argv[0]);
                  print_usage = TRUE;
                  return_code = SHELL_EXIT_ERROR;
            }
         } else  {
               printf("Error, no  bootfile specified.\n", argv[0]);
               print_usage = TRUE;
               return_code = SHELL_EXIT_ERROR;
         }
      }
      
      if (return_code != SHELL_EXIT_ERROR)  {
         RTCS_resolve_ip_address( host_ptr, &hostaddr, hostname, MAX_HOSTNAMESIZE ); 

         if (hostaddr)  {
            printf("Loading %s from %s [%ld.%ld.%ld.%ld]:\n", file_ptr, hostname, IPBYTES(hostaddr));
            if (strcmp(format_ptr, "srec") == 0)  {
               error = RTCS_exec_TFTP_SREC(hostaddr, file_ptr);
            } else if (strcmp(format_ptr, "coff") == 0)  {
               error = RTCS_exec_TFTP_COFF(hostaddr, file_ptr);
            } else {
               printf("Error, invalid format %s\n", format_ptr);
               print_usage = TRUE;
               return_code = SHELL_EXIT_ERROR;
            }
            if (error)  {
               printf("RTCS_exec_TFTP_%s returned with error code = %x\n",format_ptr, error);
               return_code = SHELL_EXIT_ERROR;
            }
         } else  {
            printf("Unable to resolve host\n");
            return_code = SHELL_EXIT_ERROR;
         }
      }         
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <file> <host> <format>\n", argv[0]);
      } else  {
         printf("Usage: %s <file> <host> <format>\n", argv[0]);
         printf("   <file>   = filename\n");
         printf("   <host>   = TFTP Server ip address or name\n");
         printf("   <format> = file format, one of coff or srec\n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 13
0
/*FUNCTION*------------------------------------------------
*
* Function Name: shell_ppp_start()
* Comments     :
*   This function start PPP communication and try to establish PPP connection.
*END*-----------------------------------------------------*/
void shell_ppp_start(SHELL_PPP_LINK_PTR ppp_current)
{
     uint_32           error;
     _ip_address       local_address;
     _ip_address       peer_address=0;
     IPCP_DATA_STRUCT  ipcp_data;

    /* This is configuration for PAP. */
     char* localname     = ppp_current->LOCAL_NAME;
     char* localsecret   = ppp_current->LOCAL_PASSWORD;
     PPP_SECRET lsecret;
    if(default_ppp.SERVER_FLAG==0)
    {   /* Setup  PAP for client mode.*/
         lsecret.PPP_ID_LENGTH = strlen(localname);
         lsecret.PPP_PW_LENGTH = strlen(localsecret);
         lsecret.PPP_ID_PTR    = localname;
         lsecret.PPP_PW_PTR    = localsecret;
        _PPP_PAP_LSECRET   = &lsecret; /* lsecrets  */
        _PPP_PAP_RSECRETS  =  NULL;    /* rsecrets  */
        _PPP_CHAP_LNAME    =  NULL;    /* localname */
        _PPP_CHAP_LSECRETS =  NULL;    /* lsecrets  */
        _PPP_CHAP_RSECRETS =  NULL;    /* rsecrets  */
    }
    else if(default_ppp.SERVER_FLAG==1)
    {   /* Setup  PAP for server mode.*/
        _PPP_PAP_LSECRET   =  NULL;                  /* lsecrets  */
        _PPP_PAP_RSECRETS  =  ppp_current->rsecrets; /* rsecrets  */
        _PPP_CHAP_LNAME    =  NULL;                  /* localname */
        _PPP_CHAP_LSECRETS =  NULL;                  /* lsecrets  */
        _PPP_CHAP_RSECRETS =  NULL;                  /* rsecrets  */
    }
    else
    {
         ppp_current->PPP_HANDLE = NULL;
         return;
    }

   /* Install a route for a default gateway */
    RTCS_gate_add(ppp_current->PPP_GATE_ADDR, INADDR_ANY, INADDR_ANY);

    ppp_current->PPP_IO_DRIVER_HANDLE = _iopcb_ppphdlc_init(ppp_current->PPP_DEV_HANDLE);
    _PPP_ACCM = 0;
    error = PPP_initialize(ppp_current->PPP_IO_DRIVER_HANDLE, &ppp_current->PPP_HANDLE);
    if (error)
    {
       printf("\n PPP initialize: %lx", error);
       _task_block();
    }
    _iopcb_open(ppp_current->PPP_IO_DRIVER_HANDLE, PPP_lowerup, PPP_lowerdown,ppp_current->PPP_HANDLE);
    error = RTCS_if_add(ppp_current->PPP_HANDLE, RTCS_IF_PPP, &ppp_current->PPP_IF_HANDLE);
    if (error)
    {
       printf("\n IF add failed, error = %lx", error);
       _task_block();
    }
    _lwsem_create(&ppp_current->PPP_SEM, 0);
    _mem_zero(&ipcp_data, sizeof(ipcp_data));
    ipcp_data.IP_UP              = PPP_linkup;
    ipcp_data.IP_DOWN            = PPP_linkdown;
    ipcp_data.IP_PARAM           = &ppp_current->PPP_SEM;

    if(default_ppp.SERVER_FLAG==0)
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = TRUE;
        ipcp_data.ACCEPT_REMOTE_ADDR = TRUE;
    }
    else
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = FALSE;
        ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
    }
    ipcp_data.LOCAL_ADDR         = ppp_current->PPP_LOCAL_ADDRESS;
    ipcp_data.REMOTE_ADDR        = ppp_current->PPP_REMOTE_ADDRESS;
    ipcp_data.DEFAULT_NETMASK    = TRUE;
    ipcp_data.DEFAULT_ROUTE      = TRUE;

    error = RTCS_if_bind_IPCP(ppp_current->PPP_IF_HANDLE, &ipcp_data);

    if (error)
    {
       printf("\n IF bind failed, error = %lx", error);
       _task_block();
    }

    /*In case "client" we need wait for connection to server*/
    if(default_ppp.SERVER_FLAG==0)
    {
        printf("\n Please wait initiate PPP connection.  Waiting...\n");
       /*Handshake with RAS server */
       /* 10 attempts to connect */
        error = 0;
        while (error < 10)
        {
            if (PPP_link == FALSE)
            {
                _time_delay(1000);
            }
            else
            {
                printf("\n PPP_link = %d, time = %d\n",PPP_link,error);
                break;
            }
            error ++;
        }

        if (PPP_link == TRUE)
        {
            local_address = IPCP_get_local_addr(ppp_current->PPP_IF_HANDLE);
            peer_address = IPCP_get_peer_addr(ppp_current->PPP_IF_HANDLE);
            printf("\n PPP device on %s is bound on.\n", ppp_current->PPP_CONNECTION_DEVICE );
            printf(" PPP local  address is : %d.%d.%d.%d\n", IPBYTES(local_address));
            printf(" PPP remote address is : %d.%d.%d.%d\n", IPBYTES(peer_address));
            printf(" Now PPP connection is established on %d.%d.%d.%d\n", IPBYTES(peer_address));
        }
        else
        {
            if(ppp_current->PPP_HANDLE)
            {
               /* clean up all PPP structure */
                error = PPP_shutdown(ppp_current->PPP_HANDLE);
            }
            ppp_current->PPP_HANDLE = NULL;
           /* We shoul remove route to clear part block. */
            RTCS_gate_remove(ppp_current->PPP_GATE_ADDR, INADDR_ANY, INADDR_ANY);
        }

    }
    else
    {
       /* In case of "server" we do not need wait at all. */
        printf("\n PPP server ready and waiting for connection.\n");
    }
}
Ejemplo n.º 14
0
int_32  Shell_dnat(int_32 argc, char_ptr argv[] )
{
   uint_32              error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   uint_32              priority=0;     
   uint_16              protocol=0;
   uint_16              start_port=0;   
   uint_16              end_port=0;     
   _ip_address          target_ip=0;      
   uint_16              target_port=0;  

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 7)  {
         if (!Shell_parse_uint_32(argv[1], &priority  )) {
            printf("Error, invalid rule priority\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[3], &start_port  )) {
            printf("Error, invalid start port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[4], &end_port  )) {
            printf("Error, invalid end port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (! Shell_parse_ip_address( argv[5], &target_ip  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[6], &target_port  )) {
            printf("Error, invalid target port\n");
            return_code = SHELL_EXIT_ERROR;
         } else {
            if (strcmp(argv[2],"TCP")==0) {
               protocol = IPPROTO_TCP;
            } else if (strcmp(argv[2],"UDP")==0) {
               protocol = IPPROTO_UDP;
            } else {
               printf("Error, invalid protocol\n");
               return_code = SHELL_EXIT_ERROR;
            }
         }
         if (return_code == SHELL_EXIT_SUCCESS) {
            printf("Adding rule:\n");
            printf("%d: %s (%d-%d) -> %03d.%03d.%03d.%03d:%d",
               priority, protocol==IPPROTO_TCP?"TCP":"UDP",start_port,end_port, 
               IPBYTES(target_ip), target_port);

            error = DNAT_add_rule(priority, protocol, start_port, end_port, target_ip, target_port );
            if (error != RTCS_OK) {
               printf("   Error: %s\n",NAT_err_str(error));
               return_code = SHELL_EXIT_ERROR;
            } else {
               printf("   OK\n");
            }
         }
      } else {
         print_usage = TRUE;
         return_code = SHELL_EXIT_ERROR;
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n", argv[0]);
      } else  {
         printf("Usage: %s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n",argv[0]);
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 15
0
int_32  Shell_natinfo(int_32 argc, char_ptr argv[] )
{
   boolean                 print_usage, shorthelp = FALSE;
   int_32                  i  , return_code = SHELL_EXIT_SUCCESS;
   uint_32                 natinfo = 0, num_nets;
   NAT_STATS_PTR           nat_stats_ptr = NULL;
   NAT_NETWORK_STRUCT_PTR  nat_network_ptr = NULL;
   boolean                 continuous = FALSE;
   uint_32                 priority;        
   uint_16                 start_port;  
   uint_16                 end_port;        
   _ip_address             target_ip;     
   uint_16                 target_port; 
   uint_16                 protocol;
   uint_32                 result;

   NAT_SESSION_STRUCT_PTR  session_ptr;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );
      
   if (!print_usage)  {

      if (argc==1) {
         natinfo = NATINFO_ALL;   
      } else {
         for (i=1;i<argc;i++) {
            if (strcmp(argv[i],"stats")==0) {
               natinfo |= NATINFO_STATS;
            } else if (strcmp(argv[i],"rules")==0) {
               natinfo |= NATINFO_RULES;
            } else if (strcmp(argv[i],"networks")==0) {
               natinfo |= NATINFO_NETWORKS;
            } else if (strcmp(argv[i],"all")==0) {
               natinfo |= NATINFO_ALL;
            } else if (strcmp(argv[i],"loop")==0) {
               continuous = TRUE;
            } else {
                print_usage = TRUE;
                return_code = SHELL_EXIT_ERROR;
            }
         }
      }   
      if (return_code == SHELL_EXIT_SUCCESS) {
         do {
            if (natinfo & NATINFO_STATS) {
               nat_stats_ptr= NAT_stats();
               if (nat_stats_ptr == NULL) {
                  printf("NAT statistics not available.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                  printf("NAT Statistics:\n");
                  printf("   ST_SESSIONS:                0x%08x\n", nat_stats_ptr->ST_SESSIONS );   
                  printf("   ST_SESSIONS_SNAT:           0x%08x\n", nat_stats_ptr->ST_SESSIONS_SNAT );   
                  printf("   ST_SESSIONS_DNAT:           0x%08x\n", nat_stats_ptr->ST_SESSIONS_DNAT );   
                  printf("   ST_SESSIONS_OPEN:           0x%08x\n", nat_stats_ptr->ST_SESSIONS_OPEN );  
                  printf("   ST_SESSIONS_OPEN_MAX:       0x%08x\n", nat_stats_ptr->ST_SESSIONS_OPEN_MAX ); 
                  printf("   ST_PACKETS_TOTAL:           0x%08x\n", nat_stats_ptr->ST_PACKETS_TOTAL ); 
                  printf("   ST_PACKETS_BYPASS:          0x%08x\n", nat_stats_ptr->ST_PACKETS_BYPASS ); 
                  printf("   ST_PACKETS_PUB_PRV:         0x%08x\n", nat_stats_ptr->ST_PACKETS_PUB_PRV ); 
                  printf("   ST_PACKETS_PUB_PRV_ERR:     0x%08x\n", nat_stats_ptr->ST_PACKETS_PUB_PRV_ERR ); 
                  printf("   ST_PACKETS_PRV_PUB:         0x%08x\n", nat_stats_ptr->ST_PACKETS_PRV_PUB );
                  printf("   ST_PACKETS_PRV_PUB_ERR:     0x%08x\n", nat_stats_ptr->ST_PACKETS_PRV_PUB_ERR );
                  printf("   ST_PACKETS_FRAGMENTS:       0x%08x\n", nat_stats_ptr->ST_PACKETS_FRAGMENTS );
                  printf("   ST_PACKETS_REASSEMBLED:     0x%08x\n", nat_stats_ptr->ST_PACKETS_REASSEMBLED );
                  printf("   ST_PACKETS_REASSSEMBLY_ERR: 0x%08x\n", nat_stats_ptr->ST_PACKETS_REASSSEMBLY_ERR );
              }
            }
            if (natinfo & NATINFO_RULES) {
               priority=0;
               result = DNAT_get_next_rule(&priority,&protocol,&start_port,&end_port,
                  &target_ip,&target_port);
               if (result==RTCS_OK) {
                  printf("NAT Rules:\n");
                  while (result==RTCS_OK) {
                     printf("%d: %s (%d-%d) -> %03d.%03d.%03d.%03d:%d\n",
                        priority, protocol==IPPROTO_TCP?"TCP":"UDP",start_port,end_port, 
                        IPBYTES(target_ip), target_port);
                     result = DNAT_get_next_rule(&priority,&protocol,&start_port,&end_port,
                        &target_ip,&target_port);
                  }
               } else {
                  printf("NAT Rule data not available.\n");
                  return_code = SHELL_EXIT_ERROR;
               }
            }
            if (natinfo & NATINFO_NETWORKS) {
               nat_network_ptr= NAT_networks();
               if (nat_network_ptr == NULL) {
                  printf("NAT Network data not available.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                  printf("NAT Networks:\n");
                  for (num_nets=0;num_nets<nat_network_ptr->NUM_PRV_NETS;num_nets++) {
                     printf("   %2d: %03d.%03d.%03d.%03d  %03d.%03d.%03d.%03d \n", 
                        num_nets,
                        IPBYTES(nat_network_ptr->PRV_NET[num_nets]),
                        IPBYTES(nat_network_ptr->PRV_MASK[num_nets]));
                  }
                  for (num_nets=nat_network_ptr->NUM_PRV_NETS;num_nets<NAT_MAX_PRIVATE_NETWORKS;num_nets++) {
                     if ((nat_network_ptr->PRV_NET[num_nets]!=0) || (nat_network_ptr->PRV_MASK[num_nets])) {
                        printf("   Invalid Entry:\n   %2d: %03d.%03d.%03d.%03d  %03d.%03d.%03d.%03d \n", 
                           num_nets,
                           IPBYTES(nat_network_ptr->PRV_NET[num_nets]),
                           IPBYTES(nat_network_ptr->PRV_MASK[num_nets]));
                     }
                  }
               }
            }
            if (natinfo & NATINFO_SESSIONS) {
               printf("NAT Inbound sessions:\n");
               session_ptr = (NAT_SESSION_STRUCT_PTR) NAT_find_next_session(NULL, 0);
               while (session_ptr!=NULL) {
                  printf("%s-%s: %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d  [%d]\n",
                     session_ptr->SNAT_OR_DNAT==SNAT?"SNAT":"DNAT",
                     IP_Prot_str(session_ptr->IP_PROT), 
                     IPBYTES(session_ptr->PUB_HST), session_ptr->PUB_PORT,
                     IPBYTES(session_ptr->NAT_HST), session_ptr->NAT_PORT,
                     IPBYTES(session_ptr->PRV_HST), session_ptr->PRV_PORT,
                     session_ptr->TIMEOUT.TIME);

                     session_ptr = (NAT_SESSION_STRUCT_PTR) NAT_find_next_session((pointer)session_ptr, 0);
               }
               printf("NAT Outbound sessions:\n");
               session_ptr = (NAT_SESSION_STRUCT_PTR) NAT_find_next_session(NULL, 1);
               while (session_ptr!=NULL) {
                  printf("%s-%s: %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d  [%d]\n",
                     session_ptr->SNAT_OR_DNAT==SNAT?"SNAT":"DNAT",
                     IP_Prot_str(session_ptr->IP_PROT), 
                     IPBYTES(session_ptr->PRV_HST), session_ptr->PRV_PORT,
                     IPBYTES(session_ptr->NAT_HST), session_ptr->NAT_PORT,
                     IPBYTES(session_ptr->PUB_HST), session_ptr->PUB_PORT,
                     session_ptr->TIMEOUT.TIME);
                     session_ptr = (NAT_SESSION_STRUCT_PTR) NAT_find_next_session((pointer)session_ptr, 1);
               }
            }
            if (continuous) {
               if (status()) {
                  continuous = FALSE;
               } else {
                  _time_delay(1000);
               }
            }
         } while (continuous);
      }        
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [stats|rules|networks|all|loop]\n", argv[0]);
      } else  {
         printf("Usage: %s [stats|rules|networks|all|loop]\n",argv[0]);
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 16
0
int_32  Shell_TFTP_client(int_32 argc, char_ptr argv[] )
{
   _ip_address          hostaddr;
   char                 hostname[MAX_HOSTNAMESIZE]="";
   char_ptr             file_ptr;
   uint_32              tftp_handle, buffer_size,byte_number;
   uchar_ptr            buffer_ptr;
   TFTP_DATA_STRUCT     tftp_data;
   MQX_FILE_PTR         fd;
   int_32               error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   char                 path[SHELL_MAX_FILELEN];  
   boolean              trans = FALSE;
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
   
      if ((argc >= 3) && (argc <= 5))  {
         RTCS_resolve_ip_address( argv[1], &hostaddr, hostname, MAX_HOSTNAMESIZE ); 

         if (!hostaddr)  {
            printf("Unable to resolve host.\n");
            return_code = SHELL_EXIT_ERROR;
         } else  {
            tftp_data.SERVER   = hostaddr;
            tftp_data.FILENAME = argv[2];
            tftp_data.FILEMODE = "netascii";
            if (argc > 3)  {
               file_ptr = argv[3];
               if (argc > 4) {
                  tftp_data.FILEMODE = argv[4];
               } else {
                  tftp_data.FILEMODE = "netascii";
               }
            } else {
               file_ptr = argv[2];
            }
#if SHELLCFG_USES_MFS  
            
            Shell_create_prefixed_filename(path, file_ptr, argv);
            fd = fopen(path,"a");
            if (fd)  {
               printf("\nDownloading file %s from TFTP server: %s [%ld.%ld.%ld.%ld]\n",
                  tftp_data.FILENAME,hostname, IPBYTES(hostaddr));
               tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data );
               if ( tftp_handle != RTCS_OK )  {
                  printf("\nError opening file %s\n",tftp_data.FILENAME);
                  return_code = SHELL_EXIT_ERROR;
               } else  {
                if (! (*FT_TFTP->EOFT)())  {
                   do {
                     buffer_ptr = (*FT_TFTP->READ)( &buffer_size );
                     if ((buffer_ptr != NULL) && (buffer_size))  {
                         fseek(fd, 0 , IO_SEEK_CUR);
                        _io_write(fd,buffer_ptr,buffer_size); 
                        trans = TRUE;
                     } else {
                   
                         switch (buffer_size) {
                         case 0:
                            // end of file
                           break;
                         case (RTCSERR_TFTP_ERROR + 1):
                            printf("\nFile %s not found\n", tftp_data.FILENAME);
                            break;
                         case (RTCSERR_TFTP_ERROR + 2):
                            printf("\nAccess violation\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 3):
                            printf("\nDisk full or allocation exceeded\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 4):
                            printf("\nIllegal TFTP operation\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 5):
                            printf("\nUnknown transfer ID\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 6):
                            printf("\nFile already exists\n");
                            break;
                         case (RTCSERR_TFTP_ERROR + 7):
                            printf("\nNo such user\n");
                            break;
                         default:
                            if(trans) 
                            {
                              trans =FALSE;
                              break;
                            }
                          else
                            printf("\nError reading file %s\n", tftp_data.FILENAME);
                         } /* Endswitch */
                        }
                     } while((buffer_ptr !=NULL) && buffer_size &&  (! (*FT_TFTP->EOFT)()) );
                     fclose(fd);
                  }
                  
                  error = (*FT_TFTP->CLOSE)();
                  
               }
               
            } else  {
               printf("\nError opening local file %s\n",file_ptr);
               return_code = SHELL_EXIT_ERROR;
            }
#else
            tftp_handle = (*FT_TFTP->OPEN)( (pointer) &tftp_data );
            if ( tftp_handle != RTCS_OK )  {
               printf("\nError opening file %s\n",tftp_data.FILENAME);
               return_code = SHELL_EXIT_ERROR;
            } else  {
               printf("SHELLCFG_USES_MFS is not set to 1 in user_config.h - file wont be written to disk\n");
            }
            error = (*FT_TFTP->CLOSE)();
#endif            
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <host> <source> [<dest>] [<mode>]\n", argv[0]);
      } else  {
         printf("Usage: %s <host> <source> [<dest>] [<mode>]\n", argv[0]);
         printf("   <host>   = host ip address or name\n");
         printf("   <source> = remote file name\n");
         printf("   <dest>   = local file name\n");
         printf("   <mode>   = file transfer mode (netascii, etc.)\n");
      }
   }
   return return_code;
} /* Endbody */
Ejemplo n.º 17
0
Archivo: Mail.c Proyecto: gxliu/MqxSrc
void SEC_EmailAlert()
{
   MQX_TICK_STRUCT      ticks;
   MQX_XDATE_STRUCT     xdate;
   sockaddr             addr;
   _ip_address          ipaddr;
   uint_32              sock;
   uint_32              error;
   uint_32              option;
   char_ptr             event_ptr;
   char                 temp[150];
   char                 domain[30];
   char                 user[30];
    
#if DEMOCFG_AUTH_REQUIRED    
   char                 temp_encoded[40];
#endif
    

  
   if (!RTCS_resolve_ip_address(EMAIL_SERVER,&ipaddr,NULL,0)) {
      printf("Error resolving IP address for %s using DNS Server at %d.%d.%d.%d\n", EMAIL_SERVER, IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE, 0)));
      return;
   }
  
    /* Create socket */        
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == RTCS_SOCKET_ERROR) 
    {
        printf("Error creating socket\n");
        return;
    } 

   /* Reduce buffer size of socket to save memory */
   option = SMTP_BUFFER_SIZE;   
   error = setsockopt(sock, SOL_TCP, OPT_TBSIZE, &option, sizeof(option));
   option = SMTP_BUFFER_SIZE;   
   error = setsockopt(sock, SOL_TCP, OPT_RBSIZE, &option, sizeof(option));
   option = 1000;   
   error = setsockopt(sock, SOL_TCP, OPT_TIMEWAIT_TIMEOUT, &option, sizeof(option));


    /* Allow binding to any address */
   
    #if RTCSCFG_ENABLE_IP4  
    ((sockaddr_in*)(&addr))->sin_family      = AF_INET;
    ((sockaddr_in*)(&addr))->sin_port        = 0;
    ((sockaddr_in*)(&addr))->sin_addr.s_addr = INADDR_ANY;
 
    #elif RTCSCFG_ENABLE_IP6
        printf("\nThis application don't support IPv6 only.\n");
        _task_block();
    #endif

    error = bind(sock, &addr, sizeof(addr));
    if (error != RTCS_OK) {
        printf("Error in binding socket %08x\n",error);
        shutdown(sock, FLAG_ABORT_CONNECTION);
        return;
    } 

    /* Connect to SMTP server */
    #if RTCSCFG_ENABLE_IP4
        ((sockaddr_in*)(&addr))->sin_port        = IPPORT_SMTP;
        ((sockaddr_in*)(&addr))->sin_addr.s_addr = ipaddr;
    #elif RTCSCFG_ENABLE_IP6
        printf("\nThis application does not support IPv6 only.\n");
        _task_block();
    #endif


    error = connect(sock, &addr, sizeof(addr));
    if (error != RTCS_OK) {
        printf("Error in connection %08x\n",error);
        shutdown(sock, FLAG_ABORT_CONNECTION);
        return;
    }
  
    printf("\nConnecting to SMTP server %s...\n",EMAIL_SERVER);
    printf("SMTP Server Response:\n");
    SMTP_Receive_string(sock, temp, sizeof(temp));


    /* Follow SMTP protocol to send email */   

    /* Parse domain name from the FROM address, 
     for use with the EHLO or HELO commands */
    sscanf(EMAIL_FROM,"%30s@%30s",user,domain);
  
#if DEMOCFG_AUTH_REQUIRED 
  
    /* If Authentification is required, use EHLO command */
    SMTP_Send_command(sock, "EHLO", domain, temp, sizeof(temp));
    SMTP_Send_command(sock,"AUTH LOGIN",NULL,temp,sizeof(temp));

    /* Find base64 econding of login name and send to SMTP server */
    sprintf(temp,"%s\r\n",base64_encode(AUTH_USERNAME,temp_encoded));
    SMTP_Send_string(sock,temp);
    SMTP_Receive_string(sock,temp,sizeof(temp)-1);

    /* Find base64 econding of password and send to SMTP server */
    sprintf(temp,"%s\r\n",base64_encode(AUTH_PASSWORD,temp_encoded));
    SMTP_Send_string(sock,temp);
    SMTP_Receive_string(sock,temp, sizeof(temp)-1);
#else
    /* If Authentification is not required, use HELO command as not all servers recognize EHLO */
    SMTP_Send_command(sock, "HELO", domain, temp, sizeof(temp));
#endif


   /* Transfer sender email address to server */     
   SMTP_Send_command(sock,"MAIL FROM:","<" EMAIL_FROM ">" ,temp,sizeof(temp));
   /* Transfer recipient email address to server */            
   SMTP_Send_command(sock,"RCPT TO:","<" EMAIL_TO ">" ,temp,sizeof(temp));

   /* Start DATA section */
   SMTP_Send_command(sock,"DATA",NULL,temp,sizeof(temp));

   printf("Sent:\n");
   /* Send Subject, To, and From fields */
   SMTP_Send_string(sock,(pointer)Email_header);


   /* Determine what to send as body of message */
   _time_get_ticks(&ticks);
   _time_ticks_to_xdate(&ticks,&xdate);    

   sprintf(temp, "Date: %s, %d %s %d %02d:%02d:%02d -0000\r\n\r\n",
      wday[xdate.WDAY],xdate.MDAY, months[xdate.MONTH-1],xdate.YEAR, xdate.HOUR, xdate.MIN, xdate.SEC  );
   SMTP_Send_string(sock,temp);


   /* If button pushed was the "Door"... */
   if(SEC_Params.Status==SEC_DOOR_OPEN_STATUS)
   {
      event_ptr = "Door was opened ";
   } else 
   /* If button pushed was the "Window"... */
   if(SEC_Params.Status==SEC_WINDOW_OPEN_STATUS)
   {
      event_ptr = "Window was opened ";
   }
   /* If not sure what caused stop mode to exit... */  
   else 
   {
      event_ptr = "Unknown event occurred ";
   }    
   SMTP_Send_string(sock,event_ptr);

   /* If SNTP enabled, then send exact date and time button press happened */
   #if DEMOCFG_ENABLE_SNTP
      sprintf(temp,"on %d/%d/%d at %02d:%02d:%02d GMT. \r\n",xdate.MONTH,xdate.MDAY,xdate.YEAR,xdate.HOUR,xdate.MIN,xdate.SEC);
   /* If SNTP not enabled, then give elapsed time instead */
   #else
      sprintf(temp,"%02d:%02d:%02d after system was started. \r\n",xdate.HOUR,xdate.MIN,xdate.SEC);
   #endif
   SMTP_Send_string(sock,temp);  

   if (last[0]) {
      /* Send out how long ago the last event was */
      SMTP_Send_string(sock,"Previous event was ");
      SMTP_Send_string(sock,last);
   }
   strcpy(last,temp); 
   
   /* Send Freescale signature and disconnect from server with QUIT command */
   SMTP_Send_string(sock,"\r\n-Freescale Semiconductor\r\n.\r\n");
   
   SMTP_Send_command(sock,"QUIT",NULL,temp,sizeof(temp));

  /* Close socket */
    shutdown(sock, FLAG_CLOSE_TX);  
}
Ejemplo n.º 18
0
void SEC_InitializeNetworking(uint_32 pcbs, uint_32 msgs, uint_32 sockets, boolean dhcp) 
{
  int_32                 error;
  IPCFG_IP_ADDRESS_DATA  ip_data;
  _enet_address          enet_address;

    /* runtime RTCS configuration */
   _RTCSPCB_init = pcbs;
   _RTCS_msgpool_init = msgs;
   _RTCS_socket_part_init = sockets;
    
   error = RTCS_create();
   if (error == RTCS_OK) {

      ip_data.ip = ENET_IPADDR;
      ip_data.mask = ENET_IPMASK;
      ip_data.gateway = ENET_IPGATEWAY;

      ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, enet_address);
      ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address);
      ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE,LWDNS_server_ipaddr);

      // check link status
      printf("\nWaiting for ethernet cable plug in ... ");
      while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {};
      printf("Cable connected\n");

       /* If DHCP Enabled, get IP address from DHCP server */
      if (dhcp) {
         printf("\nDHCP bind ... ");
         error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data);
            if (error != IPCFG_ERROR_OK) {
               printf("Error %08x!\n", error);
            }
            else {
               printf("Successful!\n");
            }
      } else {
         /* Else bind with static IP */
         printf ("\nStatic IP bind ... ");
         error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data);

         if (error != IPCFG_ERROR_OK) {
            printf("Error %08x!\n",error);
         }
         else {
            printf("Successful!\n");
         }
       }

       if (error == IPCFG_ERROR_OK) {
          ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data);
          printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
          printf("\nSubnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
          printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
          printf("\nDNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0)));
       }
   } else {
       printf("\nRTCS_Create failed !\n");
       _task_block();
   }
}
Ejemplo n.º 19
0
void rtcs_init()
{
   IPCFG_IP_ADDRESS_DATA ip_data;
   _enet_address           enet_address;   

   uint_32 error = RTCS_create();
   if (error != RTCS_OK) 
   {
      printf("\nRTCS failed to initialize, error = %X", error);
      _task_block();
   }

   _IP_forward = TRUE;

#ifdef BSP_ENET_DEVICE_COUNT
#if  (BSP_ENET_DEVICE_COUNT > 0) 
   /*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/
   
   ip_data.ip = ENET_IPADDR;
   ip_data.mask = ENET_IPMASK;
   ip_data.gateway = ENET_GATEWAY;  
   
   /* calcualte unique mac address from IP ADDRES */
   ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);
   error = ipcfg_init_device (ENET_DEVICE, enet_address);
   if (error != RTCS_OK) 
   {
      printf("\nFailed to initialize ethernet device, error = %X", error);
      _task_block();
   }

#if RTCSCFG_ENABLE_LWDNS
   LWDNS_server_ipaddr = ENET_GATEWAY;   
   ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);
#endif /* RTCSCFG_ENABLE_LWDNS */

   printf("\nWaiting for ethernet cable plug in ... ");
   while(!ipcfg_get_link_active(ENET_DEVICE)) {};
   printf("Cable connected\n");

#if RTCS_DHCP
   printf("Contacting DHCP server ... ");
   error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data);
#else
   printf("Setting static IP address ... ");
   error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);
#endif /* RTCS_DHCP */
   if (error != IPCFG_ERROR_OK) 
   {
      printf("\nRTCS failed to bind interface with IPv4, error = %X", error);
      _task_block();
   }
   else
   {
	  printf("OK\n");	   
   }

   ipcfg_get_ip(ENET_DEVICE, &ip_data);
   printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
   printf("\nSubnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
   printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
   printf("\nDNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));

#endif /* BSP_ENET_DEVICE_COUNT > 0 */
#endif /* BSP_ENET_DEVICE_COUNT */   
   
#if RTCS_PPP
    PPP_start();
#endif /* RTCS_PPP */

   /* TODO: start server(s) in separate tasks */
}