You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/10/26 11:42:14 UTC

[incubator-nuttx-apps] branch master updated (60342ec -> 909eff5)

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

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


    from 60342ec  testing/sensortest: add sensor driver test
     new 196b1f0  wireless: gs2200m: Fix to handle UDP connect() with bind()
     new 0e9594e  wireless: gs2200m: Fix to handle address info in accept()
     new b71c5f8  wireless: gs2200m: Implement getpeername_request()
     new 909eff5  wireless: gs2200m: Add support for ioctl(fd, SIOCGIFADDR, ...)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 wireless/gs2200m/gs2200m_main.c | 166 ++++++++++++++++++++++++++++++++++------
 1 file changed, 142 insertions(+), 24 deletions(-)


[incubator-nuttx-apps] 01/04: wireless: gs2200m: Fix to handle UDP connect() with bind()

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 196b1f06df53541509fe149d159b1fb18d424cf7
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Fri Oct 9 21:18:29 2020 +0900

    wireless: gs2200m: Fix to handle UDP connect() with bind()
    
    Summary:
    - This commit fixes to handle UDP connect() with bind() to local port
    - NOTE: GS2200M does not support TCP connect() with bind to local port
    
    Impact:
    - All UDP cases which use connect() with gs2200m
    - Need to update nuttx as well
    
    Testing:
    - Tested with spresense:wifi
    - Create a UDP socket and bind() to local port.
    - Then connect() to remote address with port and send()
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 wireless/gs2200m/gs2200m_main.c | 74 +++++++++++++++++++++++++++++++++--------
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/wireless/gs2200m/gs2200m_main.c b/wireless/gs2200m/gs2200m_main.c
index bbb93ad..628ea61 100644
--- a/wireless/gs2200m/gs2200m_main.c
+++ b/wireless/gs2200m/gs2200m_main.c
@@ -77,9 +77,11 @@ enum sock_state_e
 
 struct usock_s
 {
-  int8_t  type;
-  char    cid;
+  int8_t   type;
+  char     cid;
   enum sock_state_e state;
+  uint16_t lport;           /* local port */
+  struct sockaddr_in raddr; /* remote addr */
 };
 
 struct gs2200m_s
@@ -581,6 +583,35 @@ static int connect_request(int fd, FAR struct gs2200m_s *priv,
       goto prepare;
     }
 
+  memset(&cmsg, 0, sizeof(cmsg));
+
+  /* Check if this socket is already connected. */
+
+  if (BOUND == usock->state)
+    {
+      if (usock->type == SOCK_STREAM)
+        {
+          ret = -EISCONN;
+          goto prepare;
+        }
+      else
+        {
+          /* Firstly, close the socket */
+
+          struct gs2200m_close_msg clmsg;
+          memset(&clmsg, 0, sizeof(clmsg));
+          clmsg.cid = usock->cid;
+
+          ioctl(priv->gsfd, GS2200M_IOC_CLOSE, (unsigned long)&clmsg);
+
+          /* Copy the local port info */
+
+          cmsg.lport = usock->lport;
+
+          usock->state = OPENED;
+        }
+    }
+
   /* Check if address size ok. */
 
   if (req->addrlen > sizeof(addr))
@@ -622,6 +653,7 @@ static int connect_request(int fd, FAR struct gs2200m_s *priv,
     {
       usock->cid   = cmsg.cid;
       usock->state = CONNECTED;
+      usock->raddr = addr;
     }
   else
     {
@@ -704,26 +736,41 @@ static int sendto_request(int fd, FAR struct gs2200m_s *priv,
       goto prepare;
     }
 
+  memset(&smsg, 0, sizeof(smsg));
+
   smsg.is_tcp = (usock->type == SOCK_STREAM) ? true : false;
 
   /* For UDP, addlen must be provided */
 
-  if (usock->type == SOCK_DGRAM && CONNECTED != usock->state)
+  if (usock->type == SOCK_DGRAM)
     {
-      if (req->addrlen == 0)
+      if (CONNECTED != usock->state)
         {
-          ret = -EINVAL;
-          goto prepare;
-        }
+          if (req->addrlen == 0)
+            {
+              ret = -EINVAL;
+              goto prepare;
+            }
 
-      /* In UDP case, read the address. */
+          /* In UDP case, read the address. */
 
-      rlen = read(fd, &smsg.addr, sizeof(smsg.addr));
+          rlen = read(fd, &smsg.addr, sizeof(smsg.addr));
 
-      if (rlen < 0 || rlen < req->addrlen)
+          if (rlen < 0 || rlen < req->addrlen)
+            {
+              ret = -EFAULT;
+              goto prepare;
+            }
+        }
+      else if (CONNECTED == usock->state)
         {
-          ret = -EFAULT;
-          goto prepare;
+          /* Copy remote address */
+
+          smsg.addr = usock->raddr;
+        }
+      else
+        {
+          ASSERT(false);
         }
 
       gs2200m_printf("%s: addr: %s:%d",
@@ -1010,7 +1057,8 @@ static int bind_request(int fd, FAR struct gs2200m_s *priv,
 
   if (0 == ret)
     {
-      usock->cid = bmsg.cid;
+      usock->cid   = bmsg.cid;
+      usock->lport = ntohs(addr.sin_port);
       usock->state = BOUND;
     }
 


[incubator-nuttx-apps] 03/04: wireless: gs2200m: Implement getpeername_request()

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b71c5f8cb1870c6c19f0111e69dbc9a31ce0f692
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Mon Oct 12 11:47:57 2020 +0900

    wireless: gs2200m: Implement getpeername_request()
    
    Summary:
    - This commit adds getperrname_request() to gs2200m_main.c
    
    Impact:
    - Affects gs2200m only
    - Need to update nuttx as well
    
    Testing:
    - Tested with spresense:wifi
    - Modify telnetd and add getpeername() to show a client address
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 wireless/gs2200m/gs2200m_main.c | 79 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 3 deletions(-)

diff --git a/wireless/gs2200m/gs2200m_main.c b/wireless/gs2200m/gs2200m_main.c
index b95be57..ff45c25 100644
--- a/wireless/gs2200m/gs2200m_main.c
+++ b/wireless/gs2200m/gs2200m_main.c
@@ -1415,14 +1415,87 @@ err_out:
 }
 
 /****************************************************************************
- * Name: getsockname_request
+ * Name: getpeername_request
  ****************************************************************************/
 
 static int getpeername_request(int fd, FAR struct gs2200m_s *priv,
                                FAR void *hdrbuf)
 {
-  DEBUGASSERT(false);
-  return -ENOSYS;
+  FAR struct usrsock_request_getpeername_s *req = hdrbuf;
+  struct usrsock_message_datareq_ack_s resp;
+  FAR struct usock_s *usock;
+  int ret = 0;
+
+  DEBUGASSERT(priv);
+  DEBUGASSERT(req);
+
+  gs2200m_printf("%s: called **** \n", __func__);
+
+  /* Check if this socket exists. */
+
+  usock = gs2200m_socket_get(priv, req->usockid);
+
+  if (!usock)
+    {
+      ret = -EBADFD;
+      goto prepare;
+    }
+
+  if (CONNECTED != usock->state)
+    {
+      ret = -ENOTCONN;
+    }
+
+prepare:
+
+  /* Prepare response. */
+
+  memset(&resp, 0, sizeof(resp));
+  resp.reqack.xid = req->head.xid;
+  resp.reqack.head.msgid = USRSOCK_MESSAGE_RESPONSE_DATA_ACK;
+  resp.reqack.head.flags = 0;
+  resp.reqack.result = ret;
+
+  if (0 == ret)
+    {
+      resp.valuelen_nontrunc = sizeof(usock->raddr);
+      resp.valuelen = resp.valuelen_nontrunc;
+
+      if (resp.valuelen > req->max_addrlen)
+        {
+          resp.valuelen = req->max_addrlen;
+        }
+    }
+  else
+    {
+      resp.valuelen_nontrunc = 0;
+      resp.valuelen = 0;
+    }
+
+  /* Send response. */
+
+  ret = _write_to_usock(fd, &resp, sizeof(resp));
+
+  if (0 > ret)
+    {
+      goto err_out;
+    }
+
+  if (resp.valuelen > 0)
+    {
+      /* Send address (value) */
+
+      ret = _write_to_usock(fd, &usock->raddr, resp.valuelen);
+
+      if (0 > ret)
+        {
+          goto err_out;
+        }
+    }
+
+err_out:
+  gs2200m_printf("%s: end \n", __func__);
+  return ret;
 }
 
 /****************************************************************************


[incubator-nuttx-apps] 02/04: wireless: gs2200m: Fix to handle address info in accept()

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0e9594e1074efb5cc26ef6d58e20a87ef39e1ecc
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Mon Oct 12 14:02:18 2020 +0900

    wireless: gs2200m: Fix to handle address info in accept()
    
    Summary:
    - This commit fixes to handle address info in accept()
    
    Impact:
    - All use cases which use accept() with gs2200m
    - Need to update nuttx as well
    
    Testing:
    - Tested with spresene:wifi
    - Tested with telnet daemon
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 wireless/gs2200m/gs2200m_main.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/wireless/gs2200m/gs2200m_main.c b/wireless/gs2200m/gs2200m_main.c
index 628ea61..b95be57 100644
--- a/wireless/gs2200m/gs2200m_main.c
+++ b/wireless/gs2200m/gs2200m_main.c
@@ -1132,7 +1132,6 @@ static int accept_request(int fd, FAR struct gs2200m_s *priv,
   struct gs2200m_accept_msg amsg;
   FAR struct usock_s *usock;
   FAR struct usock_s *new_usock = NULL;
-  struct sockaddr_in ep_addr;
   int ret = 0;
   int16_t usockid; /* usockid for new client */
 
@@ -1173,6 +1172,7 @@ static int accept_request(int fd, FAR struct gs2200m_s *priv,
 
   new_usock->cid   = amsg.cid;
   new_usock->state = CONNECTED;
+  new_usock->raddr = amsg.addr;
 
 prepare:
 
@@ -1185,8 +1185,8 @@ prepare:
 
   if (0 == ret)
     {
-      resp.reqack.result = 2; /* ep_addr + usock */
-      resp.valuelen_nontrunc = sizeof(ep_addr);
+      resp.reqack.result = 2; /* new_usock->raddr + usock */
+      resp.valuelen_nontrunc = sizeof(new_usock->raddr);
       resp.valuelen = resp.valuelen_nontrunc;
     }
   else
@@ -1208,11 +1208,7 @@ prepare:
     {
       /* Send address (value) */
 
-      /* TODO: ep_addr should be set */
-
-      memset(&ep_addr, 0, sizeof(ep_addr));
-
-      ret = _write_to_usock(fd, &ep_addr, resp.valuelen);
+      ret = _write_to_usock(fd, &new_usock->raddr, resp.valuelen);
 
       if (0 > ret)
         {


[incubator-nuttx-apps] 04/04: wireless: gs2200m: Add support for ioctl(fd, SIOCGIFADDR, ...)

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 909eff540d8004371d5838b9c0764cc753d665cf
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Mon Oct 12 19:53:30 2020 +0900

    wireless: gs2200m: Add support for ioctl(fd, SIOCGIFADDR, ...)
    
    Summary:
    - This commit adds support for ioctl(fd, SIOCGIFADDR, ...) to gs2200m_main.c
    
    Impact:
    - Only affects ioctl(fd, SIOCGIFADDR, ...) with gs2200m
    - Need to update nuttx as well
    
    Testing:
    - Tested with spresense:wifi
    - Tested with dhcpc
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 wireless/gs2200m/gs2200m_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/wireless/gs2200m/gs2200m_main.c b/wireless/gs2200m/gs2200m_main.c
index ff45c25..5865aaf 100644
--- a/wireless/gs2200m/gs2200m_main.c
+++ b/wireless/gs2200m/gs2200m_main.c
@@ -1516,6 +1516,7 @@ static int ioctl_request(int fd, FAR struct gs2200m_s *priv,
 
   switch (req->cmd)
     {
+      case SIOCGIFADDR:
       case SIOCGIFHWADDR:
         getreq = true;
         break;