mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-28 12:50:41 +00:00
remove userspace usrsock rpmsg client/server
Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
This commit is contained in:
parent
8b368b7680
commit
fb638a13cc
6 changed files with 0 additions and 1684 deletions
|
|
@ -1,40 +0,0 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config NETUTILS_USRSOCK_RPMSG
|
||||
tristate "RPMSG usrsock"
|
||||
default n
|
||||
depends on NET && RPTUN
|
||||
select EVENT_FD if !NET_USRSOCK
|
||||
---help---
|
||||
Enable usrsock through rpmsg channel.
|
||||
|
||||
if NETUTILS_USRSOCK_RPMSG
|
||||
|
||||
config NETUTILS_USRSOCK_RPMSG_PRIORITY
|
||||
int "usrsock task priority"
|
||||
default 80
|
||||
---help---
|
||||
The priority for usrsock task.
|
||||
|
||||
config NETUTILS_USRSOCK_RPMSG_STACKSIZE
|
||||
int "usrsock task stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
---help---
|
||||
The stack size allocated for the usrsock task.
|
||||
|
||||
config NETUTILS_USRSOCK_NSOCK_DESCRIPTORS
|
||||
int "The maximum number of socket descriptors for usrsock monitoring"
|
||||
default 64
|
||||
---help---
|
||||
The maximum number of socket description for usrsosck monitoring.
|
||||
|
||||
config NETUTILS_USRSOCK_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 # NETUTILS_USRSOCK_RPMSG
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
############################################################################
|
||||
# apps/netutils/usrsock_rpmsg/Make.defs
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_NETUTILS_USRSOCK_RPMSG),)
|
||||
CONFIGURED_APPS += $(APPDIR)/netutils/usrsock_rpmsg
|
||||
endif
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
############################################################################
|
||||
# apps/netutils/usrsock_rpmsg/Makefile
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
PROGNAME = usrsock
|
||||
PRIORITY = CONFIG_NETUTILS_USRSOCK_RPMSG_PRIORITY
|
||||
STACKSIZE = CONFIG_NETUTILS_USRSOCK_RPMSG_STACKSIZE
|
||||
|
||||
ifeq ($(CONFIG_NET_USRSOCK),y)
|
||||
MAINSRC := usrsock_rpmsg_client.c
|
||||
else
|
||||
MAINSRC := usrsock_rpmsg_server.c
|
||||
endif
|
||||
MODULE = $(CONFIG_NETUTILS_USRSOCK_RPMSG)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/****************************************************************************
|
||||
* apps/netutils/usrsock_rpmsg/usrsock_rpmsg.h
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_NETUTILS_USRSOCK_RPMSG_H
|
||||
#define __APPS_NETUTILS_USRSOCK_RPMSG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/net/usrsock.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define USRSOCK_RPMSG_EPT_NAME "rpmsg-usrsock"
|
||||
|
||||
#define USRSOCK_RPMSG_DNS_REQUEST USRSOCK_REQUEST__MAX
|
||||
#define USRSOCK_RPMSG_DNS_EVENT 127
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* DNS request message */
|
||||
|
||||
begin_packed_struct struct usrsock_rpmsg_dns_request_s
|
||||
{
|
||||
struct usrsock_request_common_s head;
|
||||
|
||||
uint16_t addrlen;
|
||||
} end_packed_struct;
|
||||
|
||||
/* DNS event message */
|
||||
|
||||
begin_packed_struct struct usrsock_rpmsg_dns_event_s
|
||||
{
|
||||
struct usrsock_message_common_s head;
|
||||
|
||||
uint16_t addrlen;
|
||||
} end_packed_struct;
|
||||
|
||||
#endif /* __APPS_NETUTILS_USRSOCK_RPMSG_H */
|
||||
|
|
@ -1,328 +0,0 @@
|
|||
/****************************************************************************
|
||||
* apps/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/net/dns.h>
|
||||
#include <nuttx/rptun/openamp.h>
|
||||
|
||||
#include "usrsock_rpmsg.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct usrsock_rpmsg_s
|
||||
{
|
||||
struct rpmsg_endpoint ept;
|
||||
const char *cpuname;
|
||||
pid_t pid;
|
||||
sem_t sem;
|
||||
struct file file;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int usrsock_rpmsg_dns_handler(struct rpmsg_endpoint *ept, void *data,
|
||||
size_t len, uint32_t src, void *priv);
|
||||
static int usrsock_rpmsg_default_handler(struct rpmsg_endpoint *ept,
|
||||
void *data, size_t len,
|
||||
uint32_t src, void *priv_);
|
||||
|
||||
static void usrsock_rpmsg_device_created(struct rpmsg_device *rdev,
|
||||
void *priv_);
|
||||
static void usrsock_rpmsg_device_destroy(struct rpmsg_device *rdev,
|
||||
void *priv_);
|
||||
static int usrsock_rpmsg_ept_cb(struct rpmsg_endpoint *ept, void *data,
|
||||
size_t len, uint32_t src, void *priv);
|
||||
|
||||
static void usrsock_rpmsg_ns_unbind(struct rpmsg_endpoint *ept);
|
||||
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
static int usrsock_rpmsg_send_dns_request(void *arg,
|
||||
struct sockaddr *addr,
|
||||
socklen_t addrlen);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void usrsock_rpmsg_device_created(struct rpmsg_device *rdev,
|
||||
void *priv_)
|
||||
{
|
||||
struct usrsock_rpmsg_s *priv = priv_;
|
||||
int ret;
|
||||
|
||||
if (!strcmp(priv->cpuname, rpmsg_get_cpuname(rdev)))
|
||||
{
|
||||
priv->ept.priv = priv;
|
||||
|
||||
ret = rpmsg_create_ept(&priv->ept, rdev, USRSOCK_RPMSG_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
usrsock_rpmsg_ept_cb, usrsock_rpmsg_ns_unbind);
|
||||
if (ret == 0)
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
dns_register_notify(usrsock_rpmsg_send_dns_request, priv);
|
||||
#endif
|
||||
sem_post(&priv->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void usrsock_rpmsg_device_destroy(struct rpmsg_device *rdev,
|
||||
void *priv_)
|
||||
{
|
||||
struct usrsock_rpmsg_s *priv = priv_;
|
||||
|
||||
if (!strcmp(priv->cpuname, rpmsg_get_cpuname(rdev)))
|
||||
{
|
||||
rpmsg_destroy_ept(&priv->ept);
|
||||
kill(priv->pid, SIGUSR1);
|
||||
}
|
||||
}
|
||||
|
||||
static int usrsock_rpmsg_dns_handler(struct rpmsg_endpoint *ept, void *data,
|
||||
size_t len, uint32_t src, void *priv)
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
struct usrsock_rpmsg_dns_event_s *dns = data;
|
||||
|
||||
dns_add_nameserver((struct sockaddr *)(dns + 1), dns->addrlen);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usrsock_rpmsg_default_handler(struct rpmsg_endpoint *ept,
|
||||
void *data, size_t len,
|
||||
uint32_t src, void *priv_)
|
||||
{
|
||||
struct usrsock_rpmsg_s *priv = priv_;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
ssize_t ret = file_write(&priv->file, data, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
data += ret;
|
||||
len -= ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usrsock_rpmsg_ept_cb(struct rpmsg_endpoint *ept, void *data,
|
||||
size_t len, uint32_t src, void *priv)
|
||||
{
|
||||
struct usrsock_message_common_s *common = data;
|
||||
int ret;
|
||||
|
||||
switch (common->msgid)
|
||||
{
|
||||
case USRSOCK_RPMSG_DNS_EVENT:
|
||||
ret = usrsock_rpmsg_dns_handler(ept, data, len, src, priv);
|
||||
break;
|
||||
default:
|
||||
ret = usrsock_rpmsg_default_handler(ept, data, len, src, priv);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
static int usrsock_rpmsg_send_dns_request(void *arg,
|
||||
struct sockaddr *addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
struct usrsock_rpmsg_s *priv = arg;
|
||||
struct rpmsg_endpoint *ept = &priv->ept;
|
||||
struct usrsock_rpmsg_dns_request_s *dns;
|
||||
uint32_t len;
|
||||
|
||||
dns = rpmsg_get_tx_payload_buffer(ept, &len, true);
|
||||
|
||||
dns->head.reqid = USRSOCK_RPMSG_DNS_REQUEST;
|
||||
dns->head.xid = 0;
|
||||
dns->head.reserved = 0;
|
||||
dns->addrlen = addrlen;
|
||||
memcpy(dns + 1, addr, addrlen);
|
||||
|
||||
return rpmsg_send_nocopy(ept, dns, sizeof(*dns) + addrlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void usrsock_rpmsg_ns_unbind(struct rpmsg_endpoint *ept)
|
||||
{
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
dns_unregister_notify(usrsock_rpmsg_send_dns_request, ept->priv);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct usrsock_rpmsg_s priv =
|
||||
{
|
||||
};
|
||||
|
||||
int ret;
|
||||
|
||||
if (argv[1] == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
priv.cpuname = argv[1];
|
||||
priv.pid = getpid();
|
||||
|
||||
sem_init(&priv.sem, 0, 0);
|
||||
sem_setprotocol(&priv.sem, SEM_PRIO_NONE);
|
||||
|
||||
sigrelse(SIGUSR1);
|
||||
|
||||
ret = rpmsg_register_callback(&priv,
|
||||
usrsock_rpmsg_device_created,
|
||||
usrsock_rpmsg_device_destroy,
|
||||
NULL,
|
||||
NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto destroy_sem;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Wait until the rpmsg channel is ready */
|
||||
|
||||
do
|
||||
{
|
||||
ret = sem_wait(&priv.sem);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
goto unregister_callback;
|
||||
}
|
||||
|
||||
/* Open the kernel channel */
|
||||
|
||||
ret = file_open(&priv.file, "/dev/usrsock", O_RDWR);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
goto destroy_ept;
|
||||
}
|
||||
|
||||
/* Forward the packet from kernel to remote */
|
||||
|
||||
while (1)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
FAR void *buf;
|
||||
uint32_t len;
|
||||
|
||||
/* Wait the packet ready */
|
||||
|
||||
memset(&pfd, 0, sizeof(struct pollfd));
|
||||
pfd.ptr = &priv.file;
|
||||
pfd.events = POLLIN | POLLFILE;
|
||||
ret = poll(&pfd, 1, -1);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read the packet from kernel */
|
||||
|
||||
buf = rpmsg_get_tx_payload_buffer(&priv.ept, &len, true);
|
||||
if (!buf)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = file_read(&priv.file, buf, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Send the packet to remote */
|
||||
|
||||
ret = rpmsg_send_nocopy(&priv.ept, buf, ret);
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reclaim the resource */
|
||||
|
||||
file_close(&priv.file);
|
||||
|
||||
if (is_rpmsg_ept_ready(&priv.ept))
|
||||
{
|
||||
goto destroy_ept;
|
||||
}
|
||||
|
||||
/* The remote side crash, loop to wait it restore */
|
||||
}
|
||||
|
||||
destroy_ept:
|
||||
rpmsg_destroy_ept(&priv.ept);
|
||||
|
||||
unregister_callback:
|
||||
rpmsg_unregister_callback(&priv,
|
||||
usrsock_rpmsg_device_created,
|
||||
usrsock_rpmsg_device_destroy,
|
||||
NULL,
|
||||
NULL);
|
||||
destroy_sem:
|
||||
sem_destroy(&priv.sem);
|
||||
return ret;
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue