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.


ceb41c1d61fa31cc07067174ca59c11d68d7c151
[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   struct ip_addr ipaddr, netmask, gateway;
39   sys_sem_t sem;
40   err_t err;
41
42   sem = sys_sem_new(0);
43
44 #ifdef LWIP_DEBUG
45   PrintBoth("lwIP: before tcpip_init\n");
46 #endif
47
48   tcpip_init(tcpip_init_done, &sem);  //initial the whole lwip module
49
50 #ifdef LWIP_DEBUG
51   PrintBoth("lwIP: After tcpip_init\n");
52 #endif
53
54   sys_sem_wait(sem);
55   sys_sem_free(sem);
56  
57   IP4_ADDR(&gateway, 192,168,1,1);
58   IP4_ADDR(&ipaddr, 192,168,1,2);
59   IP4_ADDR(&netmask, 255,255,255,0);
60
61
62   err = netifapi_netif_add(&ne2kif, &ipaddr, &netmask, &gateway, 
63                                                 NULL, ne2kif_init, ethernet_input); 
64   
65   if (err != ERR_OK){
66                 PrintBoth("lwip: initial network failed! add netif error %d/n", err);
67                 return;
68   }
69   
70   netifapi_netif_set_default(&ne2kif);
71
72   //initial a network application
73   ping_init();
74
75 #endif
76
77 }
78
79
80 #if 0
81 void test_network() {
82
83     uchar_t local_addr[4];
84     uchar_t remote_addr[4];
85
86     local_addr[0] = 10;
87     local_addr[1] = 0;
88     local_addr[2] = 2;
89     local_addr[3] = 21;
90
91 //    set_ip_addr(local_addr);
92
93     remote_addr[0] = 10;
94     remote_addr[1] = 0;
95     remote_addr[2] = 2;
96     remote_addr[3] = 20;
97
98
99    // connect(remote_addr, 4301);
100
101 }
102
103 #endif