Subversion Repositories alarming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 daniel-mar 1
 
2
// https://gist.github.com/x2q/5124616
3
// https://www.raspberrypi.org/forums/viewtopic.php?t=86265https://www.raspberrypi.org/forums/viewtopic.php?t=86265
4
 
5
/* usbreset -- send a USB port reset to a USB device
6
 *
7
 * Compile using: gcc -o usbreset usbreset.c
8
 *
9
 *
10
 * */
11
 
12
 
13
 
14
 
15
#include <stdio.h>
16
#include <unistd.h>
17
#include <fcntl.h>
18
#include <errno.h>
19
#include <sys/ioctl.h>
20
 
21
#include <linux/usbdevice_fs.h>
22
 
23
 
24
int main(int argc, char **argv)
25
{
26
        const char *filename;
27
        int fd;
28
        int rc;
29
 
30
        if (argc != 2) {
31
                fprintf(stderr, "Usage: usbreset device-filename\n");
32
                return 1;
33
        }
34
        filename = argv[1];
35
 
36
        fd = open(filename, O_WRONLY);
37
        if (fd < 0) {
38
                perror("Error opening output file");
39
                return 1;
40
        }
41
 
42
        printf("Resetting USB device %s\n", filename);
43
        rc = ioctl(fd, USBDEVFS_RESET, 0);
44
        if (rc < 0) {
45
                perror("Error in ioctl");
46
                return 1;
47
        }
48
        printf("Reset successful\n");
49
 
50
        close(fd);
51
        return 0;
52
}