Removed the src/arch tree from the lwip module. (Now in seperate contrib module).

This commit is contained in:
likewise 2003-01-29 13:18:40 +00:00
parent 663b79ca72
commit bcfdf4c1cf
76 changed files with 0 additions and 7385 deletions

View File

@ -1 +0,0 @@
The 6502 code is far from complete.

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif /* __CC_H__ */

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CPU_H__
#define __CPU_H__
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* __CPU_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __LIB_H__
#define __LIB_H__
int strlen(const char *str);
int strncmp(const char *str1, const char *str2, int len);
#endif /* __LIB_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_C64_H__
#define __SYS_C64_H__
#define SYS_MBOX_NULL 0
typedef int sys_sem_t;
typedef int sys_mbox_t;
typedef int sys_thread_t;
#endif /* __SYS_C64_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/* These are generic implementations of various library functions used
* throughout the lwIP code. When porting, those should be optimized
* for the particular processor architecture, preferably coded in
* assembler.
*/

View File

@ -1,120 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include <c64.h>
#include <time.h>
#include "lwip/sys.h"
#include "lwip/def.h"
struct sys_timeouts timeouts;
/*-----------------------------------------------------------------------------------*/
void
sys_arch_block(u16_t time)
{
u16_t ticks;
ticks = time * (CLK_TCK / 1000) + clock();
printf("ticks %d\n", ticks);
while(clock() != ticks);
}
/*-----------------------------------------------------------------------------------*/
sys_mbox_t
sys_mbox_new(void)
{
return SYS_MBOX_NULL;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_free(sys_mbox_t mbox)
{
return;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_post(sys_mbox_t mbox, void *data)
{
return;
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u16_t timeout)
{
sys_arch_block(timeout);
return 0;
}
/*-----------------------------------------------------------------------------------*/
sys_sem_t
sys_sem_new(u8_t count)
{
return 0;
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_sem_wait(sys_sem_t sem, u16_t timeout)
{
sys_arch_block(timeout);
return 0;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_signal(sys_sem_t sem)
{
return;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_free(sys_sem_t sem)
{
return;
}
/*-----------------------------------------------------------------------------------*/
void
sys_init(void)
{
timeouts.next = NULL;
return;
}
/*-----------------------------------------------------------------------------------*/
struct sys_timeouts *
sys_arch_timeouts(void)
{
return &timeouts;
}
/*-----------------------------------------------------------------------------------*/
void
sys_thread_new(void (* function)(void *arg), void *arg)
{
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,29 +0,0 @@
6502/ - Architectural files for the 6502 CPU.
c16x/ - Architectural files for the C16x/ST10 uC.
Supports lwIP Raw API only.
CS8900a Ethernet driver for 16-bit mode.
msvc6/ - Architectural files for Microsoft Visual C++ 6.0.
rtxc/ - Architectural files for the RTXC operating system.
unix/ - Architectural files for testing on unix-like systems
(assuming gcc and pthreads).
v2pro/ - Architectural files for the Xilinx Virtex-II PRO device with
embedded PowerPC 405 Processor. Supports lwIP Raw API only.
(requires V2PDK - http://www.xilinx.com/ise/vii_pro/kit.htm)
Each subdirectory (may) also include:
perf.c - Optional file that should be implemented when running
performance tests of lwIP.
sys.c - Implementation of the operating system emulation layer.
include/ - Architectural specific header files.
netif/ - Architectural specific network interfaces.

View File

@ -1,13 +0,0 @@
This directory contains architecture and compiler specific stuff for porting lwIP
to the C16x and ST10 microcontrollers. The compiler specifics are for Tasking EDE
v7.5r2.
The sequential API has not been ported; it's function are empties. If someone is
interested in adding a sequential API, please contact the author (see below).
Besides this, a Cirrus (formerly Crystal Semiconductors) CS8900a Ethernet driver
is included, which assumes a 16-bit data bus configuration. When porting this
driver, note that the CS8900a does not support interrupts in 8-bit mode.
Leon Woestenberg
<leon.woestenberg@axon.tv>

View File

@ -1,22 +0,0 @@
#ifndef __CC_H__
#define __CC_H__
/* memset(), memcpy() */
#include <string.h>
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef u32_t mem_ptr_t;
// LW: Supported in at least >=v7.5 r2, but lwIP worked without the "_packed" attribute already
#define PACK_STRUCT_BEGIN _packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif /* __CC_H__ */

View File

@ -1,6 +0,0 @@
#ifndef __CPU_H__
#define __CPU_H__
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* __CPU_H__ */

View File

@ -1,39 +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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: lib.h,v 1.2 2002/12/19 10:37:08 jani Exp $
*/
#ifndef __LIB_H__
#define __LIB_H__
#endif /* __LIB_H__ */

View File

@ -1,41 +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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: perf.h,v 1.1 2002/11/29 11:03:34 likewise Exp $
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@ -1,15 +0,0 @@
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#define SEMA int
#define QUEUE int
#define TASK int
#define SYS_MBOX_NULL (QUEUE)0
#define SYS_SEM_NULL (SEMA)0
typedef SEMA sys_sem_t;
typedef QUEUE sys_mbox_t;
typedef TASK sys_thread_t;
#endif /* __SYS_ARCH_H__ */

View File

@ -1,79 +0,0 @@
/*
* Copyright (c) 2001-2003 Leon Woestenberg <leon.woestenberg@axon.tv>
* Copyright (c) 2001-2003 Axon Digital Design B.V., The Netherlands.
* 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 lwIP TCP/IP stack.
*
* Author: Leon Woestenberg <leon.woestenberg@axon.tv>
*
* This is a device driver for the Crystal Semiconductor CS8900
* chip in combination with the lwIP stack.
*
* This is work under development. Please coordinate changes
* and requests with Leon Woestenberg <leon.woestenberg@axon.tv>
*
* The Swedish Institute of Computer Science and Adam Dunkels
* are specifically granted permission to redistribute this
* source code under any conditions they seem fit.
*
*/
#ifndef __NETIF_CS8900IF_H__
#define __NETIF_CS8900IF_H__
#include "lwip/netif.h"
/* interface statistics gathering
* such as collisions, dropped packets, missed packets
* 0 = no statistics, minimal memory requirements, no overhead
* 1 = statistics on, but some have large granularity (0x200), very low overhead
* 2 = statistics on, updated on every call to cs8900_service(), low overhead
*/
#define CS8900_STATS 2
struct cs8900if
{
//struct eth_addr *ethaddr;
u8_t needs_service;
u8_t use_polling;
#if (CS8900_STATS > 0)
u32_t interrupts; // #interrupt requests of cs8900
u32_t missed; // #packets on medium that could not enter cs8900a chip due to buffer shortage
u32_t dropped; // #packets dropped after they have been received in chip buffer
u32_t collisions; // #collisions on medium when transmitting packets
u32_t sentpackets; // #number of sent packets
u32_t sentbytes; // #number of sent bytes
#endif
/* Add whatever per-interface state that is needed here. */
};
void cs8900if_init(struct netif *);
void cs8900if_service(struct netif *);
void cs8900if_input(struct netif *netif);
err_t cs8900if_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);
void cs8900_send_debug(unsigned char *p, unsigned int len);
#endif /* __NETIF_CS8900IF_H__ */

View File

@ -1,73 +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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: lib.c,v 1.2 2002/12/19 10:37:07 jani Exp $
*/
/* These are generic implementations of various library functions used
* throughout the lwIP code. When porting, those should be optimized
* for the particular processor architecture, preferably coded in
* assembler.
*/
#include "lwip/arch.h"
#if BYTE_ORDER == LITTLE_ENDIAN
/*-----------------------------------------------------------------------------------*/
u16_t
htons(u16_t n)
{
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}
/*-----------------------------------------------------------------------------------*/
u16_t
ntohs(u16_t n)
{
return htons(n);
}
/*-----------------------------------------------------------------------------------*/
u32_t
htonl(u32_t n)
{
return ((n & 0xff) << 24) |
((n & 0xff00) << 8) |
((n & 0xff0000) >> 8) |
((n & 0xff000000) >> 24);
}
/*-----------------------------------------------------------------------------------*/
u32_t
ntohl(u32_t n)
{
return htonl(n);
}
/*-----------------------------------------------------------------------------------*/
#endif /* BYTE_ORDER == LITTLE_ENDIAN */

View File

@ -1,844 +0,0 @@
/** @file
/*
* Copyright (c) 2001, 2002 Leon Woestenberg <leon.woestenberg@axon.tv>
* Copyright (c) 2001, 2002 Axon Digital Design B.V., The Netherlands.
* 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 lwIP TCP/IP stack.
*
* Author: Leon Woestenberg <leon.woestenberg@axon.tv>
*
* This is a device driver for the Crystal Semiconductor CS8900
* chip in combination with the lwIP stack.
*
* This is work under development. Please coordinate changes
* and requests with Leon Woestenberg <leon.woestenberg@axon.tv>
*
* The Swedish Institute of Computer Science and Adam Dunkels
* are specifically granted permission to redistribute this
* source code under any conditions they seem fit.
*
* A quick function roadmap:
*
* cs8900_*() are low level, cs8900 hardware specific functions.
* These are declared static in the device driver source and
* SHOULD NOT need to be called from outside this source.
*
* cs8900if_*() are the lwIP network interface functions.
*
* cs8900_interrupt() is an early interrupt service routine (ISR).
* It merely sets a flag to indicate the cs8900 needs servicing.
* (This function MAY be tied to an interrupt vector, IF present).
*
* cs8900_service() is the actual interrupt event service routine.
* It must be called whenever the cs8900 needs servicing. It MAY
* be polled safely (so, you do NOT NEED interrupt support.)
*
* cs8900_init() sets up the cs8900, using its register set. When
* using the driver on your particular hardware platform, make sure
* the register setups match.
* Function is called from cs8900if_init().
*
* cs8900_input() transfers a received packet from the chip.
* Function is called from cs8900if_input().
*
* cs8900_output() transfers a packet to the chip for transmission.
* Function is called from cs8900if_output().
*
* cs8900if_init() initializes the lwIP network interface, and
* calls cs8900_init() to initialize the hardware.
* Function is called from lwIP.
*
* cs8900if_service() is the service routine, which must be called
* upon the need for service, or on a regular basis, in order to
* service the Ethernet chip.
*
* cs8900if_input() calls cs8900_input() to get a received packet
* and then forwards the packet to protocol(s) handler(s).
* Function is called from cs8900_service().
*
* cs8900if_output() resolves the hardware address, then
* calls cs8900_output() to transfer the packet.
* Function is called from lwIP.
*
* Future development:
*
* Split the generic Ethernet functionality (a lot of the
* cs8900if_*() functions) and the actual cs8900a dependencies.
*
* Enhance the interrupt handler to service the Ethernet
* chip (to decrease latency); support early packet
* inspection (during reception) to early drop unwanted
* packets, minimize chip buffer use and maximize throughput.
*
* Statistics gathering, currently under development.
* SNMP support, currently under development.
*
*/
#include "lwip/debug.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/sys.h"
#include "netif/etharp.h"
#if 0
// include some debugging help
# define DBG_LEVEL 1
# include "leds.h"
# include "display.h"
//# include "page.h"
# define LED_NEED_SERVICE LED_FP1
#else
// no debugging
# define leds_on()
# define leds_off()
#endif
#include "cs8900if.h"
#if LWIP_SNMP > 0
# include "snmp.h"
#endif
// Define those to better describe your network interface
#define IFNAME0 'e'
#define IFNAME1 'n'
static const struct eth_addr ethbroadcast = {{0xffU,0xffU,0xffU,0xffU,0xffU,0xffU}};
// Forward declarations
static err_t cs8900_output(struct netif *netif, struct pbuf *p);
static struct pbuf *cs8900_input(struct netif *netif);
static void cs8900_service(struct netif *netif);
static u32_t cs8900_chksum(void *dataptr, int len);
// Define these to match your hardware setup
#define MEM_BASE 0x00E000
#define IO_BASE 0x800
#define INT_NR 0x00
#define RXTXREG *((volatile u16_t *)(MEM_BASE + IO_BASE))
#define TXCMD *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x04))
#define TXLENGTH *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x06))
#define ISQ *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x08))
#define PACKETPP *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x0A))
#define PPDATA *((volatile u16_t *)(MEM_BASE + IO_BASE + 0x0C))
// CS8900 PacketPage register offsets
#define CS_PP_EISA 0x0000 // EISA Registration number of CS8900
#define CS_PP_PRODID 0x0002 // Product ID Number
#define CS_PP_IOBASE 0x0020 // I/O Base Address
#define CS_PP_INTNUM 0x0022 // Interrupt number (0,1,2, or 3)
#define CS_PP_RXCFG 0x0102 // Receiver Configuration
#define CS_PP_RXCTL 0x0104 // Receiver Control
#define CS_PP_TXCFG 0x0106 // Transmit Configuration
#define CS_PP_BUFCFG 0x010A // Buffer Configuration
#define CS_PP_LINECTL 0x0112 // Line Control Register offset
#define CS_PP_SELFCTL 0x0114 // Self Control
#define CS_PP_BUSCTL 0x0116 // Bus Control
#define CS_PP_TESTCTL 0x0118 // Test Control
#define CS_PP_ISQ 0x0120 // Interrupt status queue
#define CS_PP_RXEVENT 0x0124 // Receiver Event
#define CS_PP_TX_EVENT 0x0128 // Transmitter Event
#define CS_PP_BUF_EVENT 0x012C // Buffer Event
#define CS_PP_RXMISS 0x0130 // Receiver Miss Counter
#define CS_PP_TXCOL 0x0132 // Transmit Collision Counter
#define CS_PP_LINESTATUS 0x0134 // Line Status
#define CS_PP_SELFTEST 0x0136 // Self Status
#define CS_PP_BUSSTATUS 0x0138 // Bus Status
#define CS_PP_TXCMD 0x0144 // Transmit Command Request
#define CS_PP_TXLEN 0x0146 // Transmit Length
#define CS_PP_IA1 0x0158 // Individual Address (IA)
#define CS_PP_IA2 0x015A // Individual Address (IA)
#define CS_PP_IA3 0x015C // Individual Address (IA)
#define CS_PP_RXSTATUS 0x0400 // Receive Status
#define CS_PP_RXLEN 0x0402 // Receive Length
#define CS_PP_RXFRAME 0x0404 // Receive Frame Location
#define CS_PP_TXFRAME 0x0A00 // Transmit Frame Location
// removed interrupt from library
#if 0
// hardware interrupt vector handler
_interrupt(0x18) void cs8900_interrupt(void)
{
struct cs8900if *cs8900if = cs8900if_netif->state;
// network interface is configured?
if (cs8900if != NULL)
{
// chip needs service
cs8900if->needs_service = 1;
#if (CS8900_STATS > 0)
cs8900if->interrupts++;
#endif
}
#ifdef LED_NEED_SERVICE
leds_on(LED_NEED_SERVICE);
#endif
}
#endif
// cs8900_init()
//
// initializes the CS8900A chip
//
static void cs8900_init(struct netif *netif)
{
#ifdef LED_NEED_SERVICE
leds_off(LED_NEED_SERVICE);
#endif
// set RESET bit
PACKETPP = CS_PP_SELFCTL;
PPDATA = 0x0055U;
// { the RESET bit will be cleared by the cs8900a
// as a result of the reset }
// RESET bit cleared?
while((PPDATA & 0x0040U) != 0); // TODO: add timeout
// { after full initialization of the cs8900a
// the INITD bit will be set }
PACKETPP = CS_PP_SELFTEST;
// INITD bit still clear?
while ((PPDATA & 0x0080U) == 0); // TODO: add timeout
// { INITD bit is set }
// SIBUSY bit still set?
while ((PPDATA & 0x0100U) == 0x0100); // TODO: add timeout
// { SIBUSY bit clear }
#if 1
{
u16_t dummy;
// datasheet section 3.3.3
dummy = *(u16_t *)(MEM_BASE + IO_BASE + 0x0D);
// Dummy read, put chip in 16-bit mode
dummy = *(u16_t *)(MEM_BASE + IO_BASE + 0x0D);
}
#endif
// Set MAC address
PACKETPP = CS_PP_IA1;
PPDATA = (u16_t)(netif->hwaddr[0]) | (u16_t)(netif->hwaddr[1] << 8U);
PACKETPP = CS_PP_IA2;
PPDATA = (u16_t)(netif->hwaddr[2]) | (u16_t)(netif->hwaddr[3] << 8U);
PACKETPP = CS_PP_IA3;
PPDATA = (u16_t)(netif->hwaddr[4]) | (u16_t)(netif->hwaddr[5] << 8U);
// accept valid unicast or broadcast frames
PACKETPP = CS_PP_RXCTL;
PPDATA = (0x0005U | 0x0800U/*broadcast*/ | 0x0400U/*individual*/ | 0x0100U/*RxOK*/);
// enable receive interrupt
PACKETPP = CS_PP_RXCFG;
PPDATA = (0x0003U | 0x0100U/*RXIRQ*/);
// disable transmit interrupt (is default)
PACKETPP = CS_PP_TXCFG;
PPDATA = (0x0007U | 0);
// use interrupt number 0
PACKETPP = CS_PP_INTNUM;
PPDATA = (0x0000U);
// generate interrupt event on:
// - the RxMISS counter reaches 0x200, or
// - a received frame is lost
PACKETPP = CS_PP_BUFCFG;
PPDATA = (0x000bU |
#if (CS8900_STATS > 0) // interrupt before counter overflow
(0x2000U/*MissOvfloiE*/ | 0x1000U/*TxColOvfloiE*/) |
#endif
#if (CS8900_STATS > 1) // interrupt on counter increment
(0x0400U/*RxMissiE*/) |
#endif
0x0000);
// enable interrupt generation
PACKETPP = CS_PP_BUSCTL;
PPDATA = (0x0017U | 0x8000U/*EnableIRQ*/);
// enable:
// - receiver
// - transmitter
PACKETPP = CS_PP_LINECTL;
PPDATA = (0x0013U | 0x0080U/*SerTxOn*/ | 0x0040U/*SerRxOn*/);
}
static err_t cs8900_output(struct netif *netif, struct pbuf *p)
{
int tries = 0;
// exit if link has failed
PACKETPP = CS_PP_LINESTATUS;
if ((PPDATA & 0x0080U/*LinkOK*/) == 0) return ERR_CONN; // no Ethernet link
/* issue 'transmit' command to CS8900 */
TXCMD = 0x00C9U;
/* send length (in bytes) of packet to send */
TXLENGTH = p->tot_len;
PACKETPP = CS_PP_BUSSTATUS;
// not ready for transmission and still within 100 retries?
while(((PPDATA & 0x0100U/*Rdy4TxNOW*/) == 0) && (tries++ < 100))
{
// throw away the last committed received frame
PACKETPP = CS_PP_RXCFG;
PPDATA = (0x0003U | 0x0040U/*Skip_1*/ | 0x0100U/*RxOKiE*/);
PACKETPP = CS_PP_BUSSTATUS;
/* cs8900if->dropped++; // CHECK: we do not know if we actually will drop a frame here */
}
// ready to transmit?
if((PPDATA & 0x0100U/*Rdy4TxNOW*/) != 0)
{
// q traverses through linked list of pbuf's
struct pbuf *q;
for(q = p; q != NULL; q = q->next)
{
u16_t i;
u16_t *ptr = (u16_t *)q->payload;
// Send the data from the pbuf to the interface, one pbuf at a
// time. The size of the data in each pbuf is kept in the ->len
// variable.
for(i = 0; i < q->len; i += 2)
{
RXTXREG = *ptr++;
}
#if (CS8900_STATS > 0)
((struct cs8900if *)netif->state)->sentbytes += q->len;
#endif
#if LWIP_SNMP > 0
snmp_add_ifoutoctets(p->tot_len);
#endif
#if (CS8900_STATS > 0)
((struct cs8900if *)netif->state)->sentpackets++;
#endif
}
}
else
{
// { not ready to transmit!? }
#if LWIP_SNMP > 0
snmp_inc_ifoutdiscards();
#endif
}
return ERR_OK;
}
/**
* Move a received packet from the cs8900 into a new pbuf.
*
* Must be called after reading an ISQ event containing the
* "Receiver Event" register, before reading new ISQ events.
*
* This function copies a frame from the CS8900A.
* It is designed failsafe:
* - It does not assume a frame is actually present.
* - It checks for non-zero length
* - It does not overflow the frame buffer
*/
static struct pbuf *cs8900_input(struct netif *netif)
{
struct pbuf *p = NULL, *q = NULL;
u16_t len = 0;
u16_t event_type;
u16_t i;
u16_t *ptr = NULL;
// read RxStatus
event_type = RXTXREG;
// correctly received frame, either broadcast or individual address?
// TODO: maybe defer these conditions to cs8900_input()
if ((event_type & 0x0100U/*RxOK*/) && (event_type & 0x0c00U/*Broadcast | Individual*/))
{
#if LWIP_SNMP > 0
// update number of received MAC-unicast and non-MAC-unicast packets
if (event_type & 0x0400U/*Individual*/)
{
snmp_inc_ifinucastpkts();
}
else
{
snmp_inc_ifinnucastpkts();
}
#endif
event_type = 0;
// read RxLength
len = RXTXREG;
DEBUGF(NETIF_DEBUG, ("cs8900_input: packet len %u\n", len));
#if LWIP_SNMP > 0
snmp_add_ifinoctets(len);
#endif
// positive length?
if (len > 0)
{
// allocate a pbuf chain with total length 'len'
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != 0)
{
for (q = p; q != 0; q = q->next)
{
DEBUGF(NETIF_DEBUG, ("cs8900_input: pbuf @%p len %u\n", q, q->len));
ptr = q->payload;
// TODO: CHECK: what if q->len is odd? we don't use the last byte?
for (i = 0; i < (q->len + 1) / 2; i++)
{
*ptr = RXTXREG;
ptr++;
}
}
}
// could not allocate a pbuf
else
{
// skip received frame
// TODO: maybe do not skip the frame at this point in time?
PACKETPP = CS_PP_RXCFG;
PPDATA = (0x0003U | 0x0100U/*RxOKiE*/ | 0x0040U/*Skip_1*/);
#if (CS8900_STATS > 0)
((struct cs8900if *)netif->state)->dropped++;
#endif
#if LWIP_SNMP > 0
snmp_inc_ifindiscards();
#endif
len = 0;
}
}
// length was zero
else
{
}
}
return p;
}
/**
* To be called when the cs8900a needs service. Does
* not assume the cs8900a needs service. Does test the
* cs8900a whether it needs service.
*
* As such, may be used robustly called as a deferred
* (or "late") interrupt handler, or may be called in
* a loop to implement polling, or both.
*
* Use cs8900if_service() from your application instead
* of this function.
*/
static void cs8900_service(struct netif *netif)
{
// amount of ISQ's to handle (> 0) in one cs8900_service() call
unsigned char events2service = 1;
// NOTES:
// static, so only initialized to zero at program start.
// irq_status will always hold the last ISQ event register that
// still needs service. As such, we may leave this function if
// we encounter an event we cannot service yet, and return later
// to try to service it.
static u16_t irq_status = 0x0000U;
// The "cs8900_needs_service" flag indicates whether any events
// still need to be serviced.
// clear flag here.
// a receive interrupt can, *concurrently with this function*,
// set this flag on new ISQ event occurences.
// we will re-evaluate the correct setting of this flag at
// function exit (below).
((struct cs8900if *)netif->state)->needs_service = 0;
#ifdef LED_NEED_SERVICE
leds_off(LED_NEED_SERVICE);
#endif
// no unhandled irq_status left?
if (irq_status == 0x0000U)
{
// read ISQ register
irq_status = ISQ;
}
// ISQ interrupt event, and allowed to service in this loop?
while ((irq_status != 0x0000U) && (events2service-- > 0))
{
// investigate event
if ((irq_status & 0x003fU) == 0x0004U/*Receiver Event*/)
{
// correctly received frame, either broadcast or individual address
// TODO: think where these checks should appear: here or in cs8900_input()
if ((irq_status & 0x0100U/*RxOK*/) && (irq_status & 0x0c00U/*Broadcast | Individual*/))
{
// read the frame from the cs8900a
cs8900if_input(netif);
}
else
{
// skip this frame
PACKETPP = CS_PP_RXCFG;
PPDATA |= 0x0040U/*Skip_1*/;
#if (CS8900_STATS > 0)
((struct cs8900if *)netif->state)->dropped++;
#endif
}
}
#if (CS8900_STATS > 0)
else if ((irq_status & 0x003fU) == 0x0010U/*RxMISS Event*/)
{
((struct cs8900if *)netif->state)->missed += (irq_status >> 6);
}
else if ((irq_status & 0x003fU) == 0x0012U/*TxCOL Event*/)
{
((struct cs8900if *)netif->state)->collisions += (irq_status >> 6);
}
#endif
// read ISQ register
irq_status = ISQ;
}
// we did not deplete the ISQ?
if (irq_status != 0x0000U)
{
// the cs8900a still needs service
((struct cs8900if *)netif->state)->needs_service = 1;
#ifdef LED_NEED_SERVICE
leds_on(LED_NEED_SERVICE);
#endif
}
#if (CS8900_STATS > 1)
// read RxMiss Counter (zeroes itself upon read)
PACKETPP = CS_PP_RXMISS;
((struct cs8900if *)netif->state)->missed += (PPDATA >> 6);
// read RxCol Counter (zeroes itself upon read)
PACKETPP = CS_PP_TXCOL;
((struct cs8900if *)netif->state)->collisions += (PPDATA >> 6);
#endif
}
/**
* Service the CS8900.
*
* Can be called in a polling manner, or only after the CS8900 has raised
* an interrupt request.
*
* @param netif The lwIP network interface data structure belonging to this device.
*
*/
void cs8900if_service(struct netif *netif)
{
// is there a reason to call the service routine?
if ((((struct cs8900if *)netif->state)->needs_service) ||
(((struct cs8900if *)netif->state)->use_polling))
{
cs8900_service(netif);
}
}
/**
* Writing an IP packet (to be transmitted) to the CS8900.
*
* Before writing a frame to the CS8900, the ARP module is asked to resolve the
* Ethernet MAC address. The ARP module might undertake actions to resolve the
* address first, and queue this packet for later transmission.
*
* @param netif The lwIP network interface data structure belonging to this device.
* @param p pbuf to be transmitted (or the first pbuf of a chained list of pbufs).
* @param ipaddr destination IP address.
*
* @internal It uses the function cs8900_input() that should handle the actual
* reception of bytes from the network interface.
*
*/
err_t cs8900if_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
{
struct cs8900if *cs8900if = netif->state;
p = etharp_output(netif, ipaddr, p);
/* network hardware address obtained? */
if (p != NULL)
{
/* send out the packet */
cs8900_output(netif, p);
p = NULL;
}
// { p == NULL }
else
{
/* we cannot tell if the packet was sent, the packet could have been queued */
/* on an ARP entry that was already pending. */
}
return ERR_OK;
}
/**
* Read a received packet from the CS8900.
*
* This function should be called when a packet is received by the CS8900
* and is fully available to read. It moves the received packet to a pbuf
* which is forwarded to the IP network layer or ARP module. It transmits
* a resulting ARP reply or queued packet.
*
* @param netif The lwIP network interface to read from.
*
* @internal Uses cs8900_input() to move the packet from the CS8900 to a
* newly allocated pbuf.
*
*/
void cs8900if_input(struct netif *netif)
{
struct cs8900if *cs8900if = netif->state;
struct eth_hdr *ethhdr = NULL;
struct pbuf *p = NULL, *q = NULL;
/* move received packet into a new pbuf */
p = cs8900_input(netif);
/* no packet could be read */
if (p == NULL) {
/* silently ignore this */
return;
}
/* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload;
q = NULL;
switch(htons(ethhdr->type)) {
/* IP packet? */
case ETHTYPE_IP:
/* update ARP table, obtain first queued packet */
q = etharp_ip_input(netif, p);
/* skip Ethernet header */
pbuf_header(p, -14);
/* pass to network layer */
netif->input(p, netif);
break;
/* ARP packet? */
case ETHTYPE_ARP:
/* pass p to ARP module, get ARP reply or ARP queued packet */
q = etharp_arp_input(netif, (struct eth_addr *)&netif->hwaddr, p);
break;
/* unsupported Ethernet packet type */
default:
/* free pbuf */
pbuf_free(p);
p = NULL;
break;
}
/* send out the ARP reply or ARP queued packet */
if (q != NULL) {
/* q pbuf has been succesfully sent? */
if (cs8900_output(netif, q) == ERR_OK)
{
pbuf_free(q);
q = NULL;
}
else
{
/* TODO: re-queue packet in the ARP cache here (?) */
pbuf_free(q);
q = NULL;
}
}
}
/**
* Initialize the CS8900 Ethernet MAC/PHY device driver.
*
* @param netif The lwIP network interface data structure belonging to this device.
*
*/
void cs8900if_init(struct netif *netif)
{
struct cs8900if *cs8900if;
cs8900if = mem_malloc(sizeof(struct cs8900if));
if(cs8900if == NULL) return;
// initialize lwip network interface
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
netif->output = cs8900if_output;
netif->linkoutput = cs8900_output;
// initialize cs8900 specific interface structure
netif->state = cs8900if;
// initially assume no ISQ event
cs8900if->needs_service = 0;
// set to 1 if polling method is used
cs8900if->use_polling = 0;
#if (CS8900_STATS > 0)
// number of interrupt service routine calls
cs8900if->interrupts = 0;
cs8900if->missed = 0;
cs8900if->dropped = 0;
cs8900if->sentpackets = 0;
cs8900if->sentbytes = 0;
#endif
// intialize the cs8900a chip
cs8900_init(netif);
}
#if 1
/**
* Dump an array of bytes inside a UDP message's data field.
*
* It is a self-contained function, independent of higher protocol layers or other
* functions, so it allows you to debug these higher layers, such as lwIP.
*
* @param p pointer to an array of bytes, at least with length 'len'
* @param len number of bytes available at the address pointed to by 'p'
*/
void cs8900_send_debug(unsigned char *p, unsigned int len)
{
int tries = 0, i;
// network interface state
extern struct netif *ethif;
// exit if link has failed
PACKETPP = CS_PP_LINESTATUS;
if ((PPDATA & 0x0080U/*LinkOK*/) == 0) return; // TODO: find a correct error code
// transmit command
TXCMD = 0x00C9U;
// send at least 60 bytes
TXLENGTH = (14 + 20 + 8 + len < 60) ? 60 : (14 + 20 + 8 + len);
PACKETPP = CS_PP_BUSSTATUS;
// not ready for transmission and still within 100 retries?
while (((PPDATA & 0x0100U/*Rdy4TxNOW*/) == 0) && (tries++ < 100))
{
// throw away the last committed received frame
PACKETPP = CS_PP_RXCFG;
PPDATA = (0x0003U | 0x0040U/*Skip_1*/ | 0x0100U/*RxOKiE*/);
PACKETPP = CS_PP_BUSSTATUS;
/* cs8900if->dropped++; CHECK: we do not know if we actually will drop a frame here, do we? */
}
// ready to transmit?
if((PPDATA & 0x0100U/*Rdy4TxNOW*/) != 0)
{
u16_t data, checksum = 0;
u32_t udp_checksum = 0;
// destination Ethernet address
RXTXREG = 0xa000U;
RXTXREG = 0xc524U;
RXTXREG = 0x6d72U;
// source Ethernet address
RXTXREG = htons(((u16_t)ethif->hwaddr[0] << 8U) | (u16_t)ethif->hwaddr[1]);
RXTXREG = htons(((u16_t)ethif->hwaddr[2] << 8U) | (u16_t)ethif->hwaddr[3]);
RXTXREG = htons(((u16_t)ethif->hwaddr[4] << 8U) | (u16_t)ethif->hwaddr[5]);
// frame type
RXTXREG = htons(0x0800);
// TOS, version
RXTXREG = htons(data = ((0x40 | 0x05) << 8) | 0x00);
checksum += data;
// length
RXTXREG = htons(data = 20 + 8 + len);
checksum += data;
// identifier
RXTXREG = htons(data = 0);
checksum += data;
// fragment offset
RXTXREG = htons(data = 0);
checksum += data;
// TTL, UDP protocol
RXTXREG = htons(data = (255U << 8) | 17U);
checksum += data;
checksum += (htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16;
checksum += (htonl(ethif->ip_addr.addr) & 0x0000ffffU);
checksum += 0xc0a8U;
checksum += 0x0001U;
checksum += 6; // LW: kludge/hack: checksum calculation seems to be wrong somehow
// LW: this seems (?) to fix it
// checksum
RXTXREG = htons(~checksum);
// source IP
RXTXREG = htons((htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16);
// source IP
RXTXREG = htons( htonl(ethif->ip_addr.addr) & 0x0000ffffU);
// destination IP
RXTXREG = htons(0xc0a8U);
// destination IP
RXTXREG = htons(0x0001U);
// source port 3000
RXTXREG = htons(3000U);
// destination port 3000
RXTXREG = htons(3000U);
// UDP length
RXTXREG = htons(len);
// UDP checksum (not present)
udp_checksum = (htonl(ethif->ip_addr.addr) & 0xffff0000U) >> 16;
udp_checksum += (htonl(ethif->ip_addr.addr) & 0x0000ffffU);
udp_checksum += 0xc0a8U;
udp_checksum += 0x0001U;
udp_checksum += 0x0011U;
udp_checksum += (8 + len);
udp_checksum += 3000;
udp_checksum += 3000;
udp_checksum += (8 + len);
udp_checksum += cs8900_chksum(p, len);
while(udp_checksum >> 16) {
udp_checksum = (udp_checksum & 0xffffUL) + (udp_checksum >> 16);
}
RXTXREG = htons(~(udp_checksum & 0xffff));
// UDP data
for (i = 0; i < len; i += 2)
{
RXTXREG = htons((p[i] << 8) | p[i + 1]);
}
// pad to 60 bytes
while (i < 60)
{
RXTXREG = 0;
i += 2;
}
}
}
static u32_t cs8900_chksum(void *dataptr, int len)
{
u32_t acc = 0;
u16_t *ptr = (u16_t *)dataptr;
for(acc = 0; len > 1; len -= 2) {
acc += *ptr;
ptr++;
}
/* add up any odd byte */
if(len == 1) {
acc += htons((u16_t)((*(u8_t *)ptr) & 0xffU) << 8);
}
return acc;
}
#endif

View File

@ -1,42 +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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: perf.c,v 1.1 2002/11/29 11:03:34 likewise Exp $
*/
#include "arch/perf.h"
void
perf_init(char *fname)
{
if (fname); // LEON: prevent warning
}

View File

@ -1,137 +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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: sys_arch.c,v 1.1 2002/11/29 11:03:34 likewise Exp $
*/
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
//#include "timers.h"
static struct sys_timeouts timeouts;
/*-----------------------------------------------------------------------------------*/
sys_mbox_t
sys_mbox_new(void)
{
return SYS_MBOX_NULL;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_free(sys_mbox_t mbox)
{
if (mbox); // LEON: prevent warning
return;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_post(sys_mbox_t mbox, void *data)
{
if (mbox); // LEON: prevent warning
if (data); // LEON: prevent warning
return;
}
u16_t
sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u16_t timeout)
{
if (mbox); // LEON: prevent warning
if (msg); // LEON: prevent warning
if (timeout); // LEON: prevent warning
return 0;
}
/*-----------------------------------------------------------------------------------*/
sys_sem_t
sys_sem_new(u8_t count)
{
if (count);
return 0;
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_sem_wait(sys_sem_t sem, u16_t timeout)
{
if (sem);
return 0;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_signal(sys_sem_t sem)
{
if (sem);
return;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_free(sys_sem_t sem)
{
if (sem);
return;
}
void
sys_init(void)
{
timeouts.next = NULL;
return;
}
struct sys_timeouts *
sys_arch_timeouts(void)
{
return &timeouts;
}
u8_t
sys_timeout_u32_t(u32_t msecs, sys_timeout_handler h, void *data) // LEON: arg 1 was unsigned int
{
return 0;
// WAS: return timer_obtain(msecs, h, data);
// RE-ENABLE IF DHCP_TIMER_CALLBACKS
#if DHCP_TIMER_CALLBACKS
#error DHCP_TIMER_CALLBACKS not supported!
#endif
}
void
sys_thread_new(void (* function)(void *arg), void *arg)
{
if (arg); // LW
}
/*-----------------------------------------------------------------------------------*/
void
sys_main(void)
{
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1 +0,0 @@
#pragma pack(push,1)

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
/*typedef unsigned short u8_t;
typedef signed short s8_t; */
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef u32_t mem_ptr_t;
#define PACK_STRUCT_FIELD(x) x
#define PACK_STRUCT_STRUCT
#pragma warning(disable: 4103)
#endif /* __ARCH_CC_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CPU_H__
#define __ARCH_CPU_H__
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* BYTE_ORDER */
#endif /* __ARCH_CPU_H__ */

View File

@ -1 +0,0 @@
#pragma pack(pop)

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_INIT_H__
#define __ARCH_INIT_H__
#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg)
#endif /* __ARCH_INIT_H__ */

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_LIB_H__
#define __ARCH_LIB_H__
#ifndef _STRING_H_
#ifndef _STRING_H
int strlen(const char *str);
int strncmp(const char *str1, const char *str2, int len);
#endif /* _STRING_H */
#endif /* _STRING_H_ */
#endif /* __ARCH_LIB_H__ */

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_PERF_H__
#define __ARCH_PERF_H__
#ifdef PERF
#define PERF_START
#define PERF_STOP(x)
/*#define PERF_START do { \
struct tms __perf_start, __perf_end; \
times(&__perf_start)
#define PERF_STOP(x) times(&__perf_end); \
perf_print_times(&__perf_start, &__perf_end, x);\
} while(0)*/
#else /* PERF */
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* PERF */
void perf_print(unsigned long c1l, unsigned long c1h,
unsigned long c2l, unsigned long c2h,
char *key);
void perf_print_times(struct tms *start, struct tms *end, char *key);
void perf_init(char *fname);
#endif /* __ARCH_PERF_H__ */

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_SYS_ARCH_H__
#define __ARCH_SYS_ARCH_H__
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
struct sys_sem;
typedef struct sys_sem * sys_sem_t;
struct sys_mbox;
typedef struct sys_mbox *sys_mbox_t;
struct sys_thread;
typedef struct sys_thread * sys_thread_t;
#endif /* __ARCH_SYS_ARCH_H__ */

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#endif /* __CC_H__ */

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CPU_H__
#define __CPU_H__
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* __CPU_H__ */

View File

@ -1,44 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_INIT_H__
#define __ARCH_INIT_H__
#define TCPIP_INIT_DONE(arg) tcpip_init_done(arg)
void tcpip_init_done(void *);
int wait_for_tcpip_init(void);
#endif /* __ARCH_INIT_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __LIB_H__
#define __LIB_H__
#include <string.h>
#endif /* __LIB_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_RTXC_H__
#define __SYS_RTXC_H__
#include "rtxcapi.h"
#define SYS_MBOX_NULL (QUEUE)0
#define SYS_SEM_NULL (SEMA)0
typedef SEMA sys_sem_t;
typedef QUEUE sys_mbox_t;
typedef TASK sys_thread_t;
#endif /* __SYS_RTXC_H__ */

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __NETIF_CS8900IF_H__
#define __NETIF_CS8900IF_H__
#include "lwip/netif.h"
void cs8900if_init(struct netif *);
u8_t cs8900if_poll(struct netif *);
void cs8900if_input(struct netif *);
#endif /* __NETIF_CS8900IF_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __NETIF_SIOSLIPIF_H__
#define __NETIF_SIOSLIPIF_H__
#include "lwip/netif.h"
void sioslipif_init(struct netif *);
#endif /* __NETIF_SIOSLIPIF_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/* These are generic implementations of various library functions used
* throughout the lwIP code. When porting, those should be optimized
* for the particular processor architecture, preferably coded in
* assembler.
*/

View File

@ -1 +0,0 @@
sioslipif.c - Implementation of the SLIP protocol on top of a serial line.

View File

@ -1,170 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include "lwip/def.h"
#include "netif/sioslipif.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#define SLIP_END 0300
#define SLIP_ESC 0333
#define SLIP_ESC_END 0334
#define SLIP_ESC_ESC 0335
/* This variable is used for passing the netif pointer between the
threads. */
static struct netif *netif_pass;
static int infd, outfd;
/*-----------------------------------------------------------------------------------*/
static void
sio_send(u8_t c)
{
write(outfd, &c, 1);
}
/*-----------------------------------------------------------------------------------*/
static u8_t
sio_recv(void)
{
u8_t c;
read(infd, &c, 1);
return c;
}
/*-----------------------------------------------------------------------------------*/
static int
sioslipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
{
struct pbuf *q;
int i;
u8_t c;
/* Send pbuf out on the serial I/O device. */
sio_send(SLIP_END);
for(q = p; q != NULL; q = q->next) {
for(i = 0; i < q->len; i++) {
c = ((u8_t *)q->payload)[i];
switch(c) {
case SLIP_END:
sio_send(SLIP_ESC);
sio_send(SLIP_ESC_END);
break;
case SLIP_ESC:
sio_send(SLIP_ESC);
sio_send(SLIP_ESC_ESC);
break;
default:
sio_send(c);
break;
}
}
}
sio_send(SLIP_END);
return 0;
}
/*-----------------------------------------------------------------------------------*/
static struct pbuf *
sioslipif_input(void)
{
u8_t c;
struct pbuf *p, *q;
int recved;
int i;
p = pbuf_alloc(PBUF_LINK, PBUF_MAX_SIZE, PBUF_POOL);
q = p;
recved = i = 0;
while(1) {
c = sio_recv();
switch(c) {
case SLIP_END:
if(recved > 0) {
/* Received whole packet. */
pbuf_realloc(p, recved);
return p;
}
break;
case SLIP_ESC:
c = sio_recv();
switch(c) {
case SLIP_ESC_END:
c = SLIP_END;
break;
case SLIP_ESC_ESC:
c = SLIP_ESC;
break;
}
/* FALLTHROUGH */
default:
if(recved < p->tot_len && q != NULL) {
((u8_t *)q->payload)[i] = c;
recved++;
i++;
if(i >= q->len) {
i = 0;
q = q->next;
}
}
break;
}
}
}
/*-----------------------------------------------------------------------------------*/
static void
sioslipif_loop(void)
{
struct pbuf *p;
struct netif *netif;
netif = netif_pass;
while(1) {
p = sioslipif_input();
netif->input(p, netif);
}
}
/*-----------------------------------------------------------------------------------*/
void
sioslipif_init(struct netif *netif)
{
netif->state = NULL;
netif->name[0] = 's';
netif->name[1] = 'l';
netif->output = sioslipif_output;
netif_pass = netif;
sys_thread_new((void *)sioslipif_loop, NULL);
/* Do some magic to make it possible to receive data from the serial I/O device. */
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "arch/perf.h"
void
perf_init(char *fname)
{
}

View File

@ -1,271 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "rtxcapi.h"
#include "csema.h"
#include "cclock.h"
#include "cqueue.h"
#include "cres.h"
#include "cpart.h"
#include "ctask.h"
struct timeoutlist {
struct sys_timeouts timeouts;
TASK pid;
};
#define SYS_THREAD_MAX 2
static struct timeoutlist timeoutlist[SYS_THREAD_MAX];
static u16_t nextthread = 0;
/*-----------------------------------------------------------------------------------*/
sys_mbox_t
sys_mbox_new(void)
{
QUEUE mbox;
KS_dequeuew(IP_MBOXQ, &mbox);
KS_purgequeue(mbox);
return mbox;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_free(sys_mbox_t mbox)
{
KS_enqueue(IP_MBOXQ, &mbox);
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_post(sys_mbox_t mbox, void *data)
{
if(KS_enqueue(mbox, &data) != RC_GOOD) {
}
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u16_t timeout)
{
KSRC ret;
u16_t wtime = 1;
if(timeout == 0) {
DEBUGF(SYS_DEBUG, ("PID: %d sys_mbox_fetch: without timeouts\n",KS_inqtask()));
KS_dequeuew(mbox, data);
} else {
ret = KS_dequeuet(mbox, data, (TICKS)timeout/CLKTICK);
if(ret == RC_TIMEOUT) {
/* The call timed out, so we return 0. */
wtime = 0;
} else {
/* Calculate time we waited for the message to arrive. */
/* XXX: we cheat and just pretend that we waited for half the timeout value! */
wtime = timeout / 2;
/* Make sure we don't return 0 here. */
if(wtime == 0) {
wtime = 1;
}
}
}
return wtime;
}
/*-----------------------------------------------------------------------------------*/
sys_sem_t
sys_sem_new(u8_t count)
{
SEMA sem;
KS_dequeuew(IP_SEMQ, &sem);
KS_pend(sem);
if(count > 0) {
KS_signal(sem);
}
return sem;
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_sem_wait(sys_sem_t sem, u16_t timeout)
{
KSRC ret;
u16_t wtime = 1;
if(timeout == 0) {
DEBUGF(SYS_DEBUG, ("PID: %d sys_mbox_fetch: without timeouts\n",KS_inqtask()));
KS_wait(sem);
} else {
ret = KS_waitt(sem, (TICKS)timeout/CLKTICK);
if(ret == RC_TIMEOUT) {
/* The call timed out, so we return 0. */
wtime = 0;
} else {
/* Calculate time we waited for the message to arrive. */
/* XXX: we cheat and just pretend that we waited for half the timeout value! */
wtime = timeout / 2;
/* Make sure we don't return 0 here. */
if(wtime == 0) {
wtime = 1;
}
}
}
return wtime;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_signal(sys_sem_t sem)
{
KS_signal(sem);
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_free(sys_sem_t sem)
{
KS_enqueue(IP_SEMQ, &sem);
}
/*-----------------------------------------------------------------------------------*/
void
sys_init(void)
{
/* posta in alla semaforer i IP_SEMQ, posta in alla mboxar i
IP_MBOXQ */
QUEUE mbox;
SEMA sem;
mbox = IP_Q_01; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_02; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_03; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_04; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_05; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_06; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_07; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_08; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_09; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_10; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_11; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_12; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_13; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_14; KS_enqueue(IP_MBOXQ, &mbox);
mbox = IP_Q_15; KS_enqueue(IP_MBOXQ, &mbox);
sem = IP_S_01; KS_enqueue(IP_SEMQ, &sem);
sem = IP_S_02; KS_enqueue(IP_SEMQ, &sem);
sem = IP_S_03; KS_enqueue(IP_SEMQ, &sem);
}
/*-----------------------------------------------------------------------------------*/
struct sys_timeouts *
sys_arch_timeouts(void)
{
int i;
TASK pid;
struct timeoutlist *tl;
DEBUGF(SYS_DEBUG, ("PID: %d sys_mbox_fetch: timeoutlist not empty\n",KS_inqtask()));
pid = KS_inqtask();
for(i = 0; i < nextthread; i++) {
tl = &timeoutlist[i];
if(tl->pid == pid) {
DEBUGF(SYS_DEBUG, ("PID: %d sys_mbox_fetch: corresponding pid found!\n",KS_inqtask()));
return &(tl->timeouts);
}
}
/* Error! */
return NULL;
}
/*-----------------------------------------------------------------------------------*/
struct sys_thread_arg {
void (* thread)(void *);
void *threadarg;
SEMA sem;
};
/*-----------------------------------------------------------------------------------*/
static void
sys_thread(void)
{
struct sys_thread_arg *arg;
void (* thread)(void *);
void *threadarg;
arg = KS_inqtask_arg(0);
if(arg != NULL) {
timeoutlist[nextthread].timeouts.next = NULL;
timeoutlist[nextthread].pid = KS_inqtask();
++nextthread;
thread = arg->thread;
threadarg = arg->threadarg;
KS_signal(arg->sem);
thread(threadarg);
}
KS_terminate(0);
}
/*-----------------------------------------------------------------------------------*/
void
sys_thread_new(void (* function)(void *arg), void *arg)
{
TASK newtask;
PRIORITY pri = 2; /* This may have to be changed. */
char *stack;
int stacksize = 512; /* This may have to be changed. */
struct sys_thread_arg threadarg;
newtask = KS_alloc_task();
stack = KS_allocw(MAP512);
KS_deftask(newtask, pri, (char ks_stk *)stack, (size_t)stacksize, (void (*)(void))sys_thread);
threadarg.thread = function;
threadarg.threadarg = arg;
threadarg.sem = THRDSYNC;
KS_deftask_arg(newtask, &threadarg);
KS_execute(newtask);
KS_wait(THRDSYNC);
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
/*typedef unsigned short u8_t;
typedef signed short s8_t; */
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef u32_t mem_ptr_t;
#define PACK_STRUCT_FIELD(x) x __attribute__((packed))
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
#endif /* __ARCH_CC_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CPU_H__
#define __ARCH_CPU_H__
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* BYTE_ORDER */
#endif /* __ARCH_CPU_H__ */

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_INIT_H__
#define __ARCH_INIT_H__
#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg)
#endif /* __ARCH_INIT_H__ */

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_LIB_H__
#define __ARCH_LIB_H__
#include <string.h>
#ifndef _STRING_H_
#ifndef _STRING_H
int strlen(const char *str);
int strncmp(const char *str1, const char *str2, int len);
#endif /* _STRING_H */
#endif /* _STRING_H_ */
#endif /* __ARCH_LIB_H__ */

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_PERF_H__
#define __ARCH_PERF_H__
#include <sys/times.h>
#ifdef PERF
#define PERF_START { \
unsigned long __c1l, __c1h, __c2l, __c2h; \
__asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h))
#define PERF_STOP(x) __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \
perf_print(__c1l, __c1h, __c2l, __c2h, x);}
/*#define PERF_START do { \
struct tms __perf_start, __perf_end; \
times(&__perf_start)
#define PERF_STOP(x) times(&__perf_end); \
perf_print_times(&__perf_start, &__perf_end, x);\
} while(0)*/
#else /* PERF */
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* PERF */
void perf_print(unsigned long c1l, unsigned long c1h,
unsigned long c2l, unsigned long c2h,
char *key);
void perf_print_times(struct tms *start, struct tms *end, char *key);
void perf_init(char *fname);
#endif /* __ARCH_PERF_H__ */

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_SYS_ARCH_H__
#define __ARCH_SYS_ARCH_H__
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
struct sys_sem;
typedef struct sys_sem * sys_sem_t;
struct sys_mbox;
typedef struct sys_mbox *sys_mbox_t;
struct sys_thread;
typedef struct sys_thread * sys_thread_t;
#endif /* __ARCH_SYS_ARCH_H__ */

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __DELIF_H__
#define __DELIF_H__
#include "lwip/netif.h"
#include "lwip/pbuf.h"
void delif_init(struct netif *netif);
void delif_init_thread(struct netif *netif);
#endif /* __DELIF_H__ */

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __DROPIF_H__
#define __DROPIF_H__
#include "lwip/netif.h"
#include "lwip/pbuf.h"
void dropif_init(struct netif *netif);
#endif /* __DROPIF_H__ */

View File

@ -1,54 +0,0 @@
#ifndef FIFO_H
#define FIFO_H
#include "lwip/sys.h"
/** How many bytes in fifo */
#define FIFOSIZE 2048
/** fifo data structure, this one is passed to all fifo functions */
typedef struct fifo_t {
u8_t data[FIFOSIZE+10]; /// data segment, +10 is a hack probably not needed.. FIXME!
int dataslot; /// index to next char to be read
int emptyslot; /// index to next empty slot
int len; /// len probably not needed, may be calculated from dataslot and emptyslot in conjunction with FIFOSIZE
sys_sem_t sem; /// semaphore protecting simultaneous data manipulation
sys_sem_t getSem; /// sepaphore used to signal new data if getWaiting is set
u8_t getWaiting; /// flag used to indicate that fifoget is waiting for data. fifoput is suposed to clear
/// this flag prior to signaling the getSem semaphore
} fifo_t;
/**
* Get a character from fifo
* Blocking call.
* @param pointer to fifo data structure
* @return character read from fifo
*/
u8_t fifoGet(fifo_t * fifo);
/**
* Get a character from fifo
* Non blocking call.
* @param pointer to fifo data structure
* @return character read from fifo, or < zero if non was available
*/
s16_t fifoGetNonBlock(fifo_t * fifo);
/**
* fifoput is called by the signalhandler when new data has arrived (or some other event is indicated)
* fifoput reads directly from the serialport and is thus highly dependent on unix arch at this moment
* @param fifo pointer to fifo data structure
* @param fd unix file descriptor
*/
void fifoPut(fifo_t * fifo, int fd);
/**
* fifoinit initiate fifo
* @param fifo pointer to fifo data structure, allocated by the user
*/
void fifoInit(fifo_t * fifo);
#endif

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PCAPIF_H__
#define __PCAPIF_H__
#include "lwip/netif.h"
void pcapif_init(struct netif *netif);
#endif /* __PCAPIF_H__ */

View File

@ -1,82 +0,0 @@
#ifndef SIO_H
#define SIO_H
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "netif/fifo.h"
//#include "netif/pppif.h"
/* BAUDRATE is defined in sio.c as it is implementation specific */
typedef struct sio_status_t {
int fd;
fifo_t myfifo;
} sio_status_t;
/** Baudrates */
typedef enum sioBaudrates {
SIO_BAUD_9600,
SIO_BAUD_19200,
SIO_BAUD_38400,
SIO_BAUD_57600,
SIO_BAUD_115200
} sioBaudrates;
/**
* Read a char from incoming data stream, this call blocks until data has arrived
* @param siostat siostatus struct, contains sio instance data, given by sio_open
* @return char read from input stream
*/
u8_t sio_recv( sio_status_t * siostat );
/**
* Poll for a new character from incoming data stream
* @param siostat siostatus struct, contains sio instance data, given by sio_open
* @return char read from input stream, or < 0 if no char was available
*/
s16_t sio_poll(sio_status_t * siostat);
/**
* Parse incoming characters until a string str is recieved, blocking call
* @param str zero terminated string to expect
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_expect_string(u8_t *str, sio_status_t * siostat);
/**
* Write a char to output data stream
* @param c char to write to output stream
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_send( u8_t c, sio_status_t * siostat );
/**
* Write a char to output data stream
* @param str pointer to a zero terminated string
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_send_string(u8_t *str, sio_status_t * siostat);
/**
* Flush outbuffer (send everything in buffer now), useful if some layer below is
* holding on to data, waitng to fill a buffer
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_flush( sio_status_t * siostat );
/**
* Open serial port entry point from serial protocol (slipif, pppif)
* @param devnum the device number to use, i.e. ttySx, comx:, etc. there x = devnum
* @return siostatus struct, contains sio instance data, use when calling sio functions
*/
sio_status_t * sio_open( int devnum );
/**
* Change baudrate of port, may close and reopen port
* @param baud new baudrate
* @param siostat siostatus struct, contains sio instance data, given by sio_open
*/
void sio_change_baud( sioBaudrates baud, sio_status_t * siostat );
#endif

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __TAPIF_H__
#define __TAPIF_H__
#include "lwip/netif.h"
void tapif_init(struct netif *netif);
#endif /* __TAPIF_H__ */

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __NETIF_TCPDUMP_H__
#define __NETIF_TCPDUMP_H__
#include "lwip/pbuf.h"
void tcpdump_init(void);
void tcpdump(struct pbuf *p);
#endif /* __NETIF_TCPDUMP_H__ */

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __TUNIF_H__
#define __TUNIF_H__
#include "lwip/netif.h"
#include "lwip/pbuf.h"
void tunif_init(struct netif *netif);
void tunif_init_thread(struct netif *netif);
#endif /* __TUNIF_H__ */

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __UNIXIF_H__
#define __UNIXIF_H__
#include "lwip/netif.h"
void unixif_init_server(struct netif *netif);
void unixif_init_client(struct netif *netif);
#endif /* __UNIXIF_H__ */

View File

@ -1,73 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include "lwip/arch.h"
#include "lwip/def.h"
#include "lwip/inet.h"
/*-----------------------------------------------------------------------------------*/
/* lwip_chksum:
*
* Sums up all 16 bit words in a memory portion. Also includes any odd byte.
* This function is used by the other checksum functions.
*
*/
/*-----------------------------------------------------------------------------------*/
#if 0
u16_t
lwip_chksum(void *dataptr, int len)
{
u32_t acc;
for(acc = 0; len > 1; len -= 2) {
acc += *((u16_t *)dataptr)++;
}
/* add up any odd byte */
if(len == 1) {
acc += htons((u16_t)((*(u8_t *)dataptr) & 0xff) << 8);
DEBUGF(INET_DEBUG, ("inet: chksum: odd byte %d\n", *(u8_t *)dataptr));
}
acc = (acc >> 16) + (acc & 0xffffUL);
if(acc & 0xffff0000 != 0) {
acc = (acc >> 16) + (acc & 0xffffUL);
}
return (u16_t)acc;
}
/*-----------------------------------------------------------------------------------*/
#endif

View File

@ -1,310 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include <stdlib.h>
#include "lwip/def.h"
#include "netif/delif.h"
#ifdef linux
#include "netif/tapif.h"
#else /* linux */
#include "netif/tunif.h"
#endif /* linux */
#include "lwip/sys.h"
#define DELIF_INPUT_DROPRATE 0.1
#define DELIF_OUTPUT_DROPRATE 0.1
#define DELIF_INPUT_DELAY 500 /* Miliseconds. */
#define DELIF_OUTPUT_DELAY 500 /* Miliseconds. */
#define DELIF_TIMEOUT 10
struct delif {
err_t (* input)(struct pbuf *p, struct netif *inp);
struct netif *netif;
};
struct delif_pbuf {
struct delif_pbuf *next;
struct pbuf *p;
struct ip_addr *ipaddr;
unsigned int time;
};
static struct delif_pbuf *input_list = NULL;
static struct delif_pbuf *output_list = NULL;
/*-----------------------------------------------------------------------------------*/
static void
delif_input_timeout(void *arg)
{
struct netif *netif;
struct delif *delif;
struct delif_pbuf *dp;
unsigned int timeout, now;
timeout = DELIF_TIMEOUT;
netif = arg;
delif = netif->state;
/* Check if there is anything on the input list. */
dp = input_list;
while(dp != NULL) {
now = sys_now();
if(dp->time <= now) {
delif->input(dp->p, netif);
if(dp->next != NULL) {
if(dp->next->time > now) {
timeout = dp->next->time - now;
} else {
timeout = 0;
}
DEBUGF(DELIF_DEBUG, ("delif_output_timeout: timeout %u.\n", timeout));
}
input_list = dp->next;
free(dp);
dp = input_list;
} else {
dp = dp->next;
}
}
sys_timeout(timeout, delif_input_timeout, arg);
}
/*-----------------------------------------------------------------------------------*/
static void
delif_output_timeout(void *arg)
{
struct netif *netif;
struct delif *delif;
struct delif_pbuf *dp;
unsigned int timeout, now;
timeout = DELIF_TIMEOUT;
netif = arg;
delif = netif->state;
/* Check if there is anything on the output list. */
dp = output_list;
while(dp != NULL) {
now = sys_now();
if(dp->time <= now) {
DEBUGF(DELIF_DEBUG, ("delif_output_timeout: now %u dp->time %u\n",
now, dp->time));
delif->netif->output(delif->netif, dp->p, dp->ipaddr);
if(dp->next != NULL) {
if(dp->next->time > now) {
timeout = dp->next->time - now;
} else {
timeout = 0;
}
DEBUGF(DELIF_DEBUG, ("delif_output_timeout: timeout %u.\n", timeout));
}
pbuf_free(dp->p);
output_list = dp->next;
free(dp);
dp = output_list;
} else {
dp = dp->next;
}
}
sys_timeout(timeout, delif_output_timeout, arg);
}
/*-----------------------------------------------------------------------------------*/
static err_t
delif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
{
struct delif_pbuf *dp, *np;
struct pbuf *q;
int i, j;
char *data;
DEBUGF(DELIF_DEBUG, ("delif_output\n"));
#ifdef DELIF_OUTPUT_DROPRATE
if(((double)rand()/(double)RAND_MAX) < DELIF_OUTPUT_DROPRATE) {
DEBUGF(DELIF_DEBUG, ("delif_output: Packet dropped\n"));
return 0;
}
#endif /* DELIF_OUTPUT_DROPRATE */
DEBUGF(DELIF_DEBUG, ("delif_output\n"));
dp = malloc(sizeof(struct delif_pbuf));
data = malloc(p->tot_len);
i = 0;
for(q = p; q != NULL; q = q->next) {
for(j = 0; j < q->len; j++) {
data[i] = ((char *)q->payload)[j];
i++;
}
}
dp->p = pbuf_alloc(PBUF_LINK, 0, PBUF_ROM);
dp->p->payload = data;
dp->p->len = p->tot_len;
dp->p->tot_len = p->tot_len;
dp->ipaddr = ipaddr;
dp->time = sys_now() + DELIF_OUTPUT_DELAY;
dp->next = NULL;
if(output_list == NULL) {
output_list = dp;
} else {
for(np = output_list; np->next != NULL; np = np->next);
np->next = dp;
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
static err_t
delif_input(struct pbuf *p, struct netif *inp)
{
struct delif_pbuf *dp, *np;
DEBUGF(DELIF_DEBUG, ("delif_input\n"));
#ifdef DELIF_INPUT_DROPRATE
if(((double)rand()/(double)RAND_MAX) < DELIF_INPUT_DROPRATE) {
DEBUGF(DELIF_DEBUG, ("delif_input: Packet dropped\n"));
pbuf_free(p);
return ERR_OK;
}
#endif /* DELIF_INPUT_DROPRATE */
dp = malloc(sizeof(struct delif_pbuf));
dp->p = p;
dp->time = sys_now() + DELIF_INPUT_DELAY;
dp->next = NULL;
if(input_list == NULL) {
input_list = dp;
} else {
for(np = input_list; np->next != NULL; np = np->next);
np->next = dp;
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
void
delif_init(struct netif *netif)
{
struct delif *del;
del = malloc(sizeof(struct delif));
netif->state = del;
netif->name[0] = 'd';
netif->name[1] = 'e';
netif->output = delif_output;
del->netif = malloc(sizeof(struct netif));
#ifdef linux
/* tapif_init(del->netif);*/
tunif_init(del->netif);
#else /* linux */
tunif_init(del->netif);
#endif /* linux */
del->input = netif->input;
del->netif->input = delif_input;
sys_timeout(DELIF_TIMEOUT, delif_input_timeout, netif);
sys_timeout(DELIF_TIMEOUT, delif_output_timeout, netif);
}
/*-----------------------------------------------------------------------------------*/
static void
delif_thread(void *arg)
{
struct netif *netif = arg;
struct delif *del;
sys_sem_t sem;
del = netif->state;
#ifdef linux
tapif_init(del->netif);
#else /* linux */
tunif_init(del->netif);
#endif /* linux */
sys_timeout(DELIF_TIMEOUT, delif_input_timeout, netif);
sys_timeout(DELIF_TIMEOUT, delif_output_timeout, netif);
sem = sys_sem_new(0);
sys_sem_wait(sem);
}
/*-----------------------------------------------------------------------------------*/
void
delif_init_thread(struct netif *netif)
{
struct delif *del;
DEBUGF(DELIF_DEBUG, ("delif_init_thread\n"));
del = malloc(sizeof(struct delif));
netif->state = del;
netif->name[0] = 'd';
netif->name[1] = 'e';
netif->output = delif_output;
del->netif = malloc(sizeof(struct netif));
del->netif->ip_addr = netif->ip_addr;
del->netif->gw = netif->gw;
del->netif->netmask = netif->netmask;
del->input = netif->input;
del->netif->input = delif_input;
sys_thread_new(delif_thread, netif);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,131 +0,0 @@
/* Author: Magnus Ivarsson <magnus.ivarsson@volvo.com> */
/* ---------------------------------------------- */
/* --- fifo 4 unix ------------------------------ */
/* ---------------------------------------------- */
#include "netif/fifo.h"
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/arch.h"
#include <unistd.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
u8_t fifoGet(fifo_t * fifo)
{
u8_t c;
sys_sem_wait(fifo->sem); // enter critical section
if (fifo->dataslot == fifo->emptyslot)
{
fifo->getWaiting = TRUE; // tell putFifo to signal us when data is available
sys_sem_signal(fifo->sem); // leave critical section (allow input from serial port..)
sys_sem_wait(fifo->getSem); // wait 4 data
sys_sem_wait(fifo->sem); // reenter critical section
}
c = fifo->data[fifo->dataslot++];
fifo->len--;
if (fifo->dataslot == FIFOSIZE)
{
fifo->dataslot = 0;
}
sys_sem_signal(fifo->sem); // leave critical section
return c;
}
s16_t fifoGetNonBlock(fifo_t * fifo)
{
u16_t c;
sys_sem_wait(fifo->sem); // enter critical section
if (fifo->dataslot == fifo->emptyslot)
{
// empty fifo
c = -1;
}
else
{
c = fifo->data[fifo->dataslot++];
fifo->len--;
if (fifo->dataslot == FIFOSIZE)
{
fifo->dataslot = 0;
}
}
sys_sem_signal(fifo->sem); // leave critical section
return c;
}
void fifoPut(fifo_t * fifo, int fd)
{
/* FIXME: mutex around struct data.. */
int cnt=0;
sys_sem_wait( fifo->sem ); // enter critical
DEBUGF( SIO_FIFO_DEBUG,("fifoput: len%d dat%d empt%d --> ", fifo->len, fifo->dataslot, fifo->emptyslot ) );
if ( fifo->emptyslot < fifo->dataslot )
{
cnt = read( fd, &fifo->data[fifo->emptyslot], fifo->dataslot - fifo->emptyslot );
}
else
{
cnt = read( fd, &fifo->data[fifo->emptyslot], FIFOSIZE-fifo->emptyslot );
}
fifo->emptyslot += cnt;
fifo->len += cnt;
DEBUGF( SIO_FIFO_DEBUG,("len%d dat%d empt%d\n", fifo->len, fifo->dataslot, fifo->emptyslot ) );
if ( fifo->len > FIFOSIZE )
{
printf( "ERROR: fifo overrun detected len=%d, flushing\n", fifo->len );
fifo->dataslot = 0;
fifo->emptyslot = 0;
fifo->len = 0;
}
if ( fifo->emptyslot == FIFOSIZE )
{
fifo->emptyslot = 0;
DEBUGF( SIO_FIFO_DEBUG, ("(WRAP) ") );
sys_sem_signal( fifo->sem ); // leave critical
fifoPut( fifo, fd );
return;
}
if ( fifo->getWaiting )
{
fifo->getWaiting = FALSE;
sys_sem_signal( fifo->getSem );
}
sys_sem_signal( fifo->sem ); // leave critical
return;
}
void fifoInit(fifo_t * fifo)
{
fifo->dataslot = 0;
fifo->emptyslot = 0;
fifo->len = 0;
fifo->sem = sys_sem_new(1); // critical section 1=free to enter
fifo->getSem = sys_sem_new(0); // 0 = no one waiting
fifo->getWaiting = FALSE;
}

View File

@ -1,162 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/list.h"
#include <stdlib.h>
struct list {
struct elem *first, *last;
int size, elems;
};
struct elem {
struct elem *next;
void *data;
};
/*-----------------------------------------------------------------------------------*/
struct list *
list_new(int size)
{
struct list *list;
list = malloc(sizeof(struct list));
list->first = list->last = NULL;
list->size = size;
list->elems = 0;
return list;
}
/*-----------------------------------------------------------------------------------*/
int
list_push(struct list *list, void *data)
{
struct elem *elem;
if(list->elems < list->size) {
elem = malloc(sizeof(struct elem));
elem->data = data;
elem->next = NULL;
if(list->last != NULL) {
list->last->next = elem;
}
list->last = elem;
if(list->first == NULL) {
list->first = elem;
}
list->elems++;
return 1;
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
void *
list_pop(struct list *list)
{
struct elem *elem;
void *data;
if(list->elems > 0) {
elem = list->first;
if(elem == list->last) {
list->last = elem->next;
}
list->first = elem->next;
list->elems--;
data = elem->data;
free(elem);
return data;
}
return NULL;
}
/*-----------------------------------------------------------------------------------*/
void *
list_first(struct list *list)
{
return list->first;
}
/*-----------------------------------------------------------------------------------*/
int
list_elems(struct list *list)
{
return list->elems;
}
/*-----------------------------------------------------------------------------------*/
void
list_delete(struct list *list)
{
while(list_pop(list) != NULL);
free(list);
}
/*-----------------------------------------------------------------------------------*/
int
list_remove(struct list *list, void *elem)
{
struct elem *e, *p;
p = NULL;
for(e = list->first; e != NULL; e = e->next) {
if(e->data == elem) {
if(p != NULL) {
p->next = e->next;
} else {
list->first = e->next;
}
if(list->last == e) {
list->last = p;
if(p != NULL) {
p->next = NULL;
}
}
free(e);
list->elems--;
return 1;
}
p = e;
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
void
list_map(struct list *list, void (* func)(void *arg))
{
struct elem *e;
for(e = list->first; e != NULL; e = e->next) {
func(e->data);
}
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,214 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef linux /* Apparently, this doesn't work under Linux. */
#include "lwip/debug.h"
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pcap.h>
#include "netif/etharp.h"
#include "lwip/stats.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "netif/unixif.h"
#include "lwip/sys.h"
#include "lwip/ip.h"
#include "lwip/list.h"
#include "netif/tcpdump.h"
struct pcapif {
pcap_t *pd;
sys_sem_t sem;
u8_t pkt[2048];
u32_t len;
u32_t lasttime;
struct pbuf *p;
struct eth_addr *ethaddr;
};
static char errbuf[PCAP_ERRBUF_SIZE];
/*-----------------------------------------------------------------------------------*/
static err_t
pcapif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr)
{
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
static void
timeout(void *arg)
{
struct netif *netif;
struct pcapif *pcapif;
struct pbuf *p, *q;
u8_t *bufptr;
struct eth_hdr *ethhdr;
netif = (struct netif *)arg;
pcapif = netif->state;
ethhdr = (struct eth_hdr *)pcapif->pkt;
if(htons(ethhdr->type) != ETHTYPE_IP ||
ip_lookup(pcapif->pkt + 14, netif)) {
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_LINK, pcapif->len, PBUF_POOL);
if(p != NULL) {
/* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */
bufptr = (u_char *)pcapif->pkt;
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
available data in the pbuf is given by the q->len
variable. */
/* read data into(q->payload, q->len); */
bcopy(bufptr, q->payload, q->len);
bufptr += q->len;
}
ethhdr = p->payload;
switch(htons(ethhdr->type)) {
case ETHTYPE_IP:
arp_ip_input(netif, p);
pbuf_header(p, -14);
netif->input(p, netif);
break;
case ETHTYPE_ARP:
p = arp_arp_input(netif, pcapif->ethaddr, p);
if(p != NULL) {
printf("ARP outout\n");
pbuf_free(p);
}
break;
default:
pbuf_free(p);
break;
}
}
} else {
printf("ip_lookup dropped\n");
}
sys_sem_signal(pcapif->sem);
}
/*-----------------------------------------------------------------------------------*/
static void
callback(u_char *arg, const struct pcap_pkthdr *hdr, const u_char *pkt)
{
struct netif *netif;
struct pcapif *pcapif;
u32_t time, lasttime;
netif = (struct netif *)arg;
pcapif = netif->state;
pcapif->len = hdr->len;
bcopy(pkt, pcapif->pkt, hdr->len);
time = hdr->ts.tv_sec * 1000 + hdr->ts.tv_usec / 1000;
lasttime = pcapif->lasttime;
pcapif->lasttime = time;
if(lasttime == 0) {
sys_timeout(1000, timeout, netif);
} else {
sys_timeout(time - lasttime, timeout, netif);
}
}
/*-----------------------------------------------------------------------------------*/
static void
pcapif_thread(void *arg)
{
struct netif *netif;
struct pcapif *pcapif;
netif = arg;
pcapif = netif->state;
while(1) {
pcap_loop(pcapif->pd, 1, callback, (u_char *)netif);
sys_sem_wait(pcapif->sem);
if(pcapif->p != NULL) {
netif->input(pcapif->p, netif);
}
}
}
/*-----------------------------------------------------------------------------------*/
void
pcapif_init(struct netif *netif)
{
struct pcapif *p;
p = malloc(sizeof(struct pcapif));
netif->state = p;
netif->name[0] = 'p';
netif->name[1] = 'c';
netif->output = pcapif_output;
p->pd = pcap_open_offline("pcapdump", errbuf);
if(p->pd == NULL) {
printf("pcapif_init: failed %s\n", errbuf);
return;
}
p->sem = sys_sem_new(0);
p->p = NULL;
p->lasttime = 0;
sys_thread_new(pcapif_thread, netif);
}
/*-----------------------------------------------------------------------------------*/
#endif /* linux */

View File

@ -1,319 +0,0 @@
/* Author: Magnus Ivarsson <magnus.ivarsson@volvo.com> */
#include "netif/sio.h"
#include "netif/fifo.h"
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/arch.h"
/* Following #undefs are here to keep compiler from issuing warnings
about them being double defined. (They are defined in lwip/inet.h
as well as the Unix #includes below.) */
#undef htonl
#undef ntohl
#undef htons
#undef ntohs
#undef HTONL
#undef NTOHL
#undef HTONS
#undef NTOHS
#include <stdlib.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/signal.h>
#include <sys/types.h>
//#define BAUDRATE B19200
//#define BAUDRATE B57600
#define BAUDRATE B115200
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* for all of you who dont define SIO_DEBUG in debug.h */
#ifndef SIO_DEBUG
#define SIO_DEBUG 0
#endif
// typedef struct siostruct_t
// {
// sio_status_t *sio;
// } siostruct_t;
/** array of ((siostruct*)netif->state)->sio structs */
static sio_status_t statusar[2];
/* --private-functions----------------------------------------------------------------- */
/**
* Signal handler for ttyXX0 to indicate bytes received
* one per interface is needed since we cannot send a instance number / pointer as callback argument (?)
*/
static void signal_handler_IO_0( int status )
{
DEBUGF(SIO_DEBUG, ("SigHand: rxSignal chanel 0"));
fifoPut( &statusar[0].myfifo, statusar[0].fd );
}
/**
* Signal handler for ttyXX1 to indicate bytes received
* one per interface is needed since we cannot send a instance number / pointer as callback argument (?)
*/
static void signal_handler_IO_1( int status )
{
DEBUGF(SIO_DEBUG, ("SigHand: rxSignal channel 1"));
fifoPut( &statusar[1].myfifo, statusar[1].fd );
}
/**
* Initiation of serial device
* @param device : string with the device name and path, eg. "/dev/ttyS0"
* @param netif : netinterface struct, contains interface instance data
* @return file handle to serial dev.
*/
static int sio_init( char * device, int devnum, sio_status_t * siostat )
{
struct termios oldtio,newtio;
struct sigaction saio; /* definition of signal action */
int fd;
/* open the device to be non-blocking (read will return immediatly) */
fd = open( device, O_RDWR | O_NOCTTY | O_NONBLOCK );
if ( fd < 0 )
{
perror( device );
exit( -1 );
}
/* install the signal handler before making the device asynchronous */
switch ( devnum )
{
case 0:
DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_0\r\n") );
saio.sa_handler = signal_handler_IO_0;
break;
case 1:
DEBUGF( SIO_DEBUG, ("sioinit, signal_handler_IO_1\r\n") );
saio.sa_handler = signal_handler_IO_1;
break;
default:
DEBUGF( SIO_DEBUG,("sioinit, devnum not allowed\r\n") );
break;
}
saio.sa_flags = 0;
#if linux
saio.sa_restorer = NULL;
#endif /* linux */
sigaction( SIGIO,&saio,NULL );
/* allow the process to receive SIGIO */
fcntl( fd, F_SETOWN, getpid( ) );
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl( fd, F_SETFL, FASYNC );
tcgetattr( fd,&oldtio ); /* save current port settings */
/* set new port settings */
/* see 'man termios' for further settings */
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; // | CRTSCTS;
newtio.c_iflag = 0;
newtio.c_oflag = 0;
newtio.c_lflag = 0; //ECHO;
newtio.c_cc[VMIN] = 1; /* Read 1 byte at a time, no timer */
newtio.c_cc[VTIME] = 0;
tcsetattr( fd,TCSANOW,&newtio );
tcflush( fd, TCIOFLUSH );
return fd;
}
/**
*
*/
static void sio_speed( int fd, int speed )
{
struct termios oldtio,newtio;
// int fd;
DEBUGF( 1,("sio_speed: baudcode:%d enter\n",speed ) );
if ( fd < 0 )
{
DEBUGF(SIO_DEBUG, ( "sio_speed: fd ERROR\n" ));
exit( -1 );
}
tcgetattr( fd,&oldtio ); /* get current port settings */
/* set new port settings
* see 'man termios' for further settings */
newtio.c_cflag = speed | CS8 | CLOCAL | CREAD; //§ | CRTSCTS;
newtio.c_iflag = 0;
newtio.c_oflag = 0;
newtio.c_lflag = 0; //ECHO;
newtio.c_cc[VMIN] = 1; /* Read 1 byte at a time, no timer */
newtio.c_cc[VTIME] = 0;
tcsetattr( fd,TCSANOW,&newtio );
tcflush( fd, TCIOFLUSH );
DEBUGF( SIO_DEBUG ,("sio_speed: leave\n" ));
}
/* --public-functions----------------------------------------------------------------------------- */
void sio_send( u8_t c, sio_status_t * siostat )
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
if ( write( siostat->fd, &c, 1 ) <= 0 )
{
DEBUGF( SIO_DEBUG,("sio_send: write refused") );
}
}
void sio_send_string( u8_t *str, sio_status_t * siostat )
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
int len = strlen( (const char *)str );
if ( write( siostat->fd, str, len ) <= 0 )
{
DEBUGF( SIO_DEBUG,("sio_send_string: write refused") );
}
DEBUGF( (PPP_DEBUG | SIO_DEBUG),("sent:%s",str ) );
}
void sio_flush( sio_status_t * siostat )
{
/* not implemented in unix as it is not needed */
//sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
}
//u8_t sio_recv( struct netif * netif )
u8_t sio_recv( sio_status_t * siostat )
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
return fifoGet( &(siostat->myfifo) );
}
s16_t sio_poll(sio_status_t * siostat)
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
return fifoGetNonBlock( &(siostat->myfifo) );
}
void sio_expect_string( u8_t *str, sio_status_t * siostat )
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
u8_t c;
int finger=0;
DEBUGF( (PPP_DEBUG | SIO_DEBUG), ("expect:%s\n",str) );
while ( 1 )
{
c=fifoGet( &(siostat->myfifo) );
DEBUGF( (PPP_DEBUG | SIO_DEBUG), ("_%c",c) );
if ( c==str[finger] )
{
finger++;
} else if ( finger > 0 )
{
//it might fit in the beginning?
if ( str[0] == c )
{
finger = 1;
}
}
if ( 0 == str[finger] )
break; // done, we have a match
}
DEBUGF( (PPP_DEBUG | SIO_DEBUG), ("[match]\n") );
}
sio_status_t * sio_open( int devnum )
{
char dev[20];
/* would be nice with dynamic memory alloc */
sio_status_t * siostate = &statusar[ devnum ];
// siostruct_t * tmp;
//
//
// tmp = (siostruct_t*)(netif->state);
// tmp->sio = siostate;
//
// tmp = (siostruct_t*)(netif->state);
//
// ((sio_status_t*)(tmp->sio))->fd = 0;
fifoInit( &siostate->myfifo );
sprintf( dev, "/dev/ttyS%d", devnum );
if ( (devnum == 1) || (devnum == 0) )
{
if ( ( siostate->fd = sio_init( dev, devnum, siostate ) ) == 0 )
{
DEBUGF(SIO_DEBUG, ( "sio_open: ERROR opening serial device" ));
abort( );
return NULL;
}
}
else
{
DEBUGF(SIO_DEBUG, ( "sio_open: device %s (%d) is not supported", dev, devnum ));
return NULL;
}
DEBUGF( 1,("sio_open: dev=%s open.\n", dev ));
return siostate;
}
/**
*
*/
void sio_change_baud( sioBaudrates baud, sio_status_t * siostat )
{
// sio_status_t * siostat = ((siostruct_t*)netif->state)->sio;
DEBUGF( 1,("sio_change_baud\n" ));
switch ( baud )
{
case SIO_BAUD_9600:
sio_speed( siostat->fd, B9600 );
break;
case SIO_BAUD_19200:
sio_speed( siostat->fd, B19200 );
break;
case SIO_BAUD_38400:
sio_speed( siostat->fd, B38400 );
break;
case SIO_BAUD_57600:
sio_speed( siostat->fd, B57600 );
break;
case SIO_BAUD_115200:
sio_speed( siostat->fd, B115200 );
break;
default:
DEBUGF( 1,("sio_change_baud: Unknown baudrate, code:%d", baud ));
break;
}
}

View File

@ -1,361 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include "lwip/debug.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/ip.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "netif/etharp.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 */
#define IFNAME0 't'
#define IFNAME1 'p'
static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
struct tapif {
struct eth_addr *ethaddr;
/* Add whatever per-interface state that is needed here. */
int fd;
};
/* Forward declarations. */
static void tapif_input(struct netif *netif);
static err_t tapif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr);
static void tapif_thread(void *data);
/*-----------------------------------------------------------------------------------*/
static void
low_level_init(struct netif *netif)
{
struct tapif *tapif;
char buf[100];
tapif = netif->state;
/* Obtain MAC address from network interface. */
/* (We just fake an address...) */
tapif->ethaddr->addr[0] = 0x1;
tapif->ethaddr->addr[1] = 0x2;
tapif->ethaddr->addr[2] = 0x3;
tapif->ethaddr->addr[3] = 0x4;
tapif->ethaddr->addr[4] = 0x5;
tapif->ethaddr->addr[5] = 0x6;
/* Do whatever else is needed to initialize interface. */
tapif->fd = open(DEVTAP, O_RDWR);
DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd));
if(tapif->fd == -1) {
perror("tapif_init");
exit(1);
}
#ifdef linux
{
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
if (ioctl(tapif->fd, TUNSETIFF, (void *) &ifr) < 0) {
perror(buf);
exit(1);
}
}
#endif /* Linux */
snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d",
ip4_addr1(&(netif->gw)),
ip4_addr2(&(netif->gw)),
ip4_addr3(&(netif->gw)),
ip4_addr4(&(netif->gw)));
DEBUGF(TAPIF_DEBUG, ("tapif_init: system(\"%s\");\n", buf));
system(buf);
sys_thread_new(tapif_thread, netif);
}
/*-----------------------------------------------------------------------------------*/
/*
* low_level_output():
*
* Should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
*/
/*-----------------------------------------------------------------------------------*/
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
char buf[1514];
char *bufptr;
struct tapif *tapif;
tapif = netif->state;
#if 0
if(((double)rand()/(double)RAND_MAX) < 0.2) {
printf("drop output\n");
return ERR_OK;
}
#endif
/* initiate transfer(); */
bufptr = &buf[0];
for(q = p; q != NULL; q = q->next) {
/* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len
variable. */
/* send data from(q->payload, q->len); */
memcpy(bufptr, q->payload, q->len);
bufptr += q->len;
}
/* signal that packet should be sent(); */
if(write(tapif->fd, buf, p->tot_len) == -1) {
perror("tapif: write");
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/*
* low_level_input():
*
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
*/
/*-----------------------------------------------------------------------------------*/
static struct pbuf *
low_level_input(struct tapif *tapif)
{
struct pbuf *p, *q;
u16_t len;
char buf[1514];
char *bufptr;
/* Obtain the size of the packet and put it into the "len"
variable. */
len = read(tapif->fd, buf, sizeof(buf));
#if 0
if(((double)rand()/(double)RAND_MAX) < 0.2) {
printf("drop\n");
return NULL;
}
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if(p != NULL) {
/* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */
bufptr = &buf[0];
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
available data in the pbuf is given by the q->len
variable. */
/* read data into(q->payload, q->len); */
memcpy(q->payload, bufptr, q->len);
bufptr += q->len;
}
/* acknowledge that packet has been read(); */
} else {
/* drop packet(); */
}
return p;
}
/*-----------------------------------------------------------------------------------*/
static void
tapif_thread(void *arg)
{
struct netif *netif;
struct tapif *tapif;
fd_set fdset;
int ret;
netif = arg;
tapif = netif->state;
while(1) {
FD_ZERO(&fdset);
FD_SET(tapif->fd, &fdset);
/* Wait for a packet to arrive. */
ret = select(tapif->fd + 1, &fdset, NULL, NULL, NULL);
if(ret == 1) {
/* Handle incoming packet. */
tapif_input(netif);
} else if(ret == -1) {
perror("tapif_thread: select");
}
}
}
/*-----------------------------------------------------------------------------------*/
/*
* tapif_output():
*
* This function is called by the TCP/IP stack when an IP packet
* should be sent. It calls the function called low_level_output() to
* do the actuall transmission of the packet.
*
*/
/*-----------------------------------------------------------------------------------*/
static err_t
tapif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr)
{
p = etharp_output(netif, ipaddr, p);
if(p != NULL) {
low_level_output(netif, p);
p = NULL;
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/*
* tapif_input():
*
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface.
*
*/
/*-----------------------------------------------------------------------------------*/
static void
tapif_input(struct netif *netif)
{
struct tapif *tapif;
struct eth_hdr *ethhdr;
struct pbuf *p, *q;
tapif = netif->state;
p = low_level_input(tapif);
if(p == NULL) {
DEBUGF(TAPIF_DEBUG, ("tapif_input: low_level_input returned NULL\n"));
return;
}
ethhdr = p->payload;
q = NULL;
switch(htons(ethhdr->type)) {
case ETHTYPE_IP:
DEBUGF(TAPIF_DEBUG, ("tapif_input: IP packet\n"));
q = etharp_ip_input(netif, p);
pbuf_header(p, -14);
netif->input(p, netif);
break;
case ETHTYPE_ARP:
DEBUGF(TAPIF_DEBUG, ("tapif_input: ARP packet\n"));
q = etharp_arp_input(netif, tapif->ethaddr, p);
break;
default:
pbuf_free(p);
break;
}
if(q != NULL) {
low_level_output(netif, q);
pbuf_free(q);
}
}
/*-----------------------------------------------------------------------------------*/
static void
arp_timer(void *arg)
{
etharp_tmr();
sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL);
}
/*-----------------------------------------------------------------------------------*/
/*
* tapif_init():
*
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
*/
/*-----------------------------------------------------------------------------------*/
void
tapif_init(struct netif *netif)
{
struct tapif *tapif;
tapif = mem_malloc(sizeof(struct tapif));
netif->state = tapif;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
netif->output = tapif_output;
netif->linkoutput = low_level_output;
netif->mtu = 1500;
tapif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
low_level_init(netif);
etharp_init();
sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,186 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include <stdio.h>
#include "netif/tcpdump.h"
#include "lwip/ip.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/inet.h"
static FILE *file = NULL;
/*-----------------------------------------------------------------------------------*/
void
tcpdump_init(void)
{
char *fname;
fname = "/tmp/tcpdump";
file = fopen(fname, "w");
if(file == NULL) {
perror("tcpdump_init: fopen");
}
DEBUGF(TCPDUMP_DEBUG, ("tcpdump: file %s\n", fname));
}
/*-----------------------------------------------------------------------------------*/
void
tcpdump(struct pbuf *p)
{
struct ip_hdr *iphdr;
struct tcp_hdr *tcphdr;
struct udp_hdr *udphdr;
char flags[5];
int i;
int len;
int offset;
if(file == NULL) {
return;
}
#ifdef IPv4
iphdr = p->payload;
switch(IPH_PROTO(iphdr)) {
case IP_PROTO_TCP:
tcphdr = (struct tcp_hdr *)((char *)iphdr + IP_HLEN);
pbuf_header(p, -IP_HLEN);
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len) != 0) {
DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n"));
/* fprintf(file, "chksum 0x%lx ", tcphdr->chksum);
tcphdr->chksum = 0;
fprintf(file, "should be 0x%lx ", inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len));*/
fprintf(file, "!chksum ");
}
i = 0;
if(TCPH_FLAGS(tcphdr) & TCP_SYN) {
flags[i++] = 'S';
}
if(TCPH_FLAGS(tcphdr) & TCP_PSH) {
flags[i++] = 'P';
}
if(TCPH_FLAGS(tcphdr) & TCP_FIN) {
flags[i++] = 'F';
}
if(TCPH_FLAGS(tcphdr) & TCP_RST) {
flags[i++] = 'R';
}
if(i == 0) {
flags[i++] = '.';
}
flags[i++] = 0;
fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ",
(int)(ntohl(iphdr->src.addr) >> 24) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 16) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 8) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 0) & 0xff,
ntohs(tcphdr->src),
(int)(ntohl(iphdr->dest.addr) >> 24) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 16) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 8) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 0) & 0xff,
ntohs(tcphdr->dest));
offset = TCPH_OFFSET(tcphdr) >> 4;
len = ntohs(IPH_LEN(iphdr)) - offset * 4 - IP_HLEN;
if(len != 0 || flags[0] != '.') {
fprintf(file, "%s %lu:%lu(%u) ",
flags,
ntohl(tcphdr->seqno),
ntohl(tcphdr->seqno) + len,
len);
}
if(TCPH_FLAGS(tcphdr) & TCP_ACK) {
fprintf(file, "ack %lu ",
ntohl(tcphdr->ackno));
}
fprintf(file, "wnd %u\n",
ntohs(tcphdr->wnd));
fflush(file);
pbuf_header(p, IP_HLEN);
break;
case IP_PROTO_UDP:
udphdr = (struct udp_hdr *)((char *)iphdr + IP_HLEN);
pbuf_header(p, -IP_HLEN);
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest),
IP_PROTO_UDP, p->tot_len) != 0) {
DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n"));
/* fprintf(file, "chksum 0x%lx ", tcphdr->chksum);
tcphdr->chksum = 0;
fprintf(file, "should be 0x%lx ", inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len));*/
fprintf(file, "!chksum ");
}
fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ",
(int)(ntohl(iphdr->src.addr) >> 24) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 16) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 8) & 0xff,
(int)(ntohl(iphdr->src.addr) >> 0) & 0xff,
ntohs(udphdr->src),
(int)(ntohl(iphdr->dest.addr) >> 24) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 16) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 8) & 0xff,
(int)(ntohl(iphdr->dest.addr) >> 0) & 0xff,
ntohs(udphdr->dest));
fprintf(file, "U ");
len = ntohs(IPH_LEN(iphdr)) - sizeof(struct udp_hdr) - IP_HLEN;
fprintf(file, " %d\n", len);
fflush(file);
pbuf_header(p, IP_HLEN);
break;
}
#endif /* IPv4 */
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,298 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include "lwip/debug.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/ip.h"
#include "lwip/mem.h"
#include "lwip/netif.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#define IFNAME0 't'
#define IFNAME1 'n'
struct tunif {
/* Add whatever per-interface state that is needed here. */
int fd;
};
/* Forward declarations. */
static void tunif_input(struct netif *netif);
static err_t tunif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr);
static void tunif_thread(void *data);
/*-----------------------------------------------------------------------------------*/
static void
low_level_init(struct netif *netif)
{
struct tunif *tunif;
char buf[100];
tunif = netif->state;
/* Obtain MAC address from network interface. */
/* Do whatever else is needed to initialize interface. */
tunif->fd = open("/dev/tun0", O_RDWR);
DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd));
if(tunif->fd == -1) {
perror("tunif_init");
exit(1);
}
snprintf(buf, sizeof(buf), "ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d",
ip4_addr1(&(netif->gw)),
ip4_addr2(&(netif->gw)),
ip4_addr3(&(netif->gw)),
ip4_addr4(&(netif->gw)),
ip4_addr1(&(netif->ip_addr)),
ip4_addr2(&(netif->ip_addr)),
ip4_addr3(&(netif->ip_addr)),
ip4_addr4(&(netif->ip_addr)));
DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf));
system(buf);
sys_thread_new(tunif_thread, netif);
}
/*-----------------------------------------------------------------------------------*/
/*
* low_level_output():
*
* Should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
*/
/*-----------------------------------------------------------------------------------*/
static err_t
low_level_output(struct tunif *tunif, struct pbuf *p)
{
struct pbuf *q;
char buf[1500];
char *bufptr;
/* initiate transfer(); */
if(((double)rand()/(double)RAND_MAX) < 0.4) {
printf("drop\n");
return ERR_OK;
}
bufptr = &buf[0];
for(q = p; q != NULL; q = q->next) {
/* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len
variable. */
/* send data from(q->payload, q->len); */
bcopy(q->payload, bufptr, q->len);
bufptr += q->len;
}
/* signal that packet should be sent(); */
if(write(tunif->fd, buf, p->tot_len) == -1) {
perror("tunif: write");
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/*
* low_level_input():
*
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
*/
/*-----------------------------------------------------------------------------------*/
static struct pbuf *
low_level_input(struct tunif *tunif)
{
struct pbuf *p, *q;
u16_t len;
char buf[1500];
char *bufptr;
/* Obtain the size of the packet and put it into the "len"
variable. */
len = read(tunif->fd, buf, sizeof(buf));
/* if(((double)rand()/(double)RAND_MAX) < 0.1) {
printf("drop\n");
return NULL;
}*/
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL);
if(p != NULL) {
/* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */
bufptr = &buf[0];
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
available data in the pbuf is given by the q->len
variable. */
/* read data into(q->payload, q->len); */
bcopy(bufptr, q->payload, q->len);
bufptr += q->len;
}
/* acknowledge that packet has been read(); */
} else {
/* drop packet(); */
}
return p;
}
/*-----------------------------------------------------------------------------------*/
static void
tunif_thread(void *arg)
{
struct netif *netif;
struct tunif *tunif;
fd_set fdset;
int ret;
netif = arg;
tunif = netif->state;
while(1) {
FD_ZERO(&fdset);
FD_SET(tunif->fd, &fdset);
/* Wait for a packet to arrive. */
ret = select(tunif->fd + 1, &fdset, NULL, NULL, NULL);
if(ret == 1) {
/* Handle incoming packet. */
tunif_input(netif);
} else if(ret == -1) {
perror("tunif_thread: select");
}
}
}
/*-----------------------------------------------------------------------------------*/
/*
* tunif_output():
*
* This function is called by the TCP/IP stack when an IP packet
* should be sent. It calls the function called low_level_output() to
* do the actuall transmission of the packet.
*
*/
/*-----------------------------------------------------------------------------------*/
static err_t
tunif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr)
{
struct tunif *tunif;
tunif = netif->state;
return low_level_output(tunif, p);
}
/*-----------------------------------------------------------------------------------*/
/*
* tunif_input():
*
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface.
*
*/
/*-----------------------------------------------------------------------------------*/
static void
tunif_input(struct netif *netif)
{
struct tunif *tunif;
struct pbuf *p;
tunif = netif->state;
p = low_level_input(tunif);
if(p == NULL) {
DEBUGF(TUNIF_DEBUG, ("tunif_input: low_level_input returned NULL\n"));
return;
}
if(ip_lookup(p->payload, netif)) {
netif->input(p, netif);
}
}
/*-----------------------------------------------------------------------------------*/
/*
* tunif_init():
*
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
*/
/*-----------------------------------------------------------------------------------*/
void
tunif_init(struct netif *netif)
{
struct tunif *tunif;
tunif = mem_malloc(sizeof(struct tunif));
netif->state = tunif;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
netif->output = tunif_output;
low_level_init(netif);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,480 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/debug.h"
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "lwip/stats.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "netif/unixif.h"
#include "lwip/sys.h"
#include "lwip/list.h"
#include "netif/tcpdump.h"
#define UNIXIF_BPS 512000
#define UNIXIF_QUEUELEN 6
/*#define UNIXIF_DROP_FIRST */
struct unixif_buf {
struct pbuf *p;
unsigned short len, tot_len;
void *payload;
};
struct unixif {
int fd;
sys_sem_t sem;
struct list *q;
};
/*-----------------------------------------------------------------------------------*/
static int
unix_socket_client(char *name)
{
int fd, len;
struct sockaddr_un unix_addr;
/* create a Unix domain stream socket */
if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror("unixif: unix_socket_client: socket");
return(-1);
}
/* fill socket address structure w/our address */
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
sprintf(unix_addr.sun_path, "%s%05d", "/var/tmp/", getpid());
#ifndef linux
len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) +
strlen(unix_addr.sun_path) + 1;
unix_addr.sun_len = len;
#else
len = sizeof(unix_addr.sun_family) +
strlen(unix_addr.sun_path) + 1;
#endif /* linux */
unlink(unix_addr.sun_path); /* in case it already exists */
if(bind(fd, (struct sockaddr *) &unix_addr,
sizeof(struct sockaddr_un)) < 0) {
perror("unixif: unix_socket_client: socket");
return(-1);
}
if(chmod(unix_addr.sun_path, S_IRWXU | S_IRWXO) < 0) {
perror("unixif: unix_socket_client: socket");
return(-1);
}
/* fill socket address structure w/server's addr */
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, name);
#ifndef linux
len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) +
strlen(unix_addr.sun_path) + 1;
unix_addr.sun_len = len;
#else
len = sizeof(unix_addr.sun_family) + strlen(unix_addr.sun_path) + 1;
#endif /* linux */
if(connect(fd, (struct sockaddr *) &unix_addr,
sizeof(struct sockaddr_un)) < 0) {
perror("unixif: unix_socket_client: socket");
return(-1);
}
return(fd);
}
/*-----------------------------------------------------------------------------------*/
static int
unix_socket_server(char *name)
{
int fd, len;
struct sockaddr_un unix_addr;
/* create a Unix domain stream socket */
if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror("unixif: unix_socket_server: socket");
return(-1);
}
unlink(name); /* in case it already exists */
/* fill in socket address structure */
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, name);
#ifndef linux
len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) +
strlen(unix_addr.sun_path) + 1;
unix_addr.sun_len = len;
#else
len = sizeof(unix_addr.sun_family) +
strlen(unix_addr.sun_path) + 1;
#endif /* linux */
/* bind the name to the descriptor */
if(bind(fd, (struct sockaddr *) &unix_addr,
sizeof(struct sockaddr_un)) < 0) {
perror("unixif: unix_socket_server: bind");
return(-1);
}
if(chmod(unix_addr.sun_path, S_IRWXU | S_IRWXO) < 0) {
perror("unixif: unix_socket_server: chmod");
return(-1);
}
if(listen(fd, 5) < 0) { /* tell kernel we're a server */
perror("unixif: unix_socket_server: listen");
return(-1);
}
return(fd);
}
/*-----------------------------------------------------------------------------------*/
static void
unixif_input_handler(void *data)
{
struct netif *netif;
struct unixif *unixif;
char buf[4096], *bufptr;
int len, plen, rlen;
struct pbuf *p, *q;
netif = data;
unixif = netif->state;
len = read(unixif->fd, &plen, sizeof(int));
if(len == -1) {
perror("unixif_irq_handler: read");
abort();
}
DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: len == %d plen == %d bytes\n", len, plen));
if(len == sizeof(int)) {
if(plen < 20 || plen > 1500) {
DEBUGF(UNIXIF_DEBUG, ("plen %d!\n", plen));
return;
}
len = read(unixif->fd, buf, plen);
if(len == -1) {
perror("unixif_irq_handler: read");
abort();
}
DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: read %d bytes\n", len));
p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL);
if(p != NULL) {
rlen = len;
bufptr = buf;
q = p;
while(rlen > 0) {
bcopy(bufptr, q->payload, rlen > q->len? q->len: rlen);
rlen -= q->len;
bufptr += q->len;
q = q->next;
}
pbuf_realloc(p, len);
#ifdef LINK_STATS
lwip_stats.link.recv++;
#endif /* LINK_STATS */
tcpdump(p);
netif->input(p, netif);
} else {
DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: could not allocate pbuf\n"));
}
}
}
/*-----------------------------------------------------------------------------------*/
static void
unixif_thread(void *arg)
{
struct netif *netif;
struct unixif *unixif;
DEBUGF(UNIXIF_DEBUG, ("unixif_thread: started.\n"));
netif = arg;
unixif = netif->state;
while(1) {
sys_sem_wait(unixif->sem);
unixif_input_handler(netif);
}
}
/*-----------------------------------------------------------------------------------*/
static void
unixif_thread2(void *arg)
{
struct netif *netif;
struct unixif *unixif;
fd_set fdset;
DEBUGF(UNIXIF_DEBUG, ("unixif_thread2: started.\n"));
netif = arg;
unixif = netif->state;
while(1) {
FD_ZERO(&fdset);
FD_SET(unixif->fd, &fdset);
if(select(unixif->fd + 1, &fdset, NULL, NULL, NULL) > 0) {
sys_sem_signal(unixif->sem);
}
}
}
/*-----------------------------------------------------------------------------------*/
static void unixif_output_timeout(void *arg);
static err_t
unixif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
{
struct unixif *unixif;
struct unixif_buf *buf;
unixif = netif->state;
buf = malloc(sizeof(struct unixif_buf));
buf->p = p;
buf->len = p->len;
buf->tot_len = p->tot_len;
buf->payload = p->payload;
if(list_elems(unixif->q) == 0) {
pbuf_ref(p);
list_push(unixif->q, buf);
sys_timeout((double)p->tot_len * 8000.0 / UNIXIF_BPS, unixif_output_timeout,
netif);
DEBUGF(UNIXIF_DEBUG, ("unixif_output: first on list\n"));
} else {
pbuf_ref(p);
if(list_push(unixif->q, buf) == 0) {
#ifdef UNIXIF_DROP_FIRST
struct unixif_buf *buf2;
buf2 = list_pop(unixif->q);
pbuf_free(buf2->p);
free(buf2);
list_push(unixif->q, buf);
#else
free(buf);
pbuf_free(p);
DEBUGF(UNIXIF_DEBUG, ("unixif_output: drop\n"));
#endif /* UNIXIF_DROP_FIRST */
#ifdef LINK_STATS
lwip_stats.link.drop++;
#endif /* LINK_STATS */
} else {
DEBUGF(UNIXIF_DEBUG, ("unixif_output: on list\n"));
}
}
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
static void
unixif_output_timeout(void *arg)
{
struct pbuf *p, *q;
int i, j, len;
unsigned short plen, ptot_len;
struct unixif_buf *buf;
void *payload;
struct netif *netif;
struct unixif *unixif;
char *data;
netif = arg;
unixif = netif->state;
DEBUGF(UNIXIF_DEBUG, ("unixif_output_timeout\n"));
/* buf = unixif->q[0];
unixif->q[0] = unixif->q[1];
unixif->q[1] = NULL;*/
buf = list_pop(unixif->q);
p = buf->p;
plen = p->len;
ptot_len = p->tot_len;
payload = p->payload;
p->len = buf->len;
p->tot_len = buf->tot_len;
p->payload = buf->payload;
if(p->tot_len == 0) {
DEBUGF(UNIXIF_DEBUG, ("p->len!\n"));
abort();
}
data = malloc(p->tot_len);
i = 0;
for(q = p; q != NULL; q = q->next) {
for(j = 0; j < q->len; j++) {
data[i] = ((char *)q->payload)[j];
i++;
}
}
DEBUGF(UNIXIF_DEBUG, ("unixif_output: sending %d (%d) bytes\n",
p->len, p->tot_len));
len = p->tot_len;
if(write(unixif->fd, &len, sizeof(int)) == -1) {
perror("unixif_output: write");
abort();
}
if(write(unixif->fd, data, p->tot_len) == -1) {
perror("unixif_output: write");
abort();
}
tcpdump(p);
#ifdef LINK_STATS
lwip_stats.link.xmit++;
#endif /* LINK_STATS */
free(data);
free(buf);
p->len = plen;
p->tot_len = ptot_len;
p->payload = payload;
pbuf_free(p);
/* if(unixif->q[0] != NULL) {
sys_timeout(unixif->q[0]->tot_len * 8000 / UNIXIF_BPS,
unixif_output_timeout, netif);
}*/
if(list_elems(unixif->q) > 0) {
sys_timeout(((struct unixif_buf *)list_first(unixif->q))->tot_len *
8000.0 / UNIXIF_BPS,
unixif_output_timeout, netif);
}
}
/*-----------------------------------------------------------------------------------*/
void
unixif_init_server(struct netif *netif)
{
int fd, fd2;
struct sockaddr_un addr;
socklen_t len;
struct unixif *unixif;
fd = unix_socket_server("/tmp/unixif");
if(fd == -1) {
perror("unixif_server");
abort();
}
DEBUGF(UNIXIF_DEBUG, ("unixif_server: fd %d\n", fd));
unixif = malloc(sizeof(struct unixif));
netif->state = unixif;
netif->name[0] = 'u';
netif->name[1] = 'n';
netif->output = unixif_output;
unixif->q = list_new(UNIXIF_QUEUELEN);
printf("Now run ./simnode.\n");
len = sizeof(addr);
fd2 = accept(fd, (struct sockaddr *)&addr, &len);
if(fd2 == -1) {
perror("unixif_accept");
abort();
}
DEBUGF(UNIXIF_DEBUG, ("unixif_accept: %d\n", fd2));
unixif->fd = fd2;
unixif->sem = sys_sem_new(0);
sys_thread_new(unixif_thread, netif);
sys_thread_new(unixif_thread2, netif);
}
/*-----------------------------------------------------------------------------------*/
void
unixif_init_client(struct netif *netif)
{
struct unixif *unixif;
unixif = malloc(sizeof(struct unixif));
netif->state = unixif;
netif->name[0] = 'u';
netif->name[1] = 'n';
netif->output = unixif_output;
unixif->fd = unix_socket_client("/tmp/unixif");
if(unixif->fd == -1) {
perror("unixif_init");
abort();
}
unixif->q = list_new(UNIXIF_QUEUELEN);
unixif->sem = sys_sem_new(0);
sys_thread_new(unixif_thread, netif);
sys_thread_new(unixif_thread2, netif);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "arch/perf.h"
#include <stdio.h>
static FILE *f;
void
perf_print(unsigned long c1l, unsigned long c1h,
unsigned long c2l, unsigned long c2h,
char *key)
{
unsigned long long start, end;
start = (unsigned long long)c2h << 32 | c2l;
end = (unsigned long long)c1h << 32 | c1l;
fprintf(f, "%s: %llu\n", key, start - end);
fflush(NULL);
}
void
perf_print_times(struct tms *start, struct tms *end, char *key)
{
fprintf(f, "%s: %lu\n", key, end->tms_stime - start->tms_stime);
fflush(NULL);
}
void
perf_init(char *fname)
{
f = fopen(fname, "w");
}

View File

@ -1,453 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* Wed Apr 17 16:05:29 EDT 2002 (James Roth)
*
* - Fixed an unlikely sys_thread_new() race condition.
*
* - Made current_thread() work with threads which where
* not created with sys_thread_new(). This includes
* the main thread and threads made with pthread_create().
*
* - Catch overflows where more than SYS_MBOX_SIZE messages
* are waiting to be read. The sys_mbox_post() routine
* will block until there is more room instead of just
* leaking messages.
*/
#include "lwip/debug.h"
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include "lwip/sys.h"
#include "lwip/opt.h"
#include "lwip/stats.h"
#define UMAX(a, b) ((a) > (b) ? (a) : (b))
static struct sys_thread *threads = NULL;
static pthread_mutex_t threads_mutex = PTHREAD_MUTEX_INITIALIZER;
struct sys_mbox_msg {
struct sys_mbox_msg *next;
void *msg;
};
#define SYS_MBOX_SIZE 128
struct sys_mbox {
int first, last;
void *msgs[SYS_MBOX_SIZE];
struct sys_sem *mail;
struct sys_sem *mutex;
int wait_send;
};
struct sys_sem {
unsigned int c;
pthread_cond_t cond;
pthread_mutex_t mutex;
};
struct sys_thread {
struct sys_thread *next;
struct sys_timeouts timeouts;
pthread_t pthread;
};
static struct timeval starttime;
static struct sys_sem *sys_sem_new_(u8_t count);
static void sys_sem_free_(struct sys_sem *sem);
static u16_t cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex,
u16_t timeout);
/*-----------------------------------------------------------------------------------*/
static struct sys_thread *
introduce_thread(pthread_t id)
{
struct sys_thread *thread;
thread = malloc(sizeof(struct sys_thread));
if(thread) {
pthread_mutex_lock(&threads_mutex);
thread->next = threads;
thread->timeouts.next = NULL;
thread->pthread = id;
threads = thread;
pthread_mutex_unlock(&threads_mutex);
}
return thread;
}
/*-----------------------------------------------------------------------------------*/
static struct sys_thread *
current_thread(void)
{
struct sys_thread *st;
pthread_t pt;
pt = pthread_self();
pthread_mutex_lock(&threads_mutex);
for(st = threads; st != NULL; st = st->next) {
if(pthread_equal(st->pthread, pt)) {
pthread_mutex_unlock(&threads_mutex);
return st;
}
}
pthread_mutex_unlock(&threads_mutex);
st = introduce_thread(pt);
if(!st) {
printf("current_thread???\n");
abort();
}
return st;
}
/*-----------------------------------------------------------------------------------*/
void
sys_thread_new(void (*function)(void *arg), void *arg)
{
int code;
pthread_t tmp;
struct sys_thread *st = NULL;
code = pthread_create(&tmp,
NULL,
(void *(*)(void *))
function,
arg);
if(0 == code) {
st = introduce_thread(tmp);
}
if(NULL == st) {
DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create %d, st = 0x%x",
code, (int)st));
abort();
}
}
/*-----------------------------------------------------------------------------------*/
struct sys_mbox *
sys_mbox_new()
{
struct sys_mbox *mbox;
mbox = malloc(sizeof(struct sys_mbox));
mbox->first = mbox->last = 0;
mbox->mail = sys_sem_new_(0);
mbox->mutex = sys_sem_new_(1);
mbox->wait_send = 0;
#ifdef SYS_STATS
lwip_stats.sys.mbox.used++;
if(lwip_stats.sys.mbox.used > lwip_stats.sys.mbox.max) {
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
}
#endif /* SYS_STATS */
return mbox;
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_free(struct sys_mbox *mbox)
{
if(mbox != SYS_MBOX_NULL) {
#ifdef SYS_STATS
lwip_stats.sys.mbox.used--;
#endif /* SYS_STATS */
sys_sem_wait(mbox->mutex);
sys_sem_free_(mbox->mail);
sys_sem_free_(mbox->mutex);
mbox->mail = mbox->mutex = NULL;
/* DEBUGF("sys_mbox_free: mbox 0x%lx\n", mbox); */
free(mbox);
}
}
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_post(struct sys_mbox *mbox, void *msg)
{
u8_t first;
sys_sem_wait(mbox->mutex);
DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", mbox, msg));
while((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) {
mbox->wait_send++;
sys_sem_signal(mbox->mutex);
sys_arch_sem_wait(mbox->mail, 0);
sys_arch_sem_wait(mbox->mutex, 0);
mbox->wait_send--;
}
mbox->msgs[mbox->last % SYS_MBOX_SIZE] = msg;
if(mbox->last == mbox->first) {
first = 1;
} else {
first = 0;
}
mbox->last++;
if(first) {
sys_sem_signal(mbox->mail);
}
sys_sem_signal(mbox->mutex);
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, u16_t timeout)
{
u16_t time = 1;
/* The mutex lock is quick so we don't bother with the timeout
stuff here. */
sys_arch_sem_wait(mbox->mutex, 0);
while(mbox->first == mbox->last) {
sys_sem_signal(mbox->mutex);
/* We block while waiting for a mail to arrive in the mailbox. We
must be prepared to timeout. */
if(timeout != 0) {
time = sys_arch_sem_wait(mbox->mail, timeout);
/* If time == 0, the sem_wait timed out, and we return 0. */
if(time == 0) {
return 0;
}
} else {
sys_arch_sem_wait(mbox->mail, 0);
}
sys_arch_sem_wait(mbox->mutex, 0);
}
DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg));
if(msg != NULL) {
*msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE];
}
mbox->first++;
if(mbox->wait_send) {
sys_sem_signal(mbox->mail);
}
sys_sem_signal(mbox->mutex);
return time;
}
/*-----------------------------------------------------------------------------------*/
struct sys_sem *
sys_sem_new(u8_t count)
{
#ifdef SYS_STATS
lwip_stats.sys.sem.used++;
if(lwip_stats.sys.sem.used > lwip_stats.sys.sem.max) {
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
}
#endif /* SYS_STATS */
return sys_sem_new_(count);
}
/*-----------------------------------------------------------------------------------*/
static struct sys_sem *
sys_sem_new_(u8_t count)
{
struct sys_sem *sem;
sem = malloc(sizeof(struct sys_sem));
sem->c = count;
pthread_cond_init(&(sem->cond), NULL);
pthread_mutex_init(&(sem->mutex), NULL);
return sem;
}
/*-----------------------------------------------------------------------------------*/
static u16_t
cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u16_t timeout)
{
int tdiff;
unsigned long sec, usec;
struct timeval rtime1, rtime2;
struct timespec ts;
struct timezone tz;
int retval;
if(timeout > 0) {
/* Get a timestamp and add the timeout value. */
gettimeofday(&rtime1, &tz);
sec = rtime1.tv_sec;
usec = rtime1.tv_usec;
usec += timeout % 1000 * 1000;
sec += (int)(timeout / 1000) + (int)(usec / 1000000);
usec = usec % 1000000;
ts.tv_nsec = usec * 1000;
ts.tv_sec = sec;
retval = pthread_cond_timedwait(cond, mutex, &ts);
if(retval == ETIMEDOUT) {
return 0;
} else {
/* Calculate for how long we waited for the cond. */
gettimeofday(&rtime2, &tz);
tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 +
(rtime2.tv_usec - rtime1.tv_usec) / 1000;
if(tdiff <= 0) {
return 1;
}
return tdiff;
}
} else {
pthread_cond_wait(cond, mutex);
return 0;
}
}
/*-----------------------------------------------------------------------------------*/
u16_t
sys_arch_sem_wait(struct sys_sem *sem, u16_t timeout)
{
u16_t time = 1;
pthread_mutex_lock(&(sem->mutex));
while(sem->c <= 0) {
if(timeout > 0) {
time = cond_wait(&(sem->cond), &(sem->mutex), timeout);
if(time == 0) {
pthread_mutex_unlock(&(sem->mutex));
return 0;
}
/* pthread_mutex_unlock(&(sem->mutex));
return time; */
} else {
cond_wait(&(sem->cond), &(sem->mutex), 0);
}
}
sem->c--;
pthread_mutex_unlock(&(sem->mutex));
return time;
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_signal(struct sys_sem *sem)
{
pthread_mutex_lock(&(sem->mutex));
sem->c++;
if(sem->c > 1) {
sem->c = 1;
}
pthread_cond_broadcast(&(sem->cond));
pthread_mutex_unlock(&(sem->mutex));
}
/*-----------------------------------------------------------------------------------*/
void
sys_sem_free(struct sys_sem *sem)
{
if(sem != SYS_SEM_NULL) {
#ifdef SYS_STATS
lwip_stats.sys.sem.used--;
#endif /* SYS_STATS */
sys_sem_free_(sem);
}
}
/*-----------------------------------------------------------------------------------*/
static void
sys_sem_free_(struct sys_sem *sem)
{
pthread_cond_destroy(&(sem->cond));
pthread_mutex_destroy(&(sem->mutex));
free(sem);
}
/*-----------------------------------------------------------------------------------*/
unsigned long
sys_unix_now()
{
struct timeval tv;
struct timezone tz;
long sec, usec;
unsigned long msec;
gettimeofday(&tv, &tz);
sec = tv.tv_sec - starttime.tv_sec;
usec = tv.tv_usec - starttime.tv_usec;
msec = sec * 1000 + usec / 1000;
return msec;
}
/*-----------------------------------------------------------------------------------*/
void
sys_init()
{
struct timezone tz;
gettimeofday(&starttime, &tz);
}
/*-----------------------------------------------------------------------------------*/
struct sys_timeouts *
sys_arch_timeouts(void)
{
struct sys_thread *thread;
thread = current_thread();
return &thread->timeouts;
}
/*-----------------------------------------------------------------------------------*/

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef u32_t mem_ptr_t;
#define PACK_STRUCT_FIELD(x) x __attribute__((packed))
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
#endif /* __ARCH_CC_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_CPU_H__
#define __ARCH_CPU_H__
#define BYTE_ORDER BIG_ENDIAN
#endif /* __ARCH_CPU_H__ */

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_LIB_H__
#define __ARCH_LIB_H__
#endif /* __ARCH_LIB_H__ */

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __ARCH_PERF_H__
#define __ARCH_PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __ARCH_PERF_H__ */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_XILINX_V2P_H__
#define __SYS_XILINX_V2P_H__
#define SYS_MBOX_NULL 0
#endif /* __SYS_XILINX_V2P_H__ */

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2001, 2002 Xilinx, Inc.
* 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 lwIP TCP/IP stack.
*
* Author: Chris Borrelli <chris.borrelli@xilinx.com>
*
*/
#ifndef __NETIF_XEMACIF_H__
#define __NETIF_XEMACIF_H__
#include "lwip/netif.h"
void xemacif_setmac(u8_t *addr);
u8_t * xemacif_getmac(void);
void xemacif_init(struct netif *netif);
void xemacif_input(void *CallBackRef);
/* define LWIP_XEMAC_USE_INTMODE to make the driver use interrupt mode.
* otherwise, the xemac code will use poll mode. the application
* should check this as well for init stuff
*/
//#define LWIP_XEMAC_USE_INTMODE 1
#endif /* __NETIF_XEMACIF_H__ */

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2001-2003 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. 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 lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/

View File

@ -1,511 +0,0 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Copyright (c) 2001, 2002 Xilinx, Inc.
* 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.
*
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS".
* BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS ONE POSSIBLE
* IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD, XILINX
* IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE FROM
* ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
* ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. XILINX
* EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
* WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Chris Borrelli <chris.borrelli@xilinx.com>
*
* Based on example ethernetif.c, Adam Dunkels <adam@sics.se>
*
*/
/*---------------------------------------------------------------------------*/
/* V2PDK Include Files */
/*---------------------------------------------------------------------------*/
#include "xemac.h"
#include "xparameters.h"
#include "xstatus.h"
#include "xintc.h"
#include "exception.h"
/*---------------------------------------------------------------------------*/
/* LWIP Include Files */
/*---------------------------------------------------------------------------*/
#include "lwip/debug.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "netif/etharp.h"
#include "netif/xemacif.h"
/*---------------------------------------------------------------------------*/
/* Describe network interface */
/*---------------------------------------------------------------------------*/
#define IFNAME0 'e'
#define IFNAME1 '0'
/*---------------------------------------------------------------------------*/
/* Constant Definitions */
/*---------------------------------------------------------------------------*/
#define EMAC_INTR_ID 28 /* Interrupt ID for EMAC */
#define XEM_MAX_FRAME_SIZE_IN_WORDS ((XEM_MAX_FRAME_SIZE/sizeof(Xuint32))+1)
/*---------------------------------------------------------------------------*/
/* xemacif structure */
/* contains the ethernet address and the */
/* pointer to the instance of the Xilinx */
/* EMAC driver. */
/*---------------------------------------------------------------------------*/
struct xemacif {
struct eth_addr *ethaddr;
XEmac *instance_ptr;
};
static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
static struct eth_addr mymac = {{0x00,0x0A,0x35,0x00,0x22,0x20}};
/*---------------------------------------------------------------------------*/
/* Forward declarations */
/*---------------------------------------------------------------------------*/
static err_t xemacif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr);
#ifdef LWIP_XEMAC_USE_INTMODE
static void FifoSendHandler(void *CallBackRef);
static void ErrorHandler(void *CallBackRef, XStatus Code);
#endif /* LWIP_XEMAC_USE_INTMODE */
/*---------------------------------------------------------------------------*/
/* low_level_init function */
/* - hooks up the data structures and sets the mac options and mac */
/*---------------------------------------------------------------------------*/
static err_t
low_level_init(struct netif *netif_ptr)
{
XIntc *IntcInstancePtr;
XEmac * InstancePtr;
Xuint16 DeviceId = XPAR_EMAC_0_DEVICE_ID; /* from xparameters.h */
#ifdef LWIP_XEMAC_USE_INTMODE
Xuint16 IntcDeviceId = XPAR_INTC_0_DEVICE_ID;
#endif /* LWIP_XEMAC_USE_INTMODE */
XStatus Result;
Xuint32 Options;
struct xemacif *xemacif_ptr;
xemacif_ptr = netif_ptr->state;
/* Get Instance of EMAC Driver */
xemacif_ptr->instance_ptr = InstancePtr = XEmac_GetInstance(0);
#ifdef LWIP_XEMAC_USE_INTMODE
/* Get Instance of Interrupt Controller Driver */
IntcInstancePtr = XIntc_GetInstance(0);
#endif /* LWIP_XEMAC_USE_INTMODE */
/* Call Initialize Function of EMAC driver */
Result = XEmac_Initialize(InstancePtr, DeviceId);
if (Result != XST_SUCCESS) {
return ERR_MEM;
}
#ifdef LWIP_XEMAC_USE_INTMODE
if (XIntc_Initialize(IntcInstancePtr, IntcDeviceId) != XST_SUCCESS) {
return ERR_MEM;
}
#endif /* LWIP_XEMAC_USE_INTMODE */
if (XEmac_IsSgDma(InstancePtr)) {
/* not configured for direct FIFO access */
return ERR_MEM;
}
Result = XEmac_SelfTest(InstancePtr);
if (Result != XST_SUCCESS && Result != XST_DEVICE_IS_STARTED) {
return ERR_MEM;
}
#ifdef LWIP_XEMAC_USE_INTMODE
Result = XIntc_SelfTest(IntcInstancePtr);
if (Result != XST_SUCCESS && Result != XST_DEVICE_IS_STARTED) {
return ERR_MEM;
}
#endif /* LWIP_XEMAC_USE_INTMODE */
/* Stop the EMAC hardware */
(void) XEmac_Stop(InstancePtr);
/* Set MAC Address of EMAC */
Result = XEmac_SetMacAddress(InstancePtr, (Xuint8*) netif_ptr->hwaddr);
if (Result != XST_SUCCESS) return ERR_MEM;
/* Set MAC Options - UNICAST and BROADCAST */
#ifdef LWIP_XEMAC_USE_INTMODE
Options = (XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION);
#else /* LWIP_XEMAC_USE_INTMODE */
Options = (XEM_UNICAST_OPTION | XEM_BROADCAST_OPTION | XEM_POLLED_OPTION);
#endif /* LWIP_XEMAC_USE_INTMODE */
Result = XEmac_SetOptions(InstancePtr, Options);
if (Result != XST_SUCCESS) return ERR_MEM;
#ifdef LWIP_XEMAC_USE_INTMODE
/* Set Callbacks and error handler */
XEmac_SetFifoSendHandler(InstancePtr, netif_ptr, FifoSendHandler);
XEmac_SetFifoRecvHandler(InstancePtr, netif_ptr, xemacif_input);
XEmac_SetErrorHandler(InstancePtr, netif_ptr, ErrorHandler);
/* Connect to the interrupt controller and enable interrupts */
XIntc_Connect(IntcInstancePtr, EMAC_INTR_ID,
XEmac_GetIntrHandler(InstancePtr), InstancePtr);
#endif /* LWIP_XEMAC_USE_INTMODE */
/* Start the EMAC hardware */
Result = XEmac_Start(InstancePtr);
if (Result != XST_SUCCESS)
return ERR_MEM;
#ifdef LWIP_XEMAC_USE_INTMODE
if (XST_SUCCESS != XIntc_Start(IntcInstancePtr))
return ERR_MEM;
XIntc_Enable(IntcInstancePtr, EMAC_INTR_ID);
#endif /* LWIP_XEMAC_USE_INTMODE */
return ERR_OK;
}
#ifdef LWIP_XEMAC_USE_INTMODE
/*---------------------------------------------------------------------------*/
/* FifoSendHandler() */
/* */
/* Checks for Tx Errors */
/* TODO: Add actions. Nothing happens if an error is found. */
/* */
/*---------------------------------------------------------------------------*/
static void FifoSendHandler(void *CallBackRef)
{
struct netif *netif_ptr = (struct netif *) CallBackRef;
XEmac *EmacPtr = ((struct xemacif*) netif_ptr->state)->instance_ptr;
XEmacStats Stats;
/*
* Check stats for transmission errors (overrun or underrun errors are
* caught by the asynchronous error handler).
*/
XEmac_GetStats(EmacPtr, &Stats);
if (Stats.XmitLateCollisionErrors || Stats.XmitExcessDeferral)
;
}
/*---------------------------------------------------------------------------*/
/* ErrorHandler() */
/* */
/* Resets the MAC hardware is an error occurs */
/*---------------------------------------------------------------------------*/
static void ErrorHandler(void *CallBackRef, XStatus Code)
{
struct netif *netif_ptr = (struct netif *) CallBackRef;
XEmac *EmacPtr = ((struct xemacif*) netif_ptr->state)->instance_ptr;
if (Code == XST_RESET_ERROR) {
/*
* A reset error means the application should reset the device because
* it encountered a reset condition (most likely a FIFO overrun, but
* can be other reasons). You can look at the XEmac statistics to
* see what the error is.
*/
XEmac_Reset(EmacPtr);
(void)XEmac_SetMacAddress(EmacPtr, (Xuint8*) netif_ptr->hwaddr);
(void)XEmac_SetOptions(EmacPtr,XEM_UNICAST_OPTION|XEM_BROADCAST_OPTION);
(void)XEmac_Start(EmacPtr);
}
}
#endif /* LWIP_XEMAC_USE_INTMODE */
/*---------------------------------------------------------------------------*/
/* low_level_output() */
/* */
/* Should do the actual transmission of the packet. The packet is */
/* contained in the pbuf that is passed to the function. This pbuf */
/* might be chained. */
/*---------------------------------------------------------------------------*/
static err_t low_level_output(struct xemacif *xemacif_ptr, struct pbuf *p)
{
struct pbuf *q;
u32_t frame_buffer[XEM_MAX_FRAME_SIZE_IN_WORDS]; /* word aligned */
Xuint8 *frame_ptr;
int payload_size = 0, i;
XStatus Result;
frame_ptr = (Xuint8 *) frame_buffer;
for(q = p; q != NULL; q = q->next) {
/*
* Send the data from the pbuf to the interface, one pbuf at a
* time. The size of the data in each pbuf is kept in the ->len
* variable.
*/
for(i = 0 ; i < q->len ; i++) {
*(frame_ptr++) = (Xuint8) *(((u8_t *) q->payload) + i);
payload_size++;
}
}
#ifdef LWIP_XEMAC_USE_INTMODE
Result = XEmac_FifoSend(xemacif_ptr->instance_ptr,
(Xuint8 *) frame_buffer,
payload_size);
#else /* LWIP_XEMAC_USE_INTMODE */
Result = XEmac_PollSend(xemacif_ptr->instance_ptr,
(Xuint8 *) frame_buffer,
payload_size);
#endif /* LWIP_XEMAC_USE_INTMODE */
if (Result != XST_SUCCESS) return ERR_MEM;
#ifdef LINK_STATS
lwip_stats.link.xmit++;
#endif /* LINK_STATS */
return ERR_OK;
}
/*---------------------------------------------------------------------------*/
/* low_level_input() */
/* */
/* Allocates a pbuf pool and transfers bytes of */
/* incoming packet from the interface into the pbuf. */
/*---------------------------------------------------------------------------*/
static struct pbuf * low_level_input(struct xemacif *xemacif_ptr)
{
struct pbuf *p = NULL, *q = NULL;
XEmac *EmacPtr = (XEmac *) xemacif_ptr->instance_ptr;
Xuint32 RecvBuffer[XEM_MAX_FRAME_SIZE_IN_WORDS];
Xuint32 FrameLen = XEM_MAX_FRAME_SIZE;
Xuint32 i;
u8_t * frame_bytes = (u8_t *) RecvBuffer;
XStatus Result;
#ifdef CHRIS_DEBUG
char ascii[2];
#endif /* CHRIS_DEBUG */
#ifdef LWIP_XEMAC_USE_INTMODE
Result = XEmac_FifoRecv(EmacPtr, (Xuint8 *)RecvBuffer, &FrameLen);
#else
Result = XEmac_PollRecv(EmacPtr, (Xuint8 *)RecvBuffer, &FrameLen);
#endif /* LWIP_XEMAC_USE_INTMODE */
if (Result != XST_SUCCESS)
return p;
#if 0
printf("\r\n");
for (i=0 ; i < FrameLen ; i++) {
printf("%4X", frame_bytes[i]);
if (! (i%20) && i) printf("\r\n");
else printf(" ");
}
printf ("\r\n");
#endif
/* Allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_LINK, FrameLen, PBUF_POOL);
if(p != NULL) {
/* Iterate over the pbuf chain until we have
* read the entire packet into the pbuf. */
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf
* in the chain. The available data in
* the pbuf is given by the q->len variable. */
for (i = 0 ; i < q->len ; i++) {
((u8_t *)q->payload)[i] = *(frame_bytes++);
}
}
#ifdef LINK_STATS
lwip_stats.link.recv++;
#endif /* LINK_STATS */
} else {
#ifdef LINK_STATS
lwip_stats.link.memerr++;
lwip_stats.link.drop++;
#endif /* LINK_STATS */
;
}
return p;
}
/*---------------------------------------------------------------------------*/
/* xemacif_output(): */
/* */
/* This function is called by the TCP/IP stack when an IP packet */
/* should be sent. It calls the function called low_level_output() to */
/* do the actuall transmission of the packet. */
/*---------------------------------------------------------------------------*/
static err_t xemacif_output(struct netif *netif_ptr,
struct pbuf *p,
struct ip_addr *ipaddr)
{
struct xemacif *xemacif_ptr = xemacif_ptr = netif_ptr->state;
p = etharp_output(netif_ptr, ipaddr, p);
if (p != NULL)
return low_level_output(xemacif_ptr, p);
return ERR_OK;
}
/*---------------------------------------------------------------------------*/
/* xemacif_input(): */
/* */
/* This function should be called when a packet is ready to be read */
/* from the interface. It uses the function low_level_input() that */
/* should handle the actual reception of bytes from the network */
/* interface. */
/*---------------------------------------------------------------------------*/
void xemacif_input(void *CallBackRef)
{
struct netif * netif_ptr = (struct netif *) CallBackRef;
struct xemacif * xemacif_ptr;
struct eth_hdr * ethernet_header;
struct pbuf *p, *q;
#ifdef LWIP_XEMAC_USE_INTMODE
/* Disable Interrupts */
XIntc_Disable(XIntc_GetInstance(0), XPAR_INTC_0_DEVICE_ID);
#endif /* LWIP_XEMAC_USE_INTMODE */
xemacif_ptr = netif_ptr->state;
p = low_level_input(xemacif_ptr);
if(p != NULL) {
ethernet_header = p->payload;
q = NULL;
switch(htons(ethernet_header->type)) {
case ETHTYPE_IP:
q = etharp_ip_input(netif_ptr, p);
pbuf_header(p, -14);
netif_ptr->input(p, netif_ptr);
break;
case ETHTYPE_ARP:
q = etharp_arp_input(netif_ptr, xemacif_ptr->ethaddr, p);
break;
default:
pbuf_free(p);
break;
}
if(q != NULL) {
low_level_output(xemacif_ptr, q);
pbuf_free(q);
}
}
#ifdef LWIP_XEMAC_USE_INTMODE
/* Enable Interrupts again */
XIntc_Enable(XIntc_GetInstance(0), XPAR_INTC_0_DEVICE_ID);
#endif /* LWIP_XEMAC_USE_INTMODE */
}
/*---------------------------------------------------------------------------*/
/* xemacif_setmac(): */
/* */
/* Sets the MAC address of the system. */
/* Note: Can only be called before xemacif_init is called. */
/*---------------------------------------------------------------------------*/
void xemacif_setmac(u8_t *addr)
{
mymac.addr[0] = addr[0];
mymac.addr[1] = addr[1];
mymac.addr[2] = addr[2];
mymac.addr[3] = addr[3];
mymac.addr[4] = addr[4];
mymac.addr[5] = addr[5];
}
/*---------------------------------------------------------------------------*/
/* xemacif_getmac(): */
/* */
/* Returns a pointer to the mymac variable (6 bytes in length) */
/*---------------------------------------------------------------------------*/
u8_t * xemacif_getmac(void) { return &(mymac.addr[0]); }
/*---------------------------------------------------------------------------*/
/* xemacif_init(): */
/* */
/* Should be called at the beginning of the program to set up the */
/* network interface. It calls the function low_level_init() to do the */
/* actual setup of the hardware. */
/*---------------------------------------------------------------------------*/
void xemacif_init(struct netif *netif_ptr)
{
struct xemacif *xemacif_ptr;
xemacif_ptr = mem_malloc(sizeof(struct xemacif));
netif_ptr->state = xemacif_ptr;
netif_ptr->hwaddr[0] = mymac.addr[0];
netif_ptr->hwaddr[1] = mymac.addr[1];
netif_ptr->hwaddr[2] = mymac.addr[2];
netif_ptr->hwaddr[3] = mymac.addr[3];
netif_ptr->hwaddr[4] = mymac.addr[4];
netif_ptr->hwaddr[5] = mymac.addr[5];
netif_ptr->name[0] = IFNAME0;
netif_ptr->name[1] = IFNAME1;
netif_ptr->output = xemacif_output;
netif_ptr->linkoutput = NULL;
/* Copy pointer to netif_ptr->hwaddr into the xemacif_ptr->ethaddr */
xemacif_ptr->ethaddr = (struct eth_addr *)&(netif_ptr->hwaddr[0]);
/* Set EXmac instance pointer to NULL. It gets set in low_level_init() */
xemacif_ptr->instance_ptr = NULL;
low_level_init(netif_ptr);
etharp_init();
}