1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 import composite_gadget
12 import usb_descriptors
15 class CompositeEchoGadget(composite_gadget
.CompositeGadget
):
18 device_desc
= usb_descriptors
.DeviceDescriptor(
19 idVendor
=usb_constants
.VendorID
.GOOGLE
,
20 idProduct
=usb_constants
.ProductID
.GOOGLE_COMPOSITE_ECHO_GADGET
,
21 bcdUSB
=0x0210, # USB 2.1 to indicate support for BOS descriptors.
27 echo_feature
= echo_gadget
.EchoCompositeFeature(
28 endpoints
=[(0, 5, 0x81, 0x01), (1, 6, 0x82, 0x02), (2, 7, 0x83, 0x03)])
30 hid_echo_feature
= hid_echo_gadget
.EchoFeature()
31 hid_feature
= hid_gadget
.HidCompositeFeature(
32 report_desc
=hid_echo_gadget
.EchoFeature
.REPORT_DESC
,
33 features
={0: hid_echo_feature
},
36 in_endpoint
=0x84, out_endpoint
=0x04)
38 super(CompositeEchoGadget
, self
).__init
__(
39 device_desc
, [echo_feature
, hid_feature
])
40 self
.AddStringDescriptor(1, 'Google Inc.')
41 self
.AddStringDescriptor(2, 'Echo Gadget')
42 self
.AddStringDescriptor(3, '{:06X}'.format(uuid
.getnode()))
43 self
.AddStringDescriptor(4, 'HID Echo')
44 self
.AddStringDescriptor(5, 'Interrupt Echo')
45 self
.AddStringDescriptor(6, 'Bulk Echo')
46 self
.AddStringDescriptor(7, 'Isochronous Echo')
48 # Enable Microsoft OS 2.0 Descriptors for Windows 8.1 and above.
49 self
.EnableMicrosoftOSDescriptorsV2(vendor_code
=0x02)
50 # These are used to force Windows to load WINUSB.SYS for the echo functions.
51 self
.SetMicrosoftCompatId(0, 'WINUSB')
52 self
.SetMicrosoftCompatId(1, 'WINUSB')
53 self
.SetMicrosoftCompatId(2, 'WINUSB')
55 def RegisterHandlers():
56 """Registers web request handlers with the application server."""
59 from tornado
import web
61 class WebConfigureHandler(web
.RequestHandler
):
64 server
.SwitchGadget(CompositeEchoGadget())
66 server
.app
.add_handlers('.*$', [
67 (r
'/composite_echo/configure', WebConfigureHandler
),