Hi, This is a diff to propose a new device type for USB gamecontrollers, 'ujoy'.
Rationale --------- Since the tightening of security around USB devices, USB gamecontrollers that generally attach to the kitchen-sink uhid device don't work out of the box anymore since read permissions are absent. As a consequence, USB gamecontrollers don't work out of the box anymore; requiring a root user to find what uhid device the controller is attached to and chmod +r that one. This poses a barrier to using those devices, as well as in my opinion a security risk by enticing users to indiscriminately do '# chmod +r /dev/uhid*' in order to not have to re-apply permissions on different uhid devices multiple times. The proposed solution is inspired by the implementation of fido(4) [1]; a similarly narrow use case for a certain type of USB devices. It creates a device for gamecontrollers that has the minimum required permissions, but won't require chmod(1)'ing device files to get the controller working. Implementation in this Diff --------------------------- This diff is largely based on reyk's commit for the fido(4) device from December 2019 [1]. It creates a ujoy device and attaches USB devices identified as HUG_JOYSTICK or HUG_GAME_PAD. ujoyopen() is set up such that it only allows read-only access. If it is opened with write permissions, it should error with EPERM. Only a subset of ioctls is allowed in ujoyioctl(), based on what I could find that is used in devel/sdl2 (USB_GET_DEVICEINFO,USB_GET_REPORT, USB_GET_REPORT_DESC,USB_GET_REPORT_ID), as well as FIONBIO and FIOASYNC. This contains conf.c and MAKEDEV.md bits for the same architectures as fido(4). A small man page, as well as updates to other pertinent man pages (usb(4), uhidev(4)) are included, again following the example of the commits for the fido(4) device. Credit to brynet@ who helped me extensively with this diff. Testing ------- A simple way to test this without needing to do a full release is building a kernel with the diff and booting into it, then creating the updated MAKEDEV script with: $ cd /usr/src/etc/etc.amd64/ $ make # this will create MAKEDEV in etc.amd64 $ cd /dev # sh /usr/src/etc/etc.amd64/MAKEDEV ujoy This creates 2 device ujoy/0 and ujoy/1 by default. The device is read-only by default (444). Plug in your USB gamecontroller and check in dmesg that it attaches as ujoy, not uhid. The simplest way to test is with usbhidctl(1): $ usbhidctl -f /dev/ujoy/0 -l This will loop through printing the state of buttons, sticks etc. until exited with Crtl-C. Another way to test is with games/sdl-jstest. As the SDL backends use /dev/uhid* to find gamecontrollers, the way I tested this is by repurposing /dev/uhid0 with mknod(8) (note major 100 is for amd64): $ cd /dev # rm uhid0 # mknod -m 444 uhid0 c 100 0 I put the diff through a release(8) without xenocara on amd64, and it built base without problems and /dev/MAKEDEV and the /dev/ujoy directory all look correct. I have tested usbhidctl and sdl-jstest with an XBox 360 gamepad and the Logitech F310 gamepad, the latter both in DInput and XInput mode. All of those work as expected. Issues/Follow-up Tasks ---------------------- As ujoy devices don't attach to /dev/uhid* anymore, ports that use gamecontrollers will need to be patched. This seems to be mostly (if not exclusively) sdl/sdl2-based ports, so I anticipate that patching these 2 ports will take care of the bulk of the use cases. On other OS's, writing to gamecontrollers is used at times for the "rumble" functionality of the controller, or setting LEDs (like the circle LED on XBox 360 controllers that can reflect what player number the gamepad is for). Those have to my knowledge never worked on OpenBSD and are not of any immediate interest as far as I can tell. ok? comments? [1] https://marc.info/?l=openbsd-cvs&m=157658815523208&q=mbox Index: etc/MAKEDEV.common =================================================================== RCS file: /cvs/src/etc/MAKEDEV.common,v retrieving revision 1.111 diff -u -p -r1.111 MAKEDEV.common --- etc/MAKEDEV.common 6 Jul 2020 06:11:26 -0000 1.111 +++ etc/MAKEDEV.common 28 Dec 2020 03:25:04 -0000 @@ -181,6 +181,7 @@ dnl target(usb, usb, 0, 1, 2, 3, 4, 5, 6, 7)dnl target(usb, uhid, 0, 1, 2, 3, 4, 5, 6, 7)dnl twrget(usb, fido, fido)dnl +twrget(usb, ujoy, ujoy)dnl target(usb, ulpt, 0, 1)dnl target(usb, ugen, 0, 1, 2, 3, 4, 5, 6, 7)dnl target(usb, ttyU, 0, 1, 2, 3)dnl @@ -365,6 +366,10 @@ __devitem(fido, fido, fido/* nodes, fido _mkdev(fido, fido, {-RMlist[${#RMlist[*]}]=";mkdir -p fido;rm -f" n=0 while [ $n -lt 4 ];do M fido/$n c major_fido_c $n 666;n=Add($n, 1);done MKlist[${#MKlist[*]}]=";chmod 555 fido"-})dnl +__devitem(ujoy, ujoy, ujoy/* nodes, ujoy)dnl +_mkdev(ujoy, ujoy, {-RMlist[${#RMlist[*]}]=";mkdir -p ujoy;rm -f" n=0 + while [ $n -lt 2 ];do M ujoy/$n c major_ujoy_c $n 444;n=Add($n, 1);done + MKlist[${#MKlist[*]}]=";chmod 555 ujoy"-})dnl __devitem(ulpt, ulpt*, Printer devices)dnl _mcdev({-ulpt-}, ulpt*, {-ulpt-}, {-major_ulpt_c-}, 600)dnl __devitem(ttyU, ttyU*, USB serial ports,ucom)dnl Index: etc/etc.alpha/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.alpha/MAKEDEV.md,v retrieving revision 1.76 diff -u -p -r1.76 MAKEDEV.md --- etc/etc.alpha/MAKEDEV.md 6 Jul 2020 06:11:26 -0000 1.76 +++ etc/etc.alpha/MAKEDEV.md 28 Dec 2020 03:25:04 -0000 @@ -56,6 +56,7 @@ _DEV(uall) _DEV(ugen, 48) _DEV(uhid, 46) _DEV(fido, 70) +_DEV(ujoy, 72) _DEV(ulpt, 47) _DEV(usb, 45) _TITLE(spec) Index: etc/etc.amd64/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.amd64/MAKEDEV.md,v retrieving revision 1.76 diff -u -p -r1.76 MAKEDEV.md --- etc/etc.amd64/MAKEDEV.md 6 Jul 2020 06:11:26 -0000 1.76 +++ etc/etc.amd64/MAKEDEV.md 28 Dec 2020 03:25:04 -0000 @@ -60,6 +60,7 @@ _DEV(uall) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 98) +_DEV(ujoy, 100) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.arm64/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.arm64/MAKEDEV.md,v retrieving revision 1.10 diff -u -p -r1.10 MAKEDEV.md --- etc/etc.arm64/MAKEDEV.md 6 Jul 2020 06:11:26 -0000 1.10 +++ etc/etc.arm64/MAKEDEV.md 28 Dec 2020 03:25:04 -0000 @@ -52,6 +52,7 @@ _DEV(uall) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 98) +_DEV(ujoy, 100) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.armv7/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.armv7/MAKEDEV.md,v retrieving revision 1.18 diff -u -p -r1.18 MAKEDEV.md --- etc/etc.armv7/MAKEDEV.md 6 Jul 2020 06:11:26 -0000 1.18 +++ etc/etc.armv7/MAKEDEV.md 28 Dec 2020 03:25:04 -0000 @@ -61,6 +61,7 @@ _DEV(uall) _DEV(ugen, 70) _DEV(uhid, 65) _DEV(fido, 106) +_DEV(ujoy, 108) _DEV(ulpt, 66) _DEV(usb, 64) _TITLE(spec) Index: etc/etc.hppa/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.hppa/MAKEDEV.md,v retrieving revision 1.65 diff -u -p -r1.65 MAKEDEV.md --- etc/etc.hppa/MAKEDEV.md 6 Jul 2020 06:11:26 -0000 1.65 +++ etc/etc.hppa/MAKEDEV.md 28 Dec 2020 03:25:04 -0000 @@ -54,6 +54,7 @@ _DEV(uall) _DEV(usb, 40) _DEV(uhid, 41) _DEV(fido, 61) +_DEV(ujoy, 63) _DEV(ugen, 42) _DEV(ulpt, 43) _DEV(ttyU, 45) Index: etc/etc.i386/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.i386/MAKEDEV.md,v retrieving revision 1.91 diff -u -p -r1.91 MAKEDEV.md --- etc/etc.i386/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.91 +++ etc/etc.i386/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -61,6 +61,7 @@ _DEV(uall) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 98) +_DEV(ujoy, 100) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.landisk/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.landisk/MAKEDEV.md,v retrieving revision 1.48 diff -u -p -r1.48 MAKEDEV.md --- etc/etc.landisk/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.48 +++ etc/etc.landisk/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -65,6 +65,7 @@ _DEV(uall) _DEV(ugen, 70) _DEV(uhid, 65) _DEV(fido, 106) +_DEV(ujoy, 108) _DEV(ulpt, 66) _DEV(usb, 64) _TITLE(spec) Index: etc/etc.loongson/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.loongson/MAKEDEV.md,v retrieving revision 1.32 diff -u -p -r1.32 MAKEDEV.md --- etc/etc.loongson/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.32 +++ etc/etc.loongson/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -60,6 +60,7 @@ _DEV(uall) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 88) +_DEV(ujoy, 90) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.macppc/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.macppc/MAKEDEV.md,v retrieving revision 1.75 diff -u -p -r1.75 MAKEDEV.md --- etc/etc.macppc/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.75 +++ etc/etc.macppc/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -70,6 +70,7 @@ _DEV(ttyU, 66) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 90) +_DEV(ujoy, 92) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.octeon/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.octeon/MAKEDEV.md,v retrieving revision 1.19 diff -u -p -r1.19 MAKEDEV.md --- etc/etc.octeon/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.19 +++ etc/etc.octeon/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -67,6 +67,7 @@ _DEV(uall) _DEV(usb, 61) _DEV(uhid, 62) _DEV(fido, 76) +_DEV(ujoy, 78) _TITLE(spec) _DEV(au, 44) _DEV(bio, 49) Index: etc/etc.powerpc64/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.powerpc64/MAKEDEV.md,v retrieving revision 1.6 diff -u -p -r1.6 MAKEDEV.md --- etc/etc.powerpc64/MAKEDEV.md 24 Oct 2020 21:10:41 -0000 1.6 +++ etc/etc.powerpc64/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -52,6 +52,7 @@ _DEV(uall) _DEV(ugen, 49) _DEV(uhid, 50) _DEV(fido, 51) +_DEV(ujoy, 94) _DEV(ulpt, 65) _DEV(usb, 48) _TITLE(spec) Index: etc/etc.sgi/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.sgi/MAKEDEV.md,v retrieving revision 1.54 diff -u -p -r1.54 MAKEDEV.md --- etc/etc.sgi/MAKEDEV.md 6 Jul 2020 06:11:27 -0000 1.54 +++ etc/etc.sgi/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -69,6 +69,7 @@ _DEV(uall) _DEV(ugen, 63) _DEV(uhid, 62) _DEV(fido, 76) +_DEV(ujoy, 78) _DEV(ulpt, 64) _DEV(usb, 61) _TITLE(spec) Index: etc/etc.sparc64/MAKEDEV.md =================================================================== RCS file: /cvs/src/etc/etc.sparc64/MAKEDEV.md,v retrieving revision 1.95 diff -u -p -r1.95 MAKEDEV.md --- etc/etc.sparc64/MAKEDEV.md 22 Jul 2020 14:04:37 -0000 1.95 +++ etc/etc.sparc64/MAKEDEV.md 28 Dec 2020 03:25:05 -0000 @@ -104,6 +104,7 @@ _DEV(uall) _DEV(ugen, 92) _DEV(uhid, 91) _DEV(fido, 137) +_DEV(ujoy, 139) _DEV(ulpt, 93) _DEV(usb, 90) _TITLE(spec) Index: share/man/man4/Makefile =================================================================== RCS file: /cvs/src/share/man/man4/Makefile,v retrieving revision 1.790 diff -u -p -r1.790 Makefile --- share/man/man4/Makefile 6 Dec 2020 20:48:12 -0000 1.790 +++ share/man/man4/Makefile 28 Dec 2020 03:25:31 -0000 @@ -84,7 +84,7 @@ MAN= aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 ubsec.4 ucom.4 uchcom.4 ucrcom.4 ucycom.4 ukspan.4 uslhcom.4 \ udav.4 udcf.4 udl.4 udp.4 udsbr.4 \ uftdi.4 ugen.4 ugl.4 ugold.4 uguru.4 uhci.4 uhid.4 uhidev.4 uipaq.4 \ - uk.4 ukbd.4 \ + ujoy.4 uk.4 ukbd.4 \ ukphy.4 ulpt.4 umass.4 umb.4 umbg.4 umcs.4 umct.4 umidi.4 umodem.4 \ ums.4 umsm.4 umstc.4 umt.4 unix.4 uonerng.4 uow.4 uoaklux.4 uoakrh.4 \ uoakv.4 upd.4 upgt.4 upl.4 uplcom.4 ural.4 ure.4 url.4 urlphy.4 \ Index: share/man/man4/uhidev.4 =================================================================== RCS file: /cvs/src/share/man/man4/uhidev.4,v retrieving revision 1.12 diff -u -p -r1.12 uhidev.4 --- share/man/man4/uhidev.4 21 Aug 2020 19:02:46 -0000 1.12 +++ share/man/man4/uhidev.4 28 Dec 2020 03:25:31 -0000 @@ -40,6 +40,7 @@ .Cd "ucycom* at uhidev?" .Cd "ugold* at uhidev?" .Cd "uhid* at uhidev?" +.Cd "ujoy* at uhidev?" .Cd "ukbd* at uhidev?" .Cd "ums* at uhidev?" .Cd "umstc* at uhidev?" @@ -73,6 +74,7 @@ only dispatches data to them based on th .Xr ucycom 4 , .Xr ugold 4 , .Xr uhid 4 , +.Xr ujoy 4 , .Xr ukbd 4 , .Xr ums 4 , .Xr umstc 4 , Index: share/man/man4/ujoy.4 =================================================================== RCS file: share/man/man4/ujoy.4 diff -N share/man/man4/ujoy.4 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ share/man/man4/ujoy.4 28 Dec 2020 03:25:31 -0000 @@ -0,0 +1,53 @@ +.\" $OpenBSD: ujoy.4,v 1.4 2020/08/21 19:02:46 mglocker Exp $ +.\" +.\" Copyright (c) 2020 Thomas Frohwein <t...@openbsd.org> +.\" Copyright (c) 2020 Bryan Steele <bry...@openbsd.org> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: December 27 2020 $ +.Dt UJOY 4 +.Os +.Sh NAME +.Nm ujoy +.Nd USB joystick/gamecontroller +.Sh SYNOPSIS +.Cd "ujoy* at uhidev?" +.Sh DESCRIPTION +The +.Nm +driver provides support for USB joysticks and other gamecontrollers. +They are Human Interface Devices (HID) which can be accessed via the +.Pa /dev/ujoy/N +interface. +.Pp +The driver is compatible with the +.Xr read 2 , +and a subset of +.Xr ioctl 2 +operations of the generic +.Xr uhid 4 +device. +.Sh FILES +.Bl -tag -width /dev/ujoy/* -compact +.It Pa /dev/ujoy/* +.El +.Sh SEE ALSO +.Xr uhid 4 , +.Xr uhidev 4 , +.Xr usb 4 +.Sh HISTORY +The +.Nm +driver first appeared in +.Ox 6.9 . Index: share/man/man4/usb.4 =================================================================== RCS file: /cvs/src/share/man/man4/usb.4,v retrieving revision 1.203 diff -u -p -r1.203 usb.4 --- share/man/man4/usb.4 21 Aug 2020 20:38:56 -0000 1.203 +++ share/man/man4/usb.4 28 Dec 2020 03:25:31 -0000 @@ -255,6 +255,8 @@ TEMPer gold HID thermometer and hygromet Generic driver for Human Interface Devices .It Xr uhidev 4 Base driver for all Human Interface Devices +.It Xr ujoy 4 +USB joysticks/gamecontrollers .It Xr ukbd 4 USB keyboards that follow the boot protocol .It Xr ums 4 Index: sys/arch/alpha/alpha/conf.c =================================================================== RCS file: /cvs/src/sys/arch/alpha/alpha/conf.c,v retrieving revision 1.88 diff -u -p -r1.88 conf.c --- sys/arch/alpha/alpha/conf.c 6 Jul 2020 04:32:25 -0000 1.88 +++ sys/arch/alpha/alpha/conf.c 28 Dec 2020 03:25:31 -0000 @@ -113,6 +113,7 @@ cdev_decl(cy); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -207,6 +208,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 69: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 70: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 71: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 72: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/alpha/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/alpha/conf/GENERIC,v retrieving revision 1.266 diff -u -p -r1.266 GENERIC --- sys/arch/alpha/conf/GENERIC 23 May 2020 06:28:29 -0000 1.266 +++ sys/arch/alpha/conf/GENERIC 28 Dec 2020 03:25:31 -0000 @@ -107,6 +107,7 @@ uslhcom* at uhidev? # Silicon Labs CP2 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet #atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/amd64/amd64/conf.c =================================================================== RCS file: /cvs/src/sys/arch/amd64/amd64/conf.c,v retrieving revision 1.72 diff -u -p -r1.72 conf.c --- sys/arch/amd64/amd64/conf.c 7 Oct 2020 13:37:33 -0000 1.72 +++ sys/arch/amd64/amd64/conf.c 28 Dec 2020 03:25:31 -0000 @@ -139,6 +139,7 @@ cdev_decl(cy); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -288,6 +289,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 97: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 98: FIDO/U2F security keys */ cdev_pppx_init(NPPPX,pppac), /* 99: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 100: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/amd64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v retrieving revision 1.495 diff -u -p -r1.495 GENERIC --- sys/arch/amd64/conf/GENERIC 15 Nov 2020 16:47:12 -0000 1.495 +++ sys/arch/amd64/conf/GENERIC 28 Dec 2020 03:25:31 -0000 @@ -286,6 +286,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors umstc* at uhidev? # Microsoft Surface Type Cover aue* at uhub? # ADMtek AN986 Pegasus Ethernet Index: sys/arch/arm/arm/conf.c =================================================================== RCS file: /cvs/src/sys/arch/arm/arm/conf.c,v retrieving revision 1.55 diff -u -p -r1.55 conf.c --- sys/arch/arm/arm/conf.c 6 Jul 2020 04:32:25 -0000 1.55 +++ sys/arch/arm/arm/conf.c 28 Dec 2020 03:25:31 -0000 @@ -126,6 +126,7 @@ cdev_decl(pci); #include "ugen.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ulpt.h" /* @@ -383,6 +384,7 @@ struct cdevsw cdevsw[] = { cdev_switch_init(NSWITCH,switch), /* 105: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 106: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 107: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 108: USB joystick/gamecontroller */ }; int nblkdev = nitems(bdevsw); Index: sys/arch/arm64/arm64/conf.c =================================================================== RCS file: /cvs/src/sys/arch/arm64/arm64/conf.c,v retrieving revision 1.16 diff -u -p -r1.16 conf.c --- sys/arch/arm64/arm64/conf.c 7 Oct 2020 13:37:32 -0000 1.16 +++ sys/arch/arm64/arm64/conf.c 28 Dec 2020 03:25:31 -0000 @@ -110,6 +110,7 @@ cdev_decl(spkr); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -248,6 +249,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 97: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 98: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 99: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 100: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/arm64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/arm64/conf/GENERIC,v retrieving revision 1.182 diff -u -p -r1.182 GENERIC --- sys/arch/arm64/conf/GENERIC 18 Dec 2020 18:24:44 -0000 1.182 +++ sys/arch/arm64/conf/GENERIC 28 Dec 2020 03:25:31 -0000 @@ -368,6 +368,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/armv7/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/armv7/conf/GENERIC,v retrieving revision 1.132 diff -u -p -r1.132 GENERIC --- sys/arch/armv7/conf/GENERIC 23 Jun 2020 13:57:05 -0000 1.132 +++ sys/arch/armv7/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -321,6 +321,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/hppa/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/hppa/conf/GENERIC,v retrieving revision 1.180 diff -u -p -r1.180 GENERIC --- sys/arch/hppa/conf/GENERIC 17 Dec 2019 13:08:55 -0000 1.180 +++ sys/arch/hppa/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -111,6 +111,7 @@ ukbd* at uhidev? # USB keyboard wskbd* at ukbd? mux 1 uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet url* at uhub? # Realtek RTL8150L based adapters Index: sys/arch/hppa/hppa/conf.c =================================================================== RCS file: /cvs/src/sys/arch/hppa/hppa/conf.c,v retrieving revision 1.70 diff -u -p -r1.70 conf.c --- sys/arch/hppa/hppa/conf.c 6 Jul 2020 04:32:25 -0000 1.70 +++ sys/arch/hppa/hppa/conf.c 28 Dec 2020 03:25:32 -0000 @@ -114,6 +114,7 @@ cdev_decl(pci); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -191,6 +192,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 60: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 61: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 62: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 63: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/i386/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/i386/conf/GENERIC,v retrieving revision 1.853 diff -u -p -r1.853 GENERIC --- sys/arch/i386/conf/GENERIC 12 Sep 2020 15:01:05 -0000 1.853 +++ sys/arch/i386/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -284,6 +284,7 @@ uticom* at uhub? # TI serial ucom* at uticom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/i386/i386/conf.c =================================================================== RCS file: /cvs/src/sys/arch/i386/i386/conf.c,v retrieving revision 1.170 diff -u -p -r1.170 conf.c --- sys/arch/i386/i386/conf.c 6 Jul 2020 04:32:25 -0000 1.170 +++ sys/arch/i386/i386/conf.c 28 Dec 2020 03:25:32 -0000 @@ -140,6 +140,7 @@ cdev_decl(cy); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -288,6 +289,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 97: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 98: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 99: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 100: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/landisk/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/landisk/conf/GENERIC,v retrieving revision 1.55 diff -u -p -r1.55 GENERIC --- sys/arch/landisk/conf/GENERIC 17 Dec 2019 13:08:55 -0000 1.55 +++ sys/arch/landisk/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -137,6 +137,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/landisk/landisk/conf.c =================================================================== RCS file: /cvs/src/sys/arch/landisk/landisk/conf.c,v retrieving revision 1.42 diff -u -p -r1.42 conf.c --- sys/arch/landisk/landisk/conf.c 6 Jul 2020 04:32:25 -0000 1.42 +++ sys/arch/landisk/landisk/conf.c 28 Dec 2020 03:25:32 -0000 @@ -116,6 +116,7 @@ cdev_decl(pci); #include "ugen.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ulpt.h" /* @@ -357,6 +358,7 @@ struct cdevsw cdevsw[] = { cdev_switch_init(NSWITCH,switch), /* 105: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 106: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 107: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 108: USB joystick/gamecontroller */ }; int nblkdev = nitems(bdevsw); Index: sys/arch/loongson/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/loongson/conf/GENERIC,v retrieving revision 1.62 diff -u -p -r1.62 GENERIC --- sys/arch/loongson/conf/GENERIC 30 Sep 2020 22:23:41 -0000 1.62 +++ sys/arch/loongson/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -164,6 +164,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors atu* at uhub? # Atmel AT76c50x based 802.11b aue* at uhub? # ADMtek AN986 Pegasus Ethernet Index: sys/arch/loongson/loongson/conf.c =================================================================== RCS file: /cvs/src/sys/arch/loongson/loongson/conf.c,v retrieving revision 1.29 diff -u -p -r1.29 conf.c --- sys/arch/loongson/loongson/conf.c 6 Jul 2020 04:32:25 -0000 1.29 +++ sys/arch/loongson/loongson/conf.c 28 Dec 2020 03:25:32 -0000 @@ -123,6 +123,7 @@ cdev_decl(pci); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -228,6 +229,7 @@ struct cdevsw cdevsw[] = cdev_drm_init(NDRM,drm), /* 87: drm */ cdev_fido_init(NFIDO,fido), /* 88: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 89: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 90: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/macppc/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/macppc/conf/GENERIC,v retrieving revision 1.271 diff -u -p -r1.271 GENERIC --- sys/arch/macppc/conf/GENERIC 24 Jan 2020 04:44:14 -0000 1.271 +++ sys/arch/macppc/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -260,6 +260,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/macppc/macppc/conf.c =================================================================== RCS file: /cvs/src/sys/arch/macppc/macppc/conf.c,v retrieving revision 1.72 diff -u -p -r1.72 conf.c --- sys/arch/macppc/macppc/conf.c 6 Jul 2020 04:32:25 -0000 1.72 +++ sys/arch/macppc/macppc/conf.c 28 Dec 2020 03:25:32 -0000 @@ -98,6 +98,7 @@ cdev_decl(com); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -231,6 +232,7 @@ struct cdevsw cdevsw[] = { cdev_switch_init(NSWITCH,switch), /* 89: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 90: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 91: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 92: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/octeon/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/octeon/conf/GENERIC,v retrieving revision 1.56 diff -u -p -r1.56 GENERIC --- sys/arch/octeon/conf/GENERIC 25 Oct 2020 10:33:31 -0000 1.56 +++ sys/arch/octeon/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -156,6 +156,7 @@ uslhcom* at uhidev? # Silicon Labs CP211 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/octeon/octeon/conf.c =================================================================== RCS file: /cvs/src/sys/arch/octeon/octeon/conf.c,v retrieving revision 1.25 diff -u -p -r1.25 conf.c --- sys/arch/octeon/octeon/conf.c 6 Jul 2020 04:32:25 -0000 1.25 +++ sys/arch/octeon/octeon/conf.c 28 Dec 2020 03:25:32 -0000 @@ -136,6 +136,7 @@ cdev_decl(pci); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -235,6 +236,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 75: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 76: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 77: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 78: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/powerpc64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/powerpc64/conf/GENERIC,v retrieving revision 1.22 diff -u -p -r1.22 GENERIC --- sys/arch/powerpc64/conf/GENERIC 16 Nov 2020 19:04:57 -0000 1.22 +++ sys/arch/powerpc64/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -126,6 +126,7 @@ uslhcom* at uhidev? # Silicon Labs CP21 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors umstc* at uhidev? # Microsoft Surface Type Cover aue* at uhub? # ADMtek AN986 Pegasus Ethernet Index: sys/arch/powerpc64/powerpc64/conf.c =================================================================== RCS file: /cvs/src/sys/arch/powerpc64/powerpc64/conf.c,v retrieving revision 1.10 diff -u -p -r1.10 conf.c --- sys/arch/powerpc64/powerpc64/conf.c 24 Oct 2020 21:06:56 -0000 1.10 +++ sys/arch/powerpc64/powerpc64/conf.c 28 Dec 2020 03:25:32 -0000 @@ -64,6 +64,7 @@ cdev_decl(com); #include "drm.h" #include "dt.h" #include "fido.h" +#include "ujoy.h" #include "fuse.h" #include "hotplug.h" #include "ipmi.h" @@ -203,6 +204,7 @@ struct cdevsw cdevsw[] = #else cdev_notdef(), /* 93 */ #endif + cdev_ujoy_init(NUJOY,ujoy), /* 94: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/sgi/conf/GENERIC-IP27 =================================================================== RCS file: /cvs/src/sys/arch/sgi/conf/GENERIC-IP27,v retrieving revision 1.66 diff -u -p -r1.66 GENERIC-IP27 --- sys/arch/sgi/conf/GENERIC-IP27 17 Dec 2019 13:08:56 -0000 1.66 +++ sys/arch/sgi/conf/GENERIC-IP27 28 Dec 2020 03:25:32 -0000 @@ -128,6 +128,7 @@ uslhcom* at uhidev? # Silicon Labs CP211 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support atu* at uhub? # Atmel AT76c50x based 802.11b aue* at uhub? # ADMtek AN986 Pegasus Ethernet axe* at uhub? # ASIX Electronics AX88172 USB Ethernet Index: sys/arch/sgi/conf/GENERIC-IP30 =================================================================== RCS file: /cvs/src/sys/arch/sgi/conf/GENERIC-IP30,v retrieving revision 1.59 diff -u -p -r1.59 GENERIC-IP30 --- sys/arch/sgi/conf/GENERIC-IP30 17 Dec 2019 13:08:56 -0000 1.59 +++ sys/arch/sgi/conf/GENERIC-IP30 28 Dec 2020 03:25:32 -0000 @@ -119,6 +119,7 @@ uslhcom* at uhidev? # Silicon Labs CP211 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support atu* at uhub? # Atmel AT76c50x based 802.11b aue* at uhub? # ADMtek AN986 Pegasus Ethernet axe* at uhub? # ASIX Electronics AX88172 USB Ethernet Index: sys/arch/sgi/conf/GENERIC-IP32 =================================================================== RCS file: /cvs/src/sys/arch/sgi/conf/GENERIC-IP32,v retrieving revision 1.50 diff -u -p -r1.50 GENERIC-IP32 --- sys/arch/sgi/conf/GENERIC-IP32 17 Dec 2019 13:08:56 -0000 1.50 +++ sys/arch/sgi/conf/GENERIC-IP32 28 Dec 2020 03:25:32 -0000 @@ -111,6 +111,7 @@ uslhcom* at uhidev? # Silicon Labs CP211 ucom* at uslhcom? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support atu* at uhub? # Atmel AT76c50x based 802.11b aue* at uhub? # ADMtek AN986 Pegasus Ethernet axe* at uhub? # ASIX Electronics AX88172 USB Ethernet Index: sys/arch/sgi/sgi/conf.c =================================================================== RCS file: /cvs/src/sys/arch/sgi/sgi/conf.c,v retrieving revision 1.43 diff -u -p -r1.43 conf.c --- sys/arch/sgi/sgi/conf.c 6 Jul 2020 04:32:25 -0000 1.43 +++ sys/arch/sgi/sgi/conf.c 28 Dec 2020 03:25:32 -0000 @@ -122,6 +122,7 @@ cdev_decl(pci); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -215,6 +216,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 75: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 76: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 77: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 78: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/arch/sparc64/conf/GENERIC =================================================================== RCS file: /cvs/src/sys/arch/sparc64/conf/GENERIC,v retrieving revision 1.314 diff -u -p -r1.314 GENERIC --- sys/arch/sparc64/conf/GENERIC 17 Dec 2019 13:08:56 -0000 1.314 +++ sys/arch/sparc64/conf/GENERIC 28 Dec 2020 03:25:32 -0000 @@ -224,6 +224,7 @@ umsm* at uhub? # Qualcomm MSM EVDO ucom* at umsm? uhid* at uhidev? # USB generic HID support fido* at uhidev? # FIDO/U2F security key support +ujoy* at uhidev? # USB joystick/gamecontroller support upd* at uhidev? # USB Power Devices sensors aue* at uhub? # ADMtek AN986 Pegasus Ethernet atu* at uhub? # Atmel AT76c50x based 802.11b Index: sys/arch/sparc64/sparc64/conf.c =================================================================== RCS file: /cvs/src/sys/arch/sparc64/sparc64/conf.c,v retrieving revision 1.84 diff -u -p -r1.84 conf.c --- sys/arch/sparc64/sparc64/conf.c 6 Jul 2020 04:32:25 -0000 1.84 +++ sys/arch/sparc64/sparc64/conf.c 28 Dec 2020 03:25:32 -0000 @@ -104,6 +104,7 @@ cdev_decl(pci); #include "usb.h" #include "uhid.h" #include "fido.h" +#include "ujoy.h" #include "ugen.h" #include "ulpt.h" #include "ucom.h" @@ -297,6 +298,7 @@ struct cdevsw cdevsw[] = cdev_switch_init(NSWITCH,switch), /* 136: switch(4) control interface */ cdev_fido_init(NFIDO,fido), /* 137: FIDO/U2F security key */ cdev_pppx_init(NPPPX,pppac), /* 138: PPP Access Concentrator */ + cdev_ujoy_init(NUJOY,ujoy), /* 139: USB joystick/gamecontroller */ }; int nchrdev = nitems(cdevsw); Index: sys/dev/usb/files.usb =================================================================== RCS file: /cvs/src/sys/dev/usb/files.usb,v retrieving revision 1.143 diff -u -p -r1.143 files.usb --- sys/dev/usb/files.usb 31 May 2020 18:15:37 -0000 1.143 +++ sys/dev/usb/files.usb 28 Dec 2020 03:25:33 -0000 @@ -74,12 +74,17 @@ file dev/usb/uhidev.c uhidev # Generic HID devices device uhid: hid attach uhid at uhidbus -file dev/usb/uhid.c uhid | fido needs-flag +file dev/usb/uhid.c uhid | fido | ujoy needs-flag # FIDO/U2F security keys device fido: hid attach fido at uhidbus file dev/usb/fido.c fido needs-flag + +# USB Joysticks/Gamecontrollers +device ujoy: hid +attach ujoy at uhidbus +file dev/usb/ujoy.c ujoy needs-flag # Keyboards file dev/usb/ukbdmap.c hidkbd Index: sys/dev/usb/uhid.c =================================================================== RCS file: /cvs/src/sys/dev/usb/uhid.c,v retrieving revision 1.81 diff -u -p -r1.81 uhid.c --- sys/dev/usb/uhid.c 25 Dec 2020 12:59:52 -0000 1.81 +++ sys/dev/usb/uhid.c 28 Dec 2020 03:25:33 -0000 @@ -36,6 +36,7 @@ */ #include "fido.h" +#include "ujoy.h" #include <sys/param.h> #include <sys/systm.h> @@ -96,6 +97,10 @@ uhid_lookup(dev_t dev) #if NFIDO > 0 else if (cdev->d_open == fidoopen) cd = &fido_cd; +#endif +#if NUJOY > 0 + else if (cdev->d_open == ujoyopen) + cd = &ujoy_cd; #endif else return (NULL); Index: sys/dev/usb/uhid.h =================================================================== RCS file: /cvs/src/sys/dev/usb/uhid.h,v retrieving revision 1.1 diff -u -p -r1.1 uhid.h --- sys/dev/usb/uhid.h 17 Dec 2019 13:08:54 -0000 1.1 +++ sys/dev/usb/uhid.h 28 Dec 2020 03:25:33 -0000 @@ -48,6 +48,7 @@ struct uhid_softc { extern struct cfdriver uhid_cd; extern struct cfdriver fido_cd; +extern struct cfdriver ujoy_cd; #define UHIDUNIT(dev) (minor(dev)) #define UHID_CHUNK 128 /* chunk size for read */ Index: sys/dev/usb/ujoy.c =================================================================== RCS file: sys/dev/usb/ujoy.c diff -N sys/dev/usb/ujoy.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/usb/ujoy.c 28 Dec 2020 03:25:33 -0000 @@ -0,0 +1,108 @@ +/* $OpenBSD: ujoy.c,v 1.2 2019/12/18 05:09:53 deraadt Exp $ */ + +/* + * Copyright (c) 2020 Thomas Frohwein <t...@openbsd.org> + * Copyright (c) 2020 Bryan Steele <bry...@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/signalvar.h> +#include <sys/device.h> +#include <sys/ioctl.h> +#include <sys/conf.h> +#include <sys/tty.h> +#include <sys/selinfo.h> +#include <sys/proc.h> +#include <sys/vnode.h> +#include <sys/poll.h> +#include <sys/fcntl.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbhid.h> + +#include <dev/usb/usbdevs.h> +#include <dev/usb/usbdi.h> +#include <dev/usb/usbdi_util.h> + +#include <dev/usb/uhidev.h> +#include <dev/usb/uhid.h> + +int ujoy_match(struct device *, void *, void *); + +struct cfdriver ujoy_cd = { + NULL, "ujoy", DV_DULL +}; + +const struct cfattach ujoy_ca = { + sizeof(struct uhid_softc), + ujoy_match, + uhid_attach, + uhid_detach, +}; + +int +ujoy_match(struct device *parent, void *match, void *aux) +{ + struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux; + int size; + void *desc; + int ret = UMATCH_NONE; + + if (uha->reportid == UHIDEV_CLAIM_ALLREPORTID) + return (ret); + + /* Find the general usage page and gamecontroller collections */ + uhidev_get_report_desc(uha->parent, &desc, &size); + + if (hid_is_collection(desc, size, uha->reportid, + HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_JOYSTICK))) + ret = UMATCH_IFACECLASS; + + if (hid_is_collection(desc, size, uha->reportid, + HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_GAME_PAD))) + ret = UMATCH_IFACECLASS; + + return (ret); +} + +int +ujoyopen(dev_t dev, int flag, int mode, struct proc *p) +{ + /* Restrict ujoy devices to read operations */ + if ((flag & FWRITE)) + return (EPERM); + return (uhid_do_open(dev, flag, mode, p)); +} + +int +ujoyioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) +{ + switch (cmd) { + case FIONBIO: + case FIOASYNC: + case USB_GET_DEVICEINFO: + case USB_GET_REPORT: + case USB_GET_REPORT_DESC: + case USB_GET_REPORT_ID: + break; + default: + return (EPERM); + } + + return (uhidioctl(dev, cmd, addr, flag, p)); +} Index: sys/sys/conf.h =================================================================== RCS file: /cvs/src/sys/sys/conf.h,v retrieving revision 1.155 diff -u -p -r1.155 conf.h --- sys/sys/conf.h 6 Jul 2020 04:11:26 -0000 1.155 +++ sys/sys/conf.h 28 Dec 2020 03:25:34 -0000 @@ -383,6 +383,13 @@ extern struct cdevsw cdevsw[]; (dev_type_stop((*))) enodev, 0, dev_init(c,uhid,poll), \ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) } +/* open, close, read, write, ioctl, poll, kqfilter */ +#define cdev_ujoy_init(c,n) { \ + dev_init(c,n,open), dev_init(c,uhid,close), dev_init(c,uhid,read), \ + dev_init(c,uhid,write), dev_init(c,ujoy,ioctl), \ + (dev_type_stop((*))) enodev, 0, dev_init(c,uhid,poll), \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) } + /* open, close, init */ #define cdev_pci_init(c,n) { \ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ @@ -624,6 +631,7 @@ cdev_decl(usb); cdev_decl(ugen); cdev_decl(uhid); cdev_decl(fido); +cdev_decl(ujoy); cdev_decl(ucom); cdev_decl(ulpt); cdev_decl(urio);