2017-03-31 16:58:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/usrsock/usrsock_dev.c
|
|
|
|
*
|
2021-11-15 07:53:26 +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
|
2017-03-31 16:58:14 +02:00
|
|
|
*
|
2021-11-15 07:53:26 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-03-31 16:58:14 +02:00
|
|
|
*
|
2021-11-15 07:53:26 +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.
|
2017-03-31 16:58:14 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_USRSOCK)
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2020-11-27 06:17:04 +01:00
|
|
|
#include <inttypes.h>
|
2017-03-31 16:58:14 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
|
|
|
#include <nuttx/random.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
2017-10-25 15:31:14 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2017-03-31 16:58:14 +02:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/usrsock.h>
|
|
|
|
|
|
|
|
#include "devif/devif.h"
|
|
|
|
#include "usrsock/usrsock.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-01-13 21:26:04 +01:00
|
|
|
* Pre-processor Definitions
|
2017-03-31 16:58:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NET_USRSOCKDEV_NPOLLWAITERS
|
|
|
|
# define CONFIG_NET_USRSOCKDEV_NPOLLWAITERS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct usrsockdev_s
|
|
|
|
{
|
|
|
|
sem_t devsem; /* Lock for device node */
|
|
|
|
uint8_t ocount; /* The number of times the device has been opened */
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
FAR const struct iovec *iov; /* Pending request buffers */
|
2022-01-04 08:53:22 +01:00
|
|
|
int iovcnt; /* Number of request buffers */
|
|
|
|
size_t pos; /* Reader position on request buffer */
|
|
|
|
sem_t sem; /* Request semaphore (only one outstanding
|
2017-03-31 16:58:14 +02:00
|
|
|
* request) */
|
2022-01-04 08:53:22 +01:00
|
|
|
sem_t acksem; /* Request acknowledgment notification */
|
|
|
|
uint64_t ackxid; /* Exchange id for which waiting ack */
|
|
|
|
uint16_t nbusy; /* Number of requests blocked from different
|
2018-10-30 01:00:30 +01:00
|
|
|
* threads */
|
2017-03-31 16:58:14 +02:00
|
|
|
} req;
|
|
|
|
|
|
|
|
FAR struct usrsock_conn_s *datain_conn; /* Connection instance to receive
|
|
|
|
* data buffers. */
|
|
|
|
struct pollfd *pollfds[CONFIG_NET_USRSOCKDEV_NPOLLWAITERS];
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Character driver methods */
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t len);
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t len);
|
|
|
|
|
|
|
|
static off_t usrsockdev_seek(FAR struct file *filep, off_t offset,
|
|
|
|
int whence);
|
|
|
|
|
|
|
|
static int usrsockdev_open(FAR struct file *filep);
|
|
|
|
|
|
|
|
static int usrsockdev_close(FAR struct file *filep);
|
|
|
|
|
|
|
|
static int usrsockdev_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|
|
|
bool setup);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct file_operations g_usrsockdevops =
|
|
|
|
{
|
|
|
|
usrsockdev_open, /* open */
|
|
|
|
usrsockdev_close, /* close */
|
|
|
|
usrsockdev_read, /* read */
|
|
|
|
usrsockdev_write, /* write */
|
|
|
|
usrsockdev_seek, /* seek */
|
2019-05-22 02:57:54 +02:00
|
|
|
NULL, /* ioctl */
|
|
|
|
usrsockdev_poll /* poll */
|
2017-03-31 16:58:14 +02:00
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
|
|
|
, NULL /* unlink */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usrsockdev_s g_usrsockdev;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iovec_do() - copy to/from iovec from/to buffer.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t iovec_do(FAR void *srcdst, size_t srcdstlen,
|
|
|
|
FAR struct iovec *iov, int iovcnt, size_t pos,
|
|
|
|
bool from_iov)
|
|
|
|
{
|
|
|
|
ssize_t total;
|
|
|
|
size_t srclen;
|
|
|
|
FAR uint8_t *ioout = srcdst;
|
|
|
|
FAR uint8_t *iovbuf;
|
|
|
|
|
|
|
|
/* Rewind to correct position. */
|
|
|
|
|
|
|
|
while (pos > 0 && iovcnt > 0)
|
|
|
|
{
|
|
|
|
if (iov->iov_len <= pos)
|
|
|
|
{
|
|
|
|
pos -= iov->iov_len;
|
|
|
|
iov++;
|
|
|
|
iovcnt--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iovcnt == 0)
|
|
|
|
{
|
|
|
|
/* Position beyond iovec. */
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iovbuf = iov->iov_base;
|
|
|
|
srclen = iov->iov_len;
|
|
|
|
iovbuf += pos;
|
|
|
|
srclen -= pos;
|
|
|
|
iov++;
|
|
|
|
iovcnt--;
|
|
|
|
total = 0;
|
|
|
|
|
|
|
|
while ((srclen > 0 || iovcnt > 0) && srcdstlen > 0)
|
|
|
|
{
|
|
|
|
size_t clen = srclen;
|
|
|
|
|
|
|
|
if (srclen == 0)
|
|
|
|
{
|
|
|
|
/* Skip empty iovec. */
|
|
|
|
|
|
|
|
iovbuf = iov->iov_base;
|
|
|
|
srclen = iov->iov_len;
|
|
|
|
iov++;
|
|
|
|
iovcnt--;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clen > srcdstlen)
|
|
|
|
{
|
|
|
|
clen = srcdstlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from_iov)
|
|
|
|
{
|
|
|
|
memmove(ioout, iovbuf, clen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memmove(iovbuf, ioout, clen);
|
|
|
|
}
|
|
|
|
|
|
|
|
ioout += clen;
|
|
|
|
srcdstlen -= clen;
|
|
|
|
iovbuf += clen;
|
|
|
|
srclen -= clen;
|
|
|
|
total += clen;
|
|
|
|
|
|
|
|
if (srclen == 0)
|
|
|
|
{
|
|
|
|
if (iovcnt == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iovbuf = iov->iov_base;
|
|
|
|
srclen = iov->iov_len;
|
|
|
|
iov++;
|
|
|
|
iovcnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-26 09:41:13 +01:00
|
|
|
return total == 0 && iovcnt == 0 ? -1: total;
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iovec_get() - copy from iovec to buffer.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t iovec_get(FAR void *dst, size_t dstlen,
|
|
|
|
FAR const struct iovec *iov, int iovcnt, size_t pos)
|
|
|
|
{
|
|
|
|
return iovec_do(dst, dstlen, (FAR struct iovec *)iov, iovcnt, pos, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iovec_put() - copy to iovec from buffer.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t iovec_put(FAR struct iovec *iov, int iovcnt, size_t pos,
|
|
|
|
FAR const void *src, size_t srclen)
|
|
|
|
{
|
|
|
|
return iovec_do((FAR void *)src, srclen, iov, iovcnt, pos, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_semtake() and usrsockdev_semgive()
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Take/give semaphore
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
static int usrsockdev_semtake(FAR sem_t *sem)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
2020-03-29 19:57:53 +02:00
|
|
|
return nxsem_wait_uninterruptible(sem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usrsockdev_semgive(FAR sem_t *sem)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_post(sem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_is_opened
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool usrsockdev_is_opened(FAR struct usrsockdev_s *dev)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (dev->ocount == 0)
|
|
|
|
{
|
|
|
|
ret = false; /* No usrsock daemon running. */
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_pollnotify
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-03-11 19:48:17 +01:00
|
|
|
static void usrsockdev_pollnotify(FAR struct usrsockdev_s *dev,
|
|
|
|
pollevent_t eventset)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->pollfds); i++)
|
|
|
|
{
|
|
|
|
struct pollfd *fds = dev->pollfds[i];
|
|
|
|
if (fds)
|
|
|
|
{
|
|
|
|
fds->revents |= (fds->events & eventset);
|
|
|
|
if (fds->revents != 0)
|
|
|
|
{
|
2022-04-01 14:59:55 +02:00
|
|
|
ninfo("Report events: %08" PRIx32 "\n", fds->revents);
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(fds->sem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
2020-03-29 19:57:53 +02:00
|
|
|
int ret;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Is request available? */
|
|
|
|
|
|
|
|
if (dev->req.iov)
|
|
|
|
{
|
|
|
|
ssize_t rlen;
|
|
|
|
|
|
|
|
/* Copy request to user-space. */
|
|
|
|
|
|
|
|
rlen = iovec_get(buffer, len, dev->req.iov, dev->req.iovcnt,
|
|
|
|
dev->req.pos);
|
|
|
|
if (rlen < 0)
|
|
|
|
{
|
|
|
|
/* Tried reading beyond buffer. */
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->req.pos += rlen;
|
|
|
|
len = rlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_seek
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
static off_t usrsockdev_seek(FAR struct file *filep, off_t offset,
|
|
|
|
int whence)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
|
|
|
off_t pos;
|
2020-03-29 19:57:53 +02:00
|
|
|
int ret;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (whence != SEEK_CUR && whence != SEEK_SET)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Is request available? */
|
|
|
|
|
|
|
|
if (dev->req.iov)
|
|
|
|
{
|
|
|
|
ssize_t rlen;
|
|
|
|
|
|
|
|
if (whence == SEEK_CUR)
|
|
|
|
{
|
|
|
|
pos = dev->req.pos + offset;
|
|
|
|
}
|
2020-04-29 12:15:18 +02:00
|
|
|
else
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
pos = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy request to user-space. */
|
|
|
|
|
|
|
|
rlen = iovec_get(NULL, 0, dev->req.iov, dev->req.iovcnt, pos);
|
|
|
|
if (rlen < 0)
|
|
|
|
{
|
|
|
|
/* Tried seek beyond buffer. */
|
|
|
|
|
|
|
|
pos = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->req.pos = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_handle_event
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_handle_event(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR const void *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_common_s *common = buffer;
|
|
|
|
|
|
|
|
switch (common->msgid)
|
|
|
|
{
|
|
|
|
case USRSOCK_MESSAGE_SOCKET_EVENT:
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_socket_event_s *hdr = buffer;
|
|
|
|
FAR struct usrsock_conn_s *conn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (len < sizeof(*hdr))
|
|
|
|
{
|
net/usrsock: Fix the compile warning
In file included from usrsock/usrsock_bind.c:32:
usrsock/usrsock_bind.c: In function ‘usrsock_bind’:
usrsock/usrsock_bind.c:183:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_bind.c:183:54: note: format string is defined here
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_connect.c
CC: usrsock/usrsock_dev.c
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_event’:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:488:40: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:488:45: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_datareq_response’:
usrsock/usrsock_dev.c:657:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
660 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:657:61: note: format string is defined here
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:678:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
678 | nwarn("%dth buffer not large enough "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
682 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:679:45: note: format string is defined here
679 | "(need: %" PRId32 ", have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_req_response’:
usrsock/usrsock_dev.c:745:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:745:34: note: format string is defined here
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_write’:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:858:38: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 | sizeof(struct usrsock_message_common_s));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:858:43: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getpeername.c
In file included from usrsock/usrsock_getpeername.c:32:
usrsock/usrsock_getpeername.c: In function ‘usrsock_getpeername’:
usrsock/usrsock_getpeername.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getpeername.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_event.c
CC: usrsock/usrsock_getsockname.c
In file included from usrsock/usrsock_getsockname.c:32:
usrsock/usrsock_getsockname.c: In function ‘usrsock_getsockname’:
usrsock/usrsock_getsockname.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getsockname.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getsockopt.c
CC: usrsock/usrsock_poll.c
CC: usrsock/usrsock_recvmsg.c
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c: In function ‘usrsock_recvmsg’:
usrsock/usrsock_recvmsg.c:321:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:321:62: note: format string is defined here
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:343:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
343 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:343:47: note: format string is defined here
343 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:384:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:384:58: note: format string is defined here
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_sendmsg.c
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c: In function ‘usrsock_sendmsg’:
usrsock/usrsock_sendmsg.c:302:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:302:62: note: format string is defined here
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:324:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
324 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:324:47: note: format string is defined here
324 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:364:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:364:58: note: format string is defined here
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-31 14:52:10 +01:00
|
|
|
nwarn("message too short, %zu < %zu.\n", len, sizeof(*hdr));
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get corresponding usrsock connection. */
|
|
|
|
|
|
|
|
conn = usrsock_active(hdr->usockid);
|
|
|
|
if (!conn)
|
|
|
|
{
|
|
|
|
nwarn("no active connection for usockid=%d.\n", hdr->usockid);
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEV_RANDOM
|
|
|
|
/* Add randomness. */
|
|
|
|
|
2022-03-22 14:59:46 +01:00
|
|
|
add_sw_randomness((hdr->head.events << 16) - hdr->usockid);
|
2017-03-31 16:58:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Handle event. */
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsock_event(conn,
|
2022-03-22 14:59:46 +01:00
|
|
|
hdr->head.events & ~USRSOCK_EVENT_INTERNAL_MASK);
|
2017-03-31 16:58:14 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = sizeof(*hdr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
nwarn("Unknown event type: %d\n", common->msgid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_handle_response
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_handle_response(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR struct usrsock_conn_s *conn,
|
|
|
|
FAR const void *buffer)
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_req_ack_s *hdr = buffer;
|
|
|
|
|
|
|
|
if (USRSOCK_MESSAGE_REQ_IN_PROGRESS(hdr->head.flags))
|
|
|
|
{
|
|
|
|
/* In-progress response is acknowledgment that response was
|
2019-03-11 19:48:17 +01:00
|
|
|
* received.
|
|
|
|
*/
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
conn->resp.inprogress = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
conn->resp.inprogress = false;
|
|
|
|
conn->resp.xid = 0;
|
|
|
|
|
|
|
|
/* Get result for common request. */
|
|
|
|
|
|
|
|
conn->resp.result = hdr->result;
|
|
|
|
|
|
|
|
/* Done with request/response. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
usrsock_event(conn, USRSOCK_EVENT_REQ_COMPLETE);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return sizeof(*hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_handle_datareq_response
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
usrsockdev_handle_datareq_response(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR struct usrsock_conn_s *conn,
|
|
|
|
FAR const void *buffer)
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_datareq_ack_s *datahdr = buffer;
|
|
|
|
FAR const struct usrsock_message_req_ack_s *hdr = &datahdr->reqack;
|
2019-03-11 19:48:17 +01:00
|
|
|
int num_inbufs;
|
|
|
|
int iovpos;
|
2017-03-31 16:58:14 +02:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
if (USRSOCK_MESSAGE_REQ_IN_PROGRESS(hdr->head.flags))
|
|
|
|
{
|
|
|
|
if (datahdr->reqack.result > 0)
|
|
|
|
{
|
|
|
|
ninfo("error: request in progress, and result > 0.\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
else if (datahdr->valuelen > 0)
|
|
|
|
{
|
|
|
|
ninfo("error: request in progress, and valuelen > 0.\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In-progress response is acknowledgment that response was
|
2019-03-11 19:48:17 +01:00
|
|
|
* received.
|
|
|
|
*/
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
conn->resp.inprogress = true;
|
|
|
|
|
|
|
|
ret = sizeof(*datahdr);
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->resp.inprogress = false;
|
|
|
|
conn->resp.xid = 0;
|
|
|
|
|
|
|
|
/* Prepare to read buffers. */
|
|
|
|
|
|
|
|
conn->resp.result = hdr->result;
|
|
|
|
conn->resp.valuelen = datahdr->valuelen;
|
|
|
|
conn->resp.valuelen_nontrunc = datahdr->valuelen_nontrunc;
|
|
|
|
|
|
|
|
if (conn->resp.result < 0)
|
|
|
|
{
|
|
|
|
/* Error, valuelen must be zero. */
|
|
|
|
|
|
|
|
if (datahdr->valuelen > 0 || datahdr->valuelen_nontrunc > 0)
|
|
|
|
{
|
2019-03-11 19:48:17 +01:00
|
|
|
nerr("error: response result negative, and valuelen or "
|
|
|
|
"valuelen_nontrunc non-zero.\n");
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done with request/response. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
usrsock_event(conn, USRSOCK_EVENT_REQ_COMPLETE);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
ret = sizeof(*datahdr);
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that number of buffers match available. */
|
|
|
|
|
|
|
|
num_inbufs = (hdr->result > 0) + 1;
|
|
|
|
|
|
|
|
if (conn->resp.datain.iovcnt < num_inbufs)
|
|
|
|
{
|
|
|
|
nwarn("not enough recv buffers (need: %d, have: %d).\n", num_inbufs,
|
|
|
|
conn->resp.datain.iovcnt);
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust length of receiving buffers. */
|
|
|
|
|
|
|
|
conn->resp.datain.total = 0;
|
|
|
|
iovpos = 0;
|
|
|
|
|
|
|
|
/* Value buffer is always the first */
|
|
|
|
|
|
|
|
if (conn->resp.datain.iov[iovpos].iov_len < datahdr->valuelen)
|
|
|
|
{
|
net/usrsock: Fix the compile warning
In file included from usrsock/usrsock_bind.c:32:
usrsock/usrsock_bind.c: In function ‘usrsock_bind’:
usrsock/usrsock_bind.c:183:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_bind.c:183:54: note: format string is defined here
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_connect.c
CC: usrsock/usrsock_dev.c
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_event’:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:488:40: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:488:45: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_datareq_response’:
usrsock/usrsock_dev.c:657:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
660 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:657:61: note: format string is defined here
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:678:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
678 | nwarn("%dth buffer not large enough "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
682 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:679:45: note: format string is defined here
679 | "(need: %" PRId32 ", have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_req_response’:
usrsock/usrsock_dev.c:745:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:745:34: note: format string is defined here
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_write’:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:858:38: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 | sizeof(struct usrsock_message_common_s));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:858:43: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getpeername.c
In file included from usrsock/usrsock_getpeername.c:32:
usrsock/usrsock_getpeername.c: In function ‘usrsock_getpeername’:
usrsock/usrsock_getpeername.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getpeername.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_event.c
CC: usrsock/usrsock_getsockname.c
In file included from usrsock/usrsock_getsockname.c:32:
usrsock/usrsock_getsockname.c: In function ‘usrsock_getsockname’:
usrsock/usrsock_getsockname.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getsockname.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getsockopt.c
CC: usrsock/usrsock_poll.c
CC: usrsock/usrsock_recvmsg.c
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c: In function ‘usrsock_recvmsg’:
usrsock/usrsock_recvmsg.c:321:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:321:62: note: format string is defined here
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:343:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
343 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:343:47: note: format string is defined here
343 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:384:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:384:58: note: format string is defined here
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_sendmsg.c
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c: In function ‘usrsock_sendmsg’:
usrsock/usrsock_sendmsg.c:302:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:302:62: note: format string is defined here
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:324:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
324 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:324:47: note: format string is defined here
324 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:364:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:364:58: note: format string is defined here
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-31 14:52:10 +01:00
|
|
|
nwarn("%dth buffer not large enough (need: %d, have: %zu).\n",
|
2017-03-31 16:58:14 +02:00
|
|
|
iovpos,
|
|
|
|
datahdr->valuelen,
|
|
|
|
conn->resp.datain.iov[iovpos].iov_len);
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust read size. */
|
|
|
|
|
|
|
|
conn->resp.datain.iov[iovpos].iov_len = datahdr->valuelen;
|
|
|
|
conn->resp.datain.total += conn->resp.datain.iov[iovpos].iov_len;
|
|
|
|
iovpos++;
|
|
|
|
|
|
|
|
if (hdr->result > 0)
|
|
|
|
{
|
|
|
|
/* Value buffer is always the first */
|
|
|
|
|
|
|
|
if (conn->resp.datain.iov[iovpos].iov_len < hdr->result)
|
|
|
|
{
|
2020-11-27 06:17:04 +01:00
|
|
|
nwarn("%dth buffer not large enough "
|
net/usrsock: Fix the compile warning
In file included from usrsock/usrsock_bind.c:32:
usrsock/usrsock_bind.c: In function ‘usrsock_bind’:
usrsock/usrsock_bind.c:183:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_bind.c:183:54: note: format string is defined here
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_connect.c
CC: usrsock/usrsock_dev.c
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_event’:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:488:40: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:488:45: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_datareq_response’:
usrsock/usrsock_dev.c:657:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
660 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:657:61: note: format string is defined here
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:678:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
678 | nwarn("%dth buffer not large enough "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
682 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:679:45: note: format string is defined here
679 | "(need: %" PRId32 ", have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_req_response’:
usrsock/usrsock_dev.c:745:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:745:34: note: format string is defined here
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_write’:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:858:38: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 | sizeof(struct usrsock_message_common_s));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:858:43: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getpeername.c
In file included from usrsock/usrsock_getpeername.c:32:
usrsock/usrsock_getpeername.c: In function ‘usrsock_getpeername’:
usrsock/usrsock_getpeername.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getpeername.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_event.c
CC: usrsock/usrsock_getsockname.c
In file included from usrsock/usrsock_getsockname.c:32:
usrsock/usrsock_getsockname.c: In function ‘usrsock_getsockname’:
usrsock/usrsock_getsockname.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getsockname.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getsockopt.c
CC: usrsock/usrsock_poll.c
CC: usrsock/usrsock_recvmsg.c
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c: In function ‘usrsock_recvmsg’:
usrsock/usrsock_recvmsg.c:321:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:321:62: note: format string is defined here
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:343:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
343 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:343:47: note: format string is defined here
343 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:384:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:384:58: note: format string is defined here
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_sendmsg.c
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c: In function ‘usrsock_sendmsg’:
usrsock/usrsock_sendmsg.c:302:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:302:62: note: format string is defined here
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:324:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
324 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:324:47: note: format string is defined here
324 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:364:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:364:58: note: format string is defined here
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-31 14:52:10 +01:00
|
|
|
"(need: %" PRId32 ", have: %zu).\n",
|
2017-03-31 16:58:14 +02:00
|
|
|
iovpos,
|
|
|
|
hdr->result,
|
|
|
|
conn->resp.datain.iov[iovpos].iov_len);
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust read size. */
|
|
|
|
|
|
|
|
conn->resp.datain.iov[iovpos].iov_len = hdr->result;
|
|
|
|
conn->resp.datain.total += conn->resp.datain.iov[iovpos].iov_len;
|
|
|
|
iovpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(num_inbufs == iovpos);
|
|
|
|
|
|
|
|
conn->resp.datain.iovcnt = num_inbufs;
|
|
|
|
|
|
|
|
/* Next written buffers are redirected to data buffers. */
|
|
|
|
|
|
|
|
dev->datain_conn = conn;
|
|
|
|
ret = sizeof(*datahdr);
|
|
|
|
|
|
|
|
unlock_out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_handle_req_response
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR const void *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_req_ack_s *hdr = buffer;
|
2022-01-04 08:53:22 +01:00
|
|
|
FAR struct usrsock_conn_s *conn = NULL;
|
2017-03-31 16:58:14 +02:00
|
|
|
unsigned int hdrlen;
|
|
|
|
ssize_t ret;
|
2018-10-30 01:00:30 +01:00
|
|
|
ssize_t (*handle_response)(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR struct usrsock_conn_s *conn,
|
|
|
|
FAR const void *buffer);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
switch (hdr->head.msgid)
|
|
|
|
{
|
|
|
|
case USRSOCK_MESSAGE_RESPONSE_ACK:
|
|
|
|
hdrlen = sizeof(struct usrsock_message_req_ack_s);
|
|
|
|
handle_response = &usrsockdev_handle_response;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USRSOCK_MESSAGE_RESPONSE_DATA_ACK:
|
|
|
|
hdrlen = sizeof(struct usrsock_message_datareq_ack_s);
|
|
|
|
handle_response = &usrsockdev_handle_datareq_response;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-01-04 08:53:22 +01:00
|
|
|
nwarn("unknown message type: %d, flags: %d, xid: %" PRIu64 ", "
|
2020-11-27 06:17:04 +01:00
|
|
|
"result: %" PRId32 "\n",
|
2017-03-31 16:58:14 +02:00
|
|
|
hdr->head.msgid, hdr->head.flags, hdr->xid, hdr->result);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < hdrlen)
|
|
|
|
{
|
net/usrsock: Fix the compile warning
In file included from usrsock/usrsock_bind.c:32:
usrsock/usrsock_bind.c: In function ‘usrsock_bind’:
usrsock/usrsock_bind.c:183:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_bind.c:183:54: note: format string is defined here
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_connect.c
CC: usrsock/usrsock_dev.c
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_event’:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:488:40: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:488:45: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_datareq_response’:
usrsock/usrsock_dev.c:657:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
660 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:657:61: note: format string is defined here
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:678:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
678 | nwarn("%dth buffer not large enough "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
682 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:679:45: note: format string is defined here
679 | "(need: %" PRId32 ", have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_req_response’:
usrsock/usrsock_dev.c:745:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:745:34: note: format string is defined here
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_write’:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:858:38: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 | sizeof(struct usrsock_message_common_s));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:858:43: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getpeername.c
In file included from usrsock/usrsock_getpeername.c:32:
usrsock/usrsock_getpeername.c: In function ‘usrsock_getpeername’:
usrsock/usrsock_getpeername.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getpeername.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_event.c
CC: usrsock/usrsock_getsockname.c
In file included from usrsock/usrsock_getsockname.c:32:
usrsock/usrsock_getsockname.c: In function ‘usrsock_getsockname’:
usrsock/usrsock_getsockname.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getsockname.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getsockopt.c
CC: usrsock/usrsock_poll.c
CC: usrsock/usrsock_recvmsg.c
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c: In function ‘usrsock_recvmsg’:
usrsock/usrsock_recvmsg.c:321:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:321:62: note: format string is defined here
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:343:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
343 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:343:47: note: format string is defined here
343 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:384:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:384:58: note: format string is defined here
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_sendmsg.c
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c: In function ‘usrsock_sendmsg’:
usrsock/usrsock_sendmsg.c:302:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:302:62: note: format string is defined here
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:324:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
324 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:324:47: note: format string is defined here
324 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:364:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:364:58: note: format string is defined here
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-31 14:52:10 +01:00
|
|
|
nwarn("message too short, %zu < %u.\n", len, hdrlen);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Get corresponding usrsock connection for this transfer */
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
while ((conn = usrsock_nextconn(conn)) != NULL &&
|
|
|
|
conn->resp.xid != hdr->xid);
|
2017-03-31 16:58:14 +02:00
|
|
|
if (!conn)
|
|
|
|
{
|
|
|
|
/* No connection waiting for this message. */
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
nwarn("Could find connection waiting for response"
|
|
|
|
"with xid=%" PRIu64 "\n", hdr->xid);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
if (dev->req.ackxid == hdr->xid && dev->req.iov)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
2019-03-11 19:48:17 +01:00
|
|
|
/* Signal that request was received and read by daemon and
|
|
|
|
* acknowledgment response was received.
|
|
|
|
*/
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
dev->req.iov = NULL;
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&dev->req.acksem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = handle_response(dev, conn, buffer);
|
|
|
|
|
|
|
|
unlock_out:
|
|
|
|
net_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_handle_message
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_handle_message(FAR struct usrsockdev_s *dev,
|
|
|
|
FAR const void *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
FAR const struct usrsock_message_common_s *common = buffer;
|
|
|
|
|
|
|
|
if (USRSOCK_MESSAGE_IS_EVENT(common->flags))
|
|
|
|
{
|
|
|
|
return usrsockdev_handle_event(dev, buffer, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (USRSOCK_MESSAGE_IS_REQ_RESPONSE(common->flags))
|
|
|
|
{
|
|
|
|
return usrsockdev_handle_req_response(dev, buffer, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-03-11 19:48:17 +01:00
|
|
|
static ssize_t usrsockdev_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer, size_t len)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsock_conn_s *conn;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
|
|
|
size_t origlen = len;
|
|
|
|
ssize_t ret = 0;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = (ssize_t)usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (!dev->datain_conn)
|
|
|
|
{
|
|
|
|
/* Start of message, buffer length should be at least size of common
|
2019-03-11 19:48:17 +01:00
|
|
|
* message header.
|
|
|
|
*/
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (len < sizeof(struct usrsock_message_common_s))
|
|
|
|
{
|
net/usrsock: Fix the compile warning
In file included from usrsock/usrsock_bind.c:32:
usrsock/usrsock_bind.c: In function ‘usrsock_bind’:
usrsock/usrsock_bind.c:183:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_bind.c:183:54: note: format string is defined here
183 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_connect.c
CC: usrsock/usrsock_dev.c
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_event’:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:488:40: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:488:19: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:488:45: note: format string is defined here
488 | nwarn("message too short, %d < %d.\n", len, sizeof(*hdr));
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_datareq_response’:
usrsock/usrsock_dev.c:657:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
660 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:657:61: note: format string is defined here
657 | nwarn("%dth buffer not large enough (need: %d, have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:678:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
678 | nwarn("%dth buffer not large enough "
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
682 | conn->resp.datain.iov[iovpos].iov_len);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:679:45: note: format string is defined here
679 | "(need: %" PRId32 ", have: %d).\n",
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_handle_req_response’:
usrsock/usrsock_dev.c:745:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:745:34: note: format string is defined here
745 | nwarn("message too short, %d < %d.\n", len, hdrlen);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c: In function ‘usrsockdev_write’:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| size_t {aka long unsigned int}
usrsock/usrsock_dev.c:858:38: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_dev.c:37:
usrsock/usrsock_dev.c:858:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
858 | nwarn("message too short, %d < %d.\n", len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 | sizeof(struct usrsock_message_common_s));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
usrsock/usrsock_dev.c:858:43: note: format string is defined here
858 | nwarn("message too short, %d < %d.\n", len,
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getpeername.c
In file included from usrsock/usrsock_getpeername.c:32:
usrsock/usrsock_getpeername.c: In function ‘usrsock_getpeername’:
usrsock/usrsock_getpeername.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getpeername.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_event.c
CC: usrsock/usrsock_getsockname.c
In file included from usrsock/usrsock_getsockname.c:32:
usrsock/usrsock_getsockname.c: In function ‘usrsock_getsockname’:
usrsock/usrsock_getsockname.c:190:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_getsockname.c:190:54: note: format string is defined here
190 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_getsockopt.c
CC: usrsock/usrsock_poll.c
CC: usrsock/usrsock_recvmsg.c
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c: In function ‘usrsock_recvmsg’:
usrsock/usrsock_recvmsg.c:321:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:321:62: note: format string is defined here
321 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:343:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
343 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:343:47: note: format string is defined here
343 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_recvmsg.c:32:
usrsock/usrsock_recvmsg.c:384:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_recvmsg.c:384:58: note: format string is defined here
384 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
CC: usrsock/usrsock_sendmsg.c
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c: In function ‘usrsock_sendmsg’:
usrsock/usrsock_sendmsg.c:302:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:302:62: note: format string is defined here
302 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:324:24: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
324 | nerr("net_timedwait errno: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:324:47: note: format string is defined here
324 | nerr("net_timedwait errno: %d\n", ret);
| ~^
| |
| int
| %ld
In file included from usrsock/usrsock_sendmsg.c:32:
usrsock/usrsock_sendmsg.c:364:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| ssize_t {aka long int}
usrsock/usrsock_sendmsg.c:364:58: note: format string is defined here
364 | nwarn("usrsock_setup_request_callback failed: %d\n", ret);
| ~^
| |
| int
| %ld
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-12-31 14:52:10 +01:00
|
|
|
nwarn("message too short, %zu < %zu.\n", len,
|
2017-03-31 16:58:14 +02:00
|
|
|
sizeof(struct usrsock_message_common_s));
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle message. */
|
|
|
|
|
|
|
|
ret = usrsockdev_handle_message(dev, buffer, len);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
buffer += ret;
|
|
|
|
len -= ret;
|
|
|
|
ret = origlen - len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data input handling. */
|
|
|
|
|
|
|
|
if (dev->datain_conn)
|
|
|
|
{
|
|
|
|
conn = dev->datain_conn;
|
|
|
|
|
|
|
|
/* Copy data from user-space. */
|
|
|
|
|
|
|
|
ret = iovec_put(conn->resp.datain.iov, conn->resp.datain.iovcnt,
|
|
|
|
conn->resp.datain.pos, buffer, len);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Tried writing beyond buffer. */
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
conn->resp.result = -EINVAL;
|
|
|
|
conn->resp.datain.pos =
|
|
|
|
conn->resp.datain.total;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
conn->resp.datain.pos += ret;
|
|
|
|
buffer += ret;
|
|
|
|
len -= ret;
|
|
|
|
ret = origlen - len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->resp.datain.pos == conn->resp.datain.total)
|
|
|
|
{
|
|
|
|
dev->datain_conn = NULL;
|
|
|
|
|
|
|
|
/* Done with data response. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
usrsock_event(conn, USRSOCK_EVENT_REQ_COMPLETE);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_open
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usrsockdev_open(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
2019-03-11 19:48:17 +01:00
|
|
|
int ret;
|
|
|
|
int tmp;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-31 16:58:14 +02:00
|
|
|
|
2019-06-03 13:43:43 +02:00
|
|
|
ninfo("opening /dev/usrsock\n");
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
/* Increment the count of references to the device. */
|
|
|
|
|
|
|
|
tmp = dev->ocount + 1;
|
|
|
|
if (tmp > 1)
|
|
|
|
{
|
|
|
|
/* Only one reference is allowed. */
|
|
|
|
|
|
|
|
nwarn("failed to open\n");
|
|
|
|
|
|
|
|
ret = -EPERM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->ocount = tmp;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_close
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usrsockdev_close(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2022-01-04 08:53:22 +01:00
|
|
|
FAR struct usrsock_conn_s *conn = NULL;
|
2017-03-31 16:58:14 +02:00
|
|
|
FAR struct usrsockdev_s *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
ninfo("closing /dev/usrsock\n");
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
net_lock();
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
/* Set active usrsock sockets to aborted state. */
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
while ((conn = usrsock_nextconn(conn)) != NULL)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
conn->resp.inprogress = false;
|
|
|
|
conn->resp.xid = 0;
|
|
|
|
usrsock_event(conn, USRSOCK_EVENT_ABORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement the references to the driver. */
|
|
|
|
|
|
|
|
dev->ocount--;
|
|
|
|
DEBUGASSERT(dev->ocount == 0);
|
|
|
|
ret = OK;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Give other threads short time window to complete recently completed
|
|
|
|
* requests.
|
|
|
|
*/
|
|
|
|
|
2020-01-04 11:37:46 +01:00
|
|
|
ret = net_timedwait(&dev->req.sem, 10);
|
2017-03-31 16:58:14 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-09-04 14:55:28 +02:00
|
|
|
if (ret != -ETIMEDOUT && ret != -EINTR)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
ninfo("net_timedwait errno: %d\n", ret);
|
|
|
|
DEBUGASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrsockdev_semgive(&dev->req.sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wake-up pending requests. */
|
|
|
|
|
|
|
|
if (dev->req.nbusy == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->req.iov = NULL;
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&dev->req.acksem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
while (true);
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
|
|
|
|
/* Check if request line is active */
|
|
|
|
|
|
|
|
if (dev->req.iov != NULL)
|
|
|
|
{
|
|
|
|
dev->req.iov = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-02-18 22:32:00 +01:00
|
|
|
* Name: usrsockdev_poll
|
2017-03-31 16:58:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usrsockdev_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|
|
|
bool setup)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
|
|
|
pollevent_t eventset;
|
2020-03-29 19:57:53 +02:00
|
|
|
int ret;
|
2017-03-31 16:58:14 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
|
|
|
/* Some sanity checking */
|
|
|
|
|
|
|
|
if (!dev || !fds)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are we setting up the poll? Or tearing it down? */
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = usrsockdev_semtake(&dev->devsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
net_lock();
|
|
|
|
if (setup)
|
|
|
|
{
|
|
|
|
/* This is a request to set up the poll. Find an available
|
|
|
|
* slot for the poll structure reference
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->pollfds); i++)
|
|
|
|
{
|
|
|
|
/* Find an available slot */
|
|
|
|
|
|
|
|
if (!dev->pollfds[i])
|
|
|
|
{
|
|
|
|
/* Bind the poll structure and this slot */
|
|
|
|
|
|
|
|
dev->pollfds[i] = fds;
|
|
|
|
fds->priv = &dev->pollfds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= ARRAY_SIZE(dev->pollfds))
|
|
|
|
{
|
|
|
|
fds->priv = NULL;
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should immediately notify on any of the requested events? */
|
|
|
|
|
|
|
|
eventset = 0;
|
|
|
|
|
|
|
|
/* Notify the POLLIN event if pending request. */
|
|
|
|
|
|
|
|
if (dev->req.iov != NULL &&
|
|
|
|
!(iovec_get(NULL, 0, dev->req.iov,
|
|
|
|
dev->req.iovcnt, dev->req.pos) < 0))
|
|
|
|
{
|
|
|
|
eventset |= POLLIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventset)
|
|
|
|
{
|
|
|
|
usrsockdev_pollnotify(dev, eventset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is a request to tear down the poll. */
|
|
|
|
|
|
|
|
FAR struct pollfd **slot = (FAR struct pollfd **)fds->priv;
|
|
|
|
|
|
|
|
if (!slot)
|
|
|
|
{
|
|
|
|
ret = -EIO;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove all memory of the poll setup */
|
|
|
|
|
|
|
|
*slot = NULL;
|
|
|
|
fds->priv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
net_unlock();
|
|
|
|
usrsockdev_semgive(&dev->devsem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_do_request
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
|
|
|
|
FAR struct iovec *iov, unsigned int iovcnt)
|
|
|
|
{
|
|
|
|
FAR struct usrsockdev_s *dev = conn->dev;
|
|
|
|
FAR struct usrsock_request_common_s *req_head = iov[0].iov_base;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
{
|
|
|
|
/* Setup conn for new usrsock device. */
|
|
|
|
|
|
|
|
dev = &g_usrsockdev;
|
|
|
|
conn->dev = dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!usrsockdev_is_opened(dev))
|
|
|
|
{
|
2019-06-03 13:43:43 +02:00
|
|
|
ninfo("usockid=%d; daemon has closed /dev/usrsock.\n", conn->usockid);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
return -ENETDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get exchange id. */
|
|
|
|
|
2022-01-04 08:53:22 +01:00
|
|
|
req_head->xid = (uintptr_t)conn;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
/* Prepare connection for response. */
|
|
|
|
|
|
|
|
conn->resp.xid = req_head->xid;
|
|
|
|
conn->resp.result = -EACCES;
|
|
|
|
|
|
|
|
++dev->req.nbusy; /* net_lock held. */
|
|
|
|
|
|
|
|
/* Set outstanding request for daemon to handle. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
net_lockedwait_uninterruptible(&dev->req.sem);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (usrsockdev_is_opened(dev))
|
|
|
|
{
|
|
|
|
DEBUGASSERT(dev->req.iov == NULL);
|
2022-01-04 08:53:22 +01:00
|
|
|
dev->req.ackxid = req_head->xid;
|
2017-03-31 16:58:14 +02:00
|
|
|
dev->req.iov = iov;
|
|
|
|
dev->req.pos = 0;
|
|
|
|
dev->req.iovcnt = iovcnt;
|
|
|
|
|
|
|
|
/* Notify daemon of new request. */
|
|
|
|
|
|
|
|
usrsockdev_pollnotify(dev, POLLIN);
|
|
|
|
|
|
|
|
/* Wait ack for request. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
net_lockedwait_uninterruptible(&dev->req.acksem);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-03 13:43:43 +02:00
|
|
|
ninfo("usockid=%d; daemon abruptly closed /dev/usrsock.\n",
|
2019-03-11 19:48:17 +01:00
|
|
|
conn->usockid);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free request line for next command. */
|
|
|
|
|
|
|
|
usrsockdev_semgive(&dev->req.sem);
|
|
|
|
|
|
|
|
--dev->req.nbusy; /* net_lock held. */
|
|
|
|
|
2020-02-22 11:12:37 +01:00
|
|
|
return OK;
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_register
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Register /dev/usrsock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void usrsockdev_register(void)
|
|
|
|
{
|
|
|
|
/* Initialize device private structure. */
|
|
|
|
|
|
|
|
g_usrsockdev.ocount = 0;
|
|
|
|
g_usrsockdev.req.nbusy = 0;
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_init(&g_usrsockdev.devsem, 0, 1);
|
|
|
|
nxsem_init(&g_usrsockdev.req.sem, 0, 1);
|
|
|
|
nxsem_init(&g_usrsockdev.req.acksem, 0, 0);
|
2020-05-17 15:56:21 +02:00
|
|
|
nxsem_set_protocol(&g_usrsockdev.req.acksem, SEM_PRIO_NONE);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
register_driver("/dev/usrsock", &g_usrsockdevops, 0666,
|
|
|
|
&g_usrsockdev);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_USRSOCK */
|