- Removed unnecessary PROCESS_POLLHANDLER(pollhandler()) as pollhandler is explicitly called.

- Moved all ARP handling to service wrappers (and narrowed interface to low level code).

- Unified general coding/formatting style.
This commit is contained in:
oliverschmidt 2007-03-27 20:41:10 +00:00
parent 52da435b27
commit 1ca96b614a
6 changed files with 55 additions and 92 deletions

View file

@ -28,28 +28,34 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: tapdev-service.c,v 1.2 2006/08/10 19:23:13 bg- Exp $ * @(#)$Id: tapdev-service.c,v 1.3 2007/03/27 20:41:10 oliverschmidt Exp $
*/ */
#include "contiki-net.h" #include "contiki-net.h"
#include "tapdev.h" #include "tapdev.h"
#include "net/uip-neighbor.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 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 }); static u8_t output(void);
SERVICE(tapdev_service, packet_service, { output });
PROCESS(tapdev_process, "TAP driver"); PROCESS(tapdev_process, "TAP driver");
/*---------------------------------------------------------------------------*/
static u8_t
output(void)
{
uip_arp_out();
tapdev_send();
return 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
pollhandler(void) pollhandler(void)
{ {
/* tapdev_service_request_poll();*/
process_poll(&tapdev_process); process_poll(&tapdev_process);
uip_len = tapdev_poll(); uip_len = tapdev_poll();
@ -61,13 +67,7 @@ pollhandler(void)
} else } else
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
if(BUF->type == htons(UIP_ETHTYPE_IP)) { if(BUF->type == htons(UIP_ETHTYPE_IP)) {
/* uip_arp_ipin();
uip_len -= sizeof(struct uip_eth_hdr);*/
/* uip_input();*/
tcpip_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)) { } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
uip_arp_arpin(); uip_arp_arpin();
/* If the above function invocation resulted in data that /* If the above function invocation resulted in data that
@ -80,11 +80,8 @@ pollhandler(void)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(tapdev_process, ev, data) PROCESS_THREAD(tapdev_process, ev, data)
{ {
PROCESS_POLLHANDLER(pollhandler());
PROCESS_BEGIN(); PROCESS_BEGIN();
tapdev_init(); tapdev_init();
@ -102,3 +99,4 @@ PROCESS_THREAD(tapdev_process, ev, data)
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/

View file

@ -28,8 +28,9 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: tapdev-service.h,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $ * @(#)$Id: tapdev-service.h,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $
*/ */
#ifndef __TAPDEV_SERVICE_H__ #ifndef __TAPDEV_SERVICE_H__
#define __TAPDEV_SERVICE_H__ #define __TAPDEV_SERVICE_H__

View file

@ -31,10 +31,9 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: tapdev.c,v 1.1 2006/06/17 22:41:30 adamdunkels Exp $ * $Id: tapdev.c,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $
*/ */
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -47,7 +46,6 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/socket.h> #include <sys/socket.h>
#ifdef linux #ifdef linux
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/if.h> #include <linux/if.h>
@ -57,9 +55,8 @@
#define DEVTAP "/dev/tap0" #define DEVTAP "/dev/tap0"
#endif /* linux */ #endif /* linux */
#include "tapdev.h"
#include "contiki-net.h" #include "contiki-net.h"
#include "tapdev.h"
#define DROP 0 #define DROP 0
@ -73,37 +70,6 @@ static unsigned long lasttime;
#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) #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 void
tapdev_init(void) tapdev_init(void)
@ -133,24 +99,48 @@ tapdev_init(void)
printf("%s\n", buf); printf("%s\n", buf);
lasttime = 0; lasttime = 0;
/* gdk_input_add(fd, GDK_INPUT_READ,
read_callback, NULL);*/
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void u16_t
do_send(void) 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; int ret;
if(fd <= 0) { if(fd <= 0) {
return; return;
} }
/* printf("tapdev_send: sending %d bytes\n", size);*/ /* printf("tapdev_send: sending %d bytes\n", size);*/
/* check_checksum(uip_buf, size);*/ /* check_checksum(uip_buf, size);*/
#if DROP #if DROP
drop++; drop++;
if(drop % 8 == 7) { if(drop % 8 == 7) {
@ -167,18 +157,3 @@ do_send(void)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
u8_t
tapdev_send(void)
{
uip_arp_out();
do_send();
return 0;
}
/*---------------------------------------------------------------------------*/
void
tapdev_do_send(void)
{
do_send();
}
/*---------------------------------------------------------------------------*/

View file

@ -31,16 +31,14 @@
* *
* This file is part of the uIP TCP/IP stack. * 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:41:10 oliverschmidt Exp $
*
*/ */
#ifndef __TAPDEV_H__ #ifndef __TAPDEV_H__
#define __TAPDEV_H__ #define __TAPDEV_H__
#include "contiki-net.h"
void tapdev_init(void); void tapdev_init(void);
u8_t tapdev_send(void);
u16_t tapdev_poll(void); u16_t tapdev_poll(void);
void tapdev_do_send(void); void tapdev_send(void);
#endif /* __TAPDEV_H__ */ #endif /* __TAPDEV_H__ */

View file

@ -28,9 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* Author: Oliver Schmidt <ol.sc@web.de> * @(#)$Id: wpcap-service.c,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $
*
* @(#)$Id: wpcap-service.c,v 1.1 2007/03/26 02:53:54 oliverschmidt Exp $
*/ */
#include "contiki-net.h" #include "contiki-net.h"
@ -70,9 +68,6 @@ pollhandler(void)
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
if(BUF->type == htons(UIP_ETHTYPE_IP)) { if(BUF->type == htons(UIP_ETHTYPE_IP)) {
tcpip_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)) { } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
uip_arp_arpin(); uip_arp_arpin();
/* If the above function invocation resulted in data that /* If the above function invocation resulted in data that
@ -87,8 +82,6 @@ pollhandler(void)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(wpcap_process, ev, data) PROCESS_THREAD(wpcap_process, ev, data)
{ {
PROCESS_POLLHANDLER(pollhandler());
PROCESS_BEGIN(); PROCESS_BEGIN();
wpcap_init(); wpcap_init();

View file

@ -28,9 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* Author: Oliver Schmidt <ol.sc@web.de> * $Id: wpcap-service.h,v 1.2 2007/03/27 20:41:10 oliverschmidt Exp $
*
* $Id: wpcap-service.h,v 1.1 2007/03/26 02:53:55 oliverschmidt Exp $
*/ */
#ifndef __WPCAP_SERVICE_H__ #ifndef __WPCAP_SERVICE_H__