2017-03-31 16:58:14 +02:00
|
|
|
/****************************************************************************
|
2022-09-08 10:22:23 +02:00
|
|
|
* drivers/usrsock/usrsock_dev.c
|
2017-03-31 16:58:14 +02:00
|
|
|
*
|
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>
|
2022-10-01 23:04:57 +02:00
|
|
|
#if defined(CONFIG_NET_USRSOCK_DEVICE)
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
#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>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2017-03-31 16:58:14 +02:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/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
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t devlock; /* Lock for device node */
|
|
|
|
uint8_t ocount; /* The number of times the device has been opened */
|
2017-03-31 16:58:14 +02:00
|
|
|
struct
|
|
|
|
{
|
2022-09-08 10:20:59 +02:00
|
|
|
FAR const struct iovec *iov; /* Pending request buffers */
|
|
|
|
int iovcnt; /* Number of request buffers */
|
|
|
|
size_t pos; /* Reader position on request buffer */
|
2017-03-31 16:58:14 +02:00
|
|
|
} req;
|
2022-09-08 10:20:59 +02:00
|
|
|
FAR struct pollfd *pollfds[CONFIG_NET_USRSOCKDEV_NPOLLWAITERS];
|
2017-03-31 16:58:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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 */
|
2023-01-02 14:02:51 +01:00
|
|
|
NULL, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
NULL, /* truncate */
|
2019-05-22 02:57:54 +02:00
|
|
|
usrsockdev_poll /* poll */
|
2017-03-31 16:58:14 +02:00
|
|
|
};
|
|
|
|
|
2022-09-08 10:22:23 +02:00
|
|
|
static struct usrsockdev_s g_usrsockdev =
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
NXMUTEX_INITIALIZER
|
2022-09-08 10:22:23 +02:00
|
|
|
};
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t usrsockdev_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
2022-09-08 10:20:59 +02:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2017-03-31 16:58:14 +02:00
|
|
|
FAR struct usrsockdev_s *dev;
|
2022-09-08 10:20:59 +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);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
/* Is request available? */
|
|
|
|
|
|
|
|
if (dev->req.iov)
|
|
|
|
{
|
|
|
|
ssize_t rlen;
|
|
|
|
|
|
|
|
/* Copy request to user-space. */
|
|
|
|
|
2022-09-01 04:11:44 +02:00
|
|
|
rlen = usrsock_iovec_get(buffer, len, dev->req.iov, dev->req.iovcnt,
|
2022-09-17 02:56:49 +02:00
|
|
|
dev->req.pos, NULL);
|
2017-03-31 16:58:14 +02:00
|
|
|
if (rlen < 0)
|
|
|
|
{
|
|
|
|
/* Tried reading beyond buffer. */
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->req.pos += rlen;
|
|
|
|
len = rlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
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
|
|
|
{
|
2022-09-08 10:20:59 +02:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2017-03-31 16:58:14 +02:00
|
|
|
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);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
/* 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. */
|
|
|
|
|
2022-09-01 04:11:44 +02:00
|
|
|
rlen = usrsock_iovec_get(NULL, 0, dev->req.iov, dev->req.iovcnt,
|
2022-09-17 02:56:49 +02:00
|
|
|
pos, NULL);
|
2017-03-31 16:58:14 +02:00
|
|
|
if (rlen < 0)
|
|
|
|
{
|
|
|
|
/* Tried seek beyond buffer. */
|
|
|
|
|
|
|
|
pos = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dev->req.pos = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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 usrsockdev_s *dev;
|
2022-09-01 04:11:44 +02:00
|
|
|
bool req_done = false;
|
2022-09-08 10:20:59 +02:00
|
|
|
ssize_t ret = 0;
|
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);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-31 16:58:14 +02:00
|
|
|
|
2022-09-01 04:11:44 +02:00
|
|
|
ret = usrsock_response(buffer, len, &req_done);
|
|
|
|
if (req_done && dev->req.iov)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
2022-09-01 04:11:44 +02:00
|
|
|
dev->req.iov = NULL;
|
|
|
|
dev->req.pos = 0;
|
|
|
|
dev->req.iovcnt = 0;
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
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);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: usrsockdev_close
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int usrsockdev_close(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct usrsockdev_s *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(inode);
|
|
|
|
|
|
|
|
dev = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
ninfo("closing /dev/usrsock\n");
|
|
|
|
|
|
|
|
/* Decrement the references to the driver. */
|
|
|
|
|
|
|
|
dev->ocount--;
|
|
|
|
DEBUGASSERT(dev->ocount == 0);
|
|
|
|
ret = OK;
|
2022-09-01 04:11:44 +02:00
|
|
|
dev->req.iov = NULL;
|
|
|
|
dev->req.iovcnt = 0;
|
|
|
|
dev->req.pos = 0;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2022-09-01 04:11:44 +02:00
|
|
|
usrsock_abort();
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
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? */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&dev->devlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
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 &&
|
2022-09-01 04:11:44 +02:00
|
|
|
!(usrsock_iovec_get(NULL, 0, dev->req.iov,
|
2022-09-17 02:56:49 +02:00
|
|
|
dev->req.iovcnt, dev->req.pos, NULL) < 0))
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
|
|
|
eventset |= POLLIN;
|
|
|
|
}
|
|
|
|
|
2022-09-19 05:08:57 +02:00
|
|
|
poll_notify(dev->pollfds, ARRAY_SIZE(dev->pollfds), eventset);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
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:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-09-01 04:11:44 +02:00
|
|
|
* Name: usrsock_request
|
2017-03-31 16:58:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-09-01 04:11:44 +02:00
|
|
|
int usrsock_request(FAR struct iovec *iov, unsigned int iovcnt)
|
2017-03-31 16:58:14 +02:00
|
|
|
{
|
2022-08-21 22:24:31 +02:00
|
|
|
FAR struct usrsockdev_s *dev = &g_usrsockdev;
|
2022-09-01 04:11:44 +02:00
|
|
|
int ret = 0;
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
/* Set outstanding request for daemon to handle. */
|
|
|
|
|
2023-01-28 16:02:52 +01:00
|
|
|
net_mutex_lock(&dev->devlock);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
|
|
|
if (usrsockdev_is_opened(dev))
|
|
|
|
{
|
|
|
|
DEBUGASSERT(dev->req.iov == NULL);
|
|
|
|
dev->req.iov = iov;
|
|
|
|
dev->req.pos = 0;
|
|
|
|
dev->req.iovcnt = iovcnt;
|
|
|
|
|
|
|
|
/* Notify daemon of new request. */
|
|
|
|
|
2022-09-19 05:08:57 +02:00
|
|
|
poll_notify(dev->pollfds, ARRAY_SIZE(dev->pollfds), POLLIN);
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-01 04:11:44 +02:00
|
|
|
ninfo("daemon abruptly closed /dev/usrsock.\n");
|
|
|
|
ret = -ENETDOWN;
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&dev->devlock);
|
2022-09-01 04:11:44 +02:00
|
|
|
return ret;
|
2017-03-31 16:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-09-01 04:11:44 +02:00
|
|
|
* Name: usrsock_register
|
2017-03-31 16:58:14 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Register /dev/usrsock
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-09-01 04:11:44 +02:00
|
|
|
void usrsock_register(void)
|
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
|
|
|
}
|
|
|
|
|
2022-10-01 23:04:57 +02:00
|
|
|
#endif /* CONFIG_NET_USRSOCK_DEVICE */
|