From 56a79f60e10266ba094d1ca92e0ae887edade777 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Wed, 12 Oct 2022 22:18:02 +0200 Subject: [PATCH] usb: Claim and set interface alt-setting only for used lines If a line is not auto-created, there is no point on claiming the matching interface and even less point setting the alt setting that will try to use USB isoc bandwith. With this you can no use only line 1 and not line 0 of a ice1usb for instance. While previously it would still "enable" line 0 and then line 1 would fail because on BW issues most of the case. Signed-off-by: Sylvain Munaut Change-Id: Iea5d72272f11875e7a32c78b60c188590deda831 --- src/usb.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/usb.c b/src/usb.c index 47fff14..c8ad97f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -904,21 +904,6 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev) } } - /* Get interface and set it up */ - ret = libusb_claim_interface(devh, id->bInterfaceNumber); - if (ret) { - LOGP(DE1D, LOGL_ERROR, "Failed to claim interface %d:%s\n", id->bInterfaceNumber, - libusb_strerror(ret)); - goto next_interface; - } - - ret = libusb_set_interface_alt_setting(devh, id->bInterfaceNumber, 1); - if (ret) { - LOGP(DE1D, LOGL_ERROR, "Failed to set interface %d altsetting:%s\n", id->bInterfaceNumber, - libusb_strerror(ret)); - goto next_interface; - } - /* Setup driver data and find endpoints */ line_data = talloc_zero(e1d->ctx, struct e1_usb_line_data); @@ -965,6 +950,22 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev) line->drv_data = line_data; } + /* Get interface and set it up */ + ret = libusb_claim_interface(devh, id->bInterfaceNumber); + if (ret) { + LOGP(DE1D, LOGL_ERROR, "Failed to claim interface %d:%s\n", id->bInterfaceNumber, + libusb_strerror(ret)); + goto next_interface; + } + + ret = libusb_set_interface_alt_setting(devh, id->bInterfaceNumber, 1); + if (ret) { + LOGP(DE1D, LOGL_ERROR, "Failed to set interface %d altsetting:%s\n", id->bInterfaceNumber, + libusb_strerror(ret)); + goto next_interface; + } + + /* Create data flows and start the line */ line_data->flow_in = e1uf_create(line, e1_usb_xfer_in, line_data->ep_in, 4, line_data->pkt_size, 4); line_data->flow_out = e1uf_create(line, e1_usb_xfer_out, line_data->ep_out, 4, line_data->pkt_size, 4); line_data->flow_fb = e1uf_create(line, e1_usb_xfer_fb, line_data->ep_fb, 2, 3, 1);