diff options
| author | itspy.wei <[email protected]> | 2010-11-26 16:27:45 +0000 |
|---|---|---|
| committer | itspy.wei <[email protected]> | 2010-11-26 16:27:45 +0000 |
| commit | f438f02b0fb2e4a8730bd49dfd9312b5204b097b (patch) | |
| tree | 0bfda853fbbb016a1922a6f0ba2f291d323ec7ea /components/net/uip/rt-thread | |
| parent | a9424c09e12e09c309d30eb79e2b59f177133aac (diff) | |
add uip
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1125 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/net/uip/rt-thread')
| -rw-r--r-- | components/net/uip/rt-thread/clock-arch.c | 50 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/clock-arch.h | 40 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/readme.txt | 12 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uIPmain.c | 127 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip-conf.h | 167 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_addr.h | 8 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_arch.c | 143 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_eth.h | 35 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_etharp.c | 58 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_etharp.h | 15 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_ethernetif.c | 313 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_ethernetif.h | 31 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_ipaddr.h | 20 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_netif.c | 53 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_netif.h | 269 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_pbuf.c | 50 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_pbuf.h | 87 | ||||
| -rw-r--r-- | components/net/uip/rt-thread/uip_tcpip.c | 41 |
18 files changed, 1519 insertions, 0 deletions
diff --git a/components/net/uip/rt-thread/clock-arch.c b/components/net/uip/rt-thread/clock-arch.c new file mode 100644 index 0000000000..0c00d83ff5 --- /dev/null +++ b/components/net/uip/rt-thread/clock-arch.c @@ -0,0 +1,50 @@ +/*
+ * Copyright (c) 2006, 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 uIP TCP/IP stack
+ *
+ * $Id: clock-arch.c,v 1.2 2006/06/12 08:00:31 adam Exp $
+ */
+
+/**
+ * \file
+ * Implementation of architecture-specific clock functionality
+ * \author
+ * Adam Dunkels <[email protected]>
+ */
+
+#include "clock-arch.h"
+#include "stm32f10x.h"
+
+/*---------------------------------------------------------------------------*/
+clock_time_t
+clock_time(void)
+{
+ return (rt_tick_get());
+}
+/*---------------------------------------------------------------------------*/
diff --git a/components/net/uip/rt-thread/clock-arch.h b/components/net/uip/rt-thread/clock-arch.h new file mode 100644 index 0000000000..0c4649d3ae --- /dev/null +++ b/components/net/uip/rt-thread/clock-arch.h @@ -0,0 +1,40 @@ +/*
+ * Copyright (c) 2006, 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 uIP TCP/IP stack
+ *
+ * $Id: clock-arch.h,v 1.2 2006/06/12 08:00:31 adam Exp $
+ */
+
+#ifndef __CLOCK_ARCH_H__
+#define __CLOCK_ARCH_H__
+
+typedef int clock_time_t;
+#define CLOCK_CONF_SECOND 100
+
+#endif /* __CLOCK_ARCH_H__ */
diff --git a/components/net/uip/rt-thread/readme.txt b/components/net/uip/rt-thread/readme.txt new file mode 100644 index 0000000000..d20386dfe2 --- /dev/null +++ b/components/net/uip/rt-thread/readme.txt @@ -0,0 +1,12 @@ +/************************************
+***
+***
+****
+******/
+
+
+
+2010-11-21
+��̫���е����������������ͻ���ɶ������⣿
+2010-11-21
+����һ�����⣺HELLO WORLD�в������ӣ��Ͽ����֮��֮����Ҳ�������ӣ���
\ No newline at end of file diff --git a/components/net/uip/rt-thread/uIPmain.c b/components/net/uip/rt-thread/uIPmain.c new file mode 100644 index 0000000000..089747472d --- /dev/null +++ b/components/net/uip/rt-thread/uIPmain.c @@ -0,0 +1,127 @@ +/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Adam Dunkels.
+ * 4. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack.
+ *
+ * $Id: main.c,v 1.16 2006/06/11 21:55:03 adam Exp $
+ *
+ */
+#include "uip.h"
+#include "uip_arp.h"
+#include "stm32_eth.h"
+#include "rtconfig.h"
+#include "rtdef.h"
+#include "uip_timer.h"
+#include "rtthread.h"
+
+
+
+
+
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+// Define Prototypes
+void TransmitPacket(void)
+{
+ int i;
+ u8_t data[1500];
+ // Copy the header portion part
+ for(i=0; i < (UIP_LLH_LEN + 40); ++i)
+ {
+ data[i] = uip_buf[i];
+ }
+ // Copy the data portion part
+ for(; i < uip_len; ++i)
+ {
+ data[i] = uip_appdata[i - UIP_LLH_LEN - 40 ];
+ }
+ ETH_HandleTxPkt(data,uip_len);
+}
+void uip_tcpip_thread(void *parameter)
+{
+ int i;
+ static u8_t cnt;
+ while(1)
+ {
+ rt_thread_delay(CLOCK_SECOND*5);
+ for (i = 0; i < UIP_CONNS; i++)
+ {
+ uip_periodic(i);
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if (uip_len > 0)
+ {
+ uip_arp_out();
+ TransmitPacket();
+ }
+ }
+#if UIP_UDP
+ for (i = 0; i < UIP_UDP_CONNS; i++)
+ {
+ uip_udp_periodic(i);
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if (uip_len > 0)
+ {
+ uip_arp_out();
+ TransmitPacket();
+ }
+ }
+#endif /* UIP_UDP */
+ /* Call the ARP timer function every 10 seconds. */
+ if (++cnt > 2) uip_arp_timer();
+ }
+}
+
+rt_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)
+{
+ rt_thread_t t;
+ t = rt_thread_create(name, thread, arg, stacksize, prio, 20);
+ RT_ASSERT(t != RT_NULL);
+ rt_thread_startup(t);
+ return t;
+}
+
+
+void uip_sys_init(void)
+{
+
+ uip_init(); //uip init
+ sys_thread_new("uip",uip_tcpip_thread, RT_NULL, RT_LWIP_TCPTHREAD_STACKSIZE, RT_LWIP_TCPTHREAD_PRIORITY);
+ hello_world_init(); //
+}
+
+/*---------------------------------------------------------------------------*/
+void uip_log(char *m)
+{
+ rt_kprintf("uIP log message: %s\n", m);
+}
diff --git a/components/net/uip/rt-thread/uip-conf.h b/components/net/uip/rt-thread/uip-conf.h new file mode 100644 index 0000000000..9c2a25044c --- /dev/null +++ b/components/net/uip/rt-thread/uip-conf.h @@ -0,0 +1,167 @@ +/**
+ * \addtogroup uipopt
+ * @{
+ */
+
+/**
+ * \name Project-specific configuration options
+ * @{
+ *
+ * uIP has a number of configuration options that can be overridden
+ * for each project. These are kept in a project-specific uip-conf.h
+ * file and all configuration names have the prefix UIP_CONF.
+ */
+
+/*
+ * Copyright (c) 2006, 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 uIP TCP/IP stack
+ *
+ * $Id: uip-conf.h,v 1.6 2006/06/12 08:00:31 adam Exp $
+ */
+
+/**
+ * \file
+ * An example uIP configuration file
+ * \author
+ * Adam Dunkels <[email protected]>
+ */
+
+#ifndef __UIP_CONF_H__
+#define __UIP_CONF_H__
+
+#include <inttypes.h>
+
+/**
+ * 8 bit datatype
+ *
+ * This typedef defines the 8-bit type used throughout uIP.
+ *
+ * \hideinitializer
+ */
+typedef uint8_t u8_t;
+
+/**
+ * 16 bit datatype
+ *
+ * This typedef defines the 16-bit type used throughout uIP.
+ *
+ * \hideinitializer
+ */
+typedef uint16_t u16_t;
+
+/**
+ * Statistics datatype
+ *
+ * This typedef defines the dataype used for keeping statistics in
+ * uIP.
+ *
+ * \hideinitializer
+ */
+typedef unsigned short uip_stats_t;
+
+/**
+ * Maximum number of TCP connections.
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_MAX_CONNECTIONS 20
+
+/**
+ * Maximum number of listening TCP ports.
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_MAX_LISTENPORTS 40
+
+/**
+ * uIP buffer size.
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_BUFFER_SIZE 420
+
+/**
+ * CPU byte order.
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_BYTE_ORDER LITTLE_ENDIAN
+
+/**
+ * Logging on or off
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_LOGGING 1
+
+/**
+ * UDP support on or off
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_UDP 0
+
+/**
+ * UDP checksums on or off
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_UDP_CHECKSUMS 1
+
+/**
+ * uIP statistics on or off
+ *
+ * \hideinitializer
+ */
+#define UIP_CONF_STATISTICS 1
+
+/* Here we include the header file for the application(s) we use in
+ our project. */
+/* #include "smtp.h" */
+#include "hello-world.h"
+//#include "telnetd.h"
+/* #include "webserver.h" */
+/* #include "dhcpc.h" */
+/* #include "resolv.h" */
+/* #include "webclient.h" */
+
+#define UIP_ARCH_ADD32 0
+
+#define UIP_ETHADDR0 0x00
+#define UIP_ETHADDR1 0x33
+#define UIP_ETHADDR2 0x44
+#define UIP_ETHADDR3 0x55
+#define UIP_ETHADDR4 0x66
+#define UIP_ETHADDR5 0x77
+#include <rtthread.h>
+
+#endif /* __UIP_CONF_H__ */
+
+/** @} */
+/** @} */
diff --git a/components/net/uip/rt-thread/uip_addr.h b/components/net/uip/rt-thread/uip_addr.h new file mode 100644 index 0000000000..859477a0e3 --- /dev/null +++ b/components/net/uip/rt-thread/uip_addr.h @@ -0,0 +1,8 @@ +
+#include "rtdef.h"
+
+
+
+struct ip_addr {
+ rt_uint16_t uip_ip4addr_t[2];
+} ;
\ No newline at end of file diff --git a/components/net/uip/rt-thread/uip_arch.c b/components/net/uip/rt-thread/uip_arch.c new file mode 100644 index 0000000000..d41ee2b4a3 --- /dev/null +++ b/components/net/uip/rt-thread/uip_arch.c @@ -0,0 +1,143 @@ +/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack.
+ *
+ * $Id: uip_arch.c,v 1.2.2.1 2003/10/04 22:54:17 adam Exp $
+ *
+ */
+
+
+#include "uip.h"
+#include "uip_arch.h"
+
+#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
+#define IP_PROTO_TCP 6
+
+/*-----------------------------------------------------------------------------------*/
+void uip_add32(u8_t *op32, u16_t op16)
+{
+
+ uip_acc32[3] = op32[3] + (op16 & 0xff);
+ uip_acc32[2] = op32[2] + (op16 >> 8);
+ uip_acc32[1] = op32[1];
+ uip_acc32[0] = op32[0];
+
+ if(uip_acc32[2] < (op16 >> 8)) {
+ ++uip_acc32[1];
+ if(uip_acc32[1] == 0) {
+ ++uip_acc32[0];
+ }
+ }
+
+
+ if(uip_acc32[3] < (op16 & 0xff)) {
+ ++uip_acc32[2];
+ if(uip_acc32[2] == 0) {
+ ++uip_acc32[1];
+ if(uip_acc32[1] == 0) {
+ ++uip_acc32[0];
+ }
+ }
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t uip_chksum(u16_t *sdata, u16_t len)
+{
+ u16_t acc;
+
+ for (acc = 0; len > 1; len -= 2) {
+ u16_t u = ((unsigned char *)sdata)[0] + (((unsigned char *)sdata)[1] << 8);
+ if ((acc += u) < u) {
+ /* Overflow, so we add the carry to acc (i.e., increase by
+ one). */
+ ++acc;
+ }
+ ++sdata;
+ }
+
+ /* add up any odd byte */
+ if(len == 1) {
+ acc += htons(((u16_t)(*(u8_t *)sdata)) << 8);
+ if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) {
+ ++acc;
+ }
+ }
+
+ return acc;
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t uip_ipchksum(void)
+{
+ return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20);
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t uip_tcpchksum(void)
+{
+ u16_t hsum, sum;
+
+
+ /* Compute the checksum of the TCP header. */
+ hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20);
+
+ /* Compute the checksum of the data in the TCP packet and add it to
+ the TCP header checksum. */
+ sum = uip_chksum((u16_t *)uip_appdata,
+ (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40)));
+
+ if((sum += hsum) < hsum) {
+ ++sum;
+ }
+
+ if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) {
+ ++sum;
+ }
+ if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) {
+ ++sum;
+ }
+ if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) {
+ ++sum;
+ }
+ if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) {
+ ++sum;
+ }
+
+ if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) {
+ ++sum;
+ }
+
+ hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20);
+
+ if((sum += hsum) < hsum) {
+ ++sum;
+ }
+
+ return sum;
+}
+
+
diff --git a/components/net/uip/rt-thread/uip_eth.h b/components/net/uip/rt-thread/uip_eth.h new file mode 100644 index 0000000000..e0a8ba8ba9 --- /dev/null +++ b/components/net/uip/rt-thread/uip_eth.h @@ -0,0 +1,35 @@ +#ifndef __NETIF_ETHERNETIF_H__
+#define __NETIF_ETHERNETIF_H__
+
+//#include "lwip/netif.h"
+#include <rtthread.h>
+
+#define NIOCTL_GADDR 0x01
+#define ETHERNET_MTU 1500
+struct pbuf
+{
+ rt_uint16_t len;
+};
+
+struct eth_device
+{
+ /* inherit from rt_device */
+ struct rt_device parent;
+
+ //struct eth_addr *ethaddr;
+ //struct netif *netif;
+ struct rt_semaphore tx_ack;
+ struct rt_semaphore tx_msg;
+
+ /* eth device interface */
+ struct pbuf* (*eth_rx)(rt_device_t dev);
+ rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p);
+};
+
+rt_err_t eth_device_ready(struct eth_device* dev);
+
+rt_err_t eth_device_init(struct eth_device* dev, const char* name);
+
+rt_err_t eth_system_device_init(void);
+
+#endif /* __NETIF_ETHERNETIF_H__ */
diff --git a/components/net/uip/rt-thread/uip_etharp.c b/components/net/uip/rt-thread/uip_etharp.c new file mode 100644 index 0000000000..a2d15a17a2 --- /dev/null +++ b/components/net/uip/rt-thread/uip_etharp.c @@ -0,0 +1,58 @@ +#include "uip_pbuf.h"
+#include "uip-conf.h"
+#include "rtdef.h"
+#include "uip.h"
+#include "uip_arp.h"
+#include "uip_netif.h"
+
+extern u16_t uip_len, uip_slen;
+void
+etharp_ip_input(struct netif *netif, struct pbuf *p)
+{
+ u8_t *ptr;
+ int i;
+ ptr = p->payload;
+ uip_len = p->len;
+ for (i=0;i<p->len;i++) uip_buf[i] = ptr[i];
+ uip_arp_ipin();
+ uip_input();
+ return;
+}
+void
+etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
+{
+ u8_t *ptr,*pdata;
+ //struct pbuf *q;
+ int i;
+ ptr = p->payload;
+ uip_len = p->len;
+ for (i=0;i<p->len;i++) uip_buf[i] = ptr[i];
+ uip_arp_arpin(); //update arp table uip_arp_arpin
+ if (uip_len)
+ {
+ if (( pdata =(u8_t*)rt_malloc(1500*sizeof(u8_t))) ==RT_NULL)
+ {
+ pbuf_free(p);
+ return;
+ }
+ for (i=0; i < (UIP_LLH_LEN + 40); ++i)
+ {
+ pdata[i] = uip_buf[i];
+ }
+ for (; i < uip_len; ++i)
+ {
+ pdata[i] = uip_appdata[i - UIP_LLH_LEN - 40 ];
+ }
+ //q = p;
+ p ->payload = pdata;
+ p->len = uip_len;
+ netif->linkoutput(netif,p);
+ rt_free(pdata);
+ pbuf_free(p);
+ // pbuf_free(q);
+ return ;
+
+ // return 0; //ERR_OK
+ }
+ pbuf_free(p);
+}
\ No newline at end of file diff --git a/components/net/uip/rt-thread/uip_etharp.h b/components/net/uip/rt-thread/uip_etharp.h new file mode 100644 index 0000000000..bf8ff1f726 --- /dev/null +++ b/components/net/uip/rt-thread/uip_etharp.h @@ -0,0 +1,15 @@ +#include "uip_pbuf.h"
+#include "uip-conf.h"
+#include "rtdef.h"
+
+
+struct eth_hdr {
+ u8_t ip_addrdest[6];
+ u8_t ip_addrsrc[6];
+ u16_t type;
+} ;
+#define ETHTYPE_ARP UIP_ETHTYPE_ARP
+#define ETHTYPE_IP UIP_ETHTYPE_IP
+#define ETHTYPE_VLAN 0x8100
+#define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
+#define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
diff --git a/components/net/uip/rt-thread/uip_ethernetif.c b/components/net/uip/rt-thread/uip_ethernetif.c new file mode 100644 index 0000000000..aaa25150a0 --- /dev/null +++ b/components/net/uip/rt-thread/uip_ethernetif.c @@ -0,0 +1,313 @@ +/*
+ * File : ethernetif.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-07-07 Bernard fix ethernetif_linkoutput send mail issue.
+ */
+
+/*
+ * Copyright (c) 2001-2004 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 <[email protected]>
+ *
+ */
+
+#include <rtthread.h>
+#include "uip.h"
+#include "uip_arp.h"
+#include "uip_netif.h"
+#include "uip_ethernetif.h"
+#include "uip_ipaddr.h"
+
+#ifndef NULL
+#define NULL (void *)0
+#endif /* NULL */
+
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+extern u16_t uip_len, uip_slen;
+
+/* eth rx/tx thread */
+static struct rt_mailbox eth_rx_thread_mb;
+static struct rt_thread eth_rx_thread;
+#ifndef RT_LWIP_ETHTHREAD_PRIORITY
+#define RT_ETHERNETIF_THREAD_PREORITY 0x90
+static char eth_rx_thread_mb_pool[48 * 4];
+static char eth_rx_thread_stack[1024];
+#else
+#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY
+static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4];
+static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
+#endif
+
+struct eth_tx_msg
+{
+ struct netif *netif;
+ struct pbuf *buf;
+};
+static struct rt_mailbox eth_tx_thread_mb;
+static struct rt_thread eth_tx_thread;
+#ifndef RT_LWIP_ETHTHREAD_PRIORITY
+static char eth_tx_thread_mb_pool[32 * 4];
+static char eth_tx_thread_stack[512];
+#else
+static char eth_tx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4];
+static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
+#endif
+
+/* the interface provided to uIP */
+err_t eth_init(struct netif *netif)
+{
+ return 0;
+}
+extern err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p);
+
+err_t eth_input(struct pbuf *p,struct netif *inp)
+{
+
+ struct eth_hdr *ethhdr;
+
+ if(p != RT_NULL)
+ {
+#ifdef LINK_STATS
+ //LINK_STATS_INC(link.recv);
+#endif LINK_STATS
+
+ ethhdr = p->payload;
+
+ switch(uip_htons(ethhdr->type))
+ {
+ case ETHTYPE_IP: //ETHTYPE_IP
+ etharp_ip_input(inp, p);
+ pbuf_header(p, -((rt_int16_t)sizeof(struct eth_hdr)));
+ if (tcpip_input(p, inp) != ERR_OK)
+ {
+ // discard packet
+ pbuf_free(p);
+ }
+ break;
+
+ case ETHTYPE_ARP:
+ etharp_arp_input(inp, (struct eth_addr *)inp->hwaddr, p);
+ break;
+
+ default:
+ pbuf_free(p);
+ p = RT_NULL;
+ break;
+ }
+ }
+ return ERR_OK;
+}
+
+err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
+{
+ return etharp_output(netif, p, ipaddr);
+}
+
+err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
+{
+ struct eth_tx_msg msg;
+ struct eth_device* enetif;
+
+ enetif = (struct eth_device*)netif->state;
+
+ /* send a message to eth tx thread */
+ msg.netif = netif;
+ msg.buf = p;
+ if (rt_mb_send(ð_tx_thread_mb, (rt_uint32_t) &msg) == RT_EOK)
+ {
+ /* waiting for ack */
+ rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER);
+ }
+
+ return ERR_OK;
+}
+/* ethernetif APIs */
+rt_err_t eth_device_init(struct eth_device* dev, const char* name)
+{
+ struct netif* netif;
+ uip_ipaddr_t ipaddr;
+ netif = (struct netif*) rt_malloc (sizeof(struct netif));
+ if (netif == RT_NULL)
+ {
+ rt_kprintf("malloc netif failed\n");
+ return -RT_ERROR;
+ }
+ rt_memset(netif, 0, sizeof(struct netif));
+
+ /* set netif */
+ dev->netif = netif;
+ /* register to rt-thread device manager */
+ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
+ dev->parent.type = RT_Device_Class_NetIf;
+ rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);
+
+ /* set name */
+ netif->name[0] = name[0];
+ netif->name[1] = name[1];
+
+ /* set hw address to 6 */
+ netif->hwaddr_len = 6;
+ /* maximum transfer unit */
+ netif->mtu = ETHERNET_MTU;
+ /* broadcast capability */
+ netif->flags = NETIF_FLAG_BROADCAST;
+
+#if LWIP_IGMP
+ /* igmp support */
+ netif->flags |= NETIF_FLAG_IGMP;
+#endif
+
+ /* get hardware address */
+ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
+
+ /* set output */
+ netif->output = ethernetif_output;
+ netif->linkoutput = ethernetif_linkoutput;
+
+ /* add netif to lwip */
+
+ if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
+ eth_init, eth_input) == RT_NULL)
+ {
+ /* failed, unregister device and free netif */
+ rt_device_unregister(&(dev->parent));
+ rt_free(netif);
+ return -RT_ERROR;
+ }
+
+ netif_set_default(netif);
+ return RT_EOK;
+}
+
+/* ethernet buffer */
+void eth_tx_thread_entry(void* parameter)
+{
+ struct eth_tx_msg* msg;
+
+ while (1)
+ {
+ if (rt_mb_recv(ð_tx_thread_mb, (rt_uint32_t*)&msg, RT_WAITING_FOREVER) == RT_EOK)
+ {
+ struct eth_device* enetif;
+
+ RT_ASSERT(msg->netif != RT_NULL);
+ RT_ASSERT(msg->buf != RT_NULL);
+
+ enetif = (struct eth_device*)msg->netif->state;
+ if (enetif != RT_NULL)
+ {
+ /* call driver's interface */
+ if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK)
+ {
+ rt_kprintf("transmit eth packet failed\n");
+ }
+ }
+
+ /* send ack */
+ rt_sem_release(&(enetif->tx_ack));
+ }
+ }
+}
+
+/* ethernet buffer */
+void eth_rx_thread_entry(void* parameter)
+{
+ struct eth_device* device;
+
+ while (1)
+ {
+ if (rt_mb_recv(ð_rx_thread_mb, (rt_uint32_t*)&device, RT_WAITING_FOREVER) == RT_EOK)
+ {
+ struct pbuf *p;
+
+ /* receive all of buffer */
+ while (1)
+ {
+ p = device->eth_rx(&(device->parent));
+ if (p != RT_NULL)
+ {
+ /* notify to upper layer */
+ eth_input(p, device->netif);
+ }
+ else break;
+ }
+ }
+ }
+}
+
+rt_err_t eth_device_ready(struct eth_device* dev)
+{
+ /* post message to ethernet thread */
+ return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
+}
+
+rt_err_t eth_system_device_init()
+{
+ rt_err_t result = RT_EOK;
+
+ /* init rx thread */
+ /* init mailbox and create ethernet thread */
+ result = rt_mb_init(ð_rx_thread_mb, "erxmb",
+ ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4,
+ RT_IPC_FLAG_FIFO);
+ RT_ASSERT(result == RT_EOK);
+
+ result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL,
+ ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
+ RT_ETHERNETIF_THREAD_PREORITY, 16);
+ RT_ASSERT(result == RT_EOK);
+
+ result = rt_thread_startup(ð_rx_thread);
+ RT_ASSERT(result == RT_EOK);
+
+ /* init tx thread */
+ /* init mailbox and create ethernet thread */
+
+ result = rt_mb_init(ð_tx_thread_mb, "etxmb",
+ ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4,
+ RT_IPC_FLAG_FIFO);
+ RT_ASSERT(result == RT_EOK);
+
+ result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL,
+ ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack),
+ RT_ETHERNETIF_THREAD_PREORITY, 16);
+ RT_ASSERT(result == RT_EOK);
+
+ result = rt_thread_startup(ð_tx_thread);
+ RT_ASSERT(result == RT_EOK);
+
+ return result;
+}
diff --git a/components/net/uip/rt-thread/uip_ethernetif.h b/components/net/uip/rt-thread/uip_ethernetif.h new file mode 100644 index 0000000000..612d053008 --- /dev/null +++ b/components/net/uip/rt-thread/uip_ethernetif.h @@ -0,0 +1,31 @@ +#ifndef __NETIF_ETHERNETIF_H__
+#define __NETIF_ETHERNETIF_H__
+
+//#include "lwip/netif.h"
+#include "uip_netif.h"
+#include <rtthread.h>
+
+#define NIOCTL_GADDR 0x01
+#define ETHERNET_MTU 1500
+
+struct eth_device
+{
+ /* inherit from rt_device */
+ struct rt_device parent;
+
+ struct eth_addr *ethaddr;
+ struct netif *netif;
+ struct rt_semaphore tx_ack;
+
+ /* eth device interface */
+ struct pbuf* (*eth_rx)(rt_device_t dev);
+ rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p);
+};
+
+rt_err_t eth_device_ready(struct eth_device* dev);
+
+rt_err_t eth_device_init(struct eth_device* dev, const char* name);
+
+rt_err_t eth_system_device_init(void);
+
+#endif /* __NETIF_ETHERNETIF_H__ */
diff --git a/components/net/uip/rt-thread/uip_ipaddr.h b/components/net/uip/rt-thread/uip_ipaddr.h new file mode 100644 index 0000000000..8f9e99b34a --- /dev/null +++ b/components/net/uip/rt-thread/uip_ipaddr.h @@ -0,0 +1,20 @@ +
+#include "rtdef.h"
+
+
+
+
+
+
+/* ethernetif APIs */
+#define IP_ADDR_ANY_VALUE 0x00000000UL
+#define IP_ADDR_BROADCAST_VALUE 0xffffffffUL
+
+//extern const struct ip_addr ip_addr_any;
+//extern const struct ip_addr ip_addr_broadcast;
+
+/** IP_ADDR_ can be used as a fixed IP address
+ * for the wildcard and the broadcast address
+ */
+#define IP_ADDR_ANY ((struct ip_addr *)0)
+#define IP_ADDR_BROADCAST ((struct ip_addr *)0)
\ No newline at end of file diff --git a/components/net/uip/rt-thread/uip_netif.c b/components/net/uip/rt-thread/uip_netif.c new file mode 100644 index 0000000000..cd70ba31ab --- /dev/null +++ b/components/net/uip/rt-thread/uip_netif.c @@ -0,0 +1,53 @@ +#include "rtdef.h"
+#include "uip-conf.h"
+#include "uip.h"
+#include "uip_netif.h"
+#include "uip_arp.h"
+#include "rtconfig.h"
+#include "uip_pbuf.h"
+
+void netif_set_default(struct netif *netif)
+{
+
+}
+void netif_set_addr(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
+ struct ip_addr *gw)
+{
+ uip_ipaddr_t hipaddr;
+ uip_ipaddr(hipaddr, RT_LWIP_IPADDR0,RT_LWIP_IPADDR1,RT_LWIP_IPADDR2,RT_LWIP_IPADDR3);
+ uip_sethostaddr(hipaddr);
+ uip_ipaddr(hipaddr, RT_LWIP_GWADDR0,RT_LWIP_GWADDR1,RT_LWIP_GWADDR2,RT_LWIP_GWADDR3);
+ uip_setdraddr(hipaddr);
+ uip_ipaddr(hipaddr, RT_LWIP_MSKADDR0,RT_LWIP_MSKADDR1,RT_LWIP_MSKADDR2,RT_LWIP_MSKADDR3);
+ uip_setnetmask(hipaddr);
+ return ;
+}
+
+struct netif *
+netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
+ struct ip_addr *gw,
+ void *state,
+ err_t (* init)(struct netif *netif),
+ err_t (* input)(struct pbuf *p, struct netif *netif))
+{
+ //if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
+ //eth_init, eth_input) == RT_NULL)
+ // netif->uip_hostaddr = ipaddr;
+ //netif->uip_draddr = netmask;
+ // netif->uip_netmask = gw;
+ // netif_set_addr(netif,ipaddr,netmask,gw);
+
+ // call user specified initialization function for netif
+ if (init(netif) != 0) {
+ return RT_NULL;
+ }
+ netif->input = input;
+ netif->state = state;
+ netif_set_addr(netif,ipaddr,netmask,gw);
+ return netif;
+
+}
+err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr)
+{
+ return 0;
+}
diff --git a/components/net/uip/rt-thread/uip_netif.h b/components/net/uip/rt-thread/uip_netif.h new file mode 100644 index 0000000000..5cef2bb7ad --- /dev/null +++ b/components/net/uip/rt-thread/uip_netif.h @@ -0,0 +1,269 @@ +/*
+ * Copyright (c) 2001-2004 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 <[email protected]>
+ *
+ */
+#ifndef __LWIP_NETIF_H__
+#define __LWIP_NETIF_H__
+
+//#include "lwip/opt.h"
+
+#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
+
+#include "lwip/err.h"
+
+#include "uip_ipaddr.h"
+
+//#include "lwip/inet.h"
+//#include "lwip/pbuf.h"
+#include "uip_pbuf.h"
+#include "uip-conf.h"
+
+#if LWIP_DHCP
+struct dhcp;
+#endif
+#if LWIP_AUTOIP
+struct autoip;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Throughout this file, IP addresses are expected to be in
+ * the same byte order as in IP_PCB. */
+
+/** must be the maximum of all used hardware address lengths
+ across all types of interfaces in use */
+#define NETIF_MAX_HWADDR_LEN 6U
+
+/** TODO: define the use (where, when, whom) of netif flags */
+
+/** whether the network interface is 'up'. this is
+ * a software flag used to control whether this network
+ * interface is enabled and processes traffic.
+ */
+#define NETIF_FLAG_UP 0x01U
+/** if set, the netif has broadcast capability */
+#define NETIF_FLAG_BROADCAST 0x02U
+/** if set, the netif is one end of a point-to-point connection */
+#define NETIF_FLAG_POINTTOPOINT 0x04U
+/** if set, the interface is configured using DHCP */
+#define NETIF_FLAG_DHCP 0x08U
+/** if set, the interface has an active link
+ * (set by the network interface driver) */
+#define NETIF_FLAG_LINK_UP 0x10U
+/** if set, the netif is an device using ARP */
+#define NETIF_FLAG_ETHARP 0x20U
+/** if set, the netif has IGMP capability */
+#define NETIF_FLAG_IGMP 0x40U
+
+/** Generic data structure used for all lwIP network interfaces.
+ * The following fields should be filled in by the initialization
+ * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
+struct ip_addr {
+ rt_uint16_t uip_ip4addr_t[2];
+} ;
+
+struct netif {
+ /** pointer to next in linked list */
+ struct netif *next;
+
+ /** IP address configuration in network byte order */
+ struct ip_addr ip_addr;
+ struct ip_addr netmask;
+ struct ip_addr gw;
+
+ /** This function is called by the network device driver
+ * to pass a packet up the TCP/IP stack. */
+ err_t (* input)(struct pbuf *p, struct netif *inp);
+ /** This function is called by the IP module when it wants
+ * to send a packet on the interface. This function typically
+ * first resolves the hardware address, then sends the packet. */
+ err_t (* output)(struct netif *netif, struct pbuf *p,
+ struct ip_addr *ipaddr);
+ /** This function is called by the ARP module when it wants
+ * to send a packet on the interface. This function outputs
+ * the pbuf as-is on the link medium. */
+ err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
+#if LWIP_NETIF_STATUS_CALLBACK
+ /** This function is called when the netif state is set to up or down
+ */
+ void (* status_callback)(struct netif *netif);
+#endif /* LWIP_NETIF_STATUS_CALLBACK */
+#if LWIP_NETIF_LINK_CALLBACK
+ /** This function is called when the netif link is set to up or down
+ */
+ void (* link_callback)(struct netif *netif);
+#endif /* LWIP_NETIF_LINK_CALLBACK */
+ /** This field can be set by the device driver and could point
+ * to state information for the device. */
+ void *state;
+#if LWIP_DHCP
+ /** the DHCP client state information for this netif */
+ struct dhcp *dhcp;
+#endif /* LWIP_DHCP */
+#if LWIP_AUTOIP
+ /** the AutoIP client state information for this netif */
+ struct autoip *autoip;
+#endif
+#if LWIP_NETIF_HOSTNAME
+ /* the hostname for this netif, NULL is a valid value */
+ char* hostname;
+#endif /* LWIP_NETIF_HOSTNAME */
+ /** maximum transfer unit (in bytes) */
+ u16_t mtu;
+ /** number of bytes used in hwaddr */
+ u8_t hwaddr_len;
+ /** link level hardware address of this interface */
+ u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
+ /** flags (see NETIF_FLAG_ above) */
+ u8_t flags;
+ /** descriptive abbreviation */
+ char name[2];
+ /** number of this interface */
+ u8_t num;
+#if LWIP_SNMP
+ /** link type (from "snmp_ifType" enum from snmp.h) */
+ u8_t link_type;
+ /** (estimate) link speed */
+ u32_t link_speed;
+ /** timestamp at last change made (up/down) */
+ u32_t ts;
+ /** counters */
+ u32_t ifinoctets;
+ u32_t ifinucastpkts;
+ u32_t ifinnucastpkts;
+ u32_t ifindiscards;
+ u32_t ifoutoctets;
+ u32_t ifoutucastpkts;
+ u32_t ifoutnucastpkts;
+ u32_t ifoutdiscards;
+#endif /* LWIP_SNMP */
+#if LWIP_IGMP
+ /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
+ err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
+#endif /* LWIP_IGMP */
+#if LWIP_NETIF_HWADDRHINT
+ u8_t *addr_hint;
+#endif /* LWIP_NETIF_HWADDRHINT */
+#if ENABLE_LOOPBACK
+ /* List of packets to be queued for ourselves. */
+ struct pbuf *loop_first;
+ struct pbuf *loop_last;
+#if LWIP_LOOPBACK_MAX_PBUFS
+ u16_t loop_cnt_current;
+#endif /* LWIP_LOOPBACK_MAX_PBUFS */
+#endif /* ENABLE_LOOPBACK */
+};
+
+#if LWIP_SNMP
+#define NETIF_INIT_SNMP(netif, type, speed) \
+ /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
+ netif->link_type = type; \
+ /* your link speed here (units: bits per second) */ \
+ netif->link_speed = speed; \
+ netif->ts = 0; \
+ netif->ifinoctets = 0; \
+ netif->ifinucastpkts = 0; \
+ netif->ifinnucastpkts = 0; \
+ netif->ifindiscards = 0; \
+ netif->ifoutoctets = 0; \
+ netif->ifoutucastpkts = 0; \
+ netif->ifoutnucastpkts = 0; \
+ netif->ifoutdiscards = 0
+#else /* LWIP_SNMP */
+#define NETIF_INIT_SNMP(netif, type, speed)
+#endif /* LWIP_SNMP */
+
+
+/** The list of network interfaces. */
+extern struct netif *netif_list;
+/** The default network interface. */
+extern struct netif *netif_default;
+
+#define netif_init() /* Compatibility define, not init needed. */
+
+struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
+ struct ip_addr *gw,
+ void *state,
+ err_t (* init)(struct netif *netif),
+ err_t (* input)(struct pbuf *p, struct netif *netif));
+
+void
+netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
+ struct ip_addr *gw);
+void netif_remove(struct netif * netif);
+
+/* Returns a network interface given its name. The name is of the form
+ "et0", where the first two letters are the "name" field in the
+ netif structure, and the digit is in the num field in the same
+ structure. */
+struct netif *netif_find(char *name);
+
+void netif_set_default(struct netif *netif);
+
+void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
+void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
+void netif_set_gw(struct netif *netif, struct ip_addr *gw);
+
+void netif_set_up(struct netif *netif);
+void netif_set_down(struct netif *netif);
+u8_t netif_is_up(struct netif *netif);
+
+#if LWIP_NETIF_STATUS_CALLBACK
+/*
+ * Set callback to be called when interface is brought up/down
+ */
+void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
+#endif /* LWIP_NETIF_STATUS_CALLBACK */
+
+#if LWIP_NETIF_LINK_CALLBACK
+void netif_set_link_up(struct netif *netif);
+void netif_set_link_down(struct netif *netif);
+u8_t netif_is_link_up(struct netif *netif);
+/*
+ * Set callback to be called when link is brought up/down
+ */
+void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
+#endif /* LWIP_NETIF_LINK_CALLBACK */
+
+#ifdef __cplusplus
+}
+#endif
+
+#if ENABLE_LOOPBACK
+err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
+void netif_poll(struct netif *netif);
+#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
+void netif_poll_all(void);
+#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
+#endif /* ENABLE_LOOPBACK */
+
+#endif /* __LWIP_NETIF_H__ */
diff --git a/components/net/uip/rt-thread/uip_pbuf.c b/components/net/uip/rt-thread/uip_pbuf.c new file mode 100644 index 0000000000..69ff3b5a6d --- /dev/null +++ b/components/net/uip/rt-thread/uip_pbuf.c @@ -0,0 +1,50 @@ +#include "uip_pbuf.h"
+#include "rtdef.h"
+
+typedef rt_uint32_t mem_ptr_t;
+#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + RT_ALIGN_SIZE - 1) & ~(mem_ptr_t)(RT_ALIGN_SIZE-1)))
+#define LWIP_MEM_ALIGN_SIZE(size) (((size) + RT_ALIGN_SIZE - 1) & ~(RT_ALIGN_SIZE-1))
+#define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
+
+u8_t
+pbuf_free(struct pbuf *p)
+{
+
+ //struct pbuf *q;
+
+ if (p == RT_NULL) return 0;
+ rt_free(p);
+ //rt_free(&p->len);
+
+ return 1;
+}
+
+struct pbuf *
+pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
+{
+ struct pbuf *p;
+ u16_t offset = 0;
+ offset += 16;
+
+ /* If pbuf is to be allocated in RAM, allocate memory for it. */
+ p = (struct pbuf*)rt_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
+ if (p == RT_NULL) return RT_NULL;
+ /* Set up internal structure of the pbuf. */
+ p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
+ p->len = length;
+ return p;
+}
+
+u8_t
+pbuf_header(struct pbuf *p, s16_t header_size_increment) //
+{
+ //extrat link header
+ uint8_t *ptr;
+
+ ptr = p->payload;
+ ptr -= header_size_increment;
+ p->payload = ptr;
+ p->len += header_size_increment;
+
+ return 0;
+}
\ No newline at end of file diff --git a/components/net/uip/rt-thread/uip_pbuf.h b/components/net/uip/rt-thread/uip_pbuf.h new file mode 100644 index 0000000000..284dec87fc --- /dev/null +++ b/components/net/uip/rt-thread/uip_pbuf.h @@ -0,0 +1,87 @@ +
+#ifndef __UIP_PBUF_H__
+#define __UIP_PBUF_H__
+
+//#include "lwip/opt.h"
+//#include "lwip/err.h"
+#include "uip-conf.h"
+#include "uip_etharp.h"
+
+typedef rt_int16_t s16_t;
+typedef rt_int8_t err_t;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PBUF_TRANSPORT_HLEN 20
+#define PBUF_IP_HLEN 20
+
+typedef enum {
+ PBUF_TRANSPORT,
+ PBUF_IP,
+ PBUF_LINK,
+ PBUF_RAW
+} pbuf_layer;
+
+typedef enum {
+ PBUF_RAM, /* pbuf data is stored in RAM */
+ PBUF_ROM, /* pbuf data is stored in ROM */
+ PBUF_REF, /* pbuf comes from the pbuf pool */
+ PBUF_POOL /* pbuf payload refers to RAM */
+} pbuf_type;
+
+
+/** indicates this packet's data should be immediately passed to the application */
+#define PBUF_FLAG_PUSH 0x01U
+#ifdef RT_USING_LWIP
+struct pbuf {
+ /** next pbuf in singly linked pbuf chain */
+ struct pbuf *next;
+
+ /** pointer to the actual data in the buffer */
+ void *payload;
+
+ /**
+ * total length of this buffer and all next buffers in chain
+ * belonging to the same packet.
+ *
+ * For non-queue packet chains this is the invariant:
+ * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
+ */
+ u16_t tot_len;
+
+ /** length of this buffer */
+ u16_t len;
+
+ /** pbuf_type as u8_t instead of enum to save space */
+ u8_t /*pbuf_type*/ type;
+
+ /** misc flags */
+ u8_t flags;
+
+ /**
+ * the reference count always equals the number of pointers
+ * that refer to this pbuf. This can be pointers from an application,
+ * the stack itself, or pbuf->next pointers from a chain.
+ */
+ u16_t ref;
+
+};
+#else /* RT_USING_UIP */
+struct pbuf
+{
+ /** pointer to the actual data in the buffer */
+ void *payload;
+ rt_uint16_t len;
+};
+#endif
+/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
+
+
+struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_type type);
+
+u8_t pbuf_header(struct pbuf *p, s16_t header_size);
+
+u8_t pbuf_free(struct pbuf *p);
+
+#endif /* __UIP_PBUF_H__ */
diff --git a/components/net/uip/rt-thread/uip_tcpip.c b/components/net/uip/rt-thread/uip_tcpip.c new file mode 100644 index 0000000000..4cedb05864 --- /dev/null +++ b/components/net/uip/rt-thread/uip_tcpip.c @@ -0,0 +1,41 @@ +#include "uip_pbuf.h"
+#include "uip-conf.h"
+#include "rtdef.h"
+#include "uip.h"
+#include "uip_arp.h"
+#include "uip_netif.h"
+
+err_t
+tcpip_input(struct pbuf *p, struct netif *inp)
+{
+ int i;
+ u8_t *pdata;
+ if (uip_len)
+ {
+ uip_arp_out();
+ if (( pdata =(u8_t*)rt_malloc(1500*sizeof(u8_t))) == RT_NULL)
+ {
+ pbuf_free(p);
+ return 1;
+ }
+ for (i=0; i < (UIP_LLH_LEN + 40); ++i) // 14+40 =54
+ {
+ pdata[i] = uip_buf[i]; /* get dest an src ipaddr */
+ }
+ // Copy the data portion part
+ for(; i < uip_len; ++i)
+ {
+ pdata[i] = uip_appdata[i - UIP_LLH_LEN - 40 ];
+ }
+ p ->payload = pdata;
+ p->len = uip_len;
+ inp->linkoutput(inp,p);
+ rt_free(pdata);
+ return 1;
+ }
+ else
+ {
+ pbuf_free(p);
+ return 0;
+ }
+}
\ No newline at end of file |
