From ef827e88a7352a259ba7975e64327627a32dad93 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Tue, 15 Oct 2024 15:10:52 +0300 Subject: [PATCH] net: Copy out also can cmsg data into the end of packet This has been broken at some point. Just fix it by copying the can frame and the cmsg data into IOB, and fix devif_poll to copy out the full data. The can drivers expect to find the timeout timestamp in the end of the frame. Signed-off-by: Jukka Laitinen --- net/can/can_sendmsg.c | 5 ++--- net/devif/devif_poll.c | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/can/can_sendmsg.c b/net/can/can_sendmsg.c index 5f13e99b88..9dc764dc58 100644 --- a/net/can/can_sendmsg.c +++ b/net/can/can_sendmsg.c @@ -109,8 +109,8 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev, /* Copy the packet data into the device packet buffer and send it */ int ret = devif_send(dev, pstate->snd_buffer, - pstate->snd_buflen, 0); - dev->d_len = dev->d_sndlen; + pstate->snd_buflen + pstate->pr_msglen, 0); + dev->d_len = dev->d_sndlen - pstate->pr_msglen; if (ret <= 0) { pstate->snd_sent = ret; @@ -122,7 +122,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev, { memcpy(dev->d_buf + pstate->snd_buflen, pstate->pr_msgbuf, pstate->pr_msglen); - dev->d_sndlen = pstate->snd_buflen + pstate->pr_msglen; } } diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 2d12606e94..6453e85a5f 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -1032,6 +1032,7 @@ static int devif_poll_callback(FAR struct net_driver_s *dev) int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { + unsigned len; uint16_t llhdrlen; FAR uint8_t *buf; int bstop; @@ -1054,7 +1055,8 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback) { /* Copy iob to flat buffer */ - iob_copyout(buf, dev->d_iob, dev->d_len, -llhdrlen); + len = MAX(dev->d_len, dev->d_sndlen); + iob_copyout(buf, dev->d_iob, len, -llhdrlen); /* Restore flat buffer pointer */