Advertisement
hkbruvold

usbreset.c

Jan 20th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. /* usbreset -- send a USB port reset to a USB device */
  2. /* http://marc.info/?l=linux-usb&m=121459435621262&w=2 */
  3.  
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <errno.h>
  8. #include <sys/ioctl.h>
  9.  
  10. #include <linux/usbdevice_fs.h>
  11.  
  12.  
  13. int main(int argc, char **argv)
  14. {
  15.     const char *filename;
  16.     int fd;
  17.     int rc;
  18.  
  19.     if (argc != 2) {
  20.         fprintf(stderr, "Usage: usbreset device-filename\n");
  21.         return 1;
  22.     }
  23.     filename = argv[1];
  24.  
  25.     fd = open(filename, O_WRONLY);
  26.     if (fd < 0) {
  27.         perror("Error opening output file");
  28.         return 1;
  29.     }
  30.  
  31.     printf("Resetting USB device %s\n", filename);
  32.     rc = ioctl(fd, USBDEVFS_RESET, 0);
  33.     if (rc < 0) {
  34.         perror("Error in ioctl");
  35.         return 1;
  36.     }
  37.     printf("Reset successful\n");
  38.  
  39.     close(fd);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement