diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index 69ea3e38f..de46267ae 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -1,7 +1,7 @@
 /****************************************************************************
  * apps/include/wireless/wapi.h
  *
- *   Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gnutt@nuttx.org>
  *
  * Adapted for Nuttx from WAPI:
diff --git a/include/wireless/wext.h b/include/wireless/wext.h
new file mode 100644
index 000000000..e8b65639a
--- /dev/null
+++ b/include/wireless/wext.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+ * apps/include/wireless/wapi.h
+ * WPA Supplicant - wext exported functions
+ *
+ *   Copyright (C) 2017 Gregory Nutt. All rights reserved.
+ *   Author: Simon Piriou <spiriou31@gmail.com>
+ *           Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Adapted to NuttX from driver_ext.h
+ *
+ *   Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ *    used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+#ifndef __APPS_INCLUDE_WIRELESS_WEXT_H
+#define __APPS_INCLUDE_WIRELESS_WEXT_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdint.h>
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+#ifdef CONFIG_NET_UDP
+# define NETLIB_SOCK_IOCTL SOCK_DGRAM
+#else
+# define NETLIB_SOCK_IOCTL SOCK_STREAM
+#endif
+
+#define SSID_MAX_LEN 32
+#define PF_INETX     PF_INET
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+enum wpa_alg
+{
+  WPA_ALG_NONE,
+  WPA_ALG_WEP,
+  WPA_ALG_TKIP,
+  WPA_ALG_CCMP,
+  WPA_ALG_IGTK,
+  WPA_ALG_PMK,
+  WPA_ALG_GCMP,
+  WPA_ALG_SMS4,
+  WPA_ALG_KRK,
+  WPA_ALG_GCMP_256,
+  WPA_ALG_CCMP_256,
+  WPA_ALG_BIP_GMAC_128,
+  WPA_ALG_BIP_GMAC_256,
+  WPA_ALG_BIP_CMAC_256
+};
+
+/************************************************************************************
+ * Public Function Prototypes
+ ************************************************************************************/
+
+int wpa_driver_wext_set_ssid(int sockfd, FAR char *ifname,
+                             FAR const uint8_t *ssid, size_t ssid_len);
+
+int wpa_driver_wext_set_mode(int sockfd, FAR char *ifname, int mode);
+
+int wpa_driver_wext_set_key_ext(int sockfd, FAR char *ifname, enum wpa_alg alg,
+                                FAR const uint8_t *key, size_t key_len);
+
+int wpa_driver_wext_associate(void);
+
+int wpa_driver_wext_set_auth_param(int sockfd, FAR char *ifname,
+                                   int idx, uint32_t value);
+
+#endif /* __APPS_INCLUDE_WIRELESS_WEXT_H */
diff --git a/netutils/dhcpc/Kconfig b/netutils/dhcpc/Kconfig
index 5f9034cd2..8f7765692 100644
--- a/netutils/dhcpc/Kconfig
+++ b/netutils/dhcpc/Kconfig
@@ -11,4 +11,13 @@ config NETUTILS_DHCPC
 		Enable support for the DHCP client.
 
 if NETUTILS_DHCPC
+
+config NETUTILS_DHCPC_DEVNAME
+	string "DHCP device name"
+	default "eth0" if !DRIVERS_IEEE80211
+	default "wlan0" if DRIVERS_IEEE80211
+	depends on NET_UDP && NET_BROADCAST && NET_IPv4
+	---help---
+		Specify the Ethernet or IEEE 802.15.4 device to use.
+
 endif
diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c
index 56464edaa..3215787c4 100644
--- a/netutils/dhcpc/dhcpc.c
+++ b/netutils/dhcpc/dhcpc.c
@@ -61,6 +61,16 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Configuration */
+
+#ifdef CONFIG_NETUTILS_DHCPC_DEVNAME
+#  define DEVNAME CONFIG_NETUTILS_DHCPC_DEVNAME
+#else
+#  define DEVNAME "eth0"
+#endif
+
+/* DHCP Definitions */
+
 #define STATE_INITIAL           0
 #define STATE_HAVE_OFFER        1
 #define STATE_HAVE_LEASE        2
@@ -447,7 +457,7 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
   /* Save the currently assigned IP address (should be INADDR_ANY) */
 
   oldaddr.s_addr = 0;
-  netlib_get_ipv4addr("eth0", &oldaddr);
+  netlib_get_ipv4addr(DEVNAME, &oldaddr);
 
   /* Loop until we receive the lease (or an error occurs) */
 
@@ -456,7 +466,7 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
       /* Set the IP address to INADDR_ANY. */
 
       newaddr.s_addr = INADDR_ANY;
-      (void)netlib_set_ipv4addr("eth0", &newaddr);
+      (void)netlib_set_ipv4addr(DEVNAME, &newaddr);
 
       /* Loop sending DISCOVER until we receive an OFFER from a DHCP
        * server.  We will lock on to the first OFFER and decline any
@@ -496,7 +506,7 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
                    * out of the loop.
                    */
 
-                  (void)netlib_set_ipv4addr("eth0", &presult->ipaddr);
+                  (void)netlib_set_ipv4addr(DEVNAME, &presult->ipaddr);
                   state = STATE_HAVE_OFFER;
                 }
             }
@@ -588,7 +598,7 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
             {
               /* An error other than a timeout was received */
 
-              (void)netlib_set_ipv4addr("eth0", &oldaddr);
+              (void)netlib_set_ipv4addr(DEVNAME, &oldaddr);
               return ERROR;
             }
         }
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 0231ef510..9ca6b009f 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -697,7 +697,8 @@
 #endif
 
 #if defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_NSH_DISABLESCRIPT)
-#  define CONFIG_NSH_DISABLE_SET
+#  undef  CONFIG_NSH_DISABLE_SET
+#  define CONFIG_NSH_DISABLE_SET 1
 #endif
 
 /****************************************************************************
diff --git a/nshlib/nsh_dbgcmds.c b/nshlib/nsh_dbgcmds.c
index e123f45e1..c86d77109 100644
--- a/nshlib/nsh_dbgcmds.c
+++ b/nshlib/nsh_dbgcmds.c
@@ -99,7 +99,7 @@ static int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv,
       *pcvalue = '\0';
       pcvalue++;
 
-      lvalue = (unsigned long)strtol(pcvalue, NULL, 16);
+      lvalue = strtoul(pcvalue, NULL, 16);
       if (lvalue > 0xffffffffL)
         {
           return -EINVAL;
@@ -116,13 +116,13 @@ static int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv,
 
   /* Get the address to be accessed */
 
-  mem->dm_addr = (void*)((uintptr_t)strtol(argv[1], NULL, 16));
+  mem->dm_addr = (FAR void *)((uintptr_t)strtoul(argv[1], NULL, 16));
 
   /* Get the number of bytes to access */
 
   if (argc > 2)
     {
-      mem->dm_count = (unsigned int)strtol(argv[2], NULL, 16);
+      mem->dm_count = (unsigned int)strtoul(argv[2], NULL, 16);
     }
   else
     {
@@ -346,7 +346,7 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
   FAR char *endptr;
   int       nbytes;
 
-  addr = (char*)((uintptr_t)strtol(argv[1], &endptr, 16));
+  addr = (FAR char*)((uintptr_t)strtoul(argv[1], &endptr, 16));
   if (argv[0][0] == '\0' || *endptr != '\0')
     {
       return ERROR;
diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c
index 4ca8a1293..7f1f8c943 100644
--- a/nshlib/nsh_netcmds.c
+++ b/nshlib/nsh_netcmds.c
@@ -89,6 +89,9 @@
 
 #if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0
 #  include "netutils/netlib.h"
+#  if !defined(CONFIG_NSH_DISABLE_GET) || !defined(CONFIG_NSH_DISABLE_PUT)
+#    include "netutils/tftp.h"
+#  endif
 #endif
 
 #if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0
diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c
index fd2159f1f..71b504eb6 100644
--- a/nshlib/nsh_netinit.c
+++ b/nshlib/nsh_netinit.c
@@ -80,6 +80,10 @@
 #  include "netutils/ntpclient.h"
 #endif
 
+#ifdef CONFIG_WIRELESS_WEXT
+#  include "wireless/wext.h"
+#endif
+
 #include "nsh.h"
 
 #ifdef CONFIG_NSH_NETINIT
@@ -124,7 +128,10 @@
  * not be the one that you want).
  */
 
-#if defined(CONFIG_NET_ETHERNET)
+#if defined(CONFIG_DRIVERS_IEEE80211) /* Usually also has CONFIG_NET_ETHERNET */
+#  define NET_DEVNAME "wlan0"
+#  define NSH_HAVE_NETDEV
+#elif defined(CONFIG_NET_ETHERNET)
 #  define NET_DEVNAME "eth0"
 #  define NSH_HAVE_NETDEV
 #elif defined(CONFIG_NET_6LOWPAN)
@@ -360,6 +367,14 @@ static void nsh_netinit_configure(void)
 
   netlib_getmacaddr(NET_DEVNAME, mac);
 
+#ifdef CONFIG_WIRELESS_WEXT
+  /* Associate the wlan */
+
+  sleep(2);
+  wpa_driver_wext_associate();
+  sleep(2);
+#endif
+
   /* Set up the DHCPC modules */
 
   handle = dhcpc_open(&mac, IFHWADDRLEN);
@@ -368,28 +383,28 @@ static void nsh_netinit_configure(void)
    * example.  The address should be renewed in ds.lease_time/2 seconds.
    */
 
-  if (handle)
+  if (handle != NULL)
     {
-        struct dhcpc_state ds;
-        (void)dhcpc_request(handle, &ds);
-        netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
+      struct dhcpc_state ds;
+      (void)dhcpc_request(handle, &ds);
+      netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
 
-        if (ds.netmask.s_addr != 0)
-          {
-            netlib_set_ipv4netmask(NET_DEVNAME, &ds.netmask);
-          }
+      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);
-          }
+      if (ds.default_router.s_addr != 0)
+        {
+          netlib_set_dripv4addr(NET_DEVNAME, &ds.default_router);
+        }
 
-        if (ds.dnsaddr.s_addr != 0)
-          {
-            netlib_set_ipv4dnsaddr(&ds.dnsaddr);
-          }
+      if (ds.dnsaddr.s_addr != 0)
+        {
+          netlib_set_ipv4dnsaddr(&ds.dnsaddr);
+        }
 
-        dhcpc_close(handle);
+      dhcpc_close(handle);
     }
 #endif
 
diff --git a/wireless/wext/.gitignore b/wireless/wext/.gitignore
new file mode 100644
index 000000000..f21c854d1
--- /dev/null
+++ b/wireless/wext/.gitignore
@@ -0,0 +1,6 @@
+/.built
+/.depend
+/Make.dep
+/*.src
+/*.obj
+/*.lst
diff --git a/wireless/wext/Kconfig b/wireless/wext/Kconfig
new file mode 100644
index 000000000..883e87b26
--- /dev/null
+++ b/wireless/wext/Kconfig
@@ -0,0 +1,16 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+menuconfig WIRELESS_WEXT
+	bool "Driver WEXT"
+	default n
+	depends on NET && DRIVERS_WIRELESS
+	---help---
+		The driver_wext logic from the WPA suplicant written originally
+		by Jouni Malinen
+
+if WIRELESS_WEXT
+
+endif
diff --git a/wireless/wext/Make.defs b/wireless/wext/Make.defs
new file mode 100644
index 000000000..9c4d9246a
--- /dev/null
+++ b/wireless/wext/Make.defs
@@ -0,0 +1,40 @@
+############################################################################
+# apps/wireless/wext/Make.defs
+# Adds selected applications to apps/ build
+#
+#   Copyright (C) 2017 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+ifeq ($(CONFIG_WIRELESS_WEXT),y)
+CONFIGURED_APPS += wireless/wext
+endif
+
diff --git a/wireless/wext/Makefile b/wireless/wext/Makefile
new file mode 100644
index 000000000..c4d1ad051
--- /dev/null
+++ b/wireless/wext/Makefile
@@ -0,0 +1,104 @@
+############################################################################
+# apps/wireless/wext/Makefile
+#
+#   Copyright (C) 2017 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+#    used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+# TODO, this makefile should run make under the app dirs, instead of
+# sourcing the Make.defs!
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+ASRCS =
+CSRCS = wext.c
+MAINSRC =
+
+VPATH = .
+DEPPATH = --dep-path .
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS)
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+  BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+  BIN = ..\\..\\libapps$(LIBEXT)
+else
+  BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+# Common build
+
+all: .built
+.PHONY: context depend clean distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+	$(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+	$(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+	$(call ARCHIVE, $(BIN), $(OBJS))
+	$(Q) touch .built
+
+install:
+
+context:
+
+# Create dependencies
+
+.depend: Makefile $(SRCS)
+	$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+	$(Q) touch $@
+
+depend: .depend
+
+clean:
+	$(call DELFILE, .built)
+	$(call CLEAN)
+
+distclean: clean
+	$(call DELFILE, Make.dep)
+	$(call DELFILE, .depend)
+
+-include Make.dep
+.PHONY: preconfig
+preconfig:
diff --git a/wireless/wext/wext.c b/wireless/wext/wext.c
new file mode 100644
index 000000000..f952369f4
--- /dev/null
+++ b/wireless/wext/wext.c
@@ -0,0 +1,359 @@
+/************************************************************************************
+ * apps/include/graphics/wext.c
+ * Driver interaction with generic Wireless Extensions
+ *
+ *   Copyright (C) 2017 Gregory Nutt. All rights reserved.
+ *   Author: Simon Piriou <spiriou31@gmail.com>
+ *           Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Adapted to NuttX from driver_ext.c
+ *
+ *   Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ *    used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+/* This file implements a driver interface for the Linux Wireless Extensions.
+ * When used with WE-18 or newer, this interface can be used as-is with number
+ * of drivers. In addition to this, some of the common functions in this file
+ * can be used by other driver interface implementations that use generic WE
+ * ioctls, but require private ioctls for some of the functionality.
+ */
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <debug.h>
+
+#include "wireless/wext.h"
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: wpa_driver_wext_set_auth_param
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *
+ ************************************************************************************/
+
+int wpa_driver_wext_set_auth_param(int sockfd, FAR char *ifname, int idx,
+                                   uint32_t value)
+{
+  struct iwreq iwr;
+  int errcode;
+  int ret = 0;
+
+  memset(&iwr, 0, sizeof(iwr));
+  strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
+  iwr.u.param.flags = idx & IW_AUTH_INDEX;
+  iwr.u.param.value = value;
+
+  if (ioctl(sockfd, SIOCSIWAUTH, (unsigned long)&iwr) < 0)
+    {
+      errcode = errno;
+      if (errcode != EOPNOTSUPP)
+        {
+          nerr("ERROR: SIOCSIWAUTH(param %d value 0x%x) failed: %d)",
+               idx, value, errcode);
+        }
+
+      ret = errcode == EOPNOTSUPP ? -2 : -1;
+    }
+
+  return ret;
+}
+
+/************************************************************************************
+ * Name: wpa_driver_wext_set_ssid
+ *
+ * Description:
+ *   Set SSID, SIOCSIWESSID
+ *
+ * Input Parameters:
+ *   sockfd   - Opened network socket
+ *   ifname   - Interface name
+ *   ssid     -  SSID
+ *   ssid_len - Length of SSID (0..32)
+ *
+ * Returned Value:
+ *   0 on success, -1 on failure
+ *
+ ************************************************************************************/
+
+int wpa_driver_wext_set_ssid(int sockfd,  FAR char *ifname, FAR const uint8_t *ssid,
+                             size_t ssid_len)
+{
+  struct iwreq iwr;
+  int ret = 0;
+  char buf[33];
+
+  if (ssid_len > SSID_MAX_LEN)
+    {
+      return -1;
+    }
+
+  memset(&iwr, 0, sizeof(iwr));
+  strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
+
+  /* flags: 1 = ESSID is active, 0 = not (promiscuous) */
+
+  iwr.u.essid.flags = (ssid_len != 0);
+  memset(buf, 0, sizeof(buf));
+  memcpy(buf, ssid, ssid_len);
+  iwr.u.essid.pointer = (caddr_t) buf;
+
+  iwr.u.essid.length = ssid_len;
+
+  if (ioctl(sockfd, SIOCSIWESSID, (unsigned long)&iwr) < 0)
+    {
+      nerr("ERROR: ioctl[SIOCSIWESSID]: %d", errno);
+      ret = -1;
+    }
+
+  return ret;
+}
+
+/************************************************************************************
+ * Name: wpa_driver_wext_set_key_ext
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *   sockfd - Opened network socket
+ *   ifname - Interface name
+ *
+ * Returned Value:
+ *
+ ************************************************************************************/
+
+int wpa_driver_wext_set_key_ext(int sockfd,  FAR char *ifname, enum wpa_alg alg,
+                                FAR const uint8_t *key, size_t key_len)
+{
+  struct iwreq iwr;
+  int ret = 0;
+  struct iw_encode_ext *ext;
+
+  ext = malloc(sizeof(*ext) + key_len);
+  if (ext == NULL)
+    {
+      return -1;
+    }
+
+  memset(&iwr, 0, sizeof(iwr));
+  strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
+
+  iwr.u.encoding.pointer = (caddr_t) ext;
+  iwr.u.encoding.length = sizeof(*ext) + key_len;
+
+  if (key && key_len)
+    {
+      memcpy(ext + 1, key, key_len);
+      ext->key_len = key_len;
+    }
+
+  switch (alg)
+    {
+      case WPA_ALG_NONE:
+        ext->alg = IW_ENCODE_ALG_NONE;
+        break;
+
+      case WPA_ALG_WEP:
+        ext->alg = IW_ENCODE_ALG_WEP;
+        break;
+
+      case WPA_ALG_TKIP:
+        ext->alg = IW_ENCODE_ALG_TKIP;
+        break;
+
+      case WPA_ALG_CCMP:
+        ext->alg = IW_ENCODE_ALG_CCMP;
+        break;
+
+      default:
+        nerr("ERROR: Unknown algorithm %d", alg);
+        free(ext);
+        return -1;
+    }
+
+  if (ioctl(sockfd, SIOCSIWENCODEEXT, (unsigned long)&iwr) < 0)
+    {
+      ret = errno == EOPNOTSUPP ? -2 : -1;
+      nerr("ERROR: ioctl[SIOCSIWENCODEEXT]: %d", errno);
+    }
+
+  free(ext);
+  return ret;
+}
+
+/************************************************************************************
+ * Name: wpa_driver_wext_associate
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *
+ ************************************************************************************/
+
+int wpa_driver_wext_associate(void)
+{
+  int ret;
+  int sockfd;
+  struct iwreq req;
+
+  int sta_mode = IW_MODE_INFRA;
+
+  // IW_AUTH_WPA_VERSION_DISABLED
+  // IW_AUTH_WPA_VERSION_WPA
+
+  int auth_wpa = IW_AUTH_WPA_VERSION_WPA2;
+
+  // IW_AUTH_CIPHER_NONE
+  // IW_AUTH_CIPHER_WEP40
+  // IW_AUTH_CIPHER_TKIP
+  // IW_AUTH_CIPHER_WEP104
+
+  int cipher_mode = IW_AUTH_CIPHER_CCMP;
+
+  enum wpa_alg alg = WPA_ALG_CCMP;
+
+  char ifname[] = "wlan0";
+  const uint8_t ssid[] = "myApSSID";
+  const uint8_t passphrase[] = "mySSIDpassphrase";
+
+  ninfo("Entry\n");
+
+  /* Get a socket (only so that we get access to the INET subsystem) */
+
+  sockfd = socket(PF_INETX, NETLIB_SOCK_IOCTL, 0);
+  if (sockfd < 0)
+    {
+      return sockfd;
+    }
+
+  /* Put the driver name into the request */
+
+  strncpy(req.ifr_name, ifname, IFNAMSIZ);
+
+  if (wpa_driver_wext_set_mode(sockfd, ifname, sta_mode) < 0)
+    {
+      nerr("Fail set sta mode\n");
+      ret = -1;
+      goto close_socket;
+    }
+
+  if (wpa_driver_wext_set_auth_param(sockfd, ifname, IW_AUTH_WPA_VERSION,
+                                     auth_wpa) < 0)
+    {
+      nerr("Fail set wpa version\n");
+      ret = -1;
+      goto close_socket;
+    }
+
+  if (wpa_driver_wext_set_auth_param(sockfd, ifname,
+             IW_AUTH_CIPHER_PAIRWISE, cipher_mode) < 0)
+  {
+    nerr("Fail set cipher mode\n");
+    ret = -1;
+    goto close_socket;
+  }
+
+  if (wpa_driver_wext_set_key_ext(sockfd, ifname, alg, passphrase,
+                                  sizeof(passphrase)-1))
+    {
+      nerr("Fail set key\n");
+      ret = -1;
+      goto close_socket;
+    }
+
+  if (wpa_driver_wext_set_ssid(sockfd, ifname, ssid, sizeof(ssid)-1) < 0)
+    {
+      nerr("Fail set ssid\n");
+      ret = -1;
+      goto close_socket;
+    }
+
+close_socket:
+  close(sockfd);
+  return ret;
+}
+
+/************************************************************************************
+ * Name: wpa_driver_wext_set_mode
+ *
+ * Description:
+ *   Set wireless mode (infra/adhoc), SIOCSIWMODE
+ *
+ * Input Parameters:
+ *   sockfd - Opened network socket
+ *   ifname - Interface name
+ *   mode   - 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
+ *
+ * Returned Value:
+ *   0 on success, -1 on failure
+ *
+ ************************************************************************************/
+
+int wpa_driver_wext_set_mode(int sockfd, FAR char *ifname, int mode)
+{
+  struct iwreq iwr;
+  int ret = -1;
+
+  memset(&iwr, 0, sizeof(iwr));
+  strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
+  iwr.u.mode = mode;
+
+  if (ioctl(sockfd, SIOCSIWMODE, (unsigned long)&iwr) == 0)
+    {
+      ret = 0;
+      goto done;
+    }
+
+  nerr("ERROR: ioctl[SIOCSIWMODE]: %d", errno);
+
+done:
+  return ret;
+}