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.


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