Add a small utility to set a USB device configuration from userland.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31794 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2009-07-27 01:32:32 +00:00
parent 55ae61312c
commit e5a19b2505
2 changed files with 42 additions and 0 deletions

View File

@ -162,6 +162,7 @@ StdBinCommands
# standard commands that need libbe.so, libdevice.so
StdBinCommands
listusb.cpp
setusbconfig.cpp
: be libdevice.so : $(haiku-utils_rsrc) ;
# standard commands that need libbluetooth.so, due the Bluetooth Kit

41
src/bin/setusbconfig.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include <string.h>
#include <USBKit.h>
int
main(int argc, char *argv[])
{
if (argc < 3) {
printf("usage: %s <device> <configuration index>\n", argv[0]);
return 1;
}
BUSBDevice device(argv[1]);
if (device.InitCheck() != B_OK) {
printf("failed to open device %s\n", argv[1]);
return 2;
}
uint32 index;
if (sscanf(argv[2], "%lu", &index) != 1) {
printf("could not parse configuration index\n");
return 3;
}
const BUSBConfiguration *config = device.ConfigurationAt(index);
if (config == NULL) {
printf("couldn't get configuration at %lu\n", index);
return 4;
}
status_t result = device.SetConfiguration(config);
if (result != B_OK) {
printf("failed to set configuration: %s\n", strerror(result));
return 5;
}
printf("configuration %lu set on device %s\n", index, argv[1]);
return 0;
}