Breaking uip.c into smaller functions/files

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@374 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2007-11-06 23:38:14 +00:00
parent db8aff6778
commit 81d093e29e
19 changed files with 972 additions and 386 deletions
+1
View File
@@ -218,4 +218,5 @@
* Basic client functionality verified: socket(), bind(), connect(), recv(), send().
0.3.1 2007-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Separated net/uip/uip.c into several functions in several files.
+2
View File
@@ -674,6 +674,8 @@ Other memory:
<pre><ul>
0.3.1 2007-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
* Separated net/uip/uip.c into several functions in several files.
</pre></ul>
<table width ="100%">
-1
View File
@@ -49,7 +49,6 @@ o Network
Add a txail callback into driver to eliminate send delays. Since we want to
support multiple network devices, this means we will have to add some infrastructure
to map to device.
- Break uip_interrupt() (in uip.c) into several functions.
- uIP polling issues:
(1) uIP expects a single driver to poll at a 500ms interval (dm90x0 currently
polls a 5sec).
-3
View File
@@ -79,9 +79,6 @@
#define UIP_DRV_RECEIVE 1
#define UIP_DRV_TIMER 2
#define UIP_DRV_POLL 3
#ifdef CONFIG_NET_UDP
# define UIP_DRV_UDPPOLL 4
#endif
/****************************************************************************
* Public Types
+2 -2
View File
@@ -215,7 +215,7 @@ struct uip_udp_conn
#endif /* CONFIG_NET_UDP */
/* The structure holding the TCP/IP statistics that are gathered if
* UIP_STATISTICS is set to 1.
* CONFIG_NET_STATISTICS is defined.
*/
struct uip_stats
@@ -499,7 +499,7 @@ extern uint8 uip_flags;
* TCP/IP stack.
*/
void uip_init(void);
void uip_initialize(void);
/* This function may be used at boot time to set the initial ip_id.*/
-11
View File
@@ -260,17 +260,6 @@
# define UIP_BUFSIZE CONFIG_NET_BUFFER_SIZE
#endif /* CONFIG_NET_BUFFER_SIZE */
/* Determines if statistics support should be compiled in.
*
* The statistics is useful for debugging and to show the user.
*/
#ifndef CONFIG_NET_STATISTICS
# define UIP_STATISTICS 0
#else /* CONFIG_NET_STATISTICS */
# define UIP_STATISTICS CONFIG_NET_STATISTICS
#endif /* CONFIG_NET_STATISTICS */
/* Broadcast support.
*
* This flag configures IP broadcast support. This is useful only
+1 -1
View File
@@ -100,7 +100,7 @@ void net_initialize(void)
{
/* Initialize the uIP layer */
uip_init();
uip_initialize();
/* Initialize the socket layer */
+1 -1
View File
@@ -259,7 +259,7 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags)
struct send_s state;
irqstate_t save;
int err;
int ret;
int ret = OK;
/* Verify that the sockfd corresponds to valid, allocated socket */
+17 -3
View File
@@ -14,7 +14,7 @@
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name Gregory Nutt nor the names of its contributors may be
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
@@ -34,6 +34,20 @@
############################################################################
UIP_ASRCS =
UIP_CSRCS = uip-arp.c uip.c uip-send.c uip-fw.c uip-neighbor.c uip-split.c \
uip-tcpconn.c uip-udpconn.c uip-listen.c uip-poll.c
UIP_CSRCS =
ifeq ($(CONFIG_NET),y)
UIP_CSRCS += uip-initialize.c uip-arp.c uip.c uip-send.c uip-fw.c \
uip-neighbor.c uip-split.c uip-tcpconn.c uip-listen.c \
uip-poll.c uip-chksum.c
ifeq ($(CONFIG_NET_UDP),y)
UIP_CSRCS += uip-udpconn.c uip-udppoll.c uip-udpsend.c uip-udpinput.c \
uip-udpcallback.c
endif
endif
+212
View File
@@ -0,0 +1,212 @@
/****************************************************************************
* net/uip/uip-chksum.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
*
* 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 NuttX 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 COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_NET
#include <sys/types.h>
#include <debug.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
#include "uip-internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
#if !UIP_ARCH_CHKSUM
static uint16 chksum(uint16 sum, const uint8 *data, uint16 len)
{
uint16 t;
const uint8 *dataptr;
const uint8 *last_byte;
dataptr = data;
last_byte = data + len - 1;
while(dataptr < last_byte)
{
/* At least two more bytes */
t = (dataptr[0] << 8) + dataptr[1];
sum += t;
if (sum < t)
{
sum++; /* carry */
}
dataptr += 2;
}
if (dataptr == last_byte)
{
t = (dataptr[0] << 8) + 0;
sum += t;
if (sum < t)
{
sum++; /* carry */
}
}
/* Return sum in host byte order. */
return sum;
}
static uint16 upper_layer_chksum(struct uip_driver_s *dev, uint8 proto)
{
uint16 upper_layer_len;
uint16 sum;
#ifdef CONFIG_NET_IPv6
upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]);
#else /* CONFIG_NET_IPv6 */
upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
#endif /* CONFIG_NET_IPv6 */
/* First sum pseudoheader. */
/* IP protocol and length fields. This addition cannot carry. */
sum = upper_layer_len + proto;
/* Sum IP source and destination addresses. */
sum = chksum(sum, (uint8 *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
/* Sum TCP header and data. */
sum = chksum(sum, &dev->d_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
#ifdef CONFIG_NET_IPv6
static uint16 uip_icmp6chksum(struct uip_driver_s *dev)
{
return upper_layer_chksum(dev, UIP_PROTO_ICMP6);
}
#endif /* CONFIG_NET_IPv6 */
#endif /* UIP_ARCH_CHKSUM */
/****************************************************************************
* Public Functions
****************************************************************************/
/* Calculate the Internet checksum over a buffer. */
#if !UIP_ARCH_ADD32
void uip_add32(uint8 *op32, uint16 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];
}
}
}
}
#endif /* UIP_ARCH_ADD32 */
#if !UIP_ARCH_CHKSUM
uint16 uip_chksum(uint16 *data, uint16 len)
{
return htons(chksum(0, (uint8 *)data, len));
}
/* Calculate the IP header checksum of the packet header in d_buf. */
#ifndef UIP_ARCH_IPCHKSUM
uint16 uip_ipchksum(struct uip_driver_s *dev)
{
uint16 sum;
sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif
/* Calculate the TCP checksum of the packet in d_buf and d_appdata. */
uint16 uip_tcpchksum(struct uip_driver_s *dev)
{
return upper_layer_chksum(dev, UIP_PROTO_TCP);
}
/* Calculate the UDP checksum of the packet in d_buf and d_appdata. */
#ifdef CONFIG_NET_UDP_CHECKSUMS
uint16 uip_udpchksum(struct uip_driver_s *dev)
{
return upper_layer_chksum(dev, UIP_PROTO_UDP);
}
#endif /* UIP_UDP_CHECKSUMS */
#endif /* UIP_ARCH_CHKSUM */
#endif /* CONFIG_NET */
+105
View File
@@ -0,0 +1,105 @@
/****************************************************************************
* net/uip/uip-udppoll.c
* Poll for the availability of UDP TX data
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
*
* Original author Adam Dunkels <adam@dunkels.com>
* Copyright () 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_NET
#include <net/uip/uip.h>
#include "uip-internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: uip_initialize
*
* Description:
* Perform initialization of the uIP layer
*
* Parameters:
* None
*
* Return:
* None
*
****************************************************************************/
void uip_initialize(void)
{
/* Initialize the listening port structures */
uip_listeninit();
/* Initialize the TCP/IP connection structures */
uip_tcpinit();
/* Initialize the UDP connection structures */
#ifdef CONFIG_NET_UDP
uip_udpinit();
#endif
/* IPv4 initialization. */
}
#endif /* CONFIG_NET */
+44 -6
View File
@@ -43,6 +43,9 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_NET
#include <sys/types.h>
#include <errno.h>
#include <arch/irq.h>
@@ -63,6 +66,10 @@
extern const uip_ipaddr_t all_ones_addr;
extern const uip_ipaddr_t all_zeroes_addr;
/* Increasing number used for the IP ID field. */
extern uint16 g_ipid;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -83,21 +90,52 @@ EXTERN struct uip_conn *uip_tcplistener(uint16 portno);
EXTERN struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf);
EXTERN void uip_tcpnextsequence(void);
/* Defined in uip_udpconn.c *************************************************/
EXTERN void uip_udpinit(void);
EXTERN struct uip_udp_conn *uip_udpactive(struct uip_udpip_hdr *buf);
EXTERN struct uip_udp_conn *uip_nextudpconn(struct uip_udp_conn *conn);
/* Defined in uip_listen.c **************************************************/
EXTERN void uip_listeninit(void);
EXTERN boolean uip_islistener(uint16 port);
EXTERN int uip_accept(struct uip_conn *conn, uint16 portno);
#ifdef CONFIG_NET_UDP
/* Defined in uip_udpconn.c *************************************************/
EXTERN void uip_udpinit(void);
EXTERN struct uip_udp_conn *uip_udpactive(struct uip_udpip_hdr *buf);
EXTERN struct uip_udp_conn *uip_nextudpconn(struct uip_udp_conn *conn);
/* Defined in uip-udppool.c *************************************************/
EXTERN void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn);
/* Defined in uip-udpsend.c *************************************************/
EXTERN void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn);
/* Defined in uip-udpinput.c ************************************************/
EXTERN void uip_udpinput(struct uip_driver_s *dev);
/* Defined in uip_uipcallback.c *********************************************/
EXTERN void uip_udpcallback(struct uip_driver_s *dev);
#endif /* CONFIG_NET_UDP */
/* UIP logging **************************************************************/
/* This function must be provided by the application if CONFIG_NET_LOGGING
* is defined.
*/
#ifdef CONFIG_NET_LOGGING
EXTERN void uip_log(char *msg);
#else
# define uip_log(m)
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_NET */
#endif /* __UIP_INTERNAL_H */
+2 -25
View File
@@ -58,33 +58,12 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: uip_udppoll()
*
* Description:
* Periodic processing for a UDP connection identified by its number.
* This function does the necessary periodic processing (timers,
* polling) for a uIP TCP conneciton, and should be called by the UIP
* device driver when the periodic uIP timer goes off. It should be
* called for every connection, regardless of whether they are open of
* closed.
*
* Assumptions:
* This function is called from the CAN device driver may be called from
* the timer interrupt/watchdog handle level.
*
****************************************************************************/
static inline void uip_udppoll(struct uip_driver_s *dev, unsigned int conn)
{
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: uip-poll
* Function: uip_poll
*
* Description:
* This function will traverse each active uIP connection structure and
@@ -143,15 +122,13 @@ int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback, int event)
udp_conn = NULL;
while ((udp_conn = uip_nextudpconn(udp_conn)))
{
uip_udp_conn = udp_conn;
uip_interrupt(dev, UIP_DRV_UDPPOLL);
uip_udppoll(dev, udp_conn);
if (callback(dev))
{
irqrestore(flags);
return 1;
}
}
uip_udp_conn = NULL;
#endif /* CONFIG_NET_UDP */
irqrestore(flags);
+90
View File
@@ -0,0 +1,90 @@
/****************************************************************************
* net/uip/uip-udpcallback.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
*
* 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 NuttX 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 COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
#include <sys/types.h>
#include <debug.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
#include "uip-internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: uip_udpcallback
*
* Description:
* Inform the application holding the UDP socket of a change in state.
*
* Assumptions:
* This function is called at the interrupt level with interrupts disabled.
*
****************************************************************************/
void uip_udpcallback(struct uip_driver_s *dev)
{
vdbg("uip_flags: %02x\n", uip_flags);
/* Some sanity checking */
if (uip_udp_conn && uip_udp_conn->event)
{
/* Perform the callback */
uip_udp_conn->event(dev, uip_udp_conn->private);
}
}
#endif /* CONFIG_NET && CONFIG_NET_UDP */
+156
View File
@@ -0,0 +1,156 @@
/****************************************************************************
* net/uip/uip-udpinput.c
* Handling incoming UDP input
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
*
* Original author Adam Dunkels <adam@dunkels.com>
* Copyright () 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
#include <sys/types.h>
#include <debug.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
#include "uip-internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
#define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: uip_udpinput
*
* Description:
* Handle incoming UDP input
*
* Parameters:
* dev - The device driver structure containing the received UDP packet
*
* Return:
* None
*
* Assumptions:
* Called from the interrupt level or with interrupts disabled.
*
****************************************************************************/
void uip_udpinput(struct uip_driver_s *dev)
{
/* UDP processing is really just a hack. We don't do anything to the UDP/IP
* headers, but let the UDP application do all the hard work. If the
* application sets d_sndlen, it has a packet to send.
*/
dev->d_len -= UIP_IPUDPH_LEN;
#ifdef CONFIG_NET_UDP_CHECKSUMS
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
if (UDPBUF->udpchksum != 0 && uip_udpchksum(dev) != 0xffff)
{
#ifdef CONFIG_NET_STATISTICS
uip_stat.udp.drop++;
uip_stat.udp.chkerr++;
#endif
uip_log("udp: bad checksum.");
dev->d_len = 0;
}
else
#endif
{
/* Demultiplex this UDP packet between the UDP "connections". */
uip_udp_conn = uip_udpactive(UDPBUF);
if (uip_udp_conn)
{
/* Setup for the application callback */
uip_conn = NULL;
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_sndlen = 0;
/* Perform the application callback */
uip_flags = UIP_NEWDATA;
uip_udpcallback(dev);
uip_flags = 0;
/* If the application has data to send, setup the UDP/IP header */
if (dev->d_sndlen > 0)
{
uip_udpsend(dev, uip_udp_conn);
}
uip_udp_conn = NULL;
}
else
{
uip_log("udp: no matching connection found");
dev->d_len = 0;
}
}
return;
}
#endif /* CONFIG_NET && CONFIG_NET_UDP */
+134
View File
@@ -0,0 +1,134 @@
/****************************************************************************
* net/uip/uip-udppoll.c
* Poll for the availability of UDP TX data
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
*
* Original author Adam Dunkels <adam@dunkels.com>
* Copyright () 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
#include <sys/types.h>
#include <debug.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
#include "uip-internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: uip_udppoll
*
* Description:
* Poll a UDP "connection" structure for availability of TX data
*
* Parameters:
* dev - The device driver structure to use in the send operation
* conn - The UDP "connection" to poll for TX data
*
* Return:
* None
*
* Assumptions:
* Called from the interrupt level or with interrupts disabled.
*
****************************************************************************/
void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn)
{
/* Verify that the UDP connection is valid */
if (conn->lport != 0)
{
/* Setup for the application callback */
uip_conn = NULL;
uip_udp_conn = conn;
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_len = 0;
dev->d_sndlen = 0;
/* Perform the application callback */
uip_flags = UIP_POLL;
uip_udpcallback(dev);
/* If the application has data to send, setup the UDP/IP header */
if (dev->d_sndlen > 0)
{
uip_udpsend(dev, conn);
uip_udp_conn = NULL;
uip_flags = 0;
return;
}
}
/* Make sure that d_len is zerp meaning that there is nothing to be sent */
dev->d_len = 0;
uip_udp_conn = NULL;
uip_flags = 0;
}
#endif /* CONFIG_NET && CONFIG_NET_UDP */
+176
View File
@@ -0,0 +1,176 @@
/****************************************************************************
* net/uip/uip-udpsend.c
* Poll for the availability of UDP TX data
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
*
* Original author Adam Dunkels <adam@dunkels.com>
* Copyright () 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
#include <sys/types.h>
#include <debug.h>
#include <net/uip/uipopt.h>
#include <net/uip/uip.h>
#include <net/uip/uip-arch.h>
#include "uip-internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
#define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: uip_udpsend
*
* Description:
* Setup to send a UDP packet
*
* Parameters:
* dev - The device driver structure to use in the send operation
* conn - The UDP "connection" structure holding port information
*
* Return:
* None
*
* Assumptions:
* Called from the interrupt level or with interrupts disabled.
*
****************************************************************************/
void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn)
{
if (dev->d_sndlen == 0)
{
/* The total lenth to send is the size of the application data plus
* the IP and UDP headers (and, eventually, the ethernet header)
*/
dev->d_len = dev->d_sndlen + UIP_IPUDPH_LEN;
/* Initialize the IP header. Note that for IPv6, the IP length field
* does not include the IPv6 IP header length.
*/
#ifdef CONFIG_NET_IPv6
UDPBUF->vtc = 0x60;
UDPBUF->tcf = 0x00;
UDPBUF->flow = 0x00;
UDPBUF->len[0] = (dev->d_sndlen >> 8);
UDPBUF->len[1] = (dev->d_sndlen & 0xff);
UDPBUF->proto = UIP_PROTO_UDP;
UDPBUF->ttl = conn->ttl;
uip_ipaddr_copy(UDPBUF->srcipaddr, &dev->d_ipaddr);
uip_ipaddr_copy(UDPBUF->destipaddr, &conn->ripaddr);
#else /* CONFIG_NET_IPv6 */
UDPBUF->vhl = 0x45;
UDPBUF->tos = 0;
UDPBUF->len[0] = (dev->d_len >> 8);
UDPBUF->len[1] = (dev->d_len & 0xff);
++g_ipid;
UDPBUF->ipid[0] = g_ipid >> 8;
UDPBUF->ipid[1] = g_ipid & 0xff;
UDPBUF->ipoffset[0] = 0;
UDPBUF->ipoffset[1] = 0;
UDPBUF->ttl = conn->ttl;
UDPBUF->proto = UIP_PROTO_UDP;
/* Calculate IP checksum. */
UDPBUF->ipchksum = 0;
UDPBUF->ipchksum = ~(uip_ipchksum(dev));
uiphdr_ipaddr_copy(UDPBUF->srcipaddr, &dev->d_ipaddr);
uiphdr_ipaddr_copy(UDPBUF->destipaddr, &conn->ripaddr);
#endif /* CONFIG_NET_IPv6 */
/* Initialize the UDP header */
UDPBUF->srcport = conn->lport;
UDPBUF->destport = conn->rport;
UDPBUF->udplen = HTONS(dev->d_sndlen + UIP_UDPH_LEN);
#ifdef CONFIG_NET_UDP_CHECKSUMS
/* Calculate UDP checksum. */
UDPBUF->udpchksum = ~(uip_udpchksum(dev));
if (UDPBUF->udpchksum == 0)
{
UDPBUF->udpchksum = 0xffff;
}
#else
UDPBUF->udpchksum = 0;
#endif /* UIP_UDP_CHECKSUMS */
vdbg("Outgoing UDP packet length: %d (%d)\n",
dev->d_len, (UDPBUF->len[0] << 8) | UDPBUF->len[1]);
#ifdef CONFIG_NET_STATISTICS
uip_stat.udp.sent++;
uip_stat.ip.sent++;
#endif
}
}
#endif /* CONFIG_NET && CONFIG_NET_UDP */
+27 -331
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -164,7 +164,7 @@ static void tcp_stats(struct httpd_state *pstate, char *ptr)
#ifdef CONFIG_HTTPDCGI_NETSTATS
static void net_stats(struct httpd_state *pstate, char *ptr)
{
#if UIP_STATISTICS
#ifdef CONFIG_NET_STATISTICS
char buffer[16];
for(pstate->count = 0; pstate->count < sizeof(uip_stat) / sizeof(uip_stats_t); ++pstate->count)
@@ -172,6 +172,6 @@ static void net_stats(struct httpd_state *pstate, char *ptr)
snprintf(buffer, 16, "%5u\n", ((uip_stats_t *)&uip_stat)[pstate->count]);
send(pstate->sockout, buffer, strlen(buffer), 0);
}
#endif /* UIP_STATISTICS */
#endif
}
#endif