Author: mmlr Date: 2010-01-27 00:34:23 +0100 (Wed, 27 Jan 2010) New Revision: 35306 Changeset: http://dev.haiku-os.org/changeset/35306/haiku Added: haiku/trunk/src/bin/hid_decode/ haiku/trunk/src/bin/hid_decode/Jamfile haiku/trunk/src/bin/hid_decode/UserlandHID.h haiku/trunk/src/bin/hid_decode/hid_decode.cpp Modified: haiku/trunk/src/bin/Jamfile Log: Add "hid_decode" which uses the usb_hid HID parser to decode a report descriptor (which is conveniently stored by usb_hid to /tmp for each device you plug in). Modified: haiku/trunk/src/bin/Jamfile =================================================================== --- haiku/trunk/src/bin/Jamfile 2010-01-26 23:27:56 UTC (rev 35305) +++ haiku/trunk/src/bin/Jamfile 2010-01-26 23:34:23 UTC (rev 35306) @@ -205,6 +205,7 @@ SubInclude HAIKU_TOP src bin gawk ; SubInclude HAIKU_TOP src bin gdb ; SubInclude HAIKU_TOP src bin grep ; +SubInclude HAIKU_TOP src bin hid_decode ; SubInclude HAIKU_TOP src bin iasl ; SubInclude HAIKU_TOP src bin ideinfo ; SubInclude HAIKU_TOP src bin keymap ; Added: haiku/trunk/src/bin/hid_decode/Jamfile =================================================================== --- haiku/trunk/src/bin/hid_decode/Jamfile (rev 0) +++ haiku/trunk/src/bin/hid_decode/Jamfile 2010-01-26 23:34:23 UTC (rev 35306) @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src bin hid_decode ; + +local defines = [ FDefines USERLAND_HID ] ; +local driverDir = [ FDirName $(HAIKU_TOP) src add-ons kernel drivers input + usb_hid ] ; + +SubDirC++Flags $(defines) ; + +UsePrivateHeaders drivers ; +UseHeaders $(driverDir) ; + +BinCommand hid_decode : + HIDCollection.cpp + HIDParser.cpp + HIDReport.cpp + HIDReportItem.cpp + + hid_decode.cpp + : be +; + +SEARCH on [ FGristFiles HIDCollection.cpp HIDParser.cpp HIDReport.cpp + HIDReportItem.cpp ] = $(driverDir) ; Added: haiku/trunk/src/bin/hid_decode/UserlandHID.h =================================================================== --- haiku/trunk/src/bin/hid_decode/UserlandHID.h (rev 0) +++ haiku/trunk/src/bin/hid_decode/UserlandHID.h 2010-01-26 23:34:23 UTC (rev 35306) @@ -0,0 +1,9 @@ +#ifndef HID_USERLAND_H +#define HID_USERLAND_H + +#include <stdio.h> + +#define TRACE(x...) /*printf(x)*/ +#define TRACE_ALWAYS(x...) printf(x) + +#endif Added: haiku/trunk/src/bin/hid_decode/hid_decode.cpp =================================================================== --- haiku/trunk/src/bin/hid_decode/hid_decode.cpp (rev 0) +++ haiku/trunk/src/bin/hid_decode/hid_decode.cpp 2010-01-26 23:34:23 UTC (rev 35306) @@ -0,0 +1,64 @@ +/* + * Copyright 2010, Michael Lotz, mmlr@xxxxxxxxx + * Distributed under the terms of the MIT License. + */ + +#include "HIDCollection.h" +#include "HIDParser.h" +#include "HIDReport.h" + +#include <File.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +int +main(int argc, char *argv[]) +{ + if (argc < 2) { + printf("usage: %s <hid_descriptor_file>\n", argv[0]); + return 1; + } + + BFile file(argv[1], B_READ_ONLY); + if (!file.IsReadable()) { + printf("can't open file \"%s\" for reading\n", argv[1]); + return 2; + } + + off_t descriptorLength; + file.GetSize(&descriptorLength); + + uint8 *reportDescriptor = (uint8 *)malloc(descriptorLength); + if (reportDescriptor == NULL) { + printf("failed to allocate buffer of %lld bytes\n", descriptorLength); + return 3; + } + + ssize_t read = file.Read(reportDescriptor, descriptorLength); + if (read != descriptorLength) { + printf("failed to read file of %lld bytes: %s\n", descriptorLength, + strerror(read)); + return 4; + } + + HIDParser parser(NULL); + status_t result = parser.ParseReportDescriptor(reportDescriptor, + descriptorLength); + + free(reportDescriptor); + if (result != B_OK) { + printf("failed to parse descriptor: %s\n", strerror(result)); + return 5; + } + + for (uint32 i = 0; i < parser.CountReports(HID_REPORT_TYPE_ANY); i++) + parser.ReportAt(HID_REPORT_TYPE_ANY, i)->PrintToStream(); + + if (parser.RootCollection() != NULL) + parser.RootCollection()->PrintToStream(); + + return 0; +}