N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/server/l4/patches/lwip-ore/lwip_ore.c

Go to the documentation of this file.
00001 
00012 /*
00013  * Copyright 2007. Los Alamos National Security, LLC. This material
00014  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00015  * Los Alamos National Laboratory (LANL), which is operated by Los
00016  * Alamos National Security, LLC, for the Department of Energy. The
00017  * U.S. Government has rights to use, reproduce, and distribute this
00018  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00019  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00020  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00021  * produce derivative works, such modified software should be clearly
00022  * marked, so as not to confuse it with the version available from LANL.
00023  *
00024  * Additionally, this program is free software; you can redistribute
00025  * it and/or modify it under the terms of the GNU General Public
00026  * License as published by the Free Software Foundation; version 2 of
00027  * the License. Accordingly, this program is distributed in the hope
00028  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00029  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00030  * PURPOSE. See the GNU General Public License for more details.
00031  */
00032 
00033 /*
00034  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
00035  * All rights reserved. 
00036  * 
00037  * Redistribution and use in source and binary forms, with or without modification, 
00038  * are permitted provided that the following conditions are met:
00039  *
00040  * 1. Redistributions of source code must retain the above copyright notice,
00041  *    this list of conditions and the following disclaimer.
00042  * 2. Redistributions in binary form must reproduce the above copyright notice,
00043  *    this list of conditions and the following disclaimer in the documentation
00044  *    and/or other materials provided with the distribution.
00045  * 3. The name of the author may not be used to endorse or promote products
00046  *    derived from this software without specific prior written permission. 
00047  *
00048  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00049  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00050  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00051  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00052  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00053  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00054  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00055  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00056  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00057  * OF SUCH DAMAGE.
00058  */
00059 
00060 
00061 #include "lwip/sys.h"
00062 #include "lwip/mem.h"
00063 #include "lwip/memp.h"
00064 #include "lwip/pbuf.h"
00065 #include "lwip/tcp.h"
00066 #include "lwip/tcpip.h"
00067 #include "lwip/netif.h"
00068 #include "lwip/stats.h"
00069 #include "lwip/sockets.h"
00070 #include "netif/oreif.h"
00071 #include "lwip_ore.h"
00072 
00073 
00074 static void tcpip_init_done(void *arg)
00075 {
00076   sys_sem_t *sem;
00077   sem = arg;
00078   sys_sem_signal(*sem);
00079 }
00080 
00081 struct netif netif;
00082 
00083 void lwip_ore_init(void *args)
00084 {
00085   struct ip_addr ipaddr, netmask, gateway;
00086   sys_sem_t sem;
00087   struct ore_net_cfg *cfg = (struct ore_net_cfg*)args;
00088 
00089   stats_init();
00090   sys_init();
00091   mem_init();
00092   memp_init();
00093   pbuf_init();
00094   //lwip_socket_init();
00095   
00096   sem = sys_sem_new(0);
00097   tcpip_init(tcpip_init_done, &sem);
00098   sys_sem_wait(sem);
00099   sys_sem_free(sem);
00100   
00101   netif_init();
00102 
00103   if (cfg != NULL) {
00104     memcpy(&ipaddr, &cfg->ipaddr, sizeof(struct ip_addr));
00105     memcpy(&netmask, &cfg->netmask, sizeof(struct ip_addr));
00106     memcpy(&gateway, &cfg->gateway, sizeof(struct ip_addr));
00107   } else {
00108     IP4_ADDR(&gateway, 192,168,1,1);
00109     IP4_ADDR(&ipaddr, 192,168,1,1);
00110     IP4_ADDR(&netmask, 255,255,255,0);
00111   }
00112   
00113   netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway,
00114                               NULL, oreif_init, tcpip_input));
00115 }
00116 


© 2007, Los Alamos National Security, LLC.