1 /* network.c - Toplevel networking functions
3 Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
5 This code is licensed to you under the terms of the GNU GPL, version 2;
6 see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
14 #include "lwip/init.h"
15 #include "lwip/dhcp.h"
18 #include "gelic_netif.h"
19 #include "netif/etharp.h"
22 static struct ip_addr ipaddr
, netmask
, gw
;
25 static u64 last_tcp_time
;
27 static u64 last_arp_time
;
28 static u64 last_dhcp_coarse_time
;
29 static u64 last_dhcp_fine_time
;
32 memset(&ipaddr
, 0, sizeof(ipaddr
));
33 memset(&netmask
, 0, sizeof(ipaddr
));
34 memset(&gw
, 0, sizeof(ipaddr
));
36 printf("Initializing network...\n");
38 printf("lwIP Initialized\n");
39 netif_add(ð
, &ipaddr
, &netmask
, &gw
, NULL
, gelicif_init
, ethernet_input
);
40 netif_set_default(ð
);
42 printf("Ethernet interface initialized\n");
43 printf("Starting DHCP\n");
50 last_arp_time
= last_dhcp_coarse_time
= last_dhcp_fine_time
= now
;
58 if ((now
- last_arp_time
) >= (ARP_TMR_INTERVAL
*TICKS_PER_MS
)) {
63 if ((now
- last_tcp_time
) >= (TCP_TMR_INTERVAL
*TICKS_PER_MS
)) {
68 if ((now
- last_dhcp_coarse_time
) >= (DHCP_COARSE_TIMER_SECS
*TICKS_PER_SEC
)) {
70 last_dhcp_coarse_time
= now
;
72 if ((now
- last_dhcp_fine_time
) >= (DHCP_FINE_TIMER_MSECS
*TICKS_PER_MS
)) {
74 last_dhcp_fine_time
= now
;
78 void net_shutdown(void) {
79 printf("Releasing DHCP lease...\n");
82 printf("Shutting down network...\n");
84 gelicif_shutdown(ð
);