From owner-p4-projects@FreeBSD.ORG Sun Jan 25 11:12:04 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3A6B01065675; Sun, 25 Jan 2009 11:12:04 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EED6B1065673 for ; Sun, 25 Jan 2009 11:12:03 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id D22708FC12 for ; Sun, 25 Jan 2009 11:12:03 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0PBC39T091179 for ; Sun, 25 Jan 2009 11:12:03 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0PBC3me091177 for perforce@freebsd.org; Sun, 25 Jan 2009 11:12:03 GMT (envelope-from hselasky@FreeBSD.org) Date: Sun, 25 Jan 2009 11:12:03 GMT Message-Id: <200901251112.n0PBC3me091177@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 156644 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Jan 2009 11:12:05 -0000 http://perforce.freebsd.org/chv.cgi?CH=156644 Change 156644 by hselasky@hselasky_laptop001 on 2009/01/25 11:11:59 Patches to make LibUSBHID work with new USB stack. Affected files ... .. //depot/projects/usb/src/lib/libusbhid/descr.c#2 edit .. //depot/projects/usb/src/lib/libusbhid/usbhid.3#2 edit .. //depot/projects/usb/src/lib/libusbhid/usbhid.h#2 edit Differences ... ==== //depot/projects/usb/src/lib/libusbhid/descr.c#2 (text+ko) ==== @@ -39,21 +39,68 @@ #include #include -#include +#include #include "usbhid.h" #include "usbvar.h" +int +hid_get_report_id(int fd) +{ + int temp = -1; + + if (ioctl(fd, USB_GET_REPORT_ID, &temp) < 0) + return (-1); + + return (temp); +} + report_desc_t hid_get_report_desc(int fd) { - struct usb_ctl_report_desc rep; + struct usb2_gen_descriptor ugd; + report_desc_t rep; + void *data; + int size; + + size = 256; /* be conservative */ + +retry: + + memset(&ugd, 0, sizeof(ugd)); + + data = malloc(size); + if (data == NULL) + return (NULL); + + /* + * We subtract one from size so that the maximum descriptor + * size is 65535 bytes, because "ugd_maxlen" is a 16-bit + * variable! + */ + ugd.ugd_data = data; + ugd.ugd_maxlen = size-1; + if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) { + /* could not read descriptor */ + free(data); + return (NULL); + } - rep.ucrd_size = 0; - if (ioctl(fd, USB_GET_REPORT_DESC, &rep) < 0) + if (ugd.ugd_maxlen == ugd.ugd_actlen) { + /* buffer is too small */ + free (data); + size *= 4; + if (size <= 65536) + goto retry; + /* maximum reached - should not happen */ return (NULL); + } + + rep = hid_use_report_desc(data, ugd.ugd_actlen); - return hid_use_report_desc(rep.ucrd_data, (unsigned int)rep.ucrd_size); + free(data); + + return (rep); } report_desc_t ==== //depot/projects/usb/src/lib/libusbhid/usbhid.3#2 (text+ko) ==== @@ -32,6 +32,7 @@ .Sh NAME .Nm usbhid , .Nm hid_get_report_desc , +.Nm hid_get_report_id , .Nm hid_use_report_desc , .Nm hid_dispose_report_desc , .Nm hid_start_parse , @@ -51,6 +52,8 @@ .In usbhid.h .Ft report_desc_t .Fn hid_get_report_desc "int file" +.Ft int +.Fn hid_get_report_id "int file" .Ft report_desc_t .Fn hid_use_report_desc "unsigned char *data" "unsigned int size" .Ft void @@ -95,6 +98,8 @@ parsing of the descriptor, translating to/from symbolic names, and data manipulation. .Ss Descriptor Functions +The report descriptor ID can be obtained by calling +.Fn hid_get_report_id . A report descriptor can be obtained by calling .Fn hid_get_report_desc with a file descriptor obtained by opening a ==== //depot/projects/usb/src/lib/libusbhid/usbhid.h#2 (text+ko) ==== @@ -87,6 +87,7 @@ report_desc_t hid_get_report_desc(int file); report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size); void hid_dispose_report_desc(report_desc_t); +int hid_get_report_id(int file); /* Parsing of a HID report descriptor, parse.c: */ hid_data_t hid_start_parse(report_desc_t d, int kindset, int id);