Created
May 5, 2014 20:43
-
-
Save enijkamp/87d55c0eb2d6520ff554 to your computer and use it in GitHub Desktop.
usbreset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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