From be68eabdc8dbd85b407ed2f7a0a0280360a4fa12 Mon Sep 17 00:00:00 2001 From: jcs Date: Sun, 30 May 2021 19:54:52 +0000 Subject: [PATCH] add hid_get_report_desc_data() to access the raw report descriptor data without needing to export the report_desc struct definition. suggested by and ok anton@ --- lib/libusbhid/descr.c | 9 ++++++++- lib/libusbhid/shlib_version | 2 +- lib/libusbhid/usbhid.3 | 10 +++++++--- lib/libusbhid/usbhid.h | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/libusbhid/descr.c b/lib/libusbhid/descr.c index 9d81c2f0e3f..1c18fe987f5 100644 --- a/lib/libusbhid/descr.c +++ b/lib/libusbhid/descr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: descr.c,v 1.7 2019/06/28 13:32:42 deraadt Exp $ */ +/* $OpenBSD: descr.c,v 1.8 2021/05/30 19:54:52 jcs Exp $ */ /* $NetBSD: descr.c,v 1.2 2002/02/20 20:31:07 christos Exp $ */ /* @@ -71,3 +71,10 @@ hid_dispose_report_desc(report_desc_t r) free(r); } + +void +hid_get_report_desc_data(report_desc_t d, uint8_t **data, uint32_t *size) +{ + *data = d->data; + *size = d->size; +} diff --git a/lib/libusbhid/shlib_version b/lib/libusbhid/shlib_version index 5b844bbf422..b39addfcc64 100644 --- a/lib/libusbhid/shlib_version +++ b/lib/libusbhid/shlib_version @@ -1,2 +1,2 @@ major=7 -minor=0 +minor=1 diff --git a/lib/libusbhid/usbhid.3 b/lib/libusbhid/usbhid.3 index 62771a95798..f9a555a130f 100644 --- a/lib/libusbhid/usbhid.3 +++ b/lib/libusbhid/usbhid.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: usbhid.3,v 1.21 2020/10/24 10:33:44 jmc Exp $ +.\" $OpenBSD: usbhid.3,v 1.22 2021/05/30 19:54:52 jcs Exp $ .\" $NetBSD: usbhid.3,v 1.5 2002/02/07 07:00:52 ross Exp $ .\" .\" Copyright (c) 1999, 2001 Lennart Augustsson @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: October 24 2020 $ +.Dd $Mdocdate: May 30 2021 $ .Dt USBHID 3 .Os .Sh NAME @@ -33,6 +33,7 @@ .Nm hid_get_report_desc , .Nm hid_use_report_desc , .Nm hid_dispose_report_desc , +.Nm hid_get_report_desc_data , .Nm hid_start_parse , .Nm hid_end_parse , .Nm hid_get_item , @@ -55,6 +56,8 @@ .Fn hid_use_report_desc "unsigned char *data" "unsigned int size" .Ft void .Fn hid_dispose_report_desc "report_desc_t d" +.Ft void +.Fn hid_get_report_desc_data "report_desc_t d" "uint8_t **data" "uint32_t *size" .Ft hid_data_t .Fn hid_start_parse "report_desc_t d" "int kindset" "int id" .Ft void @@ -104,7 +107,8 @@ with a file descriptor obtained by opening a device. Alternatively a data buffer containing the report descriptor can be passed into .Fn hid_use_report_desc . -The data is copied into an internal structure. +The data is copied into an internal structure which can be accessed with +.Fn hid_get_report_desc_data . When the report descriptor is no longer needed it should be freed by calling .Fn hid_dispose_report_desc . The type diff --git a/lib/libusbhid/usbhid.h b/lib/libusbhid/usbhid.h index 39adb4ad02f..e3423995289 100644 --- a/lib/libusbhid/usbhid.h +++ b/lib/libusbhid/usbhid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbhid.h,v 1.8 2016/01/09 04:14:42 jcs Exp $ */ +/* $OpenBSD: usbhid.h,v 1.9 2021/05/30 19:54:52 jcs Exp $ */ /* $NetBSD: usbhid.h,v 1.1 2001/12/28 17:45:27 augustss Exp $ */ /* @@ -77,6 +77,7 @@ typedef struct hid_item { 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); +void hid_get_report_desc_data(report_desc_t, uint8_t **, uint32_t *); /* Parsing of a HID report descriptor, parse.c: */ hid_data_t hid_start_parse(report_desc_t d, int kindset, int id); -- 2.20.1