usbreset

Git mirror of https://marc.info/?l=linux-usb&m=121459435621262&w=2
git clone git://git.finwo.net/app/usbreset
Log | Files | Refs | README

usbreset.c (707B)


      1 /* usbreset -- send a USB port reset to a USB device */
      2 
      3 #include <stdio.h>
      4 #include <unistd.h>
      5 #include <fcntl.h>
      6 #include <errno.h>
      7 #include <sys/ioctl.h>
      8 
      9 #include <linux/usbdevice_fs.h>
     10 
     11 int main(int argc, char **argv) {
     12   const char *filename;
     13   int fd;
     14   int rc;
     15 
     16   if (argc != 2) {
     17     fprintf(stderr, "Usage: usbreset device-filename\n");
     18     return 1;
     19   }
     20   filename = argv[1];
     21 
     22   fd = open(filename, O_WRONLY);
     23   if (fd < 0) {
     24     perror("Error opening output file");
     25     return 1;
     26   }
     27 
     28   printf("Resetting USB device %s\n", filename);
     29   rc = ioctl(fd, USBDEVFS_RESET, 0);
     30   if (rc < 0) {
     31     perror("Error in ioctl");
     32     return 1;
     33   }
     34   printf("Reset successful\n");
     35 
     36   close(fd);
     37   return 0;
     38 }