Merge remote-tracking branch 'origin/master' into ieee802154

This commit is contained in:
Gregory Nutt
2017-04-20 16:19:42 -06:00
185 changed files with 7731 additions and 1385 deletions
-1
View File
@@ -296,7 +296,6 @@ source "net/icmpv6/Kconfig"
source "net/igmp/Kconfig"
source "net/arp/Kconfig"
source "net/loopback/Kconfig"
source "net/iob/Kconfig"
source "net/procfs/Kconfig"
source "net/usrsock/Kconfig"
source "net/utils/Kconfig"
-1
View File
@@ -57,7 +57,6 @@ DEPPATH = --dep-path .
include socket/Make.defs
include netdev/Make.defs
include iob/Make.defs
include arp/Make.defs
include icmp/Make.defs
include icmpv6/Make.defs
+1 -2
View File
@@ -12,7 +12,6 @@ Directory Structure
+- devif - Stack/device interface layer
+- icmp - Internet Control Message Protocol (IPv4)
+- icmpv6 - Internet Control Message Protocol (IPv6)
+- iob - I/O buffering logic
+- local - Unix domain (local) sockets
+- loopback - Local loopback
+- neighbor - Neighbor Discovery Protocol (IPv6)
@@ -43,4 +42,4 @@ Directory Structure
+----------------------------------------------------------------+ +-----+
+----------------------------------------------------------------+ +--------------------------+
| Networking Hardware | | Hardware TCP/IP Stack |
+----------------------------------------------------------------+ +--------------------------+
+----------------------------------------------------------------+ +--------------------------+
+1 -1
View File
@@ -50,7 +50,7 @@ endif
# I/O buffer chain support required?
ifeq ($(CONFIG_NET_IOB),y)
ifeq ($(CONFIG_DRIVERS_IOB),y)
NET_CSRCS += devif_iobsend.c
endif
+1 -1
View File
@@ -466,7 +466,7 @@ void devif_send(FAR struct net_driver_s *dev, FAR const void *buf, int len);
*
****************************************************************************/
#ifdef CONFIG_NET_IOB
#ifdef CONFIG_DRIVERS_IOB
struct iob_s;
void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *buf,
unsigned int len, unsigned int offset);
+3 -3
View File
@@ -43,10 +43,10 @@
#include <assert.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include <nuttx/net/netdev.h>
#ifdef CONFIG_NET_IOB
#ifdef CONFIG_DRIVERS_IOB
/****************************************************************************
* Pre-processor Definitions
@@ -113,5 +113,5 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
#endif
}
#endif /* CONFIG_NET_IOB */
#endif /* CONFIG_DRIVERS_IOB */
-75
View File
@@ -1,75 +0,0 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
menu "Network I/O Buffer Support"
config NET_IOB
bool "Enable generic network I/O buffer support"
default n
---help---
This setting will build the networking I/O buffer (IOB) support
library.
if NET_IOB
config IOB_NBUFFERS
int "Number of pre-allocated network I/O buffers"
default 24 if (NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD) || (!NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD)
default 36 if NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD
default 8 if !NET_TCP_WRITE_BUFFERS && !NET_TCP_READAHEAD
---help---
Each packet is represented by a series of small I/O buffers in a
chain. This setting determines the number of preallocated I/O
buffers available for packet data.
config IOB_BUFSIZE
int "Payload size of one network I/O buffer"
default 196
---help---
Each packet is represented by a series of small I/O buffers in a
chain. This setting determines the data payload each preallocated
I/O buffer.
config IOB_NCHAINS
int "Number of pre-allocated I/O buffer chain heads"
default 0 if !NET_TCP_READAHEAD && !NET_UDP_READAHEAD
default 8 if NET_TCP_READAHEAD || NET_UDP_READAHEAD
---help---
These tiny nodes are used as "containers" to support queueing of
I/O buffer chains. This will limit the number of I/O transactions
that can be "in-flight" at any give time. The default value of
zero disables this features.
These generic I/O buffer chain containers are not currently used
by any logic in NuttX. That is because their other other specialized
I/O buffer chain containers that also carry a payload of usage
specific information.
config IOB_THROTTLE
int "I/O buffer throttle value"
default 0 if !NET_TCP_WRITE_BUFFERS || !NET_TCP_READAHEAD
default 8 if NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD
depends on NET_TCP_WRITE_BUFFERS && NET_TCP_READAHEAD
---help---
TCP write buffering and read-ahead buffer use the same pool of free
I/O buffers. In order to prevent uncontrolled incoming TCP packets
from hogging all of the available, pre-allocated I/O buffers, a
throttling value is required. This throttle value assures that
I/O buffers will be denied to the read-ahead logic before TCP writes
are halted.
config IOB_DEBUG
bool "Force I/O buffer debug"
default n
depends on DEBUG_FEATURES
---help---
This option will force debug output from I/O buffer logic,
even without network debug output. This is not normally something
that would want to do but is convenient if you are debugging the
I/O buffer logic and do not want to get overloaded with other
network-related debug output.
endif # NET_IOB
endmenu # Network I/O buffer support
-55
View File
@@ -1,55 +0,0 @@
############################################################################
# net/iob/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_IOB),y)
# Include IOB source files
NET_CSRCS += iob_add_queue.c iob_alloc.c iob_alloc_qentry.c iob_clone.c
NET_CSRCS += iob_concat.c iob_copyin.c iob_copyout.c iob_contig.c iob_free.c
NET_CSRCS += iob_free_chain.c iob_free_qentry.c iob_free_queue.c
NET_CSRCS += iob_initialize.c iob_pack.c iob_peek_queue.c iob_remove_queue.c
NET_CSRCS += iob_trimhead.c iob_trimhead_queue.c iob_trimtail.c
ifeq ($(CONFIG_DEBUG_FEATURES),y)
NET_CSRCS += iob_dump.c
endif
# Include iob build support
DEPPATH += --dep-path iob
VPATH += :iob
endif
-126
View File
@@ -1,126 +0,0 @@
/****************************************************************************
* net/iob/iob.h
*
* 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.
*
****************************************************************************/
#ifndef __NET_IOB_IOB_H
#define __NET_IOB_IOB_H 1
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <semaphore.h>
#include <nuttx/net/iob.h>
#ifdef CONFIG_NET_IOB
/****************************************************************************
* Public Data
****************************************************************************/
/* A list of all free, unallocated I/O buffers */
extern FAR struct iob_s *g_iob_freelist;
/* A list of all free, unallocated I/O buffer queue containers */
#if CONFIG_IOB_NCHAINS > 0
extern FAR struct iob_qentry_s *g_iob_freeqlist;
#endif
/* Counting semaphores that tracks the number of free IOBs/qentries */
extern sem_t g_iob_sem; /* Counts free I/O buffers */
#if CONFIG_IOB_THROTTLE > 0
extern sem_t g_throttle_sem; /* Counts available I/O buffers when throttled */
#endif
#if CONFIG_IOB_NCHAINS > 0
extern sem_t g_qentry_sem; /* Counts free I/O buffer queue containers */
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: iob_alloc_qentry
*
* Description:
* Allocate an I/O buffer chain container by taking the buffer at the head
* of the free list. This function is intended only for internal use by
* the IOB module.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_alloc_qentry(void);
/****************************************************************************
* Name: iob_tryalloc_qentry
*
* Description:
* Try to allocate an I/O buffer chain container by taking the buffer at
* the head of the free list without waiting for the container to become
* free. This function is intended only for internal use by the IOB module.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_tryalloc_qentry(void);
/****************************************************************************
* Name: iob_tryalloc
*
* Description:
* Try to allocate an I/O buffer by taking the buffer at the head of the
* free list without waiting for a buffer to become free.
*
****************************************************************************/
FAR struct iob_s *iob_tryalloc(bool throttled);
/****************************************************************************
* Name: iob_free_qentry
*
* Description:
* Free the I/O buffer chain container by returning it to the free list.
* The link to the next I/O buffer in the chain is return.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq);
#endif /* CONFIG_NET_IOB */
#endif /* __NET_IOB_IOB_H */
-159
View File
@@ -1,159 +0,0 @@
/****************************************************************************
* net/iob/iob_add_queue.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: iob_add_queue_internal
*
* Description:
* Add one I/O buffer chain to the end of a queue. May fail due to lack
* of resources.
*
****************************************************************************/
static int iob_add_queue_internal(FAR struct iob_s *iob,
FAR struct iob_queue_s *iobq,
FAR struct iob_qentry_s *qentry)
{
/* Add the I/O buffer chain to the container */
qentry->qe_head = iob;
/* Add the container to the end of the queue */
qentry->qe_flink = NULL;
if (!iobq->qh_head)
{
iobq->qh_head = qentry;
iobq->qh_tail = qentry;
}
else
{
DEBUGASSERT(iobq->qh_tail);
iobq->qh_tail->qe_flink = qentry;
iobq->qh_tail = qentry;
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_add_queue
*
* Description:
* Add one I/O buffer chain to the end of a queue. May fail due to lack
* of resources.
*
****************************************************************************/
int iob_add_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq)
{
FAR struct iob_qentry_s *qentry;
/* Allocate a container to hold the I/O buffer chain */
qentry = iob_alloc_qentry();
if (!qentry)
{
nerr("ERROR: Failed to allocate a container\n");
return -ENOMEM;
}
return iob_add_queue_internal(iob, iobq, qentry);
}
/****************************************************************************
* Name: iob_tryadd_queue
*
* Description:
* Add one I/O buffer chain to the end of a queue without waiting for
* resources to become free.
*
****************************************************************************/
int iob_tryadd_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq)
{
FAR struct iob_qentry_s *qentry;
/* Allocate a container to hold the I/O buffer chain */
qentry = iob_tryalloc_qentry();
if (!qentry)
{
nerr("ERROR: Failed to allocate a container\n");
return -ENOMEM;
}
return iob_add_queue_internal(iob, iobq, qentry);
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-275
View File
@@ -1,275 +0,0 @@
/****************************************************************************
* net/iob/iob_alloc.c
*
* Copyright (C) 2014, 2016 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <semaphore.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: iob_allocwait
*
* Description:
* Allocate an I/O buffer, waiting if necessary. This function cannot be
* called from any interrupt level logic.
*
****************************************************************************/
static FAR struct iob_s *iob_allocwait(bool throttled)
{
FAR struct iob_s *iob;
irqstate_t flags;
FAR sem_t *sem;
int ret = OK;
#if CONFIG_IOB_THROTTLE > 0
/* Select the semaphore count to check. */
sem = (throttled ? &g_throttle_sem : &g_iob_sem);
#else
sem = &g_iob_sem;
#endif
/* The following must be atomic; interrupt must be disabled so that there
* is no conflict with interrupt level I/O buffer allocations. This is
* not as bad as it sounds because interrupts will be re-enabled while
* we are waiting for I/O buffers to become free.
*/
flags = enter_critical_section();
do
{
/* Try to get an I/O buffer. If successful, the semaphore count
* will be decremented atomically.
*/
iob = iob_tryalloc(throttled);
if (!iob)
{
/* If not successful, then the semaphore count was less than or
* equal to zero (meaning that there are no free buffers). We
* need to wait for an I/O buffer to be released when the semaphore
* count will be incremented.
*/
ret = sem_wait(sem);
if (ret < 0)
{
int errcode = get_errno();
/* EINTR is not an error! EINTR simply means that we were
* awakened by a signal and we should try again.
*
* REVISIT: Many end-user interfaces are required to return
* with an error if EINTR is set. Most uses of this function
* is in internal, non-user logic. But are there cases where
* the error should be returned.
*/
if (errcode == EINTR)
{
/* Force a success indication so that we will continue
* looping.
*/
ret = 0;
}
else
{
/* Stop the loop and return a error */
DEBUGASSERT(errcode > 0);
ret = -errcode;
}
}
else
{
/* When we wake up from wait successfully, an I/O buffer was
* returned to the free list. However, if there are concurrent
* allocations from interrupt handling, then I suspect that
* there is a race condition. But no harm, we will just wait
* again in that case.
*
* We need release our count so that it is available to
* iob_tryalloc(), perhaps allowing another thread to take our
* count. In that event, iob_tryalloc() will fail above and
* we will have to wait again.
*
* TODO: Consider a design modification to permit us to
* complete the allocation without losing our count.
*/
sem_post(sem);
}
}
}
while (ret == OK && iob == NULL);
leave_critical_section(flags);
return iob;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_alloc
*
* Description:
* Allocate an I/O buffer by taking the buffer at the head of the free list.
*
****************************************************************************/
FAR struct iob_s *iob_alloc(bool throttled)
{
/* Were we called from the interrupt level? */
if (up_interrupt_context())
{
/* Yes, then try to allocate an I/O buffer without waiting */
return iob_tryalloc(throttled);
}
else
{
/* Then allocate an I/O buffer, waiting as necessary */
return iob_allocwait(throttled);
}
}
/****************************************************************************
* Name: iob_tryalloc
*
* Description:
* Try to allocate an I/O buffer by taking the buffer at the head of the
* free list without waiting for a buffer to become free.
*
****************************************************************************/
FAR struct iob_s *iob_tryalloc(bool throttled)
{
FAR struct iob_s *iob;
irqstate_t flags;
#if CONFIG_IOB_THROTTLE > 0
FAR sem_t *sem;
#endif
#if CONFIG_IOB_THROTTLE > 0
/* Select the semaphore count to check. */
sem = (throttled ? &g_throttle_sem : &g_iob_sem);
#endif
/* We don't know what context we are called from so we use extreme measures
* to protect the free list: We disable interrupts very briefly.
*/
flags = enter_critical_section();
#if CONFIG_IOB_THROTTLE > 0
/* If there are free I/O buffers for this allocation */
if (sem->semcount > 0)
#endif
{
/* Take the I/O buffer from the head of the free list */
iob = g_iob_freelist;
if (iob)
{
/* Remove the I/O buffer from the free list and decrement the
* counting semaphore(s) that tracks the number of available
* IOBs.
*/
g_iob_freelist = iob->io_flink;
/* Take a semaphore count. Note that we cannot do this in
* in the orthodox way by calling sem_wait() or sem_trywait()
* because this function may be called from an interrupt
* handler. Fortunately we know at at least one free buffer
* so a simple decrement is all that is needed.
*/
g_iob_sem.semcount--;
DEBUGASSERT(g_iob_sem.semcount >= 0);
#if CONFIG_IOB_THROTTLE > 0
/* The throttle semaphore is a little more complicated because
* it can be negative! Decrementing is still safe, however.
*/
g_throttle_sem.semcount--;
DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE);
#endif
leave_critical_section(flags);
/* Put the I/O buffer in a known state */
iob->io_flink = NULL; /* Not in a chain */
iob->io_len = 0; /* Length of the data in the entry */
iob->io_offset = 0; /* Offset to the beginning of data */
iob->io_pktlen = 0; /* Total length of the packet */
return iob;
}
}
leave_critical_section(flags);
return NULL;
}
-241
View File
@@ -1,241 +0,0 @@
/****************************************************************************
* net/iob/iob_alloc_qentry.c
*
* Copyright (C) 2014, 2016 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <semaphore.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: iob_allocwait_qentry
*
* Description:
* Allocate an I/O buffer chain container by taking the buffer at the head
* of the free list. This function is intended only for internal use by
* the IOB module.
*
****************************************************************************/
static FAR struct iob_qentry_s *iob_allocwait_qentry(void)
{
FAR struct iob_qentry_s *qentry;
irqstate_t flags;
int ret = OK;
/* The following must be atomic; interrupt must be disabled so that there
* is no conflict with interrupt level I/O buffer chain container
* allocations. This is not as bad as it sounds because interrupts will be
* re-enabled while we are waiting for I/O buffers to become free.
*/
flags = enter_critical_section();
do
{
/* Try to get an I/O buffer chain container. If successful, the
* semaphore count will be decremented atomically.
*/
qentry = iob_tryalloc_qentry();
if (!qentry)
{
/* If not successful, then the semaphore count was less than or
* equal to zero (meaning that there are no free buffers). We
* need to wait for an I/O buffer chain container to be released
* when the semaphore count will be incremented.
*/
ret = sem_wait(&g_qentry_sem);
if (ret < 0)
{
int errcode = get_errno();
/* EINTR is not an error! EINTR simply means that we were
* awakened by a signal and we should try again.
*
* REVISIT: Many end-user interfaces are required to return
* with an error if EINTR is set. Most uses of this function
* is in internal, non-user logic. But are there cases where
* the error should be returned.
*/
if (errcode == EINTR)
{
/* Force a success indication so that we will continue
* looping.
*/
ret = 0;
}
else
{
/* Stop the loop and return a error */
DEBUGASSERT(errcode > 0);
ret = -errcode;
}
}
else
{
/* When we wake up from wait successfully, an I/O buffer chain
* container was returned to the free list. However, if there
* are concurrent allocations from interrupt handling, then I
* suspect that there is a race condition. But no harm, we
* will just wait again in that case.
*
* We need release our count so that it is available to
* iob_tryalloc_qentry(), perhaps allowing another thread to
* take our count. In that event, iob_tryalloc_qentry() will
* fail above and we will have to wait again.
*
* TODO: Consider a design modification to permit us to
* complete the allocation without losing our count.
*/
sem_post(&g_qentry_sem);
}
}
}
while (ret == OK && !qentry);
leave_critical_section(flags);
return qentry;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_alloc_qentry
*
* Description:
* Allocate an I/O buffer chain container by taking the buffer at the head
* of the free list. This function is intended only for internal use by
* the IOB module.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_alloc_qentry(void)
{
/* Were we called from the interrupt level? */
if (up_interrupt_context())
{
/* Yes, then try to allocate an I/O buffer without waiting */
return iob_tryalloc_qentry();
}
else
{
/* Then allocate an I/O buffer, waiting as necessary */
return iob_allocwait_qentry();
}
}
/****************************************************************************
* Name: iob_tryalloc_qentry
*
* Description:
* Try to allocate an I/O buffer chain container by taking the buffer at
* the head of the free list without waiting for the container to become
* free. This function is intended only for internal use by the IOB module.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_tryalloc_qentry(void)
{
FAR struct iob_qentry_s *iobq;
irqstate_t flags;
/* We don't know what context we are called from so we use extreme measures
* to protect the free list: We disable interrupts very briefly.
*/
flags = enter_critical_section();
iobq = g_iob_freeqlist;
if (iobq)
{
/* Remove the I/O buffer chain container from the free list and
* decrement the counting semaphore that tracks the number of free
* containers.
*/
g_iob_freeqlist = iobq->qe_flink;
/* Take a semaphore count. Note that we cannot do this in
* in the orthodox way by calling sem_wait() or sem_trywait()
* because this function may be called from an interrupt
* handler. Fortunately we know at at least one free buffer
* so a simple decrement is all that is needed.
*/
g_qentry_sem.semcount--;
DEBUGASSERT(g_qentry_sem.semcount >= 0);
/* Put the I/O buffer in a known state */
iobq->qe_head = NULL; /* Nothing is contained */
}
leave_critical_section(flags);
return iobq;
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-182
View File
@@ -1,182 +0,0 @@
/****************************************************************************
* net/iob1/iob_copy.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_clone
*
* Description:
* Duplicate (and pack) the data in iob1 in iob2. iob2 must be empty.
*
****************************************************************************/
int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled)
{
FAR uint8_t *src;
FAR uint8_t *dest;
unsigned int ncopy;
unsigned int avail1;
unsigned int avail2;
unsigned int offset1;
unsigned int offset2;
DEBUGASSERT(iob2->io_len == 0 && iob2->io_offset == 0 &&
iob2->io_pktlen == 0 && iob2->io_flink == NULL);
/* Copy the total packet size from the I/O buffer at the head of the chain */
iob2->io_pktlen = iob1->io_pktlen;
/* Handle special case where there are empty buffers at the head
* the the list.
*/
while (iob1->io_len <= 0)
{
iob1 = iob1->io_flink;
}
/* Pack each entry from iob1 to iob2 */
offset1 = 0;
offset2 = 0;
while (iob1)
{
/* Get the source I/O buffer pointer and the number of bytes to copy
* from this address.
*/
src = &iob1->io_data[iob1->io_offset + offset1];
avail1 = iob1->io_len - offset1;
/* Get the destination I/O buffer pointer and the number of bytes to
* copy to that address.
*/
dest = &iob2->io_data[offset2];
avail2 = CONFIG_IOB_BUFSIZE - offset2;
/* Copy the smaller of the two and update the srce and destination
* offsets.
*/
ncopy = MIN(avail1, avail2);
memcpy(dest, src, ncopy);
offset1 += ncopy;
offset2 += ncopy;
/* Have we taken all of the data from the source I/O buffer? */
if (offset1 >= iob1->io_len)
{
/* Skip over empty entries in the chain (there should not be any
* but just to be safe).
*/
do
{
/* Yes.. move to the next source I/O buffer */
iob1 = iob1->io_flink;
}
while (iob1 && iob1->io_len <= 0);
/* Reset the offset to the beginning of the I/O buffer */
offset1 = 0;
}
/* Have we filled the destination I/O buffer? Is there more data to be
* transferred?
*/
if (offset2 >= CONFIG_IOB_BUFSIZE && iob1 != NULL)
{
FAR struct iob_s *next;
/* Allocate new destination I/O buffer and hook it into the
* destination I/O buffer chain.
*/
next = iob_alloc(throttled);
if (!next)
{
nerr("ERROR: Failed to allocate an I/O buffer/n");
return -ENOMEM;
}
iob2->io_flink = next;
iob2 = next;
offset2 = 0;
}
}
return 0;
}
-83
View File
@@ -1,83 +0,0 @@
/****************************************************************************
* net/iob/iob_concat.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <string.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_concat
*
* Description:
* Concatenate iob_s chain iob2 to iob1.
*
****************************************************************************/
void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2)
{
/* Find the last buffer in the iob1 buffer chain */
while (iob1->io_flink)
{
iob1 = iob1->io_flink;
}
/* Then connect iob2 buffer chain to the end of the iob1 chain */
iob1->io_flink = iob2;
/* Combine the total packet size */
iob1->io_pktlen += iob2->io_pktlen;
}
-167
View File
@@ -1,167 +0,0 @@
/****************************************************************************
* net/iob/iob_contig.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_contig
*
* Description:
* Ensure that there is'len' bytes of contiguous space at the beginning
* of the I/O buffer chain starting at 'iob'.
*
****************************************************************************/
int iob_contig(FAR struct iob_s *iob, unsigned int len)
{
FAR struct iob_s *next;
unsigned int ncopy;
/* We can't make more contiguous space that the size of one I/O buffer.
* If you get this assertion and really need that much contiguous data,
* then you will need to increase CONFIG_IOB_BUFSIZE.
*/
DEBUGASSERT(len <= CONFIG_IOB_BUFSIZE);
/* Check if there is already sufficient, contiguous space at the beginning
* of the packet
*/
if (len <= iob->io_len)
{
/* Yes we are good */
return 0;
}
/* Can we get the required amount of contiguous data by just packing the
* head I/0 buffer?
*/
else if (len <= iob->io_pktlen)
{
/* Yes.. First eliminate any leading offset */
if (iob->io_offset > 0)
{
memcpy(iob->io_data, &iob->io_data[iob->io_offset], iob->io_len);
iob->io_offset = 0;
}
/* Then move what we need from the next I/O buffer(s) */
do
{
/* Get the next I/O buffer in the chain */
next = iob->io_flink;
DEBUGASSERT(next != NULL && next->io_len > 0);
/* Copy what we need or what we can from the next buffer */
ncopy = len - iob->io_len;
ncopy = MIN(ncopy, next->io_len);
memcpy(&iob->io_data[iob->io_len],
&next->io_data[next->io_offset], ncopy);
/* Adjust counts and offsets */
iob->io_len += ncopy;
next->io_offset += ncopy;
next->io_len -= ncopy;
/* Handle a (improbable) case where we just emptied the second
* buffer in the chain.
*/
if (next->io_len == 0)
{
iob->io_flink = iob_free(next);
}
}
while (len > iob->io_len);
/* This should always succeed because we know that:
*
* pktlen >= CONFIG_IOB_BUFSIZE >= len
*/
return 0;
}
/* Otherwise, the request for contiguous data is larger then the entire
* packet. We can't do that without extending the I/O buffer chain with
* garbage (which would probably not be what the caller wants).
*/
else
{
nerr("ERROR: pktlen=%u < requested len=%u\n", iob->io_pktlen, len);
return -ENOSPC;
}
}
-280
View File
@@ -1,280 +0,0 @@
/****************************************************************************
* net/iob/iob_copyin.c
*
* Copyright (C) 2014, 2016 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Private Types
****************************************************************************/
typedef CODE struct iob_s *(*iob_alloc_t)(bool throttled);
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_copyin_internal
*
* Description:
* Copy data 'len' bytes from a user buffer into the I/O buffer chain,
* starting at 'offset', extending the chain as necessary.
*
* Returned Value:
* The number of uncopied bytes left if >= 0 OR a negative error code.
*
****************************************************************************/
static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src,
unsigned int len, unsigned int offset,
bool throttled, bool can_block)
{
FAR struct iob_s *head = iob;
FAR struct iob_s *next;
FAR uint8_t *dest;
unsigned int ncopy;
unsigned int avail;
unsigned int total = len;
ninfo("iob=%p len=%u offset=%u\n", iob, len, offset);
DEBUGASSERT(iob && src);
/* The offset must applied to data that is already in the I/O buffer chain */
if (offset > iob->io_pktlen)
{
nerr("ERROR: offset is past the end of data: %u > %u\n",
offset, iob->io_pktlen);
return -ESPIPE;
}
/* Skip to the I/O buffer containing the data offset */
while (offset > iob->io_len)
{
offset -= iob->io_len;
iob = iob->io_flink;
}
/* Then loop until all of the I/O data is copied from the user buffer */
while (len > 0)
{
next = iob->io_flink;
/* Get the destination I/O buffer address and the amount of data
* available from that address.
*/
dest = &iob->io_data[iob->io_offset + offset];
avail = iob->io_len - offset;
ninfo("iob=%p avail=%u len=%u next=%p\n", iob, avail, len, next);
/* Will the rest of the copy fit into this buffer, overwriting
* existing data.
*/
if (len > avail)
{
/* No.. Is this the last buffer in the chain? */
if (next)
{
/* No.. clip to size that will overwrite. We cannot
* extend the length of an I/O block in mid-chain.
*/
ncopy = avail;
}
else
{
unsigned int maxlen;
unsigned int newlen;
/* Yes.. We can extend this buffer to the up to the very end. */
maxlen = CONFIG_IOB_BUFSIZE - iob->io_offset;
/* This is the new buffer length that we need. Of course,
* clipped to the maximum possible size in this buffer.
*/
newlen = len + offset;
if (newlen > maxlen)
{
newlen = maxlen;
}
/* Set the new length and increment the packet length */
head->io_pktlen += (newlen - iob->io_len);
iob->io_len = newlen;
/* Set the new number of bytes to copy */
ncopy = newlen - offset;
}
}
else
{
/* Yes.. Copy all of the remaining bytes */
ncopy = len;
}
/* Copy from the user buffer to the I/O buffer. */
memcpy(dest, src, ncopy);
ninfo("iob=%p Copy %u bytes new len=%u\n",
iob, ncopy, iob->io_len);
/* Adjust the total length of the copy and the destination address in
* the user buffer.
*/
len -= ncopy;
src += ncopy;
/* Skip to the next I/O buffer in the chain. First, check if we
* are at the end of the buffer chain.
*/
if (len > 0 && !next)
{
/* Yes.. allocate a new buffer.
*
* Copy as many bytes as possible. If we have successfully copied
* any already don't block, otherwise block if we're allowed.
*/
if (!can_block || len < total)
{
next = iob_tryalloc(throttled);
}
else
{
next = iob_alloc(throttled);
}
if (next == NULL)
{
nerr("ERROR: Failed to allocate I/O buffer\n");
return len;
}
/* Add the new, empty I/O buffer to the end of the buffer chain. */
iob->io_flink = next;
ninfo("iob=%p added to the chain\n", iob);
}
iob = next;
offset = 0;
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_copyin
*
* Description:
* Copy data 'len' bytes from a user buffer into the I/O buffer chain,
* starting at 'offset', extending the chain as necessary.
*
****************************************************************************/
int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
unsigned int len, unsigned int offset, bool throttled)
{
return len - iob_copyin_internal(iob, src, len, offset, throttled, true);
}
/****************************************************************************
* Name: iob_trycopyin
*
* Description:
* Copy data 'len' bytes from a user buffer into the I/O buffer chain,
* starting at 'offset', extending the chain as necessary BUT without
* waiting if buffers are not available.
*
****************************************************************************/
int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
unsigned int len, unsigned int offset, bool throttled)
{
if (iob_copyin_internal(iob, src, len, offset, throttled, false) == 0)
{
return OK;
}
else
{
return -ENOMEM;
}
}
-131
View File
@@ -1,131 +0,0 @@
/****************************************************************************
* net/iob/iob_copyout.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_copyout
*
* Description:
* Copy data 'len' bytes of data into the user buffer starting at 'offset'
* in the I/O buffer, returning that actual number of bytes copied out.
*
****************************************************************************/
int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob,
unsigned int len, unsigned int offset)
{
FAR const uint8_t *src;
unsigned int ncopy;
unsigned int avail;
unsigned int remaining;
/* Skip to the I/O buffer containing the offset */
while (offset >= iob->io_len)
{
offset -= iob->io_len;
iob = iob->io_flink;
if (iob == NULL)
{
/* We have no requested data in iob chain */
return 0;
}
}
/* Then loop until all of the I/O data is copied to the user buffer */
remaining = len;
while (iob && remaining > 0)
{
/* Get the source I/O buffer offset address and the amount of data
* available from that address.
*/
src = &iob->io_data[iob->io_offset + offset];
avail = iob->io_len - offset;
/* Copy the from the I/O buffer in to the user buffer */
ncopy = MIN(avail, remaining);
memcpy(dest, src, ncopy);
/* Adjust the total length of the copy and the destination address in
* the user buffer.
*/
remaining -= ncopy;
dest += ncopy;
/* Skip to the next I/O buffer in the chain */
iob = iob->io_flink;
offset = 0;
}
return len - remaining;
}
-165
View File
@@ -1,165 +0,0 @@
/****************************************************************************
* net/iob/iob_dump.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#ifdef CONFIG_DEBUG_FEATURES
/****************************************************************************
* Pre-processor definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: iob_dump
*
* Description:
* Dump the contents of a I/O buffer chain
*
****************************************************************************/
void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len,
unsigned int offset)
{
FAR struct iob_s *head;
uint8_t data[32];
unsigned int maxlen;
unsigned int nbytes;
unsigned int lndx;
unsigned int cndx;
head = iob;
syslog(LOG_DEBUG, "%s: iob=%p pktlen=%d\n", msg, head, head->io_pktlen);
/* Check if the offset is beyond the data in the I/O buffer chain */
if (offset > head->io_pktlen)
{
nerr("ERROR: offset is past the end of data: %u > %u\n",
offset, head->io_pktlen);
return;
}
/* Dump I/O buffer headers */
for (; iob; iob = iob->io_flink)
{
syslog(LOG_DEBUG, " iob=%p len=%d offset=%d\n",
iob, iob->io_len, iob->io_offset);
}
/* Get the amount of data to be displayed, limited by the amount that we
* have beyond the offset.
*/
maxlen = head->io_pktlen - offset;
len = MIN(len, maxlen);
/* Then beginning printing with the buffer containing the offset in groups
* of 32 bytes.
*/
for (lndx = 0; lndx < len; lndx += 32, offset += 32)
{
/* Copy 32-bytes into our local buffer from the current offset */
nbytes = iob_copyout(data, head, 32, offset);
/* Make sure that we have something to print */
if (nbytes > 0)
{
syslog(LOG_DEBUG, " %04x: ", offset);
for (cndx = 0; cndx < 32; cndx++)
{
if (cndx == 16)
{
syslog(LOG_DEBUG, " ");
}
if ((lndx + cndx) < len)
{
syslog(LOG_DEBUG, "%02x", data[cndx]);
}
else
{
syslog(LOG_DEBUG, " ");
}
}
syslog(LOG_DEBUG, " ");
for (cndx = 0; cndx < 32; cndx++)
{
if (cndx == 16)
{
syslog(LOG_DEBUG, " ");
}
if ((lndx + cndx) < len)
{
if (data[cndx] >= 0x20 && data[cndx] < 0x7f)
{
syslog(LOG_DEBUG, "%c", data[cndx]);
}
else
{
syslog(LOG_DEBUG, ".");
}
}
}
syslog(LOG_DEBUG, "\n");
}
}
}
#endif /* CONFIG_DEBUG_FEATURES */
-131
View File
@@ -1,131 +0,0 @@
/****************************************************************************
* net/iob/iob_free.c
*
* Copyright (C) 2014, 2016 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <semaphore.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_free
*
* Description:
* Free the I/O buffer at the head of a buffer chain returning it to the
* free list. The link to the next I/O buffer in the chain is return.
*
****************************************************************************/
FAR struct iob_s *iob_free(FAR struct iob_s *iob)
{
FAR struct iob_s *next = iob->io_flink;
irqstate_t flags;
ninfo("iob=%p io_pktlen=%u io_len=%u next=%p\n",
iob, iob->io_pktlen, iob->io_len, next);
/* Copy the data that only exists in the head of a I/O buffer chain into
* the next entry.
*/
if (next)
{
/* Copy and decrement the total packet length, being careful to
* do nothing too crazy.
*/
if (iob->io_pktlen > iob->io_len)
{
/* Adjust packet length and move it to the next entry */
next->io_pktlen = iob->io_pktlen - iob->io_len;
DEBUGASSERT(next->io_pktlen >= next->io_len);
}
else
{
/* This can only happen if the next entry is last entry in the
* chain... and if it is empty
*/
next->io_pktlen = 0;
DEBUGASSERT(next->io_len == 0 && next->io_flink == NULL);
}
ninfo("next=%p io_pktlen=%u io_len=%u\n",
next, next->io_pktlen, next->io_len);
}
/* Free the I/O buffer by adding it to the head of the free list. We don't
* know what context we are called from so we use extreme measures to
* protect the free list: We disable interrupts very briefly.
*/
flags = enter_critical_section();
iob->io_flink = g_iob_freelist;
g_iob_freelist = iob;
/* Signal that an IOB is available */
sem_post(&g_iob_sem);
#if CONFIG_IOB_THROTTLE > 0
sem_post(&g_throttle_sem);
#endif
leave_critical_section(flags);
/* And return the I/O buffer after the one that was freed */
return next;
}
-77
View File
@@ -1,77 +0,0 @@
/****************************************************************************
* net/iob/iob_free_chain.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_free_chain
*
* Description:
* Free an entire buffer chain, starting at the beginning of the I/O
* buffer chain
*
****************************************************************************/
void iob_free_chain(FAR struct iob_s *iob)
{
FAR struct iob_s *next;
/* Free each IOB in the chain -- one at a time to keep the count straight */
for (; iob; iob = next)
{
next = iob_free(iob);
}
}
-97
View File
@@ -1,97 +0,0 @@
/****************************************************************************
* net/iob/iob_free_qentry.c
*
* Copyright (C) 2014, 2016 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <semaphore.h>
#include <assert.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_free_qentry
*
* Description:
* Free the I/O buffer chain container by returning it to the free list.
* The link to the next I/O buffer in the chain is return.
*
****************************************************************************/
FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq)
{
FAR struct iob_qentry_s *nextq = iobq->qe_flink;
irqstate_t flags;
/* Free the I/O buffer chain container by adding it to the head of the free
* list. We don't know what context we are called from so we use extreme
* measures to protect the free list: We disable interrupts very briefly.
*/
flags = enter_critical_section();
iobq->qe_flink = g_iob_freeqlist;
g_iob_freeqlist = iobq;
/* Signal that an I/O buffer chain container is available */
sem_post(&g_qentry_sem);
leave_critical_section(flags);
/* And return the I/O buffer chain container after the one that was freed */
return nextq;
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-113
View File
@@ -1,113 +0,0 @@
/****************************************************************************
* net/iob/iob_free_queue.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <assert.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_free_queue
*
* Description:
* Free an entire queue of I/O buffer chains.
*
****************************************************************************/
void iob_free_queue(FAR struct iob_queue_s *qhead)
{
FAR struct iob_qentry_s *iobq;
FAR struct iob_qentry_s *nextq;
FAR struct iob_s *iob;
/* Detach the list from the queue head so first for safety (should be safe
* anyway).
*/
iobq = qhead->qh_head;
qhead->qh_head = NULL;
/* Remove each I/O buffer chain from the queue */
while (iobq)
{
/* Remove the I/O buffer chain from the head of the queue and
* discard the queue container.
*/
iob = iobq->qe_head;
DEBUGASSERT(iob);
/* Remove the queue container from the list and discard it */
nextq = iobq->qe_flink;
iob_free_qentry(iobq);
iobq = nextq;
/* Free the I/O chain */
iob_free_chain(iob);
}
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-147
View File
@@ -1,147 +0,0 @@
/****************************************************************************
* net/iob/iob_initialize.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <stdbool.h>
#include <semaphore.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Private Data
****************************************************************************/
/* This is a pool of pre-allocated I/O buffers */
static struct iob_s g_iob_pool[CONFIG_IOB_NBUFFERS];
#if CONFIG_IOB_NCHAINS > 0
static struct iob_qentry_s g_iob_qpool[CONFIG_IOB_NCHAINS];
#endif
/****************************************************************************
* Public Data
****************************************************************************/
/* A list of all free, unallocated I/O buffers */
FAR struct iob_s *g_iob_freelist;
/* A list of all free, unallocated I/O buffer queue containers */
#if CONFIG_IOB_NCHAINS > 0
FAR struct iob_qentry_s *g_iob_freeqlist;
#endif
/* Counting semaphores that tracks the number of free IOBs/qentries */
sem_t g_iob_sem; /* Counts free I/O buffers */
#if CONFIG_IOB_THROTTLE > 0
sem_t g_throttle_sem; /* Counts available I/O buffers when throttled */
#endif
#if CONFIG_IOB_NCHAINS > 0
sem_t g_qentry_sem; /* Counts free I/O buffer queue containers */
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_initialize
*
* Description:
* Set up the I/O buffers for normal operations.
*
****************************************************************************/
void iob_initialize(void)
{
static bool initialized = false;
int i;
/* Perform one-time initialization */
if (!initialized)
{
/* Add each I/O buffer to the free list */
for (i = 0; i < CONFIG_IOB_NBUFFERS; i++)
{
FAR struct iob_s *iob = &g_iob_pool[i];
/* Add the pre-allocate I/O buffer to the head of the free list */
iob->io_flink = g_iob_freelist;
g_iob_freelist = iob;
}
sem_init(&g_iob_sem, 0, CONFIG_IOB_NBUFFERS);
#if CONFIG_IOB_THROTTLE > 0
sem_init(&g_throttle_sem, 0, CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE);
#endif
#if CONFIG_IOB_NCHAINS > 0
/* Add each I/O buffer chain queue container to the free list */
for (i = 0; i < CONFIG_IOB_NCHAINS; i++)
{
FAR struct iob_qentry_s *iobq = &g_iob_qpool[i];
/* Add the pre-allocate buffer container to the head of the free list */
iobq->qe_flink = g_iob_freeqlist;
g_iob_freeqlist = iobq;
}
sem_init(&g_qentry_sem, 0, CONFIG_IOB_NCHAINS);
#endif
initialized = true;
}
}
-157
View File
@@ -1,157 +0,0 @@
/****************************************************************************
* net/iob/iob_pack.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <string.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_pack
*
* Description:
* Pack all data in the I/O buffer chain so that the data offset is zero
* and all but the final buffer in the chain are filled. Any emptied
* buffers at the end of the chain are freed.
*
****************************************************************************/
FAR struct iob_s *iob_pack(FAR struct iob_s *iob)
{
FAR struct iob_s *head;
FAR struct iob_s *next;
unsigned int ncopy;
unsigned int navail;
/* Handle special cases */
while (iob->io_len <= 0)
{
iob = iob_free(iob);
}
/* Now remember the head of the chain (for the return value) */
head = iob;
/* Pack each entry in the list */
while (iob)
{
next = iob->io_flink;
/* Eliminate the data offset in this entry */
if (iob->io_offset > 0)
{
memcpy(iob->io_data, &iob->io_data[iob->io_offset], iob->io_len);
iob->io_offset = 0;
}
/* Is there a buffer after this one? */
if (next)
{
/* How many bytes can we copy from the next I/O buffer. Limit the
* size of the copy to the amount of free space in current I/O
* buffer
*/
ncopy = next->io_len;
navail = CONFIG_IOB_BUFSIZE - iob->io_len;
if (ncopy > navail)
{
ncopy = navail;
}
if (ncopy > 0)
{
/* Copy the data from the next into the current I/O buffer iob */
memcpy(&iob->io_data[iob->io_len],
&next->io_data[next->io_offset],
ncopy);
/* Adjust lengths and offsets */
iob->io_len += ncopy;
next->io_len -= ncopy;
next->io_offset += ncopy;
}
/* Have we consumed all of the data in the next entry? */
if (next->io_len <= 0)
{
/* Yes.. free the next entry in I/O buffer chain */
next = iob_free(next);
iob->io_flink = next;
}
}
/* Set up to pack the next entry in the chain */
iob = next;
}
return head;
}
-102
View File
@@ -1,102 +0,0 @@
/****************************************************************************
* net/iob/iob_peek_queue.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_peek_queue
*
* Description:
* Return a reference to the I/O buffer chain at the head of a queue. This
* is similar to iob_remove_queue except that the I/O buffer chain is in
* place at the head of the queue. The I/O buffer chain may safely be
* modified by the caller but must be removed from the queue before it can
* be freed.
*
* Returned Value:
* Returns a reference to the I/O buffer chain at the head of the queue.
*
****************************************************************************/
FAR struct iob_s *iob_peek_queue(FAR struct iob_queue_s *iobq)
{
FAR struct iob_qentry_s *qentry;
FAR struct iob_s *iob = NULL;
/* Peek at the I/O buffer chain container at the head of the queue */
qentry = iobq->qh_head;
if (qentry)
{
/* Return the I/O buffer chain from the container */
iob = qentry->qe_head;
}
return iob;
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-107
View File
@@ -1,107 +0,0 @@
/****************************************************************************
* net/iob/iob_remove_queue.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_remove_queue
*
* Description:
* Remove and return one I/O buffer chain from the head of a queue.
*
* Returned Value:
* Returns a reference to the I/O buffer chain at the head of the queue.
*
****************************************************************************/
FAR struct iob_s *iob_remove_queue(FAR struct iob_queue_s *iobq)
{
FAR struct iob_qentry_s *qentry;
FAR struct iob_s *iob = NULL;
/* Remove the I/O buffer chain from the head of the queue */
qentry = iobq->qh_head;
if (qentry)
{
iobq->qh_head = qentry->qe_flink;
if (!iobq->qh_head)
{
iobq->qh_tail = NULL;
}
/* Extract the I/O buffer chain from the container and free the
* container.
*/
iob = qentry->qe_head;
iob_free_qentry(qentry);
}
return iob;
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-196
View File
@@ -1,196 +0,0 @@
/****************************************************************************
* net/iob/iob_test.c
* Unit test driver. This is of historical interest only since it requires
* and custom build setup and modifications to the iob source and header
* files.
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "iob.h"
/****************************************************************************
* Private Data
****************************************************************************/
static uint8_t buffer1[16384];
static uint8_t buffer2[16384];
/****************************************************************************
* Private Functions
****************************************************************************/
static void dump_chain(struct iob_s *iob)
{
struct iob_s *head = iob;
unsigned int pktlen;
int n;
printf("=========================================================\n");
printf("pktlen: %d\n", iob->io_pktlen);
n = 0;
pktlen = 0;
while (iob)
{
printf("%d. len=%d, offset=%d\n", n, iob->io_len, iob->io_offset);
pktlen += iob->io_len;
iob = iob->io_flink;
n++;
}
if (pktlen != head->io_pktlen)
{
printf("ERROR: Bad packet length=%u, actual=%u\n",
head->io_pktlen, pktlen);
}
printf("=========================================================\n");
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: main
*
* Description:
* A simple unit test for the I/O buffer logic
*
****************************************************************************/
int main(int argc, char **argv)
{
struct iob_s *iob;
int nbytes;
int i;
iob_initialize();
iob = iob_alloc(false);
for (i = 0; i < 4096; i++)
{
buffer1[i] = (uint8_t)(i & 0xff);
}
memset(buffer2, 0xff, 4096);
iob_copyin(iob, buffer2, 47, 0, false);
printf("Copy IN: 47, offset 0\n");
dump_chain(iob);
iob_copyin(iob, buffer1, 4096, 47, false);
printf("Copy IN: 4096, offset 47\n");
dump_chain(iob);
nbytes = iob_copyout(buffer2, iob, 4096, 47);
printf("Copy OUT: %d, offset 47\n", nbytes);
if (memcmp(buffer1, buffer2, nbytes) != 0)
{
fprintf(stderr, "Buffer1 does not match buffer2\n");
}
iob = iob_trimhead(iob, 47);
printf("Trim: 47 from the beginning of the list\n");
dump_chain(iob);
iob = iob_trimtail(iob, 493);
printf("Trim: 493 from the end of the list\n");
dump_chain(iob);
nbytes = iob_copyout(buffer2, iob, 4096, 0);
printf("Copy OUT: %d, offset 0\n", nbytes);
if (memcmp(buffer1, buffer2, nbytes) != 0)
{
fprintf(stderr, "Buffer1 does not match buffer2\n");
}
iob = iob_trimhead(iob, 1362);
printf("Trim: 1362 from the beginning of the list\n");
dump_chain(iob);
nbytes = iob_copyout(buffer2, iob, 4096, 0);
printf("Copy OUT: %d, offset 0\n", nbytes);
if (memcmp(&buffer1[1362], buffer2, nbytes) != 0)
{
fprintf(stderr, "Buffer1 does not match buffer2\n");
}
iob = iob_pack(iob);
printf("Packed\n");
dump_chain(iob);
nbytes = iob_copyout(buffer2, iob, 4096, 0);
printf("Copy OUT: %d, offset 0\n", nbytes);
if (memcmp(&buffer1[1362], buffer2, nbytes) != 0)
{
fprintf(stderr, "Buffer1 does not match buffer2\n");
}
while (iob) iob = iob_free(iob);
return EXIT_SUCCESS;
}
/****************************************************************************
* Name: my_assert
*
* Description:
* A stand-in for the NuttX assertion routine.
*
****************************************************************************/
void my_assert(bool value)
{
if (!value)
{
fprintf(stderr, "Assertion failed\n");
abort();
}
}
-148
View File
@@ -1,148 +0,0 @@
/****************************************************************************
* net/iob/iob_trimhead.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <assert.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_trimhead
*
* Description:
* Remove bytes from the beginning of an I/O chain. Emptied I/O buffers
* are freed and, hence, the beginning of the chain may change.
*
****************************************************************************/
FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
{
uint16_t pktlen;
ninfo("iob=%p trimlen=%d\n", iob, trimlen);
if (iob && trimlen > 0)
{
/* Trim from the head of the I/IO buffer chain */
pktlen = iob->io_pktlen;
while (trimlen > 0 && iob != NULL)
{
/* Do we trim this entire I/O buffer away? */
ninfo("iob=%p io_len=%d pktlen=%d trimlen=%d\n",
iob, iob->io_len, pktlen, trimlen);
if (iob->io_len <= trimlen)
{
FAR struct iob_s *next;
/* Decrement the trim length and packet length by the full
* data size.
*/
pktlen -= iob->io_len;
trimlen -= iob->io_len;
/* Check if this was the last entry in the chain */
next = iob->io_flink;
if (next == NULL)
{
/* Yes.. break out of the loop returning the empty
* I/O buffer chain containing only one empty entry.
*/
DEBUGASSERT(pktlen == 0);
iob->io_len = 0;
iob->io_offset = 0;
break;
}
/* Free this entry and set the next I/O buffer as the head */
ninfo("iob=%p: Freeing\n", iob);
(void)iob_free(iob);
iob = next;
}
else
{
/* No, then just take what we need from this I/O buffer and
* stop the trim.
*/
pktlen -= trimlen;
iob->io_len -= trimlen;
iob->io_offset += trimlen;
trimlen = 0;
}
}
/* Adjust the pktlen by the number of bytes removed from the head
* of the I/O buffer chain.
*/
iob->io_pktlen = pktlen;
}
return iob;
}
-115
View File
@@ -1,115 +0,0 @@
/****************************************************************************
* net/iob/iob_trimhead_queue.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <assert.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
#if CONFIG_IOB_NCHAINS > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
# define NULL ((FAR void *)0)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_trimhead_queue
*
* Description:
* Remove bytes from the beginning of an I/O chain at the head of the
* queue. Emptied I/O buffers are freed and, hence, the head of the
* queue may change.
*
* This function is just a wrapper around iob_trimhead() that assures that
* the I/O buffer chain at the head of queue is modified with the trimming
* operation.
*
* Returned Value:
* The new I/O buffer chain at the head of the queue is returned.
*
****************************************************************************/
FAR struct iob_s *iob_trimhead_queue(FAR struct iob_queue_s *qhead,
unsigned int trimlen)
{
FAR struct iob_qentry_s *qentry;
FAR struct iob_s *iob = NULL;
/* Peek at the I/O buffer chain container at the head of the queue */
qentry = qhead->qh_head;
if (qentry)
{
/* Verify that the queue entry contains an I/O buffer chain */
iob = qentry->qe_head;
if (iob)
{
/* Trim the I/Buffer chain and update the queue head */
iob = iob_trimhead(iob, trimlen);
qentry->qe_head = iob;
}
}
/* Return the new I/O buffer chain at the head of the queue */
return iob;
}
#endif /* CONFIG_IOB_NCHAINS > 0 */
-145
View File
@@ -1,145 +0,0 @@
/****************************************************************************
* net/iob/iob_trimtail.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
/* Force debug output (from this file only) */
# undef CONFIG_DEBUG_NET
# define CONFIG_DEBUG_NET 1
#endif
#include <string.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include "iob.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: iob_trimtail
*
* Description:
* Remove bytes from the end of an I/O chain
*
****************************************************************************/
FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
{
FAR struct iob_s *entry;
FAR struct iob_s *penultimate;
FAR struct iob_s *last;
int len;
ninfo("iob=%p pktlen=%d trimlen=%d\n", iob, iob->io_pktlen, trimlen);
if (iob && trimlen > 0)
{
len = trimlen;
/* Loop until complete the trim */
while (len > 0)
{
/* Calculate the total length of the data in the I/O buffer
* chain and find the last entry in the chain.
*/
penultimate = NULL;
last = NULL;
for (entry = iob; entry; entry = entry->io_flink)
{
/* Remember the last and the next to the last in the chain */
penultimate = last;
last = entry;
}
/* Trim from the last entry in the chain. Do we trim this entire
* I/O buffer away?
*/
ninfo("iob=%p len=%d vs %d\n", last, last->io_len, len);
if (last->io_len <= len)
{
/* Yes.. Consume the entire buffer */
iob->io_pktlen -= last->io_len;
len -= last->io_len;
last->io_len = 0;
/* Free the last, empty buffer in the list */
iob_free(last);
/* There should be a buffer before this one */
if (!penultimate)
{
/* No.. we just freed the head of the chain */
return NULL;
}
/* Unlink the penultimate from the freed buffer */
penultimate->io_flink = NULL;
}
else
{
/* No, then just take what we need from this I/O buffer and
* stop the trim.
*/
iob->io_pktlen -= len;
last->io_len -= len;
len = 0;
}
}
}
return iob;
}
-7
View File
@@ -42,7 +42,6 @@
#include <debug.h>
#include <nuttx/net/iob.h>
#include <nuttx/net/net.h>
#include "socket/socket.h"
@@ -109,12 +108,6 @@ void net_setup(void)
#endif
#endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IOB
/* Initialize I/O buffering */
iob_initialize();
#endif
/* Initialize the device interface layer */
devif_initialize();
+1 -1
View File
@@ -59,7 +59,7 @@
#include <nuttx/semaphore.h>
#include <nuttx/cancelpt.h>
#include <nuttx/net/net.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/tcp.h>
+2 -2
View File
@@ -70,7 +70,7 @@ config NET_MAX_LISTENPORTS
config NET_TCP_READAHEAD
bool "Enable TCP/IP read-ahead buffering"
default y
select NET_IOB
select DRIVERS_IOB
---help---
Read-ahead buffers allows buffering of TCP/IP packets when there is no
receive in place to catch the TCP packet. In that case, the packet
@@ -91,7 +91,7 @@ endif # NET_TCP_READAHEAD
config NET_TCP_WRITE_BUFFERS
bool "Enable TCP/IP write buffering"
default n
select NET_IOB
select DRIVERS_IOB
---help---
Write buffers allows buffering of ongoing TCP/IP packets, providing
for higher performance, streamed output.
+1 -1
View File
@@ -45,7 +45,7 @@
#include <sys/types.h>
#include <queue.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include <nuttx/net/ip.h>
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
+1 -1
View File
@@ -45,12 +45,12 @@
#include <string.h>
#include <debug.h>
#include <nuttx/drivers/iob.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/netstats.h>
#include "devif/devif.h"
#include "iob/iob.h"
#include "tcp/tcp.h"
/****************************************************************************
+1 -1
View File
@@ -64,7 +64,7 @@
#include <arch/irq.h>
#include <nuttx/clock.h>
#include <nuttx/net/net.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/tcp.h>
+1 -1
View File
@@ -55,7 +55,7 @@
#include <debug.h>
#include <nuttx/net/net.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include "tcp/tcp.h"
+1 -1
View File
@@ -42,7 +42,7 @@
#include <stdint.h>
#include <debug.h>
#include <nuttx/net/iob.h>
#include <nuttx/drivers/iob.h>
#include "tcp/tcp.h"
+1 -1
View File
@@ -60,7 +60,7 @@ config NET_RXAVAIL
config NET_UDP_READAHEAD
bool "Enable UDP/IP read-ahead buffering"
default y
select NET_IOB
select DRIVERS_IOB
endif # NET_UDP && !NET_UDP_NO_STACK
endmenu # UDP Networking
+1 -1
View File
@@ -48,7 +48,7 @@
#include <nuttx/net/ip.h>
#ifdef CONFIG_NET_UDP_READAHEAD
# include <nuttx/net/iob.h>
# include <nuttx/drivers/iob.h>
#endif
#if defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK)
-1
View File
@@ -50,7 +50,6 @@
#include <nuttx/net/udp.h>
#include "devif/devif.h"
#include "iob/iob.h"
#include "udp/udp.h"
/****************************************************************************
-1
View File
@@ -62,7 +62,6 @@
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "iob/iob.h"
#include "udp/udp.h"
/****************************************************************************