/* * Copyright 2010 Stefan Lankes, Chair for Operating Systems, * RWTH Aachen University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This file is part of MetalSVM. */ #include #include #include #include #include #include #include #ifdef CONFIG_LWIP #include #include #include #include #include #include #include #include #endif #include void echo_init(void); void ping_init(void); static volatile int done = 0; #if defined(CONFIG_LWIP) && defined(CONFIG_PCI) static tid_t netid; int STDCALL network_task(void* arg) { struct netif netif; struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; kputs("Network task is started\n"); /* Set network address variables */ //IP4_ADDR(&gw, 192,168,1,254); //IP4_ADDR(&ipaddr, 192,168,1,100); //IP4_ADDR(&netmask, 255,255,255,0); /* Clear network address because we use DHCP to get an ip address */ IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); /* Clear the IP address, Subnet Mask, and Gateway */ ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; /* Bring up the network interface */ if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, ethernet_input)) { kputs("Unable to add network interface\n"); return -ENXIO; } netif_set_default(&netif); if (netif_is_up(&netif)) { kputs("Network interface is not up\n"); return -EIO; } kprintf("Starting DHCPCD...\n"); dhcp_start(&netif); /* wait for ip address */ while(!netif.ip_addr.addr) { rtl8139if_wait(&netif, 1); udelay(500000); } // start echo and ping server echo_init(); ping_init(); while(!done) { rtl8139if_wait(&netif, 0); } dhcp_release(&netif); dhcp_stop(&netif); return 0; } #endif int network_shotdown(void) { done = 1; return 0; } int network_init(void) { #if defined(CONFIG_LWIP) lwip_init(); #endif #if defined(CONFIG_LWIP) && defined(CONFIG_PCI) return create_kernel_task(&netid, network_task, NULL); #else return 0; #endif }