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

drivers/libusb{0,1}.c: reset driver parameters while enumerating #2611

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ https://github.com/networkupstools/nut/milestone/11
by default: `powercom_sdcmd_byte_order_fallback`. [PR #2480]
* `cps-hid` subdriver now supports more variables, as available on e.g.
CP1350EPFCLCD model. [PR #2540]
* USB parameters (per `usb_communication_subdriver_t`) are now set back to
their default values during enumeration after probing each subdriver.
Having an unrelated device connected with a VID:PID matching the
`arduino-hid` subdriver prevented use of an actual `usb-hid` device due to
changes made to this struct during probe. [#2611]

- bicker_ser: added new driver for Bicker 12/24Vdc UPS via RS-232 serial
communication protocol, which supports any UPS shipped with the PSZ-1053
Expand All @@ -170,6 +175,10 @@ https://github.com/networkupstools/nut/milestone/11
`nutdrv_atcl_usb`) and for general code to collect string readings and
other data points, and for `nut-scanner`.

- USB drivers should now be more likely to succeed with iterative detection
of an UPS interface on a composite USB device or when looking at devices
with non-default interface/endpoint/config numbers. [PR #2611]

- Introduced a new driver concept for interaction with OS-reported hardware
monitoring readings. Currently instantiated as `hwmon_ina219` specifically
made for Texas Instruments INA219 chip as exposed in the Linux "hwmon"
Expand Down
2 changes: 1 addition & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3214 utf-8
personal_ws-1.1 en 3215 utf-8
AAC
AAS
ABI
Expand Down
16 changes: 16 additions & 0 deletions drivers/libusb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ static int nut_libusb_set_altinterface(usb_dev_handle *udev)
return ret;
}

static void nut_libusb_subdriver_defaults(usb_communication_subdriver_t *subdriver)
{
if (!getval("usb_config_index"))
subdriver->usb_config_index = LIBUSB_DEFAULT_CONF_INDEX;
if (!getval("usb_hid_rep_index"))
subdriver->hid_rep_index = LIBUSB_DEFAULT_INTERFACE;
if (!getval("usb_hid_desc_index"))
subdriver->hid_desc_index = LIBUSB_DEFAULT_DESC_INDEX;
if (!getval("usb_hid_ep_in"))
subdriver->hid_ep_in = LIBUSB_DEFAULT_HID_EP_IN;
if (!getval("usb_hid_ep_out"))
subdriver->hid_ep_out = LIBUSB_DEFAULT_HID_EP_OUT;
}

#define usb_control_msg typesafe_control_msg

/* On success, fill in the curDevice structure and return the report
Expand Down Expand Up @@ -711,6 +725,8 @@ static int nut_libusb_open(usb_dev_handle **udevp,
/* if (if_claimed)
usb_release_interface(udev, 0); */
usb_close(udev);
/* reset any parameters modified by unmatched drivers back to defaults */
nut_libusb_subdriver_defaults(&usb_subdriver);
}
}

Expand Down
16 changes: 16 additions & 0 deletions drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ static int nut_libusb_set_altinterface(libusb_device_handle *udev)
return ret;
}

static void nut_libusb_subdriver_defaults(usb_communication_subdriver_t *subdriver)
{
if (!getval("usb_config_index"))
subdriver->usb_config_index = LIBUSB_DEFAULT_CONF_INDEX;
if (!getval("usb_hid_rep_index"))
subdriver->hid_rep_index = LIBUSB_DEFAULT_INTERFACE;
if (!getval("usb_hid_desc_index"))
subdriver->hid_desc_index = LIBUSB_DEFAULT_DESC_INDEX;
if (!getval("usb_hid_ep_in"))
subdriver->hid_ep_in = LIBUSB_DEFAULT_HID_EP_IN;
if (!getval("usb_hid_ep_out"))
subdriver->hid_ep_out = LIBUSB_DEFAULT_HID_EP_OUT;
}

/* On success, fill in the curDevice structure and return the report
* descriptor length. On failure, return -1.
* Note: When callback is not NULL, the report descriptor will be
Expand Down Expand Up @@ -795,6 +809,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
/* if (if_claimed)
libusb_release_interface(udev, usb_subdriver.hid_rep_index); */
libusb_close(udev);
/* reset any parameters modified by unmatched drivers back to defaults */
nut_libusb_subdriver_defaults(&usb_subdriver);
}

*udevp = NULL;
Expand Down
Loading