mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 13:18:50 +08:00
Move UDP files from net/uip to net/udp
This commit is contained in:
parent
3aca3430c4
commit
382920b9a9
10 changed files with 89 additions and 335 deletions
|
@ -104,6 +104,7 @@ include arp/Make.defs
|
|||
include icmp/Make.defs
|
||||
include igmp/Make.defs
|
||||
include tcp/Make.defs
|
||||
include udp/Make.defs
|
||||
include uip/Make.defs
|
||||
endif
|
||||
|
||||
|
|
51
net/udp/Make.defs
Normal file
51
net/udp/Make.defs
Normal file
|
@ -0,0 +1,51 @@
|
|||
############################################################################
|
||||
# net/udp/Make.defs
|
||||
#
|
||||
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
|
||||
# UDP source files
|
||||
|
||||
ifeq ($(CONFIG_NET_UDP),y)
|
||||
|
||||
NET_CSRCS += udp_conn.c udp_poll.c udp_send.c udp_input.c udp_callback.c
|
||||
|
||||
# Include uip build support
|
||||
|
||||
DEPPATH += --dep-path udp
|
||||
VPATH += :udp
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)net$(DELIM)udp}
|
||||
|
||||
endif # CONFIG_NET_UDP
|
||||
endif # CONFIG_NET
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_udpcallback.c
|
||||
* net/udp/udp_callback.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
@ -47,7 +47,7 @@
|
|||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
#include "uip/uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_udpconn.c
|
||||
* net/udp/udp_conn.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
@ -60,7 +60,7 @@
|
|||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
#include "uip/uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_udpinput.c
|
||||
* net/udp/udp_input.c
|
||||
* Handling incoming UDP input
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
|
@ -51,7 +51,7 @@
|
|||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
#include "uip/uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_udppoll.c
|
||||
* net/udp/udp_poll.c
|
||||
* Poll for the availability of UDP TX data
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
|
@ -51,7 +51,7 @@
|
|||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
#include "uip/uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_udpsend.c
|
||||
* net/udp/udp_send.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
@ -50,7 +50,7 @@
|
|||
#include <nuttx/net/uip/uip.h>
|
||||
#include <nuttx/net/uip/uip-arch.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
#include "uip/uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
|
@ -61,15 +61,6 @@ ifeq ($(CONFIG_NET_IPv6),y)
|
|||
NET_CSRCS += uip_neighbor.c
|
||||
endif
|
||||
|
||||
# UDP source files
|
||||
|
||||
ifeq ($(CONFIG_NET_UDP),y)
|
||||
|
||||
NET_CSRCS += uip_udpconn.c uip_udppoll.c uip_udpsend.c uip_udpinput.c
|
||||
NET_CSRCS += uip_udpcallback.c
|
||||
|
||||
endif
|
||||
|
||||
# Include uip build support
|
||||
|
||||
DEPPATH += --dep-path uip
|
||||
|
|
|
@ -126,7 +126,7 @@ void uip_pktpoll(struct uip_driver_s *dev, struct uip_pkt_conn *conn);
|
|||
#endif /* CONFIG_NET_PKT */
|
||||
|
||||
#ifdef CONFIG_NET_TCP
|
||||
/* Defined in uip_tcpconn.c *************************************************/
|
||||
/* Defined in tcp_conn.c ****************************************************/
|
||||
|
||||
void uip_tcpinit(void);
|
||||
struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf);
|
||||
|
@ -134,7 +134,7 @@ struct uip_conn *uip_nexttcpconn(struct uip_conn *conn);
|
|||
struct uip_conn *uip_tcplistener(uint16_t portno);
|
||||
struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf);
|
||||
|
||||
/* Defined in uip_tcpseqno.c ************************************************/
|
||||
/* Defined in tcp_seqno.c ***************************************************/
|
||||
|
||||
void uip_tcpsetsequence(FAR uint8_t *seqno, uint32_t value);
|
||||
uint32_t uip_tcpgetsequence(FAR uint8_t *seqno);
|
||||
|
@ -142,21 +142,21 @@ uint32_t uip_tcpaddsequence(FAR uint8_t *seqno, uint16_t len);
|
|||
void uip_tcpinitsequence(FAR uint8_t *seqno);
|
||||
void uip_tcpnextsequence(void);
|
||||
|
||||
/* Defined in uip_tcppoll.c *************************************************/
|
||||
/* Defined in tcp_poll.c ****************************************************/
|
||||
|
||||
void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn);
|
||||
|
||||
/* Defined in uip_udptimer.c ************************************************/
|
||||
/* Defined in tcp_timer.c ***************************************************/
|
||||
|
||||
void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec);
|
||||
|
||||
/* Defined in uip_listen.c **************************************************/
|
||||
/* Defined in tcp_listen.c **************************************************/
|
||||
|
||||
void uip_listeninit(void);
|
||||
bool uip_islistener(uint16_t port);
|
||||
int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, uint16_t portno);
|
||||
|
||||
/* Defined in uip_tcpsend.c *************************************************/
|
||||
/* Defined in tcp_send.c ****************************************************/
|
||||
|
||||
void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint16_t flags, uint16_t len);
|
||||
|
@ -164,18 +164,18 @@ void uip_tcpreset(struct uip_driver_s *dev);
|
|||
void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint8_t ack);
|
||||
|
||||
/* Defined in uip_tcpappsend.c **********************************************/
|
||||
/* Defined in tcp_appsend.c *************************************************/
|
||||
|
||||
void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint16_t result);
|
||||
void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint16_t result);
|
||||
|
||||
/* Defined in uip_tcpinput.c ************************************************/
|
||||
/* Defined in tcp_input.c ***************************************************/
|
||||
|
||||
void uip_tcpinput(struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in uip_tcpcallback.c *********************************************/
|
||||
/* Defined in tcp_callback.c ************************************************/
|
||||
|
||||
uint16_t uip_tcpcallback(FAR struct uip_driver_s *dev,
|
||||
FAR struct uip_conn *conn, uint16_t flags);
|
||||
|
@ -184,7 +184,7 @@ uint16_t uip_datahandler(FAR struct uip_conn *conn,
|
|||
FAR uint8_t *buffer, uint16_t nbytes);
|
||||
#endif
|
||||
|
||||
/* Defined in uip_tcpreadahead.c ********************************************/
|
||||
/* Defined in tcp_readahead.c ***********************************************/
|
||||
|
||||
#ifdef CONFIG_NET_TCP_READAHEAD
|
||||
void uip_tcpreadahead_init(void);
|
||||
|
@ -194,7 +194,7 @@ FAR struct uip_readahead_s *uip_tcpreadahead_alloc(void);
|
|||
void uip_tcpreadahead_release(FAR struct uip_readahead_s *readahead);
|
||||
#endif /* CONFIG_NET_TCP_READAHEAD */
|
||||
|
||||
/* Defined in uip_tcpwrbuffer.c *********************************************/
|
||||
/* Defined in tcp_wrbuffer.c ************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
void uip_tcpwrbuffer_init(void);
|
||||
|
@ -208,41 +208,41 @@ void uip_tcpwrbuffer_release(FAR struct uip_wrbuffer_s *wrbuffer);
|
|||
#endif /* CONFIG_NET_TCP */
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
/* Defined in uip_udpconn.c *************************************************/
|
||||
/* Defined in udp_conn.c ****************************************************/
|
||||
|
||||
void uip_udpinit(void);
|
||||
struct uip_udp_conn *uip_udpactive(struct uip_udpip_hdr *buf);
|
||||
struct uip_udp_conn *uip_nextudpconn(struct uip_udp_conn *conn);
|
||||
|
||||
/* Defined in uip_udppoll.c *************************************************/
|
||||
/* Defined in udp_poll.c ****************************************************/
|
||||
|
||||
void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn);
|
||||
|
||||
/* Defined in uip_udpsend.c *************************************************/
|
||||
/* Defined in udp_send.c ****************************************************/
|
||||
|
||||
void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn);
|
||||
|
||||
/* Defined in uip_udpinput.c ************************************************/
|
||||
/* Defined in udp_input.c ***************************************************/
|
||||
|
||||
int uip_udpinput(struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in uip_udpcallback.c *********************************************/
|
||||
/* Defined in udp_callback.c ************************************************/
|
||||
|
||||
uint16_t uip_udpcallback(struct uip_driver_s *dev,
|
||||
struct uip_udp_conn *conn, uint16_t flags);
|
||||
#endif /* CONFIG_NET_UDP */
|
||||
|
||||
#ifdef CONFIG_NET_ICMP
|
||||
/* Defined in uip_icmpinput.c ***********************************************/
|
||||
/* Defined in icmp_input.c **************************************************/
|
||||
|
||||
void uip_icmpinput(struct uip_driver_s *dev);
|
||||
|
||||
#ifdef CONFIG_NET_ICMP_PING
|
||||
/* Defined in uip_icmpoll.c *************************************************/
|
||||
/* Defined in icmp_poll.c ***************************************************/
|
||||
|
||||
void uip_icmppoll(struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in uip_icmsend.c *************************************************/
|
||||
/* Defined in icmp_send.c ***************************************************/
|
||||
|
||||
void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr);
|
||||
|
||||
|
@ -250,15 +250,15 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr);
|
|||
#endif /* CONFIG_NET_ICMP */
|
||||
|
||||
#ifdef CONFIG_NET_IGMP
|
||||
/* Defined in uip_igmpinit.c ************************************************/
|
||||
/* Defined in igmp_init.c ***************************************************/
|
||||
|
||||
void uip_igmpinit(void);
|
||||
|
||||
/* Defined in uip_igmpinput.c ***********************************************/
|
||||
/* Defined in igmp_input.c **************************************************/
|
||||
|
||||
void uip_igmpinput(struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in uip_igmpgroup.c ***********************************************/
|
||||
/* Defined in igmp_group.c **************************************************/
|
||||
|
||||
void uip_grpinit(void);
|
||||
FAR struct igmp_group_s *uip_grpalloc(FAR struct uip_driver_s *dev,
|
||||
|
@ -270,28 +270,28 @@ FAR struct igmp_group_s *uip_grpallocfind(FAR struct uip_driver_s *dev,
|
|||
void uip_grpfree(FAR struct uip_driver_s *dev,
|
||||
FAR struct igmp_group_s *group);
|
||||
|
||||
/* Defined in uip_igmpmsg.c **************************************************/
|
||||
/* Defined in igmp_msg.c ****************************************************/
|
||||
|
||||
void uip_igmpschedmsg(FAR struct igmp_group_s *group, uint8_t msgid);
|
||||
void uip_igmpwaitmsg(FAR struct igmp_group_s *group, uint8_t msgid);
|
||||
|
||||
/* Defined in uip_igmppoll.c *************************************************/
|
||||
/* Defined in igmp_poll.c ***************************************************/
|
||||
|
||||
void uip_igmppoll(FAR struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in up_igmpsend.c **************************************************/
|
||||
/* Defined in igmp_send.c ***************************************************/
|
||||
|
||||
void uip_igmpsend(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group,
|
||||
FAR uip_ipaddr_t *dest);
|
||||
|
||||
/* Defined in uip_igmptimer.c ************************************************/
|
||||
/* Defined in igmp_timer.c **************************************************/
|
||||
|
||||
int uip_decisec2tick(int decisecs);
|
||||
void uip_igmpstartticks(FAR struct igmp_group_s *group, int ticks);
|
||||
void uip_igmpstarttimer(FAR struct igmp_group_s *group, uint8_t decisecs);
|
||||
bool uip_igmpcmptimer(FAR struct igmp_group_s *group, int maxticks);
|
||||
|
||||
/* Defined in uip_mcastmac ***************************************************/
|
||||
/* Defined in igmp_mcastmac *****************************************************/
|
||||
|
||||
void uip_addmcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip);
|
||||
void uip_removemcastmac(FAR struct uip_driver_s *dev, FAR uip_ipaddr_t *ip);
|
||||
|
|
|
@ -1,289 +0,0 @@
|
|||
/****************************************************************************
|
||||
* net/uip/uip_listen.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* A direct leverage of logic from uIP which also has b BSD style license
|
||||
*
|
||||
* Author: Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright (c) 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/uip/uipopt.h>
|
||||
|
||||
#include "uip_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* The uip_listenports list all currently listening ports. */
|
||||
|
||||
static struct uip_conn *uip_listenports[CONFIG_NET_MAX_LISTENPORTS];
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_findlistener
|
||||
*
|
||||
* Description:
|
||||
* Return the connection listener for connections on this port (if any)
|
||||
*
|
||||
* Assumptions:
|
||||
* Called at interrupt level
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct uip_conn *uip_findlistener(uint16_t portno)
|
||||
{
|
||||
int ndx;
|
||||
|
||||
/* Examine each connection structure in each slot of the listener list */
|
||||
|
||||
for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++)
|
||||
{
|
||||
/* Is this slot assigned? If so, does the connection have the same
|
||||
* local port number?
|
||||
*/
|
||||
|
||||
struct uip_conn *conn = uip_listenports[ndx];
|
||||
if (conn && conn->lport == portno)
|
||||
{
|
||||
/* Yes.. we found a listener on this port */
|
||||
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
||||
/* No listener for this port */
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_listeninit
|
||||
*
|
||||
* Description:
|
||||
* Setup the listening data structures
|
||||
*
|
||||
* Assumptions:
|
||||
* Called early in the initialization phase while the system is still
|
||||
* single-threaded.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_listeninit(void)
|
||||
{
|
||||
int ndx;
|
||||
for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++)
|
||||
{
|
||||
uip_listenports[ndx] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_unlisten
|
||||
*
|
||||
* Description:
|
||||
* Stop listening to the port bound to the specified TCP connection
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from normal user code.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int uip_unlisten(struct uip_conn *conn)
|
||||
{
|
||||
uip_lock_t flags;
|
||||
int ndx;
|
||||
int ret = -EINVAL;
|
||||
|
||||
flags = uip_lock();
|
||||
for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++)
|
||||
{
|
||||
if (uip_listenports[ndx] == conn)
|
||||
{
|
||||
uip_listenports[ndx] = NULL;
|
||||
ret = OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uip_unlock(flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_listen
|
||||
*
|
||||
* Description:
|
||||
* Start listening to the port bound to the specified TCP connection
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from normal user code.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int uip_listen(struct uip_conn *conn)
|
||||
{
|
||||
uip_lock_t flags;
|
||||
int ndx;
|
||||
int ret;
|
||||
|
||||
/* This must be done with interrupts disabled because the listener table
|
||||
* is accessed from interrupt level as well.
|
||||
*/
|
||||
|
||||
flags = uip_lock();
|
||||
|
||||
/* First, check if there is already a socket listening on this port */
|
||||
|
||||
if (uip_islistener(conn->lport))
|
||||
{
|
||||
/* Yes, then we must refuse this request */
|
||||
|
||||
ret = -EADDRINUSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, save a reference to the connection structure in the
|
||||
* "listener" list.
|
||||
*/
|
||||
|
||||
ret = -ENOBUFS; /* Assume failure */
|
||||
|
||||
/* Search all slots until an available slot is found */
|
||||
|
||||
for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++)
|
||||
{
|
||||
/* Is the next slot available? */
|
||||
|
||||
if (!uip_listenports[ndx])
|
||||
{
|
||||
/* Yes.. we found it */
|
||||
|
||||
uip_listenports[ndx] = conn;
|
||||
ret = OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uip_unlock(flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_islistener
|
||||
*
|
||||
* Description:
|
||||
* Return true is there is a listener for the specified port
|
||||
*
|
||||
* Assumptions:
|
||||
* Called at interrupt level
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool uip_islistener(uint16_t portno)
|
||||
{
|
||||
return uip_findlistener(portno) != NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_accept
|
||||
*
|
||||
* Description:
|
||||
* Accept the new connection for the specified listening port.
|
||||
*
|
||||
* Assumptions:
|
||||
* Called at interrupt level
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint16_t portno)
|
||||
{
|
||||
struct uip_conn *listener;
|
||||
int ret = ERROR;
|
||||
|
||||
/* The interrupt logic has already allocated and initialized a TCP
|
||||
* connection -- now check there if is an application in place to accept the
|
||||
* connection.
|
||||
*/
|
||||
|
||||
listener = uip_findlistener(portno);
|
||||
if (listener)
|
||||
{
|
||||
/* Yes, there is a listener. Is it accepting connections now? */
|
||||
|
||||
if (listener->accept)
|
||||
{
|
||||
/* Yes.. accept the connection */
|
||||
|
||||
ret = listener->accept(listener, conn);
|
||||
}
|
||||
#ifdef CONFIG_NET_TCPBACKLOG
|
||||
else
|
||||
{
|
||||
/* Add the connection to the backlog and notify any threads that
|
||||
* may be waiting on poll()/select() that the connection is available.
|
||||
*/
|
||||
|
||||
ret = uip_backlogadd(listener, conn);
|
||||
if (ret == OK)
|
||||
{
|
||||
(void)uip_tcpcallback(dev, listener, UIP_BACKLOG);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
Loading…
Reference in a new issue