use netifapi to initialize the NICs
This commit is contained in:
parent
0bd2888869
commit
2dd6fb87d1
2 changed files with 45 additions and 63 deletions
103
kernel/init.c
103
kernel/init.c
|
@ -34,7 +34,7 @@
|
|||
#include <lwip/tcp.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include <lwip/timers.h>
|
||||
#include <netif/etharp.h>
|
||||
#endif
|
||||
|
@ -47,7 +47,6 @@
|
|||
#endif
|
||||
|
||||
void echo_init(void);
|
||||
void ping_init(void);
|
||||
void netio_init(void);
|
||||
int test_init(void);
|
||||
|
||||
|
@ -71,26 +70,20 @@ int lowlevel_init(void)
|
|||
}
|
||||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
static struct netif* default_netif = NULL;
|
||||
static struct netif default_netif;
|
||||
|
||||
static int init_netifs(void)
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
err_t err;
|
||||
|
||||
kputs("Initialize NICs...\n");
|
||||
|
||||
// Set up the lwIP network interface
|
||||
// Allocate and configure netif
|
||||
default_netif = (struct netif *) mem_malloc(sizeof(struct netif));
|
||||
if(default_netif == NULL)
|
||||
{
|
||||
kprintf("ERROR: Out of memory for default netif\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(default_netif, 0x00, sizeof(struct netif));
|
||||
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||
|
||||
#ifdef CONFIG_ROCKCREEK
|
||||
/* Set network address variables */
|
||||
IP4_ADDR(&gw, 192,168,28,254);
|
||||
|
@ -98,15 +91,13 @@ static int init_netifs(void)
|
|||
IP4_ADDR(&netmask, 255,255,255,0);
|
||||
|
||||
/* Bring up the network interface */
|
||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) {
|
||||
kputs("Unable to add network interface\n");
|
||||
if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) != ERR_OK) {
|
||||
kprintf("Unable to add network interface: err = %d\n", err);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
netif_set_default(default_netif);
|
||||
netif_set_up(default_netif);
|
||||
|
||||
//mmnif_open();
|
||||
netifapi_netif_set_default(&default_netif);
|
||||
netifapi_netif_set_up(&default_netif);
|
||||
#else
|
||||
/* Clear network address because we use DHCP to get an ip address */
|
||||
IP4_ADDR(&gw, 0,0,0,0);
|
||||
|
@ -114,15 +105,27 @@ static int init_netifs(void)
|
|||
IP4_ADDR(&netmask, 0,0,0,0);
|
||||
|
||||
/* Bring up the network interface */
|
||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) {
|
||||
kputs("Unable to add network interface\n");
|
||||
if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) != ERR_OK) {
|
||||
kprintf("Unable to add network interface: err = %d\n", err);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
netif_set_default(default_netif);
|
||||
netifapi_netif_set_default(&default_netif);
|
||||
|
||||
kprintf("Starting DHCPCD...\n");
|
||||
dhcp_start(default_netif);
|
||||
netifapi_dhcp_start(&default_netif);
|
||||
|
||||
int mscnt = 0;
|
||||
/* wait for ip address */
|
||||
while(!default_netif.ip_addr.addr) {
|
||||
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -134,43 +137,30 @@ static void tcpip_init_done(void* arg)
|
|||
{
|
||||
sys_sem_t* sem = (sys_sem_t*)arg;
|
||||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
init_netifs();
|
||||
#endif
|
||||
sys_sem_signal(sem);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LWIP
|
||||
static int network_shutdown(void)
|
||||
{
|
||||
#ifdef CONFIG_ROCKCREEK
|
||||
if (default_netif) {
|
||||
netif_set_link_down(default_netif);
|
||||
mem_free(default_netif);
|
||||
default_netif = NULL;
|
||||
}
|
||||
//mmnif_close();
|
||||
#elif defined(CONFIG_PCI)
|
||||
if (default_netif) {
|
||||
dhcp_release(default_netif);
|
||||
dhcp_stop(default_netif);
|
||||
mem_free(default_netif);
|
||||
default_netif = NULL;
|
||||
}
|
||||
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
|
||||
netifapi_netif_set_link_down(&default_netif);
|
||||
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||
#elif defined(CONFIG_LWIP) && defined(CONFIG_PCI)
|
||||
netifapi_dhcp_stop(&default_netif);
|
||||
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int shutdown(void)
|
||||
{
|
||||
#ifdef CONFIG_LWIP
|
||||
return network_shutdown();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
ret = network_shutdown();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void list_fs(vfs_node_t* node, uint32_t depth)
|
||||
|
@ -229,30 +219,17 @@ int initd(void* arg)
|
|||
sys_sem_free(&sem);
|
||||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
init_netifs();
|
||||
|
||||
/* test if interface is really up */
|
||||
if (!netif_is_up(default_netif)) {
|
||||
if (!netif_is_up(&default_netif)) {
|
||||
kputs("network interface is not up\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ROCKCREEK
|
||||
int mscnt = 0;
|
||||
/* wait for ip address */
|
||||
while(default_netif && !default_netif->ip_addr.addr) {
|
||||
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// start echo, ping and/or netio server
|
||||
// start echo and/or netio server
|
||||
//echo_init();
|
||||
//ping_init();
|
||||
//netio_init();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,6 +34,11 @@
|
|||
*/
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
/**
|
||||
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
|
||||
*/
|
||||
#define LWIP_NETIF_API 1
|
||||
|
||||
/**
|
||||
* LWIP_DHCP==1: Enable DHCP module.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue