2020-06-15 10:23:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/devif/devif_cansend.c
|
|
|
|
*
|
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
|
2020-06-15 10:23:25 +02:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2020-06-15 10:23:25 +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.
|
2020-06-15 10:23:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_CAN)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: devif_can_send
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called from socket logic in order to send a can packet in response to
|
|
|
|
* an xmit or poll request from the network interface driver.
|
|
|
|
*
|
|
|
|
* This is almost identical to calling devif_send() except that the data to
|
|
|
|
* be sent is copied into dev->d_buf (vs. dev->d_appdata), since there is
|
|
|
|
* no header on the data.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the network locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
2022-12-07 15:36:56 +01:00
|
|
|
unsigned int limit = NETDEV_PKTSIZE(dev) - NET_LL_HDRLEN(dev);
|
2020-06-15 10:23:25 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
if (dev == NULL || len == 0 || len > limit)
|
|
|
|
{
|
|
|
|
nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
|
|
|
|
dev, len, limit);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-15 10:23:25 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
iob_update_pktlen(dev->d_iob, 0);
|
2020-06-15 10:23:25 +02:00
|
|
|
|
2022-11-23 12:39:40 +01:00
|
|
|
/* Copy the data into the device packet buffer and set the number of
|
|
|
|
* bytes to send
|
|
|
|
*/
|
2020-06-15 10:23:25 +02:00
|
|
|
|
2022-12-07 10:44:09 +01:00
|
|
|
if (len <= iob_navail(false) * CONFIG_IOB_BUFSIZE)
|
|
|
|
{
|
|
|
|
dev->d_sndlen = iob_trycopyin(dev->d_iob, buf, len, 0, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->d_sndlen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->d_sndlen != len)
|
|
|
|
{
|
|
|
|
netdev_iob_release(dev);
|
|
|
|
dev->d_sndlen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->d_len = dev->d_sndlen;
|
2020-06-15 10:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_CAN */
|