Coder Social home page Coder Social logo

hub-ctrl's Introduction

Credit

Originally created by NIIBE Yutaka and published to Github by Joel Dare on 31 Jan 2013.

I forked the code and stated editing as of 8 Sep 2016

Dependency

For Ubuntu:

sudo apt-get install libusb-dev

Plus 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 -std=c99

That results in an executable binary called hub-ctrl.

Usage

List hubs and ports (colour-coded in actual use):

$ sudo ./hub-ctrl
Hub 0 (Bus 1, Dev 4) - ganged power switching
 ├─ Port  1:  power
 ├─ Port  2:  power
 ├─ Port  3:  power connect enable
 ├─ Port  4:  power
 ├─ Port  5:  power highspeed connect enable
 ├─ Port  6:  power
 └─ Port  7:  power
Hub 1 (Bus 1, Dev 2) - individual power switching
 ├─ Port  1:  power highspeed connect enable
 ├─ Port  2: 
 ├─ Port  3:  power highspeed connect enable
 ├─ Port  4:  power
 └─ Port  5:  power
Hub 2 (Bus 1, Dev 1) - ganged power switching
 └─ Port  1:  power highspeed connect enable

Note [Hub number] or [Bus number plus Device number] and Port number of your target port/device. To control its power:

# use hub and port number to locate device/port
#   -p 0 = off; 1 = on
$ sudo ./hub-ctrl -H 0 -P 3 -p 0

or

# use bus, device and port number to locate device/port
$ sudo ./hub-ctrl -B 1 -D 4 -P 3 -p 0

A useful command to get more information of USB devices including hierarchy of chained USB hubs is:

$ lsusb -t
/:  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 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 3: Dev 4, If 0, Class=Hub, Driver=hub/7p, 480M
            |__ Port 3: Dev 25, If 0, Class=Human Interface Device, Driver=usbhid, 12M
            |__ Port 3: Dev 25, If 1, Class=Human Interface Device, Driver=usbhid, 12M
            |__ Port 5: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 480M

Known Issues

  • No validation of command-line arguments
  • Some USB ports turn back on automatically after being turned off.

TODO

  • Add device description/type in port status lines. This is particularly useful in identifying chained hubs so you don't accidentally turn off an entire hub by powering off the port that it connects to. See above output of lsusb -t for an example - turning off bus 1 port 3 dev 4 will kill the 7-port hub. This relationship isn't clear in the output of sudo ./hub-ctrl.
  • Convert to python script as I'm more comfortable with it.

hub-ctrl's People

Contributors

codazoda avatar alokmenghrajani avatar silum avatar runderwo avatar

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.