Description: Upstream changes introduced in version 30~pre9-3ubuntu3
 This patch has been created by dpkg-source during the package build.
 Here's the last changelog entry, hopefully it gives details on why
 those changes were made:
 .
 wireless-tools (30~pre9-3ubuntu3) lucid; urgency=low
 .
   * Invoke rfkill/version.sh using /bin/sh
 .
 The person named in the Author field signed this changelog entry.
Author: Tim Gardner <tim.gardner@canonical.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- /dev/null
+++ wireless-tools-30~pre9/rfkill/rfkill.8
@@ -0,0 +1,38 @@
+.\"                                      Hey, EMACS: -*- nroff -*-
+.TH RFKILL 8 "July 10, 2009"
+.SH NAME
+rfkill \- tool for enabling and disabling wireless devices
+.SH SYNOPSIS
+.B rfkill
+.RI [ options ] " command"
+.SH OPTIONS
+.TP
+.B \-\-version
+Show the version of rfkill.
+.SH COMMANDS
+.TP
+.B help
+Show rfkill's built-in help text.
+.TP
+.B event
+Listen for rfkill events and display them on stdout.
+.TP
+.B list [type]
+List the current state of all available rfkill-using devices,
+or just all of the given type.
+.TP
+.BI block " index|type"
+Disable the device corresponding to the given index.
+\fItype\fR is one of "all", "wifi", "wlan", "bluetooth", "uwb",
+"ultrawideband", "wimax", "wwan", "gps" or "fm".
+.TP
+.BI unblock " index|type"
+Enable the device corresponding to the given index. If the device is
+hard-blocked, e.g. via a hardware switch, it will remain unavailable though
+it is now soft-unblocked.
+.SH AUTHORS
+rfkill was originally written by Johannes Berg <johannes@sipsolutions.net>
+and Marcel Holtmann <marcel@holtmann.org>.
+.PP
+This manual page was written by Darren Salt <linux@youmustbejoking.demon.co.uk>,
+for the Debian project (and may be used by others).
--- wireless-tools-30~pre9.orig/rfkill/version.sh
+++ wireless-tools-30~pre9/rfkill/version.sh
@@ -1,9 +1,18 @@
 #!/bin/sh
 
-VERSION="0.3"
+VERSION="0.4"
+
+SUFFIX=
+if test "x$1" = x--suffix; then
+	shift
+	SUFFIX="-$1"
+	shift
+fi
 OUT="$1"
 
-if head=`git rev-parse --verify HEAD 2>/dev/null`; then
+if test "x$SUFFIX" != 'x'; then
+	v="$VERSION$SUFFIX"
+elif head=`git rev-parse --verify HEAD 2>/dev/null`; then
 	git update-index --refresh --unmerged > /dev/null
 	descr=$(git describe 2>/dev/null || echo "v$VERSION")
 
--- wireless-tools-30~pre9.orig/rfkill/Makefile
+++ wireless-tools-30~pre9/rfkill/Makefile
@@ -1,7 +1,7 @@
 MAKEFLAGS += --no-print-directory
 
 PREFIX ?= /usr
-BINDIR ?= $(PREFIX)/bin
+SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 
 MKDIR ?= mkdir -p
@@ -29,7 +29,11 @@ VERSION_OBJS := $(filter-out version.o, 
 version.c: version.sh $(patsubst %.o,%.c,$(VERSION_OBJS)) rfkill.h Makefile \
 		$(wildcard .git/index .git/refs/tags)
 	@$(NQ) ' GEN ' $@
-	$(Q)sh ./version.sh $@
+ifeq (,$(VERSION_SUFFIX))
+	$(Q)./version.sh $@
+else
+	$(Q)sh ./version.sh --suffix "$(VERSION_SUFFIX)" $@
+endif
 
 %.o: %.c rfkill.h
 	@$(NQ) ' CC  ' $@
@@ -46,13 +50,13 @@ check:
 	@$(NQ) ' GZIP' $<
 	$(Q)gzip < $< > $@
 
-install: rfkill rfkill.1.gz
+install: rfkill rfkill.8.gz
 	@$(NQ) ' INST rfkill'
-	$(Q)$(MKDIR) $(DESTDIR)$(BINDIR)
-	$(Q)$(INSTALL) -m 755 -t $(DESTDIR)$(BINDIR) rfkill
-	@$(NQ) ' INST rfkill.1'
-	$(Q)$(MKDIR) $(DESTDIR)$(MANDIR)/man1/
-	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)$(MANDIR)/man1/ rfkill.1.gz
+	$(Q)$(MKDIR) $(DESTDIR)$(SBINDIR)
+	$(Q)$(INSTALL) -m 755 -t $(DESTDIR)$(SBINDIR) rfkill
+	@$(NQ) ' INST rfkill.8'
+	$(Q)$(MKDIR) $(DESTDIR)$(MANDIR)/man8/
+	$(Q)$(INSTALL) -m 644 -t $(DESTDIR)$(MANDIR)/man8/ rfkill.8.gz
 
 clean:
 	$(Q)rm -f rfkill *.o *~ *.gz version.c *-stamp
--- wireless-tools-30~pre9.orig/rfkill/rfkill.h
+++ wireless-tools-30~pre9/rfkill/rfkill.h
@@ -35,6 +35,8 @@
  * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
  * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
  * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
+ * @RFKILL_TYPE_GPS: switch is on a GPS device.
+ * @RFKILL_TYPE_FM: switch is on a FM radio device.
  * @NUM_RFKILL_TYPES: number of defined rfkill types
  */
 enum rfkill_type {
@@ -45,6 +47,7 @@ enum rfkill_type {
 	RFKILL_TYPE_WIMAX,
 	RFKILL_TYPE_WWAN,
 	RFKILL_TYPE_GPS,
+	RFKILL_TYPE_FM,
 	NUM_RFKILL_TYPES,
 };
 
--- wireless-tools-30~pre9.orig/rfkill/rfkill.c
+++ wireless-tools-30~pre9/rfkill/rfkill.c
@@ -12,6 +12,7 @@
 #include <stdbool.h>
 #include <sys/types.h>
 #include <sys/poll.h>
+#include <sys/time.h>
 
 #include "rfkill.h"
 #include "core.h"
@@ -19,6 +20,7 @@
 static void rfkill_event(void)
 {
 	struct rfkill_event event;
+	struct timeval tv;
 	struct pollfd p;
 	ssize_t len;
 	int fd, n;
@@ -54,9 +56,11 @@ static void rfkill_event(void)
 			continue;
 		}
 
-		printf("RFKILL event: idx %u type %u op %u soft %u hard %u\n",
-					event.idx, event.type, event.op,
-					event.soft, event.hard);
+		gettimeofday(&tv, NULL);
+		printf("%ld.%06u: idx %u type %u op %u soft %u hard %u\n",
+			(long) tv.tv_sec, (unsigned int) tv.tv_usec,
+			event.idx, event.type, event.op, event.soft, event.hard);
+		fflush(stdout);
 	}
 
 	close(fd);
@@ -105,6 +109,8 @@ static const char *type2string(enum rfki
 		return "Wireless WAN";
 	case RFKILL_TYPE_GPS:
 		return "GPS";
+	case RFKILL_TYPE_FM:
+		return "FM";
 	case NUM_RFKILL_TYPES:
 		return NULL;
 	}
@@ -112,22 +118,89 @@ static const char *type2string(enum rfki
 	return NULL;
 }
 
-static void rfkill_list(void)
+struct rfkill_type_str {
+	enum rfkill_type type;
+	const char *name;
+};
+static const struct rfkill_type_str rfkill_type_strings[] = {
+	{	.type = RFKILL_TYPE_ALL,		.name = "all"	},
+	{	.type = RFKILL_TYPE_WLAN,		.name = "wifi"	},
+	{	.type = RFKILL_TYPE_WLAN,		.name = "wlan"	}, /* alias */
+	{	.type = RFKILL_TYPE_BLUETOOTH,	.name = "bluetooth"	},
+	{	.type = RFKILL_TYPE_UWB,		.name = "uwb"	},
+	{	.type = RFKILL_TYPE_UWB,		.name = "ultrawideband"	}, /* alias */
+	{	.type = RFKILL_TYPE_WIMAX,		.name = "wimax"	},
+	{	.type = RFKILL_TYPE_WWAN,		.name = "wwan"	},
+	{	.type = RFKILL_TYPE_GPS,		.name = "gps"	},
+	{	.type = RFKILL_TYPE_FM,			.name = "fm"	},
+	{	.name = NULL }
+};
+
+struct rfkill_id {
+	union {
+		enum rfkill_type type;
+		__u32 index;
+	};
+	enum {
+		RFKILL_IS_INVALID,
+		RFKILL_IS_TYPE,
+		RFKILL_IS_INDEX,
+	} result;
+};
+
+static struct rfkill_id rfkill_id_to_type(const char *s)
+{
+	const struct rfkill_type_str *p;
+	struct rfkill_id ret;
+
+	if (islower(*s)) {
+		for (p = rfkill_type_strings; p->name != NULL; p++) {
+			if ((strlen(s) == strlen(p->name)) && (!strcmp(s,p->name))) {
+				ret.type = p->type;
+				ret.result = RFKILL_IS_TYPE;
+				return ret;
+			}
+		}
+	} else if (isdigit(*s)) {
+		/* assume a numeric character implies an index. */
+		ret.index = atoi(s);
+		ret.result = RFKILL_IS_INDEX;
+		return ret;
+	}
+
+	ret.result = RFKILL_IS_INVALID;
+	return ret;
+}
+
+static int rfkill_list(const char *param)
 {
+	struct rfkill_id id = { .result = RFKILL_IS_INVALID };
 	struct rfkill_event event;
 	const char *name;
 	ssize_t len;
 	int fd;
 
+	if (param) {
+		id = rfkill_id_to_type(param);
+		if (id.result == RFKILL_IS_INVALID) {
+			fprintf(stderr, "Bogus %s argument '%s'.\n", "list", param);
+			return 2;
+		}
+		/* don't filter "all" */
+		if (id.result == RFKILL_IS_TYPE && id.type == RFKILL_TYPE_ALL)
+			id.result = RFKILL_IS_INVALID;
+	}
+
 	fd = open("/dev/rfkill", O_RDONLY);
 	if (fd < 0) {
 		perror("Can't open RFKILL control device");
-		return;
+		return 1;
 	}
 
 	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
 		perror("Can't set RFKILL control device to non-blocking");
 		close(fd);
+		return 1;
 	}
 
 	while (1) {
@@ -147,6 +220,20 @@ static void rfkill_list(void)
 		if (event.op != RFKILL_OP_ADD)
 			continue;
 
+		/* filter out unwanted results */
+		switch (id.result)
+		{
+		case RFKILL_IS_TYPE:
+			if (event.type != id.type)
+				continue;
+			break;
+		case RFKILL_IS_INDEX:
+			if (event.idx != id.index)
+				continue;
+			break;
+		case RFKILL_IS_INVALID:; /* must be last */
+		}
+
 		name = get_name(event.idx);
 
 		printf("%u: %s: %s\n", event.idx, name,
@@ -156,27 +243,39 @@ static void rfkill_list(void)
 	}
 
 	close(fd);
+	return 0;
 }
 
-static void rfkill_block(bool all, __u32 idx, __u8 block, __u8 type)
+static int rfkill_block(__u8 block, const char *param)
 {
+	struct rfkill_id id;
 	struct rfkill_event event;
 	ssize_t len;
 	int fd;
 
+	id = rfkill_id_to_type(param);
+	if (id.result == RFKILL_IS_INVALID) {
+		fprintf(stderr, "Bogus %s argument '%s'.\n", block ? "block" : "unblock", param);
+		return 2;
+	}
+
 	fd = open("/dev/rfkill", O_RDWR);
 	if (fd < 0) {
 		perror("Can't open RFKILL control device");
-		return;
+		return 1;
 	}
 
 	memset(&event, 0, sizeof(event));
-	if (!all) {
-		event.idx = idx;
-		event.op = RFKILL_OP_CHANGE;
-	} else {
+	switch (id.result) {
+	case RFKILL_IS_TYPE:
 		event.op = RFKILL_OP_CHANGE_ALL;
-		event.type = type;
+		event.type = id.type;
+		break;
+	case RFKILL_IS_INDEX:
+		event.op = RFKILL_OP_CHANGE;
+		event.idx = id.index;
+		break;
+	case RFKILL_IS_INVALID:; /* must be last */
 	}
 	event.soft = block;
 
@@ -185,49 +284,29 @@ static void rfkill_block(bool all, __u32
 		perror("Failed to change RFKILL state");
 
 	close(fd);
-}
-
-struct rfkill_type_str {
-	enum rfkill_type type;
-	char *name;
-};
-static struct rfkill_type_str rfkill_type_strings[] = {
-	{	.type = RFKILL_TYPE_ALL,		.name = "all"	},
-	{	.type = RFKILL_TYPE_WLAN,		.name = "wifi"	},
-	{	.type = RFKILL_TYPE_BLUETOOTH,	.name = "bluetooth"	},
-	{	.type = RFKILL_TYPE_UWB,		.name = "uwb"	},
-	{	.type = RFKILL_TYPE_WIMAX,		.name = "wimax"	},
-	{	.type = RFKILL_TYPE_WWAN,		.name = "wwan"	},
-	{	.type = RFKILL_TYPE_GPS,		.name = "gps"	},
-	{	.name = NULL }
-};
-
-static enum rfkill_type rfkill_str_to_type(char *s)
-{
-	struct rfkill_type_str *p;
-
-	for (p = rfkill_type_strings; p->name != NULL; p++) {
-		if ((strlen(s) == strlen(p->name)) && (!strcmp(s,p->name)))
-			return p->type;
-	}
-	return NUM_RFKILL_TYPES;
+	return 0;
 }
 
 static const char *argv0;
 
-#define BLOCK_PARAMS "{<idx>,all,wifi,bluetooth,uwb,wimax,wwan,gps}"
-
 static void usage(void)
 {
+	const struct rfkill_type_str *p;
+
 	fprintf(stderr, "Usage:\t%s [options] command\n", argv0);
 	fprintf(stderr, "Options:\n");
 	fprintf(stderr, "\t--version\tshow version (%s)\n", rfkill_version);
 	fprintf(stderr, "Commands:\n");
 	fprintf(stderr, "\thelp\n");
 	fprintf(stderr, "\tevent\n");
-	fprintf(stderr, "\tlist\n");
-	fprintf(stderr, "\tblock "BLOCK_PARAMS"\n");
-	fprintf(stderr, "\tunblock "BLOCK_PARAMS"\n");
+	fprintf(stderr, "\tlist [IDENTIFIER]\n");
+	fprintf(stderr, "\tblock IDENTIFIER\n");
+	fprintf(stderr, "\tunblock IDENTIFIER\n");
+	fprintf(stderr, "where IDENTIFIER is the index no. of an rfkill switch or one of:\n");
+	fprintf(stderr, "\t<idx>");
+	for (p = rfkill_type_strings; p->name != NULL; p++)
+		fprintf(stderr, " %s", p->name);
+	fprintf(stderr, "\n");
 }
 
 static void version(void)
@@ -235,33 +314,10 @@ static void version(void)
 	printf("rfkill %s\n", rfkill_version);
 }
 
-static void do_block_unblock(__u8 block, char *param)
-{
-	enum rfkill_type t;
-	__u32 idx;
-
-	if (islower(*param)) {
-		/* assume alphabetic characters imply a wireless type name */
-		t = rfkill_str_to_type(param);
-		if (t < NUM_RFKILL_TYPES)
-			rfkill_block(true, 0, block, t);
-		else
-			goto err;
-	} else if (isdigit(*param)) {
-		/* assume a numeric character implies an index. */
-		idx = atoi(param);
-		rfkill_block(false, idx, block, 0);
-	} else
-		goto err;
-
-	return;
-err:
-	fprintf(stderr,"Bogus %sblock argument '%s'.\n",block?"":"un",param);
-	exit(1);
-}
-
 int main(int argc, char **argv)
 {
+	int ret = 0;
+
 	/* strip off self */
 	argc--;
 	argv0 = *argv++;
@@ -279,19 +335,21 @@ int main(int argc, char **argv)
 	if (strcmp(*argv, "event") == 0) {
 		rfkill_event();
 	} else if (strcmp(*argv, "list") == 0) {
-		rfkill_list();
+		argc--;
+		argv++;
+		rfkill_list(*argv); /* NULL is acceptable */
 	} else if (strcmp(*argv, "block") == 0 && argc > 1) {
 		argc--;
 		argv++;
-		do_block_unblock(1,*argv);
+		ret = rfkill_block(1,*argv);
 	} else if (strcmp(*argv, "unblock") == 0 && argc > 1) {
 		argc--;
 		argv++;
-		do_block_unblock(0,*argv);
+		ret = rfkill_block(0,*argv);
 	} else {
 		usage();
 		return 1;
 	}
 
-	return 0;
+	return ret;
 }
