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

View File

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

View File

@ -24,13 +24,10 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <poll.h>
#include <syslog.h> #include <syslog.h>
#include <string.h> #include <string.h>
#include <nuttx/fs/fs.h>
#include <nuttx/net/usrsock.h> #include <nuttx/net/usrsock.h>
#include "up_usrsock_host.h" #include "up_usrsock_host.h"
@ -47,9 +44,8 @@
struct usrsock_s struct usrsock_s
{ {
struct file usock; uint8_t in[SIM_USRSOCK_BUFSIZE];
uint8_t in [SIM_USRSOCK_BUFSIZE]; uint8_t out[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, static int usrsock_send(struct usrsock_s *usrsock,
const void *buf, size_t len) const void *buf, size_t len)
{ {
uint8_t *data = (uint8_t *)buf; return usrsock_response(buf, len, NULL);
ssize_t ret;
while (len > 0)
{
ret = file_write(&usrsock->usock, data, len);
if (ret < 0)
{
return ret;
}
data += ret;
len -= ret;
}
return 0;
} }
static int usrsock_send_ack(struct usrsock_s *usrsock, static int usrsock_send_ack(struct usrsock_s *usrsock,
@ -404,47 +385,46 @@ int usrsock_event_callback(int16_t usockid, uint16_t events)
return usrsock_send_event(&g_usrsock, usockid, 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; struct usrsock_request_common_s *common;
int ret; int ret;
struct pollfd pfd =
{
.ptr = &g_usrsock.usock,
.events = POLLIN | POLLFILE,
};
ret = poll(&pfd, 1, 0); /* Copy request to buffer */
if (ret > 0)
{
ret = file_read(&g_usrsock.usock, g_usrsock.in, sizeof(g_usrsock.in));
if (ret > 0)
{
common = (struct usrsock_request_common_s *)g_usrsock.in;
if (common->reqid >= 0 && ret = usrsock_iovec_get(g_usrsock.in, sizeof(g_usrsock.in),
common->reqid < USRSOCK_REQUEST__MAX) iov, iovcnt, 0);
{ if (ret <= 0)
ret = g_usrsock_handler[common->reqid](&g_usrsock, {
g_usrsock.in, ret); return ret;
if (ret < 0)
{
syslog(LOG_ERR, "Usrsock request %d failed: %d\n",
common->reqid, ret);
}
}
else
{
syslog(LOG_ERR, "Invalid request id: %d\n",
common->reqid);
}
}
} }
usrsock_host_loop(); common = (struct usrsock_request_common_s *)g_usrsock.in;
if (common->reqid >= 0 &&
common->reqid < USRSOCK_REQUEST__MAX)
{
ret = g_usrsock_handler[common->reqid](&g_usrsock,
g_usrsock.in, ret);
if (ret < 0)
{
syslog(LOG_ERR, "Usrsock request %d failed: %d\n",
common->reqid, ret);
}
}
else
{
syslog(LOG_ERR, "Invalid request id: %d\n",
common->reqid);
}
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, int usrsock_host_accept(int sockfd, struct sockaddr *addr,
socklen_t *addrlen); socklen_t *addrlen);
int usrsock_host_ioctl(int fd, unsigned long request, ...); int usrsock_host_ioctl(int fd, unsigned long request, ...);
void usrsock_host_loop(void); void usrsock_host_loop(void);
#endif /* __SIM__ */ #endif /* __SIM__ */

View File

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

View File

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

View File

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