static void tftp_test(struct bootp *bp) { int res, err, len; struct sockaddr_in host; #ifdef CYGPKG_NET_INET6 struct sockaddr_in6 ipv6router; char server[64]; #endif memset((char *)&host, 0, sizeof(host)); host.sin_len = sizeof(host); host.sin_family = AF_INET; host.sin_addr = bp->bp_siaddr; host.sin_port = 0; diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr)); res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err); diag_printf("res = %d, err = %d\n", res, err); if (res > 0) { diag_dump_buf(buf, min(res,1024)); } len = res; diag_printf("Trying tftp_put %s %16s, length %d\n", PUTFILE, inet_ntoa(host.sin_addr), len); res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err); diag_printf("put - res: %d\n", res); #ifdef CYGPKG_NET_INET6 // Wait for router solicit process to happen. if (!cyg_net_get_ipv6_advrouter(&ipv6router)) { diag_printf("No router advertisement recieved\n"); cyg_test_exit(); } getnameinfo((struct sockaddr *)&ipv6router,sizeof(ipv6router), server, sizeof(server), 0 ,0 ,NI_NUMERICHOST); diag_printf("Trying tftp_get %s using IPv6 from %16s...\n", GETFILE, server); res = tftp_client_get( GETFILE, server, 0, buf, sizeof(buf), TFTP_OCTET, &err); diag_printf("IPv6 res = %d, err = %d\n", res, err); if (res > 0) { diag_dump_buf(buf, min(res,1024)); } len = res; diag_printf("Trying tftp_put %s using IPv6 to %16s, length %d\n", PUTFILE, server, len); res = tftp_client_put( PUTFILE, server, 0, buf, len, TFTP_OCTET, &err); diag_printf("put - res: %d\n", res); #endif }
// // Initialize network interface[s] using BOOTP/DHCP // void init_all_network_interfaces(void) { static volatile int in_init_all_network_interfaces = 0; #ifdef CYGPKG_IO_PCMCIA cyg_netdevtab_entry_t *t; #endif // CYGPKG_IO_PCMCIA #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD int rs_wait = 40; #endif cyg_scheduler_lock(); while ( in_init_all_network_interfaces ) { // Another thread is doing this... cyg_scheduler_unlock(); cyg_thread_delay( 10 ); cyg_scheduler_lock(); } in_init_all_network_interfaces = 1; cyg_scheduler_unlock(); #ifdef CYGHWR_NET_DRIVER_ETH0 if ( ! eth0_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth0")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth0'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth0'\n"); goto bail_eth0; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth0_up = true; #ifdef CYGHWR_NET_DRIVER_ETH0_DHCP eth0_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease)) #else #ifdef CYGPKG_NET_DHCP eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth0_name, ð0_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth0\n"); eth0_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP) eth0_up = true; build_bootp_record(ð0_bootp_data, eth0_name, string(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_SERVER)); show_bootp(eth0_name, ð0_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth0: #endif } #endif // CYGHWR_NET_DRIVER_ETH0 #ifdef CYGHWR_NET_DRIVER_ETH1 if ( ! eth1_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth1")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth1'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth1'\n"); goto bail_eth1; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth1_up = true; #ifdef CYGHWR_NET_DRIVER_ETH1_DHCP eth1_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease)) #else #ifdef CYGPKG_NET_DHCP eth1_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth1_name, ð1_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth1\n"); eth1_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP) eth1_up = true; build_bootp_record(ð1_bootp_data, eth1_name, string(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_SERVER)); show_bootp(eth1_name, ð1_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth1: #endif } #endif // CYGHWR_NET_DRIVER_ETH1 #ifdef CYGHWR_NET_DRIVER_ETH0 #ifndef CYGHWR_NET_DRIVER_ETH0_MANUAL if (eth0_up) { if (!init_net(eth0_name, ð0_bootp_data)) { diag_printf("Network initialization failed for eth0\n"); eth0_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX if (!init_net_IPv6(eth0_name, ð0_bootp_data, string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth0\n"); eth0_up = false; // ??? } #endif } #endif #endif #ifdef CYGHWR_NET_DRIVER_ETH1 #ifndef CYGHWR_NET_DRIVER_ETH1_MANUAL if (eth1_up) { if (!init_net(eth1_name, ð1_bootp_data)) { diag_printf("Network initialization failed for eth1\n"); eth1_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX if (!init_net_IPv6(eth1_name, ð1_bootp_data, string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth1\n"); eth1_up = false; // ??? } #endif } #endif #endif #ifdef CYGPKG_NET_NLOOP #if 0 < CYGPKG_NET_NLOOP { static int loop_init = 0; int i; if ( 0 == loop_init++ ) for ( i = 0; i < CYGPKG_NET_NLOOP; i++ ) init_loopback_interface( i ); } #endif #endif #ifdef CYGOPT_NET_DHCP_DHCP_THREAD dhcp_start_dhcp_mgt_thread(); #endif #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD ipv6_start_routing_thread(); // Wait for router solicit process to happen. while (rs_wait-- && !cyg_net_get_ipv6_advrouter(NULL)) { cyg_thread_delay(10); } if (rs_wait == 0 ) { diag_printf("No router solicit received\n"); } else { // Give Duplicate Address Detection time to work cyg_thread_delay(200); } #endif #ifdef CYGDAT_NS_DNS_DEFAULT_SERVER cyg_dns_res_start(string(CYGDAT_NS_DNS_DEFAULT_SERVER)); #endif #ifdef CYGDAT_NS_DNS_DOMAINNAME_NAME #define _NAME string(CYGDAT_NS_DNS_DOMAINNAME_NAME) { const char buf[] = _NAME; int len = strlen(_NAME); setdomainname(buf,len); } #endif // Open the monitor to other threads. in_init_all_network_interfaces = 0; }