xref: /haiku/src/bin/setusbconfig.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 #include <stdio.h>
2 #include <string.h>
3 
4 #include <USBKit.h>
5 
6 
7 int
8 main(int argc, char *argv[])
9 {
10 	if (argc < 3) {
11 		printf("usage: %s <device> <configuration index>\n", argv[0]);
12 		return 1;
13 	}
14 
15 	BUSBDevice device(argv[1]);
16 	if (device.InitCheck() != B_OK) {
17 		printf("failed to open device %s\n", argv[1]);
18 		return 2;
19 	}
20 
21 	uint32 index;
22 	if (sscanf(argv[2], "%lu", &index) != 1) {
23 		printf("could not parse configuration index\n");
24 		return 3;
25 	}
26 
27 	const BUSBConfiguration *config = device.ConfigurationAt(index);
28 	if (config == NULL) {
29 		printf("couldn't get configuration at %lu\n", index);
30 		return 4;
31 	}
32 
33 	status_t result = device.SetConfiguration(config);
34 	if (result != B_OK) {
35 		printf("failed to set configuration: %s\n", strerror(result));
36 		return 5;
37 	}
38 
39 	printf("configuration %lu set on device %s\n", index, argv[1]);
40 	return 0;
41 }
42