Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / tools / usb_gadget / msos20_descriptors.py
blobb1e0baab062b9515139a984209f83705a022aed3
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.
5 """Microsoft OS 2.0 Descriptor generation utilities.
7 Classes to help generate Microsoft OS 2.0 descriptors.
9 Based on documentation here:
10 https://msdn.microsoft.com/en-us/library/windows/hardware/dn385747.aspx
11 """
13 import uuid
15 import usb_constants
16 import usb_descriptors
19 class PlatformCapabilityDescriptor(usb_descriptors.Descriptor):
20 """Microsoft OS 2.0 platform capability descriptor.
21 """
23 def __init__(self, **kwargs):
24 super(PlatformCapabilityDescriptor, self).__init__(**kwargs)
25 self._descriptor_set = None
27 @property
28 def descriptor_set_size(self):
29 if self._descriptor_set is None:
30 return 0
31 return len(self._descriptor_set.Encode())
33 def SetDescriptorSet(self, descriptor_set):
34 self._descriptor_set = descriptor_set
36 PlatformCapabilityDescriptor.AddComputedField('bLength', 'B', 'struct_size')
37 PlatformCapabilityDescriptor.AddFixedField(
38 'bDescriptorType', 'B', usb_constants.DescriptorType.DEVICE_CAPABILITY)
39 PlatformCapabilityDescriptor.AddFixedField(
40 'bDevCapabilityType', 'B', usb_constants.CapabilityType.PLATFORM)
41 PlatformCapabilityDescriptor.AddFixedField('bReserved', 'B', 0)
42 PlatformCapabilityDescriptor.AddFixedField(
43 'MS_OS_20_Platform_Capability_ID', '16s',
44 uuid.UUID('{D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}').bytes_le)
45 PlatformCapabilityDescriptor.AddField('dwWindowsVersion', 'I')
46 PlatformCapabilityDescriptor.AddComputedField(
47 'wMSOSDescriptorSetTotalLength', 'H', 'descriptor_set_size')
48 PlatformCapabilityDescriptor.AddField('bMS_VendorCode', 'B')
49 PlatformCapabilityDescriptor.AddField('bAltEnumCode', 'B', default=0)
52 class DescriptorSetHeader(usb_descriptors.DescriptorContainer):
53 """Microsoft OS 2.0 descriptor set header.
54 """
55 pass
57 DescriptorSetHeader.AddComputedField('wLength', 'H', 'struct_size')
58 DescriptorSetHeader.AddFixedField('wDescriptorType', 'H', 0x00)
59 DescriptorSetHeader.AddField('dwWindowsVersion', 'I')
60 DescriptorSetHeader.AddComputedField('wTotalLength', 'H', 'total_size')
63 class ConfigurationSubsetHeader(usb_descriptors.DescriptorContainer):
64 """Microsoft OS 2.0 configuration subset header.
65 """
66 pass
68 ConfigurationSubsetHeader.AddComputedField('wLength', 'H', 'struct_size')
69 ConfigurationSubsetHeader.AddFixedField('wDescriptorType', 'H', 0x01)
70 ConfigurationSubsetHeader.AddField('bConfigurationValue', 'B')
71 ConfigurationSubsetHeader.AddFixedField('bReserved', 'B', 0)
72 ConfigurationSubsetHeader.AddComputedField('wTotalLength', 'H', 'total_size')
75 class FunctionSubsetHeader(usb_descriptors.DescriptorContainer):
76 """Microsoft OS 2.0 function subset header.
77 """
78 pass
80 FunctionSubsetHeader.AddComputedField('wLength', 'H', 'struct_size')
81 FunctionSubsetHeader.AddFixedField('wDescriptorType', 'H', 0x02)
82 FunctionSubsetHeader.AddField('bFirstInterface', 'B')
83 FunctionSubsetHeader.AddFixedField('bReserved', 'B', 0)
84 FunctionSubsetHeader.AddComputedField('wSubsetLength', 'H', 'total_size')
87 class CompatibleId(usb_descriptors.Descriptor):
88 """Microsoft OS 2.0 compatible ID descriptor.
89 """
90 pass
92 CompatibleId.AddComputedField('wLength', 'H', 'struct_size')
93 CompatibleId.AddFixedField('wDescriptorType', 'H', 0x03)
94 CompatibleId.AddField('CompatibleID', '8s')
95 CompatibleId.AddField('SubCompatibleID', '8s', default='')