コード例 #1
0
ファイル: net_io.c プロジェクト: perryhg/terkos
void
net_init(void)
{
    cyg_netdevtab_entry_t *t;

    // Set defaults as appropriate
#ifdef CYGSEM_REDBOOT_DEFAULT_NO_BOOTP
    use_bootp = false;
#else
    use_bootp = true;
#endif
#ifdef CYGDBG_REDBOOT_NET_DEBUG
    net_debug = true;
#else
    net_debug = false;
#endif
    gdb_port = CYGNUM_REDBOOT_NETWORKING_TCP_PORT;
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
    // Fetch values from saved config data, if available
    flash_get_config("net_debug", &net_debug, CONFIG_BOOL);
    flash_get_config("gdb_port", &gdb_port, CONFIG_INT);
    flash_get_config("bootp", &use_bootp, CONFIG_BOOL);

    use_bootp = false;

    if (!use_bootp)
    {
        flash_get_IP("bootp_my_ip", &__local_ip_addr);
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
        flash_get_IP("bootp_my_ip_mask", &__local_ip_mask);
        flash_get_IP("bootp_my_gateway_ip", &__local_ip_gate);
#endif
        flash_get_config("bootp_server_ip", &my_bootp_info.bp_siaddr,
                         CONFIG_IP);
    }
#endif
# ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
    // Don't override if the user has deliberately set something more
    // verbose.
    if (0 == cyg_io_eth_net_debug)
        cyg_io_eth_net_debug = net_debug;
# endif
    have_net = false;
    // Make sure the recv buffers are set up
    eth_drv_buffers_init();
    __pktbuf_init();
    // Initialize all network devices
    for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
        if (t->init(t)) {
            t->status = CYG_NETDEVTAB_STATUS_AVAIL;
        } else {
            // What to do if device init fails?
            t->status = 0;  // Device not [currently] available
        }
    }
    if (!__local_enet_sc) {
        diag_printf("No network interfaces found\n");
        return;
    }    
    // Initialize the network [if present]
    if (use_bootp) {
        if (__bootp_find_local_ip(&my_bootp_info) == 0) {
            have_net = true;
        } else {
            // Is it an unset address, or has it been set to a static addr
            if (__local_ip_addr[0] == 0 && __local_ip_addr[1] == 0 &&
                __local_ip_addr[2] == 0 && __local_ip_addr[3] == 0) {
                diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
                            __local_enet_sc->dev_name,
                            __local_enet_addr[0],
                            __local_enet_addr[1],
                            __local_enet_addr[2],
                            __local_enet_addr[3],
                            __local_enet_addr[4],
                            __local_enet_addr[5]);
                diag_printf("Can't get BOOTP info for device!\n");
            } else {
                diag_printf("Can't get BOOTP info, using default IP address\n");
                have_net = true;
            }
        }
    } else {
        have_net = true;  // Assume values in FLASH were OK
    }
    if (have_net) {
        diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
                    __local_enet_sc->dev_name,
                    __local_enet_addr[0],
                    __local_enet_addr[1],
                    __local_enet_addr[2],
                    __local_enet_addr[3],
                    __local_enet_addr[4],
                    __local_enet_addr[5]);

#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
	redboot_dns_res_init();
#endif
        show_addrs();
        net_io_init();
    }
}
コード例 #2
0
ファイル: net_io.c プロジェクト: cilynx/dd-wrt
void
net_init(void)
{
    cyg_netdevtab_entry_t *t;
    unsigned index;
    struct eth_drv_sc *primary_net = (struct eth_drv_sc *)0;
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
    char *default_devname;
    int default_index;
#endif
#ifdef CYGDAT_REDBOOT_DEFAULT_BOOTP_SERVER_IP_ADDR
    char ip_addr[16];
#endif

    // Set defaults as appropriate
#ifdef CYGSEM_REDBOOT_DEFAULT_NO_BOOTP
    use_bootp = false;
#else
    use_bootp = true;
#endif
#ifdef CYGDBG_REDBOOT_NET_DEBUG
    net_debug = true;
#else
    net_debug = false;
#endif
    gdb_port = CYGNUM_REDBOOT_NETWORKING_TCP_PORT;
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
    // Fetch values from saved config data, if available
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
    flash_get_config("net_device", &default_devname, CONFIG_NETPORT);
#endif
    flash_get_config("net_debug", &net_debug, CONFIG_BOOL);
    flash_get_config("gdb_port", &gdb_port, CONFIG_INT);
    flash_get_config("bootp", &use_bootp, CONFIG_BOOL);
    if (!use_bootp) {
        flash_get_IP("bootp_my_ip", &__local_ip_addr);
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
        flash_get_IP("bootp_my_ip_mask", &__local_ip_mask);
        flash_get_IP("bootp_my_gateway_ip", &__local_ip_gate);
#endif
    }
#endif
# ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
    // Don't override if the user has deliberately set something more
    // verbose.
    if (0 == cyg_io_eth_net_debug)
        cyg_io_eth_net_debug = net_debug;
# endif
    have_net = false;
    // Make sure the recv buffers are set up
    eth_drv_buffers_init();
    __pktbuf_init();

    // Initialize network device(s).
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
    default_index = net_devindex(default_devname);
    if (default_index < 0)
	default_index = 0;
#ifdef CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE
    if ((t = net_devtab_entry(default_index)) != NULL && t->init(t)) {
	t->status = CYG_NETDEVTAB_STATUS_AVAIL;
	primary_net = __local_enet_sc;
    } else
#endif
#endif
    for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
#if defined(CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE)
	if (index == default_index)
	    continue;
#endif
	if (t->init(t)) {
            t->status = CYG_NETDEVTAB_STATUS_AVAIL;
            if (primary_net == (struct eth_drv_sc *)0) {
                primary_net = __local_enet_sc;
            }
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
#if !defined(CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE)
            if (index == default_index) {
                primary_net = __local_enet_sc;
            }
#else
	    break;
#endif
#endif
        }
    }
    __local_enet_sc = primary_net;

    if (!__local_enet_sc) {
        diag_printf("No network interfaces found\n");
        return;
    }    
    // Initialize the network [if present]
    if (use_bootp) {
        if (__bootp_find_local_ip(&my_bootp_info) == 0) {
            have_net = true;
        } else {
            // Is it an unset address, or has it been set to a static addr
            if (__local_ip_addr[0] == 0 && __local_ip_addr[1] == 0 &&
                __local_ip_addr[2] == 0 && __local_ip_addr[3] == 0) {
                show_eth_info();
                diag_printf("Can't get BOOTP info for device!\n");
            } else {
                diag_printf("Can't get BOOTP info, using default IP address\n");
                have_net = true;
            }
        }
    } else {
        enet_addr_t enet_addr;
        have_net = true;  // Assume values in FLASH were OK
        // Tell the world that we are using this fixed IP address
        if (__arp_request((ip_addr_t *)__local_ip_addr, &enet_addr, 1) >= 0) {
            diag_printf("Warning: IP address %s in use\n", inet_ntoa((in_addr_t *)&__local_ip_addr));
        }
    }
    if (have_net) {
        show_eth_info();
#ifdef CYGDAT_REDBOOT_DEFAULT_BOOTP_SERVER_IP_ADDR
        diag_sprintf(ip_addr, "%d.%d.%d.%d", 
                     CYGDAT_REDBOOT_DEFAULT_BOOTP_SERVER_IP_ADDR);
        inet_aton(ip_addr, &my_bootp_info.bp_siaddr);
#endif
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
        flash_get_IP("bootp_server_ip", (ip_addr_t *)&my_bootp_info.bp_siaddr);
#endif
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
	redboot_dns_res_init();
#endif
        show_addrs();
        net_io_init();
    }
}