Import of the contiki-2.x development code from the SICS internal CVS server
This commit is contained in:
commit
c9e808d638
671 changed files with 95332 additions and 0 deletions
57
platform/minimal-net/Makefile.minimal-net
Normal file
57
platform/minimal-net/Makefile.minimal-net
Normal file
|
@ -0,0 +1,57 @@
|
|||
ifndef CONTIKI
|
||||
$(error CONTIKI not defined! You must specify where CONTIKI resides!)
|
||||
endif
|
||||
|
||||
#contiki: contiki-$(TARGET).a
|
||||
|
||||
CONTIKI_TARGET_DIRS = . net
|
||||
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES = tapdev-service.c tapdev.c contiki-main.c dlloader.c clock.c leds.c leds-arch.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
### Define the CPU directory
|
||||
CONTIKI_CPU=$(CONTIKI)/cpu/x86
|
||||
|
||||
### Compiler definitions
|
||||
CC = gcc
|
||||
LD = ld
|
||||
AS = as
|
||||
OBJCOPY = objcopy
|
||||
STRIP = strip
|
||||
CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) \
|
||||
-I$(CONTIKI)/platform/$(TARGET) \
|
||||
${addprefix -I,$(APPDIRS)} $(APP_INCLUDES) \
|
||||
-DWITH_UIP -DWITH_ASCII \
|
||||
-Wall -g -I. -I/usr/local/include
|
||||
CFLAGS += $(CFLAGSNO)
|
||||
LDFLAGS = -Wl,-Map=contiki.map,-export-dynamic
|
||||
|
||||
### Setup directory search path for source files
|
||||
|
||||
CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
|
||||
$(CONTIKI_TARGET_DIRS)}
|
||||
vpath %.c $(PROJECTDIRS) \
|
||||
$(CONTIKIDIRS) $(APPDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
|
||||
$(CONTIKI_CPU) $(APP_DIRS)
|
||||
|
||||
### Compilation rules
|
||||
|
||||
# $(OBJECTDIR)/%.o: %.c
|
||||
# $(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.so: $(OBJECTDIR)/%.o
|
||||
$(LD) -shared -o $@ $^
|
||||
|
||||
# %.ce: %.co
|
||||
# $(LD) -shared -o $@ $^
|
||||
|
||||
# %.co: %.c
|
||||
# $(CC) $(CFLAGS) -DPROCESS_LOADABLE -c $< -o $@
|
||||
# $(STRIP) --strip-unneeded -g -x $@
|
||||
|
||||
# %: %.co $(CONTIKI_TARGET_MAIN) $(PROJECT_OBJECTFILES) contiki-$(TARGET).a
|
||||
# $(CC) $(CFLAGS) -o $@.$(TARGET) $^ $(LDFLAGS)
|
61
platform/minimal-net/clock.c
Normal file
61
platform/minimal-net/clock.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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: clock.c,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Clock implementation for Unix.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "sys/clock.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
gettimeofday(&tv, &tz);
|
||||
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
clock_delay(unsigned int d)
|
||||
{
|
||||
/* Does not do anything. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
62
platform/minimal-net/contiki-conf.h
Normal file
62
platform/minimal-net/contiki-conf.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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: contiki-conf.h,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define CC_CONF_REGISTER_ARGS 1
|
||||
#define CC_CONF_FUNCTION_POINTER_ARGS 1
|
||||
#define CC_CONF_FASTCALL
|
||||
#define CC_CONF_VA_ARGS 1
|
||||
|
||||
typedef uint8_t u8_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
#define UIP_CONF_MAX_CONNECTIONS 40
|
||||
#define UIP_CONF_MAX_LISTENPORTS 40
|
||||
#define UIP_CONF_BUFFER_SIZE 600
|
||||
#define UIP_CONF_BYTE_ORDER LITTLE_ENDIAN
|
||||
#define UIP_CONF_TCP_SPLIT 1
|
||||
#define UIP_CONF_LOGGING 1
|
||||
#define UIP_CONF_UDP_CHECKSUMS 1
|
||||
|
||||
typedef unsigned long clock_time_t;
|
||||
#define CLOCK_CONF_SECOND 1000
|
||||
|
||||
#define LOG_CONF_ENABLED 1
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
94
platform/minimal-net/contiki-main.c
Normal file
94
platform/minimal-net/contiki-main.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 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. 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 Contiki OS
|
||||
*
|
||||
* $Id: contiki-main.c,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "net/tapdev-service.h"
|
||||
|
||||
PROCINIT(&etimer_process, &tcpip_process,
|
||||
&tapdev_process);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
u16_t addr[2];
|
||||
|
||||
process_init();
|
||||
|
||||
procinit_init();
|
||||
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
uip_ipaddr(addr, 192,168,2,2);
|
||||
uip_sethostaddr(addr);
|
||||
|
||||
uip_ipaddr(addr, 192,168,2,1);
|
||||
uip_setdraddr(addr);
|
||||
|
||||
uip_ipaddr(addr, 255,255,255,0);
|
||||
uip_setnetmask(addr);
|
||||
|
||||
while(1) {
|
||||
int n;
|
||||
n = process_run();
|
||||
/* if(n > 0) {
|
||||
printf("%d processes in queue\n");
|
||||
}*/
|
||||
usleep(1);
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void log_message(char *m1, char *m2)
|
||||
{
|
||||
printf("%s%s\n", m1, m2);
|
||||
}
|
||||
|
||||
void
|
||||
uip_log(char *m)
|
||||
{
|
||||
printf("uIP: '%s'\n", m);
|
||||
}
|
||||
|
||||
unsigned short
|
||||
sensors_light1(void)
|
||||
{
|
||||
static unsigned short count;
|
||||
return count++;
|
||||
}
|
104
platform/minimal-net/net/tapdev-service.c
Normal file
104
platform/minimal-net/net/tapdev-service.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "tapdev.h"
|
||||
#include "net/uip-neighbor.h"
|
||||
|
||||
/*static struct uip_eth_addr addr =
|
||||
{{0x08, 0x12, 0x23, 0x89, 0xa3, 0x94}};*/
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
|
||||
SERVICE(tapdev_service, packet_service, { tapdev_send });
|
||||
|
||||
PROCESS(tapdev_process, "TAP driver");
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
/* tapdev_service_request_poll();*/
|
||||
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)) {
|
||||
/* uip_arp_ipin();
|
||||
uip_len -= sizeof(struct uip_eth_hdr);*/
|
||||
/* uip_input();*/
|
||||
tcpip_input();
|
||||
/* 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. */
|
||||
} 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_do_send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
PROCESS_THREAD(tapdev_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(pollhandler());
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
tapdev_init();
|
||||
|
||||
SERVICE_REGISTER(tapdev_service);
|
||||
|
||||
process_poll(&tapdev_process);
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == PROCESS_EVENT_POLL) {
|
||||
pollhandler();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
40
platform/minimal-net/net/tapdev-service.h
Normal file
40
platform/minimal-net/net/tapdev-service.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*/
|
||||
#ifndef __TAPDEV_SERVICE_H__
|
||||
#define __TAPDEV_SERVICE_H__
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
PROCESS_NAME(tapdev_process);
|
||||
|
||||
#endif /* __TAPDEV_SERVICE_H__ */
|
184
platform/minimal-net/net/tapdev.c
Normal file
184
platform/minimal-net/net/tapdev.c
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* 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 <adam@sics.se>
|
||||
*
|
||||
* $Id: tapdev.c,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#ifdef linux
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#define DEVTAP "/dev/net/tun"
|
||||
#else /* linux */
|
||||
#define DEVTAP "/dev/tap0"
|
||||
#endif /* linux */
|
||||
|
||||
#include "tapdev.h"
|
||||
|
||||
#include "contiki-net.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])
|
||||
|
||||
static void do_send(void);
|
||||
u8_t tapdev_send(void);
|
||||
|
||||
|
||||
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_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;
|
||||
|
||||
/* gdk_input_add(fd, GDK_INPUT_READ,
|
||||
read_callback, NULL);*/
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
do_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);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
tapdev_send(void)
|
||||
{
|
||||
uip_arp_out();
|
||||
|
||||
do_send();
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tapdev_do_send(void)
|
||||
{
|
||||
do_send();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
46
platform/minimal-net/net/tapdev.h
Normal file
46
platform/minimal-net/net/tapdev.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __TAPDEV_H__
|
||||
#define __TAPDEV_H__
|
||||
|
||||
#include "contiki-net.h"
|
||||
|
||||
void tapdev_init(void);
|
||||
u8_t tapdev_send(void);
|
||||
u16_t tapdev_poll(void);
|
||||
void tapdev_do_send(void);
|
||||
#endif /* __TAPDEV_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue