xref: /openbsd/sys/dev/usb/uhidev.h (revision 73471bf0)
1 /*	$OpenBSD: uhidev.h,v 1.40 2021/11/22 11:30:16 anton Exp $	*/
2 /*	$NetBSD: uhidev.h,v 1.3 2002/10/08 09:56:17 dan Exp $	*/
3 
4 /*
5  * Copyright (c) 2001 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 struct uhidev_softc {
35 	struct device sc_dev;		/* base device */
36 	struct usbd_device *sc_udev;
37 	struct usbd_interface *sc_iface;/* interface */
38 	int sc_ifaceno;			/* interface number */
39 	struct usbd_pipe *sc_ipipe;	/* input interrupt pipe */
40 	struct usbd_xfer *sc_ixfer;	/* read request */
41 	int sc_iep_addr;
42 
43 	u_char *sc_ibuf;
44 	u_int sc_isize;
45 
46 	struct usbd_pipe *sc_opipe;	/* output interrupt pipe */
47 	struct usbd_xfer *sc_oxfer;	/* write request */
48 	struct usbd_xfer *sc_owxfer;	/* internal write request */
49 	int sc_oep_addr;
50 
51 	void *sc_repdesc;
52 	int sc_repdesc_size;
53 
54 	u_int sc_nrepid;
55 	struct uhidev **sc_subdevs;
56 
57 	int sc_refcnt;
58 };
59 
60 struct uhidev {
61 	struct device sc_dev;		/* base device */
62 	struct usbd_device *sc_udev;	/* USB device */
63 	struct uhidev_softc *sc_parent;
64 	uByte sc_report_id;
65 	u_int8_t sc_state;
66 #define	UHIDEV_OPEN	0x01	/* device is open */
67 	void (*sc_intr)(struct uhidev *, void *, u_int);
68 
69 	int sc_isize;
70 	int sc_osize;
71 	int sc_fsize;
72 };
73 
74 struct uhidev_attach_arg {
75 	struct usb_attach_arg	*uaa;
76 	struct uhidev_softc	*parent;
77 	uint8_t			 reportid;
78 	u_int			 nreports;
79 	uint8_t			*claimed;
80 };
81 
82 #define UHIDEV_CLAIM_MULTIPLE_REPORTID(u)	((u)->claimed != NULL)
83 
84 int uhidev_report_type_conv(int);
85 void uhidev_get_report_desc(struct uhidev_softc *, void **, int *);
86 int uhidev_open(struct uhidev *);
87 void uhidev_close(struct uhidev *);
88 int uhidev_ioctl(struct uhidev *, u_long, caddr_t, int, struct proc *);
89 int uhidev_set_report(struct uhidev_softc *, int, int, void *, int);
90 int uhidev_set_report_async(struct uhidev_softc *, int, int, void *, int);
91 int uhidev_get_report(struct uhidev_softc *, int, int, void *, int);
92 int uhidev_get_report_async(struct uhidev_softc *, int, int, void *, int,
93     void *, void (*)(void *, int, void *, int));
94 usbd_status uhidev_write(struct uhidev_softc *, void *, int);
95 int uhidev_set_report_dev(struct uhidev_softc *, struct uhidev *, int);
96