43 Commits

Author SHA1 Message Date
Vadim Mikhailov
5ee8260c71 Release version 2.2.0 2020-05-22 13:39:47 -07:00
Vadim Mikhailov
8ba36bd8df Improve getting version from git describe
* To determine version, only consider tags starting with v{digit}
* Strip v prefix from version
2020-05-22 13:21:45 -07:00
Vadim Mikhailov
aaf87accad Add Seagate Backup Plus Hub STEL8000100 as supported device
Closes #238.
2020-05-16 15:16:46 -07:00
Sarah Foster
58385b87e6 Update README.md
Just a small typo correction
2020-04-27 22:03:45 -07:00
Vadim Mikhailov
7bf80a08d1 Update Rasperry Pi 4B USB topology note
Apparently, controlling only port 4 is not enough to actually turn power off for RPi4B.
Instead, note that all 4 ports should be turned off. Closes #233.
2020-04-24 17:45:01 -07:00
Vadim Mikhailov
b73213dd6d Mention testing VBUS off in README before reporting new devices 2020-04-14 22:53:38 -07:00
Vadim Mikhailov
e327f5aeb1 Move keyboard/mouse warning to usage section 2020-04-14 22:47:21 -07:00
Vadim Mikhailov
9b824b5587 Add Control USB Lamp With Voice to notable projects
Also fix some broken links.
2020-04-14 22:38:49 -07:00
Vadim Mikhailov
aa864285b1 Add LG Electronics 38WK95C-W as supported device
Closes #231.
2020-04-14 22:15:16 -07:00
Vadim Mikhailov
fa524cf7df Add AmazonBasics HUC9002V1ESL as supported device
AmazonBasics HUC9002V1ESL seems to be EU version of HU9002V1SBL and works the same.
Closes #229.
2020-04-04 13:27:11 -07:00
Vadim Mikhailov
7fd3080f90 Add Raspberry Pi Reboot Router into notable projects 2020-04-04 10:38:40 -07:00
Vadim Mikhailov
e3734e052f Provide workaround for using uhubctl on MacOS Catalina
This provides workaround for issue #227.
Will be fully solved only by https://github.com/libusb/libusb/issues/707.
2020-03-26 21:30:02 -07:00
Vadim Mikhailov
d576db98fb Mention udisksctl in README 2020-02-25 22:21:43 -08:00
Vadim Mikhailov
9e402917dc Add Bytecc BT-UH340 as compatible device
Reported in #217.
2020-02-25 22:11:56 -08:00
Vadim Mikhailov
b0d321a041 Add D-Link DUB-H4 rev E as supported device
Reported in #212.
2020-02-17 11:26:25 -08:00
Vadim Mikhailov
0d2aa24bae Remove statement about proper per-port switching on RPi3B+
Per discussion in issue #215, proper per-port power switching
is not necessarily supported on RPi3B+ secondary hub ports.
2020-02-17 11:21:17 -08:00
Vadim Mikhailov
bd92bcef2f Add a warning and link how to update RPi4B firmware to make power switching work 2020-01-28 11:24:49 -08:00
Vadim Mikhailov
ea70731854 Use in-document anchors to Raspberry Pi usage examples 2020-01-27 23:41:30 -08:00
Vadim Mikhailov
6366aea0bd Refactor Raspberry Pi USB topology table with sub-headers 2020-01-27 23:33:53 -08:00
Vadim Mikhailov
232dcc6f6d Clarify support for different Raspberry Pi models with example commands
* Reformat markdown
* Add example uhubctl commands to turn power off for affected port(s)
* Removed some low level techical details about USB descriptors
2020-01-21 23:58:17 -08:00
Vadim Mikhailov
5691db3379 Add Buffalo BSH4A05U3BK as supported device 2020-01-21 23:04:02 -08:00
Vadim Mikhailov
fae3da7e6f Bump copyright year 2020-01-20 12:14:48 -08:00
Vadim Mikhailov
c79c9ac667 Add Basler 2000036234 as supported device
Reported in #208.
2020-01-20 12:09:36 -08:00
Ryan O'Leary
7f25162ed3 Add AmazonBasics HU9002V1SBL as a Supported Device
Signed-off-by: Ryan O'Leary <ryanoleary@google.com>
2020-01-07 23:01:04 -08:00
Vadim Mikhailov
6f84663c6a Clarify VBUS off requirements for Raspberry Pi 4 2020-01-05 14:05:25 -08:00
Vadim Mikhailov
4aae44ced0 Add support for Raspberry Pi 4
Hack to support Raspberry Pi 4:

* Override ganged power switching reported by USB2 hub as per-port. This is not necessarily true,
  but is consistent with per-port power switching returned by dual USB3 root hub.
  Proper fix is for Raspberry Pi 4 USB firmware to return consistent descriptor information.

* When root USB3 hub is detected on RPi4 without ContainerID, it is assumed to have
  ContainerID of dual USB2 hub, so USB2/3 duality is still working as expected.
  Proper fix would be for USB3 root hub to report correct ContainerID.
2020-01-05 13:43:14 -08:00
Mark Deneen
9857849c0e Update license hash to correct value, fixing yocto building 2019-11-18 13:51:49 -08:00
Vadim Mikhailov
821cdb8833 Update Dell U2415 info 2019-11-15 00:11:09 -08:00
Vadim Mikhailov
c387442b0c Add D-Link DUB-H4 rev B as supported device
Reported in #188.
2019-11-12 17:58:21 -08:00
Vadim Mikhailov
b690bd376a Add Belkin F5U101 as supported device
Reported in #187.
2019-11-12 17:58:21 -08:00
Vadim Mikhailov
c220668adc Add Dell UltraSharp U2415 as supported device
Reported in #191
2019-11-12 12:01:07 -08:00
Karsten Hohmeier
3e10680f22 Fix compile warning about format truncation by increasing buffer size for description 2019-11-05 13:52:24 -08:00
Vadim Mikhailov
39b407a863 Add Juiced Systems 6+1+1 USB 3.0 Gigabit Ethernet Smart Charging Hub (6HUB-01) as supported device
Reported in #184.
2019-11-01 22:27:14 -07:00
Vadim Mikhailov
d227c8326f Don't complain about USB permission problems if we are already root 2019-10-23 22:52:44 -07:00
Vadim Mikhailov
743ecf226b Relax level check when looking for USB2/3 dual hubs
Some devices (notably Raspberry 4B) have USB3 hub that advertises
its USB2 compatibility partner at different depth level.
Raspberry 4B onboard hub doesn't yet support uhubctl directly
(but it should once https://github.com/raspberrypi/linux/issues/3079 is fixed),
but this breaks level check restriction for any external USB3 hub attached to RPi4B
- so this check has been removed.
2019-10-16 23:25:36 -07:00
Vadim Mikhailov
fd611df1e7 Remove Coolgear USBG-4U3MLR2 from supported list
After deeper look, it turns out that this hub doesn't really work,
see more in issue #177.
2019-10-16 23:20:53 -07:00
Vadim Mikhailov
a6cdc3dc4b Remove Plugable USB2-HUB10S from supported list
As reported in issue #181, Plugable USB2-HUB10S does not support per-port power switching.
2019-10-08 18:15:19 -07:00
Vadim Mikhailov
609d0bcae1 Clarify which revisions of D-Link hubs are working 2019-10-05 20:48:00 -07:00
Vadim Mikhailov
54365acb8d Update info for Coolgear USBG-4U3MLR2 2019-10-01 10:33:36 -07:00
Vadim Mikhailov
6e5782c3b7 Add Coolgear USBG-4U3MLR2 as supported device
Reported in #177.
2019-09-26 22:23:07 -07:00
Vadim Mikhailov
59447ce431 Add ThinkPad Ultra Docking Station 40AJ0135EU as supported device
Reported in #176.
2019-09-24 12:47:15 -07:00
Vadim Mikhailov
05647714b6 Apply debian hardening suggestions for Linux
Follow hardening tips per https://wiki.debian.org/Hardening.
We have already applied `-z relro` before, now add `-z now` as well.
2019-09-20 17:43:36 -07:00
Vadim Mikhailov
4818eddc03 FreeBSD is using bNumDeviceCapabilities instead of bNumDeviceCaps
FreeBSD libusb is different from mainline libusb, and needs hacks here and there :-(

This resolves issue #175.
2019-09-20 15:29:30 -07:00
6 changed files with 138 additions and 62 deletions

View File

@@ -1,6 +1,6 @@
uhubctl USB hub per-port power control.
Copyright (c) 2009-2019, Vadim Mikhailov
Copyright (c) 2009-2020, Vadim Mikhailov
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -14,14 +14,14 @@ RM := rm -rf
CC ?= gcc
CFLAGS ?= -g -O0
CFLAGS += -Wall -Wextra -std=c99 -pedantic
GIT_VERSION := $(shell git describe --abbrev=8 --dirty --always --tags)
GIT_VERSION := $(shell git describe --match "v[0-9]*" --abbrev=8 --dirty --always --tags | cut -c2-)
ifeq ($(GIT_VERSION),)
GIT_VERSION := $(shell cat VERSION)
endif
CFLAGS += -DPROGRAM_VERSION=\"$(GIT_VERSION)\"
ifeq ($(UNAME_S),Linux)
LDFLAGS += -Wl,-z,relro -lusb-1.0
LDFLAGS += -Wl,-zrelro,-znow -lusb-1.0
endif
ifeq ($(UNAME_S),Darwin)

113
README.md
View File

@@ -20,27 +20,38 @@ This is list of known compatible USB hubs:
|:-------------------|:-----------------------------------------------------|:------|:----|:----------|:--------|:-----|
| AmazonBasics | HU3641V1 ([RPi issue](https://goo.gl/CLt46M)) | 4 | 3.0 |`2109:2811`| 2013 | |
| AmazonBasics | HU3770V1 ([RPi issue](https://goo.gl/CLt46M)) | 7 | 3.0 |`2109:2811`| 2013 | |
| AmazonBasics | HU9002V1SBL ([RPi issue](https://goo.gl/CLt46M)) | 10 | 3.1 |`2109:2817`| 2018 | |
| AmazonBasics | HUC9002V1ESL ([RPi issue](https://goo.gl/CLt46M)) | 10 | 3.1 |`2109:2817`| 2018 | |
| Apple | Thunderbolt Display 27" (internal USB hub) | 6 | 2.0 | | 2011 | 2016 |
| Apple | USB Keyboard With Numeric Pad (internal USB hub) | 3 | 2.0 | | 2011 | |
| Asus | Z87-PLUS Motherboard (onboard USB hub) | 4 | 3.0 | | 2013 | 2016 |
| B+B SmartWorx | UHR204 | 4 | 2.0 |`0856:DB00`| 2013 | |
| B+B SmartWorx | USH304 | 4 | 3.0 |`04B4:6506`| 2017 | |
| Basler | 2000036234 | 4 | 3.0 |`0451:8046`| 2016 | |
| Belkin | F5U101 | 4 | 2.0 |`0451:2046`| 2005 | 2010 |
| Belkin | F5U701-BLK | 7 | 2.0 | | 2008 | 2012 |
| Buffalo | BSH4A05U3BK | 4 | 3.0 |`05E3:0610`| 2015 | |
| Bytecc | BT-UH340 | 4 | 3.0 |`2109:8110`| 2010 | |
| Circuitco | Beagleboard-xM (internal USB hub) | 4 | 2.0 |`0424:9514`| 2010 | |
| Club3D | CSV-3242HD Dual Display Docking Station | 4 | 3.0 |`2109:2811`| 2015 | |
| CyberPower | CP-H420P | 4 | 2.0 |`0409:0059`| 2004 | |
| Cypress | CY4608 HX2VL development kit | 4 | 2.0 |`04B4:6570`| 2012 | |
| D-Link | DUB-H4 rev D1 (black edition) | 4 | 2.0 |`05E3:0608`| 2012 | |
| D-Link | DUB-H7 rev A (silver edition) | 7 | 2.0 |`2001:F103`| 2005 | 2010 |
| D-Link | DUB-H7 rev D1 (black edition) | 7 | 2.0 |`05E3:0608`| 2012 | |
| D-Link | DUB-H4 rev B (silver) | 4 | 2.0 |`05E3:0605`| 2005 | 2010 |
| D-Link | DUB-H4 rev D,E (black). Note: rev A,C not supported | 4 | 2.0 |`05E3:0608`| 2012 | |
| D-Link | DUB-H7 rev A (silver) | 7 | 2.0 |`2001:F103`| 2005 | 2010 |
| D-Link | DUB-H7 rev D (black). Note: rev B,C not supported | 7 | 2.0 |`05E3:0608`| 2012 | |
| Dell | P2416D 24" QHD Monitor | 4 | 2.0 | | 2017 | |
| Dell | UltraSharp 1704FPT 17" LCD Monitor | 4 | 2.0 |`0424:A700`| 2005 | 2015 |
| Dell | UltraSharp U2415 24" LCD Monitor | 5 | 3.0 | | 2014 | |
| Elecom | U2H-G4S | 4 | 2.0 | | 2006 | 2011 |
| GlobalScale | ESPRESSObin SBUD102 V5 | 1 | 3.0 |`1D6B:0003`| 2017 | |
| Hawking Technology | UH214 | 4 | 2.0 | | 2003 | 2008 |
| IOI | U3H415E1 | 4 | 3.0 | | 2012 | |
| j5create | JUH470 (works only in USB2 mode) | 3 | 3.0 |`05E3:0610`| 2014 | |
| Lenovo | ThinkPad EU Ultra Dockingstation (40A20090EU) | 6 | 2.0 |`17EF:100F`| 2015 | |
| Juiced Systems | 6HUB-01 | 7 | 3.0 |`0BDA:0411`| 2014 | 2018 |
| LG Electronics | 38WK95C-W monitor | 4 | 3.0 |`0451:8142`| 2018 | |
| Lenovo | ThinkPad Ultra Docking Station (40A20090EU) | 6 | 2.0 |`17EF:100F`| 2015 | |
| Lenovo | ThinkPad Ultra Docking Station (40AJ0135EU) | 7 | 3.1 |`17EF:3070`| 2018 | |
| Lenovo | ThinkPad X200 Ultrabase 42X4963 | 3 | 2.0 |`17EF:1005`| 2008 | 2011 |
| Lenovo | ThinkPad X6 Ultrabase 42W3107 | 4 | 2.0 |`17EF:1000`| 2006 | 2009 |
| Lindy | USB serial converter 4 port | 4 | 1.1 |`058F:9254`| 2008 | |
@@ -52,12 +63,13 @@ This is list of known compatible USB hubs:
| Plugable | USB3-HUB7BC | 7 | 3.0 |`2109:0813`| 2015 | |
| Plugable | USB3-HUB7C | 7 | 3.0 |`2109:0813`| 2015 | |
| Plugable | USB3-HUB7-81X | 7 | 3.0 |`2109:0813`| 2012 | |
| Plugable | USB2-HUB10S | 10 | 2.0 | | 2010 | |
| Raspberry Pi | Model B+, 2 B, 3 B (port 2 only) | 4 | 2.0 | | 2011 | |
| Raspberry Pi | Model 3 B+ | 6 | 2.0 |`0424:2514`| 2018 | |
| Raspberry Pi | B+, 2B, 3B ([see below](#raspberry-pi-b2b3b)) | 4 | 2.0 | | 2011 | |
| Raspberry Pi | 3B+ ([see below](#raspberry-pi-3b)) | 4 | 2.0 |`0424:2514`| 2018 | |
| Raspberry Pi | 4B ([see below](#raspberry-pi-4b)) | 4 | 3.0 |`2109:3431`| 2019 | |
| Renesas | uPD720202 PCIe USB 3.0 host controller | 2 | 3.0 | | 2013 | |
| Rosewill | RHUB-210 | 4 | 2.0 |`0409:005A`| 2011 | 2014 |
| Sanwa Supply | USB-HUB14GPH | 4 | 1.1 | | 2001 | 2003 |
| Seagate | Backup Plus Hub STEL8000100 | 2 | 3.0 |`0BC2:AB44`| 2016 | |
| StarTech | ST4200USBM | 4 | 2.0 |`0409:005A`| 2004 | |
| Sunix | SHB4200MA | 4 | 2.0 |`0409:0058`| 2006 | 2009 |
| Targus | PAUH212U | 7 | 2.0 | | 2004 | 2009 |
@@ -67,12 +79,11 @@ This table is by no means complete.
If your hub works with `uhubctl`, but is not listed above, please report it
by opening new issue at https://github.com/mvp/uhubctl/issues,
so we can add it to supported table. In your report, please provide
exact product model and add output from `uhubctl`.
exact product model and add output from `uhubctl`
and please test VBUS off support as described below in FAQ.
Note that quite a few modern motherboards have built-in root hubs that
do support this feature - you may not even need to buy any external hub.
WARNING: turning off built-in USB ports may cut off your keyboard or mouse,
so be careful what ports you are turning off!
USB 3.0 duality note
@@ -99,11 +110,18 @@ is using `winusb.sys` driver, which according to Microsoft does not support
[necessary USB control requests](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f680b63f-ca4f-4e52-baa9-9e64f8eee101).
This may be fixed if `libusb` starts supporting different driver on Windows.
First, you need to install library libusb-1.0 (version 1.0.12 or later):
First, you need to install library libusb-1.0 (version 1.0.12 or later, 1.0.16 or later is recommended):
* Ubuntu: `sudo apt-get install libusb-1.0-0-dev`
* Redhat: `sudo yum install libusb1-devel`
* MacOSX: `brew install libusb`, or `sudo port install libusb-devel`
> :warning: `libusb-1.0.23` is [broken](https://github.com/libusb/libusb/issues/707) on MacOS Catalina!
You have to install `libusb-1.0.22` until [libusb issue 707](https://github.com/libusb/libusb/issues/707) is fixed,
or use this workaround to force use of older Mojave build:
brew uninstall --ignore-dependencies libusb
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/5314f1d/Formula/libusb.rb
* FreeBSD: libusb is included by default
* NetBSD: `sudo pkgin install libusb1 gmake pkg-config`
* Windows: TBD?
@@ -134,6 +152,9 @@ on port 2 (`-p 2`). Supported actions are `off`/`on`/`cycle` (or `0`/`1`/`2`).
`cycle` means turn power off, wait some delay (configurable with `-d`) and turn it back on.
Ports can be comma separated list, and may use `-` for ranges e.g. `2`, or `2,4`, or `2-5`, or `1-2,5-8`.
> :warning: Turning off built-in USB ports may cut off your keyboard or mouse,
so be careful which ports you are turning off!
If you have more than one smart USB hub connected, you should choose
specific hub to control using `-l` (location) parameter.
To find hub locations, simply run `uhubctl` without any parameters.
@@ -240,12 +261,18 @@ You can use option `-r N` where N is some number from 10 to 1000 to fix this -
`uhubctl` will try to turn power off many times in quick succession, and it should suppress that.
This may be eventually fixed in kernel, see more discussion [here](https://bit.ly/2JzczjZ).
If your device is USB mass storage, invoking `udisksctl` before calling `uhubctl`
might help to mitigate this issue:
sudo udisksctl power-off --block-device /dev/disk/...`
sudo uhubctl -a off ...
#### _Multiple 4-port hubs are detected, but I only have one 7-port hub connected_
Many hub manufacturers build their USB hubs using basic 4 port USB chips.
E.g. to make 7 port hub, they daisy-chain two 4 port hubs - 1 port is lost to daisy-chaining,
so it makes it 4+4-1=7 port hub. Simularly, 10 port hub could be built as 3 4-port hubs
so it makes it 4+4-1=7 port hub. Similarly, 10 port hub could be built as 3 4-port hubs
daisy-chained together, which gives 4+4+4-2=10 usable ports.
Note that you should never try to change power state for ports used to daisy-chain internal hubs together.
@@ -255,20 +282,48 @@ Doing so will confuse internal hub circuitry and will cause unpredictable behavi
#### _Raspberry Pi turns power off on all ports, not just the one I specified_
This is limitation of Raspberry Pi hardware design.
For reference, Raspberry Pi models have following internal USB topology:
* B+/2B/3B: one USB hub `1-1`, with port `1` for Ethernet+wifi, and ports `2-5` ganged, controlled by port `2`.
(Trying to control ports 3,4,5 won't do anything).
* 3B+: 2 hubs - main hub `1-1`, all 4 ports ganged, all controlled by port `2`.
Second hub `1-1.1` (daisy-chained to main): 3 independently controlled ports, `1` is used for Ethernet+wifi,
and ports `2,3` are available with proper per-port power switching.
In other words, 2 out of total 4 ports wired outside do support independent power switching on 3B+.
* 4B: Hardware supports power switching, but current firmware is reporting broken USB descriptors.
For more details see Raspberry Pi issue https://github.com/raspberrypi/linux/issues/3079.
USB3 hub `2`, 4 ports, per-port power switching. BOS `ContainerID` not reported (required for USB3).
USB2 hub `1`, 1 port, no usable ports, connects hub `1-1` below.
USB2 hub `1-1`, 4 ports, dual to USB3 hub above. Hub descriptor incorrectly reports ganged power switching.
USB2 hub `3`, 1 port, OTG controller, incorrectly reports ganged power switching.
For reference, supported Raspberry Pi models have following internal USB topology:
##### Raspberry Pi B+,2B,3B
* Single hub `1-1`, ports 2-5 ganged, all controlled by port `2`:
uhubctl -l 1-1 -p 2 -a 0
Trying to control ports `3`,`4`,`5` will not do anything.
Port `1` controls power for Ethernet+WiFi.
##### Raspberry Pi 3B+
* Main hub `1-1`, all 4 ports ganged, all controlled by port `2` (turns off secondary hub ports as well).
Port `1` connects hub `1-1.1` below, ports `2` and `3` are wired outside, port `4` not wired.
uhubctl -l 1-1 -p 2 -a 0
* Secondary hub `1-1.1` (daisy-chained to main): 3 ports,
port `1` is used for Ethernet+WiFi, and ports `2` and `3` are wired outside.
##### Raspberry Pi 4B
> :warning: You may need to [update firmware](https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md)
to vl805 00137ac or later to make power switching work on RPi 4B.
* USB2 hub `1`, 1 port, only connects hub `1-1` below.
* USB2 hub `1-1`, 4 ports ganged, dual to USB3 hub `2` below:
uhubctl -l 1-1 -a 0
* USB3 hub `2`, 4 ports ganged, dual to USB2 hub `1-1` above:
uhubctl -l 2 -a 0
* USB2 hub `3`, 1 port, OTG controller:
uhubctl -l 3 -p 1 -a 0
As a workaround, you can buy any external USB hub from supported list,
attach it to any USB port of Raspberry Pi, and control power on its ports independently.
@@ -285,20 +340,22 @@ Notable projects using uhubctl
| [Build Status Light](https://goo.gl/3GA82o) | Create a build status light in under 10 minutes |
| [Buildenlights](https://git.io/fj1FC) | GitLab/GitHub project build status as green/red light |
| [Weather Station](https://goo.gl/3b1FzC) | Reset Weather Station when it freezes |
| [sysmoQMOD](https://goo.gl/8wvcKA) | Reset cellular modems when necessary |
| [sysmoQMOD](https://bit.ly/2VtWrVt) | Reset cellular modems when necessary |
| [Smog Sensor](https://bit.ly/2EMwgCk) | Raspberry Pi based smog sensor power reset |
| [Terrible Cluster](https://goo.gl/XjiXFu) | Power on/off Raspberry Pi cluster nodes as needed |
| [Ideal Music Server](https://bit.ly/2UJq6Z9) | Turn off unused USB ports to improve audio quality |
| [Ideal Music Server](https://bit.ly/39MeVFQ) | Turn off unused USB ports to improve audio quality |
| [USB drives with no phantom load](https://goo.gl/qfrmGK) | Power USB drives only when needed to save power |
| [USB drive data recovery](https://goo.gl/4MddLr) | Recover data from failing USB hard drive |
| [Control power to 3D printer](https://git.io/fh5Tr) | OctoPrint web plugin for USB power control |
| [USB fan for Raspberry Pi](https://bit.ly/2TRV6sM) | Control USB fan to avoid Raspberry Pi overheating |
| [Raspberry Pi Reboot Router](https://bit.ly/3aNbQqs) | Automatically reboot router if internet isn't working |
| [Control USB Lamp With Voice](https://bit.ly/2VtW2SX) | Voice Control of USB Lamp using Siri and Raspberry Pi |
Copyright
=========
Copyright (C) 2009-2019 Vadim Mikhailov
Copyright (C) 2009-2020 Vadim Mikhailov
This file can be distributed under the terms and conditions of the
GNU General Public License version 2.

View File

@@ -1 +1 @@
v2.1.0-dev
v2.2.0-dev

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 Vadim Mikhailov
* Copyright (c) 2009-2020 Vadim Mikhailov
*
* Utility to turn USB port power on/off
* for USB hubs that support per-port power switching.
@@ -182,7 +182,7 @@ struct descriptor_strings {
char vendor[64];
char product[64];
char serial[64];
char description[256];
char description[512];
};
struct hub_info {
@@ -408,9 +408,54 @@ static int get_hub_info(struct libusb_device *dev, struct hub_info *info)
strcat(info->location, s);
}
/* Get container_id: */
bzero(info->container_id, sizeof(info->container_id));
struct libusb_bos_descriptor *bos;
rc = libusb_get_bos_descriptor(devh, &bos);
if (rc == 0) {
int cap;
#ifdef __FreeBSD__
for (cap=0; cap < bos->bNumDeviceCapabilities; cap++) {
#else
for (cap=0; cap < bos->bNumDeviceCaps; cap++) {
#endif
if (bos->dev_capability[cap]->bDevCapabilityType == LIBUSB_BT_CONTAINER_ID) {
struct libusb_container_id_descriptor *container_id;
rc = libusb_get_container_id_descriptor(NULL, bos->dev_capability[cap], &container_id);
if (rc == 0) {
int i;
for (i=0; i<16; i++) {
sprintf(info->container_id+i*2, "%02x", container_id->ContainerID[i]);
}
info->container_id[i*2] = 0;
libusb_free_container_id_descriptor(container_id);
}
}
}
libusb_free_bos_descriptor(bos);
/* Raspberry Pi 4 hack for USB3 root hub: */
if (strlen(info->container_id)==0 &&
strcasecmp(info->vendor, "1d6b:0003")==0 &&
info->level==1 &&
info->nports==4 &&
bcd_usb==USB_SS_BCD)
{
strcpy(info->container_id, "5cf3ee30d5074925b001802d79434c30");
}
}
info->ppps = 0;
/* Logical Power Switching Mode */
int lpsm = uhd->wHubCharacteristics[0] & HUB_CHAR_LPSM;
if (lpsm == HUB_CHAR_COMMON_LPSM && info->nports == 1) {
/* For 1 port hubs, ganged power switching is the same as per-port: */
lpsm = HUB_CHAR_INDV_PORT_LPSM;
}
/* Raspberry Pi 4 reports inconsistent descriptors, override: */
if (lpsm == HUB_CHAR_COMMON_LPSM && strcasecmp(info->vendor, "2109:3431")==0) {
lpsm = HUB_CHAR_INDV_PORT_LPSM;
}
/* Over-Current Protection Mode */
int ocpm = uhd->wHubCharacteristics[0] & HUB_CHAR_OCPM;
/* LPSM must be supported per-port, and OCPM per port or ganged */
@@ -423,28 +468,6 @@ static int get_hub_info(struct libusb_device *dev, struct hub_info *info)
} else {
rc = len;
}
/* Get container_id: */
bzero(info->container_id, sizeof(info->container_id));
struct libusb_bos_descriptor *bos;
rc = libusb_get_bos_descriptor(devh, &bos);
if (rc == 0) {
int cap;
for (cap=0; cap < bos->bNumDeviceCaps; cap++) {
if (bos->dev_capability[cap]->bDevCapabilityType == LIBUSB_BT_CONTAINER_ID) {
struct libusb_container_id_descriptor *container_id;
rc = libusb_get_container_id_descriptor(NULL, bos->dev_capability[cap], &container_id);
if (rc == 0) {
int i;
for (i=0; i<16; i++) {
sprintf(info->container_id+i*2, "%02x", container_id->ContainerID[i]);
}
info->container_id[i*2] = 0;
libusb_free_container_id_descriptor(container_id);
}
}
}
libusb_free_bos_descriptor(bos);
}
libusb_close(devh);
}
return rc;
@@ -750,10 +773,6 @@ static int usb_find_hubs()
if (hubs[i].nports != hubs[j].nports)
continue;
/* And the same level: */
if (hubs[i].level != hubs[j].level)
continue;
/* Finally, we claim a match: */
match = j;
break;
@@ -895,7 +914,7 @@ int main(int argc, char *argv[])
opt_location
);
#ifdef __gnu_linux__
if (rc < 0) {
if (rc < 0 && geteuid() != 0) {
fprintf(stderr,
"There were permission problems while accessing USB.\n"
"To fix this, run this tool as root using 'sudo uhubctl',\n"

View File

@@ -2,7 +2,7 @@ DESCRIPTION = "uhubctl - USB hub per-port power control"
HOMEPAGE = "https://github.com/mvp/uhubctl"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
file://LICENSE;md5=7a7d8e0fdffe495ff61f52ceee61b2f7"
file://LICENSE;md5=a79e6a142b69522fe7757fe7313895eb"
DEPENDS = "libusb1"
RDEPENDS_${PN} = "libusb1"