summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-04-08 01:01:29 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-04-08 01:01:29 +0200
commit0c2bd445f484677bcdb62430bf5ad065eb67392f (patch)
tree6429c7cf44f35223e420583411d59454e6dfbaf9
parent58beb1a403aac00f53ca290ff6c384873d6bd919 (diff)
downloadltunify-0c2bd445f484677bcdb62430bf5ad065eb67392f.tar.gz
lib/hidpp20: implement hidpp20_get_version
-rw-r--r--lib/hidpp20.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/hidpp20.c b/lib/hidpp20.c
new file mode 100644
index 0000000..25e7a43
--- /dev/null
+++ b/lib/hidpp20.c
@@ -0,0 +1,54 @@
+/*
+ * HID++ 2.0 protocol details.
+ *
+ * Copyright (C) 2014 Peter Wu <peter@lekensteyn.nl>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "debug.h"
+#include "hidpp.h"
+#include "hidpp10.h"
+#include "hidpp20.h"
+
+uint16_t hidpp20_get_version(int fd, uint8_t device_index)
+{
+ int r;
+ uint16_t ver = 0;
+ const uint8_t pingData = 0x14;
+ HidppMessage req = {
+ .report_id = HIDPP_SHORT,
+ .device_index = device_index,
+ .feature_id = 0x00,
+ .func = 0x14,
+ .params = { 0, 0, pingData }
+ };
+
+ assert(device_index >= 1 && device_index <= MAX_DEVICES);
+
+ r = hidpp10_request(fd, &req, NULL, NULL);
+ if (r == 0 && req.params[2] == pingData) {
+ ver = (req.params[0] << 8) | req.params[1];
+ } else if (r == HIDPP_ERR_INVALID_SUBID) {
+ ver = 0x0100;
+ } else {
+ trace_log("[ix=%02x] HID++ version unavailable, error=%i\n",
+ device_index, r);
+ }
+
+ return ver;
+}