Index: builder.py
===================================================================
--- builder.py	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ builder.py	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -178,4 +178,5 @@
             '-Ifreebsd/include',
             '-Ifreebsd/lib',
+            '-Ifreebsd/lib/libbsdstat',
             '-Ifreebsd/lib/libc/include',
             '-Ifreebsd/lib/libc/isc/include',
Index: freebsd/tools/tools/net80211/wlanstats/main.c
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/main.c	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ freebsd/tools/tools/net80211/wlanstats/main.c	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -1,3 +1,7 @@
 #include <machine/rtems-bsd-user-space.h>
+
+#ifdef __rtems__
+#include "rtems-bsd-wlanstats-namespace.h"
+#endif /* __rtems__ */
 
 /*-
@@ -37,4 +41,10 @@
  */
 
+#ifdef __rtems__
+#define __need_getopt_newlib
+#include <getopt.h>
+#include <machine/rtems-bsd-program.h>
+#include <machine/rtems-bsd-commands.h>
+#endif /* __rtems__ */
 #include <rtems/bsd/sys/param.h>
 #include <sys/socket.h>
@@ -51,6 +61,13 @@
 
 #include "wlanstats.h"
-
+#ifdef __rtems__
+#include "rtems-bsd-wlanstats-main-data.h"
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 static struct {
+#else /* __rtems__ */
+static const struct {
+#endif /* __rtems__ */
 	const char *tag;
 	const char *fmt;
@@ -164,4 +181,27 @@
 }
 
+#ifdef __rtems__
+static int main(int argc, char *argv[]);
+
+RTEMS_LINKER_RWSET(bsd_prog_wlanstats, char);
+
+int
+rtems_bsd_command_wlanstats(int argc, char *argv[])
+{
+	int exit_code;
+	void *data_begin;
+	size_t data_size;
+
+	data_begin = RTEMS_LINKER_SET_BEGIN(bsd_prog_wlanstats);
+	data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_wlanstats);
+
+	rtems_bsd_program_lock();
+	exit_code = rtems_bsd_program_call_main_with_data_restore("wlanstats",
+	    main, argc, argv, data_begin, data_size);
+	rtems_bsd_program_unlock();
+
+	return exit_code;
+}
+#endif /* __rtems__ */
 int
 main(int argc, char *argv[])
@@ -173,4 +213,13 @@
 	int allnodes = 0;
 	int c, mode;
+#ifdef __rtems__
+	struct getopt_data getopt_data;
+	memset(&getopt_data, 0, sizeof(getopt_data));
+#define optind getopt_data.optind
+#define optarg getopt_data.optarg
+#define opterr getopt_data.opterr
+#define optopt getopt_data.optopt
+#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data)
+#endif /* __rtems__ */
 
 	ifname = getenv("WLAN");
@@ -235,8 +284,22 @@
 		}
 		fflush(stdout);
+#ifndef __rtems__
 		omask = sigblock(sigmask(SIGALRM));
 		if (!signalled)
 			sigpause(0);
 		sigsetmask(omask);
+#else /* __rtems__ */
+		{
+		sigset_t oldmask, desired, empty;
+
+		sigemptyset(&empty);
+		sigemptyset(&desired);
+		sigaddset(&desired, SIGALRM);
+		sigprocmask(SIG_BLOCK, &desired, &oldmask);
+		while (!signalled)
+			sigsuspend(&desired);
+		sigprocmask(SIG_SETMASK, &oldmask, NULL);
+		}
+#endif /* __rtems__ */
 		signalled = 0;
 		alarm(interval);
Index: freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-data.h
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
+++ freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -0,0 +1,4 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+/* main.c */
+/* wlanstats.c */
Index: freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-main-data.h
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-main-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
+++ freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-main-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -0,0 +1,5 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-wlanstats-data.h"
+/* main.c */
+RTEMS_LINKER_RWSET_CONTENT(bsd_prog_wlanstats, static int signalled);
Index: freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-namespace.h
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-namespace.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
+++ freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-namespace.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -0,0 +1,8 @@
+/* generated by userspace-header-gen.py */
+/* main.c */
+#define main _bsd_wlanstats_main
+#define usage _bsd_wlanstats_usage
+/* wlanstats.c */
+#define wlanstats_new _bsd_wlanstats_wlanstats_new
+#define setstatus _bsd_wlanstats_setstatus
+#define setreason _bsd_wlanstats_setreason
Index: freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-wlanstats-data.h
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-wlanstats-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
+++ freebsd/tools/tools/net80211/wlanstats/rtems-bsd-wlanstats-wlanstats-data.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -0,0 +1,4 @@
+/* generated by userspace-header-gen.py */
+#include <rtems/linkersets.h>
+#include "rtems-bsd-wlanstats-data.h"
+/* wlanstats.c */
Index: freebsd/tools/tools/net80211/wlanstats/wlanstats.c
===================================================================
--- freebsd/tools/tools/net80211/wlanstats/wlanstats.c	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ freebsd/tools/tools/net80211/wlanstats/wlanstats.c	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -1,3 +1,7 @@
 #include <machine/rtems-bsd-user-space.h>
+
+#ifdef __rtems__
+#include "rtems-bsd-wlanstats-namespace.h"
+#endif /* __rtems__ */
 
 /*-
@@ -36,4 +40,7 @@
  */
 
+#ifdef __rtems__
+#include <machine/rtems-bsd-program.h>
+#endif /* __rtems__ */
 #include <rtems/bsd/sys/param.h>
 #include <sys/file.h>
@@ -58,4 +65,7 @@
 
 #include "wlanstats.h"
+#ifdef __rtems__
+#include "rtems-bsd-wlanstats-wlanstats-data.h"
+#endif /* __rtems__ */
 
 #ifndef IEEE80211_ADDR_COPY
Index: libbsd.py
===================================================================
--- libbsd.py	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ libbsd.py	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -79,4 +79,5 @@
             'rtems/rtems-bsd-shell-tcpdump.c',
             'rtems/rtems-bsd-shell-vmstat.c',
+            'rtems/rtems-bsd-shell-wlanstats.c',
             'rtems/rtems-bsd-syscall-api.c',
             'rtems/rtems-kernel-assert.c',
@@ -2456,4 +2457,25 @@
 
 #
+# User space: wlanstats utility
+#
+def user_space_wlanstats(mm):
+    mod = builder.Module('user_space_wlanstats')
+    mod.addUserSpaceHeaderFiles(
+        [
+            'tools/tools/net80211/wlanstats/wlanstats.h',
+            'lib/libbsdstat/bsdstat.h',
+        ]
+    )
+    mod.addUserSpaceSourceFiles(
+        [
+            'tools/tools/net80211/wlanstats/main.c',
+            'tools/tools/net80211/wlanstats/wlanstats.c',
+            'lib/libbsdstat/bsdstat.c',
+        ],
+        mm.generator['source'](['-DINET6', '-DINET'])
+    )
+    return mod
+
+#
 # Contrib expat
 #
@@ -3064,4 +3086,5 @@
 
     mm.addModule(user_space(mm))
+    mm.addModule(user_space_wlanstats(mm))
     mm.addModule(contrib_expat(mm))
     mm.addModule(contrib_libpcap(mm))
Index: libbsd_waf.py
===================================================================
--- libbsd_waf.py	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ libbsd_waf.py	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -68,4 +68,5 @@
     includes += ["freebsd/include"]
     includes += ["freebsd/lib"]
+    includes += ["freebsd/lib/libbsdstat"]
     includes += ["freebsd/lib/libc/include"]
     includes += ["freebsd/lib/libc/isc/include"]
@@ -251,4 +252,5 @@
                      'freebsd/lib/lib80211/lib80211_ioctl.c',
                      'freebsd/lib/lib80211/lib80211_regdomain.c',
+                     'freebsd/lib/libbsdstat/bsdstat.c',
                      'freebsd/lib/libc/gen/err.c',
                      'freebsd/lib/libc/gen/feature_present.c',
@@ -451,4 +453,6 @@
                      'freebsd/sbin/route/route.c',
                      'freebsd/sbin/sysctl/sysctl.c',
+                     'freebsd/tools/tools/net80211/wlanstats/main.c',
+                     'freebsd/tools/tools/net80211/wlanstats/wlanstats.c',
                      'freebsd/usr.bin/netstat/bpf.c',
                      'freebsd/usr.bin/netstat/flowtable.c',
@@ -1273,4 +1277,5 @@
               'rtemsbsd/rtems/rtems-bsd-shell-tcpdump.c',
               'rtemsbsd/rtems/rtems-bsd-shell-vmstat.c',
+              'rtemsbsd/rtems/rtems-bsd-shell-wlanstats.c',
               'rtemsbsd/rtems/rtems-bsd-syscall-api.c',
               'rtemsbsd/rtems/rtems-kernel-assert.c',
Index: rtemsbsd/include/machine/rtems-bsd-commands.h
===================================================================
--- rtemsbsd/include/machine/rtems-bsd-commands.h	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ rtemsbsd/include/machine/rtems-bsd-commands.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -69,4 +69,6 @@
 int rtems_bsd_command_vmstat(int argc, char **argv);
 
+int rtems_bsd_command_wlanstats(int argc, char **argv);
+
 __END_DECLS
 
Index: rtemsbsd/include/rtems/netcmds-config.h
===================================================================
--- rtemsbsd/include/rtems/netcmds-config.h	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ rtemsbsd/include/rtems/netcmds-config.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -44,4 +44,6 @@
 extern rtems_shell_cmd_t rtems_shell_VMSTAT_Command;
 
+extern rtems_shell_cmd_t rtems_shell_WLANSTATS_Command;
+
 #ifdef __cplusplus
 }
Index: rtemsbsd/rtems/rtems-bsd-shell-wlanstats.c
===================================================================
--- rtemsbsd/rtems/rtems-bsd-shell-wlanstats.c	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
+++ rtemsbsd/rtems/rtems-bsd-shell-wlanstats.c	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems@embedded-brains.de>
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <rtems/netcmds-config.h>
+#include <machine/rtems-bsd-commands.h>
+
+rtems_shell_cmd_t rtems_shell_WLANSTATS_Command = {
+  "wlanstats",                   /* name */
+  "wlanstats [args]",            /* usage */
+  "net",                         /* topic */
+  rtems_bsd_command_wlanstats,   /* command */
+  NULL,                          /* alias */
+  NULL                           /* next */
+};
Index: testsuite/include/rtems/bsd/test/default-network-init.h
===================================================================
--- testsuite/include/rtems/bsd/test/default-network-init.h	(revision d415406e34da6ca26bdf24d6f49d97b39cbff4e3)
+++ testsuite/include/rtems/bsd/test/default-network-init.h	(revision ecda18104e1ac2a5c0a5d146f78b2ef0cebada6e)
@@ -366,5 +366,6 @@
   &rtems_shell_TCPDUMP_Command, \
   &rtems_shell_SYSCTL_Command, \
-  &rtems_shell_VMSTAT_Command
+  &rtems_shell_VMSTAT_Command, \
+  &rtems_shell_WLANSTATS_Command
 
 #define CONFIGURE_SHELL_COMMAND_CPUUSE
