mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Copied tapdev from minimal-net to gtk.
This commit is contained in:
parent
1ca96b614a
commit
df02b4667a
@ -1,34 +1,73 @@
|
||||
/*
|
||||
* 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.2 2007/03/27 20:49:09 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include "net/packet-service.h"
|
||||
#include "contiki-net.h"
|
||||
#include "tapdev.h"
|
||||
#include "net/uip-neighbor.h"
|
||||
|
||||
#include "net/uip_arp.h"
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
static struct uip_eth_addr addr =
|
||||
{{0x08, 0x12, 0x23, 0x89, 0xa3, 0x94}};
|
||||
static u8_t output(void);
|
||||
|
||||
SERVICE(tapdev_service, packet_service, { tapdev_send });
|
||||
SERVICE(tapdev_service, packet_service, { output });
|
||||
|
||||
PROCESS(tapdev_process, "TAP driver");
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
static u8_t
|
||||
output(void)
|
||||
{
|
||||
uip_arp_out();
|
||||
tapdev_send();
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pollhandler(void)
|
||||
{
|
||||
/* tapdev_service_request_poll();*/
|
||||
process_poll(&tapdev_process);
|
||||
uip_len = tapdev_poll();
|
||||
|
||||
if(uip_len > 0) {
|
||||
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
|
||||
uip_arp_ipin();
|
||||
uip_len -= sizeof(struct uip_eth_hdr);
|
||||
/* uip_input();*/
|
||||
#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();
|
||||
/* 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
|
||||
@ -41,7 +80,6 @@ pollhandler(void)
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
PROCESS_THREAD(tapdev_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
@ -61,3 +99,4 @@ PROCESS_THREAD(tapdev_process, ev, data)
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,3 +1,36 @@
|
||||
/*
|
||||
* 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 20:49:09 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TAPDEV_SERVICE_H__
|
||||
#define __TAPDEV_SERVICE_H__
|
||||
|
||||
|
@ -1,40 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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 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:29 adamdunkels Exp $
|
||||
* $Id: tapdev.c,v 1.2 2007/03/27 20:49:09 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -47,7 +46,6 @@
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#ifdef linux
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/if.h>
|
||||
@ -58,46 +56,20 @@
|
||||
#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;
|
||||
static struct timezone tz;
|
||||
|
||||
#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)
|
||||
@ -124,27 +96,51 @@ tapdev_init(void)
|
||||
|
||||
snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.2.1");
|
||||
system(buf);
|
||||
printf("%s\n", buf);
|
||||
printf("%s\n", buf);
|
||||
|
||||
lasttime = 0;
|
||||
|
||||
/* gdk_input_add(fd, GDK_INPUT_READ,
|
||||
read_callback, NULL);*/
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
do_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_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) {
|
||||
@ -159,20 +155,5 @@ do_send(void)
|
||||
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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -31,13 +31,14 @@
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: tapdev.h,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $
|
||||
*
|
||||
* $Id: tapdev.h,v 1.2 2007/03/27 20:49:09 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TAPDEV_H__
|
||||
#define __TAPDEV_H__
|
||||
|
||||
void tapdev_init(void);
|
||||
u16_t tapdev_poll(void);
|
||||
void tapdev_send(void);
|
||||
|
||||
u8_t tapdev_send(void);
|
||||
#endif /* __TAPDEV_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user