linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] rfkill/rfkill-input userspace API
@ 2009-03-27 15:58 Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 1/4] rfkill: prepare to export global states to userspace Henrique de Moraes Holschuh
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-27 15:58 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ivo van Doorn

This patch set is being posted for comments and ideas.

It implements a sysfs API for the rfkill core that allows userspace to
completely implement the operations that rfkill-input is capable of.

I am not too happy about it, I think it looks ugly.  But I had no
better ideas.  Comments and ideas for a better one are welcome.

Note: unless something is done to change the way X.org deals with
input devices, rfkill-input is _useless_ in a large number of setups
as far as input event handling goes, because it will never get any
events after X.org evdev grabs the input device.

This patch set applies on top of the rfkill update patchset I just
posted, which is, in turn, based on current wireless-testing master.

Henrique de Moraes Holschuh (4):
      rfkill: prepare to export global states to userspace
      rfkill: expose global switches through sysfs
      rfkill: expose global state to sysfs
      rfkill: export events for global state changes

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/4] rfkill: prepare to export global states to userspace
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
@ 2009-03-27 15:58 ` Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 2/4] rfkill: expose global switches through sysfs Henrique de Moraes Holschuh
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-27 15:58 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ivo van Doorn, Henrique de Moraes Holschuh, Ivo van Doorn

Do some preparatory work in order to export the global states to userspace
through sysfs and uevents.

Add a platform device for use by rfkill (rfkill_global), which will allow
rfkill to export attributes over sysfs and issue uevents for global rfkill
events.

Since the ammount of runtime memory and text size used by the global states
userspace API are not going to be negligible, make it configurable.  Users
of rfkill_input don't need this userspace API, anyway.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Ivo van Doorn <IvDoorn@gmail.com>
---
 net/rfkill/Kconfig  |   19 +++++++++
 net/rfkill/rfkill.c |  102 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/net/rfkill/Kconfig b/net/rfkill/Kconfig
index ae0181f..5492314 100644
--- a/net/rfkill/Kconfig
+++ b/net/rfkill/Kconfig
@@ -20,6 +20,25 @@ config RFKILL_NO_CORE_UAPI
 	  API.  Use this on highly constrained systems when no userspace
 	  feedback or userspace-based rfkill control is needed.
 
+config RFKILL_GLOBAL_UAPI
+	bool "Export rfkill global control to userspace"
+	depends on RFKILL
+	depends on !RFKILL_NO_CORE_UAPI
+	default y
+	help
+	  Say Y here to export an userspace interface that allows
+	  the global control of rfkill switches in per-type groups,
+	  as well as other global rfkill behaviour (such as
+	  system-wide emergency transmitter power off).
+
+	  This option DOES NOT interfere with the per-device rfkill
+	  userspace interface, you will still be able to control
+	  single rfkill devices from userspace even if this option
+	  is disabled.
+
+	  Users of the rfkill_input kernel module can just say N
+	  here and save some memory.
+
 config RFKILL_INPUT
 	tristate "Input layer to RF switch connector"
 	depends on RFKILL && INPUT
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 80f0fa0..1369b56 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -25,6 +25,8 @@
 #include <linux/capability.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
 #include <linux/rfkill.h>
 
 /* Get declaration of rfkill_switch_all() to shut up sparse. */
@@ -889,6 +891,62 @@ int rfkill_set_default(enum rfkill_type type, enum rfkill_state state)
 EXPORT_SYMBOL_GPL(rfkill_set_default);
 
 /*
+ * Rfkill platform device
+ */
+
+#if defined(CONFIG_RFKILL_GLOBAL_UAPI) && !defined(CONFIG_RFKILL_NO_CORE_UAPI)
+#define RFKILL_PDEV_NAME "rfkill_global"
+static struct platform_device *rfkill_pdev;
+
+struct rfkill_dev_attr {
+	struct device_attribute devattr; /* MUST be the first field */
+	unsigned int index;
+};
+
+static struct device_attribute rfkill_g_attrs[] = {
+	__ATTR_NULL
+};
+
+static int __init rfkill_create_g_attrs(struct platform_device *pdev)
+{
+	unsigned int i = 0;
+	int error = 0;
+
+	while (!error && rfkill_g_attrs[i].attr.name) {
+		error = device_create_file(&pdev->dev, &rfkill_g_attrs[i]);
+		i++;
+	};
+
+	if (unlikely(error)) {
+		i--;
+		while (i > 0) {
+			i--;
+			device_remove_file(&pdev->dev, &rfkill_g_attrs[i]);
+		}
+	}
+
+	return error;
+}
+
+static void rfkill_destroy_g_attrs(struct platform_device *pdev)
+{
+	unsigned int i = 0;
+
+	while (rfkill_g_attrs[i].attr.name) {
+		device_remove_file(&pdev->dev, &rfkill_g_attrs[i]);
+		i++;
+	}
+}
+
+static struct platform_driver rfkill_pdrv = {
+	.driver = {
+		.name = RFKILL_PDEV_NAME,
+		.owner = THIS_MODULE,
+	},
+};
+#endif /* CONFIG_RFKILL_GLOBAL_UAPI && !CONFIG_RFKILL_NO_CORE_UAPI */
+
+/*
  * Rfkill module initialization/deinitialization.
  */
 static int __init rfkill_init(void)
@@ -910,11 +968,55 @@ static int __init rfkill_init(void)
 		return error;
 	}
 
+#ifdef CONFIG_RFKILL_NO_CORE_UAPI
+	return 0;
+#else
+  #ifdef CONFIG_RFKILL_GLOBAL_UAPI
+	error = platform_driver_register(&rfkill_pdrv);
+	if (error) {
+		printk(KERN_ERR
+			"rfkill: unable to register platform driver\n");
+		goto err_class_unregister;
+	}
+
+	rfkill_pdev = platform_device_register_simple(RFKILL_PDEV_NAME,
+							-1, NULL, 0);
+	if (IS_ERR(rfkill_pdev)) {
+		error = PTR_ERR(rfkill_pdev);
+		printk(KERN_ERR
+			"rfkill: unable to register platform device\n");
+		goto err_unregister_pdrv;
+	}
+
+	error = rfkill_create_g_attrs(rfkill_pdev);
+	if (error)
+		goto err_unregister_pdev;
+
+	return 0;
+
+err_unregister_pdev:
+	platform_device_unregister(rfkill_pdev);
+
+err_unregister_pdrv:
+	platform_driver_unregister(&rfkill_pdrv);
+
+err_class_unregister:
+	class_unregister(&rfkill_class);
+
+	return error;
+  #else /* CONFIG_RFKILL_GLOBAL_UAPI */
 	return 0;
+  #endif /* CONFIG_RFKILL_GLOBAL_UAPI */
+#endif /* CONFIG_RFKILL_NO_CORE_UAPI */
 }
 
 static void __exit rfkill_exit(void)
 {
+#if defined(CONFIG_RFKILL_GLOBAL_UAPI) && !defined(CONFIG_RFKILL_NO_CORE_UAPI)
+	rfkill_destroy_g_attrs(rfkill_pdev);
+	platform_device_unregister(rfkill_pdev);
+	platform_driver_unregister(&rfkill_pdrv);
+#endif
 	class_unregister(&rfkill_class);
 }
 
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/4] rfkill: expose global switches through sysfs
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 1/4] rfkill: prepare to export global states to userspace Henrique de Moraes Holschuh
@ 2009-03-27 15:58 ` Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 3/4] rfkill: expose global state to sysfs Henrique de Moraes Holschuh
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-27 15:58 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ivo van Doorn, Henrique de Moraes Holschuh, Ivo van Doorn

Expose global switches through sysfs.  This allows userspace to:

1. Enumerate all rfkill switch types (attr. available_types);

2. Read the full state of each global switch (one per type);

3. Manipulate te state of a global switch (block/unblock all
   transmitters of that type).

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Ivo van Doorn <IvDoorn@gmail.com>
---
 net/rfkill/rfkill.c |  238 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 238 insertions(+), 0 deletions(-)

diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 1369b56..703eb4d 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -377,6 +377,10 @@ static ssize_t rfkill_name_show(struct device *dev,
 	return sprintf(buf, "%s\n", rfkill->name);
 }
 
+/*
+ * Rules for type names: must match regexp [a-z0-9_]+
+ * (i.e. no spaces, only lowercase, numbers and '_')
+ */
 static const char *rfkill_get_type_str(enum rfkill_type type)
 {
 	switch (type) {
@@ -903,7 +907,47 @@ struct rfkill_dev_attr {
 	unsigned int index;
 };
 
+struct rfkill_gsw_attr_ptrs {
+	struct rfkill_dev_attr *state;
+	struct rfkill_dev_attr *saved_state;
+	struct rfkill_dev_attr *name;
+	struct device_attribute *eol;
+};
+
+struct rfkill_gsw_attrs {
+	struct rfkill_dev_attr state, saved_state, name;
+};
+
+static struct attribute_group *rfkill_gsw_attr_groups;
+static struct rfkill_gsw_attr_ptrs *rfkill_gsw_attr_ptrs;
+static struct rfkill_gsw_attrs *rfkill_gsw_devattrs;
+
+
+static ssize_t rfkill_attr_available_types_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	unsigned int i;
+	ssize_t s = PAGE_SIZE;
+	ssize_t c = 0;
+	int u;
+
+	for (i = 0; i < RFKILL_TYPE_MAX && s > 4; i++) {
+		u = snprintf(&buf[c], s, "%s ", rfkill_get_type_str(i));
+		c += u;
+		s -= u;
+	}
+	if (i != RFKILL_TYPE_MAX)
+		return -EIO;
+
+	if (i > 0)
+		buf[c-1] = '\n';
+
+	return c;
+}
+
 static struct device_attribute rfkill_g_attrs[] = {
+	__ATTR(available_types, S_IRUGO,
+		rfkill_attr_available_types_show, NULL),
 	__ATTR_NULL
 };
 
@@ -938,6 +982,192 @@ static void rfkill_destroy_g_attrs(struct platform_device *pdev)
 	}
 }
 
+static ssize_t rfkill_gsw_attr_state_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct rfkill_dev_attr *p = container_of(attr,
+					struct rfkill_dev_attr,
+					devattr);
+	int i = p->index;
+	BUG_ON(i < 0 || i >= RFKILL_TYPE_MAX);
+
+	return snprintf(buf, PAGE_SIZE, "%d\n",
+			rfkill_global_states[i].current_state);
+}
+
+static ssize_t rfkill_gsw_attr_state_store(struct device *dev,
+			struct device_attribute *attr, const char *buf,
+			size_t count)
+{
+	struct rfkill_dev_attr *p = container_of(attr,
+					struct rfkill_dev_attr,
+					devattr);
+	int i = p->index;
+	int error;
+	unsigned long state;
+
+	BUG_ON(i < 0 || i >= RFKILL_TYPE_MAX);
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	error = strict_strtoul(buf, 0, &state);
+	if (error)
+		return error;
+
+	if (state != RFKILL_STATE_UNBLOCKED &&
+	    state != RFKILL_STATE_SOFT_BLOCKED)
+		return -EINVAL;
+
+	if (rfkill_epo_lock_active)
+		return -EPERM;
+
+	rfkill_switch_all(i, state);
+
+	return count;
+}
+
+static ssize_t rfkill_gsw_attr_saved_state_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct rfkill_dev_attr *p = container_of(attr,
+					struct rfkill_dev_attr,
+					devattr);
+	int i = p->index;
+	BUG_ON(i < 0 || i >= RFKILL_TYPE_MAX);
+
+	return snprintf(buf, PAGE_SIZE, "%d\n",
+			rfkill_global_states[i].default_state);
+}
+
+static ssize_t rfkill_gsw_attr_name_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	struct rfkill_dev_attr *p = container_of(attr,
+					struct rfkill_dev_attr,
+					devattr);
+	int i = p->index;
+	BUG_ON(i < 0 || i >= RFKILL_TYPE_MAX);
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", rfkill_get_type_str(i));
+}
+
+static void __init rfkill_add_gsw_attr(const enum rfkill_type type)
+{
+	#define RFKILL_GSW_DEVATTR(_name, _mode, _show, _store) \
+	do { \
+		rfkill_gsw_devattrs[type]._name.devattr.attr.name = \
+							__stringify(_name); \
+		rfkill_gsw_devattrs[type]._name.devattr.attr.mode = _mode; \
+		rfkill_gsw_devattrs[type]._name.devattr.show = _show; \
+		rfkill_gsw_devattrs[type]._name.devattr.store = _store; \
+		rfkill_gsw_devattrs[type]._name.index = type; \
+		rfkill_gsw_attr_ptrs[type]._name = \
+					&rfkill_gsw_devattrs[type]._name; \
+	} while (0)
+
+	RFKILL_GSW_DEVATTR(state, S_IWUSR | S_IRUGO,
+			rfkill_gsw_attr_state_show,
+			rfkill_gsw_attr_state_store);
+	RFKILL_GSW_DEVATTR(saved_state, S_IRUGO,
+			rfkill_gsw_attr_saved_state_show, NULL);
+	RFKILL_GSW_DEVATTR(name, S_IRUGO,
+			rfkill_gsw_attr_name_show, NULL);
+
+	#undef RFKILL_GSW_DEVATTR
+}
+
+static void rfkill_deallocate_gsw_devattrs(void)
+{
+	kfree(rfkill_gsw_devattrs);
+	rfkill_gsw_devattrs = NULL;
+}
+
+/* error unwind done by caller through rfkill_deallocate_gsw_devattrs() */
+static int __init rfkill_allocate_gsw_devattrs(void)
+{
+	rfkill_gsw_devattrs = kcalloc(RFKILL_TYPE_MAX,
+					sizeof(*rfkill_gsw_devattrs),
+					GFP_KERNEL);
+	if (!rfkill_gsw_devattrs)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static int __init rfkill_create_gsw_groups(struct platform_device *pdev)
+{
+	int i;
+	int error;
+
+	rfkill_gsw_attr_ptrs = kcalloc(RFKILL_TYPE_MAX,
+					sizeof(*rfkill_gsw_attr_ptrs),
+					GFP_KERNEL);
+	if (!rfkill_gsw_attr_ptrs)
+		return -ENOMEM;
+
+	rfkill_gsw_attr_groups = kcalloc(RFKILL_TYPE_MAX,
+					sizeof(*rfkill_gsw_attr_groups),
+					GFP_KERNEL);
+	if (!rfkill_gsw_attr_groups) {
+		error = -ENOMEM;
+		goto err_alloc_1;
+	}
+
+	error = rfkill_allocate_gsw_devattrs();
+	if (error < 0)
+		goto err_exit;
+
+	error = 0;
+	i = 0;
+	while (!error && i < RFKILL_TYPE_MAX) {
+		rfkill_add_gsw_attr(i);
+
+		rfkill_gsw_attr_groups[i].name = rfkill_get_type_str(i);
+		rfkill_gsw_attr_groups[i].attrs =
+				(struct attribute **)(&rfkill_gsw_attr_ptrs[i]);
+
+		error = sysfs_create_group(&pdev->dev.kobj,
+					   &rfkill_gsw_attr_groups[i]);
+		i++;
+	}
+	if (error) {
+		i--;
+		while (i > 0) {
+			i--;
+			sysfs_remove_group(&pdev->dev.kobj,
+					   &rfkill_gsw_attr_groups[i]);
+		}
+		goto err_exit;
+	}
+
+	return 0;
+
+err_exit:
+	rfkill_deallocate_gsw_devattrs();
+	kfree(rfkill_gsw_attr_groups);
+	rfkill_gsw_attr_groups = NULL;
+err_alloc_1:
+	kfree(rfkill_gsw_attr_ptrs);
+	rfkill_gsw_attr_ptrs = NULL;
+	return error;
+}
+
+static void __exit rfkill_destroy_gsw_attr(struct platform_device *pdev)
+{
+	int i;
+
+	if (rfkill_gsw_attr_groups) {
+		for (i = 0; i < RFKILL_TYPE_MAX; i++) {
+			sysfs_remove_group(&pdev->dev.kobj,
+					   &rfkill_gsw_attr_groups[i]);
+		}
+		kfree(rfkill_gsw_attr_groups);
+	}
+	rfkill_deallocate_gsw_devattrs();
+	kfree(rfkill_gsw_attr_ptrs);
+}
+
 static struct platform_driver rfkill_pdrv = {
 	.driver = {
 		.name = RFKILL_PDEV_NAME,
@@ -992,8 +1222,15 @@ static int __init rfkill_init(void)
 	if (error)
 		goto err_unregister_pdev;
 
+	error = rfkill_create_gsw_groups(rfkill_pdev);
+	if (error)
+		goto err_unregister_pdev_attr;
+
 	return 0;
 
+err_unregister_pdev_attr:
+	rfkill_destroy_g_attrs(rfkill_pdev);
+
 err_unregister_pdev:
 	platform_device_unregister(rfkill_pdev);
 
@@ -1013,6 +1250,7 @@ err_class_unregister:
 static void __exit rfkill_exit(void)
 {
 #if defined(CONFIG_RFKILL_GLOBAL_UAPI) && !defined(CONFIG_RFKILL_NO_CORE_UAPI)
+	rfkill_destroy_gsw_attr(rfkill_pdev);
 	rfkill_destroy_g_attrs(rfkill_pdev);
 	platform_device_unregister(rfkill_pdev);
 	platform_driver_unregister(&rfkill_pdrv);
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/4] rfkill: expose global state to sysfs
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 1/4] rfkill: prepare to export global states to userspace Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 2/4] rfkill: expose global switches through sysfs Henrique de Moraes Holschuh
@ 2009-03-27 15:58 ` Henrique de Moraes Holschuh
  2009-03-27 15:58 ` [PATCH 4/4] rfkill: export events for global state changes Henrique de Moraes Holschuh
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-27 15:58 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ivo van Doorn, Henrique de Moraes Holschuh, Ivo van Doorn

Expose the global state of rfkill through sysfs.  Userspace can now:

1. Check the current state, enter or exit EPO through the
emergency_power_off attribute;

2. Restore to the state before the last EPO through a write to the
restore_saved_state attribute;

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Ivo van Doorn <IvDoorn@gmail.com>
---
 net/rfkill/rfkill.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 703eb4d..901e6c2 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -945,9 +945,73 @@ static ssize_t rfkill_attr_available_types_show(struct device *dev,
 	return c;
 }
 
+static ssize_t rfkill_attr_emergency_power_off_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, "%u\n",
+			rfkill_epo_lock_active ? 1 : 0);
+}
+
+static ssize_t rfkill_attr_emergency_power_off_store(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t count)
+{
+	unsigned long l;
+	int error;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	error = strict_strtoul(buf, 0, &l);
+	if (error)
+		return error;
+
+	if (l > 1)
+		return -EINVAL;
+
+	if (l)
+		rfkill_epo();
+	else
+		rfkill_remove_epo_lock();
+
+	return count;
+}
+
+static ssize_t rfkill_attr_restore_saved_state_store(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t count)
+{
+	unsigned long l;
+	int error;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	error = strict_strtoul(buf, 0, &l);
+	if (error)
+		return error;
+
+	if (l > 1)
+		return -EINVAL;
+
+	/* For userspace, require explicit unlock */
+	if (rfkill_epo_lock_active)
+		return -EPERM;
+
+	if (l)
+		rfkill_restore_states();
+
+	return count;
+}
+
 static struct device_attribute rfkill_g_attrs[] = {
 	__ATTR(available_types, S_IRUGO,
 		rfkill_attr_available_types_show, NULL),
+	__ATTR(emergency_power_off, S_IWUSR | S_IRUGO,
+		rfkill_attr_emergency_power_off_show,
+		rfkill_attr_emergency_power_off_store),
+	__ATTR(restore_saved_state, S_IWUSR,
+		NULL, rfkill_attr_restore_saved_state_store),
 	__ATTR_NULL
 };
 
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/4] rfkill: export events for global state changes
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
                   ` (2 preceding siblings ...)
  2009-03-27 15:58 ` [PATCH 3/4] rfkill: expose global state to sysfs Henrique de Moraes Holschuh
@ 2009-03-27 15:58 ` Henrique de Moraes Holschuh
  2009-03-27 21:34 ` [RFC] rfkill/rfkill-input userspace API Johannes Berg
  2009-03-27 22:11 ` Matthew Garrett
  5 siblings, 0 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-27 15:58 UTC (permalink / raw)
  To: linux-wireless; +Cc: Ivo van Doorn, Henrique de Moraes Holschuh, Ivo van Doorn

Issue uevents for global rfkill state changes.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Ivo van Doorn <IvDoorn@gmail.com>
---
 net/rfkill/rfkill.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 901e6c2..2f23cf7 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -56,6 +56,8 @@ static unsigned long rfkill_states_lockdflt[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
 static bool rfkill_epo_lock_active;
 
 static void rfkill_uevent(struct rfkill *rfkill);
+static void rfkill_global_uevent(enum rfkill_type type,
+				 enum rfkill_state state);
 
 #ifdef CONFIG_RFKILL_LEDS
 static void rfkill_led_trigger(struct rfkill *rfkill,
@@ -188,6 +190,7 @@ static void __rfkill_switch_all(const enum rfkill_type type,
 			mutex_unlock(&rfkill->mutex);
 		}
 	}
+	rfkill_global_uevent(type, state);
 }
 
 /**
@@ -1238,6 +1241,42 @@ static struct platform_driver rfkill_pdrv = {
 		.owner = THIS_MODULE,
 	},
 };
+
+/*
+ * Global rfkill uevents
+ */
+
+static void rfkill_global_uevent(enum rfkill_type type,
+				 enum rfkill_state state)
+{
+	struct kobj_uevent_env *env;
+
+	env = kzalloc(sizeof(*env), GFP_KERNEL);
+	if (WARN(!env, "rfkill: out of memory while trying to issue "
+			"RFKILL_GLOBAL_STATE_CHANGED uevent for type "
+			"%u\n", type))
+		return;
+
+	if (add_uevent_var(env, "RFKILL_GLOBAL_TYPE=%s",
+				rfkill_get_type_str(type)) ||
+	    add_uevent_var(env, "RFKILL_GLOBAL_STATE=%d",
+				state))
+		goto err_exit;
+
+	kobject_uevent_env(&rfkill_pdev->dev.kobj, KOBJ_CHANGE,
+			   (char **)&env->envp);
+	kfree(env);
+	return;
+
+err_exit:
+	WARN(1, "rfkill: failed to build uevent RFKILL_GLOBAL_STATE_CHANGED "
+		"data structures for type %u\n", type);
+	kfree(env);
+	return;
+}
+#else
+static void rfkill_global_uevent(enum rfkill_type type,
+				 enum rfkill_state state) {};
 #endif /* CONFIG_RFKILL_GLOBAL_UAPI && !CONFIG_RFKILL_NO_CORE_UAPI */
 
 /*
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
                   ` (3 preceding siblings ...)
  2009-03-27 15:58 ` [PATCH 4/4] rfkill: export events for global state changes Henrique de Moraes Holschuh
@ 2009-03-27 21:34 ` Johannes Berg
  2009-03-28 12:37   ` Henrique de Moraes Holschuh
  2009-03-27 22:11 ` Matthew Garrett
  5 siblings, 1 reply; 16+ messages in thread
From: Johannes Berg @ 2009-03-27 21:34 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

On Fri, 2009-03-27 at 12:58 -0300, Henrique de Moraes Holschuh wrote:
> This patch set is being posted for comments and ideas.
> 
> It implements a sysfs API for the rfkill core that allows userspace to
> completely implement the operations that rfkill-input is capable of.
> 
> I am not too happy about it, I think it looks ugly.  But I had no
> better ideas.  Comments and ideas for a better one are welcome.

Can we do it after I rewrite the core to be useful wrt. hard/soft
blocks? Same comments as in my other email apply. I'm sorry to waste
your work on it, but on the other hand you clearly didn't ever care
about it enough to have posted it earlier.

> Note: unless something is done to change the way X.org deals with
> input devices, rfkill-input is _useless_ in a large number of setups
> as far as input event handling goes, because it will never get any
> events after X.org evdev grabs the input device.

Right.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
                   ` (4 preceding siblings ...)
  2009-03-27 21:34 ` [RFC] rfkill/rfkill-input userspace API Johannes Berg
@ 2009-03-27 22:11 ` Matthew Garrett
  2009-03-28 12:36   ` Henrique de Moraes Holschuh
  5 siblings, 1 reply; 16+ messages in thread
From: Matthew Garrett @ 2009-03-27 22:11 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

On Fri, Mar 27, 2009 at 12:58:01PM -0300, Henrique de Moraes Holschuh wrote:

> Note: unless something is done to change the way X.org deals with
> input devices, rfkill-input is _useless_ in a large number of setups
> as far as input event handling goes, because it will never get any
> events after X.org evdev grabs the input device.

X.org evdev doesn't grab the input device. We fixed that precisely 
because it broke rfkill-input.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-27 22:11 ` Matthew Garrett
@ 2009-03-28 12:36   ` Henrique de Moraes Holschuh
  2009-03-28 12:44     ` Matthew Garrett
  2009-03-28 12:47     ` Henrique de Moraes Holschuh
  0 siblings, 2 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-28 12:36 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: linux-wireless, Ivo van Doorn

On Fri, 27 Mar 2009, Matthew Garrett wrote:
> On Fri, Mar 27, 2009 at 12:58:01PM -0300, Henrique de Moraes Holschuh wrote:
> > Note: unless something is done to change the way X.org deals with
> > input devices, rfkill-input is _useless_ in a large number of setups
> > as far as input event handling goes, because it will never get any
> > events after X.org evdev grabs the input device.
> 
> X.org evdev doesn't grab the input device. We fixed that precisely 
> because it broke rfkill-input.

Eh? What is that ioctl in the git version doing there, then?  Did I
get the code from the wrong branch or something?

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-27 21:34 ` [RFC] rfkill/rfkill-input userspace API Johannes Berg
@ 2009-03-28 12:37   ` Henrique de Moraes Holschuh
  0 siblings, 0 replies; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-28 12:37 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless, Ivo van Doorn

On Fri, 27 Mar 2009, Johannes Berg wrote:
> Can we do it after I rewrite the core to be useful wrt. hard/soft
> blocks? Same comments as in my other email apply. I'm sorry to waste

As long as you let me take a serious look on the new code, to make
sure the platform driver side is well represented, I don't see a
problem.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 12:36   ` Henrique de Moraes Holschuh
@ 2009-03-28 12:44     ` Matthew Garrett
  2009-03-28 12:47     ` Henrique de Moraes Holschuh
  1 sibling, 0 replies; 16+ messages in thread
From: Matthew Garrett @ 2009-03-28 12:44 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

On Sat, Mar 28, 2009 at 09:36:45AM -0300, Henrique de Moraes Holschuh wrote:
> On Fri, 27 Mar 2009, Matthew Garrett wrote:
> > On Fri, Mar 27, 2009 at 12:58:01PM -0300, Henrique de Moraes Holschuh wrote:
> > > Note: unless something is done to change the way X.org deals with
> > > input devices, rfkill-input is _useless_ in a large number of setups
> > > as far as input event handling goes, because it will never get any
> > > events after X.org evdev grabs the input device.
> > 
> > X.org evdev doesn't grab the input device. We fixed that precisely 
> > because it broke rfkill-input.
> 
> Eh? What is that ioctl in the git version doing there, then?  Did I
> get the code from the wrong branch or something?

It'll only call the ioctl if the user explicitly passes the GrabDevice
option, and if they do that they can deal with the breakage. Default 
behaviour is not to grab. From the source:

   /* Grabbing the event device stops in-kernel event forwarding. In other     
       words, it disables rfkill and the "Macintosh mouse button emulation".
       Note that this needs a server that sets the console to RAW mode. */

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 12:36   ` Henrique de Moraes Holschuh
  2009-03-28 12:44     ` Matthew Garrett
@ 2009-03-28 12:47     ` Henrique de Moraes Holschuh
  2009-03-28 12:53       ` Matthew Garrett
  1 sibling, 1 reply; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-28 12:47 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: linux-wireless, Ivo van Doorn

Hi Matthew!

On Sat, 28 Mar 2009, Henrique de Moraes Holschuh wrote:

> On Fri, 27 Mar 2009, Matthew Garrett wrote:
> > On Fri, Mar 27, 2009 at 12:58:01PM -0300, Henrique de Moraes Holschuh wrote:
> > > Note: unless something is done to change the way X.org deals with
> > > input devices, rfkill-input is _useless_ in a large number of setups
> > > as far as input event handling goes, because it will never get any
> > > events after X.org evdev grabs the input device.
> > 
> > X.org evdev doesn't grab the input device. We fixed that precisely 
> > because it broke rfkill-input.
> 
> Eh? What is that ioctl in the git version doing there, then?  Did I
> get the code from the wrong branch or something?

Ok, more on this: the ioctl _is_ needed for privacy reasons, it wasn't
added there just for the kick of it AFAIK.  Instead of just breaking
things the other way, can we configure evdev to sometimes do the grab,
and sometimes not, depending on a config option for that particular
device? 

Keyboards should be grabbed. Platform driver event sources shouldn't
(most of the time, anyway).  Adding flags to the input devices so that
the kernel can hint to userspace what should be done by default for a
given device is easy, and I offer to do the work.  I already want to
add flags to tell the joystick and mouse emulation to keep clear of
hdaps, anyway...

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 12:47     ` Henrique de Moraes Holschuh
@ 2009-03-28 12:53       ` Matthew Garrett
  2009-03-28 14:48         ` Henrique de Moraes Holschuh
  0 siblings, 1 reply; 16+ messages in thread
From: Matthew Garrett @ 2009-03-28 12:53 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

On Sat, Mar 28, 2009 at 09:47:19AM -0300, Henrique de Moraes Holschuh wrote:
> Hi Matthew!
> > Eh? What is that ioctl in the git version doing there, then?  Did I
> > get the code from the wrong branch or something?
> 
> Ok, more on this: the ioctl _is_ needed for privacy reasons, it wasn't
> added there just for the kick of it AFAIK.  Instead of just breaking
> things the other way, can we configure evdev to sometimes do the grab,
> and sometimes not, depending on a config option for that particular
> device? 

No it's not. The event devices are only readable by root, and root can 
get your keypresses anyway.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 12:53       ` Matthew Garrett
@ 2009-03-28 14:48         ` Henrique de Moraes Holschuh
  2009-03-28 15:02           ` Matthew Garrett
  0 siblings, 1 reply; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-28 14:48 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: linux-wireless, Ivo van Doorn

On Sat, 28 Mar 2009, Matthew Garrett wrote:
> On Sat, Mar 28, 2009 at 09:47:19AM -0300, Henrique de Moraes Holschuh wrote:
> > > Eh? What is that ioctl in the git version doing there, then?  Did I
> > > get the code from the wrong branch or something?
> > 
> > Ok, more on this: the ioctl _is_ needed for privacy reasons, it wasn't
> > added there just for the kick of it AFAIK.  Instead of just breaking
> > things the other way, can we configure evdev to sometimes do the grab,
> > and sometimes not, depending on a config option for that particular
> > device? 
> 
> No it's not. The event devices are only readable by root, and root can 
> get your keypresses anyway.

I can live with that.  Very well, I will hunt down what version of
evdev we have in Debian stable and unstable, what version of evdev
stopped doing grab-by-default, and document this in a few places.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 14:48         ` Henrique de Moraes Holschuh
@ 2009-03-28 15:02           ` Matthew Garrett
  2009-03-28 15:14             ` Henrique de Moraes Holschuh
  0 siblings, 1 reply; 16+ messages in thread
From: Matthew Garrett @ 2009-03-28 15:02 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

On Sat, Mar 28, 2009 at 11:48:23AM -0300, Henrique de Moraes Holschuh wrote:

> I can live with that.  Very well, I will hunt down what version of
> evdev we have in Debian stable and unstable, what version of evdev
> stopped doing grab-by-default, and document this in a few places.

The change was in commit 4912e2aa7f867a86d383010023b8426c881fb3b0 which 
was on October 16th of last year. It does depend on having an X server 
that sets the console into raw mode - the only reason evdev was ever 
doing the grabs was because that particular bit of magic had ended up in 
the legacy keyboard driver rather than being in the server core, and 
everybody had forgotten how this stuff worked.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 15:02           ` Matthew Garrett
@ 2009-03-28 15:14             ` Henrique de Moraes Holschuh
  2009-03-28 15:22               ` Matthew Garrett
  0 siblings, 1 reply; 16+ messages in thread
From: Henrique de Moraes Holschuh @ 2009-03-28 15:14 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: linux-wireless, Ivo van Doorn

On Sat, 28 Mar 2009, Matthew Garrett wrote:
> On Sat, Mar 28, 2009 at 11:48:23AM -0300, Henrique de Moraes Holschuh wrote:
> > I can live with that.  Very well, I will hunt down what version of
> > evdev we have in Debian stable and unstable, what version of evdev
> > stopped doing grab-by-default, and document this in a few places.
> 
> The change was in commit 4912e2aa7f867a86d383010023b8426c881fb3b0 which 
> was on October 16th of last year. It does depend on having an X server 
> that sets the console into raw mode - the only reason evdev was ever 
> doing the grabs was because that particular bit of magic had ended up in 
> the legacy keyboard driver rather than being in the server core, and 
> everybody had forgotten how this stuff worked.

What version of the X server does this?  This kind of thing will
probably need to end up in the rfkill-input docs :-(

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC] rfkill/rfkill-input userspace API
  2009-03-28 15:14             ` Henrique de Moraes Holschuh
@ 2009-03-28 15:22               ` Matthew Garrett
  0 siblings, 0 replies; 16+ messages in thread
From: Matthew Garrett @ 2009-03-28 15:22 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: linux-wireless, Ivo van Doorn

On Sat, Mar 28, 2009 at 12:14:16PM -0300, Henrique de Moraes Holschuh wrote:

> What version of the X server does this?  This kind of thing will
> probably need to end up in the rfkill-input docs :-(

1.5.3 or later, but any distribution running an earlier 1.5 should 
really cherry-pick it back - a lot gets broken otherwise. 
d936a4235c9625bd41569cef3452dd086284e0d7 is the commit. Pre-1.5 servers 
shouldn't be using evdev so won't have this problem.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-03-28 15:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-27 15:58 [RFC] rfkill/rfkill-input userspace API Henrique de Moraes Holschuh
2009-03-27 15:58 ` [PATCH 1/4] rfkill: prepare to export global states to userspace Henrique de Moraes Holschuh
2009-03-27 15:58 ` [PATCH 2/4] rfkill: expose global switches through sysfs Henrique de Moraes Holschuh
2009-03-27 15:58 ` [PATCH 3/4] rfkill: expose global state to sysfs Henrique de Moraes Holschuh
2009-03-27 15:58 ` [PATCH 4/4] rfkill: export events for global state changes Henrique de Moraes Holschuh
2009-03-27 21:34 ` [RFC] rfkill/rfkill-input userspace API Johannes Berg
2009-03-28 12:37   ` Henrique de Moraes Holschuh
2009-03-27 22:11 ` Matthew Garrett
2009-03-28 12:36   ` Henrique de Moraes Holschuh
2009-03-28 12:44     ` Matthew Garrett
2009-03-28 12:47     ` Henrique de Moraes Holschuh
2009-03-28 12:53       ` Matthew Garrett
2009-03-28 14:48         ` Henrique de Moraes Holschuh
2009-03-28 15:02           ` Matthew Garrett
2009-03-28 15:14             ` Henrique de Moraes Holschuh
2009-03-28 15:22               ` Matthew Garrett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).