Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


updated to 64 bits based on the wrong f#@$%ing trunk
[palacios.git] / geekos / src / geekos / net.c
1 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
2 /* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
3
4
5 #include <geekos/net.h>
6 #include <geekos/socket.h>
7 #include <geekos/ne2k.h>
8 #include <geekos/debug.h>
9
10 #ifdef LWIP
11
12 #include <lwip/apps/ping.h>
13 #include <lwip/lwip/sockets.h>
14 #include <lwip/ipv4/lwip/ip_addr.h>
15 #include <lwip/netif/ne2kif.h>
16 #include <lwip/sys.h>
17 #include <lwip/netifapi.h>
18 #include <lwip/tcpip.h>
19 #include <netif/etharp.h>
20
21
22 static void
23 tcpip_init_done(void *arg)
24 {
25   sys_sem_t *sem;
26   sem = arg;
27   sys_sem_signal(*sem);
28 }
29
30 #endif
31
32 void Init_Network() {
33
34   //temporay now we are using lwip sockets
35   // init_socket_layer();
36
37 #ifdef LWIP
38   
39   struct ip_addr ipaddr, netmask, gateway;
40   sys_sem_t sem;
41   err_t err;
42
43   sem = sys_sem_new(0);
44
45 #ifdef LWIP_DEBUG
46   PrintBoth("lwIP: before tcpip_init\n");
47 #endif
48
49   tcpip_init(tcpip_init_done, &sem);  //initial the whole lwip module
50
51 #ifdef LWIP_DEBUG
52   PrintBoth("lwIP: After tcpip_init\n");
53 #endif
54
55   sys_sem_wait(sem);
56   sys_sem_free(sem);
57  
58   IP4_ADDR(&gateway, 192,168,1,1);
59   IP4_ADDR(&ipaddr, 192,168,1,2);
60   IP4_ADDR(&netmask, 255,255,255,0);
61
62
63   err = netifapi_netif_add(&ne2kif, &ipaddr, &netmask, &gateway, 
64                                                 NULL, ne2kif_init, ethernet_input); 
65   
66   if (err != ERR_OK){
67                 PrintBoth("lwip: initial network failed! add netif error %d/n", err);
68                 return;
69   }
70   
71   netifapi_netif_set_default(&ne2kif);
72
73   //initial a network application
74   ping_init();
75
76 #endif
77
78 }
79
80
81 #if 0
82 void test_network() {
83
84     uchar_t local_addr[4];
85     uchar_t remote_addr[4];
86
87     local_addr[0] = 10;
88     local_addr[1] = 0;
89     local_addr[2] = 2;
90     local_addr[3] = 21;
91
92 //    set_ip_addr(local_addr);
93
94     remote_addr[0] = 10;
95     remote_addr[1] = 0;
96     remote_addr[2] = 2;
97     remote_addr[3] = 20;
98
99
100    // connect(remote_addr, 4301);
101
102 }
103
104 #endif