Skip to content

Commit

Permalink
Start supporting some transfers in the new Windows USB backend
Browse files Browse the repository at this point in the history
This patch starts adding support for opening USB devices and issuing
requests to them when using the new Windows USB backend. Only non-
composite devices are supported currently as enumerating the device
paths for composite devices is more complex.

This has been tested with a WebLight which is a non-composite device
that only requires control transfers.

Bug: 637404
Change-Id: Ib792896435106bd03b3d5743608be44a22d4b153
Reviewed-on: https://chromium-review.googlesource.com/834887
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525253}
  • Loading branch information
reillyeon authored and Commit Bot committed Dec 20, 2017
1 parent dfc1686 commit 68032f0
Show file tree
Hide file tree
Showing 7 changed files with 529 additions and 23 deletions.
10 changes: 9 additions & 1 deletion device/usb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ static_library("usb") {
}

if (is_win) {
libs = [ "setupapi.lib" ]
sources += [
"scoped_winusb_handle.cc",
"scoped_winusb_handle.h",
]

libs = [
"setupapi.lib",
"winusb.lib",
]
}

if (is_android || is_chromeos || is_linux) {
Expand Down
16 changes: 16 additions & 0 deletions device/usb/scoped_winusb_handle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/usb/scoped_winusb_handle.h"

#include <windows.h>
#include <winusb.h>

namespace device {

bool WinUsbHandleTraits::CloseHandle(Handle handle) {
return WinUsb_Free(handle) == TRUE;
}

} // namespace device
38 changes: 38 additions & 0 deletions device/usb/scoped_winusb_handle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEVICE_USB_SCOPED_WINUSB_HANDLE_H_
#define DEVICE_USB_SCOPED_WINUSB_HANDLE_H_

#include "base/win/scoped_handle.h"

extern "C" {
typedef void* WINUSB_INTERFACE_HANDLE;
}

namespace device {

class WinUsbHandleTraits {
public:
using Handle = WINUSB_INTERFACE_HANDLE;

static bool CloseHandle(Handle handle);

static bool IsHandleValid(Handle handle) {
return handle != nullptr && handle != INVALID_HANDLE_VALUE;
}

static Handle NullHandle() { return nullptr; }

private:
DISALLOW_IMPLICIT_CONSTRUCTORS(WinUsbHandleTraits);
};

using ScopedWinUsbHandle =
base::win::GenericScopedHandle<WinUsbHandleTraits,
base::win::DummyVerifierTraits>;

} // namespace device

#endif // DEVICE_USB_SCOPED_WINUSB_HANDLE_H_
Loading

0 comments on commit 68032f0

Please sign in to comment.