Ejemplo n.º 1
0
BOOL LWIP_SOCKETS_Driver::Initialize()
{   
    NATIVE_PROFILE_PAL_NETWORK();
    struct netif *pNetIf;

    int i;

    /* Initialize the raw lwIP stack and the tcp_tmr completion */
    lwip_init();
    
#if defined(NETWORK_USE_LOOPBACK)

    /* Bind and Open the loopback driver */
    g_LOOPBACK_LWIP_Driver.Bind();
    g_LOOPBACK_LWIP_Driver.Open();
#endif 

    for(i=0; i<g_NetworkConfig.NetworkInterfaceCount; i++)
    {
        int interfaceNumber;

        SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[i];

        /* Bind and Open the Ethernet driver */
        Network_Interface_Bind( i );
        interfaceNumber = Network_Interface_Open( i );

        if (interfaceNumber == SOCK_SOCKET_ERROR)
        {
            DEBUG_HANDLE_SOCKET_ERROR("Network init", FALSE);
            debug_printf("SocketError: %d\n", errno);
            continue;
        }
        
        g_LWIP_SOCKETS_Driver.m_interfaces[i].m_interfaceNumber = interfaceNumber;

        UpdateAdapterConfiguration(i, SOCK_NETWORKCONFIGURATION_UPDATE_DHCP | SOCK_NETWORKCONFIGURATION_UPDATE_DNS, pNetCfg);
        
        // default debugger interface
        if(0 == i)
        {
            pNetIf = netif_find_interface(interfaceNumber);

            if (pNetIf)
            {
                UINT8* addr = (UINT8*)&pNetIf->ip_addr.addr;
                lcd_printf( "\f\n\n\n\n\n\n\nip address: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3] );
                debug_printf( "ip address from interface info: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3] );
            }
        }
        
    }

    return TRUE;
}
Ejemplo n.º 2
0
void LWIP_SOCKETS_Driver::TcpipInitDone(void* arg)
{
	struct netif *pNetIf;

	for (int i = 0; i<g_NetworkConfig.NetworkInterfaceCount; i++)
	{
		int interfaceNumber;

		SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[i];

		/* Bind and Open the Ethernet driver */
		Network_Interface_Bind(i);
		interfaceNumber = Network_Interface_Open(i);

		if (interfaceNumber == SOCK_SOCKET_ERROR)
		{
			DEBUG_HANDLE_SOCKET_ERROR("Network init", FALSE);
			debug_printf("SocketError: %d\n", errno);
			continue;
		}

		g_LWIP_SOCKETS_Driver.m_interfaces[i].m_interfaceNumber = interfaceNumber;

		UpdateAdapterConfiguration(i, SOCK_NETWORKCONFIGURATION_UPDATE_DHCP | SOCK_NETWORKCONFIGURATION_UPDATE_DNS, pNetCfg);

		pNetIf = netif_find_interface(interfaceNumber);

		if (pNetIf)
		{		
			netif_set_link_callback(pNetIf, Link_callback);
			if (netif_is_link_up(pNetIf))
				Link_callback(pNetIf);

			netif_set_status_callback(pNetIf, Status_callback);
			if (netif_is_up(pNetIf))
				Status_callback(pNetIf);

			// default debugger interface
            if (0 == i)
            {
                UINT8* addr = (UINT8*)&pNetIf->ip_addr.addr;
                lcd_printf("\f\n\n\n\n\n\n\nip address: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
                debug_printf("ip address from interface info: %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]);
            }
		}
	}
}
Ejemplo n.º 3
0
BOOL RTIP_SOCKETS_Driver::Initialize()
{
    NATIVE_PROFILE_PAL_NETWORK();
    IFACE_INFO info;

    memset(g_RTIP_SOCKETS_Driver.m_interfaces, 0, sizeof(g_RTIP_SOCKETS_Driver.m_interfaces));

    /* Initialize the network stack   */
    if (rtp_net_init() != 0)
    {
        DEBUG_HANDLE_SOCKET_ERROR("rtp_net_init", TRUE);
        return FALSE;
    }

#if defined(NETWORK_USE_LOOPBACK)
    // Bind and Open the loopback driver
    g_LOOPBACK_Driver.Bind();
    
    if (g_LOOPBACK_Driver.Open() == SOCK_SOCKET_ERROR)
    {
        DEBUG_HANDLE_SOCKET_ERROR("loopback init", FALSE);
    }
#endif        

    for(int i=0; i<g_NetworkConfig.NetworkInterfaceCount; i++)
    {
        int interfaceNumber;
        
        SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[i];

        Network_Interface_Bind(i);

        interfaceNumber = Network_Interface_Open(i);
        
        if (interfaceNumber == SOCK_SOCKET_ERROR)
        {
            DEBUG_HANDLE_SOCKET_ERROR("Network init", FALSE);
            debug_printf("SocketError: %d\n", xn_getlasterror());
            continue;
        }

        g_RTIP_SOCKETS_Driver.m_interfaces[i].m_interfaceNumber = interfaceNumber;

        
        UpdateAdapterConfiguration(i, SOCK_NETWORKCONFIGURATION_UPDATE_DHCP | SOCK_NETWORKCONFIGURATION_UPDATE_DNS, pNetCfg);

        // default debugger interface
        if(0 == i)
        {
            // add multicast addresses to the routing table
            UINT32 mcast1 = SOCK_htonl(SOCK_DISCOVERY_MULTICAST_IPADDR);
            UINT32 mcast2 = SOCK_htonl(SOCK_DISCOVERY_MULTICAST_IPADDR_SND);
            UINT32 mask   = SOCK_htonl(SOCK_MAKE_IP_ADDR(255,255,255,255));
            
            if(SOCK_SOCKET_ERROR == xn_rt_add((RTP_PFCUINT8)&mcast1, (RTP_PFUINT8)&mask, (RTP_PFUINT8)0, RT_USEIFACEMETRIC, interfaceNumber, RT_INF))
            {
                DEBUG_HANDLE_SOCKET_ERROR("Multicast xn_rt_add (recv)", FALSE);
            }
            if(SOCK_SOCKET_ERROR == xn_rt_add((RTP_PFCUINT8)&mcast2, (RTP_PFUINT8)&mask, (RTP_PFUINT8)0, RT_USEIFACEMETRIC, interfaceNumber, RT_INF))
            {
                DEBUG_HANDLE_SOCKET_ERROR("Multicast xn_rt_add (send)", FALSE);
            }

            /* JRT - TBD call xn_ip_set_option */
            default_mcast_iface = interfaceNumber;
            
            xn_interface_info(interfaceNumber, &info );

            debug_printf( "ip address from interface info: %d.%d.%d.%d\r\n", (UINT32)info.my_ip_address[0], 
                                                                             (UINT32)info.my_ip_address[1],                                                                 
                                                                             (UINT32)info.my_ip_address[2], 
                                                                             (UINT32)info.my_ip_address[3] );
            
            debug_printf( "mac addrress from interface info: %x.%x.%x.%x.%x.%x\r\n", (UINT32)info.my_ethernet_address[0], 
                                                                                     (UINT32)info.my_ethernet_address[1],                                                                 
                                                                                     (UINT32)info.my_ethernet_address[2], 
                                                                                     (UINT32)info.my_ethernet_address[3],                                                            
                                                                                     (UINT32)info.my_ethernet_address[4], 
                                                                                     (UINT32)info.my_ethernet_address[5] );
        }
    }
    
    return TRUE;
}