Search Linux Wireless

[PATCH 3/4] rfkill: expose global state to sysfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Cc: Ivo van Doorn <IvDoorn@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux