Restarting/Resetting a USB Port?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Restarting/Resetting a USB Port?
# 1  
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
# 2  
Old 12-20-2014
Having read your post a few times I think that you may be going about this the wrong way. You shouldn't need to reset the USB port, the modem software (driver should take care of it.

Firstly, what operating system is it????

Do you definitely have the correct Conexant driver for that O/S?

A modem is a serial port device but in this case the serial port is a virtual one inside the USB driver on the host.

If the remote end hangs up, the local modem should detect carrier loss and, through the USB interface, notify it's host uSB driver, which in turn should signal to the O/S that the remote end has gone away. The local O/S responds by closing the session/process thereby clearing down the modem (virtual) port.

So do you have the right USB driver for your O/S?

and

Is the local modem configured to correctly report a loss of carrier (DCD signal)? See modem manual for that one.
# 3  
Old 12-22-2014
Hey, thanks for the reply.

OS: OpenSuSE 13.1 (Bottle)
PC: CuBox-i arm processor
Code:
# uname -a
Linux CuBox-HQ 3.14.14-cubox-i #1 SMP Sat Sep 13 03:48:24 UTC 2014 armv7l armv7l armv7l GNU/Linux

Quote:
You shouldn't need to reset the USB port, the modem software (driver should take care of it.
Yea, I wish it was. But in certain cases the modem seems to hang and it stops excepting AT Commands and becomse completely unresponsize at certain
times. Most of the time it will reset correctly when an unexpected hang up occurs, but not everytime. There has been a few times where I hang up randomly
on the other end (*during testing) just to see what happens and the modem completely locks up and the only way to get it back is to either reboot the PC or
unplug and plug back in the modem.

This is the 2nd USB Modem I've tried using. The 1st Modem was a Zoom USB Modem Model 3095. This modem worked MUCH better in terms of never really
locking up, but there was an issue with External Caller-ID NOT working when the CID came from the TelCO. I'm pretty sure it's an mgetty thing since the
external CID worked in Putty (*for linux and Windows). But, since the PC will except calls based on the CID, this part was not exceptable so we tried this
TRENDnet TFM-561U.
On this modem the CID worked perfectly with mgetty, so we decided to use this one since the CID was of the upmost importance...

The strange thing is both of these modems look the EXACT same, other then the physical color of the modems they are the same. Even if you watch
/var/log/messages when connecting each modem the both report the exact same Serial Number and Manufacturer. If you look at the output below
you would see the exact same thing when connecting each modem. So you'd think they would work pretty much the same...

Output from "/var/log/messages", driver is "cdc_acm":
Code:
2014-12-22T12:32:55.433571-05:00 CuBox-HQ kernel: [ 5339.850276] usb 2-1.4: new full-speed USB device number 7 using ci_hdrc
2014-12-22T12:32:55.507563-05:00 CuBox-HQ kernel: [ 5339.924329] usb 2-1.4: device descriptor read/64, error -32
2014-12-22T12:32:55.681552-05:00 CuBox-HQ kernel: [ 5340.098154] usb 2-1.4: device descriptor read/64, error -32
2014-12-22T12:32:55.855483-05:00 CuBox-HQ kernel: [ 5340.272103] usb 2-1.4: new full-speed USB device number 8 using ci_hdrc
2014-12-22T12:32:58.361628-05:00 CuBox-HQ kernel: [ 5342.778273] usb 2-1.4: New USB device found, idVendor=0572, idProduct=1329
2014-12-22T12:32:58.361712-05:00 CuBox-HQ kernel: [ 5342.778306] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
2014-12-22T12:32:58.361731-05:00 CuBox-HQ kernel: [ 5342.778327] usb 2-1.4: Product: USB Modem
2014-12-22T12:32:58.361745-05:00 CuBox-HQ kernel: [ 5342.778362] usb 2-1.4: Manufacturer: Conexant
2014-12-22T12:32:58.361757-05:00 CuBox-HQ kernel: [ 5342.778382] usb 2-1.4: SerialNumber: 24680246
2014-12-22T12:32:58.368661-05:00 CuBox-HQ kernel: [ 5342.785590] cdc_acm 2-1.4:1.0: ttyACM0: USB ACM device
2014-12-22T12:32:58.394806-05:00 CuBox-HQ mtp-probe: checking bus 2, device 8: "/sys/devices/soc0/soc.1/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb2/2-1/2-1.4"
2014-12-22T12:32:58.400412-05:00 CuBox-HQ mtp-probe: bus: 2, device: 8 was not an MTP device
2014-12-22T12:33:02.365195-05:00 CuBox-HQ ModemManager[408]: <info>  Creating modem with plugin 'Generic' and '1' ports
2014-12-22T12:33:02.368927-05:00 CuBox-HQ ModemManager[408]: <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-22T12:33:02.461291-05:00 CuBox-HQ ModemManager[408]: <warn>  Modem couldn't be initialized: couldn't load current capabilities: Failed to determine modem capabilities.

I'm not sure if the cdc_acm is the correct driver or not, so I had tried last week to use the driver that came with the Zoom modem. The TRENDnet modem
did NOT have a Linux driver on the disc, only Windows ones. So I had tried to compile the Linux driver that was on the Zoom Modem's disc, but was unable to
do so since I do not have the Kernel Sources on this machine in order to compile drivers/kernel modules. And I couldn't seem to figure out how to get that part
done...

I think I may have found the correct sources for the Kernel I'm running (*version 3.14.14)... I'm downloading them now and hopefully I can get it compiled
and symlink'ed to the correct location so I can actually compile that driver...

But in the mean time, this output below, is for the most part, what happens in the log when the modem freezes up. You'll see at the top is where I login to
the PC by dialing into the modem. Then, I hang-up the line on the other side and this is what happens. Doesn't happen everytime, but somewhat frequently...

Output from "/var/log/mgetty.ttyACM0":
Code:
12/19 17:40:01 CM0   setenv: 'CALLER_ID=5551234567'
12/19 17:40:01 CM0   setenv: 'CONNECT=57600'
12/19 17:40:01 CM0   setenv: 'DEVICE=ttyACM0'
12/19 17:40:01 ##### data dev=ttyACM0, pid=3740, caller='5551234567', conn='57600', name='', cmd='/bin/login', user='netAdmin'

--
12/19 17:42:09 CM0  mgetty: interim release 1.1.36-Jun15
12/19 17:42:09 CM0   increasing modem_check_time to 900 sec.
12/19 17:42:09 CM0  check for lockfiles
12/19 17:42:09 CM0   checklock: no active process has lock, will remove
12/19 17:42:09 CM0  locking the line
12/19 17:42:09 CM0   makelock(ttyACM0) called
12/19 17:42:09 CM0   do_makelock: lock='/var/lock/LCK..ttyACM0'
12/19 17:42:09 CM0   lock made
12/19 17:42:10 CM0   tio_get_rs232_lines: status: RTS CTS DSR DTR
12/19 17:42:10 CM0  lowering DTR to reset Modem
12/19 17:42:10 CM0  TIOCMBIC failed: Broken pipe
12/19 17:42:10 CM0   tss: set speed to 57600 (10001)
12/19 17:42:10 CM0   tio_set_flow_control( HARD )
12/19 17:42:10 CM0   waiting for line to clear (VTIME=1), read: 
12/19 17:42:10 CM0  send: ATZ[0d]
12/19 17:42:10 CM0  waiting for ``OK''
12/19 17:42:10 CM0   got: 
12/19 17:42:30 CM0  timeout in chat script, waiting for `OK'
12/19 17:42:30 CM0  init chat timed out, trying force-init-chat
12/19 17:42:30 CM0  send: \d\d\d+++\d\d\d[0d]
12/19 17:42:33 CM0  send: ATZ[0d]
12/19 17:42:33 CM0  waiting for ``OK''
12/19 17:42:33 CM0   got: 
12/19 17:42:53 CM0  timeout in chat script, waiting for `OK'
12/19 17:42:53 CM0  init chat failed, exiting...: Interrupted system call
12/19 17:42:53 ##### failed in mg_init_data, dev=ttyACM0, pid=3836

12/19 17:42:53 CM0   removing lock file
--
12/19 17:42:53 CM0  mgetty: interim release 1.1.36-Jun15
12/19 17:42:53 CM0   increasing modem_check_time to 900 sec.
12/19 17:42:53 CM0  check for lockfiles
12/19 17:42:53 CM0   checklock: stat failed, no file
12/19 17:42:53 CM0  locking the line
12/19 17:42:53 CM0   makelock(ttyACM0) called
12/19 17:42:53 CM0   do_makelock: lock='/var/lock/LCK..ttyACM0'
12/19 17:42:53 CM0   lock made
12/19 17:42:53 CM0   tio_get_rs232_lines: status: RTS CTS DSR DTR
12/19 17:42:53 CM0  lowering DTR to reset Modem
12/19 17:42:53 CM0  TIOCMBIC failed: Broken pipe
12/19 17:42:53 CM0   tss: set speed to 57600 (10001)
12/19 17:42:53 CM0   tio_set_flow_control( HARD )
12/19 17:42:53 CM0   waiting for line to clear (VTIME=1), read: 
12/19 17:42:54 CM0  send: ATZ[0d]
12/19 17:42:54 CM0  waiting for ``OK''
12/19 17:42:54 CM0   got: 
12/19 17:43:14 CM0  timeout in chat script, waiting for `OK'
12/19 17:43:14 CM0  init chat timed out, trying force-init-chat
12/19 17:43:14 CM0  send: \d\d\d+++\d\d\d[0d]
12/19 17:43:17 CM0  send: ATZ[0d]
12/19 17:43:17 CM0  waiting for ``OK''
12/19 17:43:17 CM0   got: 
12/19 17:43:37 CM0  timeout in chat script, waiting for `OK'
12/19 17:43:37 CM0  init chat failed, exiting...: Interrupted system call
12/19 17:43:37 ##### failed in mg_init_data, dev=ttyACM0, pid=3840

12/19 17:43:37 CM0   removing lock file

But I'm going to attempt to compile this Kernel again since I think I may have found the correct sources. I'll reply back with my results shortly. Hopefully this
driver will work better if I can ever get it compiled...

Thanks Again for the reply, much appreciated!

Thanks,
Matt
# 4  
Old 12-22-2014
Here's a similar discussion from the past. Interesting but no answer.

Traysoft.com
This User Gave Thanks to hicksd8 For This Post:
# 5  
Old 12-22-2014
Humm interesting, pretty similar... Too bad is not mgetty they were using. Wish there was a way to manually control mgetty while it's running, like sending it an AT command, but I don't think that's possible..?

Tomorrow I'm going to attempt to install the kernel sources I found for my version. Since both of the modems I mentioned are Conexant modems, I'm hoping the driver that came with the Zoom modem will work with the TRENDnet one. Hopefully if I can get that driver compiled tomorrow it will fix this hangup issue... Maybe it will even fix the CID problem with the Zoom modem.

Sorry I missed your question about the modem detecting the DCD... Not sure, but I think it does, but not positive. But I'll have to check up on that one. Is that the same as when I dial into the PC with that USB modem from my laptop, using minicom and another USB modem, and I issue a hangup on my laptop's side I see the message, "NO CARRIER".. Is that the same?

Thanks again for the reply...


Thanks Again,
Matt
# 6  
Old 12-23-2014
Yes, you got it. There is an interface signal (called DCD, Data Carrier Detect, which is pin 8 on the 25-pin RS232) that tells the host at each end if the modulated carrier (telephone line signal) is lost.

Although your (RS232) interface is a virtual one within the USB driver, the functionality should be the same. My point is that there may be some programming instruction (AT command(s)) to tell each of the modems what they should do if they see carrier lost. I would expect them to notify the USB driver through the USB interface so that the USB driver (if it's the correct one) can tell the host O/S that the line has gone down.
This User Gave Thanks to hicksd8 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question