From 58c7240a20b027b9dd85327bc39e81cf9e102985 Mon Sep 17 00:00:00 2001 From: tabledevil Date: Fri, 13 Apr 2018 15:36:54 +0200 Subject: [PATCH] added usbreset.c to repo usbreset.c allows for resetting an usb device while it stays plugged in --- usbreset.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 usbreset.c diff --git a/usbreset.c b/usbreset.c new file mode 100644 index 0000000..a7d5cf2 --- /dev/null +++ b/usbreset.c @@ -0,0 +1,40 @@ +/* usbreset -- send a USB port reset to a USB device */ + +#include +#include +#include +#include +#include + +#include + + +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; +} \ No newline at end of file