Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Make USB HID processing into a library.



details:   https://anonhg.NetBSD.org/src/rev/6be0f00935e1
branches:  trunk
changeset: 472902:6be0f00935e1
user:      augustss <augustss%NetBSD.org@localhost>
date:      Tue May 11 21:02:24 1999 +0000

description:
Make USB HID processing into a library.

diffstat:

 distrib/sets/lists/comp/mi       |     6 +-
 distrib/sets/lists/comp/shl.elf  |     3 +-
 distrib/sets/lists/comp/shl.mi   |     3 +-
 lib/libusb/Makefile              |    15 +
 lib/libusb/data.c                |    59 ++
 lib/libusb/descr.c               |    66 ++
 lib/libusb/parse.c               |   361 ++++++++++++
 lib/libusb/shlib_version         |     5 +
 lib/libusb/usage.c               |   197 ++++++
 lib/libusb/usb.3                 |    60 ++
 lib/libusb/usb.h                 |    93 +++
 lib/libusb/usb_hid_usages        |  1072 ++++++++++++++++++++++++++++++++++++++
 lib/libusb/usbvar.h              |    36 +
 usr.bin/usbhidctl/Makefile       |    11 +-
 usr.bin/usbhidctl/hidsubr.c      |   524 ------------------
 usr.bin/usbhidctl/hidsubr.h      |    87 ---
 usr.bin/usbhidctl/usb_hid_usages |  1072 --------------------------------------
 usr.bin/usbhidctl/usbhid.c       |    70 +-
 18 files changed, 2001 insertions(+), 1739 deletions(-)

diffs (truncated from 3971 to 300 lines):

diff -r 484ef06dea72 -r 6be0f00935e1 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Tue May 11 20:46:58 1999 +0000
+++ b/distrib/sets/lists/comp/mi        Tue May 11 21:02:24 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.140 1999/05/11 20:20:02 veego Exp $
+# $NetBSD: mi,v 1.141 1999/05/11 21:02:25 augustss Exp $
 ./sys
 ./usr/bin/ar
 ./usr/bin/as
@@ -1019,6 +1019,8 @@
 ./usr/lib/libtermcap_p.a
 ./usr/lib/libtermlib.a
 ./usr/lib/libtermlib_p.a
+./usr/lib/libusb.a
+./usr/lib/libusb_p.a
 ./usr/lib/libutil.a
 ./usr/lib/libutil_p.a
 ./usr/lib/libwrap.a
@@ -2113,6 +2115,7 @@
 ./usr/share/man/cat3/ungetc.0
 ./usr/share/man/cat3/unsetenv.0
 ./usr/share/man/cat3/unvis.0
+./usr/share/man/cat3/usb.0
 ./usr/share/man/cat3/user_from_uid.0
 ./usr/share/man/cat3/usleep.0
 ./usr/share/man/cat3/utime.0
@@ -3167,6 +3170,7 @@
 ./usr/share/man/man3/ungetc.3
 ./usr/share/man/man3/unsetenv.3
 ./usr/share/man/man3/unvis.3
+./usr/share/man/man3/usb.3
 ./usr/share/man/man3/user_from_uid.3
 ./usr/share/man/man3/usleep.3
 ./usr/share/man/man3/utime.3
diff -r 484ef06dea72 -r 6be0f00935e1 distrib/sets/lists/comp/shl.elf
--- a/distrib/sets/lists/comp/shl.elf   Tue May 11 20:46:58 1999 +0000
+++ b/distrib/sets/lists/comp/shl.elf   Tue May 11 21:02:24 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.elf,v 1.9 1999/04/19 03:11:34 simonb Exp $
+# $NetBSD: shl.elf,v 1.10 1999/05/11 21:02:26 augustss Exp $
 ./usr/lib/crtbegin.o
 ./usr/lib/crtbeginS.o
 ./usr/lib/crtend.o
@@ -23,6 +23,7 @@
 ./usr/lib/libtelnet.so
 ./usr/lib/libtermcap.so
 ./usr/lib/libtermlib.so
+./usr/lib/libusb.so
 ./usr/lib/libutil.so
 ./usr/lib/libwrap.so
 ./usr/lib/libz.so
diff -r 484ef06dea72 -r 6be0f00935e1 distrib/sets/lists/comp/shl.mi
--- a/distrib/sets/lists/comp/shl.mi    Tue May 11 20:46:58 1999 +0000
+++ b/distrib/sets/lists/comp/shl.mi    Tue May 11 21:02:24 1999 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.7 1999/04/19 03:11:34 simonb Exp $
+# $NetBSD: shl.mi,v 1.8 1999/05/11 21:02:26 augustss Exp $
 ./usr/lib/libbz2_pic.a
 ./usr/lib/libc_pic.a
 ./usr/lib/libcrypt_pic.a
@@ -19,6 +19,7 @@
 ./usr/lib/libtelnet_pic.a
 ./usr/lib/libtermcap_pic.a
 ./usr/lib/libtermlib_pic.a
+./usr/lib/libusb_pic.a
 ./usr/lib/libutil_pic.a
 ./usr/lib/libwrap_pic.a
 ./usr/lib/libz_pic.a
diff -r 484ef06dea72 -r 6be0f00935e1 lib/libusb/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libusb/Makefile       Tue May 11 21:02:24 1999 +0000
@@ -0,0 +1,15 @@
+#      $NetBSD: Makefile,v 1.1 1999/05/11 21:02:24 augustss Exp $
+
+LIB=   usb
+MAN=   usb.3
+
+SRCS=  descr.c parse.c usage.c data.c
+
+INCS=  usb.h
+INCSDIR=/usr/include
+
+FILES=  usb_hid_usages
+FILESDIR=/usr/share/misc
+
+.include <bsd.lib.mk>
+
diff -r 484ef06dea72 -r 6be0f00935e1 lib/libusb/data.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libusb/data.c Tue May 11 21:02:24 1999 +0000
@@ -0,0 +1,59 @@
+/*     $NetBSD: data.c,v 1.1 1999/05/11 21:02:24 augustss Exp $        */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (augustss%netbsd.org@localhost).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include "usb.h"
+
+unsigned int
+getdata(void *p, hid_item_t *h)
+{
+       unsigned char *buf = p;
+       unsigned int hpos = h->pos;     /* bit position of data */
+       unsigned int hsize = h->report_size; /* bit length of data */
+       unsigned int data;
+       int i, end, offs;
+
+       if (hsize == 0)
+               return (0);
+       offs = hpos / 8;
+       end = (hpos + hsize) / 8 - offs;
+       data = 0;
+       for (i = 0; i <= end; i++)
+               data |= buf[offs + i] << (i*8);
+       data >>= hpos % 8;
+       data &= (1 << hsize) - 1;
+       if (h->logical_minimum < 0) {
+               /* Need to sign extend */
+               hsize = sizeof data * 8 - hsize;
+               data = ((int)data << hsize) >> hsize;
+       }
+       return (data);
+}
diff -r 484ef06dea72 -r 6be0f00935e1 lib/libusb/descr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libusb/descr.c        Tue May 11 21:02:24 1999 +0000
@@ -0,0 +1,66 @@
+/*     $NetBSD: descr.c,v 1.1 1999/05/11 21:02:24 augustss Exp $       */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (augustss%netbsd.org@localhost).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <dev/usb/usb.h>
+
+#include "usb.h"
+#include "usbvar.h"
+
+report_desc_t 
+get_report_desc(fd)
+       int fd;
+{
+       struct usb_ctl_report_desc rep;
+       report_desc_t r;
+
+       rep.size = 0;
+       if (ioctl(fd, USB_GET_REPORT_DESC, &rep) < 0)
+               return (0);
+       r = malloc(sizeof *r + rep.size);
+       if (r == 0) {
+               errno = ENOMEM;
+               return (0);
+       }
+       r->size = rep.size;
+       memcpy(r->data, rep.data, (unsigned int)rep.size);
+       return (r);
+}
+
+void dispose_report_desc(r)
+       report_desc_t r;
+{
+       free(r);
+}
diff -r 484ef06dea72 -r 6be0f00935e1 lib/libusb/parse.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libusb/parse.c        Tue May 11 21:02:24 1999 +0000
@@ -0,0 +1,361 @@
+/*     $NetBSD: parse.c,v 1.1 1999/05/11 21:02:24 augustss Exp $       */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (augustss%netbsd.org@localhost).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+
+#include "usb.h"
+#include "usbvar.h"
+
+#define MAXUSAGE 100
+struct hid_data {
+       u_char *start;
+       u_char *end;
+       u_char *p;
+       hid_item_t cur;
+       unsigned int usages[MAXUSAGE];
+       int nusage;
+       int minset;
+       int multi;
+       int multimax;
+       int kindset;
+};
+
+static int min(int x, int y) { return x < y ? x : y; }
+
+static void
+hid_clear_local(hid_item_t *c)
+{
+       c->usage = 0;
+       c->usage_minimum = 0;
+       c->usage_maximum = 0;
+       c->designator_index = 0;
+       c->designator_minimum = 0;
+       c->designator_maximum = 0;
+       c->string_index = 0;
+       c->string_minimum = 0;
+       c->string_maximum = 0;
+       c->set_delimiter = 0;
+}
+
+hid_data_t
+hid_start_parse(report_desc_t d, int kindset)
+{
+       struct hid_data *s;
+



Home | Main Index | Thread Index | Old Index