2014-06-22 19:27:57 +02:00
|
|
|
/****************************************************************************
|
2014-06-29 02:07:02 +02:00
|
|
|
* net/devif/devif_iobsend.c
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-24 03:25:16 +02:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-06-22 19:27:57 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
2023-01-30 14:36:39 +01:00
|
|
|
#include <errno.h>
|
2014-06-22 19:27:57 +02:00
|
|
|
|
2017-05-09 15:34:59 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-06-22 19:27:57 +02:00
|
|
|
|
2017-05-09 15:34:59 +02:00
|
|
|
#ifdef CONFIG_MM_IOB
|
2014-06-22 19:27:57 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-19 23:02:56 +01:00
|
|
|
* Public Functions
|
2014-06-22 19:27:57 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-06-29 02:36:09 +02:00
|
|
|
* Name: devif_iob_send
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called from socket logic in response to a xmit or poll request from the
|
|
|
|
* the network interface driver.
|
|
|
|
*
|
2014-06-29 02:36:09 +02:00
|
|
|
* This is identical to calling devif_send() except that the data is
|
2014-06-24 03:38:10 +02:00
|
|
|
* in an I/O buffer chain, rather than a flat buffer.
|
|
|
|
*
|
2014-06-22 19:27:57 +02:00
|
|
|
* Assumptions:
|
2018-06-23 22:09:06 +02:00
|
|
|
* Called with the network locked.
|
2014-06-22 19:27:57 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-05-29 23:26:19 +02:00
|
|
|
int devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
|
|
|
|
unsigned int len, unsigned int offset,
|
|
|
|
unsigned int target_offset)
|
2014-06-22 19:27:57 +02:00
|
|
|
{
|
2023-01-30 14:36:39 +01:00
|
|
|
int ret;
|
2022-11-23 12:39:40 +01:00
|
|
|
|
2023-01-30 14:36:39 +01:00
|
|
|
if (dev == NULL)
|
2022-01-20 14:02:37 +01:00
|
|
|
{
|
2023-01-30 14:36:39 +01:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
2022-11-23 12:39:40 +01:00
|
|
|
|
2023-01-09 13:47:11 +01:00
|
|
|
#ifndef CONFIG_NET_IPFRAG
|
2023-01-30 14:36:39 +01:00
|
|
|
if (len > NETDEV_PKTSIZE(dev) - NET_LL_HDRLEN(dev) - target_offset)
|
|
|
|
{
|
|
|
|
ret = -EMSGSIZE;
|
|
|
|
goto errout;
|
2022-01-20 14:02:37 +01:00
|
|
|
}
|
2023-01-30 14:36:39 +01:00
|
|
|
#endif
|
2014-06-22 19:27:57 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
/* Append the send buffer after device buffer */
|
|
|
|
|
2023-01-30 14:36:39 +01:00
|
|
|
if (len > iob_navail(false) * CONFIG_IOB_BUFSIZE)
|
2022-11-23 12:39:40 +01:00
|
|
|
{
|
2023-01-30 14:36:39 +01:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout;
|
|
|
|
}
|
2022-11-23 12:39:40 +01:00
|
|
|
|
2023-01-30 14:36:39 +01:00
|
|
|
/* Clone the iob to target device buffer */
|
2022-11-23 12:39:40 +01:00
|
|
|
|
2023-01-30 14:36:39 +01:00
|
|
|
ret = iob_clone_partial(iob, len, offset, dev->d_iob,
|
|
|
|
target_offset, false, false);
|
|
|
|
if (ret != OK)
|
2022-11-23 12:39:40 +01:00
|
|
|
{
|
2023-01-30 14:36:39 +01:00
|
|
|
netdev_iob_release(dev);
|
|
|
|
goto errout;
|
2022-11-23 12:39:40 +01:00
|
|
|
}
|
2014-06-23 02:53:18 +02:00
|
|
|
|
2023-01-30 14:36:39 +01:00
|
|
|
dev->d_sndlen = len;
|
|
|
|
|
2014-06-23 02:53:18 +02:00
|
|
|
#ifdef CONFIG_NET_TCP_WRBUFFER_DUMP
|
|
|
|
/* Dump the outgoing device buffer */
|
|
|
|
|
2015-01-17 12:59:13 +01:00
|
|
|
lib_dumpbuffer("devif_iob_send", dev->d_appdata, len);
|
2014-06-23 02:53:18 +02:00
|
|
|
#endif
|
2023-01-30 14:36:39 +01:00
|
|
|
|
2023-05-29 23:26:19 +02:00
|
|
|
return dev->d_sndlen;
|
2023-01-30 14:36:39 +01:00
|
|
|
|
|
|
|
errout:
|
|
|
|
nerr("ERROR: devif_iob_send error: %d\n", ret);
|
2023-05-29 23:26:19 +02:00
|
|
|
return ret;
|
2014-06-22 19:27:57 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 15:34:59 +02:00
|
|
|
#endif /* CONFIG_MM_IOB */
|