You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/04/13 18:47:38 UTC

[incubator-nuttx] 01/02: rpmsg_usrsock: Support the wireless ioctl which contain pointer 1/2

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit f60480a5dbb6aac6db06bc0b90b2e00e9691bca3
Author: zhanghongyu <zh...@xiaomi.com>
AuthorDate: Sat Mar 26 16:41:13 2022 +0800

    rpmsg_usrsock: Support the wireless ioctl which contain pointer 1/2
    
    Signed-off-by: zhanghongyu <zh...@xiaomi.com>
---
 include/nuttx/wireless/wireless.h |  9 +++++++++
 net/usrsock/usrsock_dev.c         |  2 +-
 net/usrsock/usrsock_ioctl.c       | 32 +++++++++++++++++++++++++++++---
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h
index 7b240db918..ed4f5297dd 100644
--- a/include/nuttx/wireless/wireless.h
+++ b/include/nuttx/wireless/wireless.h
@@ -144,6 +144,15 @@
 
 #define SIOCSIWCOUNTRY      _WLIOC(0x0037)  /* Country code extension */
 
+#define WL_IS80211POINTERCMD(cmd) ((cmd) == SIOCGIWSCAN || \
+                                   (cmd) == SIOCSIWSCAN || \
+                                   (cmd) == SIOCSIWCOUNTRY || \
+                                   (cmd) == SIOCGIWRANGE || \
+                                   (cmd) == SIOCSIWENCODEEXT || \
+                                   (cmd) == SIOCGIWENCODEEXT || \
+                                   (cmd) == SIOCGIWESSID || \
+                                   (cmd) == SIOCSIWESSID)
+
 /* Device-specific network IOCTL commands *******************************************/
 
 #define WL_NETFIRST         0x0000          /* First network command */
diff --git a/net/usrsock/usrsock_dev.c b/net/usrsock/usrsock_dev.c
index 6edbec639b..9a41ca9854 100644
--- a/net/usrsock/usrsock_dev.c
+++ b/net/usrsock/usrsock_dev.c
@@ -222,7 +222,7 @@ static ssize_t iovec_do(FAR void *srcdst, size_t srcdstlen,
         }
     }
 
-  return total;
+  return total == 0 && iovcnt == 0 ? -1: total;
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_ioctl.c b/net/usrsock/usrsock_ioctl.c
index 0075ed1611..f77c563fd4 100644
--- a/net/usrsock/usrsock_ioctl.c
+++ b/net/usrsock/usrsock_ioctl.c
@@ -34,7 +34,9 @@
 #include <sys/socket.h>
 #include <nuttx/net/net.h>
 #include <nuttx/net/usrsock.h>
-
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+#  include <nuttx/wireless/wireless.h>
+#endif
 #include "socket/socket.h"
 #include "usrsock/usrsock.h"
 
@@ -107,7 +109,9 @@ static int do_ioctl_request(FAR struct usrsock_conn_s *conn, int cmd,
   {
   };
 
-  struct iovec bufs[2];
+  struct iovec bufs[3] =
+  {
+  };
 
   if (arglen > UINT16_MAX)
     {
@@ -126,6 +130,15 @@ static int do_ioctl_request(FAR struct usrsock_conn_s *conn, int cmd,
   bufs[1].iov_base = (FAR void *)arg;
   bufs[1].iov_len = req.arglen;
 
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+  if (WL_IS80211POINTERCMD(cmd))
+    {
+      FAR struct iwreq *wlreq = arg;
+      bufs[2].iov_base = wlreq->u.data.pointer;
+      bufs[2].iov_len = wlreq->u.data.length;
+    }
+#endif
+
   return usrsockdev_do_request(conn, bufs, ARRAY_SIZE(bufs));
 }
 
@@ -155,7 +168,10 @@ int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
   {
   };
 
-  struct iovec inbufs[1];
+  struct iovec inbufs[2] =
+  {
+  };
+
   int ret;
 
   net_lock();
@@ -186,6 +202,16 @@ int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
 
   inbufs[0].iov_base = arg;
   inbufs[0].iov_len = arglen;
+
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+  if (WL_IS80211POINTERCMD(cmd))
+    {
+      FAR struct iwreq *wlreq = arg;
+      inbufs[1].iov_base = wlreq->u.data.pointer;
+      inbufs[1].iov_len = wlreq->u.data.length;
+    }
+#endif
+
   usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
 
   /* Request user-space daemon to handle ioctl. */