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.


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