Code Monkey home page Code Monkey logo

hub-ctrl.c's Introduction

hub-ctrl.c

Control USB power on a port by port basis on some USB hubs.

Originally created by NIIBE Yutaka and published to Github by Joel Dare on January 31st, 2013.

This only works on USB hubs that have the hardware necessary to allow software controlled power switching. Most hubs DO NOT include the hardware.

Prerequisites

Before compiling it, you'll need to install libusb-dev (under Ubuntu). I installed that with the following command.

sudo apt-get install libusb-dev

You'll also need the GCC tool chain.

Compiling

To compile the hub-ctrl.c program run the following compile command.

gcc -o hub-ctrl hub-ctrl.c -lusb

That results in an executable binary called hub-ctrl.

Controlling Power

You can control the power on a port using the following command.

sudo ./hub-ctrl -h 3 -P 1 -p 0

That says to control hub 3 (-h 3) port 1 (-P 1) and to turn the power off (-p 0). You can also use ”-p 1” to turn the power back on.

You can also specify the USB device based on the BUS and DEV numbers. Use the following command the list the currently connected devices. It's useful to run this with the device disconnected and then again with the device connected so that you can tell which device is the one you are trying to target (the Targus in my case).

lsusb

Now that we know the BUS and DEV numbers, we can control the power using those numbers as well. Here's the command for that.

sudo ./hub-ctrl -b 001 -d 005 -P 1 -p 0

This time we are controlling the device on BUS 001 (-b 001) device 005 (-d 005) port 1 (-P 1) and turning the power off (-p 0).

Hubs Known to Work

The following is a list of Hubs that are known to have the hardware necessary to allow power switching.

  • D-Link-DUB-H7-High-Speed-7-Port (Tested with old Silver versions (A3, A4 & A5). Also tested with newer Black version C1 although there is one issue reporting that the C1 didn't work).
  • Elecom: U2H-G4S
  • Sanwa Supply: USB-HUB14GPH
  • Targus, Inc.: PAUH212
  • Hawking Technology: UH214
  • B+B SmartWorx (B&B Electronics): UHR204
  • B+B SmartWorx (B&B Electronics): USH304
  • Belkin: F5U701
  • Linksys: USB2HUB4

Original Copyright

Copyright (C) 2006 Free Software Initiative of Japan

Author: NIIBE Yutaka

This file can be distributed under the terms and conditions of the GNU General Public License version 2 (or later).

hub-ctrl.c's People

Contributors

alokmenghrajani avatar codazoda avatar dspinellis avatar oligu avatar runderwo avatar silum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hub-ctrl.c's Issues

Unable to turn off usb port

Hi there!

So i am using a Raspberry Pi 3 B+ with the Belkin F5U701 usb hub (the one suggested on the readme) but even though i think i am using everything the correct way it does not turn off the usb port.

Thanks in advance, any help would be greatly appreciated!

Here it is some info about what i am trying to do:

  • Output of lsusb (i am trying to turn off "Transmonde Technologies, Inc. " and it is connected to the hub "Terminus Technology Inc. Hub"

  • Output of lsusb -t (trying to turn off "Port 1: Dev 32, If 0, Class=Human Interface Device, Driver=usbhid, 12M")

  • And finally the command that i run but get no action on the usb port:

Print

Thanks again!

Realtek RTS5411 support

I tried to use the hub-ctrl to verify if a USB hub based on RTS5411 IC can be power controlled.
Unfortunately, the usb_control_msg for getting the descriptor doesn't work with this device.
The strange thing is that with lsusb command I can manage to get all the information from the HUB IC but not from the hub-ctrl software.
I analyzed the situation and find out that lsusb use libusb functions and hub-ctrl use simple usb functions.
I would like to get deep into this and maybe update a patch for this device.
In the meanwhile, do you have any suggestion that can help me?
The function usb_control_msg with the problematic hub return 0.

This is the output of lsusb for the hub:

Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.10
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 2 TT per port
bMaxPacketSize0 64
idVendor 0x0bda Realtek Semiconductor Corp.
idProduct 0x5411
bcdDevice 1.04
iManufacturer 1 Generic
iProduct 2 4-Port USB 2.0 Hub
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 1 Single TT
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 2 TT per port
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 4
wHubCharacteristic 0x00a9
Per-port power switching
Per-port overcurrent protection
TT think time 16 FS bits
Port indicators
bPwrOn2PwrGood 50 * 2 milli seconds
bHubContrCurrent 100 milli Ampere
DeviceRemovable 0x00
PortPwrCtrlMask 0xff
Hub Port Status:
Port 1: 0000.0100 power
Port 2: 0000.0100 power
Port 3: 0000.0507 highspeed power suspend enable connect
Port 4: 0000.0507 highspeed power suspend enable connect
Binary Object Store Descriptor:
bLength 5
bDescriptorType 15
wTotalLength 42
bNumDeviceCaps 3
USB 2.0 Extension Device Capability:
bLength 7
bDescriptorType 16
bDevCapabilityType 2
bmAttributes 0x0000f41e
Link Power Management (LPM) Supported
SuperSpeed USB Device Capability:
bLength 10
bDescriptorType 16
bDevCapabilityType 3
bmAttributes 0x00
wSpeedsSupported 0x000e
Device can operate at Full Speed (12Mbps)
Device can operate at High Speed (480Mbps)
Device can operate at SuperSpeed (5Gbps)
bFunctionalitySupport 1
Lowest fully-functional device speed is Full Speed (12Mbps)
bU1DevExitLat 10 micro seconds
bU2DevExitLat 1023 micro seconds
Container ID Device Capability:
bLength 20
bDescriptorType 16
bDevCapabilityType 4
bReserved 0
ContainerID {e5cdb920-3970-11e0-a935-0002a5d5c51b}
Device Status: 0x0001
Self Powered

Raspberry Pi 4 Compatible?

Hello good day. Would you like to request information if the code is compatible with Raspberry Pi 4 4GB?

Only Data signal off, not Power in RaspberryPi3 port 3, 4, 5

When I use this command, it works

sudo ./hub-ctrl -h 0 -P 2 -p 0 ; sleep 3; sudo ./hub-ctrl -h 0 -P 2 -p 1

All usb ports are powered off.

but, I want to control individual ports.

So I command this line to my raspberry pi in order to reset the power of USB port 4

sudo ./hub-ctrl -h 0 -P 4 -p 0 ; sleep 3; sudo ./hub-ctrl -h 0 -P 4 -p 1

It seams like works, but actually it doesn't.

I noticed the Signal has been off, but Power is not.

How can I solve this problem.

DLINK DUB-H7 Ver C1 no power control.

If you plug a device, for example, in the first port of the hub from the left
and execute ./hub-ctrl -h 3 -P 4 -p0
then it will just reconnect the device in that port, it doesn't shut the port power off
So I spent 35$ in vain.
Please remove this hub from the readme.

There's a newer version of the hub - D1. Maybe it works?

issue with Model B+ - elevated soft interrupts after the ethernet port is disabled

I've recently installed this on both a Model B and a Model B+. I have confirmed that the code does disable the ethernet port on both models. However on the B+ once the port is disabled the ksoftirqd/0 becomes top cpu user, starting at 5% and creeping slowly higher. I have not let it get past 15% - and the system is noticably laggy.

device not found

Hi all,

my setup is with a raspi 3b+ and a powered usb hub 2.0.
The usb hub is a 4 ports, connected to raspi usb port 2.

Below is the output of lsusb -t -v

The device I want to turn off is this one: "Port 4: Dev 25, If 0, Class=Mass Storage, Driver=usb-storage, 480M"

The command I run is: "sudo ./hub-ctrl -b 001 -d 025 -P 2 -p 0"
But I get: "Device not found."

If instead I turn off the hub with the command: "sudo ./hub-ctrl -b 001 -d 024 -P 2 -p 0"
I don't get any output, with a RC=0.

Do you have suggestions?

:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 13, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 2: Dev 24, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 4: Dev 25, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        |__ Port 3: Dev 8, If 0, Class=Vendor Specific Class, Driver=usbfs, 480M
        |__ Port 3: Dev 8, If 1, Class=Vendor Specific Class, Driver=, 480M
        |__ Port 3: Dev 8, If 2, Class=Vendor Specific Class, Driver=usbfs, 480M
        |__ Port 3: Dev 8, If 3, Class=Vendor Specific Class, Driver=, 480M
        |__ Port 3: Dev 8, If 4, Class=Vendor Specific Class, Driver=, 480M
        |__ Port 3: Dev 8, If 5, Class=Vendor Specific Class, Driver=, 480M
        |__ Port 3: Dev 8, If 6, Class=Vendor Specific Class, Driver=, 480M
        |__ Port 4: Dev 9, If 0, Class=Mass Storage, Driver=usb-storage, 480M

The output of the hub-ctrl is:

sudo ./hub-ctrl                        
Hub #0 at 001:024
 INFO: ganged switching.
 WARN: Port indicators are NOT supported.
Hub #1 at 001:002
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
Hub #2 at 001:001
 INFO: ganged switching.
 WARN: Port indicators are NOT supported.

Error in the Compilng step

When I try to do the Compiling there's an error:

gcc: error: hub-ctrl.c: The file or the directory doesn't exist

Somebody can help me pls?

PS: I'm working on a Raspberry Pi 2

Problems switching power with RaspberryPi 3 Model B+

Hi there,
actually using this tool to switch power of the internal hub at the Raspi 3 Mod B (no plus). No problem, perfect, thanks a lot.
(switches VID:PID 0424:9514)

Yesterday I adapted my application-code to support the Raspi 3 Mod B+ as well (VID:PID 0424:2514, the 2nd hub detected). What I observed is that the Raspberry's hub is automatically re-powered after approx. 7 seconds, after I switched off the hub.

Even if only related. this is probably not an issue of this tool, even more likely a new 'feature of the new kernel/firmware/module of the current Raspbian. But where and why?

Can somebody help me please, to keep the RPI-hub switched off? I do not know where to dig deeper for this issue.

Is RPi 2 (v1.1) supported?

I was wondering if this is possible on a RPi 2?

I’m running OctoPi which also turns off a relay for the printer power, but LCD/main board stays on because of USB power.

failed to control

Hi,
how can I investigate the
failed to control.
: Invalid argument
error?
I get this when I try on my Pi3 sudo ./hub-ctrl -h 0 -P 2 -p 1

best regards

EDIT
pi@octopi:~ $ sudo ./hub-ctrl -v
Hub #0 at 001:001
INFO: ganged switching.
WARN: Port indicators are NOT supported.
Hub Port Status:
Port 1: 0000.0000

Usb not powering off

Hi,
i installed hub-ctrl on my raspberry pi. When i use sudo ./hub-ctrl -h 1 -P1 -p 0 all my ports power off. But not the specific one which i want. The one to which i've attached my camera. cz if the power to it is off then the lens should come out.

When i use sudo ./hub-ctrl -b 001 -d 005 -P1 -p 0 , it says device not found. I checked with lsusb my device is at bus 001 and device 005.

Expecting an quick response!

Thanks & Regards
Sameena Shaikh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.