lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 11 Mar 2011 02:37:51 -0500
From:	Rafi Rubin <rafi@...s.upenn.edu>
To:	jkosina@...e.cz, linux-input@...r.kernel.org
Cc:	linux-kernel@...r.kernel.org, micki@...rig.com,
	rydberg@...omail.se, chatty@...c.fr, dmitry.torokhov@...il.com,
	Rafi Rubin <rafi@...s.upenn.edu>
Subject: [PATCH 1/2] hid-ntrig: sysfs nodes for modes

Signed-off-by: Rafi Rubin <rafi@...s.upenn.edu>

---

If the code is there, might as well expose a friendly interface to the
user.
---
 drivers/hid/hid-ntrig.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index fa862c5..24ab6a5 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -24,6 +24,8 @@
 
 #define NTRIG_DUPLICATE_USAGES	0x001
 
+static const char *ntrig_modes[4] = { "pen", "touch", "auto", "dual" };
+
 static unsigned int min_width;
 module_param(min_width, uint, 0644);
 MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
@@ -430,6 +432,64 @@ static ssize_t set_deactivate_slack(struct device *dev,
 static DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack,
 		   set_deactivate_slack);
 
+
+static ssize_t show_mode(struct device *dev,
+			struct device_attribute *attr,
+			char *buf)
+{
+	int mode = ntrig_get_mode(container_of(dev, struct hid_device, dev));
+	int i, ret;
+	char *s = buf;
+
+	if (mode < 0)
+		return mode;
+
+
+	for (i = 0; i < 4; i++)
+		s += sprintf(s, "%s%s%s ", (i == mode) ? "[" : "",
+			     ntrig_modes[i], (i == mode) ? "]" : "");
+
+	if (mode >= 4)
+		s += sprintf(s, "[%d]\n", mode);
+	else
+		*(s - 1) = '\n';
+
+	ret = s - buf;
+
+	return ret;
+}
+
+static ssize_t store_mode(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	int len;
+	int i;
+	int mode = -EINVAL;
+	char *p;
+
+	p = memchr(buf, '\n', count);
+	len = p ? p - buf : count;
+
+	if (len == 1 && buf[0] >= '0' && buf[0] <= '4') {
+		mode = buf[0] - '0';
+	} else
+		for (i = 0; i < 4; i++)
+			if (len == strlen(ntrig_modes[i]) &&
+			    !strncmp(buf, ntrig_modes[i], len)) {
+				mode = i;
+				break;
+			}
+
+	if (mode < 0)
+		return mode;
+
+	ntrig_set_mode(container_of(dev, struct hid_device, dev), mode);
+
+	return count;
+}
+static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, store_mode);
+
 static struct attribute *sysfs_attrs[] = {
 	&dev_attr_sensor_physical_width.attr,
 	&dev_attr_sensor_physical_height.attr,
@@ -441,6 +501,7 @@ static struct attribute *sysfs_attrs[] = {
 	&dev_attr_activation_width.attr,
 	&dev_attr_activation_height.attr,
 	&dev_attr_deactivate_slack.attr,
+	&dev_attr_mode.attr,
 	NULL
 };
 
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ