remove access on /dev/usrsock in up_usrsock.c

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
This commit is contained in:
liangchaozhong 2022-09-07 20:38:07 +08:00 committed by Xiang Xiao
parent 5ec4296553
commit 62cbd72149
7 changed files with 40 additions and 70 deletions

View File

@ -34,6 +34,7 @@
#include <stdlib.h>
#include "up_internal.h"
#include "up_usrsock_host.h"
/****************************************************************************
* Private Functions
@ -179,7 +180,7 @@ static int up_loop_task(int argc, char **argv)
#endif
#ifdef CONFIG_SIM_NETUSRSOCK
usrsock_loop();
usrsock_host_loop();
#endif
#ifdef CONFIG_RPTUN
@ -260,12 +261,6 @@ void up_initialize(void)
netdriver_init(); /* Our "real" network driver */
#endif
#ifdef CONFIG_SIM_NETUSRSOCK
/* Register the usrsock native socket device */
usrsock_init();
#endif
#if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_MTD_SMART) && \
(defined(CONFIG_SPI_FLASH) || defined(CONFIG_QSPI_FLASH))
up_init_smartfs();

View File

@ -317,13 +317,6 @@ void netdriver_setmacaddr(unsigned char *macaddr);
void netdriver_setmtu(int mtu);
void netdriver_loop(void);
/* up_usrsock.c *************************************************************/
#ifdef CONFIG_SIM_NETUSRSOCK
int usrsock_init(void);
void usrsock_loop(void);
#endif
/* up_rptun.c ***************************************************************/
#ifdef CONFIG_RPTUN

View File

@ -24,13 +24,10 @@
#include <nuttx/config.h>
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
#include <syslog.h>
#include <string.h>
#include <nuttx/fs/fs.h>
#include <nuttx/net/usrsock.h>
#include "up_usrsock_host.h"
@ -47,7 +44,6 @@
struct usrsock_s
{
struct file usock;
uint8_t in[SIM_USRSOCK_BUFSIZE];
uint8_t out[SIM_USRSOCK_BUFSIZE];
};
@ -72,22 +68,7 @@ static struct usrsock_s g_usrsock;
static int usrsock_send(struct usrsock_s *usrsock,
const void *buf, size_t len)
{
uint8_t *data = (uint8_t *)buf;
ssize_t ret;
while (len > 0)
{
ret = file_write(&usrsock->usock, data, len);
if (ret < 0)
{
return ret;
}
data += ret;
len -= ret;
}
return 0;
return usrsock_response(buf, len, NULL);
}
static int usrsock_send_ack(struct usrsock_s *usrsock,
@ -404,27 +385,28 @@ int usrsock_event_callback(int16_t usockid, uint16_t events)
return usrsock_send_event(&g_usrsock, usockid, events);
}
int usrsock_init(void)
void usrsock_register(void)
{
return file_open(&g_usrsock.usock, "/dev/usrsock", O_RDWR);
}
void usrsock_loop(void)
/****************************************************************************
* Name: usrsock_request
****************************************************************************/
int usrsock_request(FAR struct iovec *iov, unsigned int iovcnt)
{
struct usrsock_request_common_s *common;
int ret;
struct pollfd pfd =
{
.ptr = &g_usrsock.usock,
.events = POLLIN | POLLFILE,
};
ret = poll(&pfd, 1, 0);
if (ret > 0)
{
ret = file_read(&g_usrsock.usock, g_usrsock.in, sizeof(g_usrsock.in));
if (ret > 0)
/* Copy request to buffer */
ret = usrsock_iovec_get(g_usrsock.in, sizeof(g_usrsock.in),
iov, iovcnt, 0);
if (ret <= 0)
{
return ret;
}
common = (struct usrsock_request_common_s *)g_usrsock.in;
if (common->reqid >= 0 &&
@ -443,8 +425,6 @@ void usrsock_loop(void)
syslog(LOG_ERR, "Invalid request id: %d\n",
common->reqid);
}
}
}
usrsock_host_loop();
return ret;
}

View File

@ -311,7 +311,6 @@ int usrsock_host_listen(int sockfd, int backlog);
int usrsock_host_accept(int sockfd, struct sockaddr *addr,
socklen_t *addrlen);
int usrsock_host_ioctl(int fd, unsigned long request, ...);
void usrsock_host_loop(void);
#endif /* __SIM__ */

View File

@ -31,6 +31,7 @@ CONFIG_NET_ICMP_NO_STACK=y
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_TCP_NO_STACK=y
CONFIG_NET_UDP_NO_STACK=y
CONFIG_NET_USRSOCK_CUSTOM=y
CONFIG_NET_USRSOCK_OTHER=y
CONFIG_NET_USRSOCK_TCP=y
CONFIG_NET_USRSOCK_UDP=y

View File

@ -20,6 +20,7 @@ CONFIG_NET=y
CONFIG_NET_ICMP_NO_STACK=y
CONFIG_NET_TCP_NO_STACK=y
CONFIG_NET_UDP_NO_STACK=y
CONFIG_NET_USRSOCK_CUSTOM=y
CONFIG_NET_USRSOCK_OTHER=y
CONFIG_NET_USRSOCK_TCP=y
CONFIG_NET_USRSOCK_UDP=y

View File

@ -29,6 +29,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <sys/uio.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/compiler.h>