[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-usb
Subject:    Re: re-enumerating the device
From:       Alan Stern <stern () rowland ! harvard ! edu>
Date:       2008-06-27 19:18:22
Message-ID: Pine.LNX.4.44L0.0806271512330.31706-200000 () netrider ! rowland ! org
[Download RAW message or body]

On Fri, 27 Jun 2008, Greg KH wrote:

> From writing USB device firmware, I know the devices I worked with had
> no way to transition from the configured state to the "waiting for
> address to be assigned" except if the device was physically reset by
> loosing power.  So I would be very supprised if many devices could do
> this any other way.

For what it's worth, I have never seen or heard of a USB device that 
would not go into the "default" state (i.e., waiting for an address to 
be assigned) after a port reset -- unless its firmware had already 
crashed.  When that happens, all you can do is a power cycle.

In answer to Meher's question: Yes, there is a way to force Linux's USB
stack to perform a port reset and re-enumerate a device.  It can be
done using usbfs; I have attached a C program to carry it out.  Note
however, that reset followed by re-enumeration is _not_ the same thing
as power-cycle followed by reconnect and re-enumeration.

Alan Stern

["usbreset.c" (TEXT/PLAIN)]

/* 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;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic