Author Topic: DOS VDM - USB and Game port Gamepad support  (Read 27703 times)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3633
  • Karma: +77/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #45 on: November 26, 2021, 12:07:23 am »
Meanwhile I recompiled hidapi with some debugging printf's, now the output is,
Code: [Select]
H:\tmp\hidapi\lib>hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

make_path() failed. unknown error
iconv_open() failed
iconv_open() failed
make_path() failed. unknown error
iconv_open() failed
iconv_open() failed
make_path() failed. unknown error
iconv_open() failed
iconv_open() failed
Device Found
  type: 046d c534
  path:
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      2901
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c534
  path:
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      2901
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c216
  path:
  serial_number: (null)
  Manufacturer: (null)
  Product:      (null)
  Release:      300
  Interface:    0
  Usage (page): 0x0 (0x0)

unable to open device

The make_path failed is likely the problem.
I also compiled some of the test programs that come with libusb-devel-docs.
Code: [Select]
H:\tmp\libusb_test>testlibusb.exe
Dev (bus 1, device 1): Logitech - USB Receiver
Dev (bus 1, device 2): Kingston - DataTraveler 3.0
Dev (bus 1, device 3): Logitech - Logitech Dual Action
Code: [Select]
H:\tmp\libusb_test>listdevs.exe
046d:c534 (bus 1, device 1)
0951:1666 (bus 1, device 2)
046d:c216 (bus 1, device 3)
and here testing the joypad,
Code: [Select]
H:\tmp\libusb_test>xusb.exe 046d:c216
Using libusb v1.0.21.11156

Opening device 046D:C216...

Reading device descriptor:
            length: 18
      device class: 0
               S/N: 0
           VID:PID: 046D:C216
         bcdDevice: 0300
   iMan:iProd:iSer: 1:2:0
          nb confs: 1

Reading BOS descriptor: libusb: error [libusb_get_bos_descriptor] failed to read BOS (-1)
no descriptor

Reading first configuration descriptor:
             nb interfaces: 1
              interface[0]: id = 0
interface[0].altsetting[0]: num endpoints = 2
   Class.SubClass.Protocol: 03.00.00
       endpoint[0].address: 81
           max packet size: 0008
          polling interval: 0A
       endpoint[1].address: 01
           max packet size: 0008
          polling interval: 0A

Claiming interface 0...

Reading string descriptors:
   String (0x01): "Logitech"
   String (0x02): "Logitech Dual Action"
   String (0xEE): "?"

Releasing interface 0...
Closing device...
libusb: warning [libusb_exit] some libusb_devices were leaked


Dave Yeo

  • Hero Member
  • *****
  • Posts: 3633
  • Karma: +77/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #46 on: November 26, 2021, 04:25:20 am »
Taking iconv out of the equation for now (problems with converting UTF-16LE?), I now get,
Code: [Select]
H:\tmp\hidapi\lib>hidtest.exe
hidapi test/example tool. Compiled with hidapi version 0.11.0, runtime version 0.11.0.
Compile-time version matches runtime version of hidapi.

make_path() failed. unknown error
make_path() failed. unknown error
make_path() failed. unknown error
Device Found
  type: 046d c534
  path:
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      2901
  Interface:    0
  Usage (page): 0x6 (0x1)

Device Found
  type: 046d c534
  path:
  serial_number: (null)
  Manufacturer: Logitech  Product:      USB Receiver  Release:      2901
  Interface:    1
  Usage (page): 0x6 (0x1)

Device Found
  type: 046d c216
  path:
  serial_number: (null)
  Manufacturer: Logitech  Product:      Logitech Dual Action  Release:      300
  Interface:    0
  Usage (page): 0x4 (0x1)

unable to open device

Better but there is still the make_path() error.
Looking at the code, it seems that libusb screws up returning the number of ports,
Code: [Select]
static char *make_path(libusb_device *dev, int interface_number, int config_number)
{
char str[64]; /* max length "000-000.000.000.000.000.000.000:000.000" */
/* Note that USB3 port count limit is 7; use 8 here for alignment */
uint8_t port_numbers[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int num_ports = libusb_get_port_numbers(dev, port_numbers, 8);

if (num_ports > 0) {
int n = snprintf(str, sizeof("000-000"), "%u-%u", libusb_get_bus_number(dev), port_numbers[0]);
for (uint8_t i = 1; i < num_ports; i++) {
n += snprintf(&str[n], sizeof(".000"), ".%u", port_numbers[i]);
}
n += snprintf(&str[n], sizeof(":000.000"), ":%u.%u", (uint8_t)config_number, (uint8_t)interface_number);
str[n] = '\0';
} else {
/* USB3.0 specs limit number of ports to 7 and buffer size here is 8 */
if (num_ports == LIBUSB_ERROR_OVERFLOW) {
LOG("make_path() failed. buffer overflow error\n");
} else {
LOG("make_path() failed. unknown error\n");
}
str[0] = '\0';
}
return strdup(str);
}

Or maybe something else? There's also the null serial number, problem with UTF-16?

Lars

  • Hero Member
  • *****
  • Posts: 956
  • Karma: +45/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #47 on: November 26, 2021, 01:24:58 pm »
I am currently working on libusb (for various reasons).
I did some updates on what port you will find what device. That'll hopefully solve it. We will see.

Note that our implementation of libusb will NEVER be able to list the whole bus hierarchy (which encompasses root hubs and chained hubs) because USBD.SYS (and therefore USBRESMG.SYS and also USBCALLS.DLL) does not publicly expose hub information.

EDIT: now I see that "libusb_get_port_numbers" tries to resolve the whole bus hierarchy, from the plugged in device upstream up to the root hub port. As I said, that cannot work. Unless we modify USBD.SYS, USBRESMG.SYS and USBCALLS.DLL.
« Last Edit: November 26, 2021, 01:35:45 pm by Lars »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3633
  • Karma: +77/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #48 on: November 26, 2021, 10:14:48 pm »
OK, my understanding is obviously limited. It seems the code I quoted is limited to 8 ports, a USB3 limit. I took it for granted that was root ports, of which I have 8 of, as well as 2 hubs totaling 14 ports. The tree,
Code: [Select]
Controller 0: USBXHCD$
Root Hub 0 (4 ports) 1B21:2142
  Port 4: Device 046D:C216 (HID) LS Logitech, Inc. F310 Gamepad [DirectInput Mode]

Controller 1: USBEHCD$
Root Hub 1 (2 ports) 8086:1C2D
  Port 1:  Hub 3 (6 ports) 8087:0024 (HS hub with single TT) Intel Corp. Integrated Rate Matching Hub
    Port 3: Device 046D:C534 (HID)-(Keyboard)(HID)-(Mouse) FS Logitech, Inc. Unifying Receiver
    Port 4: Device 0951:1666 (MSD)-(SCSI)-(BO) HS Kingston Technology DataTraveler 100 G3/G4/SE9 G2/50

Controller 2: USBEHC2$
Root Hub 2 (2 ports) 8086:1C26
  Port 1:  Hub 4 (8 ports) 8087:0024 (HS hub with single TT) Intel Corp. Integrated Rate Matching Hub

which does seem to show enough of the bus hierarchy. Unluckily that is likely directly reading the drivers.
As for usbcalls, I've been using the one installed with YUM/RPM. Tried the one that ships with the Arca Noae drivers but it is quite different with almost none of the exports matching, different calling convention too. Guess ideally would be to basically rewrite the libusb/hid.c from hidapi to use the system usbcalls, big job likely beyond my abilities. Another idea is to call the system usbcalls from the YUM/RPM one.
Missing exports using the system usbcalls,
Code: [Select]
Error! E2028: _libusb_get_port_numbers is an undefined reference
Error! E2028: _libusb_get_bus_number is an undefined reference
Error! E2028: _libusb_alloc_transfer is an undefined reference
Error! E2028: _libusb_submit_transfer is an undefined reference
Error! E2028: _libusb_handle_events is an undefined reference
Error! E2028: _libusb_cancel_transfer is an undefined reference
Error! E2028: _libusb_handle_events_completed is an undefined reference
Error! E2028: _libusb_init is an undefined reference
Error! E2028: _libusb_exit is an undefined reference
Error! E2028: _libusb_get_device_list is an undefined reference
Error! E2028: _libusb_get_active_config_descriptor is an undefined reference
Error! E2028: _libusb_open is an undefined reference
Error! E2028: _libusb_get_device is an undefined reference
Error! E2028: _libusb_get_device_descriptor is an undefined reference
Error! E2028: _libusb_kernel_driver_active is an undefined reference
Error! E2028: _libusb_claim_interface is an undefined reference
Error! E2028: _libusb_free_config_descriptor is an undefined reference
Error! E2028: _libusb_free_device_list is an undefined reference
Error! E2028: _libusb_detach_kernel_driver is an undefined reference
Error! E2028: _libusb_close is an undefined reference
Error! E2028: _libusb_interrupt_transfer is an undefined reference
Error! E2028: _libusb_control_transfer is an undefined reference
Error! E2028: _libusb_free_transfer is an undefined reference
Error! E2028: _libusb_release_interface is an undefined reference
Error! E2028: _libusb_attach_kernel_driver is an undefined reference

Lars

  • Hero Member
  • *****
  • Posts: 956
  • Karma: +45/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #49 on: November 27, 2021, 12:09:34 am »
As to controller,hub,device info: I assume you are quoting what the testlog from AN returns.
For debugging purposes, David added an interface to USBD.SYS to completely query all USB devices, including hubs. Since USBD.SYS of course knows about all USB devices, including USB hubs.

But USBCALLS (and USBRESMG) does not have access to that interface.

Anyway, libusb is using USBCALLS to implement its functionality, so that is the proper way to go. Because that is what usbhid obviously uses.

Rich Walsh

  • Full Member
  • ***
  • Posts: 160
  • Karma: +7/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #50 on: November 27, 2021, 09:22:43 am »
As to controller,hub,device info: I assume you are quoting what the testlog from AN returns.
For debugging purposes, David added an interface to USBD.SYS to completely query all USB devices, including hubs. Since USBD.SYS of course knows about all USB devices, including USB hubs. But USBCALLS (and USBRESMG) does not have access to that interface.

For years now, the AN version of USBRESMG/USBCALLS has offered this API:

Code: [Select]
  APIRET APIENTRY UsbQueryDeviceInfo( ULONG ulDevNumber, ULONG *pulBufLen, UCHAR *pucData);
which returns this struct:

Code: [Select]
typedef struct {
  UCHAR              ctrlID;              // (00) controller ID
  UCHAR              deviceAddress;       // (01) USB device address
  UCHAR              bConfigurationValue; // (02) USB device configuration value
  UCHAR              bInterfaceNumber;    // (03) 0 based index in interface array for this item
  UCHAR              SpeedDevice;         // (04) 0 for full speed device, 1 - low speed device  2 - high speed device
  UCHAR              portNum;             // (05) port number to which device is attached
  USHORT             parentHubIndex;      // (06) index in hub table to parent hub, -1 for root hub device
  ULONG              rmDevHandle;         // (08) Resource Manager device handle
} GETDEVINFODATA;

I thought you and David had synchronized your distros.

Lars

  • Hero Member
  • *****
  • Posts: 956
  • Karma: +45/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #51 on: November 27, 2021, 10:19:42 am »
That struct returns the parent hub index a device is attached to as "parentHubIndex". But there is no public way to query the device index of that hub device. (query the device index from the hub index) And therefore you cannot build up the hierarchy.
It would not be awfully difficult to extend the functionality but now we have quite some code out in the field that makes use of USBCALLS. We could add another function that can query the device index for a given hub index. Then an application could of course build up the hierarchy.

EDIT: and sine the struct does not contain the device index but rather the real device address and rmDevHandle, then that new function should better return device address and rmDevHandle.
« Last Edit: November 27, 2021, 10:23:55 am by Lars »

Lars

  • Hero Member
  • *****
  • Posts: 956
  • Karma: +45/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #52 on: November 27, 2021, 10:36:51 am »
I just tested: libusb uses "Usbquerydeviceinfo" to query the devices. And "lsusb" uses libusb to show the devices list. It will only show non-hub devices (that is: only "end-user" devices).
Unless David has added something. But that of course will never be publicly visible. He'll always roll his own ball.

Jochen Schäfer

  • Full Member
  • ***
  • Posts: 221
  • Karma: +20/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #53 on: December 07, 2021, 11:19:36 am »
A little status update: I have enabled HIDAPI support in SDL2 and it's functions are called, but testjoystick doesn't recognizes my USB joystick, yet.
« Last Edit: December 10, 2021, 04:12:14 pm by Jochen Schäfer »

Lars

  • Hero Member
  • *****
  • Posts: 956
  • Karma: +45/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #54 on: December 07, 2021, 04:14:17 pm »
By now, I have finished work on libusb (hopefully). I'll ask BWW to create an updated RPM. You might want to try the updated version and see if that helps. Proper support of "libusb_get_port_numbers" is still a problem (what error message did you get when trying out hidapi ?)
« Last Edit: December 07, 2021, 04:21:12 pm by Lars »

Jochen Schäfer

  • Full Member
  • ***
  • Posts: 221
  • Karma: +20/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #55 on: December 07, 2021, 09:04:24 pm »
lsusb shows the joystick, but SDL2 doesn‘t. Since I don’t use hidapi directly, it have no error message.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3633
  • Karma: +77/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #56 on: December 08, 2021, 01:17:11 am »
lsusb shows the joystick, but SDL2 doesn‘t. Since I don’t use hidapi directly, it have no error message.

Did you compile it yourself or use the one I compiled? Anyways here's the last version I compiled, used a different wcsdup() based on https://github.com/bitwiseworks/libc/issues/118 and hacked to not use iconv(). Test program and diff included.
Edit: fix typo
« Last Edit: December 08, 2021, 01:19:27 am by Dave Yeo »

Jochen Schäfer

  • Full Member
  • ***
  • Posts: 221
  • Karma: +20/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #57 on: December 08, 2021, 08:58:40 am »
lsusb shows the joystick, but SDL2 doesn‘t. Since I don’t use hidapi directly, it have no error message.

Did you compile it yourself or use the one I compiled? Anyways here's the last version I compiled, used a different wcsdup() based on https://github.com/bitwiseworks/libc/issues/118 and hacked to not use iconv(). Test program and diff included.
Edit: fix typo
No, I used the version included in SDL2 with your wcsdup implementation. I'm now trying to compile the included hidapi, and test with that.

EDIT: I used hidtest from your version, but it says it cannot open the device.

BTW: Why do we have a lot wcs function,but not wcsdup?
« Last Edit: December 08, 2021, 09:28:40 am by Jochen Schäfer »

Mark Szkolnicki

  • Sr. Member
  • ****
  • Posts: 283
  • Karma: +13/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #58 on: December 08, 2021, 03:11:52 pm »
Hi Jochen

lsusb shows the joystick, but SDL2 doesn‘t. Since I don’t use hidapi directly, it have no error message.

Did you compile it yourself or use the one I compiled? Anyways here's the last version I compiled, used a different wcsdup() based on https://github.com/bitwiseworks/libc/issues/118 and hacked to not use iconv(). Test program and diff included.
Edit: fix typo
No, I used the version included in SDL2 with your wcsdup implementation. I'm now trying to compile the included hidapi, and test with that.

EDIT: I used hidtest from your version, but it says it cannot open the device.

BTW: Why do we have a lot wcs function,but not wcsdup?

Have you posted the updated hidapi? Didn't see it attached to any of the posts at the moment, and might want to see if it can see my joystick.

Haven't been following this much, as I've been busy at the moment fixing a sick printer - got a Printer Error 59.99 on my HP3500, which means tearing down the entire printer, to replace about 5 cents of worn padding on a solenoid. Takes about 12 hours ............ tedious work.

I recommend HP service manuals to anyone brave enough to undertake things like this _ very detailed.

Best!

M
Vincit Que Se Vincit - "He Who Conquers Self Succeeds"

Dave Yeo

  • Hero Member
  • *****
  • Posts: 3633
  • Karma: +77/-0
    • View Profile
Re: DOS VDM - USB and Game port Gamepad support
« Reply #59 on: December 08, 2021, 04:35:17 pm »
EDIT: I used hidtest from your version, but it says it cannot open the device.

BTW: Why do we have a lot wcs function,but not wcsdup?

Guess it is the PATH problem and needing to get all the ports. Hopefully Lars's updated libusb will help.
We've always been missing a lot of the wide character functions, Bitwise has added most but hadn't added wcsdup(). Sylvan must have seen this thread and opened the above referenced issue about it, so slowly we're getting all of them.