remove access on /dev/usrsock in up_usrsock.c
Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
This commit is contained in:
parent
5ec4296553
commit
62cbd72149
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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,9 +44,8 @@
|
||||
|
||||
struct usrsock_s
|
||||
{
|
||||
struct file usock;
|
||||
uint8_t in [SIM_USRSOCK_BUFSIZE];
|
||||
uint8_t out[SIM_USRSOCK_BUFSIZE];
|
||||
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,47 +385,46 @@ 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)
|
||||
{
|
||||
common = (struct usrsock_request_common_s *)g_usrsock.in;
|
||||
/* Copy request to buffer */
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
ret = usrsock_iovec_get(g_usrsock.in, sizeof(g_usrsock.in),
|
||||
iov, iovcnt, 0);
|
||||
if (ret <= 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user