You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/02/26 15:18:27 UTC

[incubator-nuttx-apps] branch master updated (ae36b6f -> 52ad01f)

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

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


    from ae36b6f  examples/ipforward:  IP Header issue for IPv4 fixed
     new ee615f0  net/wapi: remove unnecessary cast
     new 86bfe13  net/bringup: late net init after nsh script done
     new 52ad01f  netutils: save wapi config to file system

The 3 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:
 include/wireless/wapi.h              |  63 ++++++-
 netutils/netinit/netinit_associate.c |  35 ++--
 nshlib/nsh_altconsole.c              |   8 +
 nshlib/nsh_consolemain.c             |   8 +
 nshlib/nsh_init.c                    |   7 -
 nshlib/nsh_usbconsole.c              |   8 +
 wireless/wapi/Kconfig                |  13 ++
 wireless/wapi/src/driver_wext.c      |   5 +-
 wireless/wapi/src/util.c             | 331 +++++++++++++++++++++++++++++++++++
 wireless/wapi/src/wapi.c             |   3 +-
 10 files changed, 446 insertions(+), 35 deletions(-)


[incubator-nuttx-apps] 02/03: net/bringup: late net init after nsh script done

Posted by ag...@apache.org.
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 86bfe1339969606d1101d1d3d1d3d7bb07705bbe
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Feb 19 20:34:52 2020 +0800

    net/bringup: late net init after nsh script done
---
 nshlib/nsh_altconsole.c  | 8 ++++++++
 nshlib/nsh_consolemain.c | 8 ++++++++
 nshlib/nsh_init.c        | 7 -------
 nshlib/nsh_usbconsole.c  | 8 ++++++++
 4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index 0d5d628..dd574be 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -50,6 +50,8 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#include "netutils/netinit.h"
+
 #if defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE)
 
 /****************************************************************************
@@ -284,6 +286,12 @@ int nsh_consolemain(int argc, char *argv[])
   nsh_initscript(&pstate->cn_vtbl);
 #endif
 
+#ifdef CONFIG_NSH_NETINIT
+  /* Bring up the network */
+
+  netinit_bringup();
+#endif
+
 #if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
   /* Perform architecture-specific final-initialization (if configured) */
 
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 9ed118f..60e1f6e 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -47,6 +47,8 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#include "netutils/netinit.h"
+
 #if !defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE) && \
     !defined(HAVE_USB_KEYBOARD)
 
@@ -96,6 +98,12 @@ int nsh_consolemain(int argc, char *argv[])
 #endif
 #endif
 
+#ifdef CONFIG_NSH_NETINIT
+  /* Bring up the network */
+
+  netinit_bringup();
+#endif
+
 #ifdef CONFIG_NSH_USBDEV_TRACE
   /* Initialize any USB tracing options that were requested */
 
diff --git a/nshlib/nsh_init.c b/nshlib/nsh_init.c
index ce6d409..7ac91a0 100644
--- a/nshlib/nsh_init.c
+++ b/nshlib/nsh_init.c
@@ -42,7 +42,6 @@
 #include <sys/boardctl.h>
 
 #include "system/readline.h"
-#include "netutils/netinit.h"
 #include "nshlib/nshlib.h"
 
 #include "nsh.h"
@@ -103,10 +102,4 @@ void nsh_initialize(void)
 
   boardctl(BOARDIOC_INIT, 0);
 #endif
-
-#ifdef CONFIG_NSH_NETINIT
-  /* Bring up the network */
-
-  netinit_bringup();
-#endif
 }
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index c21fc2f..11c1602 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -59,6 +59,8 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#include "netutils/netinit.h"
+
 #ifdef HAVE_USB_CONSOLE
 
 /****************************************************************************
@@ -317,6 +319,12 @@ int nsh_consolemain(int argc, char *argv[])
   nsh_initscript(&pstate->cn_vtbl);
 #endif
 
+#ifdef CONFIG_NSH_NETINIT
+  /* Bring up the network */
+
+  netinit_bringup();
+#endif
+
 #if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
   /* Perform architecture-specific final-initialization (if configured) */
 


[incubator-nuttx-apps] 01/03: net/wapi: remove unnecessary cast

Posted by ag...@apache.org.
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 ee615f0568735f590441ca3dcbb8202ed0e271be
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Feb 19 20:50:02 2020 +0800

    net/wapi: remove unnecessary cast
---
 include/wireless/wapi.h              |  6 +++---
 netutils/netinit/netinit_associate.c | 10 ++++------
 wireless/wapi/src/driver_wext.c      |  5 ++---
 wireless/wapi/src/wapi.c             |  3 +--
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index 4f62596..8f487da 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -255,8 +255,8 @@ struct wpa_wconfig_s
   uint8_t ssidlen;               /* Length of the SSID */
   uint8_t phraselen;             /* Length of the passphrase */
   FAR const char *ifname;        /* E.g., "wlan0" */
-  FAR const uint8_t *ssid;       /* E.g., "myApSSID" */
-  FAR const uint8_t *passphrase; /* E.g., "mySSIDpassphrase" */
+  FAR const char *ssid;          /* E.g., "myApSSID" */
+  FAR const char *passphrase;    /* E.g., "mySSIDpassphrase" */
 };
 
 /****************************************************************************
@@ -678,7 +678,7 @@ int wapi_scan_coll(int sock, FAR const char *ifname,
  ****************************************************************************/
 
 int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname,
-                                enum wpa_alg_e alg, FAR const uint8_t *key,
+                                enum wpa_alg_e alg, FAR const char *key,
                                 size_t key_len);
 
 /****************************************************************************
diff --git a/netutils/netinit/netinit_associate.c b/netutils/netinit/netinit_associate.c
index 42b19b6..0cf0251 100644
--- a/netutils/netinit/netinit_associate.c
+++ b/netutils/netinit/netinit_associate.c
@@ -59,8 +59,6 @@
 
 int netinit_associate(FAR const char *ifname)
 {
-  static const char ssid[]       = CONFIG_NETINIT_WAPI_SSID;
-  static const char passphrase[] = CONFIG_NETINIT_WAPI_PASSPHRASE;
   struct wpa_wconfig_s wconfig;
   int ret;
 
@@ -70,12 +68,12 @@ int netinit_associate(FAR const char *ifname)
   wconfig.auth_wpa    = CONFIG_NETINIT_WAPI_AUTHWPA;
   wconfig.cipher_mode = CONFIG_NETINIT_WAPI_CIPHERMODE;
   wconfig.alg         = CONFIG_NETINIT_WAPI_ALG;
+  wconfig.ssid        = CONFIG_NETINIT_WAPI_SSID;
+  wconfig.passphrase  = CONFIG_NETINIT_WAPI_PASSPHRASE;
   wconfig.ifname      = ifname;
-  wconfig.ssid        = (FAR const uint8_t *)ssid;
-  wconfig.passphrase  = (FAR const uint8_t *)passphrase;
 
-  wconfig.ssidlen     = strlen(ssid);
-  wconfig.phraselen   = strlen(passphrase);
+  wconfig.ssidlen     = strlen(wconfig.ssid);
+  wconfig.phraselen   = strlen(wconfig.passphrase);
 
   /* Associate */
 
diff --git a/wireless/wapi/src/driver_wext.c b/wireless/wapi/src/driver_wext.c
index a3c86af..20e2b67 100644
--- a/wireless/wapi/src/driver_wext.c
+++ b/wireless/wapi/src/driver_wext.c
@@ -83,7 +83,7 @@
  ****************************************************************************/
 
 int wpa_driver_wext_set_key_ext(int sockfd,  FAR const char *ifname,
-                                enum wpa_alg_e alg, FAR const uint8_t *key,
+                                enum wpa_alg_e alg, FAR const char *key,
                                 size_t key_len)
 {
   struct iwreq iwr;
@@ -217,8 +217,7 @@ int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig)
       goto close_socket;
     }
 
-  ret = wapi_set_essid(sockfd, wconfig->ifname,
-                      (FAR const char *)wconfig->ssid, WAPI_ESSID_ON);
+  ret = wapi_set_essid(sockfd, wconfig->ifname, wconfig->ssid, WAPI_ESSID_ON);
   if (ret < 0)
     {
       nerr("ERROR: Fail set ssid: %d\n", ret);
diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c
index 0d656ba..2953fd2 100644
--- a/wireless/wapi/src/wapi.c
+++ b/wireless/wapi/src/wapi.c
@@ -535,8 +535,7 @@ static void wapi_psk_cmd(int sock, FAR const char *ifname,
   /* Set the Passphrase */
 
   ret = wpa_driver_wext_set_key_ext(sock, ifname, alg_flag,
-                                    (FAR const uint8_t *)passphrase,
-                                    strlen(passphrase));
+                                    passphrase, strlen(passphrase));
   if (ret < 0)
     {
       WAPI_ERROR("ERROR: wpa_driver_wext_set_key_ext() failed: %d\n", ret);


[incubator-nuttx-apps] 03/03: netutils: save wapi config to file system

Posted by ag...@apache.org.
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 52ad01f0bfef8c5226104d93ac3b6e273584382a
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Feb 24 11:31:38 2020 +0800

    netutils: save wapi config to file system
    
    save and reload the wapi config from file system
---
 include/wireless/wapi.h              |  57 +++++-
 netutils/netinit/netinit_associate.c |  33 ++--
 wireless/wapi/Kconfig                |  13 ++
 wireless/wapi/src/util.c             | 331 +++++++++++++++++++++++++++++++++++
 4 files changed, 416 insertions(+), 18 deletions(-)

diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index 8f487da..5813c31 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -90,9 +90,15 @@
  */
 
 #ifdef CONFIG_NET_UDP
-# define SOCK_WAPI SOCK_DGRAM
+#  define SOCK_WAPI SOCK_DGRAM
 #else
-# define SOCK_WAPI SOCK_STREAM
+#  define SOCK_WAPI SOCK_STREAM
+#endif
+
+#ifndef CONFIG_WIRELESS_WAPI_INITCONF
+#  define wapi_load_config(ifname, confname, conf) NULL
+#  define wapi_unload_config(load)
+#  define wapi_save_config(ifname, confname, conf) 0
 #endif
 
 /****************************************************************************
@@ -664,6 +670,53 @@ int wapi_scan_stat(int sock, FAR const char *ifname);
 int wapi_scan_coll(int sock, FAR const char *ifname,
                    FAR struct wapi_list_s *aps);
 
+#ifdef CONFIG_WIRELESS_WAPI_INITCONF
+/****************************************************************************
+ * Name: wapi_load_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *   Return a pointer to the hold the config resource, NULL On error.
+ *
+ ****************************************************************************/
+
+FAR void *wapi_load_config(FAR const char *ifname,
+                           FAR const char *confname,
+                           FAR struct wpa_wconfig_s *conf);
+
+/****************************************************************************
+ * Name: wapi_unload_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *  load - Config resource handler, allocate by wapi_load_config()
+ *
+ * Returned Value:
+ *
+ ****************************************************************************/
+
+void wapi_unload_config(FAR void *load);
+
+/****************************************************************************
+ * Name: wapi_save_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *
+ ****************************************************************************/
+
+int wapi_save_config(FAR const char *ifname,
+                     FAR const char *confname,
+                     FAR const struct wpa_wconfig_s *conf);
+#endif
+
 /****************************************************************************
  * Name: wpa_driver_wext_set_key_ext
  *
diff --git a/netutils/netinit/netinit_associate.c b/netutils/netinit/netinit_associate.c
index 0cf0251..f225d03 100644
--- a/netutils/netinit/netinit_associate.c
+++ b/netutils/netinit/netinit_associate.c
@@ -59,27 +59,28 @@
 
 int netinit_associate(FAR const char *ifname)
 {
-  struct wpa_wconfig_s wconfig;
+  struct wpa_wconfig_s conf;
   int ret;
+  FAR void *load;
 
-  /* Set up the network configuration */
+  load = wapi_load_config(ifname, NULL, &conf);
+  if (!load)
+    {
+      conf.ifname      = ifname;
+      conf.sta_mode    = CONFIG_NETINIT_WAPI_STAMODE;
+      conf.auth_wpa    = CONFIG_NETINIT_WAPI_AUTHWPA;
+      conf.cipher_mode = CONFIG_NETINIT_WAPI_CIPHERMODE;
+      conf.alg         = CONFIG_NETINIT_WAPI_ALG;
+      conf.ssid        = CONFIG_NETINIT_WAPI_SSID;
+      conf.passphrase  = CONFIG_NETINIT_WAPI_PASSPHRASE;
+      conf.ssidlen     = strlen(conf.ssid);
+      conf.phraselen   = strlen(conf.passphrase);
+    }
 
-  wconfig.sta_mode    = CONFIG_NETINIT_WAPI_STAMODE;
-  wconfig.auth_wpa    = CONFIG_NETINIT_WAPI_AUTHWPA;
-  wconfig.cipher_mode = CONFIG_NETINIT_WAPI_CIPHERMODE;
-  wconfig.alg         = CONFIG_NETINIT_WAPI_ALG;
-  wconfig.ssid        = CONFIG_NETINIT_WAPI_SSID;
-  wconfig.passphrase  = CONFIG_NETINIT_WAPI_PASSPHRASE;
-  wconfig.ifname      = ifname;
+  ret = wpa_driver_wext_associate(&conf);
 
-  wconfig.ssidlen     = strlen(wconfig.ssid);
-  wconfig.phraselen   = strlen(wconfig.passphrase);
+  wapi_unload_config(load);
 
-  /* Associate */
-
-  sleep(2);
-  ret = wpa_driver_wext_associate(&wconfig);
-  sleep(2);
   return ret;
 }
 
diff --git a/wireless/wapi/Kconfig b/wireless/wapi/Kconfig
index c5be591..65c532a 100644
--- a/wireless/wapi/Kconfig
+++ b/wireless/wapi/Kconfig
@@ -36,4 +36,17 @@ config WIRELESS_WAPI_PRIORITY
 	int "Command Priority"
 	default 100
 
+config WIRELESS_WAPI_INITCONF
+	bool "Wireless Configure Initialization"
+	default n
+	depends on NETUTILS_CJSON
+
+if WIRELESS_WAPI_INITCONF
+
+config WIRELESS_WAPI_CONFIG_PATH
+	string "Wireless Wapi Configure File Path"
+	default "/data/wapi.conf"
+
+endif
+
 endif
diff --git a/wireless/wapi/src/util.c b/wireless/wapi/src/util.c
index d7b3408..7b821ef 100644
--- a/wireless/wapi/src/util.c
+++ b/wireless/wapi/src/util.c
@@ -39,14 +39,21 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/ioctl.h>
 
 #include "wireless/wapi.h"
 #include "util.h"
 
+#ifdef CONFIG_WIRELESS_WAPI_INITCONF
+#include "netutils/cJSON.h"
+#endif /* CONFIG_WIRELESS_WAPI_INITCONF */
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -56,6 +63,99 @@
 #define WAPI_IOCTL_COMMAND_NAMEBUFSIZ 24
 
 /****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_WIRELESS_WAPI_INITCONF
+static FAR void *wapi_json_load(FAR const char *confname)
+{
+  FAR cJSON *root = NULL;
+  struct stat sb;
+  FAR char *buf;
+  int fd = -1;
+
+  if (stat(confname, &sb) < 0)
+    {
+      return NULL;
+    }
+
+  buf = malloc(sb.st_size);
+  if (!buf)
+    {
+      goto errout;
+    }
+
+  fd = open(confname, O_RDONLY);
+  if (fd < 0)
+    {
+      goto errout;
+    }
+
+  if (read(fd, buf, sb.st_size) != sb.st_size)
+    {
+      goto errout;
+    }
+
+  root = cJSON_Parse(buf);
+
+errout:
+  if (buf)
+    {
+      free(buf);
+    }
+
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  return root;
+}
+
+static bool wapi_json_update(FAR cJSON *root,
+                             FAR const char *key,
+                             FAR void *value,
+                             bool integer)
+{
+  intptr_t intval = (intptr_t)value;
+  FAR cJSON *item;
+  FAR cJSON *obj;
+
+  obj = cJSON_GetObjectItem(root, key);
+  if (obj)
+    {
+      if (integer)
+        {
+          if (intval == obj->valueint)
+            {
+              return false;
+            }
+
+          item = cJSON_CreateNumber(intval);
+        }
+      else
+        {
+          if (!strncmp(value, obj->valuestring, strlen(obj->valuestring)))
+            {
+              return false;
+            }
+
+          item = cJSON_CreateString(value);
+        }
+
+      cJSON_ReplaceItemInObject(root, key, item);
+    }
+  else
+    {
+      integer ? cJSON_AddNumberToObject(root, key, intval) :
+                cJSON_AddStringToObject(root, key, value);
+    }
+
+  return true;
+}
+#endif /* CONFIG_WIRELESS_WAPI_INITCONF */
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -159,3 +259,234 @@ FAR const char *wapi_ioctl_command_name(int cmd)
       return g_ioctl_command_namebuf;
     }
 }
+
+#ifdef CONFIG_WIRELESS_WAPI_INITCONF
+
+/****************************************************************************
+ * Name: wapi_unload_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *  load - Config resource handler, allocate by wapi_load_config()
+ *
+ * Returned Value:
+ *
+ ****************************************************************************/
+
+void wapi_unload_config(FAR void *load)
+{
+  if (load)
+    {
+      cJSON_Delete(load);
+    }
+}
+
+/****************************************************************************
+ * Name: wapi_load_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *   Return a pointer to the hold the config resource, NULL On error.
+ *
+ ****************************************************************************/
+
+FAR void *wapi_load_config(FAR const char *ifname,
+                           FAR const char *confname,
+                           FAR struct wpa_wconfig_s *conf)
+{
+  FAR cJSON *ifobj;
+  FAR cJSON *root;
+  FAR cJSON *obj;
+
+  if (ifname == NULL ||
+      conf == NULL)
+    {
+      return NULL;
+    }
+
+  if (confname == NULL)
+    {
+      confname = CONFIG_WIRELESS_WAPI_CONFIG_PATH;
+    }
+
+  root = wapi_json_load(confname);
+  if (!root)
+    {
+      return NULL;
+    }
+
+  /* Set up the network configuration */
+
+  ifobj = cJSON_GetObjectItem(root, ifname);
+  if (!ifobj)
+    {
+      goto errout;
+    }
+
+  obj = cJSON_GetObjectItem(ifobj, "mode");
+  if (!obj)
+    {
+      goto errout;
+    }
+
+  conf->sta_mode = obj->valueint;
+
+  obj = cJSON_GetObjectItem(ifobj, "auth");
+  if (!obj)
+    {
+      goto errout;
+    }
+
+  conf->auth_wpa = obj->valueint;
+
+  obj = cJSON_GetObjectItem(ifobj, "cmode");
+  if (!obj)
+    {
+      goto errout;
+    }
+
+  conf->cipher_mode = obj->valueint;
+
+  obj = cJSON_GetObjectItem(ifobj, "alg");
+  if (!obj)
+    {
+      goto errout;
+    }
+
+  conf->alg = obj->valueint;
+
+  obj = cJSON_GetObjectItem(ifobj, "ssid");
+  if (!obj || !obj->valuestring)
+    {
+      goto errout;
+    }
+
+  conf->ssid = (FAR const char *)obj->valuestring;
+
+  obj = cJSON_GetObjectItem(ifobj, "psk");
+  if (!obj || !obj->valuestring)
+    {
+      goto errout;
+    }
+
+  conf->passphrase = (FAR const char *)obj->valuestring;
+
+  conf->ifname     = ifname;
+  conf->ssidlen    = strlen(conf->ssid);
+  conf->phraselen  = strlen(conf->passphrase);
+
+  return root;
+
+errout:
+  cJSON_Delete(root);
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: wapi_save_config
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *
+ ****************************************************************************/
+
+int wapi_save_config(FAR const char *ifname,
+                     FAR const char *confname,
+                     FAR const struct wpa_wconfig_s *conf)
+{
+  FAR char *buf = NULL;
+  FAR cJSON *ifobj;
+  FAR cJSON *root;
+  int ret = -1;
+  int fd = -1;
+  bool update;
+
+  if (ifname == NULL || conf == NULL)
+    {
+      return ret;
+    }
+
+  if (confname == NULL)
+    {
+      confname = CONFIG_WIRELESS_WAPI_CONFIG_PATH;
+    }
+
+  root = wapi_json_load(confname);
+  if (!root)
+    {
+      root = cJSON_CreateObject();
+      if (root == NULL)
+        {
+          return ret;
+        }
+    }
+
+  ifobj = cJSON_GetObjectItem(root, ifname);
+  if (!ifobj)
+    {
+      ifobj = cJSON_CreateObject();
+      if (ifobj == NULL)
+        {
+          goto errout;
+        }
+
+      cJSON_AddItemToObject(root, ifname, ifobj);
+    }
+
+  update =  wapi_json_update(ifobj, "mode",
+                             (FAR void *)(intptr_t)conf->sta_mode, true);
+  update |= wapi_json_update(ifobj, "auth",
+                             (FAR void *)(intptr_t)conf->auth_wpa, true);
+  update |= wapi_json_update(ifobj, "cmode",
+                             (FAR void *)(intptr_t)conf->cipher_mode, true);
+  update |= wapi_json_update(ifobj, "alg",
+                             (FAR void *)(intptr_t)conf->alg, true);
+  update |= wapi_json_update(ifobj, "ssid",
+                             (FAR void *)conf->ssid, false);
+  update |= wapi_json_update(ifobj, "psk",
+                             (FAR void *)conf->passphrase, false);
+
+  if (!update)
+    {
+      ret = OK;
+      goto errout;
+    }
+
+  buf = cJSON_PrintUnformatted(root);
+  if (!buf)
+    {
+      goto errout;
+    }
+
+  fd = open(confname, O_RDWR | O_CREAT | O_TRUNC);
+  if (fd < 0)
+    {
+      goto errout;
+    }
+
+  ret = write(fd, buf, strlen(buf));
+
+errout:
+  if (buf)
+    {
+      free(buf);
+    }
+
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  cJSON_Delete(root);
+
+  return ret < 0 ? ret : OK;
+}
+#endif /* CONFIG_WIRELESS_WAPI_INITCONF */