drivers/net/rpmsgdrv.c: add bidirectional data netdev support, server side

Server side: when ns_bind, create the netdev.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2025-07-14 22:02:31 +08:00 committed by Xiang Xiao
parent 34b350e66e
commit be3ad13260
4 changed files with 87 additions and 0 deletions

View file

@ -35,6 +35,7 @@
#include <nuttx/input/uinput.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/net/loopback.h>
#include <nuttx/net/rpmsgdrv.h>
#include <nuttx/net/tun.h>
#include <nuttx/net/telnet.h>
#include <nuttx/note/note_driver.h>
@ -267,6 +268,12 @@ void drivers_initialize(void)
usrsock_rpmsg_server_initialize();
#endif
#ifdef CONFIG_NET_RPMSG_DRV_SERVER
/* Initialize the net rpmsg default server */
net_rpmsg_drv_server_init();
#endif
#ifdef CONFIG_SMART_DEV_LOOP
smart_loop_register_driver();
#endif

View file

@ -66,6 +66,12 @@ config NET_RPMSG_STACKSIZE
---help---
The stack size allocated for the net RPMSG task.
config NET_RPMSG_DRV_SERVER
bool "Net rpmsg default server"
default n
---help---
Enable the net rpmsg default server.
endif # NET_RPMSG_DRV
config NETDEV_TELNET

View file

@ -938,6 +938,53 @@ net_rpmsg_drv_alloc(FAR const char *devname, enum net_lltype_e lltype)
return priv;
}
#ifdef CONFIG_NET_RPMSG_DRV_SERVER
/****************************************************************************
* Name: net_rpmsg_drv_ns_match
****************************************************************************/
static bool net_rpmsg_drv_ns_match(FAR struct rpmsg_device *rdev,
FAR void *priv, FAR const char *name,
uint32_t dest)
{
return !strncmp(name, NET_RPMSG_EPT_PREFIX, strlen(NET_RPMSG_EPT_PREFIX));
}
/****************************************************************************
* Name: net_rpmsg_drv_ns_bind
****************************************************************************/
static void net_rpmsg_drv_ns_bind(FAR struct rpmsg_device *rdev,
FAR void *priv_, FAR const char *name,
uint32_t dest)
{
FAR struct net_rpmsg_drv_s *priv;
FAR struct net_driver_s *dev;
const char *devname = name + strlen(NET_RPMSG_EPT_PREFIX);
dev = netdev_findbyname(devname);
if (dev)
{
priv = container_of(dev, struct net_rpmsg_drv_s, dev.netdev);
priv->ept.priv = priv;
priv->ept.release_cb = net_rpmsg_drv_ept_release;
priv->ept.ns_bound_cb = net_rpmsg_drv_ns_bound;
}
else
{
priv = net_rpmsg_drv_alloc(devname, NET_LL_ETHERNET);
if (!priv)
{
return;
}
}
rpmsg_create_ept(&priv->ept, rdev, name, RPMSG_ADDR_ANY, dest,
net_rpmsg_drv_ept_cb, rpmsg_destroy_ept);
rpmsg_post(&drv->ept, &drv->wait);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -1025,3 +1072,18 @@ void net_rpmsg_drv_set_callback(FAR struct netdev_lowerhalf_s *dev,
priv->cb = cb;
priv->priv = priv;
}
#ifdef CONFIG_NET_RPMSG_DRV_SERVER
/****************************************************************************
* Name: net_rpmsg_drv_server_init
****************************************************************************/
int net_rpmsg_drv_server_init(void)
{
return rpmsg_register_callback(NULL,
NULL,
NULL,
net_rpmsg_drv_ns_match,
net_rpmsg_drv_ns_bind);
}
#endif

View file

@ -112,6 +112,18 @@ FAR void *net_rpmsg_drv_priv(FAR struct netdev_lowerhalf_s *dev);
void net_rpmsg_drv_set_callback(FAR struct netdev_lowerhalf_s *dev,
net_rpmsg_drv_cb_t cb, FAR void *priv);
/****************************************************************************
* Name: net_rpmsg_drv_server_init
*
* Description:
* Initialize the RPMSG network (for server side).
*
****************************************************************************/
#ifdef CONFIG_NET_RPMSG_DRV_SERVER
int net_rpmsg_drv_server_init(void);
#endif
#undef EXTERN
#ifdef __cplusplus
}