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
16 import usb_descriptors
19 class PlatformCapabilityDescriptor(usb_descriptors
.Descriptor
):
20 """Microsoft OS 2.0 platform capability descriptor.
23 def __init__(self
, **kwargs
):
24 super(PlatformCapabilityDescriptor
, self
).__init
__(**kwargs
)
25 self
._descriptor
_set
= None
28 def descriptor_set_size(self
):
29 if self
._descriptor
_set
is None:
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.
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.
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.
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.
92 CompatibleId
.AddComputedField('wLength', 'H', 'struct_size')
93 CompatibleId
.AddFixedField('wDescriptorType', 'H', 0x03)
94 CompatibleId
.AddField('CompatibleID', '8s')
95 CompatibleId
.AddField('SubCompatibleID', '8s', default
='')