Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Restarting/Resetting a USB Port? Post 302929360 by mrm5102 on Friday 19th of December 2014 06:15:27 PM
Old 12-19-2014
Restarting/Resetting a USB Port?

Hello All,

So I have been running into an issue with a USB Modem where if someone ends their dialin connection abruptly from the other side the modem gets stuck
and I found that the only way to fix it is to either unplug the USB Modem and plug it back in, or just reboot. I'd rather not reboot if that's possible, and since this
PC will be in a remote location where I won't have access to it physically, I was hoping to find another solution...

So after searching around a bit online I found this C program that is supposed to do exactly what I was trying to do, but it doesn't seem to be working properly.
Not sure if something is incorrect in the code below seeing that I have only limited knowledge of C, I was wondering if someone elswe could tell...?

If not does anyone know of any other soultion that I might try? I saw there was a command called "udevadm", and with that your supposed to be able to
control udev and devices, I believe... But I'm not sure if that command will help my cause..?

The C code at the end of the post seems to "shutdown" that USB port, but it doesn't seem to re-rigester the device...

*The USB Modem is the device labeled "Conexant Systems (Rockwell), Inc."....

If I run lsusb before I execute the C program I see:
Code:
# lsusb
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 004: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 002 Device 005: ID 413c:3012 Dell Computer Corp. Optical Wheel Mouse
Bus 002 Device 017: ID 0572:1329 Conexant Systems (Rockwell), Inc.

Then I execute the C program, and when that's done I run lsusb again and I get:
Code:
# lsusb
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 004: ID 046d:c31c Logitech, Inc. Keyboard K120 for Business
Bus 002 Device 005: ID 413c:3012 Dell Computer Corp. Optical Wheel Mouse

As you can see this time the Modem is missing... If I watch /var/log/messages when I physically unplug the modem AFTER I execute the C program I get
no output at all, so it seems like the Kernel doesn't know its there, since normally I would get output on unplugging ANY usb device...

But this is /var/log/messages while executing the C program:
Code:
# tail -f /var/log/messages
CuBox ModemManager[406]: <info>  (tty/ttyACM0): released by modem /sys/devices/soc0/soc.1/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb2/2-1/2-1.4
2014-12-19T18:05:30.397588-05:00 CuBox kernel: [26167.864681] usb 2-1.4: reset full-speed USB device number 23 using ci_hdrc
2014-12-19T18:05:30.473544-05:00 CuBox kernel: [26167.941086] cdc_acm 2-1.4:1.0: ttyACM0: USB ACM device
2014-12-19T18:05:34.446275-05:00 CuBox ModemManager[406]: <info>  Creating modem with plugin 'Generic' and '1' ports
2014-12-19T18:05:34.456924-05:00 CuBox ModemManager[406]: <info>  Modem for device at '/sys/devices/soc0/soc.1/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb2/2-1/2-1.4' successfully created
2014-12-19T18:05:34.569078-05:00 CuBox ModemManager[406]: <warn>  Modem couldn't be initialized: couldn't load current capabilities: Failed to determine modem capabilities.

So it seems like it's recognizing the modem, but when I physically unplug and re-plug back in the modem I get more messages printed then what you see above...

Here is the C code:
Code:
/* usbreset -- send a USB port reset to a USB device */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>

int main(int argc, char **argv)
{
    const char *filename;
    int fd;
    int rc;

    if (argc != 2)
    {
        fprintf(stderr, "Usage: usbreset device-filename\n");
        return 1;
    }
    filename = argv[1];
    fd = open(filename, O_WRONLY);

    if (fd < 0)
    {
        perror("Error opening output file");
        return 1;
    }
    printf("Resetting USB device %s\n", filename);
    rc = ioctl(fd, USBDEVFS_RESET, 0);

    if (rc < 0)
    {
        perror("Error in ioctl");
        return 1;
    }
    printf("Reset successful\n");

    close(fd);
    return 0;
}

If anyone has ANY thoughts or suggestion, please feel free to share... Not really sure what else I can try here..?

Thanks in Advance,
Matt
 

10 More Discussions You Might Find Interesting

1. Solaris

network on solaris 10, through usb port...(urgent)

hi all, I have been trying to setup network on solaris10 from a long time but am unable to do so.. I tried it with the ethernet card i have(dfe -520tx) but since i was not able to find drivers for that particular device, i thought of using the usb mode to run network.. However am not able... (0 Replies)
Discussion started by: wrapster
0 Replies

2. AIX

How to connect PC's USB port to pSeries system?

Hello AIX Group Members, I have two systems: (1) IBM pSeries 640, 7026-B80. (2) A 5-month old HP laptop with Windows Vista. It has no serial port and only has USB ports on it. My question are: How can I use the laptop as the p640's terminal? How can I make the connection? What type of cable... (4 Replies)
Discussion started by: aixlover
4 Replies

3. UNIX for Dummies Questions & Answers

USB port is disabled using BIOS, I want to enable it

Hi, I have PC with Linux OS RHEL3 and USB port is disabled from BIOS. BIOS access is protected using password. But, I have root access. Now, how can I enable USB port using root access? Is there any trick that I can do using root access that can enable USB port once my PC has booted up? (3 Replies)
Discussion started by: gydave
3 Replies

4. UNIX for Advanced & Expert Users

how to watch the usb port

I want to watch the USB ports. If any device is connected to the USB port I want to take the name of the device and I want to log the device name. how to watch all the USB ports. How to find the device is connected in which usb port. (1 Reply)
Discussion started by: ungalnanban
1 Replies

5. Ubuntu

driver for external drive case on usb port

Hi I have to buy my selfe external case for hdd but I don't know whether my ubuntu linux, needs some driver to be able to work with this device or it has inside of itselfe this driver ? rhx for help. (1 Reply)
Discussion started by: presul
1 Replies

6. Shell Programming and Scripting

Restarting USB Bluetooth Dongles immediately

Hi @all, i am currently having a Problem: I want to restart 2 USB Bluetooth Dongles from the shell at the same time. It is very important that they are restarted nearly simultaneously, so that their clocks are starting to run at the same time. At the moment i am using a command called... (3 Replies)
Discussion started by: cabrix
3 Replies

7. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies

8. Solaris

Solaris 11.2 does not assign serial port to 3g usb modem?

In ubuntu etopic i create this udev rules for prolink 3g usb modem: SUBSYSTEM=="block", SUBSYSTEM=="scsi", ATTRS{idVendor}=="1e0e", ATTRS{idProduct}=="f000", ACTION=="add", RUN+="/sbin/modprobe usbserial Vendor=0X1e0e Product=0Xf000" After plugging the usb modem, ubuntu assigns the ports... (4 Replies)
Discussion started by: shamsat
4 Replies

9. Shell Programming and Scripting

USB port events linstening

Hi everybody! :) I am a complete newbie. :D Is it possible to write a script (shell or python) to listen to usb port event and to notify me every time an usb storage key is plugged or ejected? I want it to echo the device to mount (eg. /dev/sdb). I wrote an udev rule wich runs a script after... (1 Reply)
Discussion started by: manuhexadec
1 Replies

10. Linux

Connect from USB to serial port of switch

I have someone wanting to connect to the serial management port of a switch from a PC running CentOS6. The management port on the switch is apparently baud 9600, 8 data bits, 1 stop bit & no parity They have plugged in a cable to connect and the output from lsusb is:-Bus 001 Device 001: ID... (7 Replies)
Discussion started by: rbatte1
7 Replies
All times are GMT -4. The time now is 08:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy