From e5a19b2505a07aef8aa1e095a374c9e147b42ab5 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 27 Jul 2009 01:32:32 +0000 Subject: [PATCH] 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 --- src/bin/Jamfile | 1 + src/bin/setusbconfig.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/bin/setusbconfig.cpp diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 66dede506f..fdbd62908f 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -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 diff --git a/src/bin/setusbconfig.cpp b/src/bin/setusbconfig.cpp new file mode 100644 index 0000000000..6f793797d1 --- /dev/null +++ b/src/bin/setusbconfig.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include + + +int +main(int argc, char *argv[]) +{ + if (argc < 3) { + printf("usage: %s \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; +}