diff options
author | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2009-03-20 21:37:35 -0700 |
---|---|---|
committer | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2009-03-20 21:37:35 -0700 |
commit | e34895f76037b8faff0646fa4e953bae4491497c (patch) | |
tree | de1cd7749055a68d46480027a0d8223eb1121c2b /bin | |
parent | fabc48d51caadc72c317e8d0946e888089781ce6 (diff) |
wait-for-state-change: add plugin to wimaxll
Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Makefile.am | 6 | ||||
-rw-r--r-- | bin/Makefile.in | 24 | ||||
-rw-r--r-- | bin/wimaxll-pl-wfsc.c | 163 |
3 files changed, 185 insertions, 8 deletions
diff --git a/bin/Makefile.am b/bin/Makefile.am index c699ba7..95dfd72 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -22,7 +22,7 @@ wimaxll_LDFLAGS = $(AM_LDFLAGS) -ldl -Wl,--export-dynamic -Wl,--version-script=w wimaxll_DEPENDENCIES = wimaxll.ver wimaxll.exp: $(wimaxll_OBJECTS) - nm -B *.o | awk '{ print $$3 }' | sort -u | grep -E -e '^w_' > $@ + nm -B *.o | awk '{ print $$3 }' | sort -u | grep -E -e '^(w|wimaxll)_' > $@ wimaxll.ver: wimaxll.exp echo "{ global:" > $@ @@ -32,10 +32,12 @@ wimaxll.ver: wimaxll.exp plugindir = $(pkglibdir)/plugins plugin_LTLIBRARIES = \ wimaxll-pl-reset.la \ - wimaxll-pl-rfkill.la + wimaxll-pl-rfkill.la \ + wimaxll-pl-wfsc.la plugin_LDFLAGS = -no-undefined -module -avoid-version \ -export-symbols-regex plugin wimaxll_pl_reset_la_LDFLAGS = $(plugin_LDFLAGS) wimaxll_pl_rfkill_la_LDFLAGS = $(plugin_LDFLAGS) +wimaxll_pl_wfsc_la_LDFLAGS = $(plugin_LDFLAGS) diff --git a/bin/Makefile.in b/bin/Makefile.in index 16b8030..045517a 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -68,6 +68,12 @@ wimaxll_pl_rfkill_la_OBJECTS = wimaxll-pl-rfkill.lo wimaxll_pl_rfkill_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(wimaxll_pl_rfkill_la_LDFLAGS) $(LDFLAGS) -o $@ +wimaxll_pl_wfsc_la_LIBADD = +wimaxll_pl_wfsc_la_SOURCES = wimaxll-pl-wfsc.c +wimaxll_pl_wfsc_la_OBJECTS = wimaxll-pl-wfsc.lo +wimaxll_pl_wfsc_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(wimaxll_pl_wfsc_la_LDFLAGS) $(LDFLAGS) -o $@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) wimaxll_SOURCES = wimaxll.c @@ -108,11 +114,11 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = wimaxll-pl-reset.c wimaxll-pl-rfkill.c wimaxll.c \ - wimaxll-reset.c wimaxll-rfkill.c \ +SOURCES = wimaxll-pl-reset.c wimaxll-pl-rfkill.c wimaxll-pl-wfsc.c \ + wimaxll.c wimaxll-reset.c wimaxll-rfkill.c \ wimaxll-wait-for-state-change.c -DIST_SOURCES = wimaxll-pl-reset.c wimaxll-pl-rfkill.c wimaxll.c \ - wimaxll-reset.c wimaxll-rfkill.c \ +DIST_SOURCES = wimaxll-pl-reset.c wimaxll-pl-rfkill.c \ + wimaxll-pl-wfsc.c wimaxll.c wimaxll-reset.c wimaxll-rfkill.c \ wimaxll-wait-for-state-change.c ETAGS = etags CTAGS = ctags @@ -161,6 +167,7 @@ LIBNL1_LIBS = @LIBNL1_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LINUX_INCLUDE_PATH = @LINUX_INCLUDE_PATH@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ @@ -247,13 +254,15 @@ wimaxll_DEPENDENCIES = wimaxll.ver plugindir = $(pkglibdir)/plugins plugin_LTLIBRARIES = \ wimaxll-pl-reset.la \ - wimaxll-pl-rfkill.la + wimaxll-pl-rfkill.la \ + wimaxll-pl-wfsc.la plugin_LDFLAGS = -no-undefined -module -avoid-version \ -export-symbols-regex plugin wimaxll_pl_reset_la_LDFLAGS = $(plugin_LDFLAGS) wimaxll_pl_rfkill_la_LDFLAGS = $(plugin_LDFLAGS) +wimaxll_pl_wfsc_la_LDFLAGS = $(plugin_LDFLAGS) all: all-am .SUFFIXES: @@ -320,6 +329,8 @@ wimaxll-pl-reset.la: $(wimaxll_pl_reset_la_OBJECTS) $(wimaxll_pl_reset_la_DEPEND $(wimaxll_pl_reset_la_LINK) -rpath $(plugindir) $(wimaxll_pl_reset_la_OBJECTS) $(wimaxll_pl_reset_la_LIBADD) $(LIBS) wimaxll-pl-rfkill.la: $(wimaxll_pl_rfkill_la_OBJECTS) $(wimaxll_pl_rfkill_la_DEPENDENCIES) $(wimaxll_pl_rfkill_la_LINK) -rpath $(plugindir) $(wimaxll_pl_rfkill_la_OBJECTS) $(wimaxll_pl_rfkill_la_LIBADD) $(LIBS) +wimaxll-pl-wfsc.la: $(wimaxll_pl_wfsc_la_OBJECTS) $(wimaxll_pl_wfsc_la_DEPENDENCIES) + $(wimaxll_pl_wfsc_la_LINK) -rpath $(plugindir) $(wimaxll_pl_wfsc_la_OBJECTS) $(wimaxll_pl_wfsc_la_LIBADD) $(LIBS) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" @@ -388,6 +399,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-pl-reset.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-pl-rfkill.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-pl-wfsc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-reset.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-rfkill.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wimaxll-wait-for-state-change.Po@am__quote@ @@ -604,7 +616,7 @@ uninstall-am: uninstall-binPROGRAMS uninstall-binSCRIPTS \ wimaxll.exp: $(wimaxll_OBJECTS) - nm -B *.o | awk '{ print $$3 }' | sort -u | grep -E -e '^w_' > $@ + nm -B *.o | awk '{ print $$3 }' | sort -u | grep -E -e '^(w|wimaxll)_' > $@ wimaxll.ver: wimaxll.exp echo "{ global:" > $@ diff --git a/bin/wimaxll-pl-wfsc.c b/bin/wimaxll-pl-wfsc.c new file mode 100644 index 0000000..866196f --- /dev/null +++ b/bin/wimaxll-pl-wfsc.c @@ -0,0 +1,163 @@ +/* + * Linux WiMax + * Swiss-army WiMAX knife: wait for an state change + * + * + * Copyright (C) 2007-2008 Intel Corporation. All rights reserved. + * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Intel Corporation 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. + */ +#define _GNU_SOURCE +#include <argp.h> +#include <wimaxll.h> +#include <wimaxll/version.h> +#include <wimaxll/cmd.h> + + +struct wfsc_args +{ + struct cmd *cmd; + enum wimax_st state; + char **argv; + size_t argc; + unsigned timeout; +}; + + +static +struct argp_option wfsc_options[] = { +#if 0 + /* not really done ... will have to rewrite some code and just + * use the callback with a select stuff */ + { "timeout", 't', "TIMEOUT", 0, + "Time (in seconds) to wait for the state change; " + "0 to wait for ever." }, +#endif + { "help-states", 's', 0, 0, + "List known WiMAX states." }, + { 0 } +}; + + +static +int wfsc_parser(int key, char *arg, struct argp_state *state) +{ + int result = 0; + struct wfsc_args *args = state->input; + char str[256]; + + switch (key) + { + case 't': + if (sscanf(arg, "%u", &args->timeout) != 1) + argp_error(state, "E: %s: cannot parse as a timeout (in seconds)\n", + arg); + break; + + case 's': + wimaxll_states_snprintf(str, sizeof(str)); + w_print("%s: known WiMAX device states: %s\n", + args->cmd->name, str); + exit(0); + break; + + case ARGP_KEY_ARG: + args->state = wimaxll_state_by_name(arg); + if (args->state == __WIMAX_ST_INVALID) + argp_error(state, "E: %s: unknown wimax state\n", arg); + args->argv = &state->argv[state->next]; + args->argc = state->argc - state->next; + /* Stop consuming args right here */ + state->next = state->argc; + break; + + default: + result = ARGP_ERR_UNKNOWN; + } + return result; +} + + +static +int wfsc_fn(struct cmd *cmd, struct wimaxll_handle *wmx, + int argc, char **argv) +{ + int result; + struct wfsc_args args; + enum wimax_st old_state, new_state; + + args.cmd = cmd; + args.state = __WIMAX_ST_INVALID; /* meaning any */ + result = argp_parse(&cmd->argp, argc, argv, + 0, 0, &args); + if (result < 0) + goto error_argp_parse; + w_cmd_need_if(wmx); + while(1) { + result = wimaxll_wait_for_state_change(wmx, &old_state, &new_state); + if (result < 0) + w_abort(1, "%s: error waiting: %d (%s)\n", cmd->name, + result, strerror(result)); + w_info("%d: %s\n", new_state, wimaxll_state_to_name(new_state)); + w_print("%d: %s\n", new_state, wimaxll_state_to_name(new_state)); + if (new_state == args.state) + break; + if (args.state == __WIMAX_ST_INVALID) + break; + } +error_argp_parse: + return result; +} + +static +struct cmd wfsc_cmd = { + .name = "wait-for-state-change", + .argp = { + .options = wfsc_options, + .parser = wfsc_parser, + .args_doc = "[STATE]", + .doc = "Wait for a device state change; if no state is " + "specified, waits until any state transition happens\n", + }, + .fn = wfsc_fn, +}; + + +static +int wfsc_init(void) +{ + return w_cmd_register(&wfsc_cmd); +} + +static +void wfsc_exit(void) +{ + w_cmd_unregister(&wfsc_cmd); +} + +PLUGIN("wfsc", WIMAXLL_VERSION, wfsc_init, wfsc_exit); |