Advertisement
Guest User

usbreset.c for restart USB port

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