1
0
Fork 0
forked from nuttx/nuttx-update

move usrsock to kernel space

Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
This commit is contained in:
梁超众 2023-01-03 10:54:07 +08:00 committed by Xiang Xiao
parent 0a885da434
commit aca1a065a8
8 changed files with 1242 additions and 14 deletions

View file

@ -45,7 +45,6 @@ CONFIG_NETDEV_STATISTICS=y
CONFIG_NETINIT_DHCPC=y
CONFIG_NETINIT_THREAD=y
CONFIG_NETUTILS_DHCPC=y
CONFIG_NETUTILS_USRSOCK_RPMSG=y
CONFIG_NET_ARP_SEND=y
CONFIG_NET_BROADCAST=y
CONFIG_NET_ICMP=y
@ -59,6 +58,7 @@ CONFIG_NET_TCPBACKLOG=y
CONFIG_NET_TCP_WRITE_BUFFERS=y
CONFIG_NET_UDP=y
CONFIG_NET_UDP_WRITE_BUFFERS=y
CONFIG_NET_USRSOCK_RPMSG_SERVER=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_PROMPT_STRING="server> "

View file

@ -40,6 +40,7 @@
#include <nuttx/serial/pty.h>
#include <nuttx/syslog/syslog.h>
#include <nuttx/syslog/syslog_console.h>
#include <nuttx/usrsock/usrsock_rpmsg.h>
/****************************************************************************
* Public Functions
@ -177,4 +178,10 @@ void drivers_initialize(void)
#ifdef CONFIG_RPMSGMTD_SERVER
rpmsgmtd_server_init();
#endif
#ifdef CONFIG_NET_USRSOCK_RPMSG_SERVER
/* Initialize the user socket rpmsg server */
usrsock_rpmsg_server_initialize();
#endif
}

View file

@ -35,3 +35,27 @@ config NET_USRSOCK_RPMSG_CPUNAME
endmenu
endif # NET_USRSOCK
config NET_USRSOCK_RPMSG_SERVER
bool "RPMSG usrsock"
default n
depends on NET && RPTUN
---help---
Enable usrsock through rpmsg channel.
if NET_USRSOCK_RPMSG_SERVER
config NET_USRSOCK_RPMSG_SERVER_NSOCKS
int "The maximum number of socket descriptors for usrsock monitoring"
default 64
---help---
The maximum number of socket description for usrsosck monitoring.
config NET_USRSOCK_RPMSG_SERVER_NIOVEC
int "The maximum number of I/O vector for reassemble buffer"
default 8
---help---
The maximum number of I/O vector for reassemble buffer.
endif # NET_USRSOCK_RPMSG_SERVER

View file

@ -36,3 +36,13 @@ DEPPATH += --dep-path usrsock
VPATH += :usrsock
endif
ifeq ($(CONFIG_NET_USRSOCK_RPMSG_SERVER),y)
CSRCS += usrsock_rpmsg_server.c
# Include User Socket Driver build support
DEPPATH += --dep-path usrsock
VPATH += :usrsock
endif

View file

@ -25,8 +25,7 @@
#include <nuttx/net/dns.h>
#include <nuttx/rptun/openamp.h>
#include <nuttx/semaphore.h>
#include "usrsock_rpmsg.h"
#include <nuttx/usrsock/usrsock_rpmsg.h>
/****************************************************************************
* Private Types
@ -85,6 +84,7 @@ static int usrsock_rpmsg_send_dns_request(FAR void *arg,
FAR struct rpmsg_endpoint *ept = &priv->ept;
FAR struct usrsock_rpmsg_dns_request_s *dns;
uint32_t len;
int ret;
dns = rpmsg_get_tx_payload_buffer(ept, &len, true);
if (dns == NULL)
@ -98,7 +98,11 @@ static int usrsock_rpmsg_send_dns_request(FAR void *arg,
dns->addrlen = addrlen;
memcpy(dns + 1, addr, addrlen);
return rpmsg_send_nocopy(ept, dns, sizeof(*dns) + addrlen);
net_lock();
ret = rpmsg_send_nocopy(ept, dns, sizeof(*dns) + addrlen);
net_unlock();
return ret;
}
#endif
@ -141,10 +145,14 @@ static int usrsock_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
{
return usrsock_rpmsg_dns_handler(ept, data);
}
else
if (common->msgid == USRSOCK_RPMSG_FRAG_RESPONSE)
{
return usrsock_response(data, len, NULL);
data = (FAR char *)data + sizeof(struct usrsock_message_frag_ack_s);
len -= sizeof(struct usrsock_message_frag_ack_s);
}
return usrsock_response(data, len, NULL);
}
static void usrsock_rpmsg_device_created(FAR struct rpmsg_device *rdev,
@ -223,6 +231,7 @@ int usrsock_request(FAR struct iovec *iov, unsigned int iovcnt)
if (done)
{
ret = OK;
break;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/****************************************************************************
* drivers/usrsock/usrsock_rpmsg.h
* include/nuttx/usrsock/usrsock_rpmsg.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -18,8 +18,8 @@
*
****************************************************************************/
#ifndef __DRIVERS_USRSOCK_USRSOCK_RPMSG_H
#define __DRIVERS_USRSOCK_USRSOCK_RPMSG_H
#ifndef __INCLUDE_NUTTX_USRSOCK_USRSOCK_RPMSG_H
#define __INCLUDE_NUTTX_USRSOCK_USRSOCK_RPMSG_H
/****************************************************************************
* Included Files
@ -33,8 +33,10 @@
#define USRSOCK_RPMSG_EPT_NAME "rpmsg-usrsock"
#define USRSOCK_RPMSG_DNS_REQUEST USRSOCK_REQUEST__MAX
#define USRSOCK_RPMSG_DNS_EVENT 127
#define USRSOCK_RPMSG_DNS_REQUEST USRSOCK_REQUEST__MAX
#define USRSOCK_RPMSG_DNS_EVENT 126
#define USRSOCK_RPMSG_FRAG_RESPONSE 127
/****************************************************************************
* Public Types
@ -58,4 +60,45 @@ begin_packed_struct struct usrsock_rpmsg_dns_event_s
uint16_t addrlen;
} end_packed_struct;
#endif /* __DRIVERS_USRSOCK_USRSOCK_RPMSG_H */
/* fragemented ack message */
begin_packed_struct struct usrsock_message_frag_ack_s
{
struct usrsock_message_req_ack_s reqack;
/* head.result => positive buflen, negative error-code. */
uint32_t datalen; /* fragment's payload length */
} end_packed_struct;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: usrsock_rpmsg_server_initialize()
*
* Description:
* Initialize the User Socket rpmsg server. Called once and only
* from the driver layer.
*
****************************************************************************/
#ifdef CONFIG_NET_USRSOCK_RPMSG_SERVER
int usrsock_rpmsg_server_initialize(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_USRSOCK_USRSOCK_RPMSG_H */

View file

@ -625,7 +625,7 @@ ssize_t usrsock_iovec_put(FAR struct iovec *iov, int iovcnt, size_t pos,
}
/****************************************************************************
* Name: usrsock_request() - finish usrsock's request
* Name: usrsock_do_request() - finish usrsock's request
****************************************************************************/
int usrsock_do_request(FAR struct usrsock_conn_s *conn,
@ -657,7 +657,7 @@ int usrsock_do_request(FAR struct usrsock_conn_s *conn,
req->ackxid = req_head->xid;
ret = usrsock_request(iov, iovcnt);
if (ret == OK)
if (ret >= 0)
{
/* Wait ack for request. */