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();
   }
}
Exemple #2
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;
}
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();
}
static int32_t Shell_ipconfig_dns (uint32_t enet_device, uint32_t index, int32_t argc, char *argv[])
{
    uint32_t        i;
    bool            res;
#if RTCSCFG_ENABLE_IP4
    _ip_address     dns_addr;
#endif
#if RTCSCFG_ENABLE_IP6
    in6_addr        dns6_addr;
#endif

    if (argc > ++index)
    {
        if (strcmp (argv[index], "add") == 0)
        {
            if (argc > ++index)
            {
#if RTCSCFG_ENABLE_IP4
                if(inet_pton(AF_INET, argv[index], &dns_addr, sizeof(dns_addr)) == RTCS_OK)
                {
                    res = ipcfg_add_dns_ip(enet_device, dns_addr);
                }
                else
#endif
#if RTCSCFG_ENABLE_IP6
                    if(inet_pton(AF_INET6, argv[index], &dns6_addr, sizeof(dns6_addr)) == RTCS_OK)
                    {
                        res = ipcfg6_add_dns_ip(enet_device, &dns6_addr);
                    }
                    else
#endif
                    {
                        printf ("Error in dns command, invalid ip address!\n");
                        return SHELL_EXIT_ERROR;
                    }

                if(res == TRUE)
                {
                    printf ("Add dns ip successful.\n");
                }
                else
                {
                    printf ("Add dns ip failed!\n");
                    return SHELL_EXIT_ERROR;
                }
            }
            else
            {
                printf ("Error in dns command, missing ip parameter!\n");
                return SHELL_EXIT_ERROR;
            }
        }
        else if (strcmp (argv[index], "del") == 0)
        {
            if (argc > ++index)
            {
#if RTCSCFG_ENABLE_IP4
                if(inet_pton(AF_INET, argv[index], &dns_addr, sizeof(dns_addr)) == RTCS_OK)
                {
                    res = ipcfg_del_dns_ip(enet_device, dns_addr);
                }
                else
#endif
#if RTCSCFG_ENABLE_IP6
                    if(inet_pton(AF_INET6, argv[index], &dns6_addr, sizeof(dns6_addr)) == RTCS_OK)
                    {
                        res = ipcfg6_del_dns_ip(enet_device, &dns6_addr);
                    }
                    else
#endif
                    {
                        printf ("Error in dns command, invalid ip address!\n");
                        return SHELL_EXIT_ERROR;
                    }

                if(res == TRUE)
                {
                    printf ("Del dns ip successful.\n");
                }
                else
                {
                    printf ("Del dns ip failed!\n");
                    return SHELL_EXIT_ERROR;
                }
            }
            else
            {
                printf ("Error in dns command, missing ip parameter!\n");
                return SHELL_EXIT_ERROR;
            }
        }
        else
        {
            printf ("Error in dns command, unknown parameter!\n");
            return SHELL_EXIT_ERROR;
        }

    }
    else
    {
        char        addr_str[RTCS_IP_ADDR_STR_SIZE];
        int         i;
        sockaddr    dns_server;

        /* Print server address list.*/
        for(i=0;; i++)
        {
            if(DNSCLN_get_dns_addr(ipcfg_get_ihandle(enet_device), i, &dns_server) == TRUE)
            {
                printf ("[%d] %s\n", i + 1, inet_ntop(dns_server.sa_family, &RTCS_SOCKADDR_ADDR(&dns_server), addr_str, sizeof(addr_str)));
            }
            else
            {
                break;
            }
        }
    }

    return SHELL_EXIT_SUCCESS;
}
Exemple #5
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 */
}