nuttx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aguettou...@apache.org
Subject [incubator-nuttx-apps] 03/04: wapi: skip associate if ssid is invalid
Date Fri, 03 Apr 2020 12:29:32 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 6ab29d4ffbba32d6a80884c6b90e8147c48b0517
Author: chao.an <anchao@xiaomi.com>
AuthorDate: Fri Apr 3 13:30:45 2020 +0800

    wapi: skip associate if ssid is invalid
    
    Signed-off-by: chao.an <anchao@xiaomi.com>
---
 netutils/netinit/netinit.c           | 56 +++++++++++++++++++-----------------
 netutils/netinit/netinit_associate.c |  8 ++++--
 2 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/netutils/netinit/netinit.c b/netutils/netinit/netinit.c
index 1921655..0bc5346 100644
--- a/netutils/netinit/netinit.c
+++ b/netutils/netinit/netinit.c
@@ -411,17 +411,24 @@ static void netinit_net_bringup(void)
 {
 #ifdef CONFIG_NETINIT_DHCPC
   uint8_t mac[IFHWADDRLEN];
+  struct dhcpc_state ds;
   FAR void *handle;
 #endif
 
   /* Bring the network up. */
 
-  netlib_ifup(NET_DEVNAME);
+  if (netlib_ifup(NET_DEVNAME) < 0)
+    {
+      return;
+    }
 
 #ifdef CONFIG_WIRELESS_WAPI
   /* Associate the wlan with an access point. */
 
-  netinit_associate(NET_DEVNAME);
+  if (netinit_associate(NET_DEVNAME) < 0)
+    {
+      return;
+    }
 #endif
 
 #ifdef CONFIG_NET_ICMPv6_AUTOCONF
@@ -438,40 +445,37 @@ static void netinit_net_bringup(void)
   /* Set up the DHCPC modules */
 
   handle = dhcpc_open(NET_DEVNAME, &mac, IFHWADDRLEN);
+  if (handle == NULL)
+    {
+      return;
+    }
 
-  /* Get an IP address.  Note that there is no logic for renewing the IP
-   * address in this example.  The address should be renewed in
-   * ds.lease_time/2 seconds.
+  /* Get an IP address.  Note that there is no logic for renewing the
+   * IP address in this example. The address should be renewed in
+   * (ds.lease_time / 2) seconds.
    */
 
-  if (handle != NULL)
+  if (dhcpc_request(handle, &ds) == OK)
     {
-      struct dhcpc_state ds =
-      {
-      };
+      netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
 
-      if (dhcpc_request(handle, &ds) == OK)
+      if (ds.netmask.s_addr != 0)
         {
-          netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
-
-          if (ds.netmask.s_addr != 0)
-            {
-              netlib_set_ipv4netmask(NET_DEVNAME, &ds.netmask);
-            }
-
-          if (ds.default_router.s_addr != 0)
-            {
-              netlib_set_dripv4addr(NET_DEVNAME, &ds.default_router);
-            }
+          netlib_set_ipv4netmask(NET_DEVNAME, &ds.netmask);
+        }
 
-          if (ds.dnsaddr.s_addr != 0)
-            {
-              netlib_set_ipv4dnsaddr(&ds.dnsaddr);
-            }
+      if (ds.default_router.s_addr != 0)
+        {
+          netlib_set_dripv4addr(NET_DEVNAME, &ds.default_router);
         }
 
-      dhcpc_close(handle);
+      if (ds.dnsaddr.s_addr != 0)
+        {
+          netlib_set_ipv4dnsaddr(&ds.dnsaddr);
+        }
     }
+
+  dhcpc_close(handle);
 #endif
 
 #ifdef CONFIG_NETUTILS_NTPCLIENT
diff --git a/netutils/netinit/netinit_associate.c b/netutils/netinit/netinit_associate.c
index f225d03..1250109 100644
--- a/netutils/netinit/netinit_associate.c
+++ b/netutils/netinit/netinit_associate.c
@@ -41,6 +41,7 @@
 
 #include <unistd.h>
 #include <string.h>
+#include <errno.h>
 
 #include <nuttx/wireless/wireless.h>
 
@@ -60,7 +61,7 @@
 int netinit_associate(FAR const char *ifname)
 {
   struct wpa_wconfig_s conf;
-  int ret;
+  int ret = -EINVAL;
   FAR void *load;
 
   load = wapi_load_config(ifname, NULL, &conf);
@@ -77,7 +78,10 @@ int netinit_associate(FAR const char *ifname)
       conf.phraselen   = strlen(conf.passphrase);
     }
 
-  ret = wpa_driver_wext_associate(&conf);
+  if (conf.ssidlen > 0)
+    {
+      ret = wpa_driver_wext_associate(&conf);
+    }
 
   wapi_unload_config(load);
 


Mime
View raw message