freebsd/wlanstats: Port to FreeBSD.

This commit is contained in:
Christian Mauderer 2016-12-09 11:51:50 +01:00
parent d415406e34
commit ecda18104e
13 changed files with 171 additions and 1 deletions

View File

@ -177,6 +177,7 @@ def includes():
'-Ifreebsd/sys/net',
'-Ifreebsd/include',
'-Ifreebsd/lib',
'-Ifreebsd/lib/libbsdstat',
'-Ifreebsd/lib/libc/include',
'-Ifreebsd/lib/libc/isc/include',
'-Ifreebsd/lib/libc/resolv',

View File

@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
#ifdef __rtems__
#include "rtems-bsd-wlanstats-namespace.h"
#endif /* __rtems__ */
/*-
* Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
* All rights reserved.
@ -36,6 +40,12 @@
* (default interface is wlan0).
*/
#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>
@ -50,8 +60,15 @@
#include <unistd.h>
#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;
} tags[] = {
@ -163,6 +180,29 @@ usage(void) {
printf("wlanstats: [-ah] [-i ifname] [-l] [-o fmt] [interval]\n");
}
#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[])
{
@ -172,6 +212,15 @@ main(int argc, char *argv[])
const char *ifname;
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");
if (ifname == NULL)
@ -234,10 +283,24 @@ main(int argc, char *argv[])
wf->print_total(wf, stdout);
}
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);
line++;

View File

@ -0,0 +1,4 @@
/* generated by userspace-header-gen.py */
#include <rtems/linkersets.h>
/* main.c */
/* wlanstats.c */

View File

@ -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);

View File

@ -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

View File

@ -0,0 +1,4 @@
/* generated by userspace-header-gen.py */
#include <rtems/linkersets.h>
#include "rtems-bsd-wlanstats-data.h"
/* wlanstats.c */

View File

@ -1,5 +1,9 @@
#include <machine/rtems-bsd-user-space.h>
#ifdef __rtems__
#include "rtems-bsd-wlanstats-namespace.h"
#endif /* __rtems__ */
/*-
* Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
* All rights reserved.
@ -35,6 +39,9 @@
* net80211 statistics class.
*/
#ifdef __rtems__
#include <machine/rtems-bsd-program.h>
#endif /* __rtems__ */
#include <rtems/bsd/sys/param.h>
#include <sys/file.h>
#include <sys/sockio.h>
@ -57,6 +64,9 @@
#include "../../../../sys/net80211/ieee80211_ioctl.h"
#include "wlanstats.h"
#ifdef __rtems__
#include "rtems-bsd-wlanstats-wlanstats-data.h"
#endif /* __rtems__ */
#ifndef IEEE80211_ADDR_COPY
#define IEEE80211_ADDR_COPY(dst, src) memcpy(dst, src, IEEE80211_ADDR_LEN)

View File

@ -78,6 +78,7 @@ def rtems(mm):
'rtems/rtems-bsd-shell-sysctl.c',
'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',
'rtems/rtems-kernel-autoconf.c',
@ -2454,6 +2455,27 @@ def user_space(mm):
)
return mod
#
# 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
#
@ -3063,6 +3085,7 @@ def sources(mm):
mm.addModule(in_cksum(mm))
mm.addModule(user_space(mm))
mm.addModule(user_space_wlanstats(mm))
mm.addModule(contrib_expat(mm))
mm.addModule(contrib_libpcap(mm))
mm.addModule(usr_sbin_tcpdump(mm))

View File

@ -67,6 +67,7 @@ def build(bld):
includes += ["freebsd/sys/net"]
includes += ["freebsd/include"]
includes += ["freebsd/lib"]
includes += ["freebsd/lib/libbsdstat"]
includes += ["freebsd/lib/libc/include"]
includes += ["freebsd/lib/libc/isc/include"]
includes += ["freebsd/lib/libc/resolv"]
@ -250,6 +251,7 @@ def build(bld):
'freebsd/contrib/libxo/libxo/xo_encoder.c',
'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',
'freebsd/lib/libc/gen/getdomainname.c',
@ -450,6 +452,8 @@ def build(bld):
'freebsd/sbin/ping6/ping6.c',
'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',
'freebsd/usr.bin/netstat/if.c',
@ -1272,6 +1276,7 @@ def build(bld):
'rtemsbsd/rtems/rtems-bsd-shell-sysctl.c',
'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',
'rtemsbsd/rtems/rtems-kernel-autoconf.c',

View File

@ -68,6 +68,8 @@ int rtems_bsd_command_sysctl(int argc, char **argv);
int rtems_bsd_command_vmstat(int argc, char **argv);
int rtems_bsd_command_wlanstats(int argc, char **argv);
__END_DECLS
#endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_COMMANDS_H_ */

View File

@ -43,6 +43,8 @@ extern rtems_shell_cmd_t rtems_shell_SYSCTL_Command;
extern rtems_shell_cmd_t rtems_shell_VMSTAT_Command;
extern rtems_shell_cmd_t rtems_shell_WLANSTATS_Command;
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -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 */
};

View File

@ -365,7 +365,8 @@ Init(rtems_task_argument arg)
&rtems_shell_IFCONFIG_Command, \
&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
#define CONFIGURE_SHELL_COMMAND_PERIODUSE