Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libusb_open returns error codes other than LIBUSB_ERROR_ACCESS #1402

Open
mcuee opened this issue Dec 26, 2023 · 5 comments
Open

libusb_open returns error codes other than LIBUSB_ERROR_ACCESS #1402

mcuee opened this issue Dec 26, 2023 · 5 comments
Labels
BSD OpenBSD, NetBSD, etc windows

Comments

@mcuee
Copy link
Member

mcuee commented Dec 26, 2023

libusb_open can return error codes other than the expected LIBUSB_ERROR_ACCESS.

For example, it can return LIBUSB_ERROR_NOT_FOUND or LIBUSB_ERROR_NOT_SUPPORTED under Windows. At least I think LIBUSB_ERROR_NOT_FOUND is really unexpected.

	/** Access denied (insufficient permissions) */
	LIBUSB_ERROR_ACCESS = -3,

	/** Entity not found */
	LIBUSB_ERROR_NOT_FOUND = -5,

	/** Operation not supported or unimplemented on this platform */
	LIBUSB_ERROR_NOT_SUPPORTED = -12,

Reference discussions.

@mcuee mcuee added windows BSD OpenBSD, NetBSD, etc labels Dec 26, 2023
@mcuee
Copy link
Member Author

mcuee commented Dec 26, 2023

To be confirmed:

  1. NetBSD --> libusb_open can return LIBUSB_ERROR_IO.
  1. OpenBSD --> libusb_open can return LIBUSB_ERROR_OTHER (maybe a false alarm).

@mcuee
Copy link
Member Author

mcuee commented Dec 28, 2023

Questions for Windows.

  1. Is the default error code LIBUSB_ERROR_IO a good choice here?
    // WinUSB requires a separate handle for each interface
    for (i = 0; i < USB_MAXINTERFACES; i++) {
    if ((priv->usb_interface[i].path != NULL)
    && (priv->usb_interface[i].apib->id == USB_API_WINUSBX)) {
    file_handle = windows_open(dev_handle, priv->usb_interface[i].path, GENERIC_READ | GENERIC_WRITE);
    if (file_handle == INVALID_HANDLE_VALUE) {
    usbi_err(HANDLE_CTX(dev_handle), "could not open device %s (interface %d): %s", priv->usb_interface[i].path, i, windows_error_str(0));
    switch (GetLastError()) {
    case ERROR_FILE_NOT_FOUND: // The device was disconnected
    return LIBUSB_ERROR_NO_DEVICE;
    case ERROR_ACCESS_DENIED:
    return LIBUSB_ERROR_ACCESS;
    default:
    return LIBUSB_ERROR_IO;
    }
    }
    handle_priv->interface_handle[i].dev_handle = file_handle;
    }
    }
    return LIBUSB_SUCCESS;
    }

And here?

for (i = 0; i < USB_MAXINTERFACES; i++) {
if ((priv->usb_interface[i].path != NULL)
&& (priv->usb_interface[i].apib->id == USB_API_HID)) {
hid_handle = windows_open(dev_handle, priv->usb_interface[i].path, GENERIC_READ | GENERIC_WRITE);
/*
* http://www.lvr.com/hidfaq.htm: Why do I receive "Access denied" when attempting to access my HID?
* "Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system
* keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not
* requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and
* HidD_GetFeature (if the device supports Feature reports)."
*/
if (hid_handle == INVALID_HANDLE_VALUE) {
usbi_warn(HANDLE_CTX(dev_handle), "could not open HID device in R/W mode (keyboard or mouse?) - trying without");
hid_handle = windows_open(dev_handle, priv->usb_interface[i].path, 0);
if (hid_handle == INVALID_HANDLE_VALUE) {
usbi_err(HANDLE_CTX(dev_handle), "could not open device %s (interface %d): %s", priv->path, i, windows_error_str(0));
switch (GetLastError()) {
case ERROR_FILE_NOT_FOUND: // The device was disconnected
return LIBUSB_ERROR_NO_DEVICE;
case ERROR_ACCESS_DENIED:
return LIBUSB_ERROR_ACCESS;
default:
return LIBUSB_ERROR_IO;
}
}
priv->usb_interface[i].restricted_functionality = true;
}
handle_priv->interface_handle[i].api_handle = hid_handle;
}
}

@mcuee
Copy link
Member Author

mcuee commented Dec 28, 2023

return LIBUSB_ERROR_NOT_FOUND; is used in many places for Windows. Maybe that is the reason we see this error code often.

@mcuee
Copy link
Member Author

mcuee commented Dec 28, 2023

Known issues where libusb_open will return LIBUSB_ERROR_NOT_SUPPORTED.

@mcuee
Copy link
Member Author

mcuee commented Jan 21, 2024

To be confirmed:

  1. NetBSD --> libusb_open can return LIBUSB_ERROR_IO.
  1. OpenBSD --> libusb_open can return LIBUSB_ERROR_OTHER (maybe a false alarm).

Both issues are considered as invalid since they are caused by Proxmox and not libusb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BSD OpenBSD, NetBSD, etc windows
Projects
None yet
Development

No branches or pull requests

1 participant