From e6301c6221f6144437951168927df7f6ee2d37c3 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sat, 31 Mar 2007 18:49:37 +0000 Subject: [PATCH] Moved tapdev*.[ch] from platform/netsim/net and platform/minimal-net/net to cpu/native/net --- cpu/native/Makefile.native | 2 + .../native}/net/tapdev-service.c | 2 +- .../native}/net/tapdev-service.h | 2 +- {platform/netsim => cpu/native}/net/tapdev.c | 11 +- {platform/netsim => cpu/native}/net/tapdev.h | 2 +- platform/minimal-net/net/tapdev-service.c | 102 ----------- platform/minimal-net/net/tapdev.c | 159 ------------------ platform/minimal-net/net/tapdev.h | 44 ----- platform/netsim/net/tapdev-service.h | 41 ----- 9 files changed, 14 insertions(+), 351 deletions(-) rename {platform/netsim => cpu/native}/net/tapdev-service.c (97%) rename {platform/minimal-net => cpu/native}/net/tapdev-service.h (96%) rename {platform/netsim => cpu/native}/net/tapdev.c (92%) rename {platform/netsim => cpu/native}/net/tapdev.h (96%) delete mode 100644 platform/minimal-net/net/tapdev-service.c delete mode 100644 platform/minimal-net/net/tapdev.c delete mode 100644 platform/minimal-net/net/tapdev.h delete mode 100644 platform/netsim/net/tapdev-service.h diff --git a/cpu/native/Makefile.native b/cpu/native/Makefile.native index e65781022..42926e140 100644 --- a/cpu/native/Makefile.native +++ b/cpu/native/Makefile.native @@ -27,3 +27,5 @@ else symbols.c symbols.h: @${CONTIKI}/tools/make-empty-symbols endif + +CONTIKI_TARGET_DIRS += $(CONTIKI_CPU)/net diff --git a/platform/netsim/net/tapdev-service.c b/cpu/native/net/tapdev-service.c similarity index 97% rename from platform/netsim/net/tapdev-service.c rename to cpu/native/net/tapdev-service.c index d100be71c..c67c36c0f 100644 --- a/platform/netsim/net/tapdev-service.c +++ b/cpu/native/net/tapdev-service.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tapdev-service.c,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $ + * @(#)$Id: tapdev-service.c,v 1.1 2007/03/31 18:49:40 adamdunkels Exp $ */ #include "contiki-net.h" diff --git a/platform/minimal-net/net/tapdev-service.h b/cpu/native/net/tapdev-service.h similarity index 96% rename from platform/minimal-net/net/tapdev-service.h rename to cpu/native/net/tapdev-service.h index 309bc22ea..62755192d 100644 --- a/platform/minimal-net/net/tapdev-service.h +++ b/cpu/native/net/tapdev-service.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tapdev-service.h,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $ + * @(#)$Id: tapdev-service.h,v 1.1 2007/03/31 18:49:40 adamdunkels Exp $ */ #ifndef __TAPDEV_SERVICE_H__ diff --git a/platform/netsim/net/tapdev.c b/cpu/native/net/tapdev.c similarity index 92% rename from platform/netsim/net/tapdev.c rename to cpu/native/net/tapdev.c index 0e80be379..a058009a8 100644 --- a/platform/netsim/net/tapdev.c +++ b/cpu/native/net/tapdev.c @@ -31,7 +31,7 @@ * * Author: Adam Dunkels * - * $Id: tapdev.c,v 1.4 2007/03/29 22:26:17 adamdunkels Exp $ + * $Id: tapdev.c,v 1.1 2007/03/31 18:49:40 adamdunkels Exp $ */ #include @@ -107,7 +107,14 @@ tapdev_init(void) snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.1.1"); system(buf); printf("%s\n", buf); - snprintf(buf, sizeof(buf), "route add -net 172.16.0.0 192.168.1.2"); +#ifdef linux + /* route add for linux */ + snprintf(buf, sizeof(buf), "route add -net 172.16.0.0/16 gw 192.168.1.2"); +#else /* linux */ + /* route add for freebsd */ + snprintf(buf, sizeof(buf), "route add -net 172.16.0.0/16 192.168.1.2"); +#endif /* linux */ + system(buf); printf("%s\n", buf); atexit(remove_route); diff --git a/platform/netsim/net/tapdev.h b/cpu/native/net/tapdev.h similarity index 96% rename from platform/netsim/net/tapdev.h rename to cpu/native/net/tapdev.h index 939bd4e0d..73a6b853e 100644 --- a/platform/netsim/net/tapdev.h +++ b/cpu/native/net/tapdev.h @@ -31,7 +31,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: tapdev.h,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $ + * $Id: tapdev.h,v 1.1 2007/03/31 18:49:40 adamdunkels Exp $ */ #ifndef __TAPDEV_H__ diff --git a/platform/minimal-net/net/tapdev-service.c b/platform/minimal-net/net/tapdev-service.c deleted file mode 100644 index 7e432b6bf..000000000 --- a/platform/minimal-net/net/tapdev-service.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * @(#)$Id: tapdev-service.c,v 1.4 2007/03/27 21:19:35 oliverschmidt Exp $ - */ - -#include "contiki-net.h" -#include "tapdev.h" -#include "net/uip-neighbor.h" - -#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) - -static u8_t output(void); - -SERVICE(tapdev_service, packet_service, { output }); - -PROCESS(tapdev_process, "TAP driver"); - -/*---------------------------------------------------------------------------*/ -static u8_t -output(void) -{ - uip_arp_out(); - tapdev_send(); - - return 0; -} -/*---------------------------------------------------------------------------*/ -static void -pollhandler(void) -{ - process_poll(&tapdev_process); - uip_len = tapdev_poll(); - - if(uip_len > 0) { -#if UIP_CONF_IPV6 - if(BUF->type == htons(UIP_ETHTYPE_IPV6)) { - uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); - tcpip_input(); - } else -#endif /* UIP_CONF_IPV6 */ - if(BUF->type == htons(UIP_ETHTYPE_IP)) { - tcpip_input(); - } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(); - /* If the above function invocation resulted in data that - should be sent out on the network, the global variable - uip_len is set to a value > 0. */ - if(uip_len > 0) { - tapdev_send(); - } - } - } -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(tapdev_process, ev, data) -{ - PROCESS_BEGIN(); - - tapdev_init(); - - SERVICE_REGISTER(tapdev_service); - - process_poll(&tapdev_process); - - while(1) { - PROCESS_YIELD(); - if(ev == PROCESS_EVENT_POLL) { - pollhandler(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/minimal-net/net/tapdev.c b/platform/minimal-net/net/tapdev.c deleted file mode 100644 index baf199452..000000000 --- a/platform/minimal-net/net/tapdev.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2001, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Author: Adam Dunkels - * - * $Id: tapdev.c,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef linux -#include -#include -#include -#define DEVTAP "/dev/net/tun" -#else /* linux */ -#define DEVTAP "/dev/tap0" -#endif /* linux */ - -#include "contiki-net.h" -#include "tapdev.h" - -#define DROP 0 - -#if DROP -static int drop = 0; -#endif - -static int fd; - -static unsigned long lasttime; - -#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) - -/*---------------------------------------------------------------------------*/ -void -tapdev_init(void) -{ - char buf[1024]; - - fd = open(DEVTAP, O_RDWR); - if(fd == -1) { - perror("tapdev: tapdev_init: open"); - return; - } - -#ifdef linux - { - struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = IFF_TAP|IFF_NO_PI; - if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { - perror(buf); - exit(1); - } - } -#endif /* Linux */ - - snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.2.1"); - system(buf); - printf("%s\n", buf); - - lasttime = 0; -} -/*---------------------------------------------------------------------------*/ -u16_t -tapdev_poll(void) -{ - fd_set fdset; - struct timeval tv; - int ret; - - tv.tv_sec = 0; - tv.tv_usec = 0; - - FD_ZERO(&fdset); - if(fd > 0) { - FD_SET(fd, &fdset); - } - - ret = select(fd + 1, &fdset, NULL, NULL, &tv); - - if(ret == 0) { - return 0; - } - ret = read(fd, uip_buf, UIP_BUFSIZE); - - if(ret == -1) { - perror("tapdev_poll: read"); - } - return ret; -} -/*---------------------------------------------------------------------------*/ -void -tapdev_send(void) -{ - int ret; - - if(fd <= 0) { - return; - } - - /* printf("tapdev_send: sending %d bytes\n", size);*/ - /* check_checksum(uip_buf, size);*/ - -#if DROP - drop++; - if(drop % 8 == 7) { - printf("Dropped an output packet!\n"); - return; - } -#endif /* DROP */ - - ret = write(fd, uip_buf, uip_len); - - if(ret == -1) { - perror("tap_dev: tapdev_send: writev"); - exit(1); - } -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/minimal-net/net/tapdev.h b/platform/minimal-net/net/tapdev.h deleted file mode 100644 index fb282e921..000000000 --- a/platform/minimal-net/net/tapdev.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2003, Adam Dunkels. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Adam Dunkels. - * 4. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This file is part of the uIP TCP/IP stack. - * - * $Id: tapdev.h,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $ - */ - -#ifndef __TAPDEV_H__ -#define __TAPDEV_H__ - -void tapdev_init(void); -u16_t tapdev_poll(void); -void tapdev_send(void); - -#endif /* __TAPDEV_H__ */ diff --git a/platform/netsim/net/tapdev-service.h b/platform/netsim/net/tapdev-service.h deleted file mode 100644 index e5127aa20..000000000 --- a/platform/netsim/net/tapdev-service.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - * @(#)$Id: tapdev-service.h,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $ - */ - -#ifndef __TAPDEV_SERVICE_H__ -#define __TAPDEV_SERVICE_H__ - -#include "contiki.h" - -PROCESS_NAME(tapdev_process); - -#endif /* __TAPDEV_SERVICE_H__ */