Skip to content

Instantly share code, notes, and snippets.

@enijkamp
Created May 5, 2014 20:43
Show Gist options
  • Save enijkamp/87d55c0eb2d6520ff554 to your computer and use it in GitHub Desktop.
Save enijkamp/87d55c0eb2d6520ff554 to your computer and use it in GitHub Desktop.
usbreset
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
// send reset to USB device
int main(int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "usage: usbreset /dev/bus/usb/<bus>/<dev>\n");
return 1;
}
const char* filename = argv[1];
int fd = open(filename, O_WRONLY);
if (fd < 0)
{
perror("Error while opening device file file");
return 1;
}
printf("Resetting USB device %s\n", filename);
int rc = ioctl(fd, USBDEVFS_RESET, 0);
if (rc < 0)
{
perror("Error in ioctl");
return 1;
}
printf("Reset successful!\n");
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment