1 /* 2 * Copyright 2010, Michael Lotz, mmlr@mlotz.ch. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "HIDCollection.h" 7 #include "HIDParser.h" 8 #include "HIDReport.h" 9 10 #include <File.h> 11 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 17 int 18 main(int argc, char *argv[]) 19 { 20 if (argc < 2) { 21 printf("usage: %s <hid_descriptor_file>\n", argv[0]); 22 return 1; 23 } 24 25 BFile file(argv[1], B_READ_ONLY); 26 if (!file.IsReadable()) { 27 printf("can't open file \"%s\" for reading\n", argv[1]); 28 return 2; 29 } 30 31 off_t descriptorLength; 32 file.GetSize(&descriptorLength); 33 34 uint8 *reportDescriptor = (uint8 *)malloc(descriptorLength); 35 if (reportDescriptor == NULL) { 36 printf("failed to allocate buffer of %lld bytes\n", descriptorLength); 37 return 3; 38 } 39 40 ssize_t read = file.Read(reportDescriptor, descriptorLength); 41 if (read != descriptorLength) { 42 printf("failed to read file of %lld bytes: %s\n", descriptorLength, 43 strerror(read)); 44 return 4; 45 } 46 47 HIDParser parser(NULL); 48 status_t result = parser.ParseReportDescriptor(reportDescriptor, 49 descriptorLength); 50 51 free(reportDescriptor); 52 if (result != B_OK) { 53 printf("failed to parse descriptor: %s\n", strerror(result)); 54 return 5; 55 } 56 57 parser.PrintToStream(); 58 return 0; 59 } 60