diff options
author | Arnon Gilboa <agilboa@redhat.com> | 2012-04-23 12:44:08 +0300 |
---|---|---|
committer | Arnon Gilboa <agilboa@redhat.com> | 2012-04-23 12:44:08 +0300 |
commit | d690f13c581d28dd867ad9fd869cfc696d39fbb1 (patch) | |
tree | f87aeec4708497b62591e3ae1e17cc1e138b8f69 /usbclerktest.cpp |
usbclerk: Windows service for signing and installing usb device drivers
When usbclerk service is up, any application can connect its named pipe with
a USB device (pid,vid) to sign and install. When done, the service will reply
with an ack or error code. Currently winusb driver is installed, in order to
use libusb for communicating with the device. The usbclerk service can be
installed/uninstalled by "usbclerk install"/"usbclerk uninstall".
usbclerktest is a sample cli app communicating with the usbclerk service.
Diffstat (limited to 'usbclerktest.cpp')
-rw-r--r-- | usbclerktest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/usbclerktest.cpp b/usbclerktest.cpp new file mode 100644 index 0000000..d16a70c --- /dev/null +++ b/usbclerktest.cpp @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <tchar.h> +#include "usbcommon.h" +
+int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) +{ + HANDLE pipe; + USBDevInfo dev; + DWORD pipe_mode; + DWORD bytes, ack = 0; + + if (argc < 3 || !swscanf_s(argv[1], L"%hx", &dev.vid) || + !swscanf_s(argv[2], L"%hx", &dev.pid)) { + printf("Use: usbclerktest VID PID\n"); + return 1; + } + pipe = CreateFile(USB_CLERK_PIPE_NAME, GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, 0, NULL); + if (pipe == INVALID_HANDLE_VALUE) { + printf("Cannot open pipe %S: %d\n", USB_CLERK_PIPE_NAME, GetLastError()); + return 1;
+ } + pipe_mode = PIPE_READMODE_MESSAGE | PIPE_WAIT; + if (!SetNamedPipeHandleState(pipe, &pipe_mode, NULL, NULL)) { + printf("SetNamedPipeHandleState() failed: %d\n", GetLastError()); + return 1;
+ } + printf("Signing & installing %04x:%04x\n", dev.vid, dev.pid); + if (!TransactNamedPipe(pipe, &dev, sizeof(dev), &ack, sizeof(ack), &bytes, NULL)) { + printf("TransactNamedPipe() failed: %d\n", GetLastError()); + CloseHandle(pipe); + return 1; + } + CloseHandle(pipe); + if (ack) { + printf("winusb driver install succeed"); + } else { + printf("winusb driver install failed"); + } + return 0; +} |